From 093715aad1898e6c030ee452cb9c82d44d19f432 Mon Sep 17 00:00:00 2001 From: Michael Kuperstein Date: Thu, 28 Jul 2016 22:08:41 +0000 Subject: [PATCH] [PM] Port LowerGuardIntrinsic to the new PM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277057 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/InitializePasses.h | 2 +- .../Transforms/Scalar/LowerGuardIntrinsic.h | 28 +++++++++++++++++ lib/Passes/PassBuilder.cpp | 1 + lib/Passes/PassRegistry.def | 1 + lib/Transforms/Scalar/LowerGuardIntrinsic.cpp | 30 ++++++++++++++----- lib/Transforms/Scalar/Scalar.cpp | 2 +- test/Transforms/LowerGuardIntrinsic/basic.ll | 1 + 7 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 include/llvm/Transforms/Scalar/LowerGuardIntrinsic.h diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index 33e1482c49d..79ecbed9c99 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -202,7 +202,7 @@ void initializeLoopVersioningPassPass(PassRegistry &); void initializeLowerAtomicLegacyPassPass(PassRegistry &); void initializeLowerEmuTLSPass(PassRegistry&); void initializeLowerExpectIntrinsicPass(PassRegistry&); -void initializeLowerGuardIntrinsicPass(PassRegistry&); +void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry&); void initializeLowerIntrinsicsPass(PassRegistry&); void initializeLowerInvokePass(PassRegistry&); void initializeLowerSwitchPass(PassRegistry&); diff --git a/include/llvm/Transforms/Scalar/LowerGuardIntrinsic.h b/include/llvm/Transforms/Scalar/LowerGuardIntrinsic.h new file mode 100644 index 00000000000..a9f19f6b84b --- /dev/null +++ b/include/llvm/Transforms/Scalar/LowerGuardIntrinsic.h @@ -0,0 +1,28 @@ +//===--- LowerGuardIntrinsic.h - Lower the guard intrinsic ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This pass lowers the llvm.experimental.guard intrinsic to a conditional call +// to @llvm.experimental.deoptimize. Once this happens, the guard can no longer +// be widened. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_TRANSFORMS_SCALAR_LOWERGUARDINTRINSIC_H +#define LLVM_TRANSFORMS_SCALAR_LOWERGUARDINTRINSIC_H + +#include "llvm/IR/PassManager.h" + +namespace llvm { + +struct LowerGuardIntrinsicPass : PassInfoMixin { + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); +}; + +} + +#endif //LLVM_TRANSFORMS_SCALAR_LOWERGUARDINTRINSIC_H diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index 261004a39a4..44ac46f3dae 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -102,6 +102,7 @@ #include "llvm/Transforms/Scalar/LoopUnrollPass.h" #include "llvm/Transforms/Scalar/LowerAtomic.h" #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" +#include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h" #include "llvm/Transforms/Scalar/MemCpyOptimizer.h" #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h" #include "llvm/Transforms/Scalar/NaryReassociate.h" diff --git a/lib/Passes/PassRegistry.def b/lib/Passes/PassRegistry.def index ac89bd5abbe..86ff8fae9ae 100644 --- a/lib/Passes/PassRegistry.def +++ b/lib/Passes/PassRegistry.def @@ -145,6 +145,7 @@ FUNCTION_PASS("float2int", Float2IntPass()) FUNCTION_PASS("no-op-function", NoOpFunctionPass()) FUNCTION_PASS("loweratomic", LowerAtomicPass()) FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass()) +FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass()) FUNCTION_PASS("guard-widening", GuardWideningPass()) FUNCTION_PASS("gvn", GVN()) FUNCTION_PASS("loop-simplify", LoopSimplifyPass()) diff --git a/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp b/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp index 57491007d01..4f413715ffe 100644 --- a/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp +++ b/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp @@ -13,7 +13,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Function.h" @@ -24,6 +24,7 @@ #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Module.h" #include "llvm/Pass.h" +#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" using namespace llvm; @@ -34,10 +35,11 @@ static cl::opt PredicatePassBranchWeight( "reciprocal of this value (default = 1 << 20)")); namespace { -struct LowerGuardIntrinsic : public FunctionPass { +struct LowerGuardIntrinsicLegacyPass : public FunctionPass { static char ID; - LowerGuardIntrinsic() : FunctionPass(ID) { - initializeLowerGuardIntrinsicPass(*PassRegistry::getPassRegistry()); + LowerGuardIntrinsicLegacyPass() : FunctionPass(ID) { + initializeLowerGuardIntrinsicLegacyPassPass( + *PassRegistry::getPassRegistry()); } bool runOnFunction(Function &F) override; @@ -83,7 +85,7 @@ static void MakeGuardControlFlowExplicit(Function *DeoptIntrinsic, DeoptBlockTerm->eraseFromParent(); } -bool LowerGuardIntrinsic::runOnFunction(Function &F) { +static bool lowerGuardIntrinsic(Function &F) { // Check if we can cheaply rule out the possibility of not having any work to // do. auto *GuardDecl = F.getParent()->getFunction( @@ -113,11 +115,23 @@ bool LowerGuardIntrinsic::runOnFunction(Function &F) { return true; } -char LowerGuardIntrinsic::ID = 0; -INITIALIZE_PASS(LowerGuardIntrinsic, "lower-guard-intrinsic", +bool LowerGuardIntrinsicLegacyPass::runOnFunction(Function &F) { + return lowerGuardIntrinsic(F); +} + +char LowerGuardIntrinsicLegacyPass::ID = 0; +INITIALIZE_PASS(LowerGuardIntrinsicLegacyPass, "lower-guard-intrinsic", "Lower the guard intrinsic to normal control flow", false, false) Pass *llvm::createLowerGuardIntrinsicPass() { - return new LowerGuardIntrinsic(); + return new LowerGuardIntrinsicLegacyPass(); +} + +PreservedAnalyses LowerGuardIntrinsicPass::run(Function &F, + FunctionAnalysisManager &AM) { + if (lowerGuardIntrinsic(F)) + return PreservedAnalyses::none(); + + return PreservedAnalyses::all(); } diff --git a/lib/Transforms/Scalar/Scalar.cpp b/lib/Transforms/Scalar/Scalar.cpp index 5e2e656d2a8..a122984fcf7 100644 --- a/lib/Transforms/Scalar/Scalar.cpp +++ b/lib/Transforms/Scalar/Scalar.cpp @@ -64,7 +64,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeLoopIdiomRecognizeLegacyPassPass(Registry); initializeLowerAtomicLegacyPassPass(Registry); initializeLowerExpectIntrinsicPass(Registry); - initializeLowerGuardIntrinsicPass(Registry); + initializeLowerGuardIntrinsicLegacyPassPass(Registry); initializeMemCpyOptLegacyPassPass(Registry); initializeMergedLoadStoreMotionLegacyPassPass(Registry); initializeNaryReassociateLegacyPassPass(Registry); diff --git a/test/Transforms/LowerGuardIntrinsic/basic.ll b/test/Transforms/LowerGuardIntrinsic/basic.ll index 7c3584a774e..6c1dd95331a 100644 --- a/test/Transforms/LowerGuardIntrinsic/basic.ll +++ b/test/Transforms/LowerGuardIntrinsic/basic.ll @@ -1,4 +1,5 @@ ; RUN: opt -S -lower-guard-intrinsic < %s | FileCheck %s +; RUN: opt -S -passes='lower-guard-intrinsic' < %s | FileCheck %s declare void @llvm.experimental.guard(i1, ...)