Skip to content

Commit

Permalink
[NewPM] Port ConstraintElimination to the new pass manager
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaskRay committed Sep 27, 2020
1 parent 7b78206 commit 50bd71e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
24 changes: 24 additions & 0 deletions llvm/include/llvm/Transforms/Scalar/ConstraintElimination.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- ConstraintElimination.h - Constraint elimination pass ----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TRANSFORMS_SCALAR_CONSTRAINTELIMINATION_H
#define LLVM_TRANSFORMS_SCALAR_CONSTRAINTELIMINATION_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class ConstraintEliminationPass
: public PassInfoMixin<ConstraintEliminationPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &);
};

} // end namespace llvm

#endif // LLVM_TRANSFORMS_SCALAR_CONSTRAINTELIMINATION_H
5 changes: 5 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
#include "llvm/Transforms/Scalar/BDCE.h"
#include "llvm/Transforms/Scalar/CallSiteSplitting.h"
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
#include "llvm/Transforms/Scalar/ConstraintElimination.h"
#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
#include "llvm/Transforms/Scalar/DCE.h"
#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
Expand Down Expand Up @@ -284,6 +285,7 @@ PipelineTuningOptions::PipelineTuningOptions() {
CallGraphProfile = true;
}

extern cl::opt<bool> EnableConstraintElimination;
extern cl::opt<bool> EnableHotColdSplit;
extern cl::opt<bool> EnableOrderFileInstrumentation;

Expand Down Expand Up @@ -606,6 +608,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
FPM.addPass(SimplifyCFGPass());
}

if (EnableConstraintElimination)
FPM.addPass(ConstraintEliminationPass());

// Speculative execution if the target has divergent branches; otherwise nop.
FPM.addPass(SpeculativeExecutionPass(/* OnlyIfDivergentTarget =*/true));

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ FUNCTION_PASS("bounds-checking", BoundsCheckingPass())
FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass())
FUNCTION_PASS("consthoist", ConstantHoistingPass())
FUNCTION_PASS("constraint-elimination", ConstraintEliminationPass())
FUNCTION_PASS("chr", ControlHeightReductionPass())
FUNCTION_PASS("coro-early", CoroEarlyPass())
FUNCTION_PASS("coro-elide", CoroElidePass())
Expand Down
14 changes: 14 additions & 0 deletions llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/Transforms/Scalar/ConstraintElimination.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/ConstraintSystem.h"
Expand Down Expand Up @@ -273,6 +274,19 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
return Changed;
}

PreservedAnalyses ConstraintEliminationPass::run(Function &F,
FunctionAnalysisManager &AM) {
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
if (!eliminateConstraints(F, DT))
return PreservedAnalyses::all();

PreservedAnalyses PA;
PA.preserve<DominatorTreeAnalysis>();
PA.preserve<GlobalsAA>();
PA.preserveSet<CFGAnalyses>();
return PA;
}

namespace {

class ConstraintElimination : public FunctionPass {
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/ConstraintElimination/dom.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -constraint-elimination -S %s | FileCheck %s
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s

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

0 comments on commit 50bd71e

Please sign in to comment.