41
41
#include " llvm/IRReader/IRReader.h"
42
42
#include " llvm/Support/Casting.h"
43
43
#include " llvm/Support/ErrorHandling.h"
44
+ #include " llvm/Support/ErrorOr.h"
44
45
#include " llvm/Support/SourceMgr.h"
45
46
#include " llvm/Support/raw_ostream.h"
46
47
#include " llvm/Transforms/Utils/ModuleUtils.h"
@@ -170,6 +171,8 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
170
171
auto *CS = cast<ConstantStruct>(Init);
171
172
172
173
// rtti
174
+ // Run-Time Type Information (RTTI) is a feature in C++ that allows the
175
+ // type of an object to be determined during program execution
173
176
Constant *OP0 = CS->getOperand (0 );
174
177
auto *OP0Cda = cast<ConstantDataArray>(OP0);
175
178
const char *RawRTTI = OP0Cda->getRawDataValues ().data ();
@@ -194,13 +197,10 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
194
197
195
198
// prog_fn
196
199
Constant *OP1 = CS->getOperand (1 );
197
- auto *OP1CE = cast<ConstantExpr>(OP1);
200
+ Function *Func = cast<Function>(OP1);
201
+ FunctionType *FuncType = Func->getFunctionType ();
198
202
199
- Type *OP1SrcTy = OP1CE->getOperand (0 )->getType ();
200
- Type *OP1PointeeT = OP1SrcTy->getNonOpaquePointerElementType ();
201
-
202
- FunctionType *ProgFuncTy = cast<FunctionType>(OP1PointeeT);
203
- Type *ProgSelfTy = ProgFuncTy->getParamType (0 );
203
+ Type *ProgSelfTy = FuncType->getParamType (0 );
204
204
205
205
SmallVector<Type *, 0 > CtxTys;
206
206
PointerType *CtxPT = StructType::get (C, CtxTys)->getPointerTo ();
@@ -215,18 +215,16 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
215
215
216
216
// name: &'a str
217
217
Constant *OP2 = CS->getOperand (2 );
218
- auto *OP2CE = cast<ConstantExpr>(OP2);
219
218
220
- Constant *ProgNameInit =
221
- cast<GlobalVariable>(OP2CE->getOperand (0 ))->getInitializer ();
219
+ Constant *ProgNameInit = cast<GlobalVariable>(OP2)->getInitializer ();
222
220
auto *ProgNameStruct = cast<ConstantStruct>(ProgNameInit);
223
221
auto *ProgNameCda =
224
222
cast<ConstantDataArray>(ProgNameStruct->getOperand (0 ));
225
223
std::string ProgName (ProgNameCda->getRawDataValues ().data (),
226
224
ProgNameCda->getType ()->getNumElements ());
227
225
228
226
// Add inserted program name metadata to backend pass
229
- if (auto *FunOP1 = dyn_cast<Function>(OP1CE-> getOperand ( 0 ) )) {
227
+ if (auto *FunOP1 = dyn_cast<Function>(Func )) {
230
228
StringRef UserProg = FunOP1->getName ();
231
229
Metadata *Str = MDString::get (Context, UserProg);
232
230
MDNode *Node = MDNode::get (Context, Str);
0 commit comments