Subzero: Allow builds with assertions disabled.

1. Setting command-line make variable NOASSERT=1 adds -DNDEBUG and builds in a separate directory.  By default, we still get Release+Asserts.

2. Add "(void)foo;" as necessary when foo is only used in an assert(), to remove warnings.

3. Minimize inclusion of llvm/Support/Timer.h because it adds warnings.

4. Call validateLiveness() only when asserts are enabled, because it's relatively expensive.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/623493002
diff --git a/Makefile.standalone b/Makefile.standalone
index 175dd12..ae39305 100644
--- a/Makefile.standalone
+++ b/Makefile.standalone
@@ -45,6 +45,13 @@
   OPTLEVEL = -O2
 endif
 
+ifdef NOASSERT
+  ASSERTIONS = -DNDEBUG
+else
+  ASSERTIONS =
+  OBJDIR := $(OBJDIR)+Asserts
+endif
+
 $(info -----------------------------------------------)
 $(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
 $(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH))
@@ -62,7 +69,7 @@
 CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
 
 CXXFLAGS := $(LLVM_CXXFLAGS) -std=c++11 -Wall -Wextra -Werror -fno-rtti \
-	-fno-exceptions $(OPTLEVEL) -g $(HOST_FLAGS) \
+	-fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g $(HOST_FLAGS) \
 	-Wno-error=unused-parameter -I$(LIBCXX_INSTALL_PATH)/include/c++/v1
 LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib
 
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index 9d59c56..ca8a96a 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -637,7 +637,6 @@
       continue;
     LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext());
 
-    Timer TConvert;
     Cfg *Fcn = FunctionConverter.convertFunction(I);
     translateFcn(Fcn);
   }
diff --git a/src/IceDefs.h b/src/IceDefs.h
index 2555b20..c54f077 100644
--- a/src/IceDefs.h
+++ b/src/IceDefs.h
@@ -34,7 +34,6 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h" // LLVM_STATIC_ASSERT
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Timer.h"
 
 // Roll our own static_assert<> in the absence of C++11.  TODO: change
 // to static_assert<> with C++11.
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index 9d9f6dc..3145aa7 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -355,11 +355,9 @@
   Func->liveness(Liveness_Intervals);
   if (Func->hasError())
     return;
-  // Validate the live range computations.  Do it outside the timing
-  // code.  TODO: Put this under a flag.
-  bool ValidLiveness = Func->validateLiveness();
-  assert(ValidLiveness);
-  (void)ValidLiveness; // used only in assert()
+  // Validate the live range computations.  The expensive validation
+  // call is deliberately only made when assertions are enabled.
+  assert(Func->validateLiveness());
   ComputedLiveRanges = true;
   // The post-codegen dump is done here, after liveness analysis and
   // associated cleanup, to make the dump cleaner and more useful.
diff --git a/src/IceTimerTree.cpp b/src/IceTimerTree.cpp
index 4bdb80a..fa0e321 100644
--- a/src/IceTimerTree.cpp
+++ b/src/IceTimerTree.cpp
@@ -12,6 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Support/Timer.h"
+
 #include "IceDefs.h"
 #include "IceTimerTree.h"
 
@@ -139,4 +141,9 @@
   Str << "Number of timer updates: " << StateChangeCount << "\n";
 }
 
+double TimerStack::timestamp() {
+  // TODO: Implement in terms of std::chrono for C++11.
+  return llvm::TimeRecord::getCurrentTime(false).getWallTime();
+}
+
 } // end of namespace Ice
diff --git a/src/IceTimerTree.h b/src/IceTimerTree.h
index 3162587..114cc6f 100644
--- a/src/IceTimerTree.h
+++ b/src/IceTimerTree.h
@@ -50,10 +50,7 @@
 
 private:
   void update();
-  static double timestamp() {
-    // TODO: Implement in terms of std::chrono for C++11.
-    return llvm::TimeRecord::getCurrentTime(false).getWallTime();
-  }
+  static double timestamp();
   const double FirstTimestamp;
   double LastTimestamp;
   uint64_t StateChangeCount;
diff --git a/src/assembler_ia32.cpp b/src/assembler_ia32.cpp
index 3dce9b7..3775cc8 100644
--- a/src/assembler_ia32.cpp
+++ b/src/assembler_ia32.cpp
@@ -91,6 +91,7 @@
   EmitFixup(DirectCallRelocation::create(this, FK_PcRel_4, label));
   EmitInt32(-4);
   assert((buffer_.GetPosition() - call_start) == kCallExternalLabelSize);
+  (void)call_start;
 }
 
 void AssemblerX86::pushl(GPRRegister reg) {
@@ -1749,6 +1750,7 @@
 void AssemblerX86::bswap(Type Ty, GPRRegister reg) {
   AssemblerBuffer::EnsureCapacity ensured(&buffer_);
   assert(Ty == IceType_i32);
+  (void)Ty;
   EmitUint8(0x0F);
   EmitUint8(0xC8 | reg);
 }
@@ -2145,6 +2147,7 @@
                                     GPRRegister shifter) {
   AssemblerBuffer::EnsureCapacity ensured(&buffer_);
   assert(shifter == RegX8632::Encoded_Reg_ecx);
+  (void)shifter;
   EmitUint8(0xD3);
   EmitOperand(rm, Operand(operand));
 }
diff --git a/src/assembler_ia32.h b/src/assembler_ia32.h
index 0f95e35..aecc15f 100644
--- a/src/assembler_ia32.h
+++ b/src/assembler_ia32.h
@@ -329,6 +329,7 @@
   explicit AssemblerX86(bool use_far_branches = false) : buffer_(*this) {
     // This mode is only needed and implemented for MIPS and ARM.
     assert(!use_far_branches);
+    (void)use_far_branches;
   }
   ~AssemblerX86() {}