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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

65

66using namespace llvm;

67

68#define DEBUG_TYPE "amdgpu-rewrite-undef-for-phi"

69

70namespace {

71

72class AMDGPURewriteUndefForPHILegacy : public FunctionPass {

73public:

74 static char ID;

75 AMDGPURewriteUndefForPHILegacy() : FunctionPass(ID) {}

77 StringRef getPassName() const override {

78 return "AMDGPU Rewrite Undef for PHI";

79 }

80

81 void getAnalysisUsage(AnalysisUsage &AU) const override {

84

87 }

88};

89

90}

91char AMDGPURewriteUndefForPHILegacy::ID = 0;

92

94 "Rewrite undef for PHI", false, false)

99

103 for (auto &BB : F) {

104 for (auto &PHI : BB.phis()) {

105 if (UA.isDivergent(&PHI))

106 continue;

107

108

109 Value *UniqueDefinedIncoming = nullptr;

110

111

113

115

116 for (unsigned i = 0; i < PHI.getNumIncomingValues(); i++) {

118 BasicBlock *IncomingBB = PHI.getIncomingBlock(i);

119

121 continue;

122

124

125 if (!DT->dominates(&BB, IncomingBB))

127 continue;

128 }

129

130 if (!UniqueDefinedIncoming) {

131 UniqueDefinedIncoming = Incoming;

132 DominateBB = IncomingBB;

133 } else if (Incoming == UniqueDefinedIncoming) {

134

135 if (DT->dominates(IncomingBB, DominateBB))

136 DominateBB = IncomingBB;

137 } else {

138 UniqueDefinedIncoming = nullptr;

139 break;

140 }

141 }

142

143

144

145

146 if (!UniqueDefinedIncoming || Undefs.empty() ||

148 continue;

149

150

151

152

153

154 if (DT->dominates(DominateBB, &BB) && all_of(Undefs, [&](BasicBlock *UD) {

155 return DT->dominates(DominateBB, UD);

156 })) {

157 PHI.replaceAllUsesWith(UniqueDefinedIncoming);

160 }

161 }

162 }

163

164 for (auto *PHI : ToBeDeleted)

165 PHI->eraseFromParent();

166

168}

169

170bool AMDGPURewriteUndefForPHILegacy::runOnFunction(Function &F) {

172 getAnalysis().getUniformityInfo();

173 DominatorTree *DT = &getAnalysis().getDomTree();

175}

176

177PreservedAnalyses

185 return PA;

186 }

187

189}

190

192 return new AMDGPURewriteUndefForPHILegacy();

193}

Rewrite undef for false bool rewritePHIs(Function &F, UniformityInfo &UA, DominatorTree *DT)

Definition AMDGPURewriteUndefForPHI.cpp:100

Rewrite undef for PHI

Definition AMDGPURewriteUndefForPHI.cpp:98

This file contains the declarations for the subclasses of Constant, which represent the different fla...

static bool runOnFunction(Function &F, bool PostInlining)

#define INITIALIZE_PASS_DEPENDENCY(depName)

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

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

LLVM IR instance of the generic uniformity analysis.

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)

Definition AMDGPURewriteUndefForPHI.cpp:178

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()

AnalysisUsage & addPreserved()

Add the specified Pass class to the set of analyses preserved by this pass.

LLVM_ABI void setPreservesCFG()

This function should be called by the pass, iff they do not:

LLVM Basic Block Representation.

const Instruction * getTerminator() const LLVM_READONLY

Returns the terminator instruction if the block is well formed or null if the block is not well forme...

Represents analyses that only rely on functions' control flow.

Analysis pass which computes a DominatorTree.

Legacy analysis pass which computes a DominatorTree.

Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.

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

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.

void push_back(const T &Elt)

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

StringRef - Represent a constant reference to a string, i.e.

Analysis pass which computes UniformityInfo.

Legacy analysis pass which computes a CycleInfo.

LLVM Value Representation.

unsigned ID

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

This is an optimization pass for GlobalISel generic memory operations.

GenericUniformityInfo< SSAContext > UniformityInfo

bool all_of(R &&range, UnaryPredicate P)

Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

FunctionPass * createAMDGPURewriteUndefForPHILegacyPass()

Definition AMDGPURewriteUndefForPHI.cpp:191

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.

Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...