25 assert(
V->getType()->isOpaquePointerTy() &&
26 "classifyPointerType called with non-opaque pointer");
27 auto It =
Map.find(V);
31 Type *PointeeTy =
nullptr;
32 if (
auto *Inst = dyn_cast<GetElementPtrInst>(V)) {
33 if (!Inst->getResultElementType()->isOpaquePointerTy())
34 PointeeTy = Inst->getResultElementType();
35 }
else if (
auto *Inst = dyn_cast<AllocaInst>(V)) {
36 PointeeTy = Inst->getAllocatedType();
37 }
else if (
auto *GV = dyn_cast<GlobalVariable>(V)) {
38 PointeeTy = GV->getValueType();
41 for (
const auto *
User :
V->users()) {
42 Type *NewPointeeTy =
nullptr;
43 if (
const auto *Inst = dyn_cast<LoadInst>(
User)) {
44 NewPointeeTy = Inst->getType();
45 }
else if (
const auto *Inst = dyn_cast<StoreInst>(
User)) {
46 NewPointeeTy = Inst->getValueOperand()->getType();
50 }
else if (
const auto *Inst = dyn_cast<GetElementPtrInst>(
User)) {
51 NewPointeeTy = Inst->getSourceElementType();
58 PointeeTy = classifyPointerType(
User, Map);
62 PointeeTy = NewPointeeTy;
63 else if (PointeeTy != NewPointeeTy)
81 auto It =
Map.find(&
F);
88 if (
RetTy->isOpaquePointerTy()) {
90 for (
const auto &
B :
F) {
91 const auto *RetInst = dyn_cast_or_null<ReturnInst>(
B.getTerminator());
95 Type *NewRetTy = classifyPointerType(RetInst->getReturnValue(), Map);
98 else if (
RetTy != NewRetTy)
107 for (
auto &
A :
F.args()) {
108 Type *ArgTy =
A.getType();
110 ArgTy = classifyPointerType(&
A, Map);
115 Map[&
F] = TypedPtrTy;
125 if (isa<ConstantPointerNull>(
C))
127 C->getType()->getPointerAddressSpace());
130 if (isa<ConstantData>(
C))
133 auto It = Map.find(
C);
137 if (
const auto *
F = dyn_cast<Function>(
C))
138 return classifyFunctionType(*
F, Map);
140 Type *Ty =
C->getType();
141 Type *TargetTy =
nullptr;
142 if (
auto *CS = dyn_cast<ConstantStruct>(
C)) {
144 for (
unsigned int I = 0;
I < CS->getNumOperands(); ++
I) {
145 const Constant *Elt =
C->getAggregateElement(
I);
150 }
else if (
auto *CA = dyn_cast<ConstantAggregate>(
C)) {
152 Type *TargetEltTy =
nullptr;
153 for (
auto &Elt : CA->operands()) {
155 assert(TargetEltTy == EltTy || TargetEltTy ==
nullptr);
159 if (
auto *AT = dyn_cast<ArrayType>(Ty)) {
160 TargetTy = ArrayType::get(TargetEltTy, AT->getNumElements());
163 auto *VT = cast<VectorType>(Ty);
164 TargetTy = VectorType::get(TargetEltTy, VT);
168 assert(TargetTy &&
"PointerTypeAnalyisis failed to identify target type");
191 for (
auto &
G : M.globals()) {
192 if (
G.getType()->isOpaquePointerTy())
193 classifyPointerType(&
G, Map);
194 if (
G.getName() ==
"llvm.global_ctors")
199 classifyFunctionType(
F, Map);
201 for (
const auto &
B :
F) {
202 for (
const auto &
I :
B) {
203 if (
I.getType()->isOpaquePointerTy())
204 classifyPointerType(&
I, Map);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Type * classifyConstantWithOpaquePtr(const Constant *C, PointerTypeMap &Map)
static void classifyGlobalCtorPointerType(const GlobalVariable &GV, PointerTypeMap &Map)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is an important base class in LLVM.
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 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.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isOpaquePointerTy() const
True if this is an instance of an opaque PointerType.
static 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.
@ C
The default llvm calling convention, compatible with C.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.