@@ -143,14 +143,20 @@ class NVPTXPassConfig : public TargetPassConfig {
143
143
void addOptimizedRegAlloc (FunctionPass *RegAllocPass) override ;
144
144
145
145
private:
146
- // if the opt level is aggressive, add GVN; otherwise, add EarlyCSE.
146
+ // If the opt level is aggressive, add GVN; otherwise, add EarlyCSE. This
147
+ // function is only called in opt mode.
147
148
void addEarlyCSEOrGVNPass ();
149
+
150
+ // Add passes that propagate special memory spaces.
151
+ void addMemorySpaceInferencePasses ();
152
+
153
+ // Add passes that perform straight-line scalar optimizations.
154
+ void addStraightLineScalarOptimizationPasses ();
148
155
};
149
156
} // end anonymous namespace
150
157
151
158
TargetPassConfig *NVPTXTargetMachine::createPassConfig (PassManagerBase &PM) {
152
- NVPTXPassConfig *PassConfig = new NVPTXPassConfig (this , PM);
153
- return PassConfig;
159
+ return new NVPTXPassConfig (this , PM);
154
160
}
155
161
156
162
TargetIRAnalysis NVPTXTargetMachine::getTargetIRAnalysis () {
@@ -166,22 +172,7 @@ void NVPTXPassConfig::addEarlyCSEOrGVNPass() {
166
172
addPass (createEarlyCSEPass ());
167
173
}
168
174
169
- void NVPTXPassConfig::addIRPasses () {
170
- // The following passes are known to not play well with virtual regs hanging
171
- // around after register allocation (which in our case, is *all* registers).
172
- // We explicitly disable them here. We do, however, need some functionality
173
- // of the PrologEpilogCodeInserter pass, so we emulate that behavior in the
174
- // NVPTXPrologEpilog pass (see NVPTXPrologEpilogPass.cpp).
175
- disablePass (&PrologEpilogCodeInserterID);
176
- disablePass (&MachineCopyPropagationID);
177
- disablePass (&TailDuplicateID);
178
-
179
- addPass (createNVVMReflectPass ());
180
- addPass (createNVPTXImageOptimizerPass ());
181
- addPass (createNVPTXAssignValidGlobalNamesPass ());
182
- addPass (createGenericToNVVMPass ());
183
-
184
- // === Propagate special address spaces ===
175
+ void NVPTXPassConfig::addMemorySpaceInferencePasses () {
185
176
addPass (createNVPTXLowerKernelArgsPass (&getNVPTXTargetMachine ()));
186
177
// NVPTXLowerKernelArgs emits alloca for byval parameters which can often
187
178
// be eliminated by SROA.
@@ -192,8 +183,9 @@ void NVPTXPassConfig::addIRPasses() {
192
183
// them unused. We could remove dead code in an ad-hoc manner, but that
193
184
// requires manual work and might be error-prone.
194
185
addPass (createDeadCodeEliminationPass ());
186
+ }
195
187
196
- // === Straight-line scalar optimizations ===
188
+ void NVPTXPassConfig::addStraightLineScalarOptimizationPasses () {
197
189
addPass (createSeparateConstOffsetFromGEPPass ());
198
190
addPass (createSpeculativeExecutionPass ());
199
191
// ReassociateGEPs exposes more opportunites for SLSR. See
@@ -208,6 +200,28 @@ void NVPTXPassConfig::addIRPasses() {
208
200
// NaryReassociate on GEPs creates redundant common expressions, so run
209
201
// EarlyCSE after it.
210
202
addPass (createEarlyCSEPass ());
203
+ }
204
+
205
+ void NVPTXPassConfig::addIRPasses () {
206
+ // The following passes are known to not play well with virtual regs hanging
207
+ // around after register allocation (which in our case, is *all* registers).
208
+ // We explicitly disable them here. We do, however, need some functionality
209
+ // of the PrologEpilogCodeInserter pass, so we emulate that behavior in the
210
+ // NVPTXPrologEpilog pass (see NVPTXPrologEpilogPass.cpp).
211
+ disablePass (&PrologEpilogCodeInserterID);
212
+ disablePass (&MachineCopyPropagationID);
213
+ disablePass (&TailDuplicateID);
214
+
215
+ addPass (createNVVMReflectPass ());
216
+ if (getOptLevel () != CodeGenOpt::None)
217
+ addPass (createNVPTXImageOptimizerPass ());
218
+ addPass (createNVPTXAssignValidGlobalNamesPass ());
219
+ addPass (createGenericToNVVMPass ());
220
+
221
+ if (getOptLevel () != CodeGenOpt::None) {
222
+ addMemorySpaceInferencePasses ();
223
+ addStraightLineScalarOptimizationPasses ();
224
+ }
211
225
212
226
// === LSR and other generic IR passes ===
213
227
TargetPassConfig::addIRPasses ();
@@ -223,7 +237,8 @@ void NVPTXPassConfig::addIRPasses() {
223
237
// %1 = shl %a, 2
224
238
//
225
239
// but EarlyCSE can do neither of them.
226
- addEarlyCSEOrGVNPass ();
240
+ if (getOptLevel () != CodeGenOpt::None)
241
+ addEarlyCSEOrGVNPass ();
227
242
}
228
243
229
244
bool NVPTXPassConfig::addInstSelector () {
0 commit comments