Subzero: Allow Makefile.standalone to build for a single target.

This makes it easier to focus on reducing the translator size.

Enable with e.g.:
  make -f Makefile.standalone MINIMAL=1 SZTARGET=X8664 bloat-sb

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4362
R=jpp@chromium.org

Review URL: https://codereview.chromium.org/1787143002 .
diff --git a/Makefile.standalone b/Makefile.standalone
index 0949b66..40d9692 100644
--- a/Makefile.standalone
+++ b/Makefile.standalone
@@ -100,6 +100,16 @@
   BASE_CXX_DEFINES += -DALLOW_DUMP=1
 endif
 
+# Restrict to a single supported target.  Current options:
+#   SZTARGET=ARM32
+#   SZTARGET=MIPS32
+#   SZTARGET=X8632
+#   SZTARGET=X8664
+ifdef SZTARGET
+  OBJDIR := $(OBJDIR)+T_$(SZTARGET)
+  BASE_CXX_DEFINES += -DSZTARGET=$(SZTARGET)
+endif
+
 CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
 
 ifdef NOASSERT
diff --git a/Makefile.standalone-help/help.txt b/Makefile.standalone-help/help.txt
index 4bf2f3a..d005fc7 100644
--- a/Makefile.standalone-help/help.txt
+++ b/Makefile.standalone-help/help.txt
@@ -3,7 +3,32 @@
 check-lit - run the lit tests
 check-xtest - run the cross tests
 
- For more detailed help:
+Additional 'make' command options:
+  MINIMAL=1
+    Create a minimal build, as small and fast as possible
+  DEBUG=1
+    Compile with -O0 instead of -O2
+  NODUMP=1
+    Disable textual dump/emission support and other verbose options
+  NOASSERT=1
+    Disable assert() calls, via -DNDEBUG
+  UBSAN=1
+    Enable UBSan support, i.e. -fsanitize=undefined
+  UBSAN_TRAP=1
+    Enable UBSan support, trapping on errors
+  TSAN=1
+    Enable TSan support, i.e. -fsanitize=thread
+  ASAN=1
+    Enable ASan support, i.e. -fsanitize=address
+  MSAN=1
+    Enable MSan support, i.e. -fsanitize=memory
+  SZTARGET=<target>
+    Restrict support to a single processor target,
+    where <target> is one of {ARM32,MIPS32,X8632,X8664}
+Most of these options can be combined, e.g.
+  make -f Makefile.standalone NOASSERT=1 NODUMP=1
 
- make -f Makefile.standalone help-<target> , e.g:
- make -f Makefile.standalone help-check-lit
+For more detailed help on a 'make' target:
+
+  make -f Makefile.standalone help-<target> , e.g:
+  make -f Makefile.standalone help-check-lit
diff --git a/src/IceCompileServer.cpp b/src/IceCompileServer.cpp
index e423032..7b9f781 100644
--- a/src/IceCompileServer.cpp
+++ b/src/IceCompileServer.cpp
@@ -142,7 +142,7 @@
 void dumpBuildAttributes(Ostream &Str) {
 // List the supported targets.
 #define SUBZERO_TARGET(TARGET) Str << "target_" #TARGET << "\n";
-#include "llvm/Config/SZTargets.def"
+#include "SZTargets.def"
   const char *Prefix[2] = {"no", "allow"};
   for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes);
        ++i) {
diff --git a/src/IceTargetLowering.cpp b/src/IceTargetLowering.cpp
index 1b57750..54d0be4 100644
--- a/src/IceTargetLowering.cpp
+++ b/src/IceTargetLowering.cpp
@@ -27,6 +27,8 @@
 #include "IceOperand.h"
 #include "IceRegAlloc.h"
 
+#define TARGET_LOWERING_CLASS_FOR(t) Target_##t
+
 // We prevent target-specific implementation details from leaking outside their
 // implementations by forbidding #include of target-specific header files
 // anywhere outside their own files. To create target-specific objects
@@ -52,7 +54,7 @@
   createTargetHeaderLowering(::Ice::GlobalContext *Ctx);                       \
   void staticInit(::Ice::GlobalContext *Ctx);                                  \
   } // end of namespace X
-#include "llvm/Config/SZTargets.def"
+#include "SZTargets.def"
 #undef SUBZERO_TARGET
 
 namespace Ice {
@@ -250,9 +252,9 @@
   default:
     badTargetFatalError(Target);
 #define SUBZERO_TARGET(X)                                                      \
-  case Target_##X:                                                             \
+  case TARGET_LOWERING_CLASS_FOR(X):                                           \
     return ::X::createTargetLowering(Func);
-#include "llvm/Config/SZTargets.def"
+#include "SZTargets.def"
 #undef SUBZERO_TARGET
   }
 }
@@ -264,7 +266,7 @@
   default:
     badTargetFatalError(Target);
 #define SUBZERO_TARGET(X)                                                      \
-  case Target_##X: {                                                           \
+  case TARGET_LOWERING_CLASS_FOR(X): {                                         \
     static bool InitGuard##X = false;                                          \
     if (InitGuard##X) {                                                        \
       return;                                                                  \
@@ -272,7 +274,7 @@
     InitGuard##X = true;                                                       \
     ::X::staticInit(Ctx);                                                      \
   } break;
-#include "llvm/Config/SZTargets.def"
+#include "SZTargets.def"
 #undef SUBZERO_TARGET
   }
 }
@@ -746,9 +748,9 @@
   default:
     badTargetFatalError(Target);
 #define SUBZERO_TARGET(X)                                                      \
-  case Target_##X:                                                             \
+  case TARGET_LOWERING_CLASS_FOR(X):                                           \
     return ::X::createTargetDataLowering(Ctx);
-#include "llvm/Config/SZTargets.def"
+#include "SZTargets.def"
 #undef SUBZERO_TARGET
   }
 }
@@ -877,9 +879,9 @@
   default:
     badTargetFatalError(Target);
 #define SUBZERO_TARGET(X)                                                      \
-  case Target_##X:                                                             \
+  case TARGET_LOWERING_CLASS_FOR(X):                                           \
     return ::X::createTargetHeaderLowering(Ctx);
-#include "llvm/Config/SZTargets.def"
+#include "SZTargets.def"
 #undef SUBZERO_TARGET
   }
 }
diff --git a/src/SZTargets.def b/src/SZTargets.def
new file mode 100644
index 0000000..b07ac47
--- /dev/null
+++ b/src/SZTargets.def
@@ -0,0 +1,31 @@
+//===- subzero/src/SZTargets.def - Target enumeration x-macro ---*- C++ -*-===//
+//
+//                        The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides an alternate implementation of llvm/Config/SZTargets.def,
+// such that when SZTARGET is defined, it enumerates the single SZTARGET instead
+// of the complete list.  This can be used to model a proper minimal build for
+// the browser.
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef SZTARGET
+
+#ifndef SUBZERO_TARGET
+#error Please define the macro SUBZERO_TARGET(TargetName)
+#endif
+
+SUBZERO_TARGET(SZTARGET)
+
+#undef SUBZERO_TARGET
+
+#else // !SZTARGET
+
+#include "llvm/Config/SZTargets.def"
+
+#endif // !SZTARGET