11#ifndef PROTEUS_TRANSFORM_ARGUMENT_SPECIALIZATION_HPP
12#define PROTEUS_TRANSFORM_ARGUMENT_SPECIALIZATION_HPP
14#include <llvm/IR/IRBuilder.h>
15#include <llvm/Support/Debug.h>
31 T *TypedPtr =
reinterpret_cast<T *
>(RC.
ArrInfo.
Blob.get());
39 static Constant *createConstantDataArray(Module &M,
44 return ConstantDataArray::get(M.getContext(), createArrayRef<bool>(RC));
46 return ConstantDataArray::get(M.getContext(), createArrayRef<int8_t>(RC));
48 return ConstantDataArray::get(M.getContext(),
49 createArrayRef<int32_t>(RC));
51 return ConstantDataArray::get(M.getContext(),
52 createArrayRef<int64_t>(RC));
54 return ConstantDataArray::get(M.getContext(), createArrayRef<float>(RC));
56 return ConstantDataArray::get(M.getContext(), createArrayRef<double>(RC));
63 static Constant *createConstantDataVector(Module &M,
68 return ConstantDataVector::get(M.getContext(),
69 createArrayRef<uint8_t>(RC));
71 return ConstantDataVector::get(M.getContext(),
72 createArrayRef<uint32_t>(RC));
74 return ConstantDataVector::get(M.getContext(),
75 createArrayRef<uint64_t>(RC));
77 return ConstantDataVector::get(M.getContext(), createArrayRef<float>(RC));
79 return ConstantDataVector::get(M.getContext(),
80 createArrayRef<double>(RC));
89 ArrayRef<RuntimeConstant> RCArray) {
90 auto &Ctx = M.getContext();
93 for (
const auto &RC : RCArray) {
95 Argument *Arg = F.getArg(ArgNo);
96 Type *ArgType = Arg->getType();
97 Constant *C =
nullptr;
133 auto *IntC = ConstantInt::get(Type::getInt64Ty(Ctx), RC.
Value.
Int64Val);
134 C = ConstantExpr::getIntToPtr(IntC, ArgType);
138 Constant *CDA = createConstantDataArray(M, RC);
140 GlobalVariable *GV =
new GlobalVariable(
141 M, CDA->getType(),
true, GlobalValue::PrivateLinkage, CDA);
144 C = ConstantExpr::getBitCast(GV, ArgType);
148 C = createConstantDataArray(M, RC);
152 C = createConstantDataVector(M, RC);
156 Constant *CDA = ConstantDataArray::getRaw(
157 StringRef{
reinterpret_cast<const char *
>(RC.
ObjInfo.
Blob.get()),
161 GlobalVariable *GV =
new GlobalVariable(
162 M, CDA->getType(),
true, GlobalValue::PrivateLinkage, CDA);
165 C = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, ArgType);
169 std::string TypeString;
170 raw_string_ostream TypeOstream(TypeString);
171 ArgType->print(TypeOstream);
177 auto TraceOut = [](Function &F,
int ArgNo, Constant *C) {
179 raw_svector_ostream OS(S);
180 OS <<
"[ArgSpec] Replaced Function " << F.getName() <<
" ArgNo "
181 << ArgNo <<
" with value " << *C->stripPointerCasts() <<
"\n";
189 Arg->replaceAllUsesWith(C);
#define PROTEUS_DBG(x)
Definition Debug.h:10
#define PROTEUS_FATAL_ERROR(x)
Definition Error.h:7
static Config & get()
Definition Config.hpp:114
static void trace(llvm::StringRef Msg)
Definition Logger.hpp:30
static llvm::raw_ostream & logs(const std::string &Name)
Definition Logger.hpp:19
Definition CppJitModule.cpp:21
@ ARRAY
Definition CompilerInterfaceTypes.h:33
@ VECTOR
Definition CompilerInterfaceTypes.h:32
@ INT32
Definition CompilerInterfaceTypes.h:25
@ INT64
Definition CompilerInterfaceTypes.h:26
@ FLOAT
Definition CompilerInterfaceTypes.h:27
@ STATIC_ARRAY
Definition CompilerInterfaceTypes.h:31
@ LONG_DOUBLE
Definition CompilerInterfaceTypes.h:29
@ INT8
Definition CompilerInterfaceTypes.h:24
@ BOOL
Definition CompilerInterfaceTypes.h:23
@ OBJECT
Definition CompilerInterfaceTypes.h:34
@ PTR
Definition CompilerInterfaceTypes.h:30
@ DOUBLE
Definition CompilerInterfaceTypes.h:28
std::string toString(CodegenOption Option)
Definition Config.hpp:23
int32_t NumElts
Definition CompilerInterfaceTypes.h:42
RuntimeConstantType EltType
Definition CompilerInterfaceTypes.h:43
std::shared_ptr< unsigned char[]> Blob
Definition CompilerInterfaceTypes.h:44
std::shared_ptr< unsigned char[]> Blob
Definition CompilerInterfaceTypes.h:53
int32_t Size
Definition CompilerInterfaceTypes.h:51
Definition CompilerInterfaceTypes.h:72
ArrayInfo ArrInfo
Definition CompilerInterfaceTypes.h:78
RuntimeConstantValue Value
Definition CompilerInterfaceTypes.h:73
RuntimeConstantType Type
Definition CompilerInterfaceTypes.h:74
ObjectInfo ObjInfo
Definition CompilerInterfaceTypes.h:79
int32_t Pos
Definition CompilerInterfaceTypes.h:75
double DoubleVal
Definition CompilerInterfaceTypes.h:65
int64_t Int64Val
Definition CompilerInterfaceTypes.h:63
bool BoolVal
Definition CompilerInterfaceTypes.h:60
int8_t Int8Val
Definition CompilerInterfaceTypes.h:61
int32_t Int32Val
Definition CompilerInterfaceTypes.h:62
float FloatVal
Definition CompilerInterfaceTypes.h:64
long double LongDoubleVal
Definition CompilerInterfaceTypes.h:66