#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/ScopedNoAliasAA.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/CodeGen/BasicBlockSectionsProfileReader.h"
#include "llvm/CodeGen/CSEConfigBase.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachinePassRegistry.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/RegAllocRegistry.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/PassInstrumentation.h"
#include "llvm/IR/Verifier.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Pass.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Discriminator.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Target/CGPassBuilderOption.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils.h"
#include <cassert>
#include <optional>
#include <string>
usingnamespacellvm;
static cl::opt<bool>
EnableIPRA("enable-ipra", cl::init(false), cl::Hidden,
cl::desc("Enable interprocedural register allocation "
"to reduce load/store at procedure calls."));
static cl::opt<bool> DisablePostRASched("disable-post-ra", cl::Hidden,
cl::desc("Disable Post Regalloc Scheduler"));
static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden,
cl::desc("Disable branch folding"));
static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden,
cl::desc("Disable tail duplication"));
static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden,
cl::desc("Disable pre-register allocation tail duplication"));
static cl::opt<bool> DisableBlockPlacement("disable-block-placement",
cl::Hidden, cl::desc("Disable probability-driven block placement"));
static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats",
cl::Hidden, cl::desc("Collect probability-driven block placement stats"));
static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden,
cl::desc("Disable Stack Slot Coloring"));
static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden,
cl::desc("Disable Machine Dead Code Elimination"));
static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden,
cl::desc("Disable Early If-conversion"));
static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden,
cl::desc("Disable Machine LICM"));
static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden,
cl::desc("Disable Machine Common Subexpression Elimination"));
static cl::opt<cl::boolOrDefault> OptimizeRegAlloc(
"optimize-regalloc", cl::Hidden,
cl::desc("Enable optimized register allocation compilation path."));
static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm",
cl::Hidden,
cl::desc("Disable Machine LICM"));
static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden,
cl::desc("Disable Machine Sinking"));
static cl::opt<bool> DisablePostRAMachineSink("disable-postra-machine-sink",
cl::Hidden,
cl::desc("Disable PostRA Machine Sinking"));
static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden,
cl::desc("Disable Loop Strength Reduction Pass"));
static cl::opt<bool> DisableConstantHoisting("disable-constant-hoisting",
cl::Hidden, cl::desc("Disable ConstantHoisting"));
static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden,
cl::desc("Disable Codegen Prepare"));
static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden,
cl::desc("Disable Copy Propagation pass"));
static cl::opt<bool> DisablePartialLibcallInlining("disable-partial-libcall-inlining",
cl::Hidden, cl::desc("Disable Partial Libcall Inlining"));
static cl::opt<bool> DisableAtExitBasedGlobalDtorLowering(
"disable-atexit-based-global-dtor-lowering", cl::Hidden,
cl::desc("For MachO, disable atexit()-based global destructor lowering"));
static cl::opt<bool> EnableImplicitNullChecks(
"enable-implicit-null-checks",
cl::desc("Fold null checks into faulting memory operations"),
cl::init(false), cl::Hidden);
static cl::opt<bool> DisableMergeICmps("disable-mergeicmps",
cl::desc("Disable MergeICmps Pass"),
cl::init(false), cl::Hidden);
static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
cl::desc("Print LLVM IR produced by the loop-reduce pass"));
static cl::opt<bool>
PrintISelInput("print-isel-input", cl::Hidden,
cl::desc("Print LLVM IR input to isel pass"));
static cl::opt<cl::boolOrDefault>
VerifyMachineCode("verify-machineinstrs", cl::Hidden,
cl::desc("Verify generated machine code"));
static cl::opt<cl::boolOrDefault>
DebugifyAndStripAll("debugify-and-strip-all-safe", cl::Hidden,
cl::desc("Debugify MIR before and Strip debug after "
"each pass except those known to be unsafe "
"when debug info is present"));
static cl::opt<cl::boolOrDefault> DebugifyCheckAndStripAll(
"debugify-check-and-strip-all-safe", cl::Hidden,
cl::desc(
"Debugify MIR before, by checking and stripping the debug info after, "
"each pass except those known to be unsafe when debug info is "
"present"));
static cl::opt<RunOutliner> EnableMachineOutliner(
"enable-machine-outliner", cl::desc("Enable the machine outliner"),
cl::Hidden, cl::ValueOptional, cl::init(RunOutliner::TargetDefault),
cl::values(clEnumValN(RunOutliner::AlwaysOutline, "always",
"Run on all functions guaranteed to be beneficial"),
clEnumValN(RunOutliner::NeverOutline, "never",
"Disable all outlining"),
clEnumValN(RunOutliner::AlwaysOutline, "", "")));
static cl::opt<bool> DisableCFIFixup("disable-cfi-fixup", cl::Hidden,
cl::desc("Disable the CFI fixup pass"));
static cl::opt<cl::boolOrDefault>
EnableFastISelOption("fast-isel", cl::Hidden,
cl::desc("Enable the \"fast\" instruction selector"));
static cl::opt<cl::boolOrDefault> EnableGlobalISelOption(
"global-isel", cl::Hidden,
cl::desc("Enable the \"global\" instruction selector"));
static cl::opt<bool>
PrintAfterISel("print-after-isel", cl::init(false), cl::Hidden,
cl::desc("Print machine instrs after ISel"));
static cl::opt<GlobalISelAbortMode> EnableGlobalISelAbort(
"global-isel-abort", cl::Hidden,
cl::desc("Enable abort calls when \"global\" instruction selection "
"fails to lower/select an instruction"),
cl::values(
clEnumValN(GlobalISelAbortMode::Disable, "0", "Disable the abort"),
clEnumValN(GlobalISelAbortMode::Enable, "1", "Enable the abort"),
clEnumValN(GlobalISelAbortMode::DisableWithDiag, "2",
"Disable the abort but emit a diagnostic on failure")));
static cl::opt<bool> DisableRAFSProfileLoader(
"disable-ra-fsprofile-loader", cl::init(false), cl::Hidden,
cl::desc("Disable MIRProfileLoader before RegAlloc"));
static cl::opt<bool> DisableLayoutFSProfileLoader(
"disable-layout-fsprofile-loader", cl::init(false), cl::Hidden,
cl::desc("Disable MIRProfileLoader before BlockPlacement"));
static cl::opt<std::string>
FSProfileFile("fs-profile-file", cl::init(""), cl::value_desc("filename"),
cl::desc("Flow Sensitive profile file name."), cl::Hidden);
static cl::opt<std::string> FSRemappingFile(
"fs-remapping-file", cl::init(""), cl::value_desc("filename"),
cl::desc("Flow Sensitive profile remapping file name."), cl::Hidden);
static cl::opt<bool> MISchedPostRA(
"misched-postra", cl::Hidden,
cl::desc(
"Run MachineScheduler post regalloc (independent of preRA sched)"));
static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden,
cl::desc("Run live interval analysis earlier in the pipeline"));
static cl::opt<bool> DisableReplaceWithVecLib(
"disable-replace-with-vec-lib", cl::Hidden,
cl::desc("Disable replace with vector math call pass"));
static const char StartAfterOptName[] = …;
static const char StartBeforeOptName[] = …;
static const char StopAfterOptName[] = …;
static const char StopBeforeOptName[] = …;
static cl::opt<std::string>
StartAfterOpt(StringRef(StartAfterOptName),
cl::desc("Resume compilation after a specific pass"),
cl::value_desc("pass-name"), cl::init(""), cl::Hidden);
static cl::opt<std::string>
StartBeforeOpt(StringRef(StartBeforeOptName),
cl::desc("Resume compilation before a specific pass"),
cl::value_desc("pass-name"), cl::init(""), cl::Hidden);
static cl::opt<std::string>
StopAfterOpt(StringRef(StopAfterOptName),
cl::desc("Stop compilation after a specific pass"),
cl::value_desc("pass-name"), cl::init(""), cl::Hidden);
static cl::opt<std::string>
StopBeforeOpt(StringRef(StopBeforeOptName),
cl::desc("Stop compilation before a specific pass"),
cl::value_desc("pass-name"), cl::init(""), cl::Hidden);
static cl::opt<bool> EnableMachineFunctionSplitter(
"enable-split-machine-functions", cl::Hidden,
cl::desc("Split out cold blocks from machine functions based on profile "
"information."));
static cl::opt<bool> DisableExpandReductions(
"disable-expand-reductions", cl::init(false), cl::Hidden,
cl::desc("Disable the expand reduction intrinsics pass from running"));
static cl::opt<bool> DisableSelectOptimize(
"disable-select-optimize", cl::init(true), cl::Hidden,
cl::desc("Disable the select-optimization pass from running"));
static cl::opt<bool>
GCEmptyBlocks("gc-empty-basic-blocks", cl::init(false), cl::Hidden,
cl::desc("Enable garbage-collecting empty basic blocks"));
static IdentifyingPassPtr applyDisable(IdentifyingPassPtr PassID,
bool Override) { … }
static IdentifyingPassPtr overridePass(AnalysisID StandardID,
IdentifyingPassPtr TargetID) { … }
static std::string getFSProfileFile(const TargetMachine *TM) { … }
static std::string getFSRemappingFile(const TargetMachine *TM) { … }
INITIALIZE_PASS(…)
char TargetPassConfig::ID = …;
namespace {
struct InsertedPass { … };
}
namespace llvm {
extern cl::opt<bool> EnableFSDiscriminator;
class PassConfigImpl { … };
}
TargetPassConfig::~TargetPassConfig() { … }
static const PassInfo *getPassInfo(StringRef PassName) { … }
static AnalysisID getPassIDFromName(StringRef PassName) { … }
static std::pair<StringRef, unsigned>
getPassNameAndInstanceNum(StringRef PassName) { … }
void TargetPassConfig::setStartStopPasses() { … }
CGPassBuilderOption llvm::getCGPassBuilderOption() { … }
void llvm::registerCodeGenCallback(PassInstrumentationCallbacks &PIC,
LLVMTargetMachine &LLVMTM) { … }
Expected<TargetPassConfig::StartStopInfo>
TargetPassConfig::getStartStopInfo(PassInstrumentationCallbacks &PIC) { … }
TargetPassConfig::TargetPassConfig(LLVMTargetMachine &TM, PassManagerBase &pm)
: … { … }
CodeGenOptLevel TargetPassConfig::getOptLevel() const { … }
void TargetPassConfig::insertPass(AnalysisID TargetPassID,
IdentifyingPassPtr InsertedPassID) { … }
TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) { … }
TargetPassConfig::TargetPassConfig()
: … { … }
bool TargetPassConfig::willCompleteCodeGenPipeline() { … }
bool TargetPassConfig::hasLimitedCodeGenPipeline() { … }
std::string TargetPassConfig::getLimitedCodeGenPipelineReason() { … }
void TargetPassConfig::setOpt(bool &Opt, bool Val) { … }
void TargetPassConfig::substitutePass(AnalysisID StandardID,
IdentifyingPassPtr TargetID) { … }
IdentifyingPassPtr TargetPassConfig::getPassSubstitution(AnalysisID ID) const { … }
bool TargetPassConfig::isPassSubstitutedOrOverridden(AnalysisID ID) const { … }
void TargetPassConfig::addPass(Pass *P) { … }
AnalysisID TargetPassConfig::addPass(AnalysisID PassID) { … }
void TargetPassConfig::printAndVerify(const std::string &Banner) { … }
void TargetPassConfig::addPrintPass(const std::string &Banner) { … }
void TargetPassConfig::addVerifyPass(const std::string &Banner) { … }
void TargetPassConfig::addDebugifyPass() { … }
void TargetPassConfig::addStripDebugPass() { … }
void TargetPassConfig::addCheckDebugPass() { … }
void TargetPassConfig::addMachinePrePasses(bool AllowDebugify) { … }
void TargetPassConfig::addMachinePostPasses(const std::string &Banner) { … }
void TargetPassConfig::addIRPasses() { … }
void TargetPassConfig::addPassesToHandleExceptions() { … }
void TargetPassConfig::addCodeGenPrepare() { … }
void TargetPassConfig::addISelPrepare() { … }
bool TargetPassConfig::addCoreISelPasses() { … }
bool TargetPassConfig::addISelPasses() { … }
static FunctionPass *useDefaultRegisterAllocator() { … }
static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
RegisterPassParser<RegisterRegAlloc>>
RegAlloc("regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
cl::desc("Register allocator to use"));
void TargetPassConfig::addMachinePasses() { … }
void TargetPassConfig::addMachineSSAOptimization() { … }
bool TargetPassConfig::getOptimizeRegAlloc() const { … }
static llvm::once_flag InitializeDefaultRegisterAllocatorFlag;
static RegisterRegAlloc
defaultRegAlloc("default",
"pick register allocator based on -O option",
useDefaultRegisterAllocator);
static void initializeDefaultRegisterAllocatorOnce() { … }
FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) { … }
FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) { … }
bool TargetPassConfig::isCustomizedRegAlloc() { … }
bool TargetPassConfig::addRegAssignAndRewriteFast() { … }
bool TargetPassConfig::addRegAssignAndRewriteOptimized() { … }
bool TargetPassConfig::usingDefaultRegAlloc() const { … }
void TargetPassConfig::addFastRegAlloc() { … }
void TargetPassConfig::addOptimizedRegAlloc() { … }
void TargetPassConfig::addMachineLateOptimization() { … }
bool TargetPassConfig::addGCPasses() { … }
void TargetPassConfig::addBlockPlacement() { … }
bool TargetPassConfig::isGlobalISelAbortEnabled() const { … }
bool TargetPassConfig::reportDiagnosticWhenGlobalISelFallback() const { … }
bool TargetPassConfig::isGISelCSEEnabled() const { … }
std::unique_ptr<CSEConfigBase> TargetPassConfig::getCSEConfig() const { … }