Skip to content

Commit

Permalink
Port -objc-arc-expand to NPM
Browse files Browse the repository at this point in the history
Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D90182
  • Loading branch information
aeubanks committed Oct 27, 2020
1 parent 90c0b0d commit 3dd1c72
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
4 changes: 4 additions & 0 deletions llvm/include/llvm/Transforms/ObjCARC.h
Expand Up @@ -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
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Expand Up @@ -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()))
Expand Down
78 changes: 38 additions & 40 deletions llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp
Expand Up @@ -27,64 +27,28 @@
#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"
#include "llvm/PassRegistry.h"
#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;
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions llvm/test/Transforms/ObjCARC/expand.ll
@@ -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"

Expand Down

0 comments on commit 3dd1c72

Please sign in to comment.