Re: [PATCH] D39079: New clang option -fno-plt to avoid PLT for external calls

2017-10-24 Thread Sriraman Tallam via cfe-commits
On Tue, Oct 24, 2017 at 10:25 AM, Joerg Sonnenberger via Phabricator
 wrote:
> joerg added a comment.
>
> Let me phrase it differently. What is this patch (and the matching backend 
> PR) supposed to achieve? There are effectively two ways to get rid of PLT 
> entries:
> (1) Bind references locally. This is effectively what -Bsymbolic does and 
> what is breaking the ELF interposition rules.
> (2) Do an indirect call via the GOT. Requires knowing what  an external 
> symbol is, making it non-attractive for anything but LTO, since it will 
> create performance issues for all non-local accesses (i.e. anything private).

With regards to performance issues, are you saying this knowing that
GOLD and BFD linkers (lld patch will follow) can convert the indirect
calls to direct?   GOLD discussion here:
https://sourceware.org/ml/binutils/2016-05/msg00322.html

>
>
> https://reviews.llvm.org/D39079
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D42217: Set Module Metadata "AvoidPLT" when -fno-plt is used.

2018-02-23 Thread Sriraman Tallam via cfe-commits
On Fri, Feb 23, 2018 at 11:54 AM, Rafael Avila de Espindola
 wrote:
> Sriraman Tallam via Phabricator  writes:
>> +  if (CodeGenOpts.NoPLT) {
>> +getModule().setAvoidPLT();
>> +  }
>> +
>
> You don't need the {}.
>
> LGTM with that.

Thanks!
Sri

>
> Cheers,
> Rafael
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r325961 - Set Module Metadata "RtLibUseGOT" when fno-plt is used.

2018-02-23 Thread Sriraman Tallam via cfe-commits
Author: tmsriram
Date: Fri Feb 23 13:27:33 2018
New Revision: 325961

URL: http://llvm.org/viewvc/llvm-project?rev=325961&view=rev
Log:
Set Module Metadata "RtLibUseGOT" when fno-plt is used.

Differential Revision: https://reviews.llvm.org/D42217

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/noplt.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=325961&r1=325960&r2=325961&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Feb 23 13:27:33 2018
@@ -555,6 +555,9 @@ void CodeGenModule::Release() {
   getModule().setPIELevel(static_cast(PLevel));
   }
 
+  if (CodeGenOpts.NoPLT)
+getModule().setRtLibUseGOT();
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)

Modified: cfe/trunk/test/CodeGen/noplt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/noplt.c?rev=325961&r1=325960&r2=325961&view=diff
==
--- cfe/trunk/test/CodeGen/noplt.c (original)
+++ cfe/trunk/test/CodeGen/noplt.c Fri Feb 23 13:27:33 2018
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT -check-prefix=CHECK-NOPLT-METADATA
 
 // CHECK-NOPLT: Function Attrs: nonlazybind
 // CHECK-NOPLT-NEXT: declare {{.*}}i32 @foo
+// CHECK-NOPLT-METADATA: !"RtLibUseGOT"
 int foo();
 
 int bar() {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e0bca46 - Options for Basic Block Sections, enabled in D68063 and D73674.

2020-06-02 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-06-02T00:23:32-07:00
New Revision: e0bca46b0854143b2f93b60aac99e669c9776979

URL: 
https://github.com/llvm/llvm-project/commit/e0bca46b0854143b2f93b60aac99e669c9776979
DIFF: 
https://github.com/llvm/llvm-project/commit/e0bca46b0854143b2f93b60aac99e669c9776979.diff

LOG: Options for Basic Block Sections, enabled in D68063 and D73674.

This patch adds clang options:
-fbasic-block-sections={all,,labels,none} and
-funique-basic-block-section-names.
LLVM Support for basic block sections is already enabled.

+ -fbasic-block-sections={all, , labels, none} : Enables/Disables basic
block sections for all or a subset of basic blocks. "labels" only enables
basic block symbols.
+ -funique-basic-block-section-names: Enables unique section names for
basic block sections, disabled by default.

Differential Revision: https://reviews.llvm.org/D68049

Added: 
clang/test/CodeGen/Inputs/basic-block-sections.funcnames
clang/test/CodeGen/basic-block-sections.c
clang/test/Driver/fbasic-block-sections.c
clang/test/Driver/funique-basic-block-section-names.c

Modified: 
clang/docs/ClangCommandLineReference.rst
clang/docs/UsersManual.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/Target/TargetMachine.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/BBSectionsPrepare.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/MachineFunction.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index a10e747153e2..4fde6034975e 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -1331,6 +1331,10 @@ Restrict code to those available for App Extensions
 
 .. option:: -fautolink, -fno-autolink
 
+.. option:: -fbasic-block-sections=labels, -fbasic-block-sections=all, 
-fbasic-block-sections=list=, -fbasic-block-sections=none
+
+Generate labels for each basic block or place each basic block or a subset of 
basic blocks in its own section.
+
 .. option:: -fblocks, -fno-blocks
 
 Enable the 'blocks' language feature

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index ae479e0a58ae..d13d4180a112 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1698,6 +1698,44 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
+**-fbasic-block-sections=[labels, all, list=, none]**
+
+  Controls whether Clang emits a label for each basic block.  Further, with
+  values "all" and "list=arg", each basic block or a subset of basic blocks
+  can be placed in its own unique section.
+
+  With the ``list=`` option, a file containing the subset of basic blocks
+  that need to placed in unique sections can be specified.  The format of the
+  file is as follows.  For example, ``list=spec.txt`` where ``spec.txt`` is the
+  following:
+
+  ::
+
+!foo
+!!2
+!_Z3barv
+
+  will place the machine basic block with ``id 2`` in function ``foo`` in a
+  unique section.  It will also place all basic blocks of functions ``bar``
+  in unique sections.
+
+  Further, section clusters can also be specified using the ``list=``
+  option.  For example, ``list=spec.txt`` where ``spec.txt`` contains:
+
+  ::
+
+!foo
+!!1 !!3 !!5
+!!2 !!4 !!6
+
+  will create two unique sections for function ``foo`` with the first
+  containing the odd numbered basic blocks and the second containing the
+  even numbered basic blocks.
+
+  Basic block sections allow the linker to reorder basic blocks and enables
+  link-time optimizations like whole program inter-procedural basic block
+  reordering.
+
 Profile Guided Optimization
 ---
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d20282316b64..89a67235b966 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -45,6 +45,9 @@ CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete 
ctors/dtors as linker
  ///< aliases to base ctors when possible.
 CODEGENOPT(DataSections  , 1, 0) ///< Set when -fdata-sections is enabled.
 CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-nam

[clang] e8147ad - Uniuqe Names for Internal Linkage Symbols.

2020-05-07 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-05-07T18:18:37-07:00
New Revision: e8147ad8222602d16728c370d5fac086260d058c

URL: 
https://github.com/llvm/llvm-project/commit/e8147ad8222602d16728c370d5fac086260d058c
DIFF: 
https://github.com/llvm/llvm-project/commit/e8147ad8222602d16728c370d5fac086260d058c.diff

LOG: Uniuqe Names for Internal Linkage Symbols.

This is a standalone patch and this would help Propeller do a better job of code
layout as it can accurately attribute the profiles to the right internal linkage
function.

This also helps SampledFDO/AutoFDO correctly associate sampled profiles to the
right internal function. Currently, if there is more than one internal symbol
foo, their profiles are aggregated by SampledFDO.

This patch adds a new clang option, -funique-internal-funcnames, to generate
unique names for functions with internal linkage. This patch appends the md5
hash of the module name to the function symbol as a best effort to generate a
unique name for symbols with internal linkage.

Differential Revision: https://reviews.llvm.org/D73307

Added: 
clang/test/CodeGen/unique-internal-linkage-names.cpp
clang/test/Driver/funique-internal-linkage-names.c

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 97ba2aad575e..ae479e0a58ae 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1677,6 +1677,27 @@ are listed below.
on ELF targets when using the integrated assembler. This flag currently
only has an effect on ELF targets.
 
+**-f[no]-unique-internal-linkage-names**
+
+   Controls whether Clang emits a unique (best-effort) symbol name for internal
+   linkage symbols.  When this option is set, compiler hashes the main source
+   file path from the command line and appends it to all internal symbols. If a
+   program contains multiple objects compiled with the same command-line source
+   file path, the symbols are not guaranteed to be unique.  This option is
+   particularly useful in attributing profile information to the correct
+   function when multiple functions with the same private linkage name exist
+   in the binary.
+
+   It should be noted that this option cannot guarantee uniqueness and the
+   following is an example where it is not unique when two modules contain
+   symbols with the same private linkage name:
+
+   .. code-block:: console
+
+ $ cd $P/foo && clang -c -funique-internal-linkage-names name_conflict.c
+ $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
+ $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
+
 Profile Guided Optimization
 ---
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index bc7108edece9..5c7fbf43ce46 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -161,6 +161,7 @@ CODEGENOPT(ReciprocalMath, 1, 0) ///< Allow FP 
divisions to be reassociated.
 CODEGENOPT(NoTrappingMath, 1, 0) ///< Set when -fno-trapping-math is 
enabled.
 CODEGENOPT(NoNaNsFPMath  , 1, 0) ///< Assume FP arguments, results not NaN.
 CODEGENOPT(CorrectlyRoundedDivSqrt, 1, 0) ///< 
-cl-fp32-correctly-rounded-divide-sqrt
+CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get 
unique names.
 
 /// When false, this attempts to generate code as if the result of an
 /// overflowing conversion matches the overflowing behavior of a target's 
native

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 66b98b1e46fa..ef8ccb5b90e2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2001,6 +2001,12 @@ def funique_section_names : Flag <["-"], 
"funique-section-names">,
 def fno_unique_section_names : Flag <["-"], "fno-unique-section-names">,
   Group, Flags<[CC1Option]>;
 
+def funique_internal_linkage_names : Flag <["-"], 
"funique-internal-linkage-names">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Uniqueify Internal Linkage Symbol Names by appending the MD5 hash 
of the module path">;
+def fno_unique_internal_linkage_names : Flag <["-"], 
"fno-unique-internal-linkage-names">,
+  Group;
+
 def fstrict_return : Flag<["-"], "fstrict-return">, Group,
   HelpText<"Always treat control flow paths that fall off the end of a "
"non-void function as unreachable">;

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a125c96fd00e..ba61a93a4d1a 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp

[PATCH] D19996: New clang option -mpie-copy-relocationss to indicate support for linker copy relocations when linking as PIE

2016-10-14 Thread Sriraman Tallam via cfe-commits
tmsriram retitled this revision from "New clang option -mpiecopyrelocs to 
indicate support for linker copy relocations when linking as PIE" to "New clang 
option -mpie-copy-relocationss to indicate support for linker copy relocations 
when linking as PIE".
tmsriram updated the summary for this revision.
tmsriram added a reviewer: davide.
tmsriram updated this revision to Diff 74757.
tmsriram added a comment.

- Option name changed to  -mpie-copy-relocations
- Option sets MCPIECopyRelocations in MCOptions


https://reviews.llvm.org/D19996

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4499,6 +4499,11 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations, 
options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -595,6 +595,8 @@
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
+  Options.MCOptions.MCPIECopyRelocations =
+  CodeGenOpts.PIECopyRelocations;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
   Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
   Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -252,6 +252,9 @@
 /// Whether to report the hotness of the code region for optimization remarks.
 CODEGENOPT(DiagnosticsWithHotness, 1, 0)
 
+/// Whether copy relocations support is available when building as PIE.
+CODEGENOPT(PIECopyRelocations, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1691,6 +1691,12 @@
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, 
Group,
+  Flags<[CC1Option]>,
+  HelpText<"Copy Relocations support for PIE builds">;
+def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, 
Group,
+  Flags<[CC1Option]>,
+  HelpText<"No Copy Relocations support for PIE builds">;
 def mx87 : Flag<["-"], "mx87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
 def msse2 : Flag<["-"], "msse2">, Group;


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4499,6 +4499,11 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations, options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approxi

[clang] 6950db3 - The wrong placement of add pass with optimizations led to -funique-internal-linkage-names being disabled.

2020-09-21 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-09-21T10:00:12-07:00
New Revision: 6950db36d33d85d18e3241ab6c87494c05ebe0fb

URL: 
https://github.com/llvm/llvm-project/commit/6950db36d33d85d18e3241ab6c87494c05ebe0fb
DIFF: 
https://github.com/llvm/llvm-project/commit/6950db36d33d85d18e3241ab6c87494c05ebe0fb.diff

LOG: The wrong placement of add pass with optimizations led to 
-funique-internal-linkage-names being disabled.

Fixed the placement of the MPM.addpass for UniqueInternalLinkageNames to make
it work correctly with -O2 and new pass manager. Updated the tests to
explicitly check O0 and O2.

Previously, the addPass was placed before BackendUtil.cpp#L1373 which is wrong
as MPM gets assigned at this point and any additions to the pass vector before
this is wrong. This change just moves it after MPM is assigned and places it at
a point where O0 and O0+ can share it.

Differential Revision: https://reviews.llvm.org/D87921

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/unique-internal-linkage-names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 01f7e239f790..07c476218bb0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1262,12 +1262,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   // Lastly, add semantically necessary passes for LTO.
   if (IsLTO || IsThinLTO) {
 MPM.addPass(CanonicalizeAliasesPass());
@@ -1363,12 +1357,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   MPM.addPass(InstrProfiling(*Options, false));
 });
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   if (IsThinLTO) {
 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
 Level, CodeGenOpts.DebugPassManager);
@@ -1385,6 +1373,11 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   }
 }
 
+// Add UniqueInternalLinkageNames Pass which renames internal linkage
+// symbols with unique names.
+if (CodeGenOpts.UniqueInternalLinkageNames)
+  MPM.addPass(UniqueInternalLinkageNamesPass());
+
 if (CodeGenOpts.MemProf) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names.cpp
