17#include "ExprConfig.h"
19#ifdef SEEXPR_ENABLE_LLVM
75 if (
sft <= ExprFuncStandard::FUNC6) {
78 case ExprFuncStandard::FUNC6:
80 case ExprFuncStandard::FUNC5:
82 case ExprFuncStandard::FUNC4:
84 case ExprFuncStandard::FUNC3:
86 case ExprFuncStandard::FUNC2:
88 case ExprFuncStandard::FUNC1:
90 case ExprFuncStandard::FUNC0:
94 }
else if (
sft == ExprFuncStandard::FUNC1V) {
97 }
else if (
sft == ExprFuncStandard::FUNC2V) {
100 }
else if (
sft == ExprFuncStandard::FUNC1VV) {
103 }
else if (
sft == ExprFuncStandard::FUNC2VV) {
106 }
else if (
sft == ExprFuncStandard::FUNCN) {
109 }
else if (
sft == ExprFuncStandard::FUNCNV) {
112 }
else if (
sft == ExprFuncStandard::FUNCNVV) {
125 }
else if (
seType.isString()) {
130 assert(!
"unknown SeExpr type encountered");
139 for (
unsigned i = 0;
i < dim;
i++)
146 if (!val.size())
return 0;
149 unsigned dim = val.size();
152 for (
unsigned i = 0;
i < dim;
i++)
160 std::vector<LLVM_VALUE>
vals;
172 Type *
VTy =
V->getType();
173 if (
VTy->isDoubleTy())
return V;
182 Type *
srcTy = val->getType();
185 if (
destTy->isDoubleTy())
return val;
238 unsigned dim =
target->getType()->getVectorNumElements();
241 if (
op1Ty->isVectorTy())
246 return std::make_pair(
op1,
op2);
250 Type *
valTy = val->getType();
262 for (
unsigned i = 0;
i < 3; ++
i) {
272 std::vector<LLVM_VALUE> args;
278 std::vector<LLVM_VALUE>
ret;
279 for (
unsigned i = 0;
i < args.size(); ++
i)
284std::vector<LLVM_VALUE>
promoteArgs(std::vector<LLVM_VALUE> args,
291 std::vector<LLVM_VALUE>
ret;
297 for (
unsigned i = 0;
i < args.size(); ++
i)
314 std::vector<LLVM_VALUE> args;
332 for (
unsigned j = 0;
j < 3; ++
j) {
344 std::vector<LLVM_VALUE> args,
358 args.insert(args.begin(),
retPtr);
366 std::vector<LLVM_VALUE> args;
373 std::string::size_type
pos = std::string::npos;
379 for (
int i = 1;
i <
seFunc->numChildren(); ++
i) {
381 if (arg->getType()->isVectorTy()) {
392 return ConstantFP::get(Type::getDoubleTy(
llvmContext), 0.0);
401 int nargs =
funcNode->numChildren();
402 assert(nargs == (
int)args.size());
414 for (
int i = 0;
i < nargs; ++
i) {
416 if (argType.
isFP()) {
421 assert(
false &&
"invalid type encountered");
452 if (argType.
isFP()) {
455 if (argType.
dim() > 1) {
456 for (
int comp = 0; comp < argType.
dim(); comp++) {
468 for (
int comp = 0; comp < promote; comp++) {
487 Module*
module = llvm_getModule(Builder);
495 module->getFunction(
"SeExpr2LLVMEvalCustomFunction"),
501 ConstantInt::get(int64Ty, (uint64_t)funcNode)
512 for (
unsigned int comp = 0; comp <
sizeOfRet; comp++) {
533 Type *
srcTy = val->getType();
534 if (
srcTy->isVectorTy() || dim <= 1)
return val;
541 for (
int i = 0;
i < numChildren();
i++) child(
i)->codegen(
Builder);
570 const bool isString = child(0)->type().isString();
588 Constant *
zero = ConstantFP::get(
op1->getType(), 0.0);
598 std::vector<LLVM_VALUE> ops = {
op1,
op2};
605 Module *
module = llvm_getModule(Builder);
641 assert(
false &&
"unexpected op");
651 const std::string &varName = name();
654 Builder.CreateStore(val, varPtr);
677 assert(
false &&
"Unkown CompareEq op.");
684 if (_op ==
'&' || _op ==
'|') {
690 Constant *
zero = ConstantFP::get(
opTy, 0.0);
703 llvm::PHINode *
phiNode =
nullptr;
719 }
else if (_op ==
'|') {
735 throw std::runtime_error(
"Logical inconsistency.");
744 Constant *
zero = ConstantFP::get(
opTy, 0.0);
771 assert(
false &&
"Unkown Compare op.");
783 ConstantFP::get(
condVal->getType(), 0.0));
831 std::vector<LLVM_VALUE> args =
854 for (
unsigned i = 0;
i < args.size(); ++
i)
863 for (
unsigned i = 0;
i < args.size(); ++
i) {
865 Type *argType = args[
i]->getType();
866 if (argType->isVectorTy() &&
paramType->isDoubleTy()) {
878 std::vector<LLVM_VALUE>
ret;
905 Constant *
zero = ConstantFP::get(
condTy, 0.0);
925 const auto &
merges = _varEnv->merge(_varEnvMergeIndex);
926 std::vector<LLVM_VALUE>
phis;
947 for (
auto &
it : _varEnv->merge(_varEnvMergeIndex)) {
948 const std::string &name =
it.first;
976 Function::arg_iterator
AI =
F->arg_begin();
977 for (
int i = 0,
e =
F->arg_size();
i !=
e; ++
i, ++
AI) {
1004 auto AI =
F->arg_begin();
1005 for (
int i = 0,
e = numChildren();
i !=
e; ++
i, ++
AI) {
1022 if (
op1->getType()->isDoubleTy())
return op1;
1033 Constant *
zero = ConstantFP::get(
op1Ty, 0.0);
1034 Constant *
one = ConstantFP::get(
op1Ty, 1.0);
1049 assert(
false &&
"not implemented.");
1065 int dim =
varRef->type().dim();
1083 assert(dim == 3 &&
"future work.");
1101 llvm::Argument *indirectIndex = &*(
argIterator++);
1103 int dim =
varRef->type().dim();
1122 varRef->type().isLifetimeUniform()
1140 std::string varName(
"external_");
1141 varName.append(name());
1147 return VarCodeGeneration::codegen(_var, varName,
Builder);
1148 }
else if (_localVar) {
1153 assert(varPtr &&
"can not found symbol?");
1154 return Builder.CreateLoad(varPtr);
1163 std::vector<LLVM_VALUE>
elems;
1165 for (
int i = 0;
i < numChildren();
i++) {
1167 elems.push_back(val->getType()->isVectorTy() ?
Builder.CreateExtractElement(val,
zero) : val);
void SeExpr2LLVMEvalFPVarRef(SeExpr2::ExprVarRef *seVR, double *result)
void SeExpr2LLVMEvalStrVarRef(SeExpr2::ExprVarRef *seVR, double *result)
std::string unescapeString(const std::string &string)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that calls a function.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual 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 &name, LLVM_VALUE referenceType) LLVM_BODY
LLVM value that has been allocated.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that stores a string.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
bool isFP() const
Direct is predicate checks.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that references a variable.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
abstract class for implementing variable references
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Internally implemented var ref used by SeExpr.
you may not use this file except in compliance with the License and the following modification to it
const ExprStrNode * isString(const ExprNode *testee)
When fbmScale is zero(the default)
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
If a scalar is used in a vector context