47 auto *IntC = ConstantInt::get(Type::getInt64Ty(Ctx), RC.
Value.
Int64Val);
48 return ConstantExpr::getIntToPtr(IntC, ArgType);
51 std::string TypeString;
52 raw_string_ostream TypeOstream(TypeString);
53 ArgType->print(TypeOstream);
62 findArgByOffset(
const SmallVector<RuntimeConstant> &RCVec, int32_t
Offset) {
63 for (
auto &Arg : RCVec) {
71 findArgByPos(
const SmallVector<RuntimeConstant> &RCVec, int32_t
Pos) {
72 for (
auto &Arg : RCVec) {
79 static auto traceOut(
int Slot, Constant *C) {
81 raw_svector_ostream OS(S);
82 OS <<
"[LambdaSpec] Replacing slot " << Slot <<
" with " << *C <<
"\n";
87 static void handleLoad(Module &M, User *User,
88 const SmallVector<RuntimeConstant> &RCVec) {
89 auto *Arg = findArgByPos(RCVec, 0);
93 Constant *C =
getConstant(M.getContext(), User->getType(), *Arg);
94 User->replaceAllUsesWith(C);
100 static void handleGEP(Module &M, GetElementPtrInst *GEP, User *User,
101 const SmallVector<RuntimeConstant> &RCVec) {
102 auto *GEPSlot = GEP->getOperand(User->getNumOperands() - 1);
103 ConstantInt *CI = dyn_cast<ConstantInt>(GEPSlot);
104 int Slot = CI->getZExtValue();
105 Type *SrcTy = GEP->getSourceElementType();
107 auto *Arg = SrcTy->isStructTy() ? findArgByPos(RCVec, Slot)
108 : findArgByOffset(RCVec, Slot);
112 for (
auto *GEPUser : GEP->users()) {
113 auto *LI = dyn_cast<LoadInst>(GEPUser);
116 Type *LoadType = LI->getType();
117 Constant *C =
getConstant(M.getContext(), LoadType, *Arg);
118 LI->replaceAllUsesWith(C);
127 const SmallVector<RuntimeConstant> &RCVec) {
128 auto *LambdaClass = F.getArg(0);
130 <<
"[LambdaSpec] Function: " << F.getName() <<
" RCVec size "
131 << RCVec.size() <<
"\n");
133 <<
"TransformLambdaSpecialization::transform" <<
"\n");
136 for (
auto &Arg : RCVec) {
138 <<
"{" << Arg.Value.Int64Val <<
", " << Arg.Pos <<
" }\n";
143 for (User *User : LambdaClass->users()) {
145 if (isa<LoadInst>(User))
146 handleLoad(M, User, RCVec);
147 else if (
auto *GEP = dyn_cast<GetElementPtrInst>(User))
148 handleGEP(M, GEP, User, RCVec);
Constant * getConstant(LLVMContext &Ctx, Type *ArgType, const RuntimeConstant &RC)
Definition TransformLambdaSpecialization.h:29