joker.eph created this revision.
joker.eph added reviewers: echristo, chandlerc.
joker.eph added a subscriber: cfe-commits.

This flag is enabled by default in the driver when NDEBUG is set. It
is forwarded on the LLVMContext to discard all value names (but
GlobalValue) for performance purpose.

This an improved version of D18024

http://reviews.llvm.org/D18127

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/ModuleBuilder.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/mips-byval-arg.c
  test/CodeGen/mips-vector-arg.c
  test/CodeGen/mips-zero-sized-struct.c
  test/CodeGen/mips64-class-return.cpp
  test/CodeGen/mips64-padding-arg.c
  test/CodeGenCXX/debug-info-class.cpp
  test/CodeGenCXX/stack-reuse.cpp

Index: test/CodeGenCXX/stack-reuse.cpp
===================================================================
--- test/CodeGenCXX/stack-reuse.cpp
+++ test/CodeGenCXX/stack-reuse.cpp
@@ -21,7 +21,7 @@
   S_large a, b;
 
   Combiner(S_large);
-  Combiner f();  
+  Combiner f();
 };
 
 extern S_small foo_small();
@@ -134,11 +134,11 @@
 // CHECK-LABEL: define i32 @large_combiner_test
 // CHECK: [[T1:%.*]] = alloca %struct.Combiner
 // CHECK: [[T2:%.*]] = alloca %struct.Combiner
-// CHECK: [[T3:%.*]] = call %struct.Combiner* @_ZN8CombinerC1E7S_large(%struct.Combiner* nonnull [[T1]], [9 x i32] %s.coerce)
-// CHECK: call void @_ZN8Combiner1fEv(%struct.Combiner* nonnull sret [[T2]], %struct.Combiner* nonnull [[T1]])
-// CHECK: [[T4:%.*]] = getelementptr inbounds %struct.Combiner, %struct.Combiner* [[T2]], i32 0, i32 0, i32 0, i32 0
-// CHECK: [[T5:%.*]] = load i32, i32* [[T4]]
-// CHECK: ret i32 [[T5]]
+  // CHECK: [[T3:%.*]] = call %struct.Combiner* @_ZN8CombinerC1E7S_large(%struct.Combiner* nonnull [[T1]], [9 x i32]
+  // CHECK: call void @_ZN8Combiner1fEv(%struct.Combiner* nonnull sret [[T2]], %struct.Combiner* nonnull [[T1]])
+  // CHECK: [[T4:%.*]] = getelementptr inbounds %struct.Combiner, %struct.Combiner* [[T2]], i32 0, i32 0, i32 0, i32 0
+  // CHECK: [[T5:%.*]] = load i32, i32* [[T4]]
+  // CHECK: ret i32 [[T5]]
 
   return Combiner(s).f().a.a[0];
 }
Index: test/CodeGenCXX/debug-info-class.cpp
===================================================================
--- test/CodeGenCXX/debug-info-class.cpp
+++ test/CodeGenCXX/debug-info-class.cpp
@@ -87,7 +87,8 @@
 // RUN: %clang -target i686-cygwin -emit-llvm -g -S %s -o - | FileCheck %s
 // RUN: %clang -target armv7l-unknown-linux-gnueabihf -emit-llvm -g -S %s -o - | FileCheck %s
 
-// CHECK: invoke {{.+}} @_ZN1BD1Ev(%class.B* %b)
+// CHECK-LABEL: main(
+// CHECK: invoke {{.+}} @_ZN1BD1Ev(%class.B* %
 // CHECK-NEXT: unwind label %{{.+}}, !dbg ![[EXCEPTLOC:.*]]
 // CHECK: store i32 0, i32* %{{.+}}, !dbg ![[RETLOC:.*]]
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
Index: test/CodeGen/mips64-padding-arg.c
===================================================================
--- test/CodeGen/mips64-padding-arg.c
+++ test/CodeGen/mips64-padding-arg.c
@@ -9,8 +9,8 @@
 
 // Insert padding to ensure arguments of type S0 are aligned to 16-byte boundaries.
 
