35 OnlyNamed = onlyNamed;
38 for (
const auto &
G : M.globals()) {
39 incorporateType(
G.getValueType());
40 if (
G.hasInitializer())
41 incorporateValue(
G.getInitializer());
45 for (
const auto &
A : M.aliases()) {
46 incorporateType(
A.getValueType());
47 if (
const Value *Aliasee =
A.getAliasee())
48 incorporateValue(Aliasee);
52 for (
const auto &GI : M.ifuncs())
53 incorporateType(GI.getValueType());
58 incorporateType(FI.getFunctionType());
59 incorporateAttributes(FI.getAttributes());
61 for (
const Use &U : FI.operands())
62 incorporateValue(U.get());
65 for (
const auto &
A : FI.args())
71 incorporateType(
I.getType());
75 for (
const auto &O :
I.operands())
76 if (&*O && !isa<Instruction>(&*O))
77 incorporateValue(&*O);
79 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(&
I))
80 incorporateType(
GEP->getSourceElementType());
81 if (
auto *AI = dyn_cast<AllocaInst>(&
I))
82 incorporateType(AI->getAllocatedType());
83 if (
const auto *CB = dyn_cast<CallBase>(&
I))
84 incorporateAttributes(CB->getAttributes());
87 I.getAllMetadataOtherThanDebugLoc(MDForInst);
88 for (
const auto &MD : MDForInst)
89 incorporateMDNode(MD.second);
93 for (
const auto &Dbg :
I.getDbgRecordRange()) {
96 dyn_cast<DbgVariableRecord>(&Dbg)) {
97 for (
Value *V : DVI->location_ops())
99 if (DVI->isDbgAssign()) {
101 incorporateValue(
Addr);
108 for (
const auto &NMD : M.named_metadata())
109 for (
const auto *MDOp : NMD.operands())
110 incorporateMDNode(MDOp);
114 VisitedConstants.
clear();
115 VisitedTypes.clear();
121void TypeFinder::incorporateType(
Type *Ty) {
123 if (!VisitedTypes.insert(Ty).second)
132 if (
StructType *STy = dyn_cast<StructType>(Ty))
133 if (!OnlyNamed || STy->hasName())
134 StructTypes.push_back(STy);
138 if (VisitedTypes.insert(SubTy).second)
140 }
while (!TypeWorklist.
empty());
147void TypeFinder::incorporateValue(
const Value *V) {
148 if (
const auto *M = dyn_cast<MetadataAsValue>(V)) {
149 if (
const auto *
N = dyn_cast<MDNode>(
M->getMetadata()))
150 return incorporateMDNode(
N);
151 if (
const auto *MDV = dyn_cast<ValueAsMetadata>(
M->getMetadata()))
152 return incorporateValue(MDV->getValue());
153 if (
const auto *AL = dyn_cast<DIArgList>(
M->getMetadata())) {
154 for (
auto *Arg :
AL->getArgs())
155 incorporateValue(Arg->getValue());
161 if (!isa<Constant>(V) || isa<GlobalValue>(V))
return;
164 if (!VisitedConstants.
insert(V).second)
168 incorporateType(
V->getType());
171 if (isa<Instruction>(V))
174 if (
auto *
GEP = dyn_cast<GEPOperator>(V))
175 incorporateType(
GEP->getSourceElementType());
178 const User *
U = cast<User>(V);
179 for (
const auto &
I :
U->operands())
180 incorporateValue(&*
I);
185void TypeFinder::incorporateMDNode(
const MDNode *V) {
187 if (!VisitedMetadata.insert(V).second)
194 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
195 incorporateMDNode(
N);
198 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
Op)) {
199 incorporateValue(
C->getValue());
206 if (!VisitedAttributes.insert(AL).second)
211 if (
A.isTypeAttribute())
212 incorporateType(
A.getValueAsType());
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.
This class represents an Operation in the Expression.
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 run(const Module &M, bool onlyNamed)
The instances of the Type class are immutable: once they are created, they are never changed.
ArrayRef< Type * > subtypes() const
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
std::pair< iterator, bool > insert(const ValueT &V)
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)