46 auto *IntC = ConstantInt::get(Type::getInt64Ty(Ctx), RC.
Value.
Int64Val);
47 return ConstantExpr::getIntToPtr(IntC, ArgType);
50 std::string TypeString;
51 raw_string_ostream TypeOstream(TypeString);
52 ArgType->print(TypeOstream);
61 findArgByOffset(
const SmallVector<RuntimeConstant> &RCVec, int32_t Offset) {
62 for (
auto &Arg : RCVec) {
63 if (Arg.Offset == Offset)
70 findArgByPos(
const SmallVector<RuntimeConstant> &RCVec, int32_t
Pos) {
71 for (
auto &Arg : RCVec) {
78 static auto traceOut(
int Slot, Constant *C) {
80 raw_svector_ostream OS(S);
81 OS <<
"[LambdaSpec] Replacing slot " << Slot <<
" with " << *C <<
"\n";
86 static void handleLoad(Module &M, User *User,
87 const SmallVector<RuntimeConstant> &RCVec) {
88 auto *Arg = findArgByPos(RCVec, 0);
92 Constant *C =
getConstant(M.getContext(), User->getType(), *Arg);
93 User->replaceAllUsesWith(C);
99 static void handleGEP(Module &M, GetElementPtrInst *GEP, User *User,
100 const SmallVector<RuntimeConstant> &RCVec) {
101 auto *GEPSlot = GEP->getOperand(User->getNumOperands() - 1);
102 ConstantInt *CI = dyn_cast<ConstantInt>(GEPSlot);
103 int Slot = CI->getZExtValue();
104 Type *SrcTy = GEP->getSourceElementType();
106 auto *Arg = SrcTy->isStructTy() ? findArgByPos(RCVec, Slot)
107 : findArgByOffset(RCVec, Slot);
111 for (
auto *GEPUser : GEP->users()) {
112 auto *LI = dyn_cast<LoadInst>(GEPUser);
115 Type *LoadType = LI->getType();
116 Constant *C =
getConstant(M.getContext(), LoadType, *Arg);
117 LI->replaceAllUsesWith(C);
126 const SmallVector<RuntimeConstant> &RCVec) {
127 auto *LambdaClass = F.getArg(0);
129 <<
"[LambdaSpec] Function: " << F.getName() <<
" RCVec size "
130 << RCVec.size() <<
"\n");
132 <<
"TransformLambdaSpecialization::transform" <<
"\n");
134#if PROTEUS_ENABLE_DEBUG
135 for (
auto &Arg : RCVec) {
137 <<
"{" << Arg.Value.Int64Val <<
", " << Arg.Pos <<
" }\n";
142 for (User *User : LambdaClass->users()) {
144 if (isa<LoadInst>(User))
145 handleLoad(M, User, RCVec);
146 else if (
auto *GEP = dyn_cast<GetElementPtrInst>(User))
147 handleGEP(M, GEP, User, RCVec);
Constant * getConstant(LLVMContext &Ctx, Type *ArgType, const RuntimeConstant &RC)
Definition TransformLambdaSpecialization.hpp:28