[PATCH] D68213: [LTO] Support for embedding bitcode section during LTO

2019-12-11 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

LGTM with a few small suggestions before you commit.




Comment at: llvm/lib/LTO/LTOBackend.cpp:317
+static cl::opt EmbedBitcode("lto-embed-bitcode", cl::init(false),
+  cl::desc("Embed LLVM bitcode"));
+

Expand description a bit to indicate that it will embed LLVM bitcode in object 
files produced by LTO.



Comment at: llvm/test/LTO/X86/embed-bitcode.ll:8
+
+; RUN: llvm-lto2 run -r %t1.o,_start,px -r %t2.o,foo,px -r %t3.o,bar,px -r 
%t2.o,bar,px -lto-embed-bitcode=0 -o %t3 %t1.o %t2.o %t3.o
+; RUN: llvm-readelf -S %t3.0 | FileCheck %s --implicit-check-not=.llvmbc

I don't think it is necessary to check anything other than 
"-lto-embed-bitcode=false" and "-lto-embed-bitcode", and the default. Otherwise 
you are just testing the standard behavior of cl::opt, and that isn't necessary 
for a new internal option.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68213/new/

https://reviews.llvm.org/D68213



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


[PATCH] D67923: [TLI] Support for per-Function TLI that overrides available libfuncs

2019-12-16 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG878ab6df033d: [TLI] Support for per-Function TLI that 
overrides available libfuncs (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67923/new/

https://reviews.llvm.org/D67923

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp

Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -1588,22 +1588,12 @@
   return I->ScalarFnName;
 }
 
-TargetLibraryInfo TargetLibraryAnalysis::run(Function ,
+TargetLibraryInfo TargetLibraryAnalysis::run(const Function ,
  FunctionAnalysisManager &) {
-  if (PresetInfoImpl)
-return TargetLibraryInfo(*PresetInfoImpl);
-
-  return TargetLibraryInfo(
-  lookupInfoImpl(Triple(F.getParent()->getTargetTriple(;
-}
-
-TargetLibraryInfoImpl ::lookupInfoImpl(const Triple ) {
-  std::unique_ptr  =
-  Impls[T.normalize()];
-  if (!Impl)
-Impl.reset(new TargetLibraryInfoImpl(T));
-
-  return *Impl;
+  if (!BaselineInfoImpl)
+BaselineInfoImpl =
+TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
+  return TargetLibraryInfo(*BaselineInfoImpl, );
 }
 
 unsigned TargetLibraryInfoImpl::getWCharSize(const Module ) const {
@@ -1614,18 +1604,18 @@
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
-: ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
+: ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple )
-: ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
+: ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
 const TargetLibraryInfoImpl )
-: ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
+: ImmutablePass(ID), TLA(TLIImpl) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/Triple.h"
@@ -212,20 +213,50 @@
   friend class TargetLibraryAnalysis;
   friend class TargetLibraryInfoWrapperPass;
 
+  /// The global (module level) TLI info.
   const TargetLibraryInfoImpl *Impl;
 
+  /// Support for -fno-builtin* options as function attributes, overrides
+  /// information in global TargetLibraryInfoImpl.
+  BitVector OverrideAsUnavailable;
+
 public:
-  explicit TargetLibraryInfo(const TargetLibraryInfoImpl ) : Impl() {}
+  explicit TargetLibraryInfo(const TargetLibraryInfoImpl ,
+ Optional F = None)
+  : Impl(), OverrideAsUnavailable(NumLibFuncs) {
+if (!F)
+  return;
+if ((*F)->hasFnAttribute("no-builtins"))
+  disableAllFunctions();
+else {
+  // Disable individual libc/libm calls in TargetLibraryInfo.
+  LibFunc LF;
+  AttributeSet FnAttrs = (*F)->getAttributes().getFnAttributes();
+  for (const Attribute  : FnAttrs) {
+if (!Attr.isStringAttribute())
+  continue;
+auto AttrStr = Attr.getKindAsString();
+if (!AttrStr.consume_front("no-builtin-"))
+  continue;
+if (getLibFunc(AttrStr, LF))
+  setUnavailable(LF);
+  }
+}
+  }
 
   // Provide value semantics.
-  TargetLibraryInfo(const TargetLibraryInfo ) : Impl(TLI.Impl) {}
-  TargetLibraryInfo(TargetLibraryInfo &) : Impl(TLI.Impl) {}
+  TargetLibraryInfo(const TargetLibraryInfo )
+  : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
+  TargetLibraryInfo(TargetLibraryInfo &)
+  : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
   TargetLibraryInfo =(const TargetLibraryInfo ) {
 Impl = TLI.Impl;
+OverrideAsUnavailable = TLI.OverrideAsUnavailable;
 return *this;
   }
   TargetLibraryInfo =(TargetLibraryInfo &) {
 Impl = TLI.Impl;
+OverrideAsUnavailable = TLI.OverrideAsUnavailable;
 return *this;
   }
 
@@ -248,9 +279,27 @@
getLibFunc(*(CS.getCalledFunction()), F);
   }
 
+  /// Disables all builtins.
+  ///
+  /// This can be used for options like -fno-builtin.
+  void disableAllFunctions() LLVM_ATTRIBUTE_UNUSED {
+OverrideAsUnavailable.set();

[PATCH] D67923: [TLI] Support for per-Function TLI that overrides available libfuncs

2019-12-16 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 234090.
tejohnson added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67923/new/

https://reviews.llvm.org/D67923

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp

Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -1588,22 +1588,12 @@
   return I->ScalarFnName;
 }
 
-TargetLibraryInfo TargetLibraryAnalysis::run(Function ,
+TargetLibraryInfo TargetLibraryAnalysis::run(const Function ,
  FunctionAnalysisManager &) {
-  if (PresetInfoImpl)
-return TargetLibraryInfo(*PresetInfoImpl);
-
-  return TargetLibraryInfo(
-  lookupInfoImpl(Triple(F.getParent()->getTargetTriple(;
-}
-
-TargetLibraryInfoImpl ::lookupInfoImpl(const Triple ) {
-  std::unique_ptr  =
-  Impls[T.normalize()];
-  if (!Impl)
-Impl.reset(new TargetLibraryInfoImpl(T));
-
-  return *Impl;
+  if (!BaselineInfoImpl)
+BaselineInfoImpl =
+TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
+  return TargetLibraryInfo(*BaselineInfoImpl, );
 }
 
 unsigned TargetLibraryInfoImpl::getWCharSize(const Module ) const {
@@ -1614,18 +1604,18 @@
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
-: ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
+: ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple )
-: ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
+: ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
 const TargetLibraryInfoImpl )
-: ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
+: ImmutablePass(ID), TLA(TLIImpl) {
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/Triple.h"
@@ -212,20 +213,50 @@
   friend class TargetLibraryAnalysis;
   friend class TargetLibraryInfoWrapperPass;
 
+  /// The global (module level) TLI info.
   const TargetLibraryInfoImpl *Impl;
 
+  /// Support for -fno-builtin* options as function attributes, overrides
+  /// information in global TargetLibraryInfoImpl.
+  BitVector OverrideAsUnavailable;
+
 public:
-  explicit TargetLibraryInfo(const TargetLibraryInfoImpl ) : Impl() {}
+  explicit TargetLibraryInfo(const TargetLibraryInfoImpl ,
+ Optional F = None)
+  : Impl(), OverrideAsUnavailable(NumLibFuncs) {
+if (!F)
+  return;
+if ((*F)->hasFnAttribute("no-builtins"))
+  disableAllFunctions();
+else {
+  // Disable individual libc/libm calls in TargetLibraryInfo.
+  LibFunc LF;
+  AttributeSet FnAttrs = (*F)->getAttributes().getFnAttributes();
+  for (const Attribute  : FnAttrs) {
+if (!Attr.isStringAttribute())
+  continue;
+auto AttrStr = Attr.getKindAsString();
+if (!AttrStr.consume_front("no-builtin-"))
+  continue;
+if (getLibFunc(AttrStr, LF))
+  setUnavailable(LF);
+  }
+}
+  }
 
   // Provide value semantics.
-  TargetLibraryInfo(const TargetLibraryInfo ) : Impl(TLI.Impl) {}
-  TargetLibraryInfo(TargetLibraryInfo &) : Impl(TLI.Impl) {}
+  TargetLibraryInfo(const TargetLibraryInfo )
+  : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
+  TargetLibraryInfo(TargetLibraryInfo &)
+  : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
   TargetLibraryInfo =(const TargetLibraryInfo ) {
 Impl = TLI.Impl;
+OverrideAsUnavailable = TLI.OverrideAsUnavailable;
 return *this;
   }
   TargetLibraryInfo =(TargetLibraryInfo &) {
 Impl = TLI.Impl;
+OverrideAsUnavailable = TLI.OverrideAsUnavailable;
 return *this;
   }
 
@@ -248,9 +279,27 @@
getLibFunc(*(CS.getCalledFunction()), F);
   }
 
+  /// Disables all builtins.
+  ///
+  /// This can be used for options like -fno-builtin.
+  void disableAllFunctions() LLVM_ATTRIBUTE_UNUSED {
+OverrideAsUnavailable.set();
+  }
+
+  /// Forces a function to be marked as unavailable.
+  void setUnavailable(LibFunc F) 

[PATCH] D68213: [LTO] Support for embedding bitcode section during LTO

2019-12-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/lib/LTO/LTOBackend.cpp:335
+   .Case("bitcode", EmbedBitcodeKind::Embed_Bitcode)
+   .Case("marker", EmbedBitcodeKind::Embed_Marker)
+   .Default(~0U);

zapster wrote:
> tejohnson wrote:
> > Does this value make any sense since CmdArgs is always empty below?
> You are right. Currently, this option value is not utterly useful, but I kept 
> it for compatibility with clangs `-fembed-bitcode`. It seems the marker 
> section is needed (even if empty), otherwise certain tools will complain 
> (notably the MacOS linker). Ideally, we would have something sensible to 
> write into the section but I am not sure about reasonable values. I was not 
> able to find any information about consumers of these commands. Pointers in 
> that regard would be highly appreciated.
> 
> Anyhow, I lean toward keeping the options for compatibility with clang and 
> for making it simple to properly implement the `marker` case. That said, I am 
> perfectly fine with removing the option. In that case, I guess I should get 
> rid of `EmbedBitcodeKind` altogether and always insert the bitcode and the 
> marker, right?
> 
> On the other hand, we should maybe just consolidate the option (parsing) with 
> the clang option. Some thoughts about that in my inline comment above.
It's unclear to me whether it is better to not provide the marker, and get a 
clear error, or put in an empty marker which may cause these tools to do the 
wrong thing. @steven_wu who might be able to provide some guidance about how 
this is used by the MacOS linker. Note that if someone is using MacOS to do 
their LTO linking, they won't even trigger this code, as that toolchain uses 
the old legacy LTO, which doesn't come here.

Presumably your tool doesn't use the marker section?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68213/new/

https://reviews.llvm.org/D68213



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


[PATCH] D69327: [Clang][ThinLTO] Add a cache for compile phase output.

2019-10-24 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

We rely on the minimized bitcode from that option in our builds, so it won't be 
going away. We could add it as a driver option, but it doesn't sound like that 
will solve the ccache issue. I'm not very familiar with that cache support, or 
if there is a way to express other output files (in our build system we 
identify all the outputs of a build action). At least with something like make 
and ninja the compile action should not be done again if none of the inputs 
change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69327/new/

https://reviews.llvm.org/D69327



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


[PATCH] D69406: [clang][ThinLTO] Promote cc1 -fthin_link_bitcode to driver -fthinlto_link_bitcode

2019-10-24 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Thanks. Prefer the old name since it is already in use and since this is for 
the "thin link" phase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69406/new/

https://reviews.llvm.org/D69406



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


[PATCH] D69327: [Clang][ThinLTO] Add a cache for compile phase output.

2019-10-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

I haven't read through the patch in detail yet, but from the description it 
sounds like a cache is being added for the compile step outputs, e.g. the 
bitcode output object of the "clang -flto=thin -c" step? Typically the build 
system takes care of incremental build handling for these explicit outputs, 
just as it would for a non-LTO clang compile output. Can you clarify the 
motivation?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69327/new/

https://reviews.llvm.org/D69327



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


[PATCH] D69327: [Clang][ThinLTO] Add a cache for compile phase output.

2019-10-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

I was just typing up a response similar to @steven_wu 's response... I don't 
think clang should be in the business of caching the outputs of a prior clang 
invocation, the build system should and usually does avoid re-executing if the 
inputs have not changed. Note that this is very different from the caching of 
objects LTO is doing - because those are not otherwise emitted at all, the 
cache has to be built in.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69327/new/

https://reviews.llvm.org/D69327



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


[PATCH] D69327: [Clang][ThinLTO] Add a cache for compile phase output.

2019-10-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D69327#1719295 , @tejohnson wrote:

> I was just typing up a response similar to @steven_wu 's response... I don't 
> think clang should be in the business of caching the outputs of a prior clang 
> invocation, the build system should and usually does avoid re-executing if 
> the inputs have not changed. Note that this is very different from the 
> caching of objects LTO is doing - because those are not otherwise emitted at 
> all, the cache has to be built in.


And also because even if some of the inputs of the link change, not all backend 
threads necessarily need to be re-executed and not all native (intermediate) 
objects will change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69327/new/

https://reviews.llvm.org/D69327



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


[PATCH] D67385: Pass -mcmodel to LTO plugin

2019-09-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Typically -mcmodel is passed to the clang compile invocation which sets a 
module flag in the IR, which is then used by LTO (see calls to 
Module::setCodeModel() and Module::getCodeModel()). Why is it necessary to pass 
through the mcmodel passed to the link invocation?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67385/new/

https://reviews.llvm.org/D67385



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


[PATCH] D68029: [ThinLTO] Enable index-only WPD from clang

2019-09-25 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: pcc.
Herald added subscribers: arphaman, dexonsmith, steven_wu, inglorion, 
mehdi_amini.
Herald added a project: clang.

To trigger the index-only Whole Program Devirt support added to LLVM, we
need to be able to specify -fno-split-lto-unit in conjunction with
-fwhole-program-vtables. Keep the default for -fwhole-program-vtables as
-fsplit-lto-unit, but don't error on that option combination.


Repository:
  rC Clang

https://reviews.llvm.org/D68029

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/split-lto-unit.c


Index: test/Driver/split-lto-unit.c
===
--- test/Driver/split-lto-unit.c
+++ test/Driver/split-lto-unit.c
@@ -6,5 +6,5 @@
 
 // UNIT: "-fsplit-lto-unit"
 // NOUNIT-NOT: "-fsplit-lto-unit"
-// ERROR1: error: invalid argument '-fno-split-lto-unit' not allowed with 
'-fwhole-program-vtables'
+// ERROR1-NOT: error: invalid argument
 // ERROR2: error: invalid argument '-fno-split-lto-unit' not allowed with 
'-fsanitize=cfi'
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5446,14 +5446,13 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
-  bool RequiresSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
+  bool DefaultsSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
   bool SplitLTOUnit =
   Args.hasFlag(options::OPT_fsplit_lto_unit,
-   options::OPT_fno_split_lto_unit, RequiresSplitLTOUnit);
-  if (RequiresSplitLTOUnit && !SplitLTOUnit)
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< "-fno-split-lto-unit"
-<< (WholeProgramVTables ? "-fwhole-program-vtables" : 
"-fsanitize=cfi");
+   options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
+  if (Sanitize.needsLTO() && !SplitLTOUnit)
+D.Diag(diag::err_drv_argument_not_allowed_with) << "-fno-split-lto-unit"
+<< "-fsanitize=cfi";
   if (SplitLTOUnit)
 CmdArgs.push_back("-fsplit-lto-unit");
 


Index: test/Driver/split-lto-unit.c
===
--- test/Driver/split-lto-unit.c
+++ test/Driver/split-lto-unit.c
@@ -6,5 +6,5 @@
 
 // UNIT: "-fsplit-lto-unit"
 // NOUNIT-NOT: "-fsplit-lto-unit"
-// ERROR1: error: invalid argument '-fno-split-lto-unit' not allowed with '-fwhole-program-vtables'
+// ERROR1-NOT: error: invalid argument
 // ERROR2: error: invalid argument '-fno-split-lto-unit' not allowed with '-fsanitize=cfi'
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5446,14 +5446,13 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
-  bool RequiresSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
+  bool DefaultsSplitLTOUnit = WholeProgramVTables || Sanitize.needsLTO();
   bool SplitLTOUnit =
   Args.hasFlag(options::OPT_fsplit_lto_unit,
-   options::OPT_fno_split_lto_unit, RequiresSplitLTOUnit);
-  if (RequiresSplitLTOUnit && !SplitLTOUnit)
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< "-fno-split-lto-unit"
-<< (WholeProgramVTables ? "-fwhole-program-vtables" : "-fsanitize=cfi");
+   options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
+  if (Sanitize.needsLTO() && !SplitLTOUnit)
+D.Diag(diag::err_drv_argument_not_allowed_with) << "-fno-split-lto-unit"
+<< "-fsanitize=cfi";
   if (SplitLTOUnit)
 CmdArgs.push_back("-fsplit-lto-unit");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

FYI I have reproduced the failure, and am starting to debug.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Sent fix for review in D75201 .

If the new problem showed up later and not when this one first went in, then it 
seems likely it is different than this issue.  I'll see if I can reproduce and 
take a look.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D73242#1894146 , @tejohnson wrote:

> Sent fix for review in D75201 .
>
> If the new problem showed up later and not when this one first went in, then 
> it seems likely it is different than this issue.  I'll see if I can reproduce 
> and take a look.


I am not seeing this, although my client is from Friday. So it is likely 
something committed subsequently that caused it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D75655: [Docs] Document -lto-whole-program-visibility

2020-03-04 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: pcc.
Herald added subscribers: dexonsmith, steven_wu, hiraditya, inglorion.
Herald added a project: clang.

Documents interaction of linker option added in D71913 
 with LTO
visibility.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75655

Files:
  clang/docs/LTOVisibility.rst


Index: clang/docs/LTOVisibility.rst
===
--- clang/docs/LTOVisibility.rst
+++ clang/docs/LTOVisibility.rst
@@ -35,6 +35,16 @@
 (e.g. classes declared in unnamed namespaces) also receive hidden LTO
 visibility.
 
+During the LTO link, all classes with public LTO visibility will be refined
+to hidden LTO visibility when the ``-lto-whole-program-visibility`` lld linker
+option is applied (``-plugin-opt=whole_program_visibility`` for gold). This
+can be used when it is known that the LTO link has whole program visibility,
+because we are LTO linking all translation units as bitcode, except certain
+(e.g.  system) libraries or other native objects known to be safe by the user 
or
+build system, and the binary will not dlopen any libraries deriving from the
+binary’s classes. This is useful in situations where it is not safe to specify
+``-fvisibility=hidden`` at compile time.
+
 A class defined in a translation unit built without LTO receives public
 LTO visibility regardless of its object file visibility, linkage or other
 attributes.


Index: clang/docs/LTOVisibility.rst
===
--- clang/docs/LTOVisibility.rst
+++ clang/docs/LTOVisibility.rst
@@ -35,6 +35,16 @@
 (e.g. classes declared in unnamed namespaces) also receive hidden LTO
 visibility.
 
+During the LTO link, all classes with public LTO visibility will be refined
+to hidden LTO visibility when the ``-lto-whole-program-visibility`` lld linker
+option is applied (``-plugin-opt=whole_program_visibility`` for gold). This
+can be used when it is known that the LTO link has whole program visibility,
+because we are LTO linking all translation units as bitcode, except certain
+(e.g.  system) libraries or other native objects known to be safe by the user or
+build system, and the binary will not dlopen any libraries deriving from the
+binary’s classes. This is useful in situations where it is not safe to specify
+``-fvisibility=hidden`` at compile time.
+
 A class defined in a translation unit built without LTO receives public
 LTO visibility regardless of its object file visibility, linkage or other
 attributes.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-03-04 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: clang/test/CodeGenCXX/lto-visibility-inference.cpp:73
   c1->f();
-  // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C2"
+  // ITANIUM: type.test{{.*}}!"_ZTS2C2"
   // MS: type.test{{.*}}!"?AUC2@@"

pcc wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > tejohnson wrote:
> > > > evgeny777 wrote:
> > > > > tejohnson wrote:
> > > > > > evgeny777 wrote:
> > > > > > > What caused this and other changes in this file?
> > > > > > Because we now will insert type tests for non-hidden vtables. This 
> > > > > > is enabled by the changes to LTO to interpret these based on the 
> > > > > > vcall_visibility metadata.
> > > > > The results of this test case
> > > > > ```
> > > > > %clang_cc1 -flto -triple x86_64-pc-windows-msvc -std=c++11 
> > > > > -fms-extensions -fwhole-program-vtables -flto-visibility-public-std 
> > > > > -emit-llvm -o - %s | FileCheck --check-prefix=MS 
> > > > > --check-prefix=MS-NOSTD %s
> > > > > ```
> > > > > look not correct to me. I think you shouldn't generate type tests for 
> > > > > standard library classes with  `-flto-visibility-public-std`. 
> > > > > Currently if this flag is given, clang doesn't do this either even 
> > > > > with `-fvisibility=hidden`
> > > > The associated vtables would get the vcall_visibility public metadata, 
> > > > so the type tests themselves aren't problematic. I tend to think that 
> > > > an application using such options should simply stick with 
> > > > -fvisibility=hidden to get WPD and not use the new LTO option to 
> > > > convert all public vcall_visibility metadata to hidden.
> > > > The associated vtables would get the vcall_visibility public metadata, 
> > > > so the type tests themselves aren't problematic. I tend to think that 
> > > > an application using such options should simply stick with 
> > > > -fvisibility=hidden to get WPD and not use the new LTO option to 
> > > > convert all public vcall_visibility metadata to hidden.
> > > 
> > > I see two issues here:
> > > 1) It's not always good option to force hidden visibility for everything. 
> > > For instance I work on proprietary platform which demands public 
> > > visibility for certain symbols in order for dynamic loader to work 
> > > properly. In this context your patch does a great job.
> > > 
> > > 2) Standard library is almost never LTOed so in general we can't narrow 
> > > std::* vtables visibility to linkage unit
> > > 
> > > Is there anything which prevents from implementing the same functionality 
> > > with new -lto-whole-program-visibility option (i.e without forcing hidden 
> > > visibility)? In other words the following looks good to me:
> > > 
> > > ```
> > > # Compile with lto/devirtualization support
> > > clang -flto=thin -flto-visibility-public-std -fwhole-program-vtables -c 
> > > *.cpp
> > > 
> > > # Link: everything is devirtualized except standard library classes 
> > > virtual methods
> > > clang -Wl,-lto-whole-program-visibility -fuse-ld=lld *.o
> > > ```
> > Ok, thanks for the info. I will go ahead and change the code to not insert 
> > the type tests in this case to support this usage.
> > 
> > Ultimately, I would like to decouple the existence of the type tests from 
> > visibility implications. I'm working on another change to delay 
> > lowering/removal of type tests until after indirect call promotion, so we 
> > can use them in other cases (streamlined indirect call promotion checks 
> > against the vtable instead of the function pointers, also useful if we want 
> > to implement speculative devirtualization based on WPD info). In those 
> > cases we need the type tests, either to locate information in the summary, 
> > or to get the address point offset for a vtable address compare. In that 
> > case it would be helpful to have the type tests in this type of code as 
> > well. So we'll need another way to communicate down to WPD that they should 
> > never be devirtualized. But I don't think it makes sense to design this 
> > support until there is a concrete use case and need. In the meantime I will 
> > change the code to be conservative and not insert the type tests in this 
> > case.
> Note that `-flto-visibility-public-std` is a cc1-only option and only used on 
> Windows, and further that `-lto-whole-program-visibility` as implemented 
> doesn't really make sense on Windows because the classes with public 
> visibility are going to be marked dllimport/dllexport/uuid (COM), and 
> `-lto-whole-program-visibility` corresponds to flags such as 
> `--version-script` or the absence of `-shared` in which the linker 
> automatically relaxes the visibility of some symbols, while there is no such 
> concept of relaxing symbol visibility on Windows.
> 
>  I would be inclined to remove this support and either let the public 
> visibility automatically derive from the absence of 
> `-lto-whole-program-visibility` at link time in COFF links or 

[PATCH] D61634: [clang/llvm] Allow efficient implementation of libc's memory functions in C/C++

2020-02-28 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

The last patch from my side just went in (D74162 
: [Inliner] Inlining should honor nobuiltin 
attributes). So I think this is now complete.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61634/new/

https://reviews.llvm.org/D61634



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


[PATCH] D75655: [Docs] Document -lto-whole-program-visibility

2020-03-05 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 248582.
tejohnson marked an inline comment as done.
tejohnson added a comment.

Fix gold plugin option


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75655/new/

https://reviews.llvm.org/D75655

Files:
  clang/docs/LTOVisibility.rst


Index: clang/docs/LTOVisibility.rst
===
--- clang/docs/LTOVisibility.rst
+++ clang/docs/LTOVisibility.rst
@@ -35,6 +35,16 @@
 (e.g. classes declared in unnamed namespaces) also receive hidden LTO
 visibility.
 
+During the LTO link, all classes with public LTO visibility will be refined
+to hidden LTO visibility when the ``-lto-whole-program-visibility`` lld linker
+option is applied (``-plugin-opt=whole-program-visibility`` for gold). This
+can be used when it is known that the LTO link has whole program visibility,
+because we are LTO linking all translation units as bitcode, except certain
+(e.g.  system) libraries or other native objects known to be safe by the user 
or
+build system, and the binary will not dlopen any libraries deriving from the
+binary’s classes. This is useful in situations where it is not safe to specify
+``-fvisibility=hidden`` at compile time.
+
 A class defined in a translation unit built without LTO receives public
 LTO visibility regardless of its object file visibility, linkage or other
 attributes.


Index: clang/docs/LTOVisibility.rst
===
--- clang/docs/LTOVisibility.rst
+++ clang/docs/LTOVisibility.rst
@@ -35,6 +35,16 @@
 (e.g. classes declared in unnamed namespaces) also receive hidden LTO
 visibility.
 
+During the LTO link, all classes with public LTO visibility will be refined
+to hidden LTO visibility when the ``-lto-whole-program-visibility`` lld linker
+option is applied (``-plugin-opt=whole-program-visibility`` for gold). This
+can be used when it is known that the LTO link has whole program visibility,
+because we are LTO linking all translation units as bitcode, except certain
+(e.g.  system) libraries or other native objects known to be safe by the user or
+build system, and the binary will not dlopen any libraries deriving from the
+binary’s classes. This is useful in situations where it is not safe to specify
+``-fvisibility=hidden`` at compile time.
+
 A class defined in a translation unit built without LTO receives public
 LTO visibility regardless of its object file visibility, linkage or other
 attributes.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75655: [Docs] Document -lto-whole-program-visibility

2020-03-05 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 3 inline comments as done.
tejohnson added a subscriber: evgeny777.
tejohnson added inline comments.



Comment at: clang/docs/LTOVisibility.rst:40
+to hidden LTO visibility when the ``-lto-whole-program-visibility`` lld linker
+option is applied (``-plugin-opt=whole_program_visibility`` for gold). This
+can be used when it is known that the LTO link has whole program visibility,

pcc wrote:
> Isn't it spelled `whole-program-visibility`?
good catch, yes



Comment at: clang/docs/LTOVisibility.rst:45
+build system, and the binary will not dlopen any libraries deriving from the
+binary’s classes. This is useful in situations where it is not safe to specify
+``-fvisibility=hidden`` at compile time.

pcc wrote:
> I thought that the motivation was avoiding duplicate work in the case where 
> you need varying LTO visibility? Otherwise you could just build with and 
> without `-fvisibility=hidden` and it would be the same from an LTO visibility 
> perspective.
Yeah I started to write that out but it seemed too verbose (essentially we 
can't share a single bitcode object anymore without this, because it isn't safe 
for all dependent links, which to me is included in "situations where it is not 
safe to specify -fvisibility=hidden"). Also, on D71913, @evgeny777 mentioned he 
had a case were the symbol visibility constraints didn't allow for 
-fvisibility=hidden, but where LTO visibility for vtables can be hidden. I 
could add something more verbose about my case if you prefer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75655/new/

https://reviews.llvm.org/D75655



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-03-02 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Reverted in 80bf137fa132ea33204e98bbefa924afe9258a4e 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D73242#1888295 , @tejohnson wrote:

> FYI I have reproduced the failure, and am starting to debug.


I see what is going on and have a simple fix, just need to create a test case. 
Expect to send a patch to fix this today, hopefully this morning.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

FYI I reverted this in rG90e630a95ecc 
 due to a 
cfi test failure in a windows sanitizer bot. Not sure what is happening, I'll 
need to try to debug it somehow tomorrow.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913



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


[PATCH] D73418: [WPD] Emit vcall_visibility metadata for MicrosoftCXXABI

2020-01-25 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

I fixed the test matching as I found that the names generated for the anonymous 
namespace comdats depend on the module identifier in some way. I changed the 
matching to look at the struct type embedded in the initializer, which is also 
more intuitive. I also moved the new MS checks to be alongside the companion 
Itanium checks. And I added comments noting that MSVC gets DSO (hidden) 
visibility by default.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73418/new/

https://reviews.llvm.org/D73418



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


[PATCH] D73418: [WPD] Emit vcall_visibility metadata for MicrosoftCXXABI

2020-01-25 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 240395.
tejohnson added a comment.

Improve test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73418/new/

https://reviews.llvm.org/D73418

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp


Index: clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
===
--- clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
+++ clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-VFE
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-NOVFE
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK-MS 
--check-prefix=CHECK-NOVFE
 
 // Check that in ThinLTO we also get vcall_visibility summary entries in the 
bitcode
 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux 
-emit-llvm-bc -fwhole-program-vtables -o - %s | llvm-dis -o - | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-NOVFE --check-prefix=CHECK-SUMMARY
@@ -8,6 +9,7 @@
 // Anonymous namespace.
 namespace {
 // CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::A{{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
 struct A {
   A() {}
   virtual int f() { return 1; }
@@ -20,6 +22,7 @@
 
 // Hidden visibility.
 // CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.B{{.*}} 
!vcall_visibility [[VIS_DSO:![0-9]+]]
 struct __attribute__((visibility("hidden"))) B {
   B() {}
   virtual int f() { return 1; }
@@ -31,6 +34,8 @@
 
 // Default visibility.
 // CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.C{{.*}} 
!vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("default"))) C {
   C() {}
   virtual int f() { return 1; }
@@ -42,6 +47,7 @@
 
 // Hidden visibility, public LTO visibility.
 // CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
+// CHECK-MS-NOT: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.D{{.*}} !vcall_visibility
 struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] 
D {
   D() {}
   virtual int f() { return 1; }
@@ -53,6 +59,8 @@
 
 // Hidden visibility, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.E{{.*}} 
!vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("hidden"))) E : C {
   E() {}
   virtual int f() { return 1; }
@@ -64,6 +72,8 @@
 
 // Anonymous namespace, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::F{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) F : C {
   F() {}
@@ -77,6 +87,7 @@
 
 // Anonymous namespace, but inherits from class with hidden visibility.
 // CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility 
[[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::G{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) G : B {
   G() {}
@@ -87,6 +98,8 @@
   return new G();
 }
 
+// CHECK-MS-DAG: [[VIS_DSO]] = !{i64 1}
+// CHECK-MS-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-DAG: [[VIS_DSO]] = !{i64 1}
 // CHECK-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-VFE-DAG: !{i32 1, !"Virtual Function Elim", i32 1}
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1621,6 +1621,15 @@
   if (!CGM.getCodeGenOpts().LTOUnit)
 return;
 
+  // TODO: Should VirtualFunctionElimination also be supported here?
+  // See similar handling in CodeGenModule::EmitVTableTypeMetadata.
+  if (CGM.getCodeGenOpts().WholeProgramVTables) {
+llvm::GlobalObject::VCallVisibility TypeVis =
+CGM.GetVCallVisibilityLevel(RD);
+if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
+  VTable->setVCallVisibilityMetadata(TypeVis);
+  }
+
   // The location of the first virtual function pointer in the virtual table,
   // aka the "address point" on 

[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 2 inline comments as done.
tejohnson added inline comments.



Comment at: llvm/lib/Transforms/IPO/GlobalSplit.cpp:116
+if (GV.hasMetadata(LLVMContext::MD_vcall_visibility))
+  SplitGV->setVCallVisibilityMetadata(GV.getVCallVisibility());
   }

evgeny777 wrote:
> I think this needs a test. Removal of this code doesn't break anything
Adding some checking in a GlobalSplit test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907



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


[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239888.
tejohnson marked an inline comment as done.
tejohnson added a comment.

Test GlobalSplit handling of vcall_visibility metadata


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/GlobalObject.h
  llvm/lib/IR/Metadata.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/lib/Transforms/IPO/GlobalSplit.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions.ll
  llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
  llvm/test/Transforms/GlobalSplit/basic.ll

Index: llvm/test/Transforms/GlobalSplit/basic.ll
===
--- llvm/test/Transforms/GlobalSplit/basic.ll
+++ llvm/test/Transforms/GlobalSplit/basic.ll
@@ -12,13 +12,13 @@
 ]
 
 ; CHECK-NOT: @global =
-; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+$]]
-; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+$]]
+; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+]], !vcall_visibility [[VIS:![0-9]+$]]
+; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+]], !vcall_visibility [[VIS$]]
 ; CHECK-NOT: @global =
 @global = internal constant { [2 x i8* ()*], [1 x i8* ()*] } {
   [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2],
   [1 x i8* ()*] [i8* ()* @f3]
-}, !type !0, !type !1, !type !2, !type !3, !type !4
+}, !type !0, !type !1, !type !2, !type !3, !type !4, !vcall_visibility !5
 
 ; CHECK: define i8* @f1()
 define i8* @f1() {
@@ -54,6 +54,7 @@
 ; CHECK: [[T1]] = !{i32 0, !"foo"}
 ; CHECK: [[T2]] = !{i32 15, !"bar"}
 ; CHECK: [[T3]] = !{i32 16, !"a"}
+; CHECK: [[VIS]] = !{i64 2}
 ; CHECK: [[T4]] = !{i32 1, !"b"}
 ; CHECK: [[T5]] = !{i32 8, !"c"}
 !0 = !{i32 0, !"foo"}
@@ -61,3 +62,4 @@
 !2 = !{i32 16, !"a"}
 !3 = !{i32 17, !"b"}
 !4 = !{i32 24, !"c"}
+!5 = !{i64 2}
Index: llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
===
--- llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
+++ llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
@@ -39,9 +39,10 @@
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!3, !4}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 2} ; translation-unit vcall visibility
 !3 = !{i32 1, !"LTOPostLink", i32 1}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
