From ffe3053a66ff0295218abe7a3ac5015a70b192cf Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Sat, 1 Apr 2017 01:21:24 +0000 Subject: 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 --- llvm/lib/Target/TargetMachine.cpp | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'llvm/lib/Target/TargetMachine.cpp') 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 + StartAfterOpt(StringRef(TargetMachine::StartAfterOptName), + cl::desc("Resume compilation after a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + +static cl::opt + StartBeforeOpt(StringRef(TargetMachine::StartBeforeOptName), + cl::desc("Resume compilation before a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + +static cl::opt + StopAfterOpt(StringRef(TargetMachine::StopAfterOptName), + cl::desc("Stop compilation after a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + +static cl::opt + StopBeforeOpt(StringRef(TargetMachine::StopBeforeOptName), + cl::desc("Stop compilation before a specific pass"), + cl::value_desc("pass-name"), cl::init("")); + cl::opt 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 *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_; } -- cgit v1.2.3