[GlobalISel] Add a hook in TargetConfigPass to run GlobalISel.

llvm-svn: 260553
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 16357de..0e61716 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -42,6 +42,12 @@
 EnableFastISelOption("fast-isel", cl::Hidden,
   cl::desc("Enable the \"fast\" instruction selector"));
 
+#ifdef LLVM_BUILD_GLOBAL_ISEL
+static cl::opt<bool>
+    EnableGlobalISel("global-isel", cl::Hidden, cl::init(false),
+                     cl::desc("Enable the \"global\" instruction selector"));
+#endif
+
 void LLVMTargetMachine::initAsmInfo() {
   MRI = TheTarget.createMCRegInfo(getTargetTriple().str());
   MII = TheTarget.createMCInstrInfo();
@@ -135,8 +141,14 @@
        TM->getO0WantsFastISel()))
     TM->setFastISel(true);
 
-  // Ask the target for an isel.
-  if (PassConfig->addInstSelector())
+#ifdef LLVM_BUILD_GLOBAL_ISEL
+  if (EnableGlobalISel) {
+    if (PassConfig->addIRTranslator())
+      return nullptr;
+  } else
+#endif
+      // Ask the target for an isel.
+      if (PassConfig->addInstSelector())
     return nullptr;
 
   PassConfig->addMachinePasses();