-// N64-LABEL: define void @foo1(i32 signext %a0, i64, double inreg %a1.coerce0, i64 inreg %a1.coerce1, i64 inreg %a1.coerce2, i64 inreg %a1.coerce3, double inreg %a2.coerce0, i64 inreg %a2.coerce1, i64 inreg %a2.coerce2, i64 inreg %a2.coerce3, i32 signext %b, i64, double inreg %a3.coerce0, i64 inreg %a3.coerce1, i64 inreg %a3.coerce2, i64 inreg %a3.coerce3)
-// N64: tail call void @foo2(i32 signext 1, i32 signext 2, i32 signext %a0, i64 undef, double inreg %a1.coerce0, i64 inreg %a1.coerce1, i64 inreg %a1.coerce2, i64 inreg %a1.coerce3, double inreg %a2.coerce0, i64 inreg %a2.coerce1, i64 inreg %a2.coerce2, i64 inreg %a2.coerce3, i32 signext 3, i64 undef, double inreg %a3.coerce0, i64 inreg %a3.coerce1, i64 inreg %a3.coerce2, i64 inreg %a3.coerce3)
+// N64-LABEL: define void @foo1(i32 signext{{.*}}, i64, double inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, double inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i32 signext{{.*}}, i64, double inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}})
+// N64: tail call void @foo2(i32 signext 1, i32 signext 2, i32 signext{{.*}}, i64 undef, double inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, double inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i32 signext 3, i64 undef, double inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}}, i64 inreg{{.*}})
 // N64: declare void @foo2(i32 signext, i32 signext, i32 signext, i64, double inreg, i64 inreg, i64 inreg, i64 inreg, double inreg, i64 inreg, i64 inreg, i64 inreg, i32 signext, i64, double inreg, i64 inreg, i64 inreg, i64 inreg)
 
 extern void foo2(int, int, int, S0, S0, int, S0);
@@ -21,8 +21,8 @@
 
 // Insert padding before long double argument.
 //
-// N64-LABEL: define void @foo3(i32 signext %a0, i64, fp128 %a1)
-// N64: tail call void @foo4(i32 signext 1, i32 signext 2, i32 signext %a0, i64 undef, fp128 %a1)
+// N64-LABEL: define void @foo3(i32 signext{{.*}}, i64, fp128{{.*}})
+// N64: tail call void @foo4(i32 signext 1, i32 signext 2, i32 signext{{.*}}, i64 undef, fp128{{.*}})
 // N64: declare void @foo4(i32 signext, i32 signext, i32 signext, i64, fp128)
 
 extern void foo4(int, int, int, long double);
@@ -33,8 +33,8 @@
 
 // Insert padding after hidden argument.
 //
-// N64-LABEL: define void @foo5(%struct.S0* noalias sret %agg.result, i64, fp128 %a0)
-// N64: call void @foo6(%struct.S0* sret %agg.result, i32 signext 1, i32 signext 2, i64 undef, fp128 %a0)
+// N64-LABEL: define void @foo5(%struct.S0* noalias sret{{.*}}, i64, fp128{{.*}})
+// N64: call void @foo6(%struct.S0* sret{{.*}}, i32 signext 1, i32 signext 2, i64 undef, fp128{{.*}})
 // N64: declare void @foo6(%struct.S0* sret, i32 signext, i32 signext, i64, fp128)
 
 extern S0 foo6(int, int, long double);
@@ -45,7 +45,7 @@
 
 // Do not insert padding if ABI is O32.
 //
-// O32-LABEL: define void @foo7(float %a0, double %a1)
+// O32-LABEL: define void @foo7(float{{.*}}, double{{.*}})
 // O32: declare void @foo8(float, double)
 
 extern void foo8(float, double);
Index: test/CodeGen/mips64-class-return.cpp
===================================================================
--- test/CodeGen/mips64-class-return.cpp
+++ test/CodeGen/mips64-class-return.cpp
@@ -34,12 +34,12 @@
   return gd1;
 }
 
-// CHECK-LABEL: define void @_Z4foo32D2(i64 inreg %a0.coerce0, double inreg %a0.coerce1)
+// CHECK-LABEL: define void @_Z4foo32D2(i64 inreg{{.*}}, double inreg{{.*}})
 void foo3(D2 a0) {
   gd2 = a0;
 }
 
