mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 12:19:53 +00:00
[PM] Port BDCE to the new pass manager.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270647 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0e9b526d1b
commit
abf016e342
@ -65,7 +65,7 @@ void initializeTarget(PassRegistry&);
|
||||
void initializeAAEvalLegacyPassPass(PassRegistry&);
|
||||
void initializeAddDiscriminatorsPass(PassRegistry&);
|
||||
void initializeADCELegacyPassPass(PassRegistry&);
|
||||
void initializeBDCEPass(PassRegistry&);
|
||||
void initializeBDCELegacyPassPass(PassRegistry &);
|
||||
void initializeAliasSetPrinterPass(PassRegistry&);
|
||||
void initializeAlwaysInlinerPass(PassRegistry&);
|
||||
void initializeArgPromotionPass(PassRegistry&);
|
||||
|
31
include/llvm/Transforms/Scalar/BDCE.h
Normal file
31
include/llvm/Transforms/Scalar/BDCE.h
Normal file
@ -0,0 +1,31 @@
|
||||
//===---- BDCE.cpp - Bit-tracking dead code elimination ---------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the Bit-Tracking Dead Code Elimination pass. Some
|
||||
// instructions (shifts, some ands, ors, etc.) kill some of their input bits.
|
||||
// We track these dead bits and remove instructions that compute only these
|
||||
// dead bits.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_SCALAR_BDCE_H
|
||||
#define LLVM_TRANSFORMS_SCALAR_BDCE_H
|
||||
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
// The Bit-Tracking Dead Code Elimination pass.
|
||||
struct BDCEPass : PassInfoMixin<BDCEPass> {
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LLVM_TRANSFORMS_SCALAR_BDCE_H
|
@ -63,11 +63,12 @@
|
||||
#include "llvm/Transforms/InstrProfiling.h"
|
||||
#include "llvm/Transforms/PGOInstrumentation.h"
|
||||
#include "llvm/Transforms/Scalar/ADCE.h"
|
||||
#include "llvm/Transforms/Scalar/BDCE.h"
|
||||
#include "llvm/Transforms/Scalar/DCE.h"
|
||||
#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
|
||||
#include "llvm/Transforms/Scalar/EarlyCSE.h"
|
||||
#include "llvm/Transforms/Scalar/GuardWidening.h"
|
||||
#include "llvm/Transforms/Scalar/GVN.h"
|
||||
#include "llvm/Transforms/Scalar/GuardWidening.h"
|
||||
#include "llvm/Transforms/Scalar/LoopRotation.h"
|
||||
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
|
||||
#include "llvm/Transforms/Scalar/LowerAtomic.h"
|
||||
|
@ -110,6 +110,7 @@ FUNCTION_ALIAS_ANALYSIS("type-based-aa", TypeBasedAA())
|
||||
#endif
|
||||
FUNCTION_PASS("aa-eval", AAEvaluator())
|
||||
FUNCTION_PASS("adce", ADCEPass())
|
||||
FUNCTION_PASS("bdce", BDCEPass())
|
||||
FUNCTION_PASS("dce", DCEPass())
|
||||
FUNCTION_PASS("dse", DSEPass())
|
||||
FUNCTION_PASS("early-cse", EarlyCSEPass())
|
||||
|
@ -14,11 +14,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Scalar/BDCE.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/Analysis/GlobalsModRef.h"
|
||||
#include "llvm/Analysis/DemandedBits.h"
|
||||
#include "llvm/Analysis/GlobalsModRef.h"
|
||||
#include "llvm/IR/CFG.h"
|
||||
#include "llvm/IR/InstIterator.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
@ -27,6 +27,7 @@
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
using namespace llvm;
|
||||
|
||||
#define DEBUG_TYPE "bdce"
|
||||
@ -34,35 +35,7 @@ using namespace llvm;
|
||||
STATISTIC(NumRemoved, "Number of instructions removed (unused)");
|
||||
STATISTIC(NumSimplified, "Number of instructions trivialized (dead bits)");
|
||||
|
||||
namespace {
|
||||
struct BDCE : public FunctionPass {
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
BDCE() : FunctionPass(ID) {
|
||||
initializeBDCEPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnFunction(Function& F) override;
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage& AU) const override {
|
||||
AU.setPreservesCFG();
|
||||
AU.addRequired<DemandedBitsWrapperPass>();
|
||||
AU.addPreserved<GlobalsAAWrapperPass>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char BDCE::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(BDCE, "bdce", "Bit-Tracking Dead Code Elimination",
|
||||
false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(DemandedBitsWrapperPass)
|
||||
INITIALIZE_PASS_END(BDCE, "bdce", "Bit-Tracking Dead Code Elimination",
|
||||
false, false)
|
||||
|
||||
bool BDCE::runOnFunction(Function& F) {
|
||||
if (skipFunction(F))
|
||||
return false;
|
||||
auto &DB = getAnalysis<DemandedBitsWrapperPass>().getDemandedBits();
|
||||
|
||||
static bool bitTrackingDCE(Function &F, DemandedBits &DB) {
|
||||
SmallVector<Instruction*, 128> Worklist;
|
||||
bool Changed = false;
|
||||
for (Instruction &I : instructions(F)) {
|
||||
@ -96,7 +69,40 @@ bool BDCE::runOnFunction(Function& F) {
|
||||
return Changed;
|
||||
}
|
||||
|
||||
FunctionPass *llvm::createBitTrackingDCEPass() {
|
||||
return new BDCE();
|
||||
PreservedAnalyses BDCEPass::run(Function &F, FunctionAnalysisManager &AM) {
|
||||
auto &DB = AM.getResult<DemandedBitsAnalysis>(F);
|
||||
if (bitTrackingDCE(F, DB))
|
||||
return PreservedAnalyses::none();
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct BDCELegacyPass : public FunctionPass {
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
BDCELegacyPass() : FunctionPass(ID) {
|
||||
initializeBDCELegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override {
|
||||
if (skipFunction(F))
|
||||
return false;
|
||||
auto &DB = getAnalysis<DemandedBitsWrapperPass>().getDemandedBits();
|
||||
return bitTrackingDCE(F, DB);
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesCFG();
|
||||
AU.addRequired<DemandedBitsWrapperPass>();
|
||||
AU.addPreserved<GlobalsAAWrapperPass>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char BDCELegacyPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(BDCELegacyPass, "bdce",
|
||||
"Bit-Tracking Dead Code Elimination", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(DemandedBitsWrapperPass)
|
||||
INITIALIZE_PASS_END(BDCELegacyPass, "bdce",
|
||||
"Bit-Tracking Dead Code Elimination", false, false)
|
||||
|
||||
FunctionPass *llvm::createBitTrackingDCEPass() { return new BDCELegacyPass(); }
|
||||
|
@ -32,7 +32,7 @@ using namespace llvm;
|
||||
/// ScalarOpts library.
|
||||
void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
||||
initializeADCELegacyPassPass(Registry);
|
||||
initializeBDCEPass(Registry);
|
||||
initializeBDCELegacyPassPass(Registry);
|
||||
initializeAlignmentFromAssumptionsPass(Registry);
|
||||
initializeConstantHoistingPass(Registry);
|
||||
initializeConstantPropagationPass(Registry);
|
||||
|
@ -1,4 +1,5 @@
|
||||
; RUN: opt -bdce -S < %s | FileCheck %s
|
||||
; RUN: opt -passes=bdce -S < %s | FileCheck %s
|
||||
|
||||
declare i32 @strlen(i8*) readonly nounwind
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user