@@ -85,10 +85,11 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{}
+!llvm.module.flags = !{!5}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 0} ; public vcall visibility
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
+!5 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
@@ -85,7 +85,7 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{!5}
+!llvm.module.flags = !{!5, !6}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
@@ -93,3 +93,4 @@
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
 !5 = !{i32 1, !"LTOPostLink", i32 1}
+!6 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions.ll
+++ 

[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239890.
tejohnson added a comment.

Implement suggestion


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/cfi-mfcall.cpp
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_alias.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -625,6 +626,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr ThinLinkOut;
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ 

[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-27 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D71913#1837872 , @tejohnson wrote:

> FYI I reverted this in rG90e630a95ecc 
>  due to 
> a cfi test failure in a windows sanitizer bot. Not sure what is happening, 
> I'll need to try to debug it somehow tomorrow.


This patch went back in a little while ago at 
2f63d549f1e1edd165392837aaa53f569f7fb88d 
, and 
looks like it will stick this time. The windows bot no longer fails with this 
patch after the enabling fix in D73418  went 
in before this at
af954e441a5170a75687699d91d85e0692929d43 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-04 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1678
+// breaks any uses on assumes.
+if (TypeIdMap.count(TypeId))
+  continue;

evgeny777 wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > tejohnson wrote:
> > > > evgeny777 wrote:
> > > > > I don't think, I understand this.
> > > > > It looks like that if (a) we have type.test in the module and (b) we 
> > > > > don't have vtable definition with corresponding type metadata in the 
> > > > > same module then we'll remove type.test/assume sequence before even 
> > > > > getting to ICP. This seems strange in the context of previous 
> > > > > discussion because virtual function may be called in different module 
> > > > > from one where vtable is defined, like so:
> > > > > ```
> > > > > struct A { virtual int foo() { return 42; } };
> > > > > 
> > > > > // calls pA->foo
> > > > > extern int callFoo(A *pA);
> > > > > int main() { A a; return callFoo(); }
> > > > > ```
> > > > > 
> > > > We will only be able to do ICP this way if we have the target vtable in 
> > > > the module (similar to how we currently can only do ICP if the target 
> > > > function is in the module). I anticipate doing something similar for 
> > > > vtable defs as to what we do for virtual functions, where a fake call 
> > > > edge is added to the summary based on the value profile results to 
> > > > ensure they are imported before the LTO backend ICP.
> > > > We will only be able to do ICP this way if we have the target vtable in 
> > > > the module (similar to how we currently can only do ICP if the target 
> > > > function is in the module).
> > > 
> > > I was thinking of slightly different approach: it seems you have required 
> > > type information in combined index together with type name in the module, 
> > > so you probably can add external declarations of required vtables (this 
> > > may require promotion) to the module in the ICP pass and run ICP over 
> > > them. Do you think this can work?
> > Possibly, but we'd still need to have type metadata on those vtable 
> > declarations, because the type metadata provides the address point offset 
> > which is needed in the comparison sequence.
> > Possibly, but we'd still need to have type metadata on those vtable 
> > declarations, because the type metadata provides the address point offset 
> > which is needed in the comparison sequence.
> 
> I think it's stored in the index in VFuncId structures. Isn't it?
> I think it's stored in the index in VFuncId structures. Isn't it?

No, that holds the offset from the address point to the virtual function within 
the vtable def, not the address point offset itself, which is what we need from 
the type metadata. But actually, we need both offsets:

Consider the following example:

```
class A {
   virtual void foo();
}

void bar(A *a) {
   a->foo();
}
```

The indirect call sequence will look like (not showing the type test for 
simplicity):

```
 %0 = bitcast %class.A* %a to i32 (%class.A*)***
  %vtable = load i32 (%class.A*)**, i32 (%class.A*)*** %0
  %1 = load i32 (%class.A*)*, i32 (%class.A*)** %vtable
  %call = tail call i32 %1(%class.A* %a)
```

With type profiling we will profile the value of %vtable, and figure out that 
it is associated with the symbol for A's vtable (the profiling support uses 
symbol table info for this), which is:

```
@_ZTV1A = dso_local unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, 
i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* bitcast (i32 (%class.A*)* 
@_ZN1A3fooEv to i8*)] }, align 8, !type !0

!0 = !{i64 16, !"_ZTS1A"}
```

When we promote the call using the vtable profile results, we need to add the 
address point offset (16) from the type metadata to the profiled result which 
will be the symbol @_ZTV1A, before comparing against %vtable.

We then need to look at the IR and compute the offset to the function address 
used there (0 in the above IR), and add it to the address point offset, 
resulting in 16 here, looking in the vtable def to see what function is at the 
combined offset (_ZN1A3fooEv here), so that we insert a direct call to that 
function.

For the address point offset, we only have it in the summary for index-only WPD 
(TypeIdCompatibleVtableMap). However, I don't want to restrict the ICP 
improvements to that build mode.

For the latter, the VFuncId does summarize the offsets, but we can compute it 
from the IR as I described above (it's the amount added to %vtable before 
loading the virtual function pointer) and don't need the summary. And in any 
case the VFuncId doesn't tell us which function is at the aggregate offset, we 
need the vtable def to tell us that (or the vTableFuncs array saved on the 
GlobalVarSummary, again only in index-only WPD mode).

Also, I believe we can support this type profiling based ICP in non-ThinLTO 
mode as well - with my recent changes to make WPD rely on 

[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-05 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D73242#186 , @thakis wrote:

> This makes lld crash when linking chromium's base_unittests and probably does 
> the same for most other binaries that use both thinlto and cfi: 
> https://bugs.chromium.org/p/chromium/issues/detail?id=1049434


Reverted at 25aa2eef993e17708889abf56ed1ffad5074a9f4 
. Will 
investigate using repro @thakis sent off patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-01-30 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D73242#1849484 , @tejohnson wrote:

> Both of these approaches need the type tests to determine the correct address 
> point offset (the offset in the type test) to use in the compare sequence.


I typed this too fast - the offset is in the type metadata, but we need the 
type tests to correlate them with the indirect call sites.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-03 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 3 inline comments as done.
tejohnson added inline comments.



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:830
   enum Kind {
+Unknown,   ///< Unknown (analysis not performed, don't lower)
 Unsat, ///< Unsatisfiable type (i.e. no global has this type metadata)

evgeny777 wrote:
> I don't think such implicit conversion of Unsat to Unknown is good idea. I 
> guess problem will arise for legacy index files: for those ByteArray 
> resolution will become Unsat and so on. I suggest moving Unknown the end of 
> the list and bumping index version respectively (parseTypeIdSummaryRecord 
> doesn't verify TheKind).
Sounds like a good idea, will do.



Comment at: llvm/lib/Passes/PassBuilder.cpp:1380
+  // in ICP (which is performed earlier than this in the regular LTO pipeline).
+  MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true));
 

evgeny777 wrote:
> Can we get rid of two identical passes here (and in other places also)? For 
> instance 
> ```
> MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr, true));
> ```
> can both lower type metadata and do final cleanup.
The problem is that currently under DropTypeTests=true, LTT will drop the type 
tests up front and return without doing any other lowering. Which is what we 
want in the already existing callers of LTT with DropTypeTests=true. Here, we 
want LTT to perform its usual lowering, and only afterwards do the dropping. We 
want to do this only during regular LTO, but unfortunately we can't just key 
off of the ExportSummary (e.g. drop at the start if ExportSummary is nullptr, 
and drop at the end if ExportSummary is non-nullptr), since in some cases here 
ExportSummary may be nullptr (i.e. regular LTO invoked via the old LTO API). So 
I would need to introduce another option to essentially say "drop them after 
lowering". I can certainly do this if you think it would be better (I was 
thinking about that before, but thought it might be more confusing). WDYT?



Comment at: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1678
+// breaks any uses on assumes.
+if (TypeIdMap.count(TypeId))
+  continue;

evgeny777 wrote:
> I don't think, I understand this.
> It looks like that if (a) we have type.test in the module and (b) we don't 
> have vtable definition with corresponding type metadata in the same module 
> then we'll remove type.test/assume sequence before even getting to ICP. This 
> seems strange in the context of previous discussion because virtual function 
> may be called in different module from one where vtable is defined, like so:
> ```
> struct A { virtual int foo() { return 42; } };
> 
> // calls pA->foo
> extern int callFoo(A *pA);
> int main() { A a; return callFoo(); }
> ```
> 
We will only be able to do ICP this way if we have the target vtable in the 
module (similar to how we currently can only do ICP if the target function is 
in the module). I anticipate doing something similar for vtable defs as to what 
we do for virtual functions, where a fake call edge is added to the summary 
based on the value profile results to ensure they are imported before the LTO 
backend ICP.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-05 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG748bb5a0f196: [WPD/LowerTypeTests] Delay lowering/removal of 
type tests until after ICP (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242

Files:
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/Bitcode/summary_version.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl2.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll

Index: llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
+++ llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
@@ -25,7 +25,7 @@
   %fptr = load i8*, i8** %fptrptr
   %fptr_casted = bitcast i8* %fptr to i32 (i8*)*
   %result = call i32 %fptr_casted(i8* %obj)
-  ; CHECK-NOT: call
+  ; CHECK-NOT: call i32 %
   ; CHECK: ret i32 123
   ret i32 %result
 }
Index: llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
+++ llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
@@ -32,7 +32,7 @@
 ; SUMMARY-NEXT: TypeIdMap:
 ; SUMMARY-NEXT:   typeid1:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
+++ llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
@@ -9,7 +9,7 @@
 ; SUMMARY:  TypeIdMap:
 ; SUMMARY-NEXT:   typeid3:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
@@ -29,7 +29,7 @@
 ; SUMMARY-ARM-NEXT: Bit: 1
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
+++ llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
@@ -6,7 +6,7 @@
 ; SUMMARY:  TypeIdMap:
 ; SUMMARY-NEXT:   typeid3:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
@@ -24,7 +24,7 @@
 ; SUMMARY-NEXT: Bit: 0
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
+++ llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
@@ -6,7 +6,7 @@
 ; SUMMARY:  TypeIdMap:
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: 

[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG458676db6e41: [WPD/VFE] Always emit vcall_visibility 
metadata for -fwhole-program-vtables (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/GlobalObject.h
  llvm/lib/IR/Metadata.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/lib/Transforms/IPO/GlobalSplit.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions.ll
  llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
  llvm/test/Transforms/GlobalSplit/basic.ll

Index: llvm/test/Transforms/GlobalSplit/basic.ll
===
--- llvm/test/Transforms/GlobalSplit/basic.ll
+++ llvm/test/Transforms/GlobalSplit/basic.ll
@@ -12,13 +12,13 @@
 ]
 
 ; CHECK-NOT: @global =
-; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+$]]
-; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+$]]
+; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+]], !vcall_visibility [[VIS:![0-9]+$]]
+; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+]], !vcall_visibility [[VIS$]]
 ; CHECK-NOT: @global =
 @global = internal constant { [2 x i8* ()*], [1 x i8* ()*] } {
   [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2],
   [1 x i8* ()*] [i8* ()* @f3]
-}, !type !0, !type !1, !type !2, !type !3, !type !4
+}, !type !0, !type !1, !type !2, !type !3, !type !4, !vcall_visibility !5
 
 ; CHECK: define i8* @f1()
 define i8* @f1() {
@@ -54,6 +54,7 @@
 ; CHECK: [[T1]] = !{i32 0, !"foo"}
 ; CHECK: [[T2]] = !{i32 15, !"bar"}
 ; CHECK: [[T3]] = !{i32 16, !"a"}
+; CHECK: [[VIS]] = !{i64 2}
 ; CHECK: [[T4]] = !{i32 1, !"b"}
 ; CHECK: [[T5]] = !{i32 8, !"c"}
 !0 = !{i32 0, !"foo"}
@@ -61,3 +62,4 @@
 !2 = !{i32 16, !"a"}
 !3 = !{i32 17, !"b"}
 !4 = !{i32 24, !"c"}
+!5 = !{i64 2}
Index: llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
===
--- llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
+++ llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
@@ -39,9 +39,10 @@
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!3, !4}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 2} ; translation-unit vcall visibility
 !3 = !{i32 1, !"LTOPostLink", i32 1}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