-// CHECK-LABEL: define void @_Z4foo42D0(i64 inreg %a0.coerce0, i64 inreg %a0.coerce1)
+// CHECK-LABEL: define void @_Z4foo42D0(i64 inreg{{.*}}, i64 inreg{{.*}})
 void foo4(D0 a0) {
   gd0 = a0;
 }
Index: test/CodeGen/mips-zero-sized-struct.c
===================================================================
--- test/CodeGen/mips-zero-sized-struct.c
+++ test/CodeGen/mips-zero-sized-struct.c
@@ -5,9 +5,9 @@
 // RUN: %clang -target mips64-unknown-linux-gnu -S -emit-llvm -o - %s | FileCheck -check-prefix=N64 %s
 // RUN: %clang -target mips64el-unknown-linux-gnu -S -emit-llvm -o - %s | FileCheck -check-prefix=N64 %s
 
-// O32: define void @fn28(%struct.T2* noalias sret %agg.result, i8 signext %arg0)
-// N32: define void @fn28(i8 signext %arg0)
-// N64: define void @fn28(i8 signext %arg0)
+// O32: define void @fn28(%struct.T2* noalias sret{{.*}}, i8 signext{{.*}})
+// N32: define void @fn28(i8 signext{{.*}})
+// N64: define void @fn28(i8 signext{{.*}})
 
 typedef struct T2 {  } T2;
 T2 T2_retval;
Index: test/CodeGen/mips-vector-arg.c
===================================================================
--- test/CodeGen/mips-vector-arg.c
+++ test/CodeGen/mips-vector-arg.c
@@ -8,18 +8,18 @@
 typedef float  v4sf __attribute__ ((__vector_size__ (16)));
 typedef int v4i32 __attribute__ ((__vector_size__ (16)));
 
-// O32: define void @test_v4sf(i32 inreg %a1.coerce0, i32 inreg %a1.coerce1, i32 inreg %a1.coerce2, i32 inreg %a1.coerce3, i32 signext %a2, i32, i32 inreg %a3.coerce0, i32 inreg %a3.coerce1, i32 inreg %a3.coerce2, i32 inreg %a3.coerce3) [[NUW:#[0-9]+]]
+// O32: define void @test_v4sf(i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 signext{{.*}}, i32, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}) [[NUW:#[0-9]+]]
 // O32: declare i32 @test_v4sf_2(i32 inreg, i32 inreg, i32 inreg, i32 inreg, i32 signext, i32, i32 inreg, i32 inreg, i32 inreg, i32 inreg)
-// N64: define void @test_v4sf(i64 inreg %a1.coerce0, i64 inreg %a1.coerce1, i32 signext %a2, i64, i64 inreg %a3.coerce0, i64 inreg %a3.coerce1) [[NUW:#[0-9]+]]
+// N64: define void @test_v4sf(i64 inreg{{.*}}, i64 inreg{{.*}}, i32 signext{{.*}}, i64, i64 inreg{{.*}}, i64 inreg{{.*}}) [[NUW:#[0-9]+]]
 // N64: declare i32 @test_v4sf_2(i64 inreg, i64 inreg, i32 signext, i64, i64 inreg, i64 inreg)
 extern test_v4sf_2(v4sf, int, v4sf);
 void test_v4sf(v4sf a1, int a2, v4sf a3) {
   test_v4sf_2(a3, a2, a1);
 }
 
-// O32: define void @test_v4i32(i32 inreg %a1.coerce0, i32 inreg %a1.coerce1, i32 inreg %a1.coerce2, i32 inreg %a1.coerce3, i32 signext %a2, i32, i32 inreg %a3.coerce0, i32 inreg %a3.coerce1, i32 inreg %a3.coerce2, i32 inreg %a3.coerce3) [[NUW]]
+// O32: define void @test_v4i32(i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 signext{{.*}}, i32, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}}) [[NUW]]
 // O32: declare i32 @test_v4i32_2(i32 inreg, i32 inreg, i32 inreg, i32 inreg, i32 signext, i32, i32 inreg, i32 inreg, i32 inreg, i32 inreg)
