@@ -176,6 +176,22 @@ namespace {
176
176
initializeReassociatePass (*PassRegistry::getPassRegistry ());
177
177
}
178
178
179
+ // HLSL Change - begin
180
+ // Enable global reassociation when HLSLEnableAggressiveReassociation is
181
+ // set
182
+ bool HLSLEnableAggressiveReassociation = true ;
183
+ Reassociate (bool HLSLEnableAggressiveReassociation) : Reassociate() {
184
+ this ->HLSLEnableAggressiveReassociation =
185
+ HLSLEnableAggressiveReassociation;
186
+ }
187
+
188
+ void applyOptions (PassOptions O) override {
189
+ GetPassOptionBool (O, " EnableAggressiveReassociation" ,
190
+ &HLSLEnableAggressiveReassociation,
191
+ /* defaultValue*/ true );
192
+ }
193
+ // HLSL Change - end
194
+
179
195
bool runOnFunction (Function &F) override ;
180
196
181
197
void getAnalysisUsage (AnalysisUsage &AU) const override {
@@ -242,6 +258,13 @@ INITIALIZE_PASS(Reassociate, "reassociate",
242
258
// Public interface to the Reassociate pass
243
259
FunctionPass *llvm::createReassociatePass() { return new Reassociate (); }
244
260
261
+ // HLSL Change - begin
262
+ FunctionPass *
263
+ llvm::createReassociatePass (bool HLSLEnableAggressiveReassociation) {
264
+ return new Reassociate (HLSLEnableAggressiveReassociation);
265
+ }
266
+ // HLSL Change - end
267
+
245
268
// / Return true if V is an instruction of the specified opcode and if it
246
269
// / only has one use.
247
270
static BinaryOperator *isReassociableOp (Value *V, unsigned Opcode) {
@@ -2243,7 +2266,8 @@ void Reassociate::ReassociateExpression(BinaryOperator *I) {
2243
2266
return ;
2244
2267
}
2245
2268
2246
- if (Ops.size () > 2 && Ops.size () <= GlobalReassociateLimit) {
2269
+ if (HLSLEnableAggressiveReassociation && // HLSL Change
2270
+ (Ops.size () > 2 && Ops.size () <= GlobalReassociateLimit)) {
2247
2271
// Find the pair with the highest count in the pairmap and move it to the
2248
2272
// back of the list so that it can later be CSE'd.
2249
2273
// example:
@@ -2347,22 +2371,24 @@ bool Reassociate::runOnFunction(Function &F) {
2347
2371
// Calculate the rank map for F
2348
2372
BuildRankMap (F);
2349
2373
2350
- // Build the pair map before running reassociate.
2351
- // Technically this would be more accurate if we did it after one round
2352
- // of reassociation, but in practice it doesn't seem to help much on
2353
- // real-world code, so don't waste the compile time running reassociate
2354
- // twice.
2355
- // If a user wants, they could expicitly run reassociate twice in their
2356
- // pass pipeline for further potential gains.
2357
- // It might also be possible to update the pair map during runtime, but the
2358
- // overhead of that may be large if there's many reassociable chains.
2359
- // TODO: RPOT
2360
- // Get the functions basic blocks in Reverse Post Order. This order is used by
2361
- // BuildRankMap to pre calculate ranks correctly. It also excludes dead basic
2362
- // blocks (it has been seen that the analysis in this pass could hang when
2363
- // analysing dead basic blocks).
2364
- ReversePostOrderTraversal<Function *> RPOT (&F);
2365
- BuildPairMap (RPOT);
2374
+ if (HLSLEnableAggressiveReassociation) { // HLSL Change
2375
+ // Build the pair map before running reassociate.
2376
+ // Technically this would be more accurate if we did it after one round
2377
+ // of reassociation, but in practice it doesn't seem to help much on
2378
+ // real-world code, so don't waste the compile time running reassociate
2379
+ // twice.
2380
+ // If a user wants, they could expicitly run reassociate twice in their
2381
+ // pass pipeline for further potential gains.
2382
+ // It might also be possible to update the pair map during runtime, but the
2383
+ // overhead of that may be large if there's many reassociable chains.
2384
+ // TODO: RPOT
2385
+ // Get the functions basic blocks in Reverse Post Order. This order is used
2386
+ // by BuildRankMap to pre calculate ranks correctly. It also excludes dead
2387
+ // basic blocks (it has been seen that the analysis in this pass could hang
2388
+ // when analysing dead basic blocks).
2389
+ ReversePostOrderTraversal<Function *> RPOT (&F);
2390
+ BuildPairMap (RPOT);
2391
+ } // HLSL Change
2366
2392
2367
2393
MadeChange = false ;
2368
2394
for (Function::iterator BI = F.begin (), BE = F.end (); BI != BE; ++BI) {
@@ -2389,8 +2415,10 @@ bool Reassociate::runOnFunction(Function &F) {
2389
2415
// We are done with the rank map and pair map.
2390
2416
RankMap.clear ();
2391
2417
ValueRankMap.clear ();
2392
- for (auto &Entry : PairMap)
2393
- Entry.clear ();
2418
+ if (HLSLEnableAggressiveReassociation) { // HLSL Change
2419
+ for (auto &Entry : PairMap)
2420
+ Entry.clear ();
2421
+ } // HLSL Change
2394
2422
2395
2423
return MadeChange;
2396
2424
}
0 commit comments