@@ -85,10 +85,11 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{}
+!llvm.module.flags = !{!5}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 0} ; public vcall visibility
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
+!5 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
@@ -85,7 +85,7 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{!5}
+!llvm.module.flags = !{!5, !6}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
@@ -93,3 +93,4 @@
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
 !5 = !{i32 1, !"LTOPostLink", i32 1}
+!6 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions.ll
+++ 

[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c2eb220edd5: [ThinLTO] Summarize vcall_visibility metadata 
(authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71911/new/

https://reviews.llvm.org/D71911

Files:
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/thinlto-vtable-summary.ll

Index: llvm/test/Assembler/thinlto-vtable-summary.ll
===
--- llvm/test/Assembler/thinlto-vtable-summary.ll
+++ llvm/test/Assembler/thinlto-vtable-summary.ll
@@ -29,9 +29,9 @@
 
 ^0 = module: (path: "", hash: (0, 0, 0, 0, 0))
 ^1 = gv: (name: "_ZN1A1nEi") ; guid = 1621563287929432257
-^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
+^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
 ^3 = gv: (name: "_ZN1B1fEi") ; guid = 7162046368816414394
-^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
+^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
 ^5 = gv: (name: "_ZN1C1fEi") ; guid = 14876272565662207556
 ^6 = typeidCompatibleVTable: (name: "_ZTS1A", summary: ((offset: 16, ^2), (offset: 16, ^4))) ; guid = 7004155349499253778
 ^7 = typeidCompatibleVTable: (name: "_ZTS1B", summary: ((offset: 16, ^2))) ; guid = 6203814149063363976
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -2900,11 +2900,15 @@
 }
 
 void AssemblyWriter::printGlobalVarSummary(const GlobalVarSummary *GS) {
+  auto VTableFuncs = GS->vTableFuncs();
   Out << ", varFlags: (readonly: " << GS->VarFlags.MaybeReadOnly << ", "
   << "writeonly: " << GS->VarFlags.MaybeWriteOnly << ", "
-  << "constant: " << GS->VarFlags.Constant << ")";
+  << "constant: " << GS->VarFlags.Constant;
+  if (!VTableFuncs.empty())
+Out << ", "
+<< "vcall_visibility: " << GS->VarFlags.VCallVisibility;
+  Out << ")";
 
-  auto VTableFuncs = GS->vTableFuncs();
   if (!VTableFuncs.empty()) {
 Out << ", vTableFuncs: (";
 FieldSeparator FS;
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1028,8 +1028,8 @@
 }
 
 static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags) {
-  uint64_t RawFlags =
-  Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) | (Flags.Constant << 2);
+  uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
+  (Flags.Constant << 2) | Flags.VCallVisibility << 3;
   return RawFlags;
 }
 
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -985,9 +985,10 @@
 
 // Decode the flags for GlobalVariable in the summary
 static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags) {
-  return GlobalVarSummary::GVarFlags((RawFlags & 0x1) ? true : false,
- (RawFlags & 0x2) ? true : false,
- (RawFlags & 0x4) ? true : false);
+  return GlobalVarSummary::GVarFlags(
+  (RawFlags & 0x1) ? true : false, (RawFlags & 0x2) ? true : false,
+  (RawFlags & 0x4) ? true : false,
+  (GlobalObject::VCallVisibility)(RawFlags >> 3));
 }
 
 static GlobalValue::VisibilityTypes 

[PATCH] D73418: [WPD] Emit vcall_visibility metadata for MicrosoftCXXABI

2020-01-25 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: evgeny777.
Herald added a subscriber: Prazek.
Herald added a project: clang.

The MicrosoftCXXABI uses a separate mechanism for emitting vtable
type metadata, and thus didn't pick up the change from D71907 

to emit the vcall_visibility metadata under -fwhole-program-vtables.

I believe this is the cause of a Windows bot failure when I committed
follow on change D71913  that required a 
revert. The failure occurred
in a CFI test that was expecting to not abort because it expected a
devirtualization to occur, and without the necessary vcall_visibility
metadata we would not get devirtualization.

Note in the equivalent code in CodeGenModule::EmitVTableTypeMetadata
(used by the ItaniumCXXABI), we also emit the vcall_visibility metadata
when Virtual Function Elimination is enabled. Since I am not as familiar
with the details of that optimization, I have marked that as a TODO and
am only inserting under -fwhole-program-vtables.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73418

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp


Index: clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
===
--- clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
+++ clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-VFE
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-NOVFE
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK-MS 
--check-prefix=CHECK-NOVFE
 
 // Check that in ThinLTO we also get vcall_visibility summary entries in the 
bitcode
 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux 
-emit-llvm-bc -fwhole-program-vtables -o - %s | llvm-dis -o - | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-NOVFE --check-prefix=CHECK-SUMMARY
@@ -87,6 +88,15 @@
   return new G();
 }
 
+// CHECK-MS: comdat($"??_7A@?A0xE24FC2D5@@6B@"){{.*}} !vcall_visibility 
[[VIS_TU:![0-9]+]]
+// CHECK-MS: comdat($"??_7B@@6B@"){{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+// CHECK-MS: comdat($"??_7C@@6B@"){{.*}} !vcall_visibility [[VIS_DSO]]
+// CHECK-MS: comdat($"??_7E@@6B@"){{.*}} !vcall_visibility [[VIS_DSO]]
+// CHECK-MS: comdat($"??_7F@?A0xE24FC2D5@@6B@"){{.*}} !vcall_visibility 
[[VIS_DSO]]
+// CHECK-MS: comdat($"??_7G@?A0xE24FC2D5@@6B@"){{.*}} !vcall_visibility 
[[VIS_DSO]]
+// CHECK-MS-DAG: [[VIS_TU]] = !{i64 2}
+// CHECK-MS-DAG: [[VIS_DSO]] = !{i64 1}
+
 // CHECK-DAG: [[VIS_DSO]] = !{i64 1}
 // CHECK-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-VFE-DAG: !{i32 1, !"Virtual Function Elim", i32 1}
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1621,6 +1621,15 @@
   if (!CGM.getCodeGenOpts().LTOUnit)
 return;
 
+  // TODO: Should VirtualFunctionElimination also be supported here?
+  // See similar handling in CodeGenModule::EmitVTableTypeMetadata.
+  if (CGM.getCodeGenOpts().WholeProgramVTables) {
+llvm::GlobalObject::VCallVisibility TypeVis =
+CGM.GetVCallVisibilityLevel(RD);
+if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
+  VTable->setVCallVisibilityMetadata(TypeVis);
+  }
+
   // The location of the first virtual function pointer in the virtual table,
   // aka the "address point" on Itanium. This is at offset 0 if RTTI is
   // disabled, or sizeof(void*) if RTTI is enabled.


Index: clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
===
--- clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
+++ clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VFE
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOVFE
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -emit-llvm -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK-MS --check-prefix=CHECK-NOVFE
 
 // Check that in ThinLTO we also get vcall_visibility summary entries in the bitcode
 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux -emit-llvm-bc 

[PATCH] D73418: [WPD] Emit vcall_visibility metadata for MicrosoftCXXABI

