r300741 - Parse backend options during thinlto backend compile actions

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 19 13:08:21 PDT 2017


Author: dblaikie
Date: Wed Apr 19 15:08:21 2017
New Revision: 300741

URL: http://llvm.org/viewvc/llvm-project?rev=300741&view=rev
Log:
Parse backend options during thinlto backend compile actions

Added:
    cfe/trunk/test/CodeGen/thinlto-backend-option.ll
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=300741&r1=300740&r2=300741&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Apr 19 15:08:21 2017
@@ -83,9 +83,6 @@ class EmitAssemblyHelper {
     return TargetIRAnalysis();
   }
 
-  /// Set LLVM command line options passed through -backend-option.
-  void setCommandLineOpts();
-
   void CreatePasses(legacy::PassManager &MPM, legacy::FunctionPassManager &FPM);
 
   /// Generates the TargetMachine.
@@ -604,7 +601,7 @@ void EmitAssemblyHelper::CreatePasses(le
   PMBuilder.populateModulePassManager(MPM);
 }
 
-void EmitAssemblyHelper::setCommandLineOpts() {
+static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
   SmallVector<const char *, 16> BackendArgs;
   BackendArgs.push_back("clang"); // Fake program name.
   if (!CodeGenOpts.DebugPass.empty()) {
@@ -677,7 +674,7 @@ void EmitAssemblyHelper::EmitAssembly(Ba
                                       std::unique_ptr<raw_pwrite_stream> OS) {
   TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : nullptr);
 
-  setCommandLineOpts();
+  setCommandLineOpts(CodeGenOpts);
 
   bool UsesCodeGen = (Action != Backend_EmitNothing &&
                       Action != Backend_EmitBC &&
@@ -806,7 +803,7 @@ static PassBuilder::OptimizationLevel ma
 void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
     BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) {
   TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : nullptr);
-  setCommandLineOpts();
+  setCommandLineOpts(CodeGenOpts);
 
   // The new pass manager always makes a target machine available to passes
   // during construction.
@@ -944,6 +941,8 @@ static void runThinLTOBackend(ModuleSumm
       ModuleToDefinedGVSummaries;
   CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
 
+  setCommandLineOpts(CGOpts);
+
   // We can simply import the values mentioned in the combined index, since
   // we should only invoke this using the individual indexes written out
   // via a WriteIndexesThinBackend.

Added: cfe/trunk/test/CodeGen/thinlto-backend-option.ll
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-backend-option.ll?rev=300741&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/thinlto-backend-option.ll (added)
+++ cfe/trunk/test/CodeGen/thinlto-backend-option.ll Wed Apr 19 15:08:21 2017
@@ -0,0 +1,13 @@
+; Test to ensure -backend-options work when invoking the ThinLTO backend path.
+
+; This test uses a non-existent backend option to test that backend options are
+; being parsed. While it's more important that the existing options are parsed
+; than that this error is produced, this provides a reliable way to test this
+; scenario independent of any particular backend options that may exist now or
+; in the future.
+
+; RUN: %clang -flto=thin -c -o %t.o %s
+; RUN: llvm-lto -thinlto -o %t %t.o
+; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -backend-option -nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: clang: Unknown command line argument '-nonexistent'




More information about the cfe-commits mailing list