37
37
// ===----------------------------------------------------------------------===//
38
38
#define DEBUG_TYPE " spv-lower-const-expr"
39
39
40
+ #include " SPIRVLowerConstExpr.h"
40
41
#include " OCLUtil.h"
41
42
#include " SPIRVInternal.h"
42
43
#include " SPIRVMDBuilder.h"
@@ -65,29 +66,6 @@ cl::opt<bool> SPIRVLowerConst(
65
66
" spirv-lower-const-expr" , cl::init(true ),
66
67
cl::desc(" LLVM/SPIR-V translation enable lowering constant expression" ));
67
68
68
- class SPIRVLowerConstExprBase {
69
- public:
70
- SPIRVLowerConstExprBase () : M(nullptr ), Ctx(nullptr ) {}
71
-
72
- bool runLowerConstExpr (Module &M);
73
- void visit (Module *M);
74
-
75
- private:
76
- Module *M;
77
- LLVMContext *Ctx;
78
- };
79
-
80
- class SPIRVLowerConstExprPass
81
- : public llvm::PassInfoMixin<SPIRVLowerConstExprPass>,
82
- public SPIRVLowerConstExprBase {
83
- public:
84
- llvm::PreservedAnalyses run (llvm::Module &M,
85
- llvm::ModuleAnalysisManager &MAM) {
86
- return runLowerConstExpr (M) ? llvm::PreservedAnalyses::none ()
87
- : llvm::PreservedAnalyses::all ();
88
- }
89
- };
90
-
91
69
class SPIRVLowerConstExprLegacy : public ModulePass ,
92
70
public SPIRVLowerConstExprBase {
93
71
public:
@@ -110,11 +88,11 @@ bool SPIRVLowerConstExprBase::runLowerConstExpr(Module &Module) {
110
88
Ctx = &M->getContext ();
111
89
112
90
LLVM_DEBUG (dbgs () << " Enter SPIRVLowerConstExpr:\n " );
113
- visit (M);
91
+ bool Changed = visit (M);
114
92
115
93
verifyRegularizationPass (*M, " SPIRVLowerConstExpr" );
116
94
117
- return true ;
95
+ return Changed ;
118
96
}
119
97
120
98
// / Since SPIR-V cannot represent constant expression, constant expressions
@@ -126,7 +104,8 @@ bool SPIRVLowerConstExprBase::runLowerConstExpr(Module &Module) {
126
104
// / is replaced by one instruction.
127
105
// / ToDo: remove redundant instructions for common subexpression
128
106
129
- void SPIRVLowerConstExprBase::visit (Module *M) {
107
+ bool SPIRVLowerConstExprBase::visit (Module *M) {
108
+ bool Changed = false ;
130
109
for (auto &I : M->functions ()) {
131
110
std::list<Instruction *> WorkList;
132
111
for (auto &BI : I) {
@@ -138,7 +117,7 @@ void SPIRVLowerConstExprBase::visit(Module *M) {
138
117
while (!WorkList.empty ()) {
139
118
auto II = WorkList.front ();
140
119
141
- auto LowerOp = [&II, &FBegin, &I](Value *V) -> Value * {
120
+ auto LowerOp = [&II, &FBegin, &I, &Changed ](Value *V) -> Value * {
142
121
if (isa<Function>(V))
143
122
return V;
144
123
auto *CE = cast<ConstantExpr>(V);
@@ -163,6 +142,7 @@ void SPIRVLowerConstExprBase::visit(Module *M) {
163
142
ReplInst->moveBefore (User);
164
143
User->replaceUsesOfWith (CE, ReplInst);
165
144
}
145
+ Changed = true ;
166
146
return ReplInst;
167
147
};
168
148
@@ -190,6 +170,7 @@ void SPIRVLowerConstExprBase::visit(Module *M) {
190
170
}
191
171
}
192
172
}
173
+ return Changed;
193
174
}
194
175
195
176
} // namespace SPIRV
0 commit comments