2020-01-27 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf954e441a51: [WPD] Emit vcall_visibility metadata for 
MicrosoftCXXABI (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73418/new/

https://reviews.llvm.org/D73418

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp


Index: clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
===
--- clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
+++ clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-VFE
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-NOVFE
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK-MS 
--check-prefix=CHECK-NOVFE
 
 // Check that in ThinLTO we also get vcall_visibility summary entries in the 
bitcode
 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux 
-emit-llvm-bc -fwhole-program-vtables -o - %s | llvm-dis -o - | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-NOVFE --check-prefix=CHECK-SUMMARY
@@ -8,6 +9,7 @@
 // Anonymous namespace.
 namespace {
 // CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::A{{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
 struct A {
   A() {}
   virtual int f() { return 1; }
@@ -20,6 +22,7 @@
 
 // Hidden visibility.
 // CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.B{{.*}} 
!vcall_visibility [[VIS_DSO:![0-9]+]]
 struct __attribute__((visibility("hidden"))) B {
   B() {}
   virtual int f() { return 1; }
@@ -31,6 +34,8 @@
 
 // Default visibility.
 // CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.C{{.*}} 
!vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("default"))) C {
   C() {}
   virtual int f() { return 1; }
@@ -42,6 +47,7 @@
 
 // Hidden visibility, public LTO visibility.
 // CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
+// CHECK-MS-NOT: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.D{{.*}} !vcall_visibility
 struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] 
D {
   D() {}
   virtual int f() { return 1; }
@@ -53,6 +59,8 @@
 
 // Hidden visibility, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.E{{.*}} 
!vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("hidden"))) E : C {
   E() {}
   virtual int f() { return 1; }
@@ -64,6 +72,8 @@
 
 // Anonymous namespace, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::F{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) F : C {
   F() {}
@@ -77,6 +87,7 @@
 
 // Anonymous namespace, but inherits from class with hidden visibility.
 // CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility 
[[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::G{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) G : B {
   G() {}
@@ -87,6 +98,8 @@
   return new G();
 }
 
+// CHECK-MS-DAG: [[VIS_DSO]] = !{i64 1}
+// CHECK-MS-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-DAG: [[VIS_DSO]] = !{i64 1}
 // CHECK-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-VFE-DAG: !{i32 1, !"Virtual Function Elim", i32 1}
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1621,6 +1621,15 @@
   if (!CGM.getCodeGenOpts().LTOUnit)
 return;
 
+  // TODO: Should VirtualFunctionElimination also be supported here?
+  // See similar handling in CodeGenModule::EmitVTableTypeMetadata.
+  if (CGM.getCodeGenOpts().WholeProgramVTables) {
+llvm::GlobalObject::VCallVisibility TypeVis =
+CGM.GetVCallVisibilityLevel(RD);
+if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
+  VTable->setVCallVisibilityMetadata(TypeVis);
+  }
+
   // The 

[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-04 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 242493.
tejohnson added a comment.

Rebase and implement suggestion (move Unknown to end and bump index version)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242

Files:
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/Bitcode/summary_version.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl2.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll

Index: llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
+++ llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
@@ -25,7 +25,7 @@
   %fptr = load i8*, i8** %fptrptr
   %fptr_casted = bitcast i8* %fptr to i32 (i8*)*
   %result = call i32 %fptr_casted(i8* %obj)
-  ; CHECK-NOT: call
+  ; CHECK-NOT: call i32 %
   ; CHECK: ret i32 123
   ret i32 %result
 }
Index: llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
+++ llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
@@ -32,7 +32,7 @@
 ; SUMMARY-NEXT: TypeIdMap:
 ; SUMMARY-NEXT:   typeid1:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
+++ llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
@@ -9,7 +9,7 @@
 ; SUMMARY:  TypeIdMap:
 ; SUMMARY-NEXT:   typeid3:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
@@ -29,7 +29,7 @@
 ; SUMMARY-ARM-NEXT: Bit: 1
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
+++ llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
@@ -6,7 +6,7 @@
 ; SUMMARY:  TypeIdMap:
 ; SUMMARY-NEXT:   typeid3:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
@@ -24,7 +24,7 @@
 ; SUMMARY-NEXT: Bit: 0
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
+++ llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
@@ -6,7 +6,7 @@
 ; SUMMARY:  TypeIdMap:
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll

[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-05 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1678
+// breaks any uses on assumes.
+if (TypeIdMap.count(TypeId))
+  continue;

evgeny777 wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > tejohnson wrote:
> > > > evgeny777 wrote:
> > > > > tejohnson wrote:
> > > > > > evgeny777 wrote:
> > > > > > > I don't think, I understand this.
> > > > > > > It looks like that if (a) we have type.test in the module and (b) 
> > > > > > > we don't have vtable definition with corresponding type metadata 
> > > > > > > in the same module then we'll remove type.test/assume sequence 
> > > > > > > before even getting to ICP. This seems strange in the context of 
> > > > > > > previous discussion because virtual function may be called in 
> > > > > > > different module from one where vtable is defined, like so:
> > > > > > > ```
> > > > > > > struct A { virtual int foo() { return 42; } };
> > > > > > > 
> > > > > > > // calls pA->foo
> > > > > > > extern int callFoo(A *pA);
> > > > > > > int main() { A a; return callFoo(); }
> > > > > > > ```
> > > > > > > 
> > > > > > We will only be able to do ICP this way if we have the target 
> > > > > > vtable in the module (similar to how we currently can only do ICP 
> > > > > > if the target function is in the module). I anticipate doing 
> > > > > > something similar for vtable defs as to what we do for virtual 
> > > > > > functions, where a fake call edge is added to the summary based on 
> > > > > > the value profile results to ensure they are imported before the 
> > > > > > LTO backend ICP.
> > > > > > We will only be able to do ICP this way if we have the target 
> > > > > > vtable in the module (similar to how we currently can only do ICP 
> > > > > > if the target function is in the module).
> > > > > 
> > > > > I was thinking of slightly different approach: it seems you have 
> > > > > required type information in combined index together with type name 
> > > > > in the module, so you probably can add external declarations of 
> > > > > required vtables (this may require promotion) to the module in the 
> > > > > ICP pass and run ICP over them. Do you think this can work?
> > > > Possibly, but we'd still need to have type metadata on those vtable 
> > > > declarations, because the type metadata provides the address point 
> > > > offset which is needed in the comparison sequence.
> > > > Possibly, but we'd still need to have type metadata on those vtable 
> > > > declarations, because the type metadata provides the address point 
> > > > offset which is needed in the comparison sequence.
> > > 
> > > I think it's stored in the index in VFuncId structures. Isn't it?
> > > I think it's stored in the index in VFuncId structures. Isn't it?
> > 
> > No, that holds the offset from the address point to the virtual function 
> > within the vtable def, not the address point offset itself, which is what 
> > we need from the type metadata. But actually, we need both offsets:
> > 
> > Consider the following example:
> > 
> > ```
> > class A {
> >virtual void foo();
> > }
> > 
> > void bar(A *a) {
> >a->foo();
> > }
> > ```
> > 
> > The indirect call sequence will look like (not showing the type test for 
> > simplicity):
> > 
> > ```
> >  %0 = bitcast %class.A* %a to i32 (%class.A*)***
> >   %vtable = load i32 (%class.A*)**, i32 (%class.A*)*** %0
> >   %1 = load i32 (%class.A*)*, i32 (%class.A*)** %vtable
> >   %call = tail call i32 %1(%class.A* %a)
> > ```
> > 
> > With type profiling we will profile the value of %vtable, and figure out 
> > that it is associated with the symbol for A's vtable (the profiling support 
> > uses symbol table info for this), which is:
> > 
> > ```
> > @_ZTV1A = dso_local unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* 
> > null, i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* bitcast (i32 
> > (%class.A*)* @_ZN1A3fooEv to i8*)] }, align 8, !type !0
> > 
> > !0 = !{i64 16, !"_ZTS1A"}
> > ```
> > 
> > When we promote the call using the vtable profile results, we need to add 
> > the address point offset (16) from the type metadata to the profiled result 
> > which will be the symbol @_ZTV1A, before comparing against %vtable.
> > 
> > We then need to look at the IR and compute the offset to the function 
> > address used there (0 in the above IR), and add it to the address point 
> > offset, resulting in 16 here, looking in the vtable def to see what 
> > function is at the combined offset (_ZN1A3fooEv here), so that we insert a 
> > direct call to that function.
> > 
> > For the address point offset, we only have it in the summary for index-only 
> > WPD (TypeIdCompatibleVtableMap). However, I don't want to restrict the ICP 
> > improvements to that build mode.
> > 
> > For the latter, the VFuncId does summarize the offsets, but we can compute 
> > it from the IR as I described above (it's the amount 

[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-04 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1678
+// breaks any uses on assumes.
+if (TypeIdMap.count(TypeId))
+  continue;

evgeny777 wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > I don't think, I understand this.
> > > It looks like that if (a) we have type.test in the module and (b) we 
> > > don't have vtable definition with corresponding type metadata in the same 
> > > module then we'll remove type.test/assume sequence before even getting to 
> > > ICP. This seems strange in the context of previous discussion because 
> > > virtual function may be called in different module from one where vtable 
> > > is defined, like so:
> > > ```
> > > struct A { virtual int foo() { return 42; } };
> > > 
> > > // calls pA->foo
> > > extern int callFoo(A *pA);
> > > int main() { A a; return callFoo(); }
> > > ```
> > > 
> > We will only be able to do ICP this way if we have the target vtable in the 
> > module (similar to how we currently can only do ICP if the target function 
> > is in the module). I anticipate doing something similar for vtable defs as 
> > to what we do for virtual functions, where a fake call edge is added to the 
> > summary based on the value profile results to ensure they are imported 
> > before the LTO backend ICP.
> > We will only be able to do ICP this way if we have the target vtable in the 
> > module (similar to how we currently can only do ICP if the target function 
> > is in the module).
> 
> I was thinking of slightly different approach: it seems you have required 
> type information in combined index together with type name in the module, so 
> you probably can add external declarations of required vtables (this may 
> require promotion) to the module in the ICP pass and run ICP over them. Do 
> you think this can work?
Possibly, but we'd still need to have type metadata on those vtable 
declarations, because the type metadata provides the address point offset which 
is needed in the comparison sequence.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-01-30 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added a comment.

In D73242#1847051 , @evgeny777 wrote:

> > This is an enabler for upcoming enhancements to indirect call promotion, 
> > for example streamlined promotion guard sequences that compare against 
> > vtable address instead of the target function
>
> Can you please describe the whole approach in more detail? At the moment ICP 
> is capable to do (a sort of) devirtualization is replacing indirect vtbl call 
> with sequence of function address comparisons and direct calls.
>  Are you going to speedup this by means of comparing vtable pointers instead 
> of function pointers (thus eliminating a single load per each vtbl call) or 
> there is also something else in mind?


That's exactly what we want to do here. We found a relatively significant 
number of cycles are being spent on virtual function pointer loads in these 
sequences, and by doing a vtable comparison instead, that is moved off the 
critical path. I had prototyped something like this in ICP awhile back and 
found a speedup in an important app.

> If that's true, what's the next
>  step? Make ICP pass analyze type test intrinsics?

There are a few ways to do the alternate ICP compare sequences, one is using 
statically available info from the vtable definitions in the module that 
utilize the profiled target. This relies on ThinLTO to import all the relevant 
vtable definitions. The other is to profile vtable addresses with FDO (not just 
the target function pointer) - I've got the type profiling implemented, but it 
needs some cleanup before I send for review. Both of these approaches need the 
type tests to determine the correct address point offset (the offset in the 
type test) to use in the compare sequence. And in both cases you want to trade 
off the number of comparisons needed for the two approaches to determine 
whether a vtable compare or a target function compare is better. I.e. if there 
are a lot of vtable definitions that utilize a hot target, it is likely better 
to do a single target function comparison.




Comment at: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1660
+cast(CI->getArgOperand(1))->getMetadata();
 // If we found any, add them to CallSlots.
 if (!Assumes.empty()) {

evgeny777 wrote:
> This change seems to be unrelated
It is needed to have the TypeId available outside this if statement (see the 
map check below).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59733525d37c: [LTO/WPD] Enable aggressive WPD under LTO 
option (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/cfi-mfcall.cpp
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_alias.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -625,6 +626,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr ThinLinkOut;
Index: llvm/tools/gold/gold-plugin.cpp

[PATCH] D74591: [Driver] Rename AddGoldPlugin to addLTOOptions. NFC

2020-02-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74591/new/

https://reviews.llvm.org/D74591



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-02-11 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added a comment.

In D73242#1861125 , @tejohnson wrote:

> In D73242#186 , @thakis wrote:
>
> > This makes lld crash when linking chromium's base_unittests and probably 
> > does the same for most other binaries that use both thinlto and cfi: 
> > https://bugs.chromium.org/p/chromium/issues/detail?id=1049434
>
>
> Reverted at 25aa2eef993e17708889abf56ed1ffad5074a9f4 
> . Will 
> investigate using repro @thakis sent off patch.


Recommitted with fix and additional test case at 
80d0a137a5aba6998fadb764f1e11cb901aae233 
.




Comment at: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1999
+WholeProgramDevirtResolution *Res = nullptr;
+if (ExportSummary && isa(S.first.TypeID))
+  // Create the type id summary resolution regardlness of whether we can

The fix needed for the Chromium issue was to guard the TypeIdSummary creation 
here by whether the TypeID exists in the TypeIdMap (which makes it match the 
comment in fact), as we don't want to create a summary if the type id is not 
used on a global (in which case it should in fact be Unsat). The equivalent 
code in the index-only WPD is essentially already guarded by that condition, 
because of the way the CallSlots are created (and in fact there is an assert in 
that code that we have a use on a vtable, i.e. that a 
TypeIdCompatibleVtableSummary is found for the TypeID).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: wmi.
Herald added subscribers: jfb, dexonsmith, steven_wu, hiraditya, inglorion, 
mehdi_amini.
Herald added projects: clang, LLVM.

I've added some more extensive ThinLTO pipeline testing with the new PM,
motivated by the bug fixed in D72386 .

I beefed up llvm/test/Other/new-pm-pgo.ll a little so that it tests
ThinLTO pre and post link with PGO, similar to the testing for the
default pipelines with PGO.

Added new pre and post link PGO tests for both instrumentation and
sample PGO that exhaustively test the pipelines at different
optimization levels via opt.

Added a clang test to exhaustively test the post link pipeline invoked for
distributed builds. I am currently only testing O2 
 and O3 
 since these
are the most important for performance.

It would be nice to add similar exhaustive testing for full LTO, and for
the old PM, but I don't have the bandwidth now and this is a start to
cover some of the situations that are not currently default and were
under tested.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72538

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/test/Other/Inputs/new-pm-thinlto-prelink-pgo-defaults.proftext
  llvm/test/Other/Inputs/new-pm-thinlto-samplepgo-defaults.prof
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -0,0 +1,213 @@
+; Validate ThinLTO prelink pipeline when we have Sample PGO
+;
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123,CHECK-EP-PIPELINE-START
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O123
+;
+; CHECK-O: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor
+; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting 

[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 237427.
tejohnson added a comment.

Remove some cruft


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72538/new/

https://reviews.llvm.org/D72538

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/test/Other/Inputs/new-pm-thinlto-prelink-pgo-defaults.proftext
  llvm/test/Other/Inputs/new-pm-thinlto-samplepgo-defaults.prof
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -0,0 +1,213 @@
+; Validate ThinLTO prelink pipeline when we have Sample PGO
+;
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123,CHECK-EP-PIPELINE-START
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O123
+;
+; CHECK-O: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor
+; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SimplifyCFGPass
+; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
+; CHECK-O-NEXT: Running analysis: AssumptionAnalysis
+; CHECK-O-NEXT: Running pass: SROA
+; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
+; CHECK-O-NEXT: Running pass: EarlyCSEPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
+; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
+; CHECK-O-NEXT: Running pass: InstCombinePass on foo
+; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on foo
+; CHECK-O-NEXT: Running analysis: AAManager on foo
+; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy on foo
+; CHECK-O-NEXT: Finished llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SampleProfileLoaderPass
+; CHECK-O-NEXT: Running analysis: ProfileSummaryAnalysis
+; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
+; CHECK-O-NEXT: Running pass: 

[PATCH] D72523: [remark][diagnostics] Using clang diagnostic handler for IR input files

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Thanks for fixing this missing -Rpass support!




Comment at: clang/lib/CodeGen/CodeGenAction.cpp:594
+  // SourceLoc.
+  if (Context == nullptr) {
+return FullSourceLoc();

Does this only happen with IR input? Does it always happen with IR input? If 
not, what happens when we have a non-null Context but IR input? It sounds like 
it should still always return an invalid Loc since there is no SourceManager? 
In that case can you set a flag on the BackendConsumer so we can bail out 
directly in the IR input case, instead of going through the motions only to get 
an invalid Loc back anyway? It would also be more clear.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:650
+  if (!Loc.isValid()) {
+MsgStream << D.getLocationStr() << ": in function "
+  << D.getFunction().getName() << ' '

Can you add a test for this one?

Also, what determines the format of the message when Loc is valid? I was trying 
to figure out where that got determined, but couldn't easily track it down. 



Comment at: clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c:8
+// RUN: llvm-lto -thinlto -o %t %t1.bo
+// RUN: %clang -cc1 -O2 -fexperimental-new-pass-manager -x ir %t1.bo 
-fthinlto-index=%t.thinlto.bc -emit-obj -Rpass-analysis=info 2>&1 | FileCheck 
%s -check-prefix=CHECK-REMARK
+// RUN: llvm-profdata merge -o %t2.profdata %S/Inputs/thinlto_expect2.proftext

In this case (since no -Wmisexpect), presumably we should not be getting the 
warning, whereas without your fix we were, correct? In that case, please add a 
NOT check to confirm that we don't get the message anymore.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72523/new/

https://reviews.llvm.org/D72523



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


[PATCH] D72547: [llvm] Make new pass manager's OptimizationLevel a class

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

I just have a few high level comments from looking through it just now. The 
summary needs a fix since Os/Oz are in fact O2 
 so OptLevel > 1 was not doing the 
wrong thing.




Comment at: llvm/include/llvm/Passes/PassBuilder.h:224
+
+bool isOptimizingForSpeed() const { return Level > 0 && Level < 4; }
+bool isOptimizingForSize() const { return Level == 4 || Level == 5; }

Can you add a comment as to why Os and Oz are considered as optimizing for 
speed? I know this is for compatibility with the current code, but would be 
good to document (and consider changing in the future).



Comment at: llvm/include/llvm/Passes/PassBuilder.h:225
+bool isOptimizingForSpeed() const { return Level > 0 && Level < 4; }
+bool isOptimizingForSize() const { return Level == 4 || Level == 5; }
+bool isO2Or3() const { return Level == 2 || Level == 3; }

This one is a little confusing to read, since at this point there is no 
correlation between the values 4 and 5, and the Os and Oz static variables. 
Consider making some constexpr values for each level, used in the methods here 
and in the static variable initializations?



Comment at: llvm/include/llvm/Passes/PassBuilder.h:226
+bool isOptimizingForSize() const { return Level == 4 || Level == 5; }
+bool isO2Or3() const { return Level == 2 || Level == 3; }
+bool operator==(const OptimizationLevel ) const {

Since (as discussed off-patch), in the old PM Os and Oz are also opt level 2, 
this should presumably return true for those as well. That should obviate the 
need for many places in the patch where you are currently checking isO2Or3 || 
isOptimizingForSize, and you can just check isO2Or3.



Comment at: llvm/include/llvm/Passes/PassBuilder.h:274
+  /// This is an interface that can be used to populate a \c
+  /// CGSCCAnalysisManager with all registered CGSCC analyses. Callers can 
still
+  /// manually register any additional analyses. Callers can also pre-register

There are a lot of formatting changes throughout the patch that are unrelated 
to your changes - it seems like you might have clang formatted the whole files? 
Can you only include the changes related to the patch here, it's harder to 
review with lots of spurious diffs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72547/new/

https://reviews.llvm.org/D72547



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


[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 2 inline comments as done.
tejohnson added a comment.

In D72538#1815074 , @wmi wrote:

> The additional pipeline testing will catch any future pass change to the 
> pipeline. A related but separate question is do we have a way to check 
> whether there is any other missing pass in thinlto newpm similar as that in 
> D72386 ?


Unfortunately not. That will take some painstaking comparisons between the pass 
debug output between the old and new PMs, which is going to be manual given the 
different format and structuring of the dependences. I am going to try to do 
that at least for a few important cases. As you noted, this is to help flag any 
future changes (although the last one did actually result in a test being 
changed, but it looks like no one realized the implications). Hopefully by 
having additional testing it will be more likely to trigger concerns if it 
happens again.




Comment at: clang/test/CodeGen/thinlto-distributed-newpm.ll:11
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -O2 -fexperimental-new-pass-manager -fdebug-pass-manager \

wmi wrote:
> Can we test %clang intead of %clang_cc1? so we don't have to add flags like 
> -vectorize-slp and -vectorize-loops. clang `O2/O3` pipeline is something we 
> care about. Those flags added by clang to cc1 options may be subject to 
> change.  
> 
Good idea, done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72538/new/

https://reviews.llvm.org/D72538



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


[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 237462.
tejohnson marked an inline comment as done.
tejohnson added a comment.

Implement suggestion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72538/new/

https://reviews.llvm.org/D72538

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/test/Other/Inputs/new-pm-thinlto-prelink-pgo-defaults.proftext
  llvm/test/Other/Inputs/new-pm-thinlto-samplepgo-defaults.prof
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -0,0 +1,213 @@
+; Validate ThinLTO prelink pipeline when we have Sample PGO
+;
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123,CHECK-EP-PIPELINE-START
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O123
+;
+; CHECK-O: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor
+; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SimplifyCFGPass
+; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
+; CHECK-O-NEXT: Running analysis: AssumptionAnalysis
+; CHECK-O-NEXT: Running pass: SROA
+; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
+; CHECK-O-NEXT: Running pass: EarlyCSEPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
+; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
+; CHECK-O-NEXT: Running pass: InstCombinePass on foo
+; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on foo
+; CHECK-O-NEXT: Running analysis: AAManager on foo
+; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy on foo
+; CHECK-O-NEXT: Finished llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SampleProfileLoaderPass
+; CHECK-O-NEXT: Running analysis: ProfileSummaryAnalysis
+; CHECK-O-NEXT: Running analysis: CallGraphAnalysis

[PATCH] D72547: [llvm] Make new pass manager's OptimizationLevel a class

2020-01-15 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

LGTM

One thing to consider changing/removing in the summary is this comment:
"For example, (enum) "Level > 1" captures not only O2 
 and O3 
, but also Os, and Oz."
since that is actually correct (Os/Oz should be included in Level>1 as they are 
O2 ).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72547/new/

https://reviews.llvm.org/D72547



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-16 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 2 inline comments as done.
tejohnson added inline comments.



Comment at: llvm/test/Transforms/WholeProgramDevirt/import-indir.ll:2
 ; Test that we correctly import an indir resolution for type identifier 
"typeid1".
-; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import 
-wholeprogramdevirt-read-summary=%S/Inputs/import-indir.yaml 
-wholeprogramdevirt-write-summary=%t < %s | FileCheck %s
+; RUN: opt -S -wholeprogramdevirt -whole-program-visibility 
-wholeprogramdevirt-summary-action=import 
-wholeprogramdevirt-read-summary=%S/Inputs/import-indir.yaml 
-wholeprogramdevirt-write-summary=%t < %s | FileCheck %s
 ; RUN: FileCheck --check-prefix=SUMMARY %s < %t

evgeny777 wrote:
> Why do you need `-whole-program-visibility` here? Correct me if I'm wrong, 
> but AFAIK module scanning doesn't happen during import and GV visibility 
> should be taken from imported summary.
Before my patch, type tests were only inserted for vtables with hidden LTO 
visibility. Therefore, the very presence of type tests communicated the hidden 
visibility and enabled the WPD.

With this patch, to support enabling WPD aggressively at LTO time, we now 
insert type tests unconditionally under -fwhole-program-vtables. The 
vcall_visibility metadata tells LTO how to interpret them. And the new options 
allow changing those to hidden visibility to get the more aggressive WPD.

Because these legacy tests have type tests but no vcall_visibility metadata, we 
now will conservatively treat them as having public LTO visibility. This option 
is therefore required to convert the summarized (default public) vcall 
visibility into hidden to get the prior more aggressive behavior they are 
trying to test.

Note I could have instead changed the assembly here to add hidden 
vcall_visibility metadata everywhere. That seemed a little onerous so that's 
why I just added the option. I could add a comment to that effect if it would 
help?



Comment at: llvm/tools/opt/opt.cpp:634
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ 
false);

evgeny777 wrote:
> Hm, looks like I don't fully understand this. I have following concerns:
> 
> 1) According to your changes every time I use `opt -wholeprogramdevirt` I 
> also have to pass `-whole-program-visibility`. Has `-wholeprogramdevirt` flag 
> become no-op without this additional flag? If so this looks counter intuitive 
> to me.
> 
> 2) When I use `opt -wholeprogramdevirt` default constructor of 
> `WholeProgramDevirt` class is called and `UseCommandLine` flag is set to 
> true. Can't I use this flag to effectively lower visibility in module instead 
> of playing with metadata?
> 
> ```
> if (VS->vCallVisibility() == GlobalObject::VCallVisibilityPublic && 
> !UseCommandLine)
>  return false;
> ```
> 
> According to your changes every time I use opt -wholeprogramdevirt I also 
> have to pass -whole-program-visibility. Has -wholeprogramdevirt flag become 
> no-op without this additional flag? If so this looks counter intuitive to me.

No, it wouldn't be needed if the tests contained !vcall_visibility metadata 
indicating hidden LTO visibility (see my earlier comment response).

> When I use opt -wholeprogramdevirt default constructor of WholeProgramDevirt 
> class is called and UseCommandLine flag is set to true. Can't I use this flag 
> to effectively lower visibility in module instead of playing with metadata?

I could do that. What it would mean though is that we would be unable to use 
opt for any future testing of vtables intended to have public vcall visibility 
(either through a lack of that metadata, or explicit vcall_vsibility metadata 
indicating public). Which might be ok - in fact all my new testing of this 
behavior is via llvm-lto2 or the linkers. I suppose that would obviate this 
change as well as all the opt based test changes to pass the flag. Do you think 
that is better?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913



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


[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2020-01-16 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D71911#1823497 , @evgeny777 wrote:

> I think this has to be rebased - I see multiple failures when trying to apply


I'll rebase it today.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71911/new/

https://reviews.llvm.org/D71911



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


[PATCH] D72245: [PoC][RISCV][LTO] Pass target-abi via module flag metadata

2020-01-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/lib/LTO/LTOBackend.cpp:151
 
+  TargetMachine::initTargetOptions(M, Conf.Options);
+

This is going to be problematic. The Conf is a reference to the Config object 
saved on the LTO class instance shared by all backend invocations (the regular 
LTO module if one exists and any ThinLTO modules). They will end up clobbering 
each other's values here - although from the assert in initTargetOptions I see 
they are required to all have the same value anyway. Still, it is not good as 
the assert may actually be missed with unlucky interference between the 
threads. The Config object here should really be marked const, let me see if I 
can change that.

You could make a copy of the Config here, but that essentially misses the 
assertion completely. 

A better way to do this would be in LTO::addModule, which is invoked serially 
to add each Module to the LTO object.

However - this misses other places that invoke createTargetMachine - should 
other places be looking at this new module flag as well? One example I can 
think of is the old LTO API (*LTOCodeGenerator.cpp files), used by linkers such 
as ld64 and some other proprietary linkers and the llvm-lto testing tool. But I 
have no idea about other invocations of createTargetMachine.

Note that changes to LTO.cpp/LTOBackend.cpp (the new LTO API) needs some kind 
of llvm-lto2 based test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72245/new/

https://reviews.llvm.org/D72245



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


[PATCH] D72245: [PoC][RISCV][LTO] Pass target-abi via module flag metadata

2020-01-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/lib/LTO/LTOBackend.cpp:151
 
+  TargetMachine::initTargetOptions(M, Conf.Options);
+

lenary wrote:
> tejohnson wrote:
> > This is going to be problematic. The Conf is a reference to the Config 
> > object saved on the LTO class instance shared by all backend invocations 
> > (the regular LTO module if one exists and any ThinLTO modules). They will 
> > end up clobbering each other's values here - although from the assert in 
> > initTargetOptions I see they are required to all have the same value 
> > anyway. Still, it is not good as the assert may actually be missed with 
> > unlucky interference between the threads. The Config object here should 
> > really be marked const, let me see if I can change that.
> > 
> > You could make a copy of the Config here, but that essentially misses the 
> > assertion completely. 
> > 
> > A better way to do this would be in LTO::addModule, which is invoked 
> > serially to add each Module to the LTO object.
> > 
> > However - this misses other places that invoke createTargetMachine - should 
> > other places be looking at this new module flag as well? One example I can 
> > think of is the old LTO API (*LTOCodeGenerator.cpp files), used by linkers 
> > such as ld64 and some other proprietary linkers and the llvm-lto testing 
> > tool. But I have no idea about other invocations of createTargetMachine.
> > 
> > Note that changes to LTO.cpp/LTOBackend.cpp (the new LTO API) needs some 
> > kind of llvm-lto2 based test.
> Thank you for this feedback. 
> 
> I've been looking at how to add an overridable TargetMachine hook which is 
> not dissimilar to this static function, but is overridable by TargetMachine 
> subclasses. It sounds like this approach will also not work (unless the 
> TargetMachine is allowed to update its (Default)Options in LTO without 
> issue). 
> 
> I am hoping to get a patch out today for review (which does not include the 
> RISC-V specific parts of this patch, and only includes a default empty 
> implementation), but I imagine it will remain unsatisfactory for LTO for the 
> same reasons this is.
Presumably you could still do the same thing I'm suggesting here - validate and 
aggregate the value across modules in LTO::addModule. Then your hook would just 
check the aggregated setting on the Config.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72245/new/

https://reviews.llvm.org/D72245



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


[PATCH] D72624: [WIP] TargetMachine Hook for Module Metadata

2020-01-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

I'm not sure if ThinLTOCodeGenerator.cpp and LTOBackend.cpp were intentionally 
left out due to the LTO concerns mentioned in the description?

Note if we are just passing in the Module and updating the TM based on that, it 
wouldn't hit the threading issue I mentioned in D72245 
, but neither would you get the proper 
aggregation/checking across ThinLTO'ed modules.




Comment at: llvm/include/llvm/Target/TargetMachine.h:188
+  // `M.setTargetTriple(TM->getTargetTriple())` and before
+  // `M.setDataLayout(createDataLayout())`.
+  virtual void resetTargetDefaultOptions(const Module ) const;

Is there a way to enforce this? Otherwise I foresee fragility. E.g. what if 
this method set a flag on the TM indicating that we have updated it properly 
from the Module, and TargetMachine::createDataLayout() asserted that this flag 
was set?



Comment at: llvm/lib/Target/TargetMachine.cpp:51
+//
+// Override methods should only change DefaultOptions, and use this super
+// method to copy the default options into the current options.


Looks like DefaultOptions is const, so override methods wouldn't be able to 
change it.



Comment at: llvm/lib/Target/TargetMachine.cpp:53
+// method to copy the default options into the current options.
+void TargetMachine::resetTargetDefaultOptions(const Module ) const {
+  Options = DefaultOptions;

Can you clarify how M will be used - will a follow on patch set the 
MCOptions.ABIName from the Module? Note in the meantime you will likely need to 
mark this with an LLVM_ATTRIBUTE_UNUSED.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72624/new/

https://reviews.llvm.org/D72624



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


[PATCH] D72538: [ThinLTO] Add additional ThinLTO pipeline testing with new PM

2020-01-13 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2af97be8027a: [ThinLTO] Add additional ThinLTO pipeline 
testing with new PM (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72538/new/

https://reviews.llvm.org/D72538

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/test/Other/Inputs/new-pm-thinlto-prelink-pgo-defaults.proftext
  llvm/test/Other/Inputs/new-pm-thinlto-samplepgo-defaults.prof
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -0,0 +1,213 @@
+; Validate ThinLTO prelink pipeline when we have Sample PGO
+;
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-O23SZ,CHECK-O-NODIS,CHECK-O123,CHECK-EP-PIPELINE-START
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-O23SZ,CHECK-O-NODIS
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
+; RUN: -passes='thinlto-pre-link,name-anon-globals' -S  %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-O23SZ,CHECK-O123
+;
+; CHECK-O: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor
+; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
+; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
+; CHECK-O-NEXT: Starting llvm::Module pass manager run.
+; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
+; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
+; CHECK-O-NEXT: Starting llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SimplifyCFGPass
+; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
+; CHECK-O-NEXT: Running analysis: AssumptionAnalysis
+; CHECK-O-NEXT: Running pass: SROA
+; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
+; CHECK-O-NEXT: Running pass: EarlyCSEPass
+; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
+; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
+; CHECK-O-NEXT: Running pass: InstCombinePass on foo
+; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on foo
+; CHECK-O-NEXT: Running analysis: AAManager on foo
+; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy on foo
+; CHECK-O-NEXT: Finished llvm::Function pass manager run.
+; CHECK-O-NEXT: Running pass: SampleProfileLoaderPass
+; CHECK-O-NEXT: Running analysis: ProfileSummaryAnalysis

[PATCH] D72523: [remark][diagnostics] Using clang diagnostic handler for IR input files

2020-01-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:594
+  // SourceLoc.
+  if (Context == nullptr) {
+return FullSourceLoc();

xur wrote:
> tejohnson wrote:
> > Does this only happen with IR input? Does it always happen with IR input? 
> > If not, what happens when we have a non-null Context but IR input? It 
> > sounds like it should still always return an invalid Loc since there is no 
> > SourceManager? In that case can you set a flag on the BackendConsumer so we 
> > can bail out directly in the IR input case, instead of going through the 
> > motions only to get an invalid Loc back anyway? It would also be more clear.
> Before this patch, IR input does not called to this function. IR input has a 
> null Context (so it will seg-fault at the dereference at line 598). Context 
> == nullptr should be only happening with the empty BackendConsume that 
> installed in this patch. 
> I tried to set Context but the whole point was to get SrouceManager which was 
> not available for IR input.
> 
> 
Since Context==nullptr iff IR input, then for clarity can you add a comment by 
these checks that this case is specifically corresponding to when we have IR 
input?

(Also, I was a little confused when I first reviewed this since I didn't 
realize this Context variable was an ASTContext and not the LLVMContext being 
passed in to the new BackendConsumer constructor, now I see why it is always 
null in that case.)



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:650
+  if (!Loc.isValid()) {
+MsgStream << D.getLocationStr() << ": in function "
+  << D.getFunction().getName() << ' '

xur wrote:
> tejohnson wrote:
> > Can you add a test for this one?
> > 
> > Also, what determines the format of the message when Loc is valid? I was 
> > trying to figure out where that got determined, but couldn't easily track 
> > it down. 
> Do you mean adding a test to test the path of branch starting line 650?
> (For the case of valid Loc, I don't think we need to test as it's not 
> changed.)
> 
> If so, there is already a test for this:
> clang/test/CodeGen/backend-unsupported-error.ll
> I think this calls to llvm's diagnostic handler for IR input files (before 
> this patch). The format is here:
> DiagnosticInfoUnsupported::print(...) in  llvm/lib/IR/DiagnosticInfo.cpp
> 
> For the case of input other than IR files, the Diags should go to clang 
> diagnostic handler.  This patch might change the behavior. 
> 
> I think I will check Context == nullptr directly (rather Loc.isValid). This 
> way we don't need to call into getBestLocationFromDebugLoc(), and it will not 
> affect non-IR input files.
> 
> Do you mean adding a test to test the path of branch starting line 650?

Yes, but:

> If so, there is already a test for this:
> clang/test/CodeGen/backend-unsupported-error.ll

I see, I didn't realize this was already being tested with IR input.  Nevermind 
then.


> The format is here:
> DiagnosticInfoUnsupported::print(...) in llvm/lib/IR/DiagnosticInfo.cpp

Ok thanks. Looking at that file, I'm wondering if we can use those facilities 
directly rather than cloning the formatting code here. I.e. instead of 
constructing a MsgStream manually here, duplicating the code in 
DiagnosticInfoUnsupported::print, couldn't this handling be something like:

DiagnosticPrinterRawOStream DP(MsgStream);
D.print(DP);

These lines would subsume the manual setup of MsgStream in the null Context 
case, as well as the MsgStream << D.getMessage() line below it. Then you would 
still call Diags.Report with MsgStream.str() as usual.

And ditto for the other 2 types of DiagnosticInfos below. This mechanism is 
used in quite a few diagnostic handlers setup in LLVM (e.g. the one in 
gold-plugin.cpp).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72523/new/

https://reviews.llvm.org/D72523



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


[PATCH] D72245: [PoC][RISCV][LTO] Pass target-abi via module flag metadata

2020-01-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/lib/LTO/LTOBackend.cpp:151
 
+  TargetMachine::initTargetOptions(M, Conf.Options);
+

lenary wrote:
> tejohnson wrote:
> > lenary wrote:
> > > tejohnson wrote:
> > > > This is going to be problematic. The Conf is a reference to the Config 
> > > > object saved on the LTO class instance shared by all backend 
> > > > invocations (the regular LTO module if one exists and any ThinLTO 
> > > > modules). They will end up clobbering each other's values here - 
> > > > although from the assert in initTargetOptions I see they are required 
> > > > to all have the same value anyway. Still, it is not good as the assert 
> > > > may actually be missed with unlucky interference between the threads. 
> > > > The Config object here should really be marked const, let me see if I 
> > > > can change that.
> > > > 
> > > > You could make a copy of the Config here, but that essentially misses 
> > > > the assertion completely. 
> > > > 
> > > > A better way to do this would be in LTO::addModule, which is invoked 
> > > > serially to add each Module to the LTO object.
> > > > 
> > > > However - this misses other places that invoke createTargetMachine - 
> > > > should other places be looking at this new module flag as well? One 
> > > > example I can think of is the old LTO API (*LTOCodeGenerator.cpp 
> > > > files), used by linkers such as ld64 and some other proprietary linkers 
> > > > and the llvm-lto testing tool. But I have no idea about other 
> > > > invocations of createTargetMachine.
> > > > 
> > > > Note that changes to LTO.cpp/LTOBackend.cpp (the new LTO API) needs 
> > > > some kind of llvm-lto2 based test.
> > > Thank you for this feedback. 
> > > 
> > > I've been looking at how to add an overridable TargetMachine hook which 
> > > is not dissimilar to this static function, but is overridable by 
> > > TargetMachine subclasses. It sounds like this approach will also not work 
> > > (unless the TargetMachine is allowed to update its (Default)Options in 
> > > LTO without issue). 
> > > 
> > > I am hoping to get a patch out today for review (which does not include 
> > > the RISC-V specific parts of this patch, and only includes a default 
> > > empty implementation), but I imagine it will remain unsatisfactory for 
> > > LTO for the same reasons this is.
> > Presumably you could still do the same thing I'm suggesting here - validate 
> > and aggregate the value across modules in LTO::addModule. Then your hook 
> > would just check the aggregated setting on the Config.
> D72624 is the patch I have prepared, noting I haven't had time to implement 
> the aggregation yet, which suggests that patch's approach is too general.
FYI I committed a change to make the Config object passed down to the backends 
a const reference in d0aad9f56e1588effa94b15804b098e6307da6b4.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72245/new/

https://reviews.llvm.org/D72245



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 9 inline comments as done.
tejohnson added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:559
+  if (!CodeGenOpts.ThinLTOIndexFile.empty())
+MPM.add(createLowerTypeTestsPass(/*ExportSummary=*/nullptr,
+ /*ImportSummary=*/nullptr,

evgeny777 wrote:
> Test case?
See  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp. Specifically 
the second block of clang invocations:

```
// Also check type test are lowered when the distributed ThinLTO backend clang
// invocation is passed an empty index file, in which case a non-ThinLTO
// compilation pipeline is invoked. If not lowered then LLVM CodeGen may assert.

```
I'm testing both the new and old PMs, as well as the new PM O0 path (basically 
all paths modified in this file).



Comment at: clang/test/CodeGenCXX/lto-visibility-inference.cpp:73
   c1->f();
-  // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C2"
+  // ITANIUM: type.test{{.*}}!"_ZTS2C2"
   // MS: type.test{{.*}}!"?AUC2@@"

evgeny777 wrote:
> What caused this and other changes in this file?
Because we now will insert type tests for non-hidden vtables. This is enabled 
by the changes to LTO to interpret these based on the vcall_visibility metadata.



Comment at: llvm/include/llvm/Transforms/IPO.h:245
+ const ModuleSummaryIndex *ImportSummary,
+ bool StripAll = false);
 

evgeny777 wrote:
> s/StripAll/DropTypeTests/g ?
Woops, missed this one after my rename! Good catch.

Also, noticed the description in the comments is now stale, fixed.



Comment at: llvm/lib/LTO/LTOCodeGenerator.cpp:550
+  // pipeline run below.
+  updateVCallVisibilityInModule(*MergedModule);
+

evgeny777 wrote:
> I'd rather use
> ```
> updateVCallVisibilityInModule(*MergedModule,  /* 
> WholeProgramVisibilityEnabledInLTO */ false)
> ```
> and remove default value for second parameter
Good idea, changed.



Comment at: llvm/lib/Transforms/IPO/LowerTypeTests.cpp:1775
+if (TypeTestFunc) {
+  for (auto UI = TypeTestFunc->use_begin(), UE = TypeTestFunc->use_end();
+   UI != UE;) {

evgeny777 wrote:
> Fold identical code blocks
After looking at this code again, I have changed it a bit. We should only be 
removing assumes that are consuming type test instructions. I have changed this 
(which removes the redundancy in any case). I also added a check to the test 
mentioned earlier for this handling 
(clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp) to ensure we 
don't remove unrelated llvm.assume.



Comment at: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:145
+/// when enabled via the linker.
+cl::opt DisableWholeProgramVisibility(
+"disable-whole-program-visibility", cl::init(false), cl::Hidden,

evgeny777 wrote:
> Is this tested?
Added a test of it to llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 238048.
tejohnson marked 2 inline comments as done.
tejohnson added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
  llvm/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll
  llvm/test/Transforms/WholeProgramDevirt/import.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -626,6 +627,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr ThinLinkOut;
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ 

[PATCH] D72624: [WIP] TargetMachine Hook for Module Metadata

2020-01-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D72624#1820598 , @dblaikie wrote:

> (just a general comment that this code review should be only in service of 
> the design discussion happening on llvm-dev - please don't approve/commit 
> this without closing out the design discussion there if there are actionable 
> conclusions from this review)


Got it, I will just look at from the LTO perspective. The target ABI specifics 
I haven't followed very closely and are not really my expertise.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72624/new/

https://reviews.llvm.org/D72624



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


[PATCH] D72624: [WIP] TargetMachine Hook for Module Metadata

2020-01-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D72624#1820281 , @lenary wrote:

> In D72624#1817464 , @tejohnson wrote:
>
> >
>
>
> Thank you for your feedback! It has been very helpful.
>
> > I'm not sure if ThinLTOCodeGenerator.cpp and LTOBackend.cpp were 
> > intentionally left out due to the LTO concerns mentioned in the description?
>
> Mostly left out because I wasn't sure how to attack them. I've got an update 
> to this patch which I'm testing right now and it looks much better. I will 
> post that imminently.
>
> > Note if we are just passing in the Module and updating the TM based on 
> > that, it wouldn't hit the threading issue I mentioned in D72245 
> > , but neither would you get the proper 
> > aggregation/checking across ThinLTO'ed modules.
>
> Ok, right, so I think I know what else this patch needs to do. At the moment, 
> I think the `ModFlagBehavior` for module flags are not being checked during 
> ThinLTO. I think this is something that has to be checked for compatibility 
> in `ThinLTOCodeGenerator::addModule` (like the triple is checked for 
> compatibility).


And LTO::addModule (just to add confusion, there are two LTO APIs, 
ThinLTOCodeGenerator is the old one and LTO is the new one, the latter being 
used by lld and the gold plugin).

I had mentioned using LTO::addModule to do the checking in the other patch, but 
there is a complication I should mention:

> I see that the checking behaviour is in `IRMover`, but I don't think ThinLTO 
> uses that, and I don't feel familiar enough with ThinLTO to be sure.

The ThinLTO "link", which is where the modules are added serially, does not 
read IR, only the summaries, which are linked together into a large index used 
to drive ThinLTO whole program analysis. So you can't really read the module 
flags directly during addModule, they need to be propagated via the summary 
flags. The ThinLTO backends which are subsequently fired off in parallel do 
read IR. In those backends, depending on the results of the ThinLTO analysis 
phase, we may use IRMover to link in ("import) functions from other modules. At 
that point, the module flags from any modules that backend is importing from 
will be combined and any errors due to conficting values will be issued.

Thinking through this some more, rather than attempting to fully validate the 
consistency of the module flags across all modules in ThinLTO mode, just rely 
on some checking when we merge subsections of the IR in the ThinLTO backends 
during this importing, which will happen automatically. This is presumably 
where the checking is desirable anyway (in terms of the cases you are most 
interested in catching with ThinLTO, because the IR is getting merged). Note 
that unlike in the full LTO case, where the IR is merged before you create the 
TM, in the ThinLTO case the TM will be created before any of this cross-module 
importing (partial IR merging), so with your patch presumably it will just use 
whatever module flag is on that original Module for it's corresponding ThinLTO 
backend. But since it sounds like any difference in these module flags is an 
error, it will just get flagged a little later but not affect how the TM is set 
up in the correct case. Does that sound reasonable?

> The update to my patch will not address this part of ThinLTO.

I'll take a look through your patch later today or tomorrow, but it may be just 
fine from the above perspective.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72624/new/

https://reviews.llvm.org/D72624



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


[PATCH] D72523: [remark][diagnostics] Using clang diagnostic handler for IR input files

2020-01-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

LGTM. One more request for a comment below that I forgot to add earlier.




Comment at: clang/lib/CodeGen/CodeGenAction.cpp:154
 }
+BackendConsumer(BackendAction Action, DiagnosticsEngine ,
+const HeaderSearchOptions ,

Add comment as to what specific case this new constructor is for.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72523/new/

https://reviews.llvm.org/D72523



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


[PATCH] D72547: [llvm] Make new pass manager's OptimizationLevel a class

2020-01-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Overall I like this approach.




Comment at: llvm/lib/Passes/PassBuilder.cpp:246
 
-static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
-  switch (Level) {
-  case PassBuilder::O0:
-  case PassBuilder::O1:
-  case PassBuilder::O2:
-  case PassBuilder::O3:
-return false;
-
-  case PassBuilder::Os:
-  case PassBuilder::Oz:
-return true;
-  }
-  llvm_unreachable("Invalid optimization level!");
-}
+const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O0 = {0,
+   0};

Nit, it would be good to document the constant parameters, e.g. 
{/*SpeedLevel*/0, /*SizeLevel*/0}



Comment at: llvm/lib/Passes/PassBuilder.cpp:407
   // Hoisting of scalars and load expressions.
-  if (Level > O1) {
+  if (Level.getSpeedupLevel() >= 2) {
 if (EnableGVNHoist)

Nit, all similar checks below are Level.getSpeedupLevel() > 1, make this one 
consistent.



Comment at: llvm/lib/Passes/PassBuilder.cpp:487
   PTO.LoopUnrolling)
-LPM2.addPass(LoopFullUnrollPass(Level, /*OnlyWhenForced=*/false,
+LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
+/*OnlyWhenForced=*/false,

This results in a behavior, change, right? I.e. we used to inadvertently get 
the O3 threshold for full unrolling with Oz/Os but no longer will. If so, make 
sure you note this in the patch summary. Also add a test.



Comment at: llvm/lib/Passes/PassBuilder.cpp:973
   if (EnableUnrollAndJam && PTO.LoopUnrolling) {
-OptimizePM.addPass(LoopUnrollAndJamPass(Level));
+OptimizePM.addPass(LoopUnrollAndJamPass(Level.getSpeedupLevel()));
   }

This one and the loop unrolling pass below will also get a change in behavior 
for Os/Oz, correct? That seems reasonable, but needs to be noted in summary and 
tested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72547/new/

https://reviews.llvm.org/D72547



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


[PATCH] D72624: [WIP] TargetMachine Hook for Module Metadata

2020-01-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

From an LTO perspective, this seems fine for the reasons we discussed here. I 
looked through the patch and have a few comments.




Comment at: clang/lib/CodeGen/BackendUtil.cpp:818
+  if (TM) {
+TM->initializeOptionsWithModuleMetadata(*TheModule);
 TheModule->setDataLayout(TM->createDataLayout());

Also needed in EmitAssemblyWithNewPassManager. Maybe it should be moved into 
CreateTargetMachine which would cover both cases.

I'm not sure if this was already discussed - but is there a reason why this 
can't be done in Target::createTargetMachine()? Is it not possible to ensure it 
is called once we have the Module available and pass that in? That would 
centralize this handling and seems cleaner overall.



Comment at: llvm/include/llvm/Target/TargetMachine.h:157
+  const DataLayout createDataLayout() const {
+OptionsCanBeInitalizedFromModule = false;
+return DL;

Do you want to also ensure that createDataLayout is only called iff 
initializeOptionsWithModuleMetadata was previously called? That would need to 
make this a tri-state, or use 2 bools. Then you could assert here that the 
other routine was already called at this point, which would help avoid missing 
calls (like the one I pointed out above), possibly due to future code drift.



Comment at: llvm/include/llvm/Target/TargetMachine.h:192
+  virtual void
+  setTargetOptionsWithModuleMetadata(const Module  LLVM_ATTRIBUTE_UNUSED) {}
+

Should this be private so that it can only be called via 
initializeOptionsWithModuleMetadata?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72624/new/

https://reviews.llvm.org/D72624



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: clang/test/CodeGenCXX/lto-visibility-inference.cpp:73
   c1->f();
-  // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C2"
+  // ITANIUM: type.test{{.*}}!"_ZTS2C2"
   // MS: type.test{{.*}}!"?AUC2@@"

evgeny777 wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > tejohnson wrote:
> > > > evgeny777 wrote:
> > > > > What caused this and other changes in this file?
> > > > Because we now will insert type tests for non-hidden vtables. This is 
> > > > enabled by the changes to LTO to interpret these based on the 
> > > > vcall_visibility metadata.
> > > The results of this test case
> > > ```
> > > %clang_cc1 -flto -triple x86_64-pc-windows-msvc -std=c++11 
> > > -fms-extensions -fwhole-program-vtables -flto-visibility-public-std 
> > > -emit-llvm -o - %s | FileCheck --check-prefix=MS --check-prefix=MS-NOSTD 
> > > %s
> > > ```
> > > look not correct to me. I think you shouldn't generate type tests for 
> > > standard library classes with  `-flto-visibility-public-std`. Currently 
> > > if this flag is given, clang doesn't do this either even with 
> > > `-fvisibility=hidden`
> > The associated vtables would get the vcall_visibility public metadata, so 
> > the type tests themselves aren't problematic. I tend to think that an 
> > application using such options should simply stick with -fvisibility=hidden 
> > to get WPD and not use the new LTO option to convert all public 
> > vcall_visibility metadata to hidden.
> > The associated vtables would get the vcall_visibility public metadata, so 
> > the type tests themselves aren't problematic. I tend to think that an 
> > application using such options should simply stick with -fvisibility=hidden 
> > to get WPD and not use the new LTO option to convert all public 
> > vcall_visibility metadata to hidden.
> 
> I see two issues here:
> 1) It's not always good option to force hidden visibility for everything. For 
> instance I work on proprietary platform which demands public visibility for 
> certain symbols in order for dynamic loader to work properly. In this context 
> your patch does a great job.
> 
> 2) Standard library is almost never LTOed so in general we can't narrow 
> std::* vtables visibility to linkage unit
> 
> Is there anything which prevents from implementing the same functionality 
> with new -lto-whole-program-visibility option (i.e without forcing hidden 
> visibility)? In other words the following looks good to me:
> 
> ```
> # Compile with lto/devirtualization support
> clang -flto=thin -flto-visibility-public-std -fwhole-program-vtables -c *.cpp
> 
> # Link: everything is devirtualized except standard library classes virtual 
> methods
> clang -Wl,-lto-whole-program-visibility -fuse-ld=lld *.o
> ```
Ok, thanks for the info. I will go ahead and change the code to not insert the 
type tests in this case to support this usage.

Ultimately, I would like to decouple the existence of the type tests from 
visibility implications. I'm working on another change to delay 
lowering/removal of type tests until after indirect call promotion, so we can 
use them in other cases (streamlined indirect call promotion checks against the 
vtable instead of the function pointers, also useful if we want to implement 
speculative devirtualization based on WPD info). In those cases we need the 
type tests, either to locate information in the summary, or to get the address 
point offset for a vtable address compare. In that case it would be helpful to 
have the type tests in this type of code as well. So we'll need another way to 
communicate down to WPD that they should never be devirtualized. But I don't 
think it makes sense to design this support until there is a concrete use case 
and need. In the meantime I will change the code to be conservative and not 
insert the type tests in this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239646.
tejohnson added a comment.

Address remaining comment by blocking type test insertion for public std 
visibility


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/cfi-mfcall.cpp
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_alias.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -625,6 +626,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr ThinLinkOut;
Index: llvm/tools/gold/gold-plugin.cpp

[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-01-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: pcc, evgeny777.
Herald added subscribers: arphaman, dexonsmith, steven_wu, hiraditya, Prazek, 
mehdi_amini.
Herald added projects: clang, LLVM.

Currently type test assume sequences inserted for devirtualization are
removed during WPD. This patch delays their removal until later in the
optimization pipeline. This is an enabler for upcoming enhancements to
indirect call promotion, for example streamlined promotion guard
sequences that compare against vtable address instead of the target
function, when there are small number of possible vtables (either
determined via WPD or by in-progress type profiling). We need the type
tests to correlate the callsites with the address point offset needed in
the compare sequence, and optionally to associated type summary info
computed during WPD.

This depends on work in D71913  to enable 
invocation of LowerTypeTests to
drop type test assume sequences, which will now be invoked following ICP
in the ThinLTO post-LTO link pipelines, and also after the existing
export phase LowerTypeTests invocation in regular LTO (which is already
after ICP). We cannot simply move the existing import phase
LowerTypeTests pass later in the ThinLTO post link pipelines, as the
comment in PassBuilder.cpp notes (it must run early because when
performing CFI other passes may disturb the sequences it looks for).

This necessitated adding a new type test resolution "Unknown" that we
can use on the type test assume sequences previously removed by WPD,
that we now want LTT to ignore.

Depends on D71913 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73242

Files:
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGen/thinlto-distributed-cfi.ll
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/ThinLTO/X86/cfi-icall-only-defuse.ll
  llvm/test/ThinLTO/X86/cfi-icall.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll

Index: llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
+++ llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
@@ -25,7 +25,7 @@
   %fptr = load i8*, i8** %fptrptr
   %fptr_casted = bitcast i8* %fptr to i32 (i8*)*
   %result = call i32 %fptr_casted(i8* %obj)
-  ; CHECK-NOT: call
+  ; CHECK-NOT: call i32 %
   ; CHECK: ret i32 123
   ret i32 %result
 }
Index: llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
+++ llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
@@ -32,7 +32,7 @@
 ; SUMMARY-NEXT: TypeIdMap:
 ; SUMMARY-NEXT:   typeid1:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
===
--- llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
+++ llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
@@ -9,7 +9,7 @@
 ; SUMMARY:  TypeIdMap:
 ; SUMMARY-NEXT:   typeid3:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
@@ -29,7 +29,7 @@
 ; SUMMARY-ARM-NEXT: Bit: 1
 ; SUMMARY-NEXT:   typeid4:
 ; SUMMARY-NEXT: TTRes:
-; SUMMARY-NEXT:   Kind:Unsat
+; SUMMARY-NEXT:   Kind:Unknown
 ; SUMMARY-NEXT:   SizeM1BitWidth:  0
 ; SUMMARY-NEXT:   AlignLog2:   0
 ; SUMMARY-NEXT:   SizeM1:  0
Index: llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll

[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-01-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll:28
   %result = call i32 %fptr_casted(i8* %obj)
-  ; CHECK-NOT: call
+  ; CHECK-NOT: call i32 %
   ; CHECK: ret i32 123

This change is to distinguish the indirect call here that should have been 
removed from the @llvm.type.test and @llvm.assume calls that are no longer 
removed at this point.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73242/new/

https://reviews.llvm.org/D73242



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


[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-16 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 238561.
tejohnson added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/GlobalObject.h
  llvm/lib/IR/Metadata.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/lib/Transforms/IPO/GlobalSplit.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions.ll
  llvm/test/Transforms/GlobalDCE/vtable-rtti.ll

Index: llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
===
--- llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
+++ llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
@@ -39,9 +39,10 @@
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!3, !4}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 2} ; translation-unit vcall visibility
 !3 = !{i32 1, !"LTOPostLink", i32 1}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
@@ -85,10 +85,11 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{}
+!llvm.module.flags = !{!5}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 0} ; public vcall visibility
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
+!5 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
@@ -85,7 +85,7 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{!5}
+!llvm.module.flags = !{!5, !6}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
@@ -93,3 +93,4 @@
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
 !5 = !{i32 1, !"LTOPostLink", i32 1}
+!6 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions.ll
@@ -48,8 +48,11 @@
   ret i32 %call1
 }
 
+!llvm.module.flags = !{!4}
+
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFivE.virtual"}
 !2 = !{i64 24, !"_ZTSM1AFivE.virtual"}
 !3 = !{i64 2}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
 !9 = !{}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
@@ -1,3 +1,5 @@
+; Tests that VFE is not performed when the Virtual Function Elim metadata set
+; to 0. This is the same as virtual-functions.ll otherwise.
 ; RUN: opt < %s -globaldce -S | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
@@ -11,14 +13,12 @@
 ; intrinsic. Function test_A makes a call to A::foo, but there is no call to
 ; A::bar anywhere, so A::bar can be deleted, and its vtable slot replaced with
 ; null.
+; However, with the metadata set to 0 we should not perform this VFE.
 
 %struct.A = type { i32 (...)** }
 
-; The pointer to A::bar in the vtable can be removed, because it will never be
-; loaded. We replace it with null to keep the layout the same. Because it is at
-; the end of the vtable we could potentially shrink the vtable, but don't
-; currently do that.
-; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*), i8* null] }
+; We should retain @_ZN1A3barEv in the vtable.
+; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] 

[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-16 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 238569.
tejohnson added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_alias.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
  llvm/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll
  llvm/test/Transforms/WholeProgramDevirt/import.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -625,6 +626,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr ThinLinkOut;
Index: llvm/tools/gold/gold-plugin.cpp
===
--- 

[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2020-01-16 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 238565.
tejohnson added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71911/new/

https://reviews.llvm.org/D71911

Files:
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/thinlto-vtable-summary.ll

Index: llvm/test/Assembler/thinlto-vtable-summary.ll
===
--- llvm/test/Assembler/thinlto-vtable-summary.ll
+++ llvm/test/Assembler/thinlto-vtable-summary.ll
@@ -29,9 +29,9 @@
 
 ^0 = module: (path: "", hash: (0, 0, 0, 0, 0))
 ^1 = gv: (name: "_ZN1A1nEi") ; guid = 1621563287929432257
-^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
+^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
 ^3 = gv: (name: "_ZN1B1fEi") ; guid = 7162046368816414394
-^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
+^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
 ^5 = gv: (name: "_ZN1C1fEi") ; guid = 14876272565662207556
 ^6 = typeidCompatibleVTable: (name: "_ZTS1A", summary: ((offset: 16, ^2), (offset: 16, ^4))) ; guid = 7004155349499253778
 ^7 = typeidCompatibleVTable: (name: "_ZTS1B", summary: ((offset: 16, ^2))) ; guid = 6203814149063363976
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -2900,11 +2900,15 @@
 }
 
 void AssemblyWriter::printGlobalVarSummary(const GlobalVarSummary *GS) {
+  auto VTableFuncs = GS->vTableFuncs();
   Out << ", varFlags: (readonly: " << GS->VarFlags.MaybeReadOnly << ", "
   << "writeonly: " << GS->VarFlags.MaybeWriteOnly << ", "
-  << "constant: " << GS->VarFlags.Constant << ")";
+  << "constant: " << GS->VarFlags.Constant;
+  if (!VTableFuncs.empty())
+Out << ", "
+<< "vcall_visibility: " << GS->VarFlags.VCallVisibility;
+  Out << ")";
 
-  auto VTableFuncs = GS->vTableFuncs();
   if (!VTableFuncs.empty()) {
 Out << ", vTableFuncs: (";
 FieldSeparator FS;
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1028,8 +1028,8 @@
 }
 
 static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags) {
-  uint64_t RawFlags =
-  Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) | (Flags.Constant << 2);
+  uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
+  (Flags.Constant << 2) | Flags.VCallVisibility << 3;
   return RawFlags;
 }
 
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -985,9 +985,10 @@
 
 // Decode the flags for GlobalVariable in the summary
 static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags) {
-  return GlobalVarSummary::GVarFlags((RawFlags & 0x1) ? true : false,
- (RawFlags & 0x2) ? true : false,
- (RawFlags & 0x4) ? true : false);
+  return GlobalVarSummary::GVarFlags(
+  (RawFlags & 0x1) ? true : false, (RawFlags & 0x2) ? true : false,
+  (RawFlags & 0x4) ? true : false,
+  (GlobalObject::VCallVisibility)(RawFlags >> 3));
 }
 
 static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val) {
Index: llvm/lib/AsmParser/LLToken.h

[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-21 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239406.
tejohnson added a comment.

Remove stale change that didn't belong here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/GlobalObject.h
  llvm/lib/IR/Metadata.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/lib/Transforms/IPO/GlobalSplit.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions.ll
  llvm/test/Transforms/GlobalDCE/vtable-rtti.ll

Index: llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
===
--- llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
+++ llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
@@ -39,9 +39,10 @@
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!3, !4}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 2} ; translation-unit vcall visibility
 !3 = !{i32 1, !"LTOPostLink", i32 1}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
@@ -85,10 +85,11 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{}
+!llvm.module.flags = !{!5}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 0} ; public vcall visibility
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
+!5 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
@@ -85,7 +85,7 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{!5}
+!llvm.module.flags = !{!5, !6}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
@@ -93,3 +93,4 @@
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
 !5 = !{i32 1, !"LTOPostLink", i32 1}
+!6 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions.ll
@@ -48,8 +48,11 @@
   ret i32 %call1
 }
 
+!llvm.module.flags = !{!4}
+
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFivE.virtual"}
 !2 = !{i64 24, !"_ZTSM1AFivE.virtual"}
 !3 = !{i64 2}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
 !9 = !{}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
@@ -1,3 +1,5 @@
+; Tests that VFE is not performed when the Virtual Function Elim metadata set
+; to 0. This is the same as virtual-functions.ll otherwise.
 ; RUN: opt < %s -globaldce -S | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
@@ -11,14 +13,12 @@
 ; intrinsic. Function test_A makes a call to A::foo, but there is no call to
 ; A::bar anywhere, so A::bar can be deleted, and its vtable slot replaced with
 ; null.
+; However, with the metadata set to 0 we should not perform this VFE.
 
 %struct.A = type { i32 (...)** }
 
-; The pointer to A::bar in the vtable can be removed, because it will never be
-; loaded. We replace it with null to keep the layout the same. Because it is at
-; the end of the vtable we could potentially shrink the vtable, but don't
-; currently do that.
-; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*), i8* null] }
+; We should retain @_ZN1A3barEv in the vtable.
+; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] 

[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-21 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:676
+  bool ShouldEmitWPDInfo = CGM.getCodeGenOpts().WholeProgramVTables &&
+   CGM.HasHiddenLTOVisibility(RD);
   llvm::Value *VirtualFn = nullptr;

evgeny777 wrote:
> Why are we checking for hidden visibility here?
This one is leftover from an earlier attempt at doing something more clever 
during GlobalOpt to decide whether we should be doing VFE or not, and I 
eventually abandoned that as it didn't work well, and went with the module flag 
here. You're right that we should be emitting the type test here under 
WholeProgramVtables, and not just with hidden visibility, but that belongs in 
D71913 (where I make the other change to insert type tests without hidden 
visibility). I've removed this change from this patch and am going to add it 
along with a test to that later patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907



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


[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2020-01-21 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239412.
tejohnson added a comment.

Address comment and rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71911/new/

https://reviews.llvm.org/D71911

Files:
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/thinlto-vtable-summary.ll

Index: llvm/test/Assembler/thinlto-vtable-summary.ll
===
--- llvm/test/Assembler/thinlto-vtable-summary.ll
+++ llvm/test/Assembler/thinlto-vtable-summary.ll
@@ -29,9 +29,9 @@
 
 ^0 = module: (path: "", hash: (0, 0, 0, 0, 0))
 ^1 = gv: (name: "_ZN1A1nEi") ; guid = 1621563287929432257
-^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
+^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
 ^3 = gv: (name: "_ZN1B1fEi") ; guid = 7162046368816414394
-^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
+^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
 ^5 = gv: (name: "_ZN1C1fEi") ; guid = 14876272565662207556
 ^6 = typeidCompatibleVTable: (name: "_ZTS1A", summary: ((offset: 16, ^2), (offset: 16, ^4))) ; guid = 7004155349499253778
 ^7 = typeidCompatibleVTable: (name: "_ZTS1B", summary: ((offset: 16, ^2))) ; guid = 6203814149063363976
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -2900,11 +2900,15 @@
 }
 
 void AssemblyWriter::printGlobalVarSummary(const GlobalVarSummary *GS) {
+  auto VTableFuncs = GS->vTableFuncs();
   Out << ", varFlags: (readonly: " << GS->VarFlags.MaybeReadOnly << ", "
   << "writeonly: " << GS->VarFlags.MaybeWriteOnly << ", "
-  << "constant: " << GS->VarFlags.Constant << ")";
+  << "constant: " << GS->VarFlags.Constant;
+  if (!VTableFuncs.empty())
+Out << ", "
+<< "vcall_visibility: " << GS->VarFlags.VCallVisibility;
+  Out << ")";
 
-  auto VTableFuncs = GS->vTableFuncs();
   if (!VTableFuncs.empty()) {
 Out << ", vTableFuncs: (";
 FieldSeparator FS;
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1028,8 +1028,8 @@
 }
 
 static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags) {
-  uint64_t RawFlags =
-  Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) | (Flags.Constant << 2);
+  uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
+  (Flags.Constant << 2) | Flags.VCallVisibility << 3;
   return RawFlags;
 }
 
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -985,9 +985,10 @@
 
 // Decode the flags for GlobalVariable in the summary
 static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags) {
-  return GlobalVarSummary::GVarFlags((RawFlags & 0x1) ? true : false,
- (RawFlags & 0x2) ? true : false,
- (RawFlags & 0x4) ? true : false);
+  return GlobalVarSummary::GVarFlags(
+  (RawFlags & 0x1) ? true : false, (RawFlags & 0x2) ? true : false,
+  (RawFlags & 0x4) ? true : false,
+  (GlobalObject::VCallVisibility)(RawFlags >> 3));
 }
 
 static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val) {
@@ -5967,7 +5968,8 @@
   unsigned RefArrayStart = 

[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-20 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 4 inline comments as done.
tejohnson added inline comments.



Comment at: llvm/test/Transforms/WholeProgramDevirt/import-indir.ll:2
 ; Test that we correctly import an indir resolution for type identifier 
"typeid1".
-; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import 
-wholeprogramdevirt-read-summary=%S/Inputs/import-indir.yaml 
-wholeprogramdevirt-write-summary=%t < %s | FileCheck %s
+; RUN: opt -S -wholeprogramdevirt -whole-program-visibility 
-wholeprogramdevirt-summary-action=import 
-wholeprogramdevirt-read-summary=%S/Inputs/import-indir.yaml 
-wholeprogramdevirt-write-summary=%t < %s | FileCheck %s
 ; RUN: FileCheck --check-prefix=SUMMARY %s < %t

evgeny777 wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > Why do you need `-whole-program-visibility` here? Correct me if I'm 
> > > wrong, but AFAIK module scanning doesn't happen during import and GV 
> > > visibility should be taken from imported summary.
> > Before my patch, type tests were only inserted for vtables with hidden LTO 
> > visibility. Therefore, the very presence of type tests communicated the 
> > hidden visibility and enabled the WPD.
> > 
> > With this patch, to support enabling WPD aggressively at LTO time, we now 
> > insert type tests unconditionally under -fwhole-program-vtables. The 
> > vcall_visibility metadata tells LTO how to interpret them. And the new 
> > options allow changing those to hidden visibility to get the more 
> > aggressive WPD.
> > 
> > Because these legacy tests have type tests but no vcall_visibility 
> > metadata, we now will conservatively treat them as having public LTO 
> > visibility. This option is therefore required to convert the summarized 
> > (default public) vcall visibility into hidden to get the prior more 
> > aggressive behavior they are trying to test.
> > 
> > Note I could have instead changed the assembly here to add hidden 
> > vcall_visibility metadata everywhere. That seemed a little onerous so 
> > that's why I just added the option. I could add a comment to that effect if 
> > it would help?
> I think you can remove this option from this test (and probably others using 
> -wholeprogramdevirt-summary-action=import option), because visibility seems 
> to be not analyzed on import phase. I just did this btw and test still passes 
> flawlessly.
Good point, removed from here and a couple other similar tests. I added it a 
little overeagerly to address the failures I got originally.



Comment at: llvm/tools/opt/opt.cpp:634
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ 
false);

evgeny777 wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > Hm, looks like I don't fully understand this. I have following concerns:
> > > 
> > > 1) According to your changes every time I use `opt -wholeprogramdevirt` I 
> > > also have to pass `-whole-program-visibility`. Has `-wholeprogramdevirt` 
> > > flag become no-op without this additional flag? If so this looks counter 
> > > intuitive to me.
> > > 
> > > 2) When I use `opt -wholeprogramdevirt` default constructor of 
> > > `WholeProgramDevirt` class is called and `UseCommandLine` flag is set to 
> > > true. Can't I use this flag to effectively lower visibility in module 
> > > instead of playing with metadata?
> > > 
> > > ```
> > > if (VS->vCallVisibility() == GlobalObject::VCallVisibilityPublic && 
> > > !UseCommandLine)
> > >  return false;
> > > ```
> > > 
> > > According to your changes every time I use opt -wholeprogramdevirt I also 
> > > have to pass -whole-program-visibility. Has -wholeprogramdevirt flag 
> > > become no-op without this additional flag? If so this looks counter 
> > > intuitive to me.
> > 
> > No, it wouldn't be needed if the tests contained !vcall_visibility metadata 
> > indicating hidden LTO visibility (see my earlier comment response).
> > 
> > > When I use opt -wholeprogramdevirt default constructor of 
> > > WholeProgramDevirt class is called and UseCommandLine flag is set to 
> > > true. Can't I use this flag to effectively lower visibility in module 
> > > instead of playing with metadata?
> > 
> > I could do that. What it would mean though is that we would be unable to 
> > use opt for any future testing of vtables intended to have public vcall 
> > visibility (either through a lack of that metadata, or explicit 
> > vcall_vsibility metadata indicating public). Which might be ok - in fact 
> > all my new testing of this behavior is via llvm-lto2 or the linkers. I 
> > suppose that would obviate this change as well as all the opt based test 
> > changes to pass the flag. Do you think that is better?
> > I could do that. What it would mean though is that we would be unable to 
> > use opt for any future testing of vtables intended to have public vcall 
> > visibility (either through a lack of that metadata, or 

[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-20 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239214.
tejohnson marked 2 inline comments as done.
tejohnson added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_alias.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -625,6 +626,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr ThinLinkOut;
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -204,6 +204,8 @@
   static std::string dwo_dir;
   /// Statistics output 

[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-21 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 5 inline comments as done.
tejohnson added inline comments.



Comment at: clang/test/CodeGenCXX/lto-visibility-inference.cpp:73
   c1->f();
-  // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C2"
+  // ITANIUM: type.test{{.*}}!"_ZTS2C2"
   // MS: type.test{{.*}}!"?AUC2@@"

evgeny777 wrote:
> tejohnson wrote:
> > evgeny777 wrote:
> > > What caused this and other changes in this file?
> > Because we now will insert type tests for non-hidden vtables. This is 
> > enabled by the changes to LTO to interpret these based on the 
> > vcall_visibility metadata.
> The results of this test case
> ```
> %clang_cc1 -flto -triple x86_64-pc-windows-msvc -std=c++11 -fms-extensions 
> -fwhole-program-vtables -flto-visibility-public-std -emit-llvm -o - %s | 
> FileCheck --check-prefix=MS --check-prefix=MS-NOSTD %s
> ```
> look not correct to me. I think you shouldn't generate type tests for 
> standard library classes with  `-flto-visibility-public-std`. Currently if 
> this flag is given, clang doesn't do this either even with 
> `-fvisibility=hidden`
The associated vtables would get the vcall_visibility public metadata, so the 
type tests themselves aren't problematic. I tend to think that an application 
using such options should simply stick with -fvisibility=hidden to get WPD and 
not use the new LTO option to convert all public vcall_visibility metadata to 
hidden.



Comment at: clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp:7
+// as expected.
+// RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux 
-fvisibility hidden -fwhole-program-vtables -emit-llvm-bc -o %t.o %s
+// RUN: llvm-dis %t.o -o - | FileCheck --check-prefix=TT %s

evgeny777 wrote:
> I think, we no longer need `-fvisibility hidden` here, do we?
Right, we aren't relying on the visibility for this test which is just ensuring 
the type tests are lowered properly in the distributed backends. I removed it.



Comment at: llvm/lib/LTO/ThinLTOCodeGenerator.cpp:976
+  // via the internal option. Must be done before WPD below.
+  updateVCallVisibilityInIndex(*Index);
+

evgeny777 wrote:
> evgeny777 wrote:
> > ditto
> updateVCallVisibilityInIndex(*Index, /* WholeProgramVisibilityEnabledInLTO */ 
> false) ?
Missed this one before (did the InModule version but not InIndex), fixed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-21 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239428.
tejohnson marked 2 inline comments as done.
tejohnson added a comment.

Address comments and rebase. Also apply modified change to ItaniumCXXABI.cpp
and a change to an associated test (cfi-mfcall.cpp) here as discussed
in child revision D71907 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71913/new/

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/cfi-mfcall.cpp
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_alias.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -625,6 +626,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr 

[PATCH] D70765: LTOVisibility.rst: fix up syntax in example

2020-01-08 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D70765#1807609 , @dankamongmen 
wrote:

> > Typically the author commits the patch, unless they don't have commit 
> > access and request the reviewer to commit for them, but I don't see a 
> > request for that here.
>
> Thanks, Teresa. I indeed do not have commit access (so far as I know or can 
> tell, anyway), so please consider this comment to be such a request.


I can go ahead and take care of committing for you today. BTW if you plan to 
contribute more and want commit access, the instructions are here: 
https://llvm.org/docs/DeveloperPolicy.html#new-contributors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70765/new/

https://reviews.llvm.org/D70765



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


[PATCH] D70765: LTOVisibility.rst: fix up syntax in example

2020-01-08 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43f938eddc8a: LTOVisibility.rst: fix up syntax in example 
(authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70765/new/

https://reviews.llvm.org/D70765

Files:
  clang/docs/LTOVisibility.rst


Index: clang/docs/LTOVisibility.rst
===
--- clang/docs/LTOVisibility.rst
+++ clang/docs/LTOVisibility.rst
@@ -83,7 +83,7 @@
 |  |  }; |  |  |  struct E 
: D {|
 |  |  struct [[clang::lto_visibility_public]] D {|  |  |
virtual void g() { ... }|
 |  |virtual void g() = 0;|  |  |  };   
 |
-|  |  }; |  |  |  
__attribute__(visibility("default"))) D *mkE() {  |
+|  |  }; |  |  |  
__attribute__((visibility("default"))) D *mkE() { |
 |  | |  |  |return 
new E;   |
 |  +-+  |  |  }
 |
 |   |  |   
 |


Index: clang/docs/LTOVisibility.rst
===
--- clang/docs/LTOVisibility.rst
+++ clang/docs/LTOVisibility.rst
@@ -83,7 +83,7 @@
 |  |  }; |  |  |  struct E : D {|
 |  |  struct [[clang::lto_visibility_public]] D {|  |  |virtual void g() { ... }|
 |  |virtual void g() = 0;|  |  |  };|
-|  |  }; |  |  |  __attribute__(visibility("default"))) D *mkE() {  |
+|  |  }; |  |  |  __attribute__((visibility("default"))) D *mkE() { |
 |  | |  |  |return new E;   |
 |  +-+  |  |  } |
 |   |  ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2019-12-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: pcc, evgeny777, steven_wu.
Herald added subscribers: arphaman, dexonsmith, hiraditya, inglorion, Prazek, 
mehdi_amini.
Herald added projects: clang, LLVM.

Second patch in series to support Safe Whole Program Devirtualization
Enablement, see RFC here:
http://lists.llvm.org/pipermail/llvm-dev/2019-December/137543.html

Summarize vcall_visibility metadata in ThinLTO global variable summary.

Depends on D71907 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71911

Files:
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/thinlto-vtable-summary.ll

Index: llvm/test/Assembler/thinlto-vtable-summary.ll
===
--- llvm/test/Assembler/thinlto-vtable-summary.ll
+++ llvm/test/Assembler/thinlto-vtable-summary.ll
@@ -29,9 +29,9 @@
 
 ^0 = module: (path: "", hash: (0, 0, 0, 0, 0))
 ^1 = gv: (name: "_ZN1A1nEi") ; guid = 1621563287929432257
-^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
+^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
 ^3 = gv: (name: "_ZN1B1fEi") ; guid = 7162046368816414394
-^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
+^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
 ^5 = gv: (name: "_ZN1C1fEi") ; guid = 14876272565662207556
 ^6 = typeidCompatibleVTable: (name: "_ZTS1A", summary: ((offset: 16, ^2), (offset: 16, ^4))) ; guid = 7004155349499253778
 ^7 = typeidCompatibleVTable: (name: "_ZTS1B", summary: ((offset: 16, ^2))) ; guid = 6203814149063363976
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -2896,10 +2896,14 @@
 }
 
 void AssemblyWriter::printGlobalVarSummary(const GlobalVarSummary *GS) {
+  auto VTableFuncs = GS->vTableFuncs();
   Out << ", varFlags: (readonly: " << GS->VarFlags.MaybeReadOnly << ", "
-  << "writeonly: " << GS->VarFlags.MaybeWriteOnly << ")";
+  << "writeonly: " << GS->VarFlags.MaybeWriteOnly;
+  if (!VTableFuncs.empty())
+Out << ", "
+<< "vcall_visibility: " << GS->VarFlags.VCallVisibility;
+  Out << ")";
 
-  auto VTableFuncs = GS->vTableFuncs();
   if (!VTableFuncs.empty()) {
 Out << ", vTableFuncs: (";
 FieldSeparator FS;
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1028,7 +1028,8 @@
 }
 
 static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags) {
-  uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1);
+  uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
+  Flags.VCallVisibility << 2;
   return RawFlags;
 }
 
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -985,8 +985,9 @@
 
 // Decode the flags for GlobalVariable in the summary
 static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags) {
-  return GlobalVarSummary::GVarFlags((RawFlags & 0x1) ? true : false,
- (RawFlags & 0x2) ? true : false);
+  return GlobalVarSummary::GVarFlags(
+  (RawFlags & 0x1) ? true : false, (RawFlags & 0x2) ? true : false,
+  (GlobalObject::VCallVisibility)(RawFlags >> 2));
 }
 
 static GlobalValue::VisibilityTypes 

[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2019-12-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: pcc, ostannard, evgeny777, steven_wu.
Herald added subscribers: dexonsmith, hiraditya, Prazek, mehdi_amini.
Herald added projects: clang, LLVM.

First patch to support Safe Whole Program Devirtualization Enablement,
see RFC here: http://lists.llvm.org/pipermail/llvm-dev/2019-December/137543.html

Always emit !vcall_visibility metadata under -fwhole-program-vtables,
and not just for -fvirtual-function-elimination. The vcall visibility
metadata will (in a subsequent patch) be used to communicate to WPD
which vtables are safe to devirtualize, and we will optionally convert
the metadata to hidden visibility at link time. Subsequent follow on
patches will help enable this by adding vcall_visibility metadata to the
ThinLTO summaries, and always emit type test intrinsics under
-fwhole-program-vtables (and not just for vtables with hidden
visibility).

In order to do this safely with VFE, since for VFE all vtable loads must
be type checked loads which will no longer be the case, this patch adds
a new "Virtual Function Elim" module flag to communicate to GlobalDCE
whether to perform VFE using the vcall_visibility metadata.

One additional advantage of using the vcall_visibility metadata to drive
more WPD at LTO link time is that we can use the same mechanism to
enable more aggressive VFE at LTO link time as well. The link time
option proposed in the RFC will convert vcall_visibility metadata to
hidden (aka linkage unit visibility), which combined with
-fvirtual-function-elimination will allow it to be done more
aggressively at LTO link time under the same conditions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71907

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/GlobalObject.h
  llvm/lib/IR/Metadata.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/lib/Transforms/IPO/GlobalSplit.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions.ll
  llvm/test/Transforms/GlobalDCE/vtable-rtti.ll

Index: llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
===
--- llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
+++ llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
@@ -39,9 +39,10 @@
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!3, !4}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 2} ; translation-unit vcall visibility
 !3 = !{i32 1, !"LTOPostLink", i32 1}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
