LLVM: lib/Target/BPF/BPFASpaceCastSimplifyPass.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10#include

11

12#define DEBUG_TYPE "bpf-aspace-simplify"

13

14using namespace llvm;

15

16namespace {

17

18struct CastGEPCast {

20

21

22

23

24

25

26 static std::optional match(Value *I) {

28 if (!OuterCast)

29 return std::nullopt;

32 return std::nullopt;

34 if (!InnerCast)

35 return std::nullopt;

37 return std::nullopt;

38 if (InnerCast->getDestAddressSpace() != OuterCast->getSrcAddressSpace())

39 return std::nullopt;

40 return CastGEPCast{OuterCast};

41 }

42

44 return Ty->get(Ty->getContext(), AS);

45 }

46

47

48

49

50

56 NewGEP->setName(GEP->getName());

57 NewGEP->insertAfter(OuterCast->getIterator());

58 NewGEP->setOperand(0, InnerCast->getPointerOperand());

60 NewGEP->mutateType(changeAddressSpace(GEPTy, AS));

63 if (GEP->use_empty())

64 GEP->eraseFromParent();

65 if (InnerCast->use_empty())

66 InnerCast->eraseFromParent();

67 return NewGEP;

68 }

69};

70

71}

72

79 if (auto It = CastGEPCast::match(&I))

82

83 while (!WorkList.empty()) {

84 CastGEPCast InsnChain = WorkList.pop_back_val();

87 if (auto It = CastGEPCast::match(U))

89 }

90 }

92}

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.

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)

Definition BPFASpaceCastSimplifyPass.cpp:73

LLVM Basic Block Representation.

an instruction for type-safe pointer arithmetic to access elements of arrays and structs

LLVM_ABI 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.

LLVM_ABI void replaceAllUsesWith(Value *V)

Change all uses of this to point to a new Value.

iterator_range< user_iterator > users()

self_iterator getIterator()

bool match(Val *V, const Pattern &P)

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.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.