30 assert(
V->getType()->isPointerTy() &&
31 "classifyPointerType called with non-pointer");
35 if (
const Function *
F = dyn_cast<Function>(V))
36 return classifyFunctionType(*
F, Map);
41 GV->removeDeadConstantUsers();
43 auto It =
Map.find(V);
47 Type *PointeeTy =
nullptr;
48 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
49 if (!
GEP->getResultElementType()->isPointerTy())
50 PointeeTy =
GEP->getResultElementType();
51 }
else if (
auto *Inst = dyn_cast<AllocaInst>(V)) {
52 PointeeTy = Inst->getAllocatedType();
53 }
else if (
auto *GV = dyn_cast<GlobalVariable>(V)) {
54 PointeeTy = GV->getValueType();
57 for (
const auto *
User :
V->users()) {
58 Type *NewPointeeTy =
nullptr;
59 if (
const auto *Inst = dyn_cast<LoadInst>(
User)) {
60 NewPointeeTy = Inst->getType();
61 }
else if (
const auto *Inst = dyn_cast<StoreInst>(
User)) {
62 NewPointeeTy = Inst->getValueOperand()->getType();
66 }
else if (
const auto *
GEP = dyn_cast<GEPOperator>(
User)) {
67 NewPointeeTy =
GEP->getSourceElementType();
74 PointeeTy = classifyPointerType(
User, Map);
78 PointeeTy = NewPointeeTy;
79 else if (PointeeTy != NewPointeeTy)
97 auto It =
Map.find(&
F);
104 if (
RetTy->isPointerTy()) {
106 for (
const auto &
B :
F) {
107 const auto *RetInst = dyn_cast_or_null<ReturnInst>(
B.getTerminator());
111 Type *NewRetTy = classifyPointerType(RetInst->getReturnValue(), Map);
114 else if (
RetTy != NewRetTy)
123 for (
auto &
A :
F.args()) {
124 Type *ArgTy =
A.getType();
126 ArgTy = classifyPointerType(&
A, Map);
131 Map[&
F] = TypedPtrTy;
141 if (isa<ConstantPointerNull>(
C))
143 C->getType()->getPointerAddressSpace());
146 if (isa<ConstantData>(
C))
149 auto It = Map.find(
C);
153 if (
const auto *
F = dyn_cast<Function>(
C))
154 return classifyFunctionType(*
F, Map);
156 Type *Ty =
C->getType();
157 Type *TargetTy =
nullptr;
158 if (
auto *CS = dyn_cast<ConstantStruct>(
C)) {
160 for (
unsigned int I = 0;
I < CS->getNumOperands(); ++
I) {
161 const Constant *Elt =
C->getAggregateElement(
I);
166 }
else if (
auto *CA = dyn_cast<ConstantAggregate>(
C)) {
168 Type *TargetEltTy =
nullptr;
169 for (
auto &Elt : CA->operands()) {
171 assert(TargetEltTy == EltTy || TargetEltTy ==
nullptr);
175 if (
auto *AT = dyn_cast<ArrayType>(Ty)) {
176 TargetTy = ArrayType::get(TargetEltTy, AT->getNumElements());
179 auto *VT = cast<VectorType>(Ty);
180 TargetTy = VectorType::get(TargetEltTy, VT);
184 assert(TargetTy &&
"PointerTypeAnalyisis failed to identify target type");
207 for (
auto &
G : M.globals()) {
208 if (
G.getType()->isPointerTy())
209 classifyPointerType(&
G, Map);
210 if (
G.getName() ==
"llvm.global_ctors")
215 classifyFunctionType(
F, Map);
217 for (
const auto &
B :
F) {
218 for (
const auto &
I :
B) {
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);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
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 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.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
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 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.