mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[ObjCARC][NewPM] Port objc-arc-contract to NPM
Similar to https://reviews.llvm.org/D86178. This is a module pass instead of a function pass since ARCRuntimeEntryPoints can lazily add function declarations. Reviewed By: ahatanak Differential Revision: https://reviews.llvm.org/D87806
This commit is contained in:
parent
85f907b9af
commit
1a477f367f
@ -317,7 +317,7 @@ void initializeNaryReassociateLegacyPassPass(PassRegistry&);
|
||||
void initializeNewGVNLegacyPassPass(PassRegistry&);
|
||||
void initializeObjCARCAAWrapperPassPass(PassRegistry&);
|
||||
void initializeObjCARCAPElimPass(PassRegistry&);
|
||||
void initializeObjCARCContractPass(PassRegistry&);
|
||||
void initializeObjCARCContractLegacyPassPass(PassRegistry &);
|
||||
void initializeObjCARCExpandPass(PassRegistry&);
|
||||
void initializeObjCARCOptLegacyPassPass(PassRegistry &);
|
||||
void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry&);
|
||||
|
@ -44,10 +44,11 @@ Pass *createObjCARCContractPass();
|
||||
//
|
||||
Pass *createObjCARCOptPass();
|
||||
|
||||
class ObjCARCOptPass : public PassInfoMixin<ObjCARCOptPass> {
|
||||
public:
|
||||
ObjCARCOptPass() {}
|
||||
struct ObjCARCOptPass : public PassInfoMixin<ObjCARCOptPass> {
|
||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
|
||||
};
|
||||
|
||||
struct ObjCARCContractPass : public PassInfoMixin<ObjCARCContractPass> {
|
||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
|
||||
};
|
||||
|
||||
|
@ -70,6 +70,7 @@ MODULE_PASS("mergefunc", MergeFunctionsPass())
|
||||
MODULE_PASS("name-anon-globals", NameAnonGlobalPass())
|
||||
MODULE_PASS("no-op-module", NoOpModulePass())
|
||||
MODULE_PASS("objc-arc", ObjCARCOptPass())
|
||||
MODULE_PASS("objc-arc-contract", ObjCARCContractPass())
|
||||
MODULE_PASS("partial-inliner", PartialInlinerPass())
|
||||
MODULE_PASS("pgo-icall-prom", PGOIndirectCallPromotion())
|
||||
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
|
||||
|
@ -29,7 +29,7 @@ void llvm::initializeObjCARCOpts(PassRegistry &Registry) {
|
||||
initializeObjCARCAAWrapperPassPass(Registry);
|
||||
initializeObjCARCAPElimPass(Registry);
|
||||
initializeObjCARCExpandPass(Registry);
|
||||
initializeObjCARCContractPass(Registry);
|
||||
initializeObjCARCContractLegacyPassPass(Registry);
|
||||
initializeObjCARCOptLegacyPassPass(Registry);
|
||||
initializePAEvalPass(Registry);
|
||||
}
|
||||
|
@ -35,10 +35,12 @@
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/InstIterator.h"
|
||||
#include "llvm/IR/Operator.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/InitializePasses.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/ObjCARC.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::objcarc;
|
||||
@ -57,7 +59,8 @@ namespace {
|
||||
///
|
||||
/// These change the IR in a way that makes it difficult to be analyzed by
|
||||
/// ObjCARCOpt, so it's run late.
|
||||
class ObjCARCContract : public FunctionPass {
|
||||
|
||||
class ObjCARCContract {
|
||||
bool Changed;
|
||||
AliasAnalysis *AA;
|
||||
DominatorTree *DT;
|
||||
@ -80,15 +83,13 @@ namespace {
|
||||
bool tryToPeepholeInstruction(
|
||||
Function &F, Instruction *Inst, inst_iterator &Iter,
|
||||
SmallPtrSetImpl<Instruction *> &DepInsts,
|
||||
SmallPtrSetImpl<const BasicBlock *> &Visited,
|
||||
bool &TailOkForStoreStrong,
|
||||
SmallPtrSetImpl<const BasicBlock *> &Visited, bool &TailOkForStoreStrong,
|
||||
const DenseMap<BasicBlock *, ColorVector> &BlockColors);
|
||||
|
||||
bool optimizeRetainCall(Function &F, Instruction *Retain);
|
||||
|
||||
bool
|
||||
contractAutorelease(Function &F, Instruction *Autorelease,
|
||||
ARCInstKind Class,
|
||||
contractAutorelease(Function &F, Instruction *Autorelease, ARCInstKind Class,
|
||||
SmallPtrSetImpl<Instruction *> &DependingInstructions,
|
||||
SmallPtrSetImpl<const BasicBlock *> &Visited);
|
||||
|
||||
@ -96,14 +97,22 @@ namespace {
|
||||
Instruction *Release, inst_iterator &Iter,
|
||||
const DenseMap<BasicBlock *, ColorVector> &BlockColors);
|
||||
|
||||
public:
|
||||
bool init(Module &M);
|
||||
bool run(Function &F, AAResults *AA, DominatorTree *DT);
|
||||
};
|
||||
|
||||
class ObjCARCContractLegacyPass : public FunctionPass {
|
||||
ObjCARCContract OCARCC;
|
||||
|
||||
public:
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
||||
bool doInitialization(Module &M) override;
|
||||
bool runOnFunction(Function &F) override;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
ObjCARCContract() : FunctionPass(ID) {
|
||||
initializeObjCARCContractPass(*PassRegistry::getPassRegistry());
|
||||
ObjCARCContractLegacyPass() : FunctionPass(ID) {
|
||||
initializeObjCARCContractLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -542,7 +551,22 @@ bool ObjCARCContract::tryToPeepholeInstruction(
|
||||
// Top Level Driver
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
bool ObjCARCContract::runOnFunction(Function &F) {
|
||||
bool ObjCARCContract::init(Module &M) {
|
||||
// If nothing in the Module uses ARC, don't do anything.
|
||||
Run = ModuleHasARC(M);
|
||||
if (!Run)
|
||||
return false;
|
||||
|
||||
EP.init(&M);
|
||||
|
||||
// Initialize RVInstMarker.
|
||||
const char *MarkerKey = "clang.arc.retainAutoreleasedReturnValueMarker";
|
||||
RVInstMarker = dyn_cast_or_null<MDString>(M.getModuleFlag(MarkerKey));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
|
||||
if (!EnableARCOpts)
|
||||
return false;
|
||||
|
||||
@ -550,11 +574,9 @@ bool ObjCARCContract::runOnFunction(Function &F) {
|
||||
if (!Run)
|
||||
return false;
|
||||
|
||||
Changed = false;
|
||||
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
||||
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
|
||||
PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults());
|
||||
AA = A;
|
||||
DT = D;
|
||||
PA.setAA(A);
|
||||
|
||||
DenseMap<BasicBlock *, ColorVector> BlockColors;
|
||||
if (F.hasPersonalityFn() &&
|
||||
@ -720,33 +742,51 @@ bool ObjCARCContract::runOnFunction(Function &F) {
|
||||
// Misc Pass Manager
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
char ObjCARCContract::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(ObjCARCContract, "objc-arc-contract",
|
||||
char ObjCARCContractLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(ObjCARCContractLegacyPass, "objc-arc-contract",
|
||||
"ObjC ARC contraction", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_END(ObjCARCContract, "objc-arc-contract",
|
||||
INITIALIZE_PASS_END(ObjCARCContractLegacyPass, "objc-arc-contract",
|
||||
"ObjC ARC contraction", false, false)
|
||||
|
||||
void ObjCARCContract::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
void ObjCARCContractLegacyPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<AAResultsWrapperPass>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.setPreservesCFG();
|
||||
}
|
||||
|
||||
Pass *llvm::createObjCARCContractPass() { return new ObjCARCContract(); }
|
||||
|
||||
bool ObjCARCContract::doInitialization(Module &M) {
|
||||
// If nothing in the Module uses ARC, don't do anything.
|
||||
Run = ModuleHasARC(M);
|
||||
if (!Run)
|
||||
return false;
|
||||
|
||||
EP.init(&M);
|
||||
|
||||
// Initialize RVInstMarker.
|
||||
const char *MarkerKey = "clang.arc.retainAutoreleasedReturnValueMarker";
|
||||
RVInstMarker = dyn_cast_or_null<MDString>(M.getModuleFlag(MarkerKey));
|
||||
|
||||
return false;
|
||||
Pass *llvm::createObjCARCContractPass() {
|
||||
return new ObjCARCContractLegacyPass();
|
||||
}
|
||||
|
||||
bool ObjCARCContractLegacyPass::doInitialization(Module &M) {
|
||||
return OCARCC.init(M);
|
||||
}
|
||||
|
||||
bool ObjCARCContractLegacyPass::runOnFunction(Function &F) {
|
||||
auto *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
||||
auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
return OCARCC.run(F, AA, DT);
|
||||
}
|
||||
|
||||
PreservedAnalyses ObjCARCContractPass::run(Module &M,
|
||||
ModuleAnalysisManager &AM) {
|
||||
ObjCARCContract OCAC;
|
||||
OCAC.init(M);
|
||||
|
||||
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
|
||||
bool Changed = false;
|
||||
for (Function &F : M) {
|
||||
if (F.isDeclaration())
|
||||
continue;
|
||||
Changed |= OCAC.run(F, &FAM.getResult<AAManager>(F),
|
||||
&FAM.getResult<DominatorTreeAnalysis>(F));
|
||||
}
|
||||
if (Changed) {
|
||||
PreservedAnalyses PA;
|
||||
PA.preserveSet<CFGAnalyses>();
|
||||
return PA;
|
||||
}
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
|
||||
; RUN: opt -passes=objc-arc-contract -S < %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-p:64:64:64"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user