@@ -85,10 +85,11 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{}
+!llvm.module.flags = !{!5}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 0} ; public vcall visibility
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
+!5 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
@@ -85,7 +85,7 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{!5}
+!llvm.module.flags = !{!5, !6}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
@@ -93,3 +93,4 @@
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
 !5 = !{i32 1, !"LTOPostLink", i32 1}
+!6 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions.ll
@@ -48,8 +48,11 @@
   ret i32 %call1
 }
 
+!llvm.module.flags = !{!4}
+
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, 

[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2019-12-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: llvm/lib/IR/Metadata.cpp:1505
+  // updating.
+  eraseMetadata(LLVMContext::MD_vcall_visibility);
   addMetadata(LLVMContext::MD_vcall_visibility,

The erasing of old metadata is needed to enable upgrading the visibility to 
hidden (linkage unit) in a subsequent patch. Made that change here as well as 
the associated rename of the method to try to contain the main vcall visibility 
metadata changes in a single patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2019-12-26 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: pcc, evgeny777, steven_wu.
Herald added subscribers: dang, dexonsmith, MaskRay, hiraditya, arichardson, 
inglorion, Prazek, emaste.
Herald added a reviewer: espindola.
Herald added projects: clang, LLVM.

Third part in series to support Safe Whole Program Devirtualization
Enablement, see RFC here:
http://lists.llvm.org/pipermail/llvm-dev/2019-December/137543.html

This patch adds type test metadata under -fwhole-program-vtables,
even for classes without hidden visibility. It then changes WPD to skip
devirtualization for a virtual function call when any of the compatible
vtables has public vcall visibility.

Additionally, internal LLVM options as well as lld and gold-plugin
options are added which enable upgrading all public vcall visibility
to linkage unit (hidden) visibility during LTO. This enables the more
aggressive WPD to kick in based on LTO time knowledge of the visibility
guarantees.

Support was added to all flavors of LTO WPD (regular, hybrid and
index-only), and to both the new and old LTO APIs.

Unfortunately it was not simple to split the first and second parts of
this part of the change (the unconditional emission of type tests and
the upgrading of the vcall visiblity) as I needed a way to upgrade the
public visibility on legacy WPD llvm assembly tests that don't include
linkage unit vcall visibility specifiers, to avoid a lot of test churn.

I also added a mechanism to LowerTypeTests that allows dropping type
test assume sequences we now aggressively insert when we invoke
distributed ThinLTO backends with null indexes, which is used in testing
mode, and which doesn't invoke the normal ThinLTO backend pipeline.

Depends on D71907  and D71911 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/import-indir.ll
  llvm/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll
  llvm/test/Transforms/WholeProgramDevirt/import.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  

[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2019-12-29 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 235509.
tejohnson added a comment.

Implement suggested name change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71911/new/

https://reviews.llvm.org/D71911

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/GlobalObject.h
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/Metadata.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/lib/Transforms/IPO/GlobalSplit.cpp
  llvm/test/Assembler/thinlto-vtable-summary.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions.ll
  llvm/test/Transforms/GlobalDCE/vtable-rtti.ll

Index: llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
===
--- llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
+++ llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
@@ -39,9 +39,10 @@
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!3, !4}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 2} ; translation-unit vcall visibility
 !3 = !{i32 1, !"LTOPostLink", i32 1}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
@@ -85,10 +85,11 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{}
+!llvm.module.flags = !{!5}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 0} ; public vcall visibility
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
+!5 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
@@ -85,7 +85,7 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{!5}
+!llvm.module.flags = !{!5, !6}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
@@ -93,3 +93,4 @@
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
 !5 = !{i32 1, !"LTOPostLink", i32 1}
