LLVM: lib/IR/TypeFinder.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

30#include

31

32using namespace llvm;

33

35 OnlyNamed = onlyNamed;

36

37

38 for (const auto &G : M.globals()) {

39 incorporateType(G.getValueType());

40 if (G.hasInitializer())

41 incorporateValue(G.getInitializer());

42 }

43

44

45 for (const auto &A : M.aliases()) {

46 incorporateType(A.getValueType());

47 if (const Value *Aliasee = A.getAliasee())

48 incorporateValue(Aliasee);

49 }

50

51

52 for (const auto &GI : M.ifuncs())

53 incorporateType(GI.getValueType());

54

55

57 for (const Function &FI : M) {

58 incorporateType(FI.getFunctionType());

59 incorporateAttributes(FI.getAttributes());

60

61 for (const Use &U : FI.operands())

62 incorporateValue(U.get());

63

64

65 for (const auto &A : FI.args())

66 incorporateValue(&A);

67

70

71 incorporateType(I.getType());

72

73

74

75 for (const auto &O : I.operands())

77 incorporateValue(&*O);

78

80 incorporateType(GEP->getSourceElementType());

82 incorporateType(AI->getAllocatedType());

84 incorporateAttributes(CB->getAttributes());

85

86

87 I.getAllMetadataOtherThanDebugLoc(MDForInst);

88 for (const auto &MD : MDForInst)

89 incorporateMDNode(MD.second);

90 MDForInst.clear();

91

92

93 for (const auto &Dbg : I.getDbgRecordRange()) {

94

97 for (Value *V : DVI->location_ops())

98 incorporateValue(V);

99 if (DVI->isDbgAssign()) {

100 if (Value *Addr = DVI->getAddress())

101 incorporateValue(Addr);

102 }

103 }

104 }

105 }

106 }

107

108 for (const auto &NMD : M.named_metadata())

109 for (const auto *MDOp : NMD.operands())

110 incorporateMDNode(MDOp);

111}

112

114 VisitedConstants.clear();

115 VisitedTypes.clear();

116 StructTypes.clear();

117}

118

119

120

121void TypeFinder::incorporateType(Type *Ty) {

122

123 if (!VisitedTypes.insert(Ty).second)

124 return;

125

128 do {

130

131

133 if (!OnlyNamed || STy->hasName())

134 StructTypes.push_back(STy);

135

136

138 if (VisitedTypes.insert(SubTy).second)

140 } while (!TypeWorklist.empty());

141}

142

143

144

145

146

147void TypeFinder::incorporateValue(const Value *V) {

150 return incorporateMDNode(N);

152 return incorporateValue(MDV->getValue());

154 for (auto *Arg : AL->getArgs())

155 incorporateValue(Arg->getValue());

156 return;

157 }

158 return;

159 }

160

162

163

164 if (!VisitedConstants.insert(V).second)

165 return;

166

167

168 incorporateType(V->getType());

169

170

172 return;

173

175 incorporateType(GEP->getSourceElementType());

176

177

179 for (const auto &I : U->operands())

180 incorporateValue(&*I);

181}

182

183

184

185void TypeFinder::incorporateMDNode(const MDNode *V) {

186

187 if (!VisitedMetadata.insert(V).second)

188 return;

189

190

192 if (Op)

193 continue;

195 incorporateMDNode(N);

196 continue;

197 }

199 incorporateValue(C->getValue());

200 continue;

201 }

202 }

203}

204

205void TypeFinder::incorporateAttributes(AttributeList AL) {

206 if (!VisitedAttributes.insert(AL).second)

207 return;

208

209 for (AttributeSet AS : AL)

211 if (A.isTypeAttribute())

212 incorporateType(A.getValueAsType());

213}

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

Module.h This file contains the declarations for the Module class.

This defines the Use class.

This file defines the SmallVector class.

LLVM Basic Block Representation.

Record of a variable value-assignment, aka a non instruction representation of the dbg....

A Module instance is used to store all the information related to an LLVM module.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Class to represent struct types.

void clear()

Definition TypeFinder.cpp:113

void run(const Module &M, bool onlyNamed)

Definition TypeFinder.cpp:34

The instances of the Type class are immutable: once they are created, they are never changed.

A Use represents the edge between a Value definition and its users.

LLVM Value Representation.

@ C

The default llvm calling convention, compatible with C.

@ User

could "use" a pointer

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

auto reverse(ContainerTy &&C)

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

DWARFExpression::Operation Op

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.