From b424c9db34e2ead1f9000366813ccf7991e9b941 Mon Sep 17 00:00:00 2001 From: Ahmed Bougacha Date: Wed, 1 Mar 2017 23:33:08 +0000 Subject: [PATCH] [GlobalISel] Add a way for targets to enable GISel. Until now, we've had to use -global-isel to enable GISel. But using that on other targets that don't support it will result in an abort, as we can't build a full pipeline. Additionally, we want to experiment with enabling GISel by default for some targets: we can't just enable GISel by default, even among those target that do have some support, because the level of support varies. This first step adds an override for the target to explicitly define its level of support. For AArch64, do that using a new command-line option (I know..): -aarch64-enable-global-isel-at-O= Where N is the opt-level below which GISel should be used. Default that to -1, so that we still don't enable GISel anywhere. We're not there yet! While there, remove a couple LLVM_UNLIKELYs. Building the pipeline is such a cold path that in practice that shouldn't matter at all. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296710 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/TargetPassConfig.h | 4 ++ lib/CodeGen/LLVMTargetMachine.cpp | 10 +++-- lib/CodeGen/TargetPassConfig.cpp | 5 +++ lib/Target/AArch64/AArch64TargetMachine.cpp | 11 +++++ .../AArch64/GlobalISel/gisel-commandline-option.ll | 48 ++++++++++++++++++++++ 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 test/CodeGen/AArch64/GlobalISel/gisel-commandline-option.ll diff --git a/include/llvm/CodeGen/TargetPassConfig.h b/include/llvm/CodeGen/TargetPassConfig.h index 2287f9aca4b..2156e87872f 100644 --- a/include/llvm/CodeGen/TargetPassConfig.h +++ b/include/llvm/CodeGen/TargetPassConfig.h @@ -286,6 +286,10 @@ public: /// verification is enabled. void addVerifyPass(const std::string &Banner); + /// Check whether or not GlobalISel should be enabled by default. + /// Fallback/abort behavior is controlled via other methods. + virtual bool isGlobalISelEnabled() const; + /// Check whether or not GlobalISel should abort on error. /// When this is disable, GlobalISel will fall back on SDISel instead of /// erroring out. diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index 367fd66304a..7b1706f0f4b 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -42,8 +42,8 @@ static cl::opt EnableFastISelOption("fast-isel", cl::Hidden, cl::desc("Enable the \"fast\" instruction selector")); -static cl::opt - EnableGlobalISel("global-isel", cl::Hidden, cl::init(false), +static cl::opt + EnableGlobalISel("global-isel", cl::Hidden, cl::desc("Enable the \"global\" instruction selector")); void LLVMTargetMachine::initAsmInfo() { @@ -149,7 +149,9 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM, TM->setFastISel(true); // Ask the target for an isel. - if (LLVM_UNLIKELY(EnableGlobalISel)) { + // Enable GlobalISel if the target wants to, but allow that to be overriden. + if (EnableGlobalISel == cl::BOU_TRUE || (EnableGlobalISel == cl::BOU_UNSET && + PassConfig->isGlobalISelEnabled())) { if (PassConfig->addIRTranslator()) return nullptr; @@ -177,7 +179,7 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM, // Provide a fallback path when we do not want to abort on // not-yet-supported input. - if (LLVM_UNLIKELY(!PassConfig->isGlobalISelAbortEnabled()) && + if (!PassConfig->isGlobalISelAbortEnabled() && PassConfig->addInstSelector()) return nullptr; diff --git a/lib/CodeGen/TargetPassConfig.cpp b/lib/CodeGen/TargetPassConfig.cpp index 30d45b7b750..271f5c3c94e 100644 --- a/lib/CodeGen/TargetPassConfig.cpp +++ b/lib/CodeGen/TargetPassConfig.cpp @@ -910,6 +910,11 @@ void TargetPassConfig::addBlockPlacement() { //===---------------------------------------------------------------------===// /// GlobalISel Configuration //===---------------------------------------------------------------------===// + +bool TargetPassConfig::isGlobalISelEnabled() const { + return false; +} + bool TargetPassConfig::isGlobalISelAbortEnabled() const { return EnableGlobalISelAbort == 1; } diff --git a/lib/Target/AArch64/AArch64TargetMachine.cpp b/lib/Target/AArch64/AArch64TargetMachine.cpp index 3368c984187..db79eed709e 100644 --- a/lib/Target/AArch64/AArch64TargetMachine.cpp +++ b/lib/Target/AArch64/AArch64TargetMachine.cpp @@ -139,6 +139,11 @@ static cl::opt cl::desc("Enable the loop data prefetch pass"), cl::init(true)); +static cl::opt EnableGlobalISelAtO( + "aarch64-enable-global-isel-at-O", cl::Hidden, + cl::desc("Enable GlobalISel at or below an opt level (-1 to disable)"), + cl::init(-1)); + extern "C" void LLVMInitializeAArch64Target() { // Register the target. RegisterTargetMachine X(getTheAArch64leTarget()); @@ -358,6 +363,8 @@ public: void addPostRegAlloc() override; void addPreSched2() override; void addPreEmitPass() override; + + bool isGlobalISelEnabled() const override; }; } // end anonymous namespace @@ -467,6 +474,10 @@ bool AArch64PassConfig::addGlobalInstructionSelect() { } #endif +bool AArch64PassConfig::isGlobalISelEnabled() const { + return TM->getOptLevel() <= EnableGlobalISelAtO; +} + bool AArch64PassConfig::addILPOpts() { if (EnableCondOpt) addPass(createAArch64ConditionOptimizerPass()); diff --git a/test/CodeGen/AArch64/GlobalISel/gisel-commandline-option.ll b/test/CodeGen/AArch64/GlobalISel/gisel-commandline-option.ll new file mode 100644 index 00000000000..3ecdb7bbedf --- /dev/null +++ b/test/CodeGen/AArch64/GlobalISel/gisel-commandline-option.ll @@ -0,0 +1,48 @@ +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: -O0 -aarch64-enable-global-isel-at-O=0 \ +; RUN: | FileCheck %s --check-prefix ENABLED --check-prefix NOFALLBACK + +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: -O0 -aarch64-enable-global-isel-at-O=0 -global-isel-abort=2 \ +; RUN: | FileCheck %s --check-prefix ENABLED --check-prefix FALLBACK + +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: -global-isel \ +; RUN: | FileCheck %s --check-prefix ENABLED --check-prefix NOFALLBACK + +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: -global-isel -global-isel-abort=2 \ +; RUN: | FileCheck %s --check-prefix ENABLED --check-prefix FALLBACK + +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: -O1 -aarch64-enable-global-isel-at-O=3 \ +; RUN: | FileCheck %s --check-prefix ENABLED + +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: -O1 -aarch64-enable-global-isel-at-O=0 \ +; RUN: | FileCheck %s --check-prefix DISABLED + +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: -aarch64-enable-global-isel-at-O=-1 \ +; RUN: | FileCheck %s --check-prefix DISABLED + +; RUN: llc -mtriple=aarch64-- -debug-pass=Structure %s -o /dev/null 2>&1 \ +; RUN: | FileCheck %s --check-prefix DISABLED + +; ENABLED: IRTranslator +; ENABLED-NEXT: Legalizer +; ENABLED-NEXT: RegBankSelect +; ENABLED-NEXT: InstructionSelect +; ENABLED-NEXT: ResetMachineFunction + +; FALLBACK: AArch64 Instruction Selection +; NOFALLBACK-NOT: AArch64 Instruction Selection + +; DISABLED-NOT: IRTranslator + +; DISABLED: AArch64 Instruction Selection +; DISABLED: Expand ISel Pseudo-instructions + +define void @empty() { + ret void +} -- 2.11.0