LLVM: lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
19
20using namespace llvm;
22
23namespace {
24
26
27
28
30 assert(V->getType()->isPointerTy() &&
31 "classifyPointerType called with non-pointer");
32
33
34
36 return classifyFunctionType(*F, Map);
37
38
39
41 GV->removeDeadConstantUsers();
42
43 auto It = Map.find(V);
44 if (It != Map.end())
45 return It->second;
46
47 Type *PointeeTy = nullptr;
49 if (->getResultElementType()->isPointerTy())
50 PointeeTy = GEP->getResultElementType();
52 PointeeTy = Inst->getAllocatedType();
54 PointeeTy = GV->getValueType();
55 }
56
57 for (const auto *User : V->users()) {
58 Type *NewPointeeTy = nullptr;
60 NewPointeeTy = Inst->getType();
62 NewPointeeTy = Inst->getValueOperand()->getType();
63
65 continue;
67 NewPointeeTy = GEP->getSourceElementType();
68 }
69 if (NewPointeeTy) {
70
71
72
74 PointeeTy = classifyPointerType(User, Map);
75 break;
76 }
77 if (!PointeeTy)
78 PointeeTy = NewPointeeTy;
79 else if (PointeeTy != NewPointeeTy)
81 }
82 }
83
84 if (!PointeeTy)
86 auto *TypedPtrTy =
88
89 Map[V] = TypedPtrTy;
90 return TypedPtrTy;
91}
92
93
94
95
98 if (It != Map.end())
99 return It->second;
100
102 Type *RetTy = F.getReturnType();
105 RetTy = nullptr;
108 if (!RetInst)
109 continue;
110
111 Type *NewRetTy = classifyPointerType(RetInst->getReturnValue(), Map);
112 if (!RetTy)
113 RetTy = NewRetTy;
114 else if (RetTy != NewRetTy)
116 Type::getInt8Ty(Ctx), F.getReturnType()->getPointerAddressSpace());
117 }
118
119 if (!RetTy)
121 Type::getInt8Ty(Ctx), F.getReturnType()->getPointerAddressSpace());
122 }
123 for (auto &A : F.args()) {
124 Type *ArgTy = A.getType();
126 ArgTy = classifyPointerType(&A, Map);
128 }
129 auto *TypedPtrTy =
132 return TypedPtrTy;
133}
134}
135
138
139
140
143 C->getType()->getPointerAddressSpace());
144
145
147 return C->getType();
148
149 auto It = Map.find(C);
150 if (It != Map.end())
151 return It->second;
152
154 return classifyFunctionType(*F, Map);
155
157 Type *TargetTy = nullptr;
160 for (unsigned int I = 0; I < CS->getNumOperands(); ++I) {
161 const Constant *Elt = C->getAggregateElement(I);
164 }
167
168 Type *TargetEltTy = nullptr;
169 for (auto &Elt : CA->operands()) {
171 assert(TargetEltTy == EltTy || TargetEltTy == nullptr);
172 TargetEltTy = EltTy;
173 }
174
176 TargetTy = ArrayType::get(TargetEltTy, AT->getNumElements());
177 } else {
178
181 }
182 }
183
184 assert(TargetTy && "PointerTypeAnalyisis failed to identify target type");
185
186
187 if (TargetTy == Ty)
188 return Ty;
189
190 Map[C] = TargetTy;
191 return TargetTy;
192}
193
204
207 for (auto &G : M.globals()) {
208 if (G.getType()->isPointerTy())
209 classifyPointerType(&G, Map);
210 if (G.getName() == "llvm.global_ctors")
212 }
213
214 for (auto &F : M) {
215 classifyFunctionType(F, Map);
216
219 if (I.getType()->isPointerTy())
220 classifyPointerType(&I, Map);
221 for (const auto &O : I.operands())
222 if (O.get()->getType()->isPointerTy())
223 classifyPointerType(O.get(), Map);
224 }
225 }
226 }
227 return Map;
228}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
static Type * classifyConstantWithOpaquePtr(const Constant *C, PointerTypeMap &Map)
Definition PointerTypeAnalysis.cpp:136
static void classifyGlobalCtorPointerType(const GlobalVariable &GV, PointerTypeMap &Map)
Definition PointerTypeAnalysis.cpp:194
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
This is an important base class in LLVM.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
PointerType * getType() const
Global values are always pointers.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
static LLVM_ABI TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
LLVM Value Representation.
iterator_range< user_iterator > users()
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
@ C
The default llvm calling convention, compatible with C.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Definition PointerTypeAnalysis.cpp:205
DenseMap< const Value *, Type * > PointerTypeMap
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 dyn_cast_or_null(const Y &Val)
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.