index 271d30e4e6fb..6bef338b5f1d 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,8 +1,10 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck 
%s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUEO1
 
 static int glob;
 static int foo() {
@@ -59,3 +61,7 @@ int mver_call() {
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
 // UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
+// UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
+// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
+// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
htt

Re: [PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-21 Thread Sriraman Tallam via cfe-commits
On Mon, Sep 21, 2020 at 5:58 PM Matt Morehouse via Phabricator
 wrote:
>
> morehouse added a comment.
>
> This change appears to trigger an assertion failure in sysmsg.c on the PPC 
> bot:  
> http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/26845/steps/ninja%20check%
>
>    TEST 'SanitizerCommon-msan-powerpc64le-Linux :: 
> Linux/sysmsg.c' FAILED 
>   Script:
>   --
>   : 'RUN: at line 1';  
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang  
> -gline-tables-only -fsanitize=memory  -m64 -fno-function-sections  -ldl -O1 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c
>  -o 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
>  &&  
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
>   --
>   Exit Code: 134
>
>   Command Output (stderr):
>   --
>   sysmsg.c.tmp: 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c:14:
>  int main(): Assertion `msgq != -1' failed.
>   
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.script:
>  line 1: 2982426 Aborted (core dumped) 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
>
>   --
>
> It's not immediately obvious to me what is going wrong.  If you could take a 
> look, I'd appreciate it.  Otherwise I will look closer tomorrow.

Surprised that this change is responsible.  I will take a look too. Thanks.

>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D87921/new/
>
> https://reviews.llvm.org/D87921
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-21 Thread Sriraman Tallam via cfe-commits
On Mon, Sep 21, 2020 at 5:58 PM Matt Morehouse via Phabricator
 wrote:
>
> morehouse added a comment.
>
> This change appears to trigger an assertion failure in sysmsg.c on the PPC 
> bot:  
> http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/26845/steps/ninja%20check%
>
>    TEST 'SanitizerCommon-msan-powerpc64le-Linux :: 
> Linux/sysmsg.c' FAILED 
>   Script:
>   --
>   : 'RUN: at line 1';  
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang  
> -gline-tables-only -fsanitize=memory  -m64 -fno-function-sections  -ldl -O1 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c
>  -o 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
>  &&  
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
>   --
>   Exit Code: 134
>
>   Command Output (stderr):
>   --
>   sysmsg.c.tmp: 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c:14:
>  int main(): Assertion `msgq != -1' failed.
>   
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.script:
>  line 1: 2982426 Aborted (core dumped) 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
>
>   --
>
> It's not immediately obvious to me what is going wrong.  If you could take a 
> look, I'd appreciate it.  Otherwise I will look closer tomorrow.

I am having trouble getting access to a PPC machine,  this is going to
take me longer. Should I revert the patch?

Thanks
Sri

>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D87921/new/
>
> https://reviews.llvm.org/D87921
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Sriraman Tallam via cfe-commits
On Tue, Sep 22, 2020 at 8:34 AM Fāng-ruì Sòng  wrote:
>
> FWIW I tested check-msan in a -DCMAKE_BUILD_TYPE=Release build on a
> powerpc64le machine. All tests passed. I cannot connect the failure to
> the clang patch.

Thanks for doing this! Much appreciated!

>
> On Mon, Sep 21, 2020 at 10:02 PM Sriraman Tallam  wrote:
> >
> > On Mon, Sep 21, 2020 at 5:58 PM Matt Morehouse via Phabricator
> >  wrote:
> > >
> > > morehouse added a comment.
> > >
> > > This change appears to trigger an assertion failure in sysmsg.c on the 
> > > PPC bot:  
> > > http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/26845/steps/ninja%20check%
> > >
> > >    TEST 'SanitizerCommon-msan-powerpc64le-Linux :: 
> > > Linux/sysmsg.c' FAILED 
> > >   Script:
> > >   --
> > >   : 'RUN: at line 1';  
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang
> > >   -gline-tables-only -fsanitize=memory  -m64 -fno-function-sections  -ldl 
> > > -O1 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c
> > >  -o 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> > >  &&  
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> > >   --
> > >   Exit Code: 134
> > >
> > >   Command Output (stderr):
> > >   --
> > >   sysmsg.c.tmp: 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c:14:
> > >  int main(): Assertion `msgq != -1' failed.
> > >   
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.script:
> > >  line 1: 2982426 Aborted (core dumped) 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> > >
> > >   --
> > >
> > > It's not immediately obvious to me what is going wrong.  If you could 
> > > take a look, I'd appreciate it.  Otherwise I will look closer tomorrow.
> >
> > I am having trouble getting access to a PPC machine,  this is going to
> > take me longer. Should I revert the patch?
> >
> > Thanks
> > Sri
> >
> > >
> > >
> > > Repository:
> > >   rG LLVM Github Monorepo
> > >
> > > CHANGES SINCE LAST ACTION
> > >   https://reviews.llvm.org/D87921/new/
> > >
> > > https://reviews.llvm.org/D87921
> > >
>
>
>
> --
> 宋方睿
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Sriraman Tallam via cfe-commits
On Tue, Sep 22, 2020 at 11:28 AM Albion Fung via Phabricator
 wrote:
>
> Conanap added a comment.
>
> It looks like this commit is causing a few failures on nearly all PPC bots 
> and a sanitizer bot; would it be possible to revert this commit for now until 
> the issue is resolved?

Ya sure, I can revert this. I do not have access to a PPC machine and
I could use some help to get it back in at an appropriate time.

Thanks
Sri

>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D87921/new/
>
> https://reviews.llvm.org/D87921
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b89059a - Revert "The wrong placement of add pass with optimizations led to -funique-internal-linkage-names being disabled."

2020-09-22 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-09-22T12:32:43-07:00
New Revision: b89059a31347dd09b55a96b99b3dbe38d7749908

URL: 
https://github.com/llvm/llvm-project/commit/b89059a31347dd09b55a96b99b3dbe38d7749908
DIFF: 
https://github.com/llvm/llvm-project/commit/b89059a31347dd09b55a96b99b3dbe38d7749908.diff

LOG: Revert "The wrong placement of add pass with optimizations led to 
-funique-internal-linkage-names being disabled."

This reverts commit 6950db36d33d85d18e3241ab6c87494c05ebe0fb.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/unique-internal-linkage-names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 07c476218bb0..01f7e239f790 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1262,6 +1262,12 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (CodeGenOpts.UniqueInternalLinkageNames) {
+MPM.addPass(UniqueInternalLinkageNamesPass());
+  }
+
   // Lastly, add semantically necessary passes for LTO.
   if (IsLTO || IsThinLTO) {
 MPM.addPass(CanonicalizeAliasesPass());
@@ -1357,6 +1363,12 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   MPM.addPass(InstrProfiling(*Options, false));
 });
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (CodeGenOpts.UniqueInternalLinkageNames) {
+MPM.addPass(UniqueInternalLinkageNamesPass());
+  }
+
   if (IsThinLTO) {
 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
 Level, CodeGenOpts.DebugPassManager);
@@ -1373,11 +1385,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   }
 }
 
-// Add UniqueInternalLinkageNames Pass which renames internal linkage
-// symbols with unique names.
-if (CodeGenOpts.UniqueInternalLinkageNames)
-  MPM.addPass(UniqueInternalLinkageNamesPass());
-
 if (CodeGenOpts.MemProf) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names.cpp
index 6bef338b5f1d..271d30e4e6fb 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,10 +1,8 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck 
%s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUEO1
+// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
 
 static int glob;
 static int foo() {
@@ -61,7 +59,3 @@ int mver_call() {
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
 // UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
-// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
-// UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
-// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7d0bbe4 - Re-apply https://reviews.llvm.org/D87921, was reverted to triage a PPC bot failure.

2020-09-23 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-09-23T10:28:40-07:00
New Revision: 7d0bbe40901cf60558c619c3174d71d7c53ca144

URL: 
https://github.com/llvm/llvm-project/commit/7d0bbe40901cf60558c619c3174d71d7c53ca144
DIFF: 
https://github.com/llvm/llvm-project/commit/7d0bbe40901cf60558c619c3174d71d7c53ca144.diff

LOG: Re-apply https://reviews.llvm.org/D87921, was reverted to triage a PPC bot 
failure.

D87921 was reverted in commit b89059a31347dd09b55a96b99b3dbe38d7749908
as it was causing an unknown llvm PPC bot failure.  Reapplying the patch
after confirming that this is not responsible. Build bot failure:
https://reviews.llvm.org/D87921#2286644  which caused the revert.

The wrong placement of add pass with optimizations led to
-funique-internal-linkage-names being disabled.

Fixed the placement of the MPM.addpass for UniqueInternalLinkageNames to make it
work correctly with -O2 and new pass manager. Updated the tests to explicitly
check O0 and O1.

Differential Revision: https://reviews.llvm.org/D87921

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/unique-internal-linkage-names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 44f0434f2021..f83ec2479652 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1262,12 +1262,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   // Lastly, add semantically necessary passes for LTO.
   if (IsLTO || IsThinLTO) {
 MPM.addPass(CanonicalizeAliasesPass());
@@ -1363,12 +1357,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   MPM.addPass(InstrProfiling(*Options, false));
 });
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   if (IsThinLTO) {
 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
 Level, CodeGenOpts.DebugPassManager);
@@ -1385,6 +1373,11 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   }
 }
 
+// Add UniqueInternalLinkageNames Pass which renames internal linkage
+// symbols with unique names.
+if (CodeGenOpts.UniqueInternalLinkageNames)
+  MPM.addPass(UniqueInternalLinkageNamesPass());
+
 if (CodeGenOpts.MemProf) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names.cpp
index 271d30e4e6fb..6bef338b5f1d 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,8 +1,10 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck 
%s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUEO1
 
 static int glob;
 static int foo() {
@@ -59,3 +61,7 @@ int mver_call() {
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
 // UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
+// UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
+// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
+// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}



___

[clang] 34e70d7 - Append ".__part." to every basic block section symbol.

2020-12-23 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-12-23T11:35:44-08:00
New Revision: 34e70d722dfd0e73d460802e8d43d3a885d24784

URL: 
https://github.com/llvm/llvm-project/commit/34e70d722dfd0e73d460802e8d43d3a885d24784
DIFF: 
https://github.com/llvm/llvm-project/commit/34e70d722dfd0e73d460802e8d43d3a885d24784.diff

LOG: Append ".__part." to every basic block section symbol.

Every basic block section symbol created by -fbasic-block-sections will contain
".__part." to know that this symbol corresponds to a basic block fragment of
the function.

This patch solves two problems:

a) Like D89617, we want function symbols with suffixes to be properly qualified
   so that external tools like profile aggregators know exactly what this
   symbol corresponds to.
b) The current basic block naming just adds a ".N" to the symbol name where N is
   some integer. This collides with how clang creates __cxx_global_var_init.N.
   clang creates these symbol names to call constructor functions and basic
   block symbol naming should not use the same style.

Fixed all the test cases and added an extra test for __cxx_global_var_init
breakage.

Differential Revision: https://reviews.llvm.org/D93082

Added: 
llvm/test/CodeGen/X86/basic-block-sections_2.ll

Modified: 
clang/test/CodeGen/basic-block-sections.c
lld/test/ELF/lto/basic-block-sections.ll
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/test/CodeGen/X86/basic-block-sections-blockaddress-taken.ll
llvm/test/CodeGen/X86/basic-block-sections-clusters-branches.ll
llvm/test/CodeGen/X86/basic-block-sections-clusters-eh.ll
llvm/test/CodeGen/X86/basic-block-sections-clusters.ll
llvm/test/CodeGen/X86/basic-block-sections-directjumps.ll
llvm/test/CodeGen/X86/basic-block-sections-eh.ll
llvm/test/CodeGen/X86/basic-block-sections-list.ll
llvm/test/CodeGen/X86/basic-block-sections-listbb.ll
llvm/test/CodeGen/X86/basic-block-sections-mir-parse.mir
llvm/test/CodeGen/X86/basic-block-sections-unreachable.ll
llvm/test/CodeGen/X86/basic-block-sections.ll
llvm/test/CodeGen/X86/cfi-basic-block-sections-1.ll

llvm/test/CodeGen/X86/cfi-inserter-basic-block-sections-callee-save-registers.ll
llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
llvm/test/DebugInfo/X86/basic-block-sections_1.ll

Removed: 




diff  --git a/clang/test/CodeGen/basic-block-sections.c 
b/clang/test/CodeGen/basic-block-sections.c
index 805539f06f08..70cdeeebb0d3 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -31,14 +31,14 @@ int another(int a) {
 // BB_WORLD: .section .text.world,"ax",@progbits{{$}}
 // BB_WORLD: world:
 // BB_WORLD: .section .text.world,"ax",@progbits,unique
-// BB_WORLD: world.1:
+// BB_WORLD: world.__part.1:
 // BB_WORLD: .section .text.another,"ax",@progbits
 // BB_ALL: .section .text.another,"ax",@progbits,unique
-// BB_ALL: another.1:
+// BB_ALL: another.__part.1:
 // BB_LIST-NOT: .section .text.another,"ax",@progbits,unique
 // BB_LIST: another:
-// BB_LIST-NOT: another.1:
+// BB_LIST-NOT: another.__part.1:
 //
-// UNIQUE: .section .text.world.world.1,
-// UNIQUE: .section .text.another.another.1,
+// UNIQUE: .section .text.world.world.__part.1,
+// UNIQUE: .section .text.another.another.__part.1,
 // ERROR: error:  unable to load basic block sections function list: 
'{{[Nn]}}o such file or directory'

diff  --git a/lld/test/ELF/lto/basic-block-sections.ll 
b/lld/test/ELF/lto/basic-block-sections.ll
index 1f932ac50a87..35b638ac488a 100644
--- a/lld/test/ELF/lto/basic-block-sections.ll
+++ b/lld/test/ELF/lto/basic-block-sections.ll
@@ -11,12 +11,12 @@
 ; SECNAMES: Name: .text.foo {{.*}}
 
 ; SECNAMES-FULL: Name: .text.foo {{.*}}
-; SECNAMES-FULL: Name: .text.foo.foo.1 {{.*}}
-; SECNAMES-FULL: Name: .text.foo.foo.2 {{.*}}
+; SECNAMES-FULL: Name: .text.foo.foo.__part.1 {{.*}}
+; SECNAMES-FULL: Name: .text.foo.foo.__part.2 {{.*}}
 
 ; SYMS: foo
-; SYMS: foo.1
-; SYMS: foo.2
+; SYMS: foo.__part.1
+; SYMS: foo.__part.2
 
 target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"

diff  --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp 
b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 0278999a8f72..14a270f994b4 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -71,7 +71,10 @@ MCSymbol *MachineBasicBlock::getSymbol() const {
   } else if (SectionID == MBBSectionID::ExceptionSectionID) {
 Suffix += ".eh";
   } else {
-Suffix += "." + std::to_string(SectionID.Number);
+// For symbols that represent basic block sections, we add ".__part." 
to
+// allow tools like symbolizers to know that this represents a part of
+// the original function.
+Suffix = (Suffix + Twine(".__part.") + Twine(SectionID.Number)).str();
   }
   CachedM

[clang] f887854 - Improve file doesnt exist error with -fbasic-block-sections=

2020-10-20 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-10-20T16:41:56-07:00
New Revision: f88785460ecf40a9176f58637d38fb785eb91ac4

URL: 
https://github.com/llvm/llvm-project/commit/f88785460ecf40a9176f58637d38fb785eb91ac4
DIFF: 
https://github.com/llvm/llvm-project/commit/f88785460ecf40a9176f58637d38fb785eb91ac4.diff

LOG: Improve file doesnt exist error with -fbasic-block-sections=

With -fbasicblock-sections=, let the front-end handle the case where the file
doesnt exist. The driver only checks if the option syntax is right.

Differential Revision: https://reviews.llvm.org/D89500

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/basic-block-sections.c
clang/test/Driver/fbasic-block-sections.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9cdee130af431..34ccc8cffb799 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4924,7 +4924,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 if (Triple.isX86() && Triple.isOSBinFormatELF()) {
   StringRef Val = A->getValue();
   if (Val != "all" && Val != "labels" && Val != "none" &&
-  !(Val.startswith("list=") && llvm::sys::fs::exists(Val.substr(5
+  !Val.startswith("list="))
 D.Diag(diag::err_drv_invalid_value)
 << A->getAsString(Args) << A->getValue();
   else

diff  --git a/clang/test/CodeGen/basic-block-sections.c 
b/clang/test/CodeGen/basic-block-sections.c
index dc414d70ba5f9..f07a387685c86 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -6,6 +6,7 @@
 // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all -o - < %s | 
FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
 // RUN: %clang_cc1 -triple x86_64 -S 
-fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames -o - < %s 
| FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_LIST
 // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all 
-funique-basic-block-section-names -o - < %s | FileCheck %s 
--check-prefix=UNIQUE
+// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-obj %s 2>&1 | 
FileCheck %s --check-prefix=ERROR
 
 int world(int a) {
   if (a > 10)
@@ -38,3 +39,4 @@ int another(int a) {
 //
 // UNIQUE: .section .text.world.world.1,
 // UNIQUE: .section .text.another.another.1,
+// ERROR: error:  unable to load basic block sections function list: 'No such 
file or directory'

diff  --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 93c7fe9fc0699..6aa030bf27ca5 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -4,9 +4,14 @@
 // RUN: %clang -### -target x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
 // RUN: not %clang -c -target arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: not %clang -c -target x86_64-apple-darwin10 -fbasic-block-sections=all 
%s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=alll %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-INVALID-VALUE %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=list %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-INVALID-VALUE %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=list= %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NULL-LIST %s
 //
 // CHECK-OPT-NONE:   "-fbasic-block-sections=none"
 // CHECK-OPT-ALL:"-fbasic-block-sections=all"
 // CHECK-OPT-LIST:   "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
 // CHECK-OPT-LABELS: "-fbasic-block-sections=labels"
 // CHECK-TRIPLE: error: unsupported option '-fbasic-block-sections=all' 
for target
+// CHECK-INVALID-VALUE: error: invalid value {{[^ ]*}} in 
'-fbasic-block-sections={{.*}}'
+// CHECK-OPT-NULL-LIST: "-fbasic-block-sections=list="



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D89500: Fix the error message with -fbasic-block-sections=list=

2020-10-20 Thread Sriraman Tallam via cfe-commits
On Tue, Oct 20, 2020 at 6:19 PM Nico Weber via Phabricator
 wrote:
>
> thakis added a comment.
>
> Looks like this breaks tests on windows: 
> http://45.33.8.238/win/26253/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

Sorry I saw this message late.
Looks like Fangrui already fixed it.

Thanks
Sri

>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D89500/new/
>
> https://reviews.llvm.org/D89500
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D89500: Fix the error message with -fbasic-block-sections=list=

2020-10-21 Thread Sriraman Tallam via cfe-commits
On Wed, Oct 21, 2020 at 11:07 AM David Blaikie via Phabricator
 wrote:
>
> dblaikie added a comment.
>
> In D89500#2344234 , @davezarzycki 
> wrote:
>
> > I think I fixed it. Please verify: 87f6de72bcd346bbbf468e9f9a0e9d1bbf0630a9 
> > 
>
> Thanks - if that's unblocked you, great!
>
> @tmsriram could you check on this? I'm surprised this test isn't failing - I 
> can't see any CHECK lines for the "ERROR" prefix used by the error test (& 
> FileCheck usually fails if it finds no relevant CHECK lines... so I'm not 
> sure what's happening there).
>
> Also: I'd expect a failing compilation not to write the file out? (I'd expect 
> it to be writing to a temporary file, then moving the file into position once 
> the compilation has finished successfully, so there's never a half-written 
> file, etc - in case the compiler crashes) so I wonder what's going on here. 
> Could you check what the behavior is/why it's trying to write a file even 
> when there's an error? (I could be wrong on my assumptions/understanding here 
> - perhaps this is true of other error paths too, that they do try to write 
> the output file and maybe delete it after instead (though that wouldn't be 
> crash-resilient))

Taking a look right now.

>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D89500/new/
>
> https://reviews.llvm.org/D89500
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D89500: Fix the error message with -fbasic-block-sections=list=

2020-10-21 Thread Sriraman Tallam via cfe-commits
On Wed, Oct 21, 2020 at 11:07 AM David Blaikie via Phabricator
 wrote:
>
> dblaikie added a comment.
>
> In D89500#2344234 , @davezarzycki 
> wrote:
>
> > I think I fixed it. Please verify: 87f6de72bcd346bbbf468e9f9a0e9d1bbf0630a9 
> > 
>
> Thanks - if that's unblocked you, great!
>
> @tmsriram could you check on this? I'm surprised this test isn't failing - I 
> can't see any CHECK lines for the "ERROR" prefix used by the error test (& 
> FileCheck usually fails if it finds no relevant CHECK lines... so I'm not 
> sure what's happening there).

@dblaikie 
https://github.com/llvm/llvm-project/blob/master/clang/test/CodeGen/basic-block-sections.c#L42


>
> Also: I'd expect a failing compilation not to write the file out? (I'd expect 
> it to be writing to a temporary file, then moving the file into position once 
> the compilation has finished successfully, so there's never a half-written 
> file, etc - in case the compiler crashes) so I wonder what's going on here. 
> Could you check what the behavior is/why it's trying to write a file even 
> when there's an error? (I could be wrong on my assumptions/understanding here 
> - perhaps this is true of other error paths too, that they do try to write 
> the output file and maybe delete it after instead (though that wouldn't be 
> crash-resilient))
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D89500/new/
>
> https://reviews.llvm.org/D89500
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D89500: Fix the error message with -fbasic-block-sections=list=

2020-10-21 Thread Sriraman Tallam via cfe-commits
On Wed, Oct 21, 2020 at 11:45 AM Sriraman Tallam  wrote:
>
> On Wed, Oct 21, 2020 at 11:07 AM David Blaikie via Phabricator
>  wrote:
> >
> > dblaikie added a comment.
> >
> > In D89500#2344234 , @davezarzycki 
> > wrote:
> >
> > > I think I fixed it. Please verify: 
> > > 87f6de72bcd346bbbf468e9f9a0e9d1bbf0630a9 
> > > 
> >
> > Thanks - if that's unblocked you, great!
> >
> > @tmsriram could you check on this? I'm surprised this test isn't failing - 
> > I can't see any CHECK lines for the "ERROR" prefix used by the error test 
> > (& FileCheck usually fails if it finds no relevant CHECK lines... so I'm 
> > not sure what's happening there).
>
> @dblaikie 
> https://github.com/llvm/llvm-project/blob/master/clang/test/CodeGen/basic-block-sections.c#L42
>
>
> >
> > Also: I'd expect a failing compilation not to write the file out? (I'd 
> > expect it to be writing to a temporary file, then moving the file into 
> > position once the compilation has finished successfully, so there's never a 
> > half-written file, etc - in case the compiler crashes) so I wonder what's 
> > going on here. Could you check what the behavior is/why it's trying to 
> > write a file even when there's an error? (I could be wrong on my 
> > assumptions/understanding here - perhaps this is true of other error paths 
> > too, that they do try to write the output file and maybe delete it after 
> > instead (though that wouldn't be crash-resilient))

So, this change:

diff --git a/clang/test/CodeGen/basic-block-sections.c
b/clang/test/CodeGen/basic-block-sections.c
index 2eefbbfd21e..95ab2e54cb2 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -6,7 +6,7 @@
 // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all -o -
< %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
 // RUN: %clang_cc1 -triple x86_64 -S
-fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames
-o - < %s | FileCheck %s --check-prefix=BB_WORLD
--check-prefix=BB_LIST
 // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all
-funique-basic-block-section-names -o - < %s | FileCheck %s
--check-prefix=UNIQUE
-// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-obj -o - %s
2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-obj -o
/dev/null %s 2>&1 | FileCheck %s --check-prefix=ERROR

 specifically redirecting the file to /dev/null seems like it would
solve the problem.  WDYT?

Thanks
Sri


> >
> >
> > Repository:
> >   rG LLVM Github Monorepo
> >
> > CHANGES SINCE LAST ACTION
> >   https://reviews.llvm.org/D89500/new/
> >
> > https://reviews.llvm.org/D89500
> >
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D89500: Fix the error message with -fbasic-block-sections=list=

2020-10-21 Thread Sriraman Tallam via cfe-commits
On Wed, Oct 21, 2020 at 11:59 AM Sriraman Tallam  wrote:
>
> On Wed, Oct 21, 2020 at 11:45 AM Sriraman Tallam  wrote:
> >
> > On Wed, Oct 21, 2020 at 11:07 AM David Blaikie via Phabricator
> >  wrote:
> > >
> > > dblaikie added a comment.
> > >
> > > In D89500#2344234 , 
> > > @davezarzycki wrote:
> > >
> > > > I think I fixed it. Please verify: 
> > > > 87f6de72bcd346bbbf468e9f9a0e9d1bbf0630a9 
> > > > 
> > >
> > > Thanks - if that's unblocked you, great!
> > >
> > > @tmsriram could you check on this? I'm surprised this test isn't failing 
> > > - I can't see any CHECK lines for the "ERROR" prefix used by the error 
> > > test (& FileCheck usually fails if it finds no relevant CHECK lines... so 
> > > I'm not sure what's happening there).
> >
> > @dblaikie 
> > https://github.com/llvm/llvm-project/blob/master/clang/test/CodeGen/basic-block-sections.c#L42
> >
> >
> > >
> > > Also: I'd expect a failing compilation not to write the file out? (I'd 
> > > expect it to be writing to a temporary file, then moving the file into 
> > > position once the compilation has finished successfully, so there's never 
> > > a half-written file, etc - in case the compiler crashes) so I wonder 
> > > what's going on here. Could you check what the behavior is/why it's 
> > > trying to write a file even when there's an error? (I could be wrong on 
> > > my assumptions/understanding here - perhaps this is true of other error 
> > > paths too, that they do try to write the output file and maybe delete it 
> > > after instead (though that wouldn't be crash-resilient))
>
> So, this change:
>
> diff --git a/clang/test/CodeGen/basic-block-sections.c
> b/clang/test/CodeGen/basic-block-sections.c
> index 2eefbbfd21e..95ab2e54cb2 100644
> --- a/clang/test/CodeGen/basic-block-sections.c
> +++ b/clang/test/CodeGen/basic-block-sections.c
> @@ -6,7 +6,7 @@
>  // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all -o -
> < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
>  // RUN: %clang_cc1 -triple x86_64 -S
> -fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames
> -o - < %s | FileCheck %s --check-prefix=BB_WORLD
> --check-prefix=BB_LIST
>  // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all
> -funique-basic-block-section-names -o - < %s | FileCheck %s
> --check-prefix=UNIQUE
> -// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-obj -o - %s
> 2>&1 | FileCheck %s --check-prefix=ERROR
> +// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-obj -o
> /dev/null %s 2>&1 | FileCheck %s --check-prefix=ERROR
>
>  specifically redirecting the file to /dev/null seems like it would
> solve the problem.  WDYT?

Sorry the diff got clobbered.  Basically replacing "-o -" with "-o /dev/null".

>
> Thanks
> Sri
>
>
> > >
> > >
> > > Repository:
> > >   rG LLVM Github Monorepo
> > >
> > > CHANGES SINCE LAST ACTION
> > >   https://reviews.llvm.org/D89500/new/
> > >
> > > https://reviews.llvm.org/D89500
> > >
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eef2e67 - Simple fix to basic-block-sections to replace emit-obj with emit-llvm

2020-10-21 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-10-21T13:52:33-07:00
New Revision: eef2e67d2326e7d4027fddb29eefdb69371dc24a

URL: 
https://github.com/llvm/llvm-project/commit/eef2e67d2326e7d4027fddb29eefdb69371dc24a
DIFF: 
https://github.com/llvm/llvm-project/commit/eef2e67d2326e7d4027fddb29eefdb69371dc24a.diff

LOG: Simple fix to basic-block-sections to replace emit-obj with emit-llvm

emit-obj is unnecessary here and further wasn't redirected to /dev/null.

Added: 


Modified: 
clang/test/CodeGen/basic-block-sections.c

Removed: 




diff  --git a/clang/test/CodeGen/basic-block-sections.c 
b/clang/test/CodeGen/basic-block-sections.c
index 2eefbbfd21e1..0381bc78c6a9 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -6,7 +6,7 @@
 // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all -o - < %s | 
FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
 // RUN: %clang_cc1 -triple x86_64 -S 
-fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames -o - < %s 
| FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_LIST
 // RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all 
-funique-basic-block-section-names -o - < %s | FileCheck %s 
--check-prefix=UNIQUE
-// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-obj -o - %s 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang_cc1 -fbasic-block-sections=list= -emit-llvm -o - %s 2>&1 | 
FileCheck %s --check-prefix=ERROR
 
 int world(int a) {
   if (a > 10)



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ad1b9da - Prepend "__uniq" to symbol names hash with -funique-internal-linkage-names.

2020-10-26 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-10-26T14:24:28-07:00
New Revision: ad1b9daa4bf40c1907794fd5de7807aad1f0553c

URL: 
https://github.com/llvm/llvm-project/commit/ad1b9daa4bf40c1907794fd5de7807aad1f0553c
DIFF: 
https://github.com/llvm/llvm-project/commit/ad1b9daa4bf40c1907794fd5de7807aad1f0553c.diff

LOG: Prepend "__uniq" to symbol names hash with -funique-internal-linkage-names.

Prepend the module name hash with a fixed string ".__uniq." which helps tools
that consume sampled profiles and attribute it to functions to understand
that this symbol belongs to a unique internal linkage type symbol.

Symbols with suffixes can result from various optimizations in the compiler.
Function Multiversioning, function splitting, parameter constant propogation,
unique internal linkage names.

External tools like sampled profile aggregators combine profiles from multiple
runs of a binary. They use various heuristics with symbols that have suffixes
to try and attribute the profile to the right function instance. For instance
multi-versioned symbols like foo.avx, foo.sse4.2, etc even though different
should be attributed to the same source function if a single function is
versioned, using attribute target_clones (supported in GCC but yet to land in
LLVM). Similarly, functions that are split (split part having a .cold suffix)
could have profiles for both the original and split symbols but would be
aggregated and attributed to the original function that was split.

Unique internal linkage functions however have different source instances and
the aggregator must not put them together but attribute it to the appropriate
function instance. To be sure that we are dealing with a symbol of a unique
internal linkage function, we would like to prepend the hash with a known
string ".__uniq." which these tools can check to understand the suffix type.

Differential Revision: https://reviews.llvm.org/D89617

Added: 


Modified: 
clang/test/CodeGen/unique-internal-linkage-names.cpp
llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll

Removed: 




diff  --git a/clang/test/CodeGen/unique-internal-linkage-names.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names.cpp
index 6bef338b5f1d..3ad3bdc9f1bb 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -53,15 +53,15 @@ int mver_call() {
 // PLAIN: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // PLAIN: define internal i32 @_ZL4mverv()
 // PLAIN: define internal i32 @_ZL4mverv.sse4.2()
-// UNIQUE: @_ZL4glob.{{[0-9a-f]+}} = internal global
-// UNIQUE: @_ZZ8retAnonMvE5fGlob.{{[0-9a-f]+}} = internal global
-// UNIQUE: @_ZN12_GLOBAL__N_16anon_mE.{{[0-9a-f]+}} = internal global
-// UNIQUE: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
-// UNIQUE: define internal i32 @_ZN12_GLOBAL__N_14getMEv.{{[0-9a-f]+}}
+// UNIQUE: @_ZL4glob.__uniq.{{[0-9a-f]+}} = internal global
+// UNIQUE: @_ZZ8retAnonMvE5fGlob.__uniq.{{[0-9a-f]+}} = internal global
+// UNIQUE: @_ZN12_GLOBAL__N_16anon_mE.__uniq.{{[0-9a-f]+}} = internal global
+// UNIQUE: define internal i32 @_ZL3foov.__uniq.{{[0-9a-f]+}}()
+// UNIQUE: define internal i32 @_ZN12_GLOBAL__N_14getMEv.__uniq.{{[0-9a-f]+}}
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
-// UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
-// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
+// UNIQUE: define internal i32 @_ZL4mverv.__uniq.{{[0-9a-f]+}}()
+// UNIQUE: define internal i32 @_ZL4mverv.sse4.2.__uniq.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL3foov.__uniq.{{[0-9a-f]+}}()
 // UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
-// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL4mverv.__uniq.{{[0-9a-f]+}}()
+// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.__uniq.{{[0-9a-f]+}}

diff  --git a/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp 
b/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
index 5b58548e54dc..385bf8bb429a 100644
--- a/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ b/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -27,7 +27,9 @@ static bool uniqueifyInternalLinkageNames(Module &M) {
   Md5.final(R);
   SmallString<32> Str;
   llvm::MD5::stringifyResult(R, Str);
-  std::string ModuleNameHash = (Twine(".") + Twine(Str)).str();
+  // Prepend "__uniq" before the hash for tools like profilers to understand 
that
+  // this symbol is of internal linkage type.
+  std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
   bool Changed = false;
 
   // Append the module hash to all internal linkage functions.

diff  --git 
a/llvm/test/Transforms/Un

Re: [PATCH] D89500: Fix the error message with -fbasic-block-sections=list=

2020-10-27 Thread Sriraman Tallam via cfe-commits
On Tue, Oct 27, 2020 at 2:14 PM David Blaikie via Phabricator <
revi...@reviews.llvm.org> wrote:

> dblaikie added a comment.
>
> @tmsriram ping on the follow-up here
>

I checked in the patch that emits llvm instead of obj which spews garbage
to the terminal as I wasn't redirecting it to /dev/null.  The test seems
stable. Is there a particular concern? Sorry if I missed somethig here?


>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D89500/new/
>
> https://reviews.llvm.org/D89500
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e741916 - Basic block sections should enable not function sections implicitly.

2021-02-17 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2021-02-17T12:37:50-08:00
New Revision: e74191633036905388245818f54553813c880f83

URL: 
https://github.com/llvm/llvm-project/commit/e74191633036905388245818f54553813c880f83
DIFF: 
https://github.com/llvm/llvm-project/commit/e74191633036905388245818f54553813c880f83.diff

LOG: Basic block sections should enable not function sections implicitly.

Basic block sections enables function sections implicitly, this is not needed
and is inefficient with "=list" option.

We had basic block sections enable function sections implicitly in clang. This
is particularly inefficient with "=list" option as it places functions that do
not have any basic block sections in separate sections. This causes unnecessary
object file overhead for large applications.

This patch disables this implicit behavior. It only creates function sections
for those functions that require basic block sections.

This patch is the second of two patches and this patch removes the implicit
enabling of function sections with basic block sections in clang.

Differential Revision: https://reviews.llvm.org/D93876

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/basic-block-sections.c

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f92964732688..a49c97860324 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1383,8 +1383,7 @@ void CompilerInvocation::GenerateCodeGenArgs(
   GenerateArg(Args, OPT_ftime_report, SA);
   }
 
-  if (Opts.FunctionSections &&
-  (Opts.BBSections == "none" || Opts.BBSections == "labels"))
+  if (Opts.FunctionSections)
 GenerateArg(Args, OPT_ffunction_sections, SA);
 
   if (Opts.PrepareForLTO && !Opts.PrepareForThinLTO)
@@ -1678,9 +1677,7 @@ bool 
CompilerInvocation::ParseCodeGenArgsImpl(CodeGenOptions &Opts,
   }
 
   // Basic Block Sections implies Function Sections.
-  Opts.FunctionSections =
-  Args.hasArg(OPT_ffunction_sections) ||
-  (Opts.BBSections != "none" && Opts.BBSections != "labels");
+  Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
   Opts.PrepareForThinLTO = false;

diff  --git a/clang/test/CodeGen/basic-block-sections.c 
b/clang/test/CodeGen/basic-block-sections.c
index ee0dc90e2d02..a61b8dd4ac37 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -32,10 +32,9 @@ int another(int a) {
 // BB_WORLD: world:
 // BB_WORLD: .section .text.world,"ax",@progbits,unique
 // BB_WORLD: world.__part.1:
-// BB_WORLD: .section .text.another,"ax",@progbits
-// BB_ALL: .section .text.another,"ax",@progbits,unique
+// BB_ALL: .section .text.another,"ax",@progbits
 // BB_ALL: another.__part.1:
-// BB_LIST-NOT: .section .text.another,"ax",@progbits,unique
+// BB_LIST-NOT: .section .text.another,"ax",@progbits
 // BB_LIST: another:
 // BB_LIST-NOT: another.__part.1:
 //



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 78d0e91 - Refactor -funique-internal-linakge-names implementation.

2021-03-05 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2021-03-05T13:32:17-08:00
New Revision: 78d0e91865f6038adb23ec272c3e1e7e1525057f

URL: 
https://github.com/llvm/llvm-project/commit/78d0e91865f6038adb23ec272c3e1e7e1525057f
DIFF: 
https://github.com/llvm/llvm-project/commit/78d0e91865f6038adb23ec272c3e1e7e1525057f.diff

LOG: Refactor -funique-internal-linakge-names implementation.

The option -funique-internal-linkage-names was added in D73307 and D78243 as a
LLVM early pass to insert a unique suffix to internal linkage functions and
vars. The unique suffix was the hash of the module path. However, we found
that this can be done more cleanly in clang early and the fixes that need to
be done later can be completely avoided. The fixes in particular are trying
to modify the DW_AT_linkage_name and finding the right place to insert the
pass.

This patch ressurects the original implementation proposed in D73307 which
was reviewed and then ditched in favor of the pass based approach.

Differential Revision: https://reviews.llvm.org/D96109

Added: 
clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
clang/test/CodeGen/unique-internal-linkage-names-dwarf.cpp

Modified: 
clang/include/clang/AST/Mangle.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/Mangle.cpp
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGen/unique-internal-linkage-names.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index 13b436cdca3e..dc620ec10ff9 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -110,6 +110,12 @@ class MangleContext {
   virtual bool isDeviceMangleContext() const { return false; }
   virtual void setDeviceMangleContext(bool) {}
 
+  virtual bool isUniqueInternalLinkageDecl(const NamedDecl *ND) {
+return false;
+  }
+
+  virtual void needsUniqueInternalLinkageNames() { }
+
   // FIXME: consider replacing raw_ostream & with something like SmallString &.
   void mangleName(GlobalDecl GD, raw_ostream &);
   virtual void mangleCXXName(GlobalDecl GD, raw_ostream &) = 0;

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 8bc9d33d5bae..885d9e28ee69 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -126,6 +126,7 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
   llvm::DenseMap Uniquifier;
 
   bool IsDevCtx = false;
+  bool NeedsUniqueInternalLinkageNames = false;
 
 public:
   explicit ItaniumMangleContextImpl(ASTContext &Context,
@@ -140,6 +141,11 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
 return false;
   }
 
+  bool isUniqueInternalLinkageDecl(const NamedDecl *ND) override;
+  void needsUniqueInternalLinkageNames() override {
+NeedsUniqueInternalLinkageNames = true;
+  }
+
   bool isDeviceMangleContext() const override { return IsDevCtx; }
   void setDeviceMangleContext(bool IsDev) override { IsDevCtx = IsDev; }
 
@@ -613,6 +619,33 @@ class CXXNameMangler {
 
 }
 
+static bool isInternalLinkageDecl(const NamedDecl *ND) {
+  if (ND && ND->getFormalLinkage() == InternalLinkage &&
+  !ND->isExternallyVisible() &&
+  getEffectiveDeclContext(ND)->isFileContext() &&
+  !ND->isInAnonymousNamespace())
+return true;
+  return false;
+}
+
+// Check if this Decl needs a unique internal linkage name.
+bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
+const NamedDecl *ND) {
+  if (!NeedsUniqueInternalLinkageNames || !ND)
+return false;
+
+  // For C functions without prototypes, return false as their
+  // names should not be mangled.
+  if (auto *FD = dyn_cast(ND)) {
+if (!FD->getType()->getAs())
+  return false;
+  }
+
+  if (isInternalLinkageDecl(ND))
+return true;
+  return false;
+}
+
 bool ItaniumMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) {
   const FunctionDecl *FD = dyn_cast(D);
   if (FD) {
@@ -1376,10 +1409,7 @@ void CXXNameMangler::mangleUnqualifiedName(GlobalDecl GD,
   // 12_GLOBAL__N_1 mangling is quite sufficient there, and this better
   // matches GCC anyway, because GCC does not treat anonymous namespaces as
   // implying internal linkage.
-  if (ND && ND->getFormalLinkage() == InternalLinkage &&
-  !ND->isExternallyVisible() &&
-  getEffectiveDeclContext(ND)->isFileContext() &&
-  !ND->isInAnonymousNamespace())
+  if (isInternalLinkageDecl(ND))
 Out << 'L';
 
   auto *FD = dyn_cast(ND);

diff  --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index 3282fcbd584f..2b0d55568cb8 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -116,6 +116,12 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl 
*D) {
   if (!D->hasExternalFormalLinkage() && D->getOwnin

[clang] cdb42a4 - Disable unique linkage suffixes ifor global vars until demanglers can be fixed.

2021-03-11 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2021-03-11T20:59:30-08:00
New Revision: cdb42a4cc4239c0b592fc82021c945ce02ebe5cc

URL: 
https://github.com/llvm/llvm-project/commit/cdb42a4cc4239c0b592fc82021c945ce02ebe5cc
DIFF: 
https://github.com/llvm/llvm-project/commit/cdb42a4cc4239c0b592fc82021c945ce02ebe5cc.diff

LOG: Disable unique linkage suffixes ifor global vars until demanglers can be 
fixed.

D96109 added support for unique internal linkage names for both internal
linkage functions and global variables. There was a lot of discussion on how to
get the demangling right for functions but I completely missed the point that
demanglers do not support suffixes for global vars. For example:

$ c++filt _ZL3foo
foo
$ c++filt _ZL3foo.uniq.123
_ZL3foo.uniq.123

The demangling for functions works as expected.

I am not sure of the impact of this. I don't understand how debuggers and other
tools depend on the correctness of global variable demangling so I am
pre-emptively disabling it until we can get the demangling support added.

Importantly, uniquefying global variables is not needed right now as we do not
do profile attribution to global vars based on sampling. It was added for
completeness and so this feature is not exactly missed.

Differential Revision: https://reviews.llvm.org/D98392

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
clang/test/CodeGen/unique-internal-linkage-names-dwarf.cpp
clang/test/CodeGen/unique-internal-linkage-names.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 885d9e28ee69..ba96fda6cd57 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -628,21 +628,24 @@ static bool isInternalLinkageDecl(const NamedDecl *ND) {
   return false;
 }
 
-// Check if this Decl needs a unique internal linkage name.
+// Check if this Function Decl needs a unique internal linkage name.
 bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
 const NamedDecl *ND) {
   if (!NeedsUniqueInternalLinkageNames || !ND)
 return false;
 
+  const auto *FD = dyn_cast(ND);
+  if (!FD)
+return false;
+
   // For C functions without prototypes, return false as their
   // names should not be mangled.
-  if (auto *FD = dyn_cast(ND)) {
-if (!FD->getType()->getAs())
-  return false;
-  }
+  if (!FD->getType()->getAs())
+return false;
 
   if (isInternalLinkageDecl(ND))
 return true;
+
   return false;
 }
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 4bf339786d42..250946bd56dd 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1175,18 +1175,13 @@ static void AppendTargetMangling(const CodeGenModule 
&CGM,
   }
 }
 
-// Returns true if GD is a function/var decl with internal linkage and
+// Returns true if GD is a function decl with internal linkage and
 // needs a unique suffix after the mangled name.
 static bool isUniqueInternalLinkageDecl(GlobalDecl GD,
 CodeGenModule &CGM) {
   const Decl *D = GD.getDecl();
-  if (!CGM.getModuleNameHash().empty() &&
-  ((isa(D) &&
-CGM.getFunctionLinkage(GD) == llvm::GlobalValue::InternalLinkage) ||
-   (isa(D) && CGM.getContext().GetGVALinkageForVariable(
-   cast(D)) == GVA_Internal)))
-return true;
-  return false;
+  return !CGM.getModuleNameHash().empty() && isa(D) &&
+ (CGM.getFunctionLinkage(GD) == llvm::GlobalValue::InternalLinkage);
 }
 
 static std::string getMangledNameImpl(CodeGenModule &CGM, GlobalDecl GD,

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c 
b/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
index 916d293f2e5a..a3583426de79 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
+++ b/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
@@ -22,7 +22,7 @@ void baz() {
 // PLAIN: distinct !DISubprogram(name: "foo"{{.*}})
 // PLAIN-NOT: linkageName:
 //
-// UNIQUE: @_ZL4glob.[[MODHASH:__uniq.[0-9]+]] = internal global i32
-// UNIQUE: define internal i32 @_ZL3foov.[[MODHASH]]()
-// UNIQUE: distinct !DIGlobalVariable(name: "glob", linkageName: 
"_ZL4glob.[[MODHASH]]"{{.*}})
+// UNIQUE: @glob = internal global i32
+// UNIQUE: define internal i32 @_ZL3foov.[[MODHASH:__uniq.[0-9]+]]()
+// UNIQUE: distinct !DIGlobalVariable(name: "glob"{{.*}})
 // UNIQUE: distinct !DISubprogram(name: "foo", linkageName: 
"_ZL3foov.[[MODHASH]]"{{.*}})

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names-dwarf.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names-dwarf.cpp
index 41b13754396e..37ebfe5eee17 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names-dwarf.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-na

r317605 - New clang option -fno-plt which avoids the PLT and lazy binding while making external calls.

2017-11-07 Thread Sriraman Tallam via cfe-commits
Author: tmsriram
Date: Tue Nov  7 11:37:51 2017
New Revision: 317605

URL: http://llvm.org/viewvc/llvm-project?rev=317605&view=rev
Log:
New clang option -fno-plt which avoids the PLT and lazy binding while making 
external calls.

Differential Revision: https://reviews.llvm.org/D39079

Added:
cfe/trunk/test/CodeGen/noplt.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=317605&r1=317604&r2=317605&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Nov  7 11:37:51 2017
@@ -1384,6 +1384,10 @@ def fpic : Flag<["-"], "fpic">, Group, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+def fplt : Flag<["-"], "fplt">, Group, Flags<[CC1Option]>,
+  HelpText<"Use the PLT to make function calls">;
+def fno_plt : Flag<["-"], "fno-plt">, Group, Flags<[CC1Option]>,
+  HelpText<"Do not use the PLT to make function calls">;
 def fropi : Flag<["-"], "fropi">, Group;
 def fno_ropi : Flag<["-"], "fno-ropi">, Group;
 def frwpi : Flag<["-"], "frwpi">, Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=317605&r1=317604&r2=317605&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Nov  7 11:37:51 2017
@@ -297,6 +297,8 @@ CODEGENOPT(PreserveVec3Type, 1, 0)
 /// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
 CODEGENOPT(GnuPubnames, 1, 0)
 
+CODEGENOPT(NoPLT, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=317605&r1=317604&r2=317605&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Nov  7 11:37:51 2017
@@ -1855,6 +1855,16 @@ void CodeGenModule::ConstructAttributeLi
   !(TargetDecl && TargetDecl->hasAttr()))
 FuncAttrs.addAttribute("split-stack");
 
+  // Add NonLazyBind attribute to function declarations when -fno-plt
+  // is used.
+  if (TargetDecl && CodeGenOpts.NoPLT) {
+if (auto *Fn = dyn_cast(TargetDecl)) {
+  if (!Fn->isDefined() && !AttrOnCallSite) {
+FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);
+  }
+}
+  }
+
   if (!AttrOnCallSite) {
 bool DisableTailCalls =
 CodeGenOpts.DisableTailCalls ||

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=317605&r1=317604&r2=317605&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Nov  7 11:37:51 2017
@@ -3423,6 +3423,10 @@ void Clang::ConstructJob(Compilation &C,
 CmdArgs.push_back("-mpie-copy-relocations");
   }
 
+  if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
+CmdArgs.push_back("-fno-plt");
+  }
+
   // -fhosted is default.
   // TODO: Audit uses of KernelOrKext and see where it'd be more appropriate to
   // use Freestanding.

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=317605&r1=317604&r2=317605&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Nov  7 11:37:51 2017
@@ -653,6 +653,7 @@ static bool ParseCodeGenArgs(CodeGenOpti
   Args.hasArg(OPT_mincremental_linker_compatible);
   Opts.PIECopyRelocations =
   Args.hasArg(OPT_mpie_copy_relocations);
+  Opts.NoPLT = Args.hasArg(OPT_fno_plt);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);

Added: cfe/trunk/test/CodeGen/noplt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/noplt.c?rev=317605&view=auto
==
--- cfe/trunk/test/CodeGen/noplt.c (added)
+++ cfe/trunk/test/CodeGen/noplt.c Tue Nov  7 11:37:51 2017
@@ -0,0 +1,9 

r317627 - Change noplt.c to work for non-x86 targets.

2017-11-07 Thread Sriraman Tallam via cfe-commits
Author: tmsriram
Date: Tue Nov  7 14:34:55 2017
New Revision: 317627

URL: http://llvm.org/viewvc/llvm-project?rev=317627&view=rev
Log:
Change noplt.c to work for non-x86 targets.

Differential Revision: https://reviews.llvm.org/D39759

Modified:
cfe/trunk/test/CodeGen/noplt.c

Modified: cfe/trunk/test/CodeGen/noplt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/noplt.c?rev=317627&r1=317626&r2=317627&view=diff
==
--- cfe/trunk/test/CodeGen/noplt.c (original)
+++ cfe/trunk/test/CodeGen/noplt.c Tue Nov  7 14:34:55 2017
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT
 
 // CHECK-NOPLT: Function Attrs: nonlazybind
-// CHECK-NOPLT-NEXT: declare i32 @foo
+// CHECK-NOPLT-NEXT: declare {{.*}}i32 @foo
 int foo();
 
 int bar() {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19996: New clang option -mpie-copy-relocationss to indicate support for linker copy relocations when linking as PIE

2016-10-19 Thread Sriraman Tallam via cfe-commits
tmsriram updated this revision to Diff 75179.
tmsriram added a comment.

- Changed help text to "Avail copy relocations support for PIE builds"
- Removed mno-pie... as a CC1 option
- Removed help text from mno-pie..


https://reviews.llvm.org/D19996

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4499,6 +4499,11 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations, 
options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -595,6 +595,8 @@
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
+  Options.MCOptions.MCPIECopyRelocations =
+  CodeGenOpts.PIECopyRelocations;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
   Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
   Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -252,6 +252,9 @@
 /// Whether to report the hotness of the code region for optimization remarks.
 CODEGENOPT(DiagnosticsWithHotness, 1, 0)
 
+/// Whether copy relocations support is available when building as PIE.
+CODEGENOPT(PIECopyRelocations, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1691,6 +1691,10 @@
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, 
Group,
+  Flags<[CC1Option]>,
+  HelpText<"Avail copy relocations support for PIE builds">;
+def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, 
Group;
 def mx87 : Flag<["-"], "mx87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
 def msse2 : Flag<["-"], "msse2">, Group;


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4499,6 +4499,11 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations, options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -595,6 +595,8 @@
   Options.MCOptions.MCNoExecStack = C

[PATCH] D19996: New clang option -mpie-copy-relocationss to indicate support for linker copy relocations when linking as PIE

2016-10-19 Thread Sriraman Tallam via cfe-commits
tmsriram added inline comments.



Comment at: lib/Frontend/CompilerInvocation.cpp:589
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);

mgrang wrote:
> You should also check for the negative flag here:
> 
> Opts.PIECopyRelocations = Args.hasFlag(options::OPT_mpie_copy_relocations,
> options::OPT_mno_pie_copy_relocations, false);
mpie_copy_relocations is  the only CC1 flag here and that is pushed into CC1 
command after checking for the negative. 


https://reviews.llvm.org/D19996



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19996: New clang option -mpie-copy-relocationss to indicate support for linker copy relocations when linking as PIE

2016-10-19 Thread Sriraman Tallam via cfe-commits
tmsriram updated this revision to Diff 75189.
tmsriram added a comment.

- Fix Help text.
- Fix indentation.


https://reviews.llvm.org/D19996

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4499,6 +4499,12 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations,
+   options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -595,6 +595,8 @@
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
+  Options.MCOptions.MCPIECopyRelocations =
+  CodeGenOpts.PIECopyRelocations;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
   Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
   Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -252,6 +252,9 @@
 /// Whether to report the hotness of the code region for optimization remarks.
 CODEGENOPT(DiagnosticsWithHotness, 1, 0)
 
+/// Whether copy relocations support is available when building as PIE.
+CODEGENOPT(PIECopyRelocations, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1691,6 +1691,10 @@
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, 
Group,
+  Flags<[CC1Option]>,
+  HelpText<"Use copy relocations support for PIE builds">;
+def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, 
Group;
 def mx87 : Flag<["-"], "mx87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
 def msse2 : Flag<["-"], "msse2">, Group;


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4499,6 +4499,12 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations,
+   options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -595,6 +595,8 @@
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompat

r284638 - New clang option -mpie-copy-relocations to use copy relocations for PIE builds.

2016-10-19 Thread Sriraman Tallam via cfe-commits
Author: tmsriram
Date: Wed Oct 19 15:24:06 2016
New Revision: 284638

URL: http://llvm.org/viewvc/llvm-project?rev=284638&view=rev
Log:
New clang option -mpie-copy-relocations to use copy relocations for PIE builds.

Differential Revision: https://reviews.llvm.org/D19996

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=284638&r1=284637&r2=284638&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Oct 19 15:24:06 2016
@@ -1691,6 +1691,10 @@ def mno_implicit_float : Flag<["-"], "mn
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, 
Group,
+  Flags<[CC1Option]>,
+  HelpText<"Use copy relocations support for PIE builds">;
+def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, 
Group;
 def mx87 : Flag<["-"], "mx87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
 def msse2 : Flag<["-"], "msse2">, Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=284638&r1=284637&r2=284638&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Wed Oct 19 15:24:06 2016
@@ -252,6 +252,9 @@ VALUE_CODEGENOPT(EmitCheckPathComponents
 /// Whether to report the hotness of the code region for optimization remarks.
 CODEGENOPT(DiagnosticsWithHotness, 1, 0)
 
+/// Whether copy relocations support is available when building as PIE.
+CODEGENOPT(PIECopyRelocations, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=284638&r1=284637&r2=284638&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Oct 19 15:24:06 2016
@@ -595,6 +595,8 @@ void EmitAssemblyHelper::CreateTargetMac
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
+  Options.MCOptions.MCPIECopyRelocations =
+  CodeGenOpts.PIECopyRelocations;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
   Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
   Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284638&r1=284637&r2=284638&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Oct 19 15:24:06 2016
@@ -4499,6 +4499,12 @@ void Clang::ConstructJob(Compilation &C,
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations,
+   options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=284638&r1=284637&r2=284638&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Oct 19 15:24:06 2016
@@ -586,6 +586,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
htt

[PATCH] D19996: New clang option -mpie-copy-relocationss to indicate support for linker copy relocations when linking as PIE

2016-10-19 Thread Sriraman Tallam via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284638: New clang option -mpie-copy-relocations to use copy 
relocations for PIE builds. (authored by tmsriram).

Changed prior to commit:
  https://reviews.llvm.org/D19996?vs=75189&id=75212#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D19996

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp


Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -595,6 +595,8 @@
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
+  Options.MCOptions.MCPIECopyRelocations =
+  CodeGenOpts.PIECopyRelocations;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
   Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
   Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
Index: cfe/trunk/lib/Driver/Tools.cpp
===
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -4499,6 +4499,12 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpie_copy_relocations,
+   options::OPT_mno_pie_copy_relocations,
+   false)) {
+CmdArgs.push_back("-mpie-copy-relocations");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1691,6 +1691,10 @@
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, 
Group,
+  Flags<[CC1Option]>,
+  HelpText<"Use copy relocations support for PIE builds">;
+def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, 
Group;
 def mx87 : Flag<["-"], "mx87">, Group;
 def m80387 : Flag<["-"], "m80387">, Alias;
 def msse2 : Flag<["-"], "msse2">, Group;
Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def
@@ -252,6 +252,9 @@
 /// Whether to report the hotness of the code region for optimization remarks.
 CODEGENOPT(DiagnosticsWithHotness, 1, 0)
 
+/// Whether copy relocations support is available when building as PIE.
+CODEGENOPT(PIECopyRelocations, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT


Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -586,6 +586,8 @@
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
+  Opts.PIECopyRelocations =
+  Args.hasArg(OPT_mpie_copy_relocations);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -595,6 +595,8 @@
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
   Options.MCOptions.MCIncrementalLinkerCompatible =
   CodeGenOpts.IncrementalLinkerCompatible;
+  Options.MCOptions.MCPIECopyRelocations =
+  CodeGenOpts.PIECopyRelocation

[PATCH] D19687: Set PIELevel module flag

2016-04-28 Thread Sriraman Tallam via cfe-commits
tmsriram created this revision.
tmsriram added reviewers: rnk, davidxl.
tmsriram added a subscriber: cfe-commits.

In patch http://reviews.llvm.org/D19671, I added a patch to create PIELevel 
module flag.  This patch sets the flag.

http://reviews.llvm.org/D19687

Files:
  lib/CodeGen/CodeGenModule.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -488,6 +488,18 @@
 getModule().setPICLevel(PL);
   }
 
+  if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
+llvm::PIELevel::Level PL = llvm::PIELevel::Default;
+switch (PLevel) {
+case 0: break;
+case 1: PL = llvm::PIELevel::Small; break;
+case 2: PL = llvm::PIELevel::Large; break;
+default: llvm_unreachable("Invalid PIE Level");
+}
+
+getModule().setPIELevel(PL);
+  }
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -488,6 +488,18 @@
 getModule().setPICLevel(PL);
   }
 
+  if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
+llvm::PIELevel::Level PL = llvm::PIELevel::Default;
+switch (PLevel) {
+case 0: break;
+case 1: PL = llvm::PIELevel::Small; break;
+case 2: PL = llvm::PIELevel::Large; break;
+default: llvm_unreachable("Invalid PIE Level");
+}
+
+getModule().setPIELevel(PL);
+  }
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19687: Set PIELevel module flag

2016-04-28 Thread Sriraman Tallam via cfe-commits
tmsriram updated this revision to Diff 55493.
tmsriram added a comment.

Simplify code setting PICLevel and PIELevel module flags.


http://reviews.llvm.org/D19687

Files:
  lib/CodeGen/CodeGenModule.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -477,15 +477,13 @@
   }
 
   if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
-llvm::PICLevel::Level PL = llvm::PICLevel::Default;
-switch (PLevel) {
-case 0: break;
-case 1: PL = llvm::PICLevel::Small; break;
-case 2: PL = llvm::PICLevel::Large; break;
-default: llvm_unreachable("Invalid PIC Level");
-}
+assert (PLevel < 3 && "Invalid PIC Level");
+getModule().setPICLevel(static_cast(PLevel));
+  }
 
-getModule().setPICLevel(PL);
+  if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
+assert (PLevel < 3 && "Invalid PIE Level");
+getModule().setPIELevel(static_cast(PLevel));
   }
 
   SimplifyPersonality();


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -477,15 +477,13 @@
   }
 
   if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
-llvm::PICLevel::Level PL = llvm::PICLevel::Default;
-switch (PLevel) {
-case 0: break;
-case 1: PL = llvm::PICLevel::Small; break;
-case 2: PL = llvm::PICLevel::Large; break;
-default: llvm_unreachable("Invalid PIC Level");
-}
+assert (PLevel < 3 && "Invalid PIC Level");
+getModule().setPICLevel(static_cast(PLevel));
+  }
 
-getModule().setPICLevel(PL);
+  if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
+assert (PLevel < 3 && "Invalid PIE Level");
+getModule().setPIELevel(static_cast(PLevel));
   }
 
   SimplifyPersonality();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r267948 - Differential Revision: http://reviews.llvm.org/D19687

2016-04-28 Thread Sriraman Tallam via cfe-commits
Author: tmsriram
Date: Thu Apr 28 17:34:00 2016
New Revision: 267948

URL: http://llvm.org/viewvc/llvm-project?rev=267948&view=rev
Log:
Differential Revision: http://reviews.llvm.org/D19687

Set module flag PIELevel. Simplify code that sets PICLevel flag.

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

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=267948&r1=267947&r2=267948&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Apr 28 17:34:00 2016
@@ -477,15 +477,13 @@ void CodeGenModule::Release() {
   }
 
   if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
-llvm::PICLevel::Level PL = llvm::PICLevel::Default;
-switch (PLevel) {
-case 0: break;
-case 1: PL = llvm::PICLevel::Small; break;
-case 2: PL = llvm::PICLevel::Large; break;
-default: llvm_unreachable("Invalid PIC Level");
-}
+assert(PLevel < 3 && "Invalid PIC Level");
+getModule().setPICLevel(static_cast(PLevel));
+  }
 
-getModule().setPICLevel(PL);
+  if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
+assert(PLevel < 3 && "Invalid PIE Level");
+getModule().setPIELevel(static_cast(PLevel));
   }
 
   SimplifyPersonality();


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19687: Set PIELevel module flag

2016-04-29 Thread Sriraman Tallam via cfe-commits
tmsriram closed this revision.
tmsriram added a comment.

267948


http://reviews.llvm.org/D19687



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19749: Delete store to Target option PositionIndependentExecutable

2016-04-29 Thread Sriraman Tallam via cfe-commits
tmsriram created this revision.
tmsriram added a reviewer: rnk.
tmsriram added subscribers: cfe-commits, davidxl.

Delete store to Target option PositionIndependentExecutable which will be 
deleted.  PIE is set in module flags.

http://reviews.llvm.org/D19749

Files:
  lib/CodeGen/BackendUtil.cpp

Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -595,7 +595,6 @@
   Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
   Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
   Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
-  Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
   Options.FunctionSections = CodeGenOpts.FunctionSections;
   Options.DataSections = CodeGenOpts.DataSections;
   Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;


Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -595,7 +595,6 @@
   Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
   Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
   Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
-  Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
   Options.FunctionSections = CodeGenOpts.FunctionSections;
   Options.DataSections = CodeGenOpts.DataSections;
   Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r268137 - Delete store to Target option PositionIndependentExecutable as PIE is now set in module flags.

2016-04-29 Thread Sriraman Tallam via cfe-commits
Author: tmsriram
Date: Fri Apr 29 18:38:53 2016
New Revision: 268137

URL: http://llvm.org/viewvc/llvm-project?rev=268137&view=rev
Log:
Delete store to Target option PositionIndependentExecutable as PIE is now set 
in module flags.

Differential Revision: http://reviews.llvm.org/D19749

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=268137&r1=268136&r2=268137&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Apr 29 18:38:53 2016
@@ -595,7 +595,6 @@ TargetMachine *EmitAssemblyHelper::Creat
   Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
   Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
   Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
-  Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
   Options.FunctionSections = CodeGenOpts.FunctionSections;
   Options.DataSections = CodeGenOpts.DataSections;
   Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19749: Delete store to Target option PositionIndependentExecutable

2016-04-29 Thread Sriraman Tallam via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268137: Delete store to Target option 
PositionIndependentExecutable as PIE is now set… (authored by tmsriram).

Changed prior to commit:
  http://reviews.llvm.org/D19749?vs=55676&id=55687#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19749

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

Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -595,7 +595,6 @@
   Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
   Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
   Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
-  Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
   Options.FunctionSections = CodeGenOpts.FunctionSections;
   Options.DataSections = CodeGenOpts.DataSections;
   Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;


Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -595,7 +595,6 @@
   Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
   Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
   Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
-  Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
   Options.FunctionSections = CodeGenOpts.FunctionSections;
   Options.DataSections = CodeGenOpts.DataSections;
   Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19996: New clang option -mpiecopyrelocs to indicate support for linker copy relocations when linking as PIE

2016-05-05 Thread Sriraman Tallam via cfe-commits
tmsriram created this revision.
tmsriram added a reviewer: rnk.
tmsriram added subscribers: cfe-commits, davidxl, rafael.

With linker copy relocations, PIE can generate better code for external global 
variable accesses.  This patch adds a new option to clang to specify this.  
Please see  http://reviews.llvm.org/D19995  for the patch to LLVM to optimize 
global accesses when this is available. With this option, the module flag "PIE 
Copy Relocations" is set.

http://reviews.llvm.org/D19996

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -570,6 +570,7 @@
   Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
   Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums);
   Opts.StrictVTablePointers = Args.hasArg(OPT_fstrict_vtable_pointers);
+  Opts.PIECopyRelocs = Args.hasArg(OPT_piecopyrelocs);
   Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
   Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
   Args.hasArg(OPT_cl_fast_relaxed_math);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4161,6 +4161,11 @@
 CmdArgs.push_back("-mms-bitfields");
   }
 
+  if (Args.hasFlag(options::OPT_mpiecopyrelocs, options::OPT_mno_piecopyrelocs,
+   false)) {
+CmdArgs.push_back("-piecopyrelocs");
+  }
+
   // This is a coarse approximation of what llvm-gcc actually does, both
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -484,6 +484,8 @@
   if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
 assert(PLevel < 3 && "Invalid PIE Level");
 getModule().setPIELevel(static_cast(PLevel));
+if (CodeGenOpts.PIECopyRelocs)
+  getModule().setPIECopyRelocs();
   }
 
   SimplifyPersonality();
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -222,6 +222,8 @@
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+CODEGENOPT(PIECopyRelocs, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1544,6 +1544,8 @@
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mpiecopyrelocs : Flag<["-"], "mpiecopyrelocs">, Group;
+def mno_piecopyrelocs : Flag<["-"], "mno-piecopyrelocs">, Group;
 def msse2 : Flag<["-"], "msse2">, Group;
 def msse3 : Flag<["-"], "msse3">, Group;
 def msse4a : Flag<["-"], "msse4a">, Group;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -175,6 +175,8 @@
 def dwarf_ext_refs : Flag<["-"], "dwarf-ext-refs">,
   HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
+def piecopyrelocs : Flag<["-"], "piecopyrelocs">,
+  HelpText<"Linker copy relocations support when linking as PIE">;
 def fforbid_guard_variables : Flag<["-"], "fforbid-guard-variables">,
   HelpText<"Emit an error if a C++ static local initializer would need a guard 
variable">;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -570,6 +570,7 @@
   Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
   Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums);
   Opts.StrictVTablePointers = Args.hasArg(OPT_fstrict_vtable_pointers);
+  Opts.PIECopyRelocs = Args.hasArg(OPT_piecopyrelocs);
   Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
   Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
   Args.hasArg(OPT_cl_fast_relaxed_math);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4161,6 +4161,11 @@
 CmdArgs.push

Re: [PATCH] D19996: New clang option -mpiecopyrelocs to indicate support for linker copy relocations when linking as PIE

2016-05-05 Thread Sriraman Tallam via cfe-commits
On Thu, May 5, 2016 at 2:31 PM, Rafael Espíndola
 wrote:
> Is there a gcc option or they just assume they are targeting the
> linker that was around when gcc was built?

It is done at configure time, the linker is checked for copy
relocations support.  I recently saw a request to replace this with a
flag like -mpiecopyrelocs.  I chatted off-line with Reid about this
and a flag was suggested.

>
>
>> +  if (Args.hasFlag(options::OPT_mpiecopyrelocs, 
>> options::OPT_mno_piecopyrelocs,
>> +   false)) {
>> +CmdArgs.push_back("-piecopyrelocs");
>> +  }
>
> you don't need the {}
>
>> +def piecopyrelocs : Flag<["-"], "piecopyrelocs">,
>> +  HelpText<"Linker copy relocations support when linking as PIE">;
>
> I think you are missing a verb: Linker copy relocations *are* supported.
>
> But how about just "Position independent executables can have copy 
> relocations"?
>
> Cheers,
> Rafael
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D18843: Always have clang pass -pie-level and -pic-level values to the code generator

2016-04-06 Thread Sriraman Tallam via cfe-commits
tmsriram created this revision.
tmsriram added reviewers: rnk, davidxl.
tmsriram added a subscriber: cfe-commits.

clang does not pass pie-level and pic-level option values to the code generator 
with "-x ir" due to the following code in CompilerInvocation.cpp:

   if (DashX == IK_AST || DashX == IK_LLVM_IR) {
   ;
} else {
   ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), 
Diags);
}
pie-level and pic-level are LangArgs and are not parsed with "-x ir". They 
define macros __PIC__ and __PIE___ when set, see 
lib/Frontend/InitPreprocessor.cpp

Not setting LangOpts.PIELevel means that Options.PositionIndependentExecutable 
is always false even when -fPIE is used.  This patch fixes that.

I considered an alternative of making pie-level and pic-level CodeGen Options.  
However, since these options are used to set macros __PIE__, __PIC__, etc. this 
looked better as LangOpts.  Please let me know what you think.

For a broader context, I am working on optimizing accesses to global variables  
with -fPIE on x86-64 and this patch is the first step to get there.  In 
particular, I noticed the following code generated with clang:

hello.cpp:

int a = 0;

int main() {
  return a;
}

$ clang -O2 -fPIE hello.cc -S
$ cat hello.s

main:   # @main
movqa@GOTPCREL(%rip), %rax
movl(%rax), %eax
retq

Creating a GOT entry for global 'a' is unnecessary as 'a' is defined in 
hello.cpp which will be linked into a position independent executable (fPIE).  
Hence, the definition of 'a' cannot be overridden and we can remove a load. The 
efficient access is this:

main:   # @main
movla(%rip), %eax
retq

I plan to address this in a separate patch.


http://reviews.llvm.org/D18843

Files:
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2142,6 +2142,12 @@
 // what the input type is.
 if (Args.hasArg(OPT_fobjc_arc))
   Res.getLangOpts()->ObjCAutoRefCount = 1;
+// PIClevel and PIELevel are needed during code generation and this should 
be
+// set regardless of the input type.
+Res.getLangOpts()->PICLevel = getLastArgIntValue(Args, OPT_pic_level,
+ 0, Diags);
+Res.getLangOpts()->PIELevel = getLastArgIntValue(Args, OPT_pie_level,
+ 0, Diags);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
 Diags, Res.getLangOpts()->Sanitize);
   } else {


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2142,6 +2142,12 @@
 // what the input type is.
 if (Args.hasArg(OPT_fobjc_arc))
   Res.getLangOpts()->ObjCAutoRefCount = 1;
+// PIClevel and PIELevel are needed during code generation and this should be
+// set regardless of the input type.
+Res.getLangOpts()->PICLevel = getLastArgIntValue(Args, OPT_pic_level,
+ 0, Diags);
+Res.getLangOpts()->PIELevel = getLastArgIntValue(Args, OPT_pie_level,
+ 0, Diags);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
 Diags, Res.getLangOpts()->Sanitize);
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18843: Always have clang pass -pie-level and -pic-level values to the code generator

2016-04-07 Thread Sriraman Tallam via cfe-commits
tmsriram updated this revision to Diff 52945.
tmsriram added a comment.

Cleanup the code to use a local variable to store *Res.getLangOpts()


http://reviews.llvm.org/D18843

Files:
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2110,6 +2110,7 @@
   InputArgList Args =
   Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex,
   MissingArgCount, IncludedFlagsBitmask);
+  LangOptions &LangOpts = *Res.getLangOpts();
 
   // Check for missing argument error.
   if (MissingArgCount) {
@@ -2128,7 +2129,7 @@
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
   Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags);
-  ParseCommentArgs(Res.getLangOpts()->CommentOpts, Args);
+  ParseCommentArgs(LangOpts.CommentOpts, Args);
   ParseFileSystemArgs(Res.getFileSystemOpts(), Args);
   // FIXME: We shouldn't have to pass the DashX option around here
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags);
@@ -2141,22 +2142,26 @@
 // PassManager in BackendUtil.cpp. They need to be initializd no matter
 // what the input type is.
 if (Args.hasArg(OPT_fobjc_arc))
-  Res.getLangOpts()->ObjCAutoRefCount = 1;
+  LangOpts.ObjCAutoRefCount = 1;
+// PIClevel and PIELevel are needed during code generation and this should 
be
+// set regardless of the input type.
+LangOpts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
+LangOpts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
-Diags, Res.getLangOpts()->Sanitize);
+Diags, LangOpts.Sanitize);
   } else {
 // Other LangOpts are only initialzed when the input is not AST or LLVM IR.
-ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), Diags);
+ParseLangArgs(LangOpts, Args, DashX, Res.getTargetOpts(), Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
-  Res.getLangOpts()->ObjCExceptions = 1;
+  LangOpts.ObjCExceptions = 1;
   }
 
   // FIXME: Override value name discarding when asan or msan is used because 
the
   // backend passes depend on the name of the alloca in order to print out
   // names.
   Res.getCodeGenOpts().DiscardValueNames &=
-  !Res.getLangOpts()->Sanitize.has(SanitizerKind::Address) &&
-  !Res.getLangOpts()->Sanitize.has(SanitizerKind::Memory);
+  !LangOpts.Sanitize.has(SanitizerKind::Address) &&
+  !LangOpts.Sanitize.has(SanitizerKind::Memory);
 
   // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of
   // PCH file and find the original header name. Remove the need to do that in


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2110,6 +2110,7 @@
   InputArgList Args =
   Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex,
   MissingArgCount, IncludedFlagsBitmask);
+  LangOptions &LangOpts = *Res.getLangOpts();
 
   // Check for missing argument error.
   if (MissingArgCount) {
@@ -2128,7 +2129,7 @@
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
   Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags);
-  ParseCommentArgs(Res.getLangOpts()->CommentOpts, Args);
+  ParseCommentArgs(LangOpts.CommentOpts, Args);
   ParseFileSystemArgs(Res.getFileSystemOpts(), Args);
   // FIXME: We shouldn't have to pass the DashX option around here
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags);
@@ -2141,22 +2142,26 @@
 // PassManager in BackendUtil.cpp. They need to be initializd no matter
 // what the input type is.
 if (Args.hasArg(OPT_fobjc_arc))
-  Res.getLangOpts()->ObjCAutoRefCount = 1;
+  LangOpts.ObjCAutoRefCount = 1;
+// PIClevel and PIELevel are needed during code generation and this should be
+// set regardless of the input type.
+LangOpts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
+LangOpts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
-Diags, Res.getLangOpts()->Sanitize);
+Diags, LangOpts.Sanitize);
   } else {
 // Other LangOpts are only initialzed when the input is not AST or LLVM IR.
-ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), Diags);
+ParseLangArgs(LangOpts, Args, DashX, Res.getTargetOpts(), Diags);
 

[clang] Propeller config for clang (PR #91002)

2024-05-03 Thread Sriraman Tallam via cfe-commits

https://github.com/tmsri created https://github.com/llvm/llvm-project/pull/91002

This patch adds a Propeller config to cmake to allow building a
Propeller optimized clang.

Building a propeller optimizing clang requires hardware LBR support
and a built create_llvm_prof binary from: https://github.com/google/autofdo

Add -DPATH_TO_CREATE_LLVM_PROF= and
-C /clang/cmake/caches/Propeller.cmake to the cmake
command. To build a propeller optimized binary, build target
propeller-opt-binary.


>From a9daae4fafb096253a985054bbfa8482669796e0 Mon Sep 17 00:00:00 2001
From: Sriraman Tallam 
Date: Fri, 3 May 2024 12:43:29 -0700
Subject: [PATCH] Propeller config for clang

This patch adds a Propeller config to cmake to allow building a
Propeller optimized clang.

Building a propeller optimizing clang requires hardware LBR support
and a built create_llvm_prof binary from: https://github.com/google/autofdo

Add -DPATH_TO_CREATE_LLVM_PROF= and
-C /clang/cmake/caches/Propeller.cmake to the cmake
command. To build a propeller optimized binary, build target
propeller-opt-binary.
---
 clang/CMakeLists.txt   | 180 +
 clang/cmake/caches/Propeller.cmake |  10 ++
 2 files changed, 190 insertions(+)
 create mode 100644 clang/cmake/caches/Propeller.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index cf97e3c6e851ae..51fabe3dab9c79 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -928,6 +928,186 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   )
 endif()
 
+if (CLANG_PROPELLER_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+  set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
+  set(CLANGXX_PATH ${CLANG_PATH}++)
+  set(PROPELLER_ARTIFACTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/propeller-artifacts)
+  set(PROPELLER_INSTRUMENTED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-instrumented-clang/)
+  set(PROPELLER_PROFILING_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-profile-collection-run/)
+  set(PROPELLER_OPTIMIZED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-optimized-clang/)
+  set(CLANG_PROPELLER_LABELS ${PROPELLER_INSTRUMENTED_BINARY_DIR}/bin/clang)
+  set(CLANG_PROPELLER_LABELS_BINARY 
${CLANG_PROPELLER_LABELS}-${CLANG_VERSION_MAJOR})
+  set(CLANGXX_PROPELLER_LABELS ${CLANG_PROPELLER_LABELS}++)
+  set(PROPELLER_PERF_DATA 
${PROPELLER_ARTIFACTS_DIR}/profiles/propeller_perf.data)
+  set(PROPELLER_CLUSTER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/cluster.txt)
+  set(PROPELLER_SYMORDER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/symorder.txt)
+
+  #  Check if perf is available on the system and supports LBR, otherwise
+  #  abort as Propeller cannot be applied here.
+  set(perf_args "${PROPELLER_PERF_PROFILE_COLLECTION_PREFIX}")
+  separate_arguments(perf_args UNIX_COMMAND "${perf_args}")
+  execute_process(
+ COMMAND perf ${perf_args} -- ls
+ RESULT_VARIABLE perf_status
+ OUTPUT_VARIABLE perf_stats
+ ERROR_QUIET
+  )
+  if (perf_status)
+ message(FATAL_ERROR "perf with LBR is not available on this system")
+  else()
+ message(STATUS "perf is available and supports LBR")
+  endif()
+
+  #  Check if create_llvm_prof is available, otherwise abort as Propeller
+  #  cannot be applied here.
+  execute_process(
+ COMMAND sh -c "${PATH_TO_CREATE_LLVM_PROF} --version"
+ RESULT_VARIABLE create_llvm_prof_status
+ OUTPUT_VARIABLE create_llvm_prof_out
+ ERROR_QUIET
+  )
+  if (create_llvm_prof_status)
+ message(FATAL_ERROR "create_llvm_prof is not installed/available at: 
${PATH_TO_CREATE_LLVM_PROF}. "
+ "Use -DPATH_TO_CREATE_LLVM_PROF= during cmake to 
specify its location.")
+  else()
+ message(STATUS "create_llvm_prof is available")
+  endif()
+
+  #  Build an "instrumented" Propeller binary with Propeller labels.  This adds
+  #  a metadata section to the clang binary.
+  add_custom_target(propeller-labels
+ COMMENT "Creating Propeller Labels Binary"
+ DEPENDS clang clang-propeller-labels-build
+  )
+
+  # This command converts hardware profiles to the propeller format.
+  add_custom_command(OUTPUT ${PROPELLER_CLUSTER_FILE}
+ DEPENDS ${PROPELLER_PERF_DATA}
+ COMMAND ${PATH_TO_CREATE_LLVM_PROF} --format=propeller
+ --binary=${CLANG_PROPELLER_LABELS_BINARY}
+--profile=${PROPELLER_PERF_DATA}
+ --out=${PROPELLER_CLUSTER_FILE}
+--propeller_symorder=${PROPELLER_SYMORDER_FILE}
+--propeller_call_chain_clustering
+--propeller_chain_split
+ VERBATIM
+  )
+
+  # Generate Propeller profiles by first hardware sampling a build of clang and
+  # then converting it using create_llvm_prof.
+  add_custom_target(propeller-gen-profiles
+ COMMENT "Generating Propeller Profiles"
+ DEPENDS ${PROPELLER_CLUSTER_FILE}
+  )
+
+  #  This uses the generated Propeller layout files to build the final 
optimized
+  #  clang binary.
+  add_custom_target(propeller-opt-binary
+ COMMENT "Generating Propeller Optimized Clang"
+ DEPENDS clang-propel

[clang] Propeller config for clang (PR #91002)

2024-05-03 Thread Sriraman Tallam via cfe-commits

https://github.com/tmsri updated https://github.com/llvm/llvm-project/pull/91002

>From a9daae4fafb096253a985054bbfa8482669796e0 Mon Sep 17 00:00:00 2001
From: Sriraman Tallam 
Date: Fri, 3 May 2024 12:43:29 -0700
Subject: [PATCH 1/2] Propeller config for clang

This patch adds a Propeller config to cmake to allow building a
Propeller optimized clang.

Building a propeller optimizing clang requires hardware LBR support
and a built create_llvm_prof binary from: https://github.com/google/autofdo

Add -DPATH_TO_CREATE_LLVM_PROF= and
-C /clang/cmake/caches/Propeller.cmake to the cmake
command. To build a propeller optimized binary, build target
propeller-opt-binary.
---
 clang/CMakeLists.txt   | 180 +
 clang/cmake/caches/Propeller.cmake |  10 ++
 2 files changed, 190 insertions(+)
 create mode 100644 clang/cmake/caches/Propeller.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index cf97e3c6e851ae..51fabe3dab9c79 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -928,6 +928,186 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   )
 endif()
 
+if (CLANG_PROPELLER_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+  set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
+  set(CLANGXX_PATH ${CLANG_PATH}++)
+  set(PROPELLER_ARTIFACTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/propeller-artifacts)
+  set(PROPELLER_INSTRUMENTED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-instrumented-clang/)
+  set(PROPELLER_PROFILING_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-profile-collection-run/)
+  set(PROPELLER_OPTIMIZED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-optimized-clang/)
+  set(CLANG_PROPELLER_LABELS ${PROPELLER_INSTRUMENTED_BINARY_DIR}/bin/clang)
+  set(CLANG_PROPELLER_LABELS_BINARY 
${CLANG_PROPELLER_LABELS}-${CLANG_VERSION_MAJOR})
+  set(CLANGXX_PROPELLER_LABELS ${CLANG_PROPELLER_LABELS}++)
+  set(PROPELLER_PERF_DATA 
${PROPELLER_ARTIFACTS_DIR}/profiles/propeller_perf.data)
+  set(PROPELLER_CLUSTER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/cluster.txt)
+  set(PROPELLER_SYMORDER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/symorder.txt)
+
+  #  Check if perf is available on the system and supports LBR, otherwise
+  #  abort as Propeller cannot be applied here.
+  set(perf_args "${PROPELLER_PERF_PROFILE_COLLECTION_PREFIX}")
+  separate_arguments(perf_args UNIX_COMMAND "${perf_args}")
+  execute_process(
+ COMMAND perf ${perf_args} -- ls
+ RESULT_VARIABLE perf_status
+ OUTPUT_VARIABLE perf_stats
+ ERROR_QUIET
+  )
+  if (perf_status)
+ message(FATAL_ERROR "perf with LBR is not available on this system")
+  else()
+ message(STATUS "perf is available and supports LBR")
+  endif()
+
+  #  Check if create_llvm_prof is available, otherwise abort as Propeller
+  #  cannot be applied here.
+  execute_process(
+ COMMAND sh -c "${PATH_TO_CREATE_LLVM_PROF} --version"
+ RESULT_VARIABLE create_llvm_prof_status
+ OUTPUT_VARIABLE create_llvm_prof_out
+ ERROR_QUIET
+  )
+  if (create_llvm_prof_status)
+ message(FATAL_ERROR "create_llvm_prof is not installed/available at: 
${PATH_TO_CREATE_LLVM_PROF}. "
+ "Use -DPATH_TO_CREATE_LLVM_PROF= during cmake to 
specify its location.")
+  else()
+ message(STATUS "create_llvm_prof is available")
+  endif()
+
+  #  Build an "instrumented" Propeller binary with Propeller labels.  This adds
+  #  a metadata section to the clang binary.
+  add_custom_target(propeller-labels
+ COMMENT "Creating Propeller Labels Binary"
+ DEPENDS clang clang-propeller-labels-build
+  )
+
+  # This command converts hardware profiles to the propeller format.
+  add_custom_command(OUTPUT ${PROPELLER_CLUSTER_FILE}
+ DEPENDS ${PROPELLER_PERF_DATA}
+ COMMAND ${PATH_TO_CREATE_LLVM_PROF} --format=propeller
+ --binary=${CLANG_PROPELLER_LABELS_BINARY}
+--profile=${PROPELLER_PERF_DATA}
+ --out=${PROPELLER_CLUSTER_FILE}
+--propeller_symorder=${PROPELLER_SYMORDER_FILE}
+--propeller_call_chain_clustering
+--propeller_chain_split
+ VERBATIM
+  )
+
+  # Generate Propeller profiles by first hardware sampling a build of clang and
+  # then converting it using create_llvm_prof.
+  add_custom_target(propeller-gen-profiles
+ COMMENT "Generating Propeller Profiles"
+ DEPENDS ${PROPELLER_CLUSTER_FILE}
+  )
+
+  #  This uses the generated Propeller layout files to build the final 
optimized
+  #  clang binary.
+  add_custom_target(propeller-opt-binary
+ COMMENT "Generating Propeller Optimized Clang"
+ DEPENDS clang-propeller-optimized-build
+  )
+
+  # This project is setup to build a propeller "instrumented" labels binary.
+  set(STAMP_DIR 
${PROPELLER_ARTIFACTS_DIR}/stamps/propeller-instrumented-clang-stamps/)
+  set(build_configuration "$")
+  include(ExternalProject)
+  set(CLANG_PROPELLER_INSTRUMENT_CMAKE_CC_FLAGS "-fbasic-block-sections=labels 
${CLANG_PROPELLER_EXTRA_CMAKE_CC_FLAGS}")
+  set(CLANG_PROPELLER_INSTR

[clang] Propeller config for clang (PR #91002)

2024-05-03 Thread Sriraman Tallam via cfe-commits


@@ -928,6 +928,186 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   )
 endif()
 
+if (CLANG_PROPELLER_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+  set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
+  set(CLANGXX_PATH ${CLANG_PATH}++)
+  set(PROPELLER_ARTIFACTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/propeller-artifacts)
+  set(PROPELLER_INSTRUMENTED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-instrumented-clang/)
+  set(PROPELLER_PROFILING_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-profile-collection-run/)
+  set(PROPELLER_OPTIMIZED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-optimized-clang/)
+  set(CLANG_PROPELLER_LABELS ${PROPELLER_INSTRUMENTED_BINARY_DIR}/bin/clang)
+  set(CLANG_PROPELLER_LABELS_BINARY 
${CLANG_PROPELLER_LABELS}-${CLANG_VERSION_MAJOR})
+  set(CLANGXX_PROPELLER_LABELS ${CLANG_PROPELLER_LABELS}++)
+  set(PROPELLER_PERF_DATA 
${PROPELLER_ARTIFACTS_DIR}/profiles/propeller_perf.data)
+  set(PROPELLER_CLUSTER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/cluster.txt)
+  set(PROPELLER_SYMORDER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/symorder.txt)
+
+  #  Check if perf is available on the system and supports LBR, otherwise
+  #  abort as Propeller cannot be applied here.
+  set(perf_args "${PROPELLER_PERF_PROFILE_COLLECTION_PREFIX}")
+  separate_arguments(perf_args UNIX_COMMAND "${perf_args}")
+  execute_process(
+ COMMAND perf ${perf_args} -- ls
+ RESULT_VARIABLE perf_status
+ OUTPUT_VARIABLE perf_stats
+ ERROR_QUIET
+  )
+  if (perf_status)
+ message(FATAL_ERROR "perf with LBR is not available on this system")
+  else()
+ message(STATUS "perf is available and supports LBR")
+  endif()
+
+  #  Check if create_llvm_prof is available, otherwise abort as Propeller
+  #  cannot be applied here.
+  execute_process(
+ COMMAND sh -c "${PATH_TO_CREATE_LLVM_PROF} --version"
+ RESULT_VARIABLE create_llvm_prof_status
+ OUTPUT_VARIABLE create_llvm_prof_out
+ ERROR_QUIET
+  )
+  if (create_llvm_prof_status)
+ message(FATAL_ERROR "create_llvm_prof is not installed/available at: 
${PATH_TO_CREATE_LLVM_PROF}. "
+ "Use -DPATH_TO_CREATE_LLVM_PROF= during cmake to 
specify its location.")
+  else()
+ message(STATUS "create_llvm_prof is available")
+  endif()
+
+  #  Build an "instrumented" Propeller binary with Propeller labels.  This adds
+  #  a metadata section to the clang binary.
+  add_custom_target(propeller-labels
+ COMMENT "Creating Propeller Labels Binary"
+ DEPENDS clang clang-propeller-labels-build
+  )
+
+  # This command converts hardware profiles to the propeller format.
+  add_custom_command(OUTPUT ${PROPELLER_CLUSTER_FILE}
+ DEPENDS ${PROPELLER_PERF_DATA}
+ COMMAND ${PATH_TO_CREATE_LLVM_PROF} --format=propeller
+ --binary=${CLANG_PROPELLER_LABELS_BINARY}
+--profile=${PROPELLER_PERF_DATA}
+ --out=${PROPELLER_CLUSTER_FILE}
+--propeller_symorder=${PROPELLER_SYMORDER_FILE}
+--propeller_call_chain_clustering
+--propeller_chain_split
+ VERBATIM
+  )
+
+  # Generate Propeller profiles by first hardware sampling a build of clang and
+  # then converting it using create_llvm_prof.
+  add_custom_target(propeller-gen-profiles
+ COMMENT "Generating Propeller Profiles"
+ DEPENDS ${PROPELLER_CLUSTER_FILE}
+  )
+
+  #  This uses the generated Propeller layout files to build the final 
optimized
+  #  clang binary.
+  add_custom_target(propeller-opt-binary
+ COMMENT "Generating Propeller Optimized Clang"
+ DEPENDS clang-propeller-optimized-build
+  )
+
+  # This project is setup to build a propeller "instrumented" labels binary.
+  set(STAMP_DIR 
${PROPELLER_ARTIFACTS_DIR}/stamps/propeller-instrumented-clang-stamps/)
+  set(build_configuration "$")
+  include(ExternalProject)
+  set(CLANG_PROPELLER_INSTRUMENT_CMAKE_CC_FLAGS "-fbasic-block-sections=labels 
${CLANG_PROPELLER_EXTRA_CMAKE_CC_FLAGS}")

tmsri wrote:

Updated.

https://github.com/llvm/llvm-project/pull/91002
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D96109: Refactor implementation of -funique-internal-linkage-names.

2022-03-02 Thread Sriraman Tallam via cfe-commits
On Wed, Mar 2, 2022 at 11:08 AM Ellis Hoag via Phabricator <
revi...@reviews.llvm.org> wrote:

> ellis added a comment.
> Herald added a subscriber: ormris.
> Herald added a project: All.
>
> Hi @tmsriram. I found a clang crash when using the flag
> `-funique-internal-linkage-names` that only happens after this diff. Would
> you mind taking a look?
>
>   $ cat test.c
>   inline void foo() {}
>   extern void foo();
>   $ clang -funique-internal-linkage-names test.c -c
>

Sure, will take a look.  The first foo here is internal linkage and must be
mangled, not the second.


>
> More details are in this bug report
> https://github.com/llvm/llvm-project/issues/54139
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D96109/new/
>
> https://reviews.llvm.org/D96109
>
>

-- 

SriTallam |

Software Engineer |

tmsri...@google.com |
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d8c6d24 - -funique-internal-linkage-names appends a hex md5hash suffix to the symbol name which is not demangler friendly, convert it to decimal.

2021-01-11 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2021-01-11T11:10:29-08:00
New Revision: d8c6d24359f17c55a8966231ef74e8f4b03ad282

URL: 
https://github.com/llvm/llvm-project/commit/d8c6d24359f17c55a8966231ef74e8f4b03ad282
DIFF: 
https://github.com/llvm/llvm-project/commit/d8c6d24359f17c55a8966231ef74e8f4b03ad282.diff

LOG: -funique-internal-linkage-names appends a hex md5hash suffix to the symbol 
name which is not demangler friendly, convert it to decimal.

Please see D93747 for more context which tries to make linkage names of internal
linkage functions to be the uniqueified names. This causes a problem with gdb
because breaking using the demangled function name will not work if the new
uniqueified name cannot be demangled. The problem is the generated suffix which
is a mix of integers and letters which do not demangle. The demangler accepts
either all numbers or all letters. This patch simply converts the hash to 
decimal.

There is no loss of uniqueness by doing this as the precision is maintained.
The symbol names get longer by a few characters though.

Differential Revision: https://reviews.llvm.org/D94154

Added: 


Modified: 
clang/test/CodeGen/unique-internal-linkage-names.cpp
llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll

Removed: 




diff  --git a/clang/test/CodeGen/unique-internal-linkage-names.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names.cpp
index 3ad3bdc9f1bbb..b731ed07f4a76 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -53,15 +53,15 @@ int mver_call() {
 // PLAIN: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // PLAIN: define internal i32 @_ZL4mverv()
 // PLAIN: define internal i32 @_ZL4mverv.sse4.2()
-// UNIQUE: @_ZL4glob.__uniq.{{[0-9a-f]+}} = internal global
-// UNIQUE: @_ZZ8retAnonMvE5fGlob.__uniq.{{[0-9a-f]+}} = internal global
-// UNIQUE: @_ZN12_GLOBAL__N_16anon_mE.__uniq.{{[0-9a-f]+}} = internal global
-// UNIQUE: define internal i32 @_ZL3foov.__uniq.{{[0-9a-f]+}}()
-// UNIQUE: define internal i32 @_ZN12_GLOBAL__N_14getMEv.__uniq.{{[0-9a-f]+}}
+// UNIQUE: @_ZL4glob.__uniq.{{[0-9]+}} = internal global
+// UNIQUE: @_ZZ8retAnonMvE5fGlob.__uniq.{{[0-9]+}} = internal global
+// UNIQUE: @_ZN12_GLOBAL__N_16anon_mE.__uniq.{{[0-9]+}} = internal global
+// UNIQUE: define internal i32 @_ZL3foov.__uniq.{{[0-9]+}}()
+// UNIQUE: define internal i32 @_ZN12_GLOBAL__N_14getMEv.__uniq.{{[0-9]+}}
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUE: define internal i32 @_ZL4mverv.__uniq.{{[0-9a-f]+}}()
-// UNIQUE: define internal i32 @_ZL4mverv.sse4.2.__uniq.{{[0-9a-f]+}}
-// UNIQUEO1: define internal i32 @_ZL3foov.__uniq.{{[0-9a-f]+}}()
+// UNIQUE: define internal i32 @_ZL4mverv.__uniq.{{[0-9]+}}()
+// UNIQUE: define internal i32 @_ZL4mverv.sse4.2.__uniq.{{[0-9]+}}
+// UNIQUEO1: define internal i32 @_ZL3foov.__uniq.{{[0-9]+}}()
 // UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUEO1: define internal i32 @_ZL4mverv.__uniq.{{[0-9a-f]+}}()
-// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.__uniq.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL4mverv.__uniq.{{[0-9]+}}()
+// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.__uniq.{{[0-9]+}}

diff  --git a/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp 
b/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
index 385bf8bb429ae..29ad0b6fcae50 100644
--- a/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ b/llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -27,9 +27,12 @@ static bool uniqueifyInternalLinkageNames(Module &M) {
   Md5.final(R);
   SmallString<32> Str;
   llvm::MD5::stringifyResult(R, Str);
+  // Convert MD5hash to Decimal. Demangler suffixes can either contain numbers
+  // or characters but not both.
+  APInt IntHash = APInt(128, Str.str(), 16);
   // Prepend "__uniq" before the hash for tools like profilers to understand 
that
   // this symbol is of internal linkage type.
-  std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
+  std::string ModuleNameHash = (Twine(".__uniq.") + Twine(IntHash.toString(10, 
false))).str();
   bool Changed = false;
 
   // Append the module hash to all internal linkage functions.

diff  --git 
a/llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll 
b/llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
index bf15daebda383..492c716a0bb11 100644
--- a/llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
+++ b/llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
@@ -10,5 +10,5 @@ entry:
   ret i32 0
 }
 
-; CHECK: @glob.__uniq.6ae72bb15a7d1834b42ae042a58f7a4d = internal global
-; CHECK: define internal i32 @foo.__uniq.6ae72bb15a7d1834b42ae042a58f7a4d()
+; CHECK: @glob.__uniq.142098474322525230676991677

[clang] [lld] [llvm] Adding Matching and Inference Functionality to Propeller (PR #139008)

2025-05-23 Thread Sriraman Tallam via cfe-commits


@@ -1688,6 +1688,11 @@ def fprofile_sample_accurate : Flag<["-"], 
"fprofile-sample-accurate">,
as cold. Otherwise, treat callsites without profile samples as 
if
we have no profile}]>,
MarshallingInfoFlag>;
+def fpropeller_profile_use_EQ : Joined<["-"], "fpropeller-profile-use=">,
+Group, Visibility<[ClangOption, CC1Option, CLOption]>, 
+MetaVarName<"">,

tmsri wrote:

So, we want :

1.  Another option to expose raw propeller profiles, MBB hashes and counts to 
the compiler.  
2.  It would be mutually exclusive to -fbasic-block-sections=list options

I want to have a discussion on how much of a maintenance burden this would 
cause.  This is because Propeller will now do code layout in two different 
ways.  With stale profiles, the compiler will do it.   By default, the offline 
tool would do it.  For future optimizations, we need to figure out how to 
support two paths.  @rlavaee @shenhanc78 

Can we expose raw profiles using -fbasic-blocks-sections=list= itself?  Do we 
need a new option?   I like the stale profile matching ideas but I am not sure 
adding a new flag and a new file is the way to go forward.




https://github.com/llvm/llvm-project/pull/139008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits