* If compiling on X86 or Sparc, automagically enable the JIT for that arch
* Setting ENABLE_X86_JIT or ENABLE_SPARC_JIT on the `make' command-line will
  force the inclusion of that JIT on a different architecture
* If neither JIT is enabled (e.g., compiling on a different architecture), the
  -march option will not be available to LLI.
* As a side effect of the $ARCH variable, the Sparc LLI can now link just a bit
  faster by not including the x86 library.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7070 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index 44875df..ef47884 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -14,24 +14,31 @@
 // FIXME: REMOVE THIS
 #include "llvm/PassManager.h"
 
-namespace {
-  enum ArchName { nojit, x86, Sparc };
+#if !defined(ENABLE_X86_JIT) && !defined(ENABLE_SPARC_JIT)
+#define NO_JITS_ENABLED
+#endif
 
+namespace {
+  enum ArchName { x86, Sparc };
+
+#ifndef NO_JITS_ENABLED
   cl::opt<ArchName>
   Arch("march", cl::desc("Architecture to JIT to:"), cl::Prefix,
-       cl::values(clEnumVal(x86, "  IA-32 (pentium and above)"),
-#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
+       cl::values(
+#ifdef ENABLE_X86_JIT
+                  clEnumVal(x86, "  IA-32 (Pentium and above)"),
+#endif
+#ifdef ENABLE_SPARC_JIT
                   clEnumValN(Sparc, "sparc", "  Sparc-V9"),
 #endif
                   0),
-#if defined(i386) || defined(__i386__) || defined(__x86__)
+#if defined(ENABLE_X86_JIT)
   cl::init(x86)
-#elif defined(sparc) || defined(__sparc__) || defined(__sparcv9)
+#elif defined(ENABLE_SPARC_JIT)
   cl::init(Sparc)
-#else
-  cl::init(nojit)
 #endif
        );
+#endif /* NO_JITS_ENABLED */
 }
 
 /// createJIT - Create an return a new JIT compiler if there is one available
@@ -43,20 +50,24 @@
 
   // Allow a command-line switch to override what *should* be the default target
   // machine for this platform. This allows for debugging a Sparc JIT on X86 --
-  // our X86 machines are much faster at recompiling LLVM and linking lli.
+  // our X86 machines are much faster at recompiling LLVM and linking LLI.
+#ifdef NO_JITS_ENABLED
+  return 0;
+#endif
+
   switch (Arch) {
+#ifdef ENABLE_X86_JIT
   case x86:
     TargetMachineAllocator = allocateX86TargetMachine;
     break;
-#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
+#endif
+#ifdef ENABLE_SPARC_JIT
   case Sparc:
     TargetMachineAllocator = allocateSparcTargetMachine;
     break;
 #endif
   default:
     assert(0 && "-march flag not supported on this host!");
-  case nojit:
-    return 0;
   }
 
   // Allocate a target...
@@ -75,7 +86,7 @@
 
   setupPassManager();
 
-#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
+#ifdef ENABLE_SPARC_JIT
   // THIS GOES BEYOND UGLY HACKS
   if (TM.getName() == "UltraSparc-Native") {
     extern Pass *createPreSelectionPass(TargetMachine &TM);
diff --git a/lib/ExecutionEngine/JIT/Makefile b/lib/ExecutionEngine/JIT/Makefile
index bc3f709..95b89ae 100644
--- a/lib/ExecutionEngine/JIT/Makefile
+++ b/lib/ExecutionEngine/JIT/Makefile
@@ -1,4 +1,29 @@
 LEVEL = ../../..
 LIBRARYNAME = lli-jit
 
+# Get the $(ARCH) setting
+include $(LEVEL)/Makefile.config
+
+# Enable the X86 JIT if compiling on X86
+ifeq ($(ARCH), x86)
+  ENABLE_X86_JIT = 1
+endif
+
+# This flag can also be used on the command line to force inclusion
+# of the X86 JIT on non-X86 hosts
+ifdef ENABLE_X86_JIT
+  CPPFLAGS += -DENABLE_X86_JIT
+endif
+
+# Enable the X86 JIT if compiling on X86
+ifeq ($(ARCH), Sparc)
+  ENABLE_SPARC_JIT = 1
+endif
+
+# This flag can also be used on the command line to force inclusion
+# of the Sparc JIT on non-Sparc hosts
+ifdef ENABLE_SPARC_JIT
+  CPPFLAGS += -DENABLE_SPARC_JIT
+endif
+
 include $(LEVEL)/Makefile.common
diff --git a/lib/ExecutionEngine/Makefile b/lib/ExecutionEngine/Makefile
index d74adf9..7e08ca2 100644
--- a/lib/ExecutionEngine/Makefile
+++ b/lib/ExecutionEngine/Makefile
@@ -2,25 +2,41 @@
 TOOLNAME = lli
 PARALLEL_DIRS = Interpreter JIT
 
-# Get the config name...
+# Get the $(ARCH) setting
 include $(LEVEL)/Makefile.config
 
 # Generic JIT libraries
 JITLIBS   = lli-jit codegen
 ARCHLIBS  =
 
+# You can enable the X86 JIT on a non-X86 host by setting the flag
+# ENABLE_X86_JIT on the make command line. If not, it will still be
+# enabled automagically on an X86 host.
+ifeq ($(ARCH), x86)
+  ENABLE_X86_JIT = 1
+endif
+
 # What the X86 JIT requires
-JITLIBS  += x86
-# X86 doesn't require any ARCHLIBS
+ifdef ENABLE_X86_JIT
+  CPPFLAGS += -DENABLE_X86_JIT
+  JITLIBS  += x86
+  # X86 doesn't require any ARCHLIBS
+endif
 
-
+# You can enable the Sparc JIT on a non-Sparc host by setting the flag
+# ENABLE_SPARC_JIT on the make command line. If not, it will still be
+# enabled automagically on an Sparc host.
+ifeq ($(ARCH), Sparc)
+  ENABLE_SPARC_JIT = 1
+endif
 
 # What the Sparc JIT requires
-ifeq ($(ARCH),Sparc)
-JITLIBS  += sparc 
-ARCHLIBS  = sched livevar instrument.a profpaths \
-           bcwriter transforms.a ipo.a ipa.a datastructure.a regalloc \
-           mapping select postopts.a preopts
+ifdef ENABLE_SPARC_JIT
+  CPPFLAGS += -DENABLE_SPARC_JIT
+  JITLIBS  += sparc 
+  ARCHLIBS += sched livevar instrument.a profpaths \
+              bcwriter transforms.a ipo.a ipa.a datastructure.a regalloc \
+              mapping select postopts.a preopts
 endif
 
 USEDLIBS = lli-interpreter $(JITLIBS) $(ARCHLIBS) scalaropts analysis.a \
diff --git a/tools/lli/Makefile b/tools/lli/Makefile
index d74adf9..7e08ca2 100644
--- a/tools/lli/Makefile
+++ b/tools/lli/Makefile
@@ -2,25 +2,41 @@
 TOOLNAME = lli
 PARALLEL_DIRS = Interpreter JIT
 
-# Get the config name...
+# Get the $(ARCH) setting
 include $(LEVEL)/Makefile.config
 
 # Generic JIT libraries
 JITLIBS   = lli-jit codegen
 ARCHLIBS  =
 
+# You can enable the X86 JIT on a non-X86 host by setting the flag
+# ENABLE_X86_JIT on the make command line. If not, it will still be
+# enabled automagically on an X86 host.
+ifeq ($(ARCH), x86)
+  ENABLE_X86_JIT = 1
+endif
+
 # What the X86 JIT requires
-JITLIBS  += x86
-# X86 doesn't require any ARCHLIBS
+ifdef ENABLE_X86_JIT
+  CPPFLAGS += -DENABLE_X86_JIT
+  JITLIBS  += x86
+  # X86 doesn't require any ARCHLIBS
+endif
 
-
+# You can enable the Sparc JIT on a non-Sparc host by setting the flag
+# ENABLE_SPARC_JIT on the make command line. If not, it will still be
+# enabled automagically on an Sparc host.
+ifeq ($(ARCH), Sparc)
+  ENABLE_SPARC_JIT = 1
+endif
 
 # What the Sparc JIT requires
-ifeq ($(ARCH),Sparc)
-JITLIBS  += sparc 
-ARCHLIBS  = sched livevar instrument.a profpaths \
-           bcwriter transforms.a ipo.a ipa.a datastructure.a regalloc \
-           mapping select postopts.a preopts
+ifdef ENABLE_SPARC_JIT
+  CPPFLAGS += -DENABLE_SPARC_JIT
+  JITLIBS  += sparc 
+  ARCHLIBS += sched livevar instrument.a profpaths \
+              bcwriter transforms.a ipo.a ipa.a datastructure.a regalloc \
+              mapping select postopts.a preopts
 endif
 
 USEDLIBS = lli-interpreter $(JITLIBS) $(ARCHLIBS) scalaropts analysis.a \