-// N64: define void @test_v4i32(i64 inreg %a1.coerce0, i64 inreg %a1.coerce1, i32 signext %a2, i64, i64 inreg %a3.coerce0, i64 inreg %a3.coerce1) [[NUW]]
+// N64: define void @test_v4i32(i64 inreg{{.*}}, i64 inreg{{.*}}, i32 signext{{.*}}, i64, i64 inreg{{.*}}, i64 inreg{{.*}}) [[NUW]]
 // N64: declare i32 @test_v4i32_2(i64 inreg, i64 inreg, i32 signext, i64, i64 inreg, i64 inreg)
 extern test_v4i32_2(v4i32, int, v4i32);
 void test_v4i32(v4i32 a1, int a2, v4i32 a3) {
Index: test/CodeGen/mips-byval-arg.c
===================================================================
--- test/CodeGen/mips-byval-arg.c
+++ test/CodeGen/mips-byval-arg.c
@@ -7,8 +7,8 @@
 
 extern void foo2(S0);
 
-// O32-LABEL: define void @foo1(i32 inreg %a0.coerce0, i32 inreg %a0.coerce1, i32 inreg %a0.coerce2)
-// N64-LABEL: define void @foo1(i64 inreg %a0.coerce0, i32 inreg %a0.coerce1)
+// O32-LABEL: define void @foo1(i32 inreg{{.*}}, i32 inreg{{.*}}, i32 inreg{{.*}})
+// N64-LABEL: define void @foo1(i64 inreg{{.*}}, i32 inreg{{.*}})
 
 void foo1(S0 a0) {
   foo2(a0);
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -541,6 +541,7 @@
   Opts.DisableFPElim =
       (Args.hasArg(OPT_mdisable_fp_elim) || Args.hasArg(OPT_pg));
   Opts.DisableFree = Args.hasArg(OPT_disable_free);
+  Opts.DiscardValueNames = Args.hasArg(OPT_discard_value_names);
   Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
   Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
   if (Arg *A = Args.getLastArg(OPT_meabi)) {
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3712,6 +3712,8 @@
 // Disable the verification pass in -asserts builds.
 #ifdef NDEBUG
   CmdArgs.push_back("-disable-llvm-verifier");
+  // Disable LLVM value names in -asserts builds.
+  CmdArgs.push_back("-discard-value-names");
 #endif
 
   // Set the main file name, so that debug info works even with
Index: lib/CodeGen/ModuleBuilder.cpp
===================================================================
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -64,8 +64,9 @@
                       CoverageSourceInfo *CoverageInfo = nullptr)
         : Diags(diags), Ctx(nullptr), HeaderSearchOpts(HSO),
           PreprocessorOpts(PPO), CodeGenOpts(CGO), HandlingTopLevelDecls(0),
-          CoverageInfo(CoverageInfo),
-          M(new llvm::Module(ModuleName, C)) {}
+          CoverageInfo(CoverageInfo), M(new llvm::Module(ModuleName, C)) {
+      C.setDiscardValueNames(CGO.DiscardValueNames);
+    }
 
     ~CodeGeneratorImpl() override {
       // There should normally not be any leftover inline method definitions.
Index: lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -747,9 +747,7 @@
   // later.  Don't create this with the builder, because we don't want it
   // folded.
   llvm::Value *Undef = llvm::UndefValue::get(Int32Ty);
-  AllocaInsertPt = new llvm::BitCastInst(Undef, Int32Ty, "", EntryBB);
-  if (Builder.isNamePreserving())
-    AllocaInsertPt->setName("allocapt");
+  AllocaInsertPt = new llvm::BitCastInst(Undef, Int32Ty, "allocapt", EntryBB);
 
   ReturnBlock = getJumpDestInCurrentScope("return");
 
@@ -1862,26 +1860,14 @@
     CGM.getSanitizerMetadata()->disableSanitizerForInstruction(I);
 }
 
-template <bool PreserveNames>
-void CGBuilderInserter<PreserveNames>::InsertHelper(
+void CGBuilderInserter::InsertHelper(
     llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB,
     llvm::BasicBlock::iterator InsertPt) const {
-  llvm::IRBuilderDefaultInserter<PreserveNames>::InsertHelper(I, Name, BB,
-                                                              InsertPt);
+  llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
   if (CGF)
     CGF->InsertHelper(I, Name, BB, InsertPt);
 }
 
-#ifdef NDEBUG
-#define PreserveNames false
-#else
-#define PreserveNames true
-#endif
-template void CGBuilderInserter<PreserveNames>::InsertHelper(
-    llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB,
-    llvm::BasicBlock::iterator InsertPt) const;
-#undef PreserveNames
-
 static bool hasRequiredFeatures(const SmallVectorImpl<StringRef> &ReqFeatures,
                                 CodeGenModule &CGM, const FunctionDecl *FD,
                                 std::string &FirstMissing) {
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -66,8 +66,6 @@
 /// block.
 llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
                                                     const Twine &Name) {
-  if (!Builder.isNamePreserving())
-    return new llvm::AllocaInst(Ty, nullptr, "", AllocaInsertPt);
   return new llvm::AllocaInst(Ty, nullptr, Name, AllocaInsertPt);
 }
 
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3840,7 +3840,7 @@
   }
 
   llvm::Instruction *CI = CS.getInstruction();
-  if (Builder.isNamePreserving() && !CI->getType()->isVoidTy())
+  if (!CI->getType()->isVoidTy())
     CI->setName("call");
 
   // Emit any writebacks immediately.  Arguably this should happen
Index: lib/CodeGen/CGBuilder.h
===================================================================
--- lib/CodeGen/CGBuilder.h
+++ lib/CodeGen/CGBuilder.h
@@ -23,9 +23,7 @@
 /// \brief This is an IRBuilder insertion helper that forwards to
 /// CodeGenFunction::InsertHelper, which adds necessary metadata to
 /// instructions.
-template <bool PreserveNames>
-class CGBuilderInserter
-    : protected llvm::IRBuilderDefaultInserter<PreserveNames> {
+class CGBuilderInserter : protected llvm::IRBuilderDefaultInserter {
 public:
   CGBuilderInserter() = default;
   explicit CGBuilderInserter(CodeGenFunction *CGF) : CGF(CGF) {}
@@ -39,17 +37,10 @@
   CodeGenFunction *CGF = nullptr;
 };
 
-// Don't preserve names on values in an optimized build.
-#ifdef NDEBUG
-#define PreserveNames false
-#else
-#define PreserveNames true
-#endif
-
-typedef CGBuilderInserter<PreserveNames> CGBuilderInserterTy;
+typedef CGBuilderInserter CGBuilderInserterTy;
 
-typedef llvm::IRBuilder<PreserveNames, llvm::ConstantFolder,
-                        CGBuilderInserterTy> CGBuilderBaseTy;
+typedef llvm::IRBuilder<llvm::ConstantFolder, CGBuilderInserterTy>
+    CGBuilderBaseTy;
 
 class CGBuilderTy : public CGBuilderBaseTy {
   /// Storing a reference to the type cache here makes it a lot easier
@@ -305,8 +296,6 @@
   }
 };
 
-#undef PreserveNames
-
 }  // end namespace CodeGen
 }  // end namespace clang
 
Index: include/clang/Frontend/CodeGenOptions.def
===================================================================
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -43,6 +43,7 @@
 CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names.
 CODEGENOPT(DisableFPElim     , 1, 0) ///< Set when -fomit-frame-pointer is enabled.
 CODEGENOPT(DisableFree       , 1, 0) ///< Don't free memory.
+CODEGENOPT(DiscardValueNames , 1, 0) ///< Discard Value Names from the IR (LLVMContext flag)
 CODEGENOPT(DisableGCov       , 1, 0) ///< Don't run the GCov pass, for testing.
 CODEGENOPT(DisableLLVMOpts   , 1, 0) ///< Don't run any optimizations, for use in
                                      ///< getting .bc files that correspond to the
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -367,6 +367,8 @@
   HelpText<"Include brief documentation comments in code-completion results.">;
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">;
+def discard_value_names : Flag<["-"], "discard-value-names">,
+  HelpText<"Discard value names in LLVM IR">;
 def load : Separate<["-"], "load">, MetaVarName<"<dsopath>">,
   HelpText<"Load the named plugin (dynamic shared object)">;
 def plugin : Separate<["-"], "plugin">, MetaVarName<"<name>">,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to