summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/CMakeLists.txt1
-rw-r--r--llvm/lib/CodeGen/LLVMTargetMachine.cpp9
-rw-r--r--llvm/lib/CodeGen/ResetMachineFunctionPass.cpp53
3 files changed, 63 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index cc9ed95be59..f68bac98564 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -105,6 +105,7 @@ add_llvm_library(LLVMCodeGen
RegisterUsageInfo.cpp
RegUsageInfoCollector.cpp
RegUsageInfoPropagate.cpp
+ ResetMachineFunctionPass.cpp
SafeStack.cpp
SafeStackColoring.cpp
SafeStackLayout.cpp
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 844e1ffe681..e11eb014111 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -168,6 +168,15 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
if (PassConfig->addGlobalInstructionSelect())
return nullptr;
+ // Pass to reset the MachineFunction if the ISel failed.
+ PM.add(createResetMachineFunctionPass());
+
+ // Provide a fallback path when we do not want to abort on
+ // not-yet-supported input.
+ if (LLVM_UNLIKELY(!PassConfig->isGlobalISelAbortEnabled()) &&
+ PassConfig->addInstSelector())
+ return nullptr;
+
} else if (PassConfig->addInstSelector())
return nullptr;
diff --git a/llvm/lib/CodeGen/ResetMachineFunctionPass.cpp b/llvm/lib/CodeGen/ResetMachineFunctionPass.cpp
new file mode 100644
index 00000000000..3b7729a0540
--- /dev/null
+++ b/llvm/lib/CodeGen/ResetMachineFunctionPass.cpp
@@ -0,0 +1,53 @@
+//===-- ResetMachineFunctionPass.cpp - Machine Loop Invariant Code Motion Pass ---------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/Support/Debug.h"
+using namespace llvm;
+
+#define DEBUG_TYPE "reset-machine-function"
+
+namespace {
+ class ResetMachineFunction : public MachineFunctionPass {
+ public:
+ static char ID; // Pass identification, replacement for typeid
+ ResetMachineFunction() :
+ MachineFunctionPass(ID) {
+ }
+
+ const char *getPassName() const override {
+ return "ResetMachineFunction";
+ }
+
+ bool runOnMachineFunction(MachineFunction &MF) override {
+ if (MF.getProperties().hasProperty(
+ MachineFunctionProperties::Property::FailedISel)) {
+ DEBUG(dbgs() << "Reseting: " << MF.getName() << '\n');
+ MF.reset();
+ return true;
+ }
+ return false;
+ }
+
+ };
+} // end anonymous namespace
+
+char ResetMachineFunction::ID = 0;
+INITIALIZE_PASS(ResetMachineFunction, DEBUG_TYPE,
+ "reset machine function if ISel failed", false, false)
+
+MachineFunctionPass *
+llvm::createResetMachineFunctionPass() {
+ return new ResetMachineFunction();
+}
OpenPOWER on IntegriCloud