[cfe-commits] r166543 - /cfe/trunk/lib/CodeGen/BackendUtil.cpp

Nadav Rotem nrotem at apple.com
Tue Oct 23 20:52:31 PDT 2012


Author: nadav
Date: Tue Oct 23 22:52:31 2012
New Revision: 166543

URL: http://llvm.org/viewvc/llvm-project?rev=166543&view=rev
Log:
Clang now attempts to create a TargetMachine whenever a triple is given.
Many of our tests specify triples that are not built into clang.
In this commit we allow clang to fail loading the triple if we are only
using clang to emit llvm ir.


Modified:
    cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=166543&r1=166542&r2=166543&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Oct 23 22:52:31 2012
@@ -100,9 +100,15 @@
 
   void CreatePasses(TargetMachine *TM);
 
-  /// CreateTargetMachine - Generates the TargetMachine. Returns Null
-  /// if it is unable to create the target machine.
-  TargetMachine *CreateTargetMachine();
+  /// CreateTargetMachine - Generates the TargetMachine.
+  /// Returns Null if it is unable to create the target machine.
+  /// Some of our clang tests specify triples which are not built
+  /// into clang. This is okay because these tests check the generated
+  /// IR, and they require DataLayout which depends on the triple.
+  /// In this case, we allow this method to fail and not report an error.
+  /// When MustCreateTM is used, we print an error if we are unable to load
+  /// the requested target.
+  TargetMachine *CreateTargetMachine(bool MustCreateTM);
 
   /// AddEmitPasses - Add passes necessary to emit assembly or LLVM IR.
   ///
@@ -260,18 +266,18 @@
     if (CodeGenOpts.getDebugInfo() == CodeGenOptions::NoDebugInfo)
       MPM->add(createStripSymbolsPass(true));
   }
-  
-  
+
   PMBuilder.populateModulePassManager(*MPM);
 }
 
-TargetMachine *EmitAssemblyHelper::CreateTargetMachine() {
+TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
   // Create the TargetMachine for generating code.
   std::string Error;
   std::string Triple = TheModule->getTargetTriple();
   const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
   if (!TheTarget) {
-    Diags.Report(diag::err_fe_unable_to_create_target) << Error;
+    if (MustCreateTM)
+      Diags.Report(diag::err_fe_unable_to_create_target) << Error;
     return 0;
   }
 
@@ -466,7 +472,10 @@
   TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : 0);
   llvm::formatted_raw_ostream FormattedOS;
 
-  TargetMachine *TM = CreateTargetMachine();
+  bool UsesCodeGen = (Action != Backend_EmitNothing &&
+                      Action != Backend_EmitBC &&
+                      Action != Backend_EmitLL);
+  TargetMachine *TM = CreateTargetMachine(UsesCodeGen);
   CreatePasses(TM);
 
   switch (Action) {





More information about the cfe-commits mailing list