12#define DEBUG_TYPE "bpf-aspace-simplify"
27 auto *OuterCast = dyn_cast<AddrSpaceCastInst>(
I);
33 auto *InnerCast = dyn_cast<AddrSpaceCastInst>(
GEP->getPointerOperand());
40 return CastGEPCast{OuterCast};
44 return Ty->get(Ty->getContext(), AS);
53 auto *InnerCast = cast<AddrSpaceCastInst>(
GEP->getPointerOperand());
55 auto *NewGEP = cast<GetElementPtrInst>(
GEP->clone());
56 NewGEP->setName(
GEP->getName());
57 NewGEP->insertAfter(OuterCast);
58 NewGEP->setOperand(0, InnerCast->getPointerOperand());
59 auto *GEPTy = cast<PointerType>(
GEP->getType());
60 NewGEP->mutateType(changeAddressSpace(GEPTy, AS));
64 GEP->eraseFromParent();
65 if (InnerCast->use_empty())
66 InnerCast->eraseFromParent();
79 if (
auto It = CastGEPCast::match(&
I))
81 Changed |= !WorkList.
empty();
83 while (!WorkList.
empty()) {
87 if (
auto It = CastGEPCast::match(U))
static bool rewrite(Function &F)
This class represents a conversion between pointers from one address space to another.
Value * getPointerOperand()
Gets the pointer operand.
unsigned getSrcAddressSpace() const
Returns the address space of the pointer operand.
unsigned getDestAddressSpace() const
Returns the address space of the result.
A container for analyses that lazily runs them and caches their results.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM Basic Block Representation.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
bool match(Val *V, const Pattern &P)
This is an optimization pass for GlobalISel generic memory operations.