+!6 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions.ll
@@ -48,8 +48,11 @@
   ret i32 %call1
 }
 
+!llvm.module.flags = !{!4}
+
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFivE.virtual"}
 !2 = !{i64 24, !"_ZTSM1AFivE.virtual"}
 !3 = !{i64 2}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
 !9 = !{}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
@@ -1,3 +1,5 @@
+; Tests that VFE is not performed when the Virtual Function Elim metadata set
+; to 0. This is the same as virtual-functions.ll otherwise.
 ; RUN: opt < %s -globaldce -S | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
@@ -11,14 +13,12 @@
 ; intrinsic. Function test_A makes a call to A::foo, but there is no call to
 ; A::bar anywhere, so A::bar can be deleted, and its vtable slot replaced with
 ; null.
+; However, with the metadata set to 0 we should not perform this VFE.
 
 %struct.A = type { i32 (...)** }
 
-; The pointer to A::bar in the vtable can be removed, because it will never be
-; loaded. We replace it with null to keep the layout the same. Because it is at
-; the 

[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2019-12-29 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 235510.
tejohnson added a comment.

Attempt to fix patch to not include parent revision changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71911/new/

https://reviews.llvm.org/D71911

Files:
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/thinlto-vtable-summary.ll

Index: llvm/test/Assembler/thinlto-vtable-summary.ll
===
--- llvm/test/Assembler/thinlto-vtable-summary.ll
+++ llvm/test/Assembler/thinlto-vtable-summary.ll
@@ -29,9 +29,9 @@
 
 ^0 = module: (path: "", hash: (0, 0, 0, 0, 0))
 ^1 = gv: (name: "_ZN1A1nEi") ; guid = 1621563287929432257
-^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
+^2 = gv: (name: "_ZTV1B", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^3, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^3, ^1 ; guid = 5283576821522790367
 ^3 = gv: (name: "_ZN1B1fEi") ; guid = 7162046368816414394
-^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
+^4 = gv: (name: "_ZTV1C", summaries: (variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^5, offset: 16), (virtFunc: ^1, offset: 24)), refs: (^1, ^5 ; guid = 1362402378846296
 ^5 = gv: (name: "_ZN1C1fEi") ; guid = 14876272565662207556
 ^6 = typeidCompatibleVTable: (name: "_ZTS1A", summary: ((offset: 16, ^2), (offset: 16, ^4))) ; guid = 7004155349499253778
 ^7 = typeidCompatibleVTable: (name: "_ZTS1B", summary: ((offset: 16, ^2))) ; guid = 6203814149063363976
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -2896,10 +2896,14 @@
 }
 
 void AssemblyWriter::printGlobalVarSummary(const GlobalVarSummary *GS) {
+  auto VTableFuncs = GS->vTableFuncs();
   Out << ", varFlags: (readonly: " << GS->VarFlags.MaybeReadOnly << ", "
-  << "writeonly: " << GS->VarFlags.MaybeWriteOnly << ")";
+  << "writeonly: " << GS->VarFlags.MaybeWriteOnly;
+  if (!VTableFuncs.empty())
+Out << ", "
+<< "vcall_visibility: " << GS->VarFlags.VCallVisibility;
+  Out << ")";
 
-  auto VTableFuncs = GS->vTableFuncs();
   if (!VTableFuncs.empty()) {
 Out << ", vTableFuncs: (";
 FieldSeparator FS;
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1028,7 +1028,8 @@
 }
 
 static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags) {
-  uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1);
+  uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
+  Flags.VCallVisibility << 2;
   return RawFlags;
 }
 
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -985,8 +985,9 @@
 
 // Decode the flags for GlobalVariable in the summary
 static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags) {
-  return GlobalVarSummary::GVarFlags((RawFlags & 0x1) ? true : false,
- (RawFlags & 0x2) ? true : false);
+  return GlobalVarSummary::GVarFlags(
+  (RawFlags & 0x1) ? true : false, (RawFlags & 0x2) ? true : false,
+  (GlobalObject::VCallVisibility)(RawFlags >> 2));
 }
 
 static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val) {
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -421,6 +421,7 @@
   kw_sizeM1,
   kw_bitMask,
   kw_inlineBits,
+  kw_vcall_visibility,
   kw_wpdResolutions,
   

[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2019-12-27 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D71907#1797218 , @evgeny777 wrote:

> Looks good at first sight. Do you have linker patch for me to try this out?


The linker changes are in D71913 . This one 
should be a noop by itself (other than just getting the additional metadata). 
You need all three (this one, D71911  and 
D71913 ) to implement the RFC.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71907/new/

https://reviews.llvm.org/D71907



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


[PATCH] D70765: LTOVisibility.rst: fix up syntax in example

2020-01-06 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D70765#1802564 , @dankamongmen 
wrote:

> I hate to bother anyone, but can this go ahead and get merged? :) thanks


Typically the author commits the patch, unless they don't have commit access 
and request the reviewer to commit for them, but I don't see a request for that 
here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70765/new/

https://reviews.llvm.org/D70765



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


[PATCH] D61634: [clang/llvm] Allow efficient implementation of libc's memory functions in C/C++

2020-01-07 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D61634#1515176 , @tejohnson wrote:

> In D61634#1512020 , @gchatelet wrote:
>
> > AFAIU here is a coarse plan of what needs to happen
>


I've listed below what I believe is the status:

>> 
>> 
>> 1. Add a `no-builtin` clang function attribute that has the same semantic as 
>> the `no-builtin` cmd line argument 
>> 

Done (D68028  committed at bd8791610948).

>> 2. Propagate it to the IR.
>>   - In the light of recent discussions and as @theraven suggested it seems 
>> more appropriate to encode them as individual IR attributes (e.g. 
>> `"no-builtin-memcpy"`, `"no-builtin-sqrt"`, etc..)

Done (also in D68028  committed at 
bd8791610948).
Additionally the -fno-builtin* options were translated to the IR attributes in 
D71193  (committed at 0508c994f0b1 
).

>> 3. Propagate/merge the `no-builtin` IR attribute for LTO by "updating 
>> `AttributeFuncs::areInlineCompatible` and/or 
>> `AttributeFuncs::mergeAttributesForInlining` and adding a new MergeRule in 
>> `include/llvm/IR/Attributes.td` and writing a function like 
>> `adjustCallerStackProbeSize`."
> 
> This one isn't about LTO, but rather the inliner. You could have different 
> functions in the same module even without LTO that have incompatible 
> no-builtin attributes. There isn't any propagation required for LTO.

Not done yet - I can work on this.

> 
> 
>> 4. Get inspiration from `TargetTransformInfo` to get `TargetLibraryInfo` on 
>> a per function basis for all passes and respect the IR attribute.

Done (D67923  was the last patch in the series 
to enable this, committed at 878ab6df033d 
).

I'm not quite sure where D71710  
([instrinsics] Add @llvm.memcpy.inline instrinsics) fits in to the above list.

Anything else missing?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61634/new/

https://reviews.llvm.org/D61634



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


[PATCH] D75655: [Docs] Document -lto-whole-program-visibility

2020-03-11 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75655/new/

https://reviews.llvm.org/D75655



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-08 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Needs testing of the inline handling, and of LTO linking IR with different 
attributes (which is going to hit your assert, see below).




Comment at: clang/lib/CodeGen/CGCall.cpp:1987
 
+  // Attach "vect-lib" attribute to function based on '-fveclib' setting.
+  addVectLibAttributes(FuncAttrs, getCodeGenOpts());

Nit: why not "vec-lib" or just "veclib", to match the option?



Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:47
 /// depends on the triple. So users typically interact with the \c
 /// TargetLibraryInfo wrapper below.
 class TargetLibraryInfoImpl {

Key comment about handling of TLII vs TLI. The former is computed once per 
module by the analysis (which is going to be the combined module in the case of 
LTO), the latter is the per-function data structure.



Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:91
+  /// Vector library available for vectorization.
+  VectorLibrary VectLibrary = NoLibrary;
 

To avoid building and storing the VectorDescs and ScalarDescs for every 
function in the TLI, what I would do is keep 3 sets of VectorDescs/ScalarDescs 
on the TLII object (one set per possible veclib, built once per module during 
construction of the TLII), then move the new VectorLibrary member to the TLI 
and set it there per function based on the attribute, and use it to select 
which pair of VectorDescs/ScalarDescs is queried.



Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:275
 if (!AllowCallerSuperset)
-  return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
+  return Impl->VectLibrary == CalleeTLI.Impl->VectLibrary &&
+ OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;

I don't think this will do anything currently since the TLII is built once per 
module by the analysis. You'll hit your assert about incompatibility below 
first, see comment there.



Comment at: llvm/lib/Analysis/TargetLibraryInfo.cpp:1549
+assert(VectLibrary == VecLib && 
+   "Conflicting VectorLibrary detected");
+return;

You'll certainly hit this assert if you try LTO linking two .ll files built 
with different -fveclib options, because the TLII is built once per module by 
the analysis.



Comment at: llvm/lib/Analysis/TargetLibraryInfo.cpp:1631
+  if (!VectLibName.empty())
+BaselineInfoImpl->addVectorizableFunctionsFromVecLib(VectLibName);
+

This is going to override the baseline TLI veclib with whatever is the latest 
function we build a TLI for (and you'll hit the assert as noted earlier if they 
conflict).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77632/new/

https://reviews.llvm.org/D77632



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-09 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Great, thanks! A few minor comments below. Looks like it needs a clang-format 
too.




Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:272
+else
+  VectLibrary = Impl.ClVectorLibrary;
+

Suggest moving the implementation of this constructor to the .cpp file, in 
which case you can just set VectLibrary directly from ClVectorLibrary there and 
remove the member on the Impl object.



Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:318
bool AllowCallerSuperset) const {
 if (!AllowCallerSuperset)
+  return VectLibrary == CalleeTLI.VectLibrary &&

This is set via a flag called "inline-caller-superset-nobuiltin". Suggest 
changing the name to something like "inline-caller-superset-tli" to reflect new 
larger scope. Also add a check with that option to your new inline test case.



Comment at: llvm/lib/Analysis/TargetLibraryInfo.cpp:577
   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
-  VectorDescs = TLI.VectorDescs;
-  ScalarDescs = TLI.ScalarDescs;
+  for (unsigned i = 0; i < sizeof(TLI.VecLibDescs) / 
sizeof(TLI.VecLibDescs[0]);
+   i++)

Why not just have "i < NumVecLibs"?



Comment at: llvm/lib/Analysis/TargetLibraryInfo.cpp:590
 AvailableArray);
-  VectorDescs = TLI.VectorDescs;
-  ScalarDescs = TLI.ScalarDescs;
+  for (unsigned i = 0; i < sizeof(TLI.VecLibDescs) / 
sizeof(TLI.VecLibDescs[0]);
+   i++)

ditto



Comment at: llvm/lib/Analysis/TargetLibraryInfo.cpp:1574
+  case NumVecLibs:
 break;
   }

