LLVM: lib/Target/AMDGPU/AMDGPUPromoteKernelArguments.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

25

26#define DEBUG_TYPE "amdgpu-promote-kernel-arguments"

27

28using namespace llvm;

29

30namespace {

31

32class AMDGPUPromoteKernelArguments : public FunctionPass {

34

36

38

40

41 void enqueueUsers(Value *Ptr);

42

43 bool promotePointer(Value *Ptr);

44

45 bool promoteLoad(LoadInst *LI);

46

47public:

48 static char ID;

49

51

53

55

56 void getAnalysisUsage(AnalysisUsage &AU) const override {

60 }

61};

62

63}

64

65void AMDGPUPromoteKernelArguments::enqueueUsers(Value *Ptr) {

67

68 while (!PtrUsers.empty()) {

70 if (!U)

71 continue;

72

73 switch (U->getOpcode()) {

74 default:

75 break;

76 case Instruction::Load: {

78 if (LD->getPointerOperand()->stripInBoundsOffsets() == Ptr &&

80 Ptrs.push_back(LD);

81

82 break;

83 }

84 case Instruction::GetElementPtr:

85 case Instruction::AddrSpaceCast:

86 case Instruction::BitCast:

87 if (U->getOperand(0)->stripInBoundsOffsets() == Ptr)

88 PtrUsers.append(U->user_begin(), U->user_end());

89 break;

90 }

91 }

92}

93

94bool AMDGPUPromoteKernelArguments::promotePointer(Value *Ptr) {

96

98 if (LI)

99 Changed |= promoteLoad(LI);

100

102 if (!PT)

104

108 enqueueUsers(Ptr);

109

112

114 : ArgCastInsertPt);

115

116

117

121 B.CreateAddrSpaceCast(Ptr, NewPT, Twine(Ptr->getName(), ".global"));

122 Value *CastBack =

123 B.CreateAddrSpaceCast(Cast, PT, Twine(Ptr->getName(), ".flat"));

125 [Cast](Use &U) { return U.getUser() != Cast; });

126

127 return true;

128}

129

130bool AMDGPUPromoteKernelArguments::promoteLoad(LoadInst *LI) {

132 return false;

133

135 return true;

136}

137

138

143

144

145

147 break;

148 }

149

150 return InsPt;

151}

152

153bool AMDGPUPromoteKernelArguments::run(Function &F, MemorySSA &MSSA,

155 if (skipFunction(F))

156 return false;

157

158 CallingConv::ID CC = F.getCallingConv();

159 if (CC != CallingConv::AMDGPU_KERNEL || F.arg_empty())

160 return false;

161

163 this->MSSA = &MSSA;

164 this->AA = &AA;

165

166 for (Argument &Arg : F.args()) {

167 if (Arg.use_empty())

168 continue;

169

174 continue;

175

176 Ptrs.push_back(&Arg);

177 }

178

180 while (!Ptrs.empty()) {

181 Value *Ptr = Ptrs.pop_back_val();

182 Changed |= promotePointer(Ptr);

183 }

184

186}

187

188bool AMDGPUPromoteKernelArguments::runOnFunction(Function &F) {

189 MemorySSA &MSSA = getAnalysis().getMSSA();

190 AliasAnalysis &AA = getAnalysis().getAAResults();

191 return run(F, MSSA, AA);

192}

193

195 "AMDGPU Promote Kernel Arguments", false, false)

200

201char AMDGPUPromoteKernelArguments::ID = 0;

202

204 return new AMDGPUPromoteKernelArguments();

205}

206

212 if (AMDGPUPromoteKernelArguments().run(F, MSSA, AA)) {

216 return PA;

217 }

219}

static BasicBlock::iterator getInsertPt(BasicBlock &BB)

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

early cse Early CSE w MemorySSA

static bool runOnFunction(Function &F, bool PostInlining)

This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...

#define INITIALIZE_PASS_DEPENDENCY(depName)

#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)

#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)

This file defines the SmallVector class.

A manager for alias analyses.

A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.

an instruction to allocate memory on the stack

LLVM_ABI bool isStaticAlloca() const

Return true if this alloca is in the entry block of the function and is a constant size.

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

void setPreservesAll()

Set by analyses that do not transform their input at all.

LLVM Basic Block Representation.

LLVM_ABI const_iterator getFirstInsertionPt() const

Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...

InstListType::iterator iterator

Instruction iterators...

Represents analyses that only rely on functions' control flow.

FunctionPass class - This class is used to implement most global optimizations.

LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)

Set the metadata of the specified kind to the specified node.

An instruction for reading from memory.

static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)

An analysis that produces MemorySSA for a function.

Legacy analysis pass which computes MemorySSA.

Encapsulates MemorySSA, including all data associated with memory accesses.

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalyses & preserveSet()

Mark an analysis set as preserved.

PreservedAnalyses & preserve()

Mark an analysis as preserved.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

LLVM Value Representation.

Type * getType() const

All values are typed, get the type of this value.

iterator_range< user_iterator > users()

LLVM_ABI void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)

Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...

LLVM_ABI LLVMContext & getContext() const

All values hold a context through their type.

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

Abstract Attribute helper functions.

@ CONSTANT_ADDRESS

Address space for constant memory (VTX2).

@ FLAT_ADDRESS

Address space for flat memory.

@ GLOBAL_ADDRESS

Address space for global memory (RAT0, VTX0).

bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA, AAResults *AA)

Check is a Load is clobbered in its function.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

PointerTypeMap run(const Module &M)

Compute the PointerTypeMap for the module M.

friend class Instruction

Iterator for Instructions in a `BasicBlock.

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

decltype(auto) dyn_cast(const From &Val)

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

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >

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.

AAResults AliasAnalysis

Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.

FunctionPass * createAMDGPUPromoteKernelArgumentsPass()

Definition AMDGPUPromoteKernelArguments.cpp:203