27 assert(
V->getType()->isPointerTy() &&
28 "classifyPointerType called with non-pointer");
29 auto It =
Map.find(V);
33 Type *PointeeTy =
nullptr;
34 if (
auto *Inst = dyn_cast<GetElementPtrInst>(V)) {
35 if (!Inst->getResultElementType()->isPointerTy())
36 PointeeTy = Inst->getResultElementType();
37 }
else if (
auto *Inst = dyn_cast<AllocaInst>(V)) {
38 PointeeTy = Inst->getAllocatedType();
39 }
else if (
auto *GV = dyn_cast<GlobalVariable>(V)) {
40 PointeeTy = GV->getValueType();
43 for (
const auto *
User :
V->users()) {
44 Type *NewPointeeTy =
nullptr;
45 if (
const auto *Inst = dyn_cast<LoadInst>(
User)) {
46 NewPointeeTy = Inst->getType();
47 }
else if (
const auto *Inst = dyn_cast<StoreInst>(
User)) {
48 NewPointeeTy = Inst->getValueOperand()->getType();
52 }
else if (
const auto *Inst = dyn_cast<GetElementPtrInst>(
User)) {
53 NewPointeeTy = Inst->getSourceElementType();
60 PointeeTy = classifyPointerType(
User, Map);
64 PointeeTy = NewPointeeTy;
65 else if (PointeeTy != NewPointeeTy)
83 auto It =
Map.find(&
F);
90 if (
RetTy->isPointerTy()) {
92 for (
const auto &
B :
F) {
93 const auto *RetInst = dyn_cast_or_null<ReturnInst>(
B.getTerminator());
97 Type *NewRetTy = classifyPointerType(RetInst->getReturnValue(), Map);
100 else if (
RetTy != NewRetTy)
109 for (
auto &
A :
F.args()) {
110 Type *ArgTy =
A.getType();
112 ArgTy = classifyPointerType(&
A, Map);
117 Map[&
F] = TypedPtrTy;
127 if (isa<ConstantPointerNull>(
C))
129 C->getType()->getPointerAddressSpace());
132 if (isa<ConstantData>(
C))
135 auto It = Map.find(
C);
139 if (
const auto *
F = dyn_cast<Function>(
C))
140 return classifyFunctionType(*
F, Map);
142 Type *Ty =
C->getType();
143 Type *TargetTy =
nullptr;
144 if (
auto *CS = dyn_cast<ConstantStruct>(
C)) {
146 for (
unsigned int I = 0;
I < CS->getNumOperands(); ++
I) {
147 const Constant *Elt =
C->getAggregateElement(
I);
152 }
else if (
auto *CA = dyn_cast<ConstantAggregate>(
C)) {
154 Type *TargetEltTy =
nullptr;
155 for (
auto &Elt : CA->operands()) {
157 assert(TargetEltTy == EltTy || TargetEltTy ==
nullptr);
161 if (
auto *AT = dyn_cast<ArrayType>(Ty)) {
162 TargetTy = ArrayType::get(TargetEltTy, AT->getNumElements());
165 auto *VT = cast<VectorType>(Ty);
166 TargetTy = VectorType::get(TargetEltTy, VT);
170 assert(TargetTy &&
"PointerTypeAnalyisis failed to identify target type");
193 for (
auto &
G : M.globals()) {
194 if (
G.getType()->isPointerTy())
195 classifyPointerType(&
G, Map);
196 if (
G.getName() ==
"llvm.global_ctors")
201 classifyFunctionType(
F, Map);
203 for (
const auto &
B :
F) {
204 for (
const auto &
I :
B) {
205 if (
I.getType()->isPointerTy())
206 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...
Module.h This file contains the declarations for the Module class.
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.
bool isPointerTy() const
True if this is an instance of PointerType.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static IntegerType * getInt8Ty(LLVMContext &C)
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.