Should these two be llvm_unreachable?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77632/new/

https://reviews.llvm.org/D77632



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-09 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

lgtm. I think one check is missing in the test, see comment below.




Comment at: llvm/test/Transforms/Inline/veclib-compat.ll:28
+  %rslt = call i32 @callee_massv(i8 123)
+; SUPERSET: call i32 @callee_massv
+  %tmp1 = call i32 @callee_nolibrary(i8 123)

I think NOSUPERSET should also check that there is still a call here. You can 
probably replace some of the duplicated checks with COMMON in this function too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77632/new/

https://reviews.llvm.org/D77632



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-09 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:272
+else
+  VectLibrary = Impl.ClVectorLibrary;
+

wenlei wrote:
> tejohnson wrote:
> > Suggest moving the implementation of this constructor to the .cpp file, in 
> > which case you can just set VectLibrary directly from ClVectorLibrary there 
> > and remove the member on the Impl object.
> There're utilities that use `TargetLibraryInfo`, but don't link with 
> `TargetLibraryInfo.o`. And looking at `TargetLibraryInfo`, all of the 
> functions are in this header, so I assumed it's intentional to keep this type 
> self-contained in this header, as it's public API, which is why I add 
> `ClVectorLibrary` to Impl to pass it back to `TargetLibraryInfo`. For 
> `TargetLibraryInfoImpl`, it's ok to have the implementation outside of the 
> header. I can give it a try if keeping the class implementation/definition 
> self-contained in the header isn't important.  
I don't think there should be anything using TLI without linking with 
libAnalysis, which contains TargetLibraryInfo.o. I don't think it should be 
important to keep the implementation in the header, any more so than for other 
headers in the Analysis library.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77632/new/

