[PATCH] Remove nasty environment variables in MachineVerifier in favor of a build option

Owen Anderson resistor at mac.com
Mon Feb 2 16:05:48 PST 2015


Hi chandlerc,

This patch removes two uses of getenv() to read environment variables related to the MachineVerifier.  Instead, it creates a new CMake build variable LLVM_ENABLE_MACHINE_VERIFIER that can be used to achieve the same purpose.  There's a little bit of CMake cleverness involved here to minimize the amount of rebuilding required when toggling the flag on or off, which is important in my envisioned use case of staged builders.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7365

Files:
  CMakeLists.txt
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/MachineVerifier.cpp
  lib/CodeGen/Passes.cpp

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -235,6 +235,7 @@
 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
+option(LLVM_ENABLE_MACHINE_VERIFIER "Enable the LLVM machine verifier by default" OFF)
 
 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
Index: lib/CodeGen/CMakeLists.txt
===================================================================
--- lib/CodeGen/CMakeLists.txt
+++ lib/CodeGen/CMakeLists.txt
@@ -125,3 +125,9 @@
 
 add_subdirectory(SelectionDAG)
 add_subdirectory(AsmPrinter)
+
+if (LLVM_ENABLE_MACHINE_VERIFIER)
+  set_property(SOURCE Passes.cpp APPEND_STRING
+    PROPERTY COMPILE_DEFINITIONS "LLVM_ENABLE_MACHINE_VERIFIER")
+endif()
+
Index: lib/CodeGen/MachineVerifier.cpp
===================================================================
--- lib/CodeGen/MachineVerifier.cpp
+++ lib/CodeGen/MachineVerifier.cpp
@@ -55,15 +55,13 @@
 
     MachineVerifier(Pass *pass, const char *b) :
       PASS(pass),
-      Banner(b),
-      OutFileName(getenv("LLVM_VERIFY_MACHINEINSTRS"))
+      Banner(b)
       {}
 
     bool runOnMachineFunction(MachineFunction &MF);
 
     Pass *const PASS;
     const char *Banner;
-    const char *const OutFileName;
     raw_ostream *OS;
     const MachineFunction *MF;
     const TargetMachine *TM;
@@ -277,21 +275,7 @@
 }
 
 bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
-  raw_ostream *OutFile = nullptr;
-  if (OutFileName) {
-    std::error_code EC;
-    OutFile = new raw_fd_ostream(OutFileName, EC,
-                                 sys::fs::F_Append | sys::fs::F_Text);
-    if (EC) {
-      errs() << "Error opening '" << OutFileName << "': " << EC.message()
-             << '\n';
-      exit(1);
-    }
-
-    OS = OutFile;
-  } else {
-    OS = &errs();
-  }
+  OS = &errs();
 
   foundErrors = 0;
 
@@ -363,9 +347,7 @@
   }
   visitMachineFunctionAfter();
 
-  if (OutFile)
-    delete OutFile;
-  else if (foundErrors)
+  if (foundErrors)
     report_fatal_error("Found "+Twine(foundErrors)+" machine code errors.");
 
   // Clean up.
Index: lib/CodeGen/Passes.cpp
===================================================================
--- lib/CodeGen/Passes.cpp
+++ lib/CodeGen/Passes.cpp
@@ -81,7 +81,12 @@
     cl::desc("Dump garbage collector data"));
 static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
     cl::desc("Verify generated machine code"),
-    cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=nullptr));
+#ifdef LLVM_ENABLE_MACHINE_VERIFIER
+    cl::init(true));
+#else
+    cl::init(false));
+#endif
+
 static cl::opt<std::string>
 PrintMachineInstrs("print-machineinstrs", cl::ValueOptional,
                    cl::desc("Print machine instrs"),

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7365.19201.patch
Type: text/x-patch
Size: 2974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150203/b278d1ed/attachment.bin>


More information about the llvm-commits mailing list