[PM] Port LowerGuardIntrinsic to the new PM.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277057 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Kuperstein 2016-07-28 22:08:41 +00:00
parent 912dfc3998
commit 093715aad1
7 changed files with 55 additions and 10 deletions

View File

@ -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&);

View File

@ -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<LowerGuardIntrinsicPass> {
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
}
#endif //LLVM_TRANSFORMS_SCALAR_LOWERGUARDINTRINSIC_H

View File

@ -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"

View File

@ -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())

View File

@ -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<uint32_t> 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();
}

View File

@ -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);

View File

@ -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, ...)