https://reviews.llvm.org/D77632



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D77632#1974363 , @wenlei wrote:

> In D77632#1974015 , @nikic wrote:
>
> > This change causes a ~0.5% compile-time regressions: 
> > http://llvm-compile-time-tracker.com/compare.php?from=5b18b6e9a84d985c0a907009fb71de7c1943bc88=60c642e74be6af86906d9f3d982728be7bd4329f=instructions
> >  This is quite a lot as these things go, so it would be great if you could 
> > double check if there's any optimization potential here. In particular I'm 
> > wondering why this affects normal builds so much, even though they 
> > (presumably?) don't use any veclib at all.
>
>
> Thanks for the heads-up. This is surprising but there is a change even when 
> veclib is not used - in order to allow each function to use different veclib 
> without duplicating the work of populating vector function list for each 
> function, we now always pre-populate vector function list for three supported 
> vector libraries for each module. However 0.5% compile-time for that work 
> given it's per-module is not expected. I suspect we may be passing/copying 
> TLII around more than we anticipated (now we always have more stuff to copy). 
> I will take a look. We could also turn this into a lazy initialization - only 
> populate the needed list for module level TLII when it's first queried by a 
> function level TLI.


Hmm, yeah that is surprising, because the TLII should be built once per module 
per TLI analysis, which is never invalidated. We've gone from populating one 
set of vec libs to 3, I wouldn't have thought that was particularly expensive, 
so it would be good to see what is going on here and confirm we are only 
building this once as expected.

Looking at the compile time data at that link, interestingly the "instructions" 
metric increased, but not wall time or cycles or task clock - they were all 
neutral.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77632/new/

https://reviews.llvm.org/D77632



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-13 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D77632#1976308 , @mehdi_amini wrote:

> In D77632#1976231 , @wenlei wrote:
>
> > And agree with @tejohnson, if the openness is a feature, it should be 
> > covered in tests, otherwise it can feel somewhat like a loophole and prone 
> > to breakage
>
>
> The thing is that LLVM does not have much C++ unittests in general, so most 
> of the "features" like this one that LLVM offers as a library are just an 
> artifact of being "designed as a library" and being mindful about the 
> layering.
>  From this point of view this patch is changing the design of a component 
> that was modular/pluggable into a closed system.


The interfaces being relied on were in the underlying Impl class, I think if 
that is expected to be pluggable and stable it really needs unit testing to 
reflect that usage.

> I'm perfectly fine with trying to add a unit-test, I just don't know yet 
> where it would fit in the LLVM testing though.

Presumably the testing should be in 
llvm/unittests/Analysis/TargetLibraryInfoTest.cpp, which already exists but 
only tests the LibFuncs (builtins) interfaces.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77632/new/

https://reviews.llvm.org/D77632



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


[PATCH] D77989: Allow disabling of vectorization using internal options

2020-04-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 257562.
tejohnson added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77989/new/

https://reviews.llvm.org/D77989

Files:
  clang/test/CodeGen/thinlto-loop-vectorize-pm.c
  clang/test/CodeGen/thinlto-slp-vectorize-pm.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
  llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/test/Transforms/SLPVectorizer/X86/opt.ll
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -180,11 +180,6 @@
  cl::desc("Disable loop unrolling in all relevant passes"),
  cl::init(false));
 
-static cl::opt
-DisableSLPVectorization("disable-slp-vectorization",
-cl::desc("Disable the slp vectorization pass"),
-cl::init(false));
-
 static cl::opt EmitSummaryIndex("module-summary",
   cl::desc("Emit module summary index"),
   cl::init(false));
@@ -406,18 +401,9 @@
   Builder.DisableUnrollLoops = (DisableLoopUnrolling.getNumOccurrences() > 0) ?
DisableLoopUnrolling : OptLevel == 0;
 
-  // Check if vectorization is explicitly disabled via -vectorize-loops=false.
-  // The flag enables vectorization in the LoopVectorize pass, it is on by
-  // default, and if it was disabled, leave it disabled here.
-  // Another flag that exists: -loop-vectorize, controls adding the pass to the
-  // pass manager. If set, the pass is added, and there is no additional check
-  // here for it.
-  if (Builder.LoopVectorize)
-Builder.LoopVectorize = OptLevel > 1 && SizeLevel < 2;
-
-  // When #pragma vectorize is on for SLP, do the same as above
-  Builder.SLPVectorize =
-  DisableSLPVectorization ? false : OptLevel > 1 && SizeLevel < 2;
+  Builder.LoopVectorize = OptLevel > 1 && SizeLevel < 2;
+
+  Builder.SLPVectorize = OptLevel > 1 && SizeLevel < 2;
 
   if (TM)
 TM->adjustPassManager(Builder);
Index: llvm/test/Transforms/SLPVectorizer/X86/opt.ll
===
--- llvm/test/Transforms/SLPVectorizer/X86/opt.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/opt.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -O3 -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s --check-prefix=SLP
-; RUN: opt < %s -O3 -disable-slp-vectorization -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s --check-prefix=NOSLP
+; RUN: opt < %s -O3 -vectorize-slp=false -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s --check-prefix=NOSLP
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.8.0"
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -108,9 +108,8 @@
 
 STATISTIC(NumVectorInstructions, "Number of vector instructions generated");
 
-cl::opt
-llvm::RunSLPVectorization("vectorize-slp", cl::init(false), cl::Hidden,
-  cl::desc("Run the SLP vectorization passes"));
+cl::opt RunSLPVectorization("vectorize-slp", cl::init(true), cl::Hidden,
+  cl::desc("Run the SLP vectorization passes"));
 
 static cl::opt
 SLPCostThreshold("slp-threshold", cl::init(0), cl::Hidden,
@@ -5645,6 +5644,8 @@
 LoopInfo *LI_, DominatorTree *DT_,
 AssumptionCache *AC_, DemandedBits *DB_,
 OptimizationRemarkEmitter *ORE_) {
+  if (!RunSLPVectorization)
+return false;
   SE = SE_;
   TTI = TTI_;
   TLI = TLI_;
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1590,9 +1590,8 @@
 
   explicit LoopVectorize(bool InterleaveOnlyWhenForced = false,
  bool VectorizeOnlyWhenForced = false)
-  : FunctionPass(ID) {
-Impl.InterleaveOnlyWhenForced = InterleaveOnlyWhenForced;
-Impl.VectorizeOnlyWhenForced = VectorizeOnlyWhenForced;
+  : FunctionPass(ID),
+Impl({InterleaveOnlyWhenForced, 

[PATCH] D77989: Allow disabling of vectorization using internal options

2020-04-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked an inline comment as done.
tejohnson added inline comments.



Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7618-7621
+: InterleaveOnlyWhenForced(Opts.InterleaveOnlyWhenForced |
+   !EnableLoopInterleaving),
+  VectorizeOnlyWhenForced(Opts.VectorizeOnlyWhenForced |
+  !EnableLoopVectorization) {}

wmi wrote:
> Use boolean operator || instead of bitwise operator?
Good catch, fixed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77989/new/

https://reviews.llvm.org/D77989



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


<    1   2   3   4   5   6   7   >