Skip to content

Commit 50bd71e

Browse files
committed
[NewPM] Port ConstraintElimination to the new pass manager
If -enable-constraint-elimination is specified, add it to the -O2/-O3 pipeline. (-O1 uses a separate function now.) Reviewed By: fhahn, aeubanks Differential Revision: https://reviews.llvm.org/D88365
1 parent 7b78206 commit 50bd71e

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===- ConstraintElimination.h - Constraint elimination pass ----*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_TRANSFORMS_SCALAR_CONSTRAINTELIMINATION_H
10+
#define LLVM_TRANSFORMS_SCALAR_CONSTRAINTELIMINATION_H
11+
12+
#include "llvm/IR/PassManager.h"
13+
14+
namespace llvm {
15+
16+
class ConstraintEliminationPass
17+
: public PassInfoMixin<ConstraintEliminationPass> {
18+
public:
19+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &);
20+
};
21+
22+
} // end namespace llvm
23+
24+
#endif // LLVM_TRANSFORMS_SCALAR_CONSTRAINTELIMINATION_H

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
#include "llvm/Transforms/Scalar/BDCE.h"
131131
#include "llvm/Transforms/Scalar/CallSiteSplitting.h"
132132
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
133+
#include "llvm/Transforms/Scalar/ConstraintElimination.h"
133134
#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
134135
#include "llvm/Transforms/Scalar/DCE.h"
135136
#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
@@ -284,6 +285,7 @@ PipelineTuningOptions::PipelineTuningOptions() {
284285
CallGraphProfile = true;
285286
}
286287

288+
extern cl::opt<bool> EnableConstraintElimination;
287289
extern cl::opt<bool> EnableHotColdSplit;
288290
extern cl::opt<bool> EnableOrderFileInstrumentation;
289291

@@ -606,6 +608,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
606608
FPM.addPass(SimplifyCFGPass());
607609
}
608610

611+
if (EnableConstraintElimination)
612+
FPM.addPass(ConstraintEliminationPass());
613+
609614
// Speculative execution if the target has divergent branches; otherwise nop.
610615
FPM.addPass(SpeculativeExecutionPass(/* OnlyIfDivergentTarget =*/true));
611616

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ FUNCTION_PASS("bounds-checking", BoundsCheckingPass())
188188
FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
189189
FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass())
190190
FUNCTION_PASS("consthoist", ConstantHoistingPass())
191+
FUNCTION_PASS("constraint-elimination", ConstraintEliminationPass())
191192
FUNCTION_PASS("chr", ControlHeightReductionPass())
192193
FUNCTION_PASS("coro-early", CoroEarlyPass())
193194
FUNCTION_PASS("coro-elide", CoroElidePass())

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "llvm/Transforms/Scalar/ConstraintElimination.h"
1415
#include "llvm/ADT/SmallVector.h"
1516
#include "llvm/ADT/Statistic.h"
1617
#include "llvm/Analysis/ConstraintSystem.h"
@@ -273,6 +274,19 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
273274
return Changed;
274275
}
275276

277+
PreservedAnalyses ConstraintEliminationPass::run(Function &F,
278+
FunctionAnalysisManager &AM) {
279+
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
280+
if (!eliminateConstraints(F, DT))
281+
return PreservedAnalyses::all();
282+
283+
PreservedAnalyses PA;
284+
PA.preserve<DominatorTreeAnalysis>();
285+
PA.preserve<GlobalsAA>();
286+
PA.preserveSet<CFGAnalyses>();
287+
return PA;
288+
}
289+
276290
namespace {
277291

278292
class ConstraintElimination : public FunctionPass {

llvm/test/Transforms/ConstraintElimination/dom.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt -constraint-elimination -S %s | FileCheck %s
3+
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
34

45
; Test cases where both the true and false successors reach the same block,
56
; dominated by one of them.

0 commit comments

Comments
 (0)