1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

Port -objc-arc-expand to NPM

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D90182
This commit is contained in:
Arthur Eubanks 2020-10-26 11:59:23 -07:00
parent 6085a8c54a
commit 7e6a52443b
4 changed files with 44 additions and 40 deletions

View File

@ -56,6 +56,10 @@ struct ObjCARCAPElimPass : public PassInfoMixin<ObjCARCAPElimPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
struct ObjCARCExpandPass : public PassInfoMixin<ObjCARCExpandPass> {
PreservedAnalyses run(Function &M, FunctionAnalysisManager &AM);
};
} // End llvm namespace
#endif

View File

@ -254,6 +254,7 @@ FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass())
FUNCTION_PASS("loop-fusion", LoopFusePass())
FUNCTION_PASS("loop-distribute", LoopDistributePass())
FUNCTION_PASS("loop-versioning", LoopVersioningPass())
FUNCTION_PASS("objc-arc-expand", ObjCARCExpandPass())
FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt())
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))

View File

@ -27,6 +27,7 @@
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
@ -34,57 +35,20 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/ObjCARC.h"
#define DEBUG_TYPE "objc-arc-expand"
namespace llvm {
class Module;
}
using namespace llvm;
using namespace llvm::objcarc;
namespace {
/// Early ARC transformations.
class ObjCARCExpand : public FunctionPass {
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool doInitialization(Module &M) override;
bool runOnFunction(Function &F) override;
/// A flag indicating whether this optimization pass should run.
bool Run;
public:
static char ID;
ObjCARCExpand() : FunctionPass(ID) {
initializeObjCARCExpandPass(*PassRegistry::getPassRegistry());
}
};
}
char ObjCARCExpand::ID = 0;
INITIALIZE_PASS(ObjCARCExpand,
"objc-arc-expand", "ObjC ARC expansion", false, false)
Pass *llvm::createObjCARCExpandPass() {
return new ObjCARCExpand();
}
void ObjCARCExpand::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
}
bool ObjCARCExpand::doInitialization(Module &M) {
Run = ModuleHasARC(M);
return false;
}
bool ObjCARCExpand::runOnFunction(Function &F) {
static bool runImpl(Function &F) {
if (!EnableARCOpts)
return false;
// If nothing in the Module uses ARC, don't do anything.
if (!Run)
if (!ModuleHasARC(*F.getParent()))
return false;
bool Changed = false;
@ -126,3 +90,37 @@ bool ObjCARCExpand::runOnFunction(Function &F) {
return Changed;
}
/// Early ARC transformations.
class ObjCARCExpand : public FunctionPass {
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnFunction(Function &F) override;
public:
static char ID;
ObjCARCExpand() : FunctionPass(ID) {
initializeObjCARCExpandPass(*PassRegistry::getPassRegistry());
}
};
} // namespace
char ObjCARCExpand::ID = 0;
INITIALIZE_PASS(ObjCARCExpand, "objc-arc-expand", "ObjC ARC expansion", false,
false)
Pass *llvm::createObjCARCExpandPass() { return new ObjCARCExpand(); }
void ObjCARCExpand::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
}
bool ObjCARCExpand::runOnFunction(Function &F) { return runImpl(F); }
PreservedAnalyses ObjCARCExpandPass::run(Function &F,
FunctionAnalysisManager &AM) {
if (!runImpl(F))
return PreservedAnalyses::all();
PreservedAnalyses PA;
PA.preserveSet<CFGAnalyses>();
return PA;
}

View File

@ -1,4 +1,5 @@
; RUN: opt -objc-arc-expand -S < %s | FileCheck %s
; RUN: opt -passes=objc-arc-expand -S < %s | FileCheck %s
target datalayout = "e-p:64:64:64"