18
18
#include " llvm/IR/DerivedTypes.h"
19
19
#include " llvm/IR/Function.h"
20
20
#include " llvm/IR/Instruction.h"
21
+ #include " llvm/IR/Instructions.h"
21
22
#include " llvm/IR/Metadata.h"
22
23
#include " llvm/IR/Module.h"
24
+ #include " llvm/IR/Operator.h"
23
25
#include " llvm/IR/Type.h"
24
26
#include " llvm/IR/Use.h"
25
27
#include " llvm/IR/User.h"
@@ -34,22 +36,23 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
34
36
35
37
// Get types from global variables.
36
38
for (const auto &G : M.globals ()) {
37
- incorporateType (G.getType ());
39
+ incorporateType (G.getValueType ());
38
40
if (G.hasInitializer ())
39
41
incorporateValue (G.getInitializer ());
40
42
}
41
43
42
44
// Get types from aliases.
43
45
for (const auto &A : M.aliases ()) {
44
- incorporateType (A.getType ());
46
+ incorporateType (A.getValueType ());
45
47
if (const Value *Aliasee = A.getAliasee ())
46
48
incorporateValue (Aliasee);
47
49
}
48
50
49
51
// Get types from functions.
50
52
SmallVector<std::pair<unsigned , MDNode *>, 4 > MDForInst;
51
53
for (const Function &FI : M) {
52
- incorporateType (FI.getType ());
54
+ incorporateType (FI.getFunctionType ());
55
+ incorporateAttributes (FI.getAttributes ());
53
56
54
57
for (const Use &U : FI.operands ())
55
58
incorporateValue (U.get ());
@@ -69,6 +72,13 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
69
72
if (&*O && !isa<Instruction>(&*O))
70
73
incorporateValue (&*O);
71
74
75
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(&I))
76
+ incorporateType (GEP->getSourceElementType ());
77
+ if (auto *AI = dyn_cast<AllocaInst>(&I))
78
+ incorporateType (AI->getAllocatedType ());
79
+ if (const auto *CB = dyn_cast<CallBase>(&I))
80
+ incorporateAttributes (CB->getAttributes ());
81
+
72
82
// Incorporate types hiding in metadata.
73
83
I.getAllMetadataOtherThanDebugLoc (MDForInst);
74
84
for (const auto &MD : MDForInst)
@@ -138,6 +148,9 @@ void TypeFinder::incorporateValue(const Value *V) {
138
148
if (isa<Instruction>(V))
139
149
return ;
140
150
151
+ if (auto *GEP = dyn_cast<GEPOperator>(V))
152
+ incorporateType (GEP->getSourceElementType ());
153
+
141
154
// Look in operands for types.
142
155
const User *U = cast<User>(V);
143
156
for (const auto &I : U->operands ())
@@ -173,3 +186,13 @@ void TypeFinder::incorporateMDNode(const MDNode *V) {
173
186
}
174
187
}
175
188
}
189
+
190
+ void TypeFinder::incorporateAttributes (AttributeList AL) {
191
+ if (!VisitedAttributes.insert (AL).second )
192
+ return ;
193
+
194
+ for (AttributeSet AS : AL)
195
+ for (Attribute A : AS)
196
+ if (A.isTypeAttribute ())
197
+ incorporateType (A.getValueAsType ());
198
+ }
0 commit comments