28 ArrayRef<RuntimeConstant> RCArray) {
29 auto &Ctx = M.getContext();
32 for (
const auto &RC : RCArray) {
34 Value *Arg = F.getArg(ArgNo);
35 Type *ArgType = Arg->getType();
36 Constant *C =
nullptr;
38 if (ArgType->isIntegerTy(1)) {
39 C = ConstantInt::get(ArgType, RC.Value.BoolVal);
40 }
else if (ArgType->isIntegerTy(8)) {
41 C = ConstantInt::get(ArgType, RC.Value.Int8Val);
42 }
else if (ArgType->isIntegerTy(32)) {
44 C = ConstantInt::get(ArgType, RC.Value.Int32Val);
45 }
else if (ArgType->isIntegerTy(64)) {
47 C = ConstantInt::get(ArgType, RC.Value.Int64Val);
48 }
else if (ArgType->isFloatTy()) {
50 C = ConstantFP::get(ArgType, RC.Value.FloatVal);
51 }
else if (ArgType->isDoubleTy()) {
56 C = ConstantFP::get(ArgType, RC.Value.LongDoubleVal);
58 C = ConstantFP::get(ArgType, RC.Value.DoubleVal);
59 }
else if (ArgType->isX86_FP80Ty() || ArgType->isPPC_FP128Ty() ||
60 ArgType->isFP128Ty()) {
61 C = ConstantFP::get(ArgType, RC.Value.LongDoubleVal);
62 }
else if (ArgType->isPointerTy()) {
63 auto *IntC = ConstantInt::get(Type::getInt64Ty(Ctx), RC.Value.Int64Val);
64 C = ConstantExpr::getIntToPtr(IntC, ArgType);
66 std::string TypeString;
67 raw_string_ostream TypeOstream(TypeString);
68 ArgType->print(TypeOstream);
73 auto TraceOut = [](Function &F,
int ArgNo, Constant *C) {
75 raw_svector_ostream OS(S);
76 OS <<
"[ArgSpec] Replaced Function " << F.getName() <<
" ArgNo "
77 << ArgNo <<
" with value " << *C <<
"\n";
85 Arg->replaceAllUsesWith(C);