diff options
author | Quentin Colombet <qcolombet@apple.com> | 2017-04-01 01:21:24 +0000 |
---|---|---|
committer | Quentin Colombet <qcolombet@apple.com> | 2017-04-01 01:21:24 +0000 |
commit | ffe3053a66ff0295218abe7a3ac5015a70b192cf (patch) | |
tree | d2f8c6b378124119348d6f329b607e06aa616554 /llvm/lib/Target/TargetMachine.cpp | |
parent | 63b6df4f05f0c099fd8c361af24a99709af8c3db (diff) | |
download | bcm5719-llvm-ffe3053a66ff0295218abe7a3ac5015a70b192cf.tar.gz bcm5719-llvm-ffe3053a66ff0295218abe7a3ac5015a70b192cf.zip |
Feature generic option to setup start/stop-after/before
This patch refactors the code used in llc such that all the users of the
addPassesToEmitFile API have access to a homogeneous way of handling
start/stop-after/before options right out of the box.
Previously each user would have needed to duplicate this logic and set
up its own options.
NFC
llvm-svn: 299282
Diffstat (limited to 'llvm/lib/Target/TargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index e8fe0a2b218..357f02ba5ef 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -31,6 +31,31 @@ #include "llvm/Target/TargetSubtargetInfo.h" using namespace llvm; +const char *TargetMachine::StartAfterOptName = "start-after"; +const char *TargetMachine::StartBeforeOptName = "start-before"; +const char *TargetMachine::StopAfterOptName = "stop-after"; +const char *TargetMachine::StopBeforeOptName = "stop-before"; + +static cl::opt<std::string> + StartAfterOpt(StringRef(TargetMachine::StartAfterOptName), + cl::desc("Resume compilation after a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + +static cl::opt<std::string> + StartBeforeOpt(StringRef(TargetMachine::StartBeforeOptName), + cl::desc("Resume compilation before a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + +static cl::opt<std::string> + StopAfterOpt(StringRef(TargetMachine::StopAfterOptName), + cl::desc("Stop compilation after a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + +static cl::opt<std::string> + StopBeforeOpt(StringRef(TargetMachine::StopBeforeOptName), + cl::desc("Stop compilation before a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + cl::opt<bool> EnableIPRA("enable-ipra", cl::init(false), cl::Hidden, cl::desc("Enable interprocedural register allocation " "to reduce load/store at procedure calls.")); @@ -56,6 +81,42 @@ TargetMachine::~TargetMachine() { delete STI; } +AnalysisID TargetMachine::getPassIDForOption(PipelineControlOption Kind, + bool AbortIfNotRegistered) { + static cl::opt<std::string> *PassNames[] = {&StartAfterOpt, &StartBeforeOpt, + &StopAfterOpt, &StopBeforeOpt}; +#define CHECK_OPT(OPTNAME) \ + assert(PassNames[TargetMachine::OPTNAME] == &OPTNAME##Opt && \ + "Static array is messed up for " #OPTNAME); + CHECK_OPT(StartAfter); + CHECK_OPT(StartBefore); + CHECK_OPT(StopAfter); + CHECK_OPT(StopBefore); + static_assert(LastPipelineControlOption == 3, + "The check before needs to be updated"); + return getPassID(*PassNames[Kind], AbortIfNotRegistered); +} + +const PassInfo *TargetMachine::getPassInfo(StringRef PassName, + bool AbortIfNotRegistered) { + if (PassName.empty()) + return nullptr; + + const PassRegistry &PR = *PassRegistry::getPassRegistry(); + const PassInfo *PI = PR.getPassInfo(PassName); + if (!PI && AbortIfNotRegistered) { + errs() << "\"" << PassName << "\" pass is not registered.\n"; + exit(1); + } + return PI; +} + +AnalysisID TargetMachine::getPassID(StringRef PassName, + bool AbortIfNotRegistered) { + const PassInfo *PI = getPassInfo(PassName, AbortIfNotRegistered); + return PI ? PI->getTypeInfo() : nullptr; +} + bool TargetMachine::isPositionIndependent() const { return getRelocationModel() == Reloc::PIC_; } |