8#if defined(SEEXPR_ENABLE_LLVM)
28 return Builder.GetInsertBlock()->getParent();
70 if (
sft <= ExprFuncStandard::FUNC6) {
73 case ExprFuncStandard::FUNC6:
75 case ExprFuncStandard::FUNC5:
77 case ExprFuncStandard::FUNC4:
79 case ExprFuncStandard::FUNC3:
81 case ExprFuncStandard::FUNC2:
83 case ExprFuncStandard::FUNC1:
85 case ExprFuncStandard::FUNC0:
89 }
else if (
sft == ExprFuncStandard::FUNC1V) {
92 }
else if (
sft == ExprFuncStandard::FUNC2V) {
95 }
else if (
sft == ExprFuncStandard::FUNC1VV) {
98 }
else if (
sft == ExprFuncStandard::FUNC2VV) {
101 }
else if (
sft == ExprFuncStandard::FUNCN) {
104 }
else if (
sft == ExprFuncStandard::FUNCNV) {
107 }
else if (
sft == ExprFuncStandard::FUNCNVV) {
118#if LLVM_VERSION_MAJOR >= 11
122 assert(
funcCast &&
"ERROR! The callee value is not a pointer cast!");
124 assert(
funcPtr &&
"ERROR! The callee value does not contain a function!");
125 auto *
TY = llvm::cast<llvm::FunctionType>(
funcPtr->getElementType());
126 assert(
TY &&
"ERROR! The callee value does not return a function signature!");
137#if LLVM_VERSION_MAJOR >= 10
142 }
else if (
seType.isString()) {
143 static_assert(
sizeof(
char*) == 8,
"Expect 64-bit pointers");
146 assert(!
"unknown SeExpr type encountered");
154#if LLVM_VERSION_MAJOR >= 10
160 for (
unsigned i = 0;
i < dim;
i++)
172 unsigned dim = val.size();
173#if LLVM_VERSION_MAJOR >= 10
179 for (
unsigned i = 0;
i < dim;
i++)
188 std::vector<LLVM_VALUE>
vals;
201#if LLVM_VERSION_MAJOR >= 11
202 assert(
ty &&
ty->isVectorTy() &&
"This is not a vector type!");
203 auto *
VT = llvm::cast<llvm::VectorType>(
ty);
204#if LLVM_VERSION_MAJOR >= 13
205 return VT->getElementCount().getKnownMinValue();
207 return VT->getNumElements();
210 return ty->getVectorNumElements();
216 Type *
VTy =
V->getType();
217 if (
VTy->isDoubleTy())
219 if (
VTy->isPointerTy())
230 Type *
srcTy = val->getType();
282 return std::make_pair(
op1,
op2);
286 if (
op1Ty->isVectorTy())
294 if (
op1Ty->isVectorTy())
299 return std::make_pair(
op1,
op2);
304 Type *
valTy = val->getType();
316 for (
unsigned i = 0;
i < 3; ++
i) {
327 std::vector<LLVM_VALUE> args;
328 args.reserve(
funcNode->numChildren());
336 std::vector<LLVM_VALUE>
ret;
337 for (
unsigned i = 0;
i < args.size(); ++
i)
348#if LLVM_VERSION_MAJOR >= 10
353 std::vector<LLVM_VALUE>
ret;
354 ret.reserve(args.size());
355 for (
auto & arg : args)
362 for (
auto & arg : args)
379 std::vector<LLVM_VALUE> args;
397 for (
unsigned j = 0;
j < 3; ++
j) {
423 args.insert(args.begin(),
retPtr);
432 std::vector<LLVM_VALUE> args;
439 std::string::size_type
pos = std::string::npos;
440 while ((
pos =
formatStr.find(
"%v")) != std::string::npos)
446 for (
int i = 1;
i <
seFunc->numChildren(); ++
i) {
448 if (arg->getType()->isVectorTy()) {
459 return ConstantFP::get(Type::getDoubleTy(
llvmContext), 0.0);
469 int nargs =
funcNode->numChildren();
470 assert(nargs == (
int)args.size());
482 for (
int i = 0;
i < nargs; ++
i) {
484 if (argType.
isFP()) {
489 assert(
false &&
"invalid type encountered");
519 if (argType.
isFP()) {
522 if (argType.
dim() > 1) {
523 for (
int comp = 0; comp < argType.
dim(); comp++) {
535 for (
int comp = 0; comp < promote; comp++) {
554 Module *
module = llvm_getModule(Builder);
561 Builder.CreateCall(
module->getFunction(
"KSeExprLLVMEvalCustomFunction"), {opDataArg, fpArg, strArg, dataGV, ConstantInt::get(int64Ty, reinterpret_cast<uint64_t>(funcNode))});
570 for (
unsigned int comp = 0; comp <
sizeOfRet; comp++) {
598 Type *
srcTy = val->getType();
599 if (
srcTy->isVectorTy() || dim <= 1)
663 Constant *
zero = ConstantFP::get(
op1->getType(), 0.0);
673 std::vector<LLVM_VALUE> ops = {
op1,
op2};
680 Module *
module = llvm_getModule(Builder);
682 Type *
i32Ty = Type::getInt32Ty(context);
716 assert(
false &&
"unexpected op");
727 const std::string &varName =
name();
730 Builder.CreateStore(val, varPtr);
759 assert(
false &&
"Unkown CompareEq op.");
765 Module *
module = llvm_getModule(Builder);
770 Constant *
zero = ConstantInt::get(
strcmp->getReturnType(), 0);
780 assert(
false &&
"Unkown CompareEq op.");
788 if (
_op ==
'&' ||
_op ==
'|') {
794 Constant *
zero = ConstantFP::get(
opTy, 0.0);
807 llvm::PHINode *
phiNode =
nullptr;
823 }
else if (
_op ==
'|') {
839 throw std::runtime_error(
"Logical inconsistency.");
848 Constant *
zero = ConstantFP::get(
opTy, 0.0);
875 assert(
false &&
"Unkown Compare op.");
887 ConstantFP::get(
condVal->getType(), 0.0));
959 for (
unsigned i = 0;
i < args.size(); ++
i) {
968 for (
unsigned i = 0;
i < args.size(); ++
i) {
970 Type *argType = args[
i]->getType();
971 if (argType->isVectorTy() &&
paramType->isDoubleTy()) {
983 std::vector<LLVM_VALUE>
ret;
1011 Constant *
zero = ConstantFP::get(
condTy, 0.0);
1032 std::vector<LLVM_VALUE>
phis;
1054 const std::string &name =
it.first;
1083 for (
auto &
AI :
F->args()) {
1114 auto *
AI =
F->arg_begin();
1134 if (
op1->getType()->isDoubleTy())
1147 Constant *
zero = ConstantFP::get(
op1Ty, 0.0);
1148 Constant *
one = ConstantFP::get(
op1Ty, 1.0);
1163 assert(
false &&
"not implemented.");
1180 int dim =
varRef->type().dim();
1212 llvm::Argument *indirectIndex = &*(
argIterator++);
1214 int dim =
varRef->type().dim();
1246 std::string varName(
"external_");
1247 varName.append(
name());
1253 return VarCodeGeneration::codegen(
_var, varName,
Builder);
1259 assert(varPtr &&
"can not found symbol?");
1270 std::vector<LLVM_VALUE>
elems;
1274 elems.push_back(val->getType()->isVectorTy() ?
Builder.CreateExtractElement(val,
zero) : val);
void KSeExprLLVMEvalFPVarRef(KSeExpr::ExprVarRef *seVR, double *result)
void KSeExprLLVMEvalStrVarRef(KSeExpr::ExprVarRef *seVR, double *result)
std::string unescapeString(const std::string &string)
const std::string & name() const
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
char _op
_op '<' less-than, 'l' less-than-eq, '>' greater-than, 'g' greater-than-eq
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that calls a function.
const char * name() const
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprLocalVar join (merge) references. Remembers which variables are possible assigners to this.
virtual LLVM_VALUE codegen(LLVM_BUILDER, const std::string &, LLVM_VALUE) LLVM_BASE
LLVM value that has been allocated.
virtual LLVM_VALUE varPtr()
LLVM value that has been pre-done.
ExprType type() const
returns type of the variable
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BASE
int numChildren() const
Number of children.
const ExprNode * child(size_t i) const
Get 0 indexed child.
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprType returnType() const
ExprType argType(int i) const
const std::string & name() const
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that stores a string.
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
bool isFP() const
Direct is predicate checks.
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
std::vector< std::pair< std::string, ExprLocalVarPhi * > > & merge(size_t index)
Node that references a variable.
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const char * name() const
abstract class for implementing variable references
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Internally implemented var ref used by SeExpr.
Vec()
Empty constructor (this is invalid for a reference type)
const ExprStrNode * isString(const ExprNode *testee)