[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-14 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin approved this pull request.


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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-14 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

> I think my patch is a significant improvement, both in terms of simplicity 
> and reliability of the codegen for symmetric transfer, and would like to move 
> forward. @ChuanqiXu9 @mtrofin do you have any further comments?

Nothing on my side, lgtm for my narrow concern. Please wait for @ChuanqiXu9 's 
lgtm tho. 

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


[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-12 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin approved this pull request.

LGTM for the `ctx_profile` part.

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-03 Thread Mircea Trofin via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

mtrofin wrote:

> That still sounds like the remark would not target the compiler user, but the 
> developer of the compiler tool -- and that's not really what optimization 
> remarks are for.

Not sure if that's the case anymore, they do have a yaml outputter.

But that's besides the point. I think I can see this your way: in our running 
example, if I worked on coverage, and knew to write the ORE post-processor, I 
would also know to fix my coverage instrumenter to recognize not to place 
instructions in the wrong place. (I realize there are other cases where passes 
are OK to stay agnostic despite losing instructions here, but in the coverage 
scenario that's not the case any way you look at it). The main thing is how to 
figure I may have a problem, and really the fix there is "integration testing", 
really.

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-02 Thread Mircea Trofin via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

mtrofin wrote:

For a fictitious example using some concrete actors: they could author a 
coverage analysis tool that would know to look for that and not misreport (say) 
66% coverage because one of the edges was never traversed (because it never 
really existed)?

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-05-02 Thread Mircea Trofin via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

mtrofin wrote:

In your example, if they derive some result based on the initial set of 
instrumentations they insert, they may produce reports that say "incomplete 
coverage" (for example). Some level of knowledge ends up being passed down to 
someone - maybe the user, maybe the analyzer of the data.

But I get the idea that maybe the domain is OK with loss of instructions, so 
the assert could be annoying. Dunno, only saw the example where it wasn't.

How about an ORE? The output could technically be usable by a tool in a 
fictitious coverage case, it offers more focused observability than dumping IR 
before/after in a debugging case, and it serves as self-documentation in the 
pass itself that "ya, we're dropping stuff here. It's intentional". The ORE 
wouldn't need to be too complex, maybe if we detect non-debug (and maybe also 
exclude lifetime) instructions, ORE out. WDYT?

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-04-30 Thread Mircea Trofin via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

mtrofin wrote:

> But in that case the problem was kind of the opposite, right? Instructions 
> between the resume and suspend blocked the musttail optimization. The problem 
> was not whether those instructions would have been executed or not, but that 
> they were inserted in a place where it wasn't allowed due to special 
> constraints on this intrinsic.
> The idea with my patch is to eliminate that problem by not having special 
> restrictions about instructions after the intrinsic, they just won't be 
> executed because control continues in the resumed function and doesn't come 
> back.

I think I see where the disconnect comes from. You're referring to the desired 
outcome for coro: tailcalls being ensured. I agree with that, but I'm concerned 
with maintenance: suppose some other pass does what PGOInstrument did, in the 
future. Just like with coro, the potential for a undesired interaction between 
coro and their pass isn't known to them. How easy would it be to discover they 
made incorrect assumptions in their pass, diagnose and fix?

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-04-29 Thread Mircea Trofin via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

mtrofin wrote:

Sorry for insisting on this, it's maybe because I got "bitten" before (with the 
suspend), but what other examples do we have where, silently, instructions 
don't get executed after a call?

Also, maybe this would become moot if we address 
https://discourse.llvm.org/t/coro-pre-split-handling-of-the-suspend-edge/75043 
like @jyknight suggested (i.e. not even have the misleading edge)?

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-04-29 Thread Mircea Trofin via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

mtrofin wrote:

It's not about legality, it's about the fact they wouldn't be executed being a 
symptom of a bug - e.g. earlier pass (like coverage) believing there is 
something to cover while there isn't. We could at minimum have some "under 
build with asserts" behavior that (except for trivial cases like debug/lifetime 
instructions) says something. 

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-04-25 Thread Mircea Trofin via cfe-commits


@@ -1056,6 +1083,25 @@ void CoroCloner::create() {
   // Set up the new entry block.
   replaceEntryBlock();
 
+  // Turn symmetric transfers into musttail calls.
+  for (CallInst *ResumeCall : Shape.SymmetricTransfers) {
+ResumeCall = cast(VMap[ResumeCall]);
+ResumeCall->setCallingConv(NewF->getCallingConv());
+if (TTI.supportsTailCallFor(ResumeCall)) {
+  // FIXME: Could we support symmetric transfer effectively without
+  // musttail?
+  ResumeCall->setTailCallKind(CallInst::TCK_MustTail);
+}
+
+// Put a 'ret void' after the call, and split any remaining instructions to

mtrofin wrote:

if there are remaining instructions, this will silently elide them. I realize 
that there shouldn't be remaining instructions, but we could detect bugs like 
the PGO instrumentation + coro one (PR #71263) if that was asserted or WARNed 
or something more visible.

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


[clang] [buildbot] VE builders: disable ctx_profile (PR #89969)

2024-04-24 Thread Mircea Trofin via cfe-commits

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


[clang] [buildbot] VE builders: disable ctx_profile (PR #89969)

2024-04-24 Thread Mircea Trofin via cfe-commits

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


[clang] [buildbot] VE builders: disable ctx_profile (PR #89969)

2024-04-24 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin created 
https://github.com/llvm/llvm-project/pull/89969

Just like e.g. memprof, it is not supported.

>From 29ac1a1e7562bb6cd324437013747f16fa2d52f3 Mon Sep 17 00:00:00 2001
From: Mircea Trofin 
Date: Wed, 24 Apr 2024 11:24:21 -0700
Subject: [PATCH] [buildbot] VE builders: disable ctx_profile

Just like e.g. memprof, it is not supported.
---
 clang/cmake/caches/VectorEngine.cmake | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/cmake/caches/VectorEngine.cmake 
b/clang/cmake/caches/VectorEngine.cmake
index e3976f3206db53..2f968a21cc407e 100644
--- a/clang/cmake/caches/VectorEngine.cmake
+++ b/clang/cmake/caches/VectorEngine.cmake
@@ -40,6 +40,7 @@ set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_CRT 
OFF CACHE BOOL "")
 set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_SANITIZERS OFF CACHE 
BOOL "")
 set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
 set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_LIBFUZZER OFF CACHE 
BOOL "")
+set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_CTX_PROFILE OFF CACHE 
BOOL "")
 set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL 
"")
 set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_MEMPROF OFF CACHE BOOL 
"")
 set(RUNTIMES_x86_64-unknown-linux-gnu_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
@@ -52,6 +53,7 @@ 
set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL ""
 set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
 set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL 
"")
 set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_PROFILE ON CACHE BOOL "")
+set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_CTX_PROFILE OFF CACHE BOOL 
"")
 set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_MEMPROF OFF CACHE BOOL "")
 set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
 set(RUNTIMES_ve-unknown-linux-gnu_COMPILER_RT_BUILD_GWP_ASAN OFF CACHE BOOL "")

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


[clang] [llvm] [coro] Lower `llvm.coro.await.suspend.handle` to resume with tail call (PR #89751)

2024-04-23 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

Does this address 
https://discourse.llvm.org/t/coro-pre-split-handling-of-the-suspend-edge/75043? 
Could you add a note there in that direction - a few folks were looking at 
going at the direction @jyknight was suggesting there, and it'd be good to have 
closure on the topic.

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


[clang] [clang] Add flag to experiment with cold function attributes (PR #89298)

2024-04-18 Thread Mircea Trofin via cfe-commits


@@ -768,42 +783,41 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
: 
CodeGenOpts.InstrProfileOutput,
 "", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
-PGOOptions::NoCSAction, PGOOptions::ColdFuncOpt::Default,
+PGOOptions::NoCSAction, ClPGOColdFuncAttr,
 CodeGenOpts.DebugInfoForProfiling,
 /*PseudoProbeForProfiling=*/false, CodeGenOpts.AtomicProfileUpdate);
   else if (CodeGenOpts.hasProfileIRUse()) {
 // -fprofile-use.
 auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
 : PGOOptions::NoCSAction;
-PGOOpt = PGOOptions(
-CodeGenOpts.ProfileInstrumentUsePath, "",
-CodeGenOpts.ProfileRemappingFile, CodeGenOpts.MemoryProfileUsePath, 
VFS,
-PGOOptions::IRUse, CSAction, PGOOptions::ColdFuncOpt::Default,
-CodeGenOpts.DebugInfoForProfiling);
+PGOOpt = PGOOptions(CodeGenOpts.ProfileInstrumentUsePath, "",

mtrofin wrote:

could you do a clang-format, commit and rebase? This and the stuff at line 812 
seems mostly that. Or does adding the `ClPGOCouldFuncAttr` mess up formatting?

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


[clang] [clang] Add flag to experiment with cold function attributes (PR #89298)

2024-04-18 Thread Mircea Trofin via cfe-commits

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


[clang] [clang] Add flag to experiment with cold function attributes (PR #89298)

2024-04-18 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin approved this pull request.


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


[llvm] [lld] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-25 Thread Mircea Trofin via cfe-commits


@@ -858,62 +899,64 @@ struct BBAddrMap {
 bool hasIndirectBranch() const { return MD.HasIndirectBranch; }
   };
 
-  BBAddrMap(uint64_t Addr, std::vector BBEntries)
-  : Addr(Addr), BBEntries(std::move(BBEntries)) {}
+  // Struct representing the BBAddrMap information for a contiguous range of
+  // basic blocks (a function or a basic block section).
+  struct BBRangeEntry {
+uint64_t BaseAddress;   // Base address of the range.
+std::vector BBEntries; // Basic block entries for this range.
+
+// Equality operator for unit testing.
+bool operator==(const BBRangeEntry ) const {
+  return BaseAddress == Other.BaseAddress &&
+ std::equal(BBEntries.begin(), BBEntries.end(),
+Other.BBEntries.begin());
+}
+  };
 
-  // Returns the address of the corresponding function.
-  uint64_t getFunctionAddress() const { return Addr; }
+  // All ranges for this function. The first range always corresponds to the
+  // function entry.
+  std::vector BBRanges;
 
-  // Returns the basic block entries for this function.
-  const std::vector () const { return BBEntries; }
+  // Returns the function address associated with this BBAddrMap, which is
+  // stored as the `BaseAddress` of its first BBRangeEntry. Returns 0 if
+  // BBRanges is empty.
+  uint64_t getFunctionAddress() const {

mtrofin wrote:

nit: how about return `std::optional`? makes the user check that the 
result is actually a value ("0" can be used in subsequent numerical operations, 
`std::nullopt` can't)

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


[llvm] [clang] [lld] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-25 Thread Mircea Trofin via cfe-commits


@@ -858,62 +899,64 @@ struct BBAddrMap {
 bool hasIndirectBranch() const { return MD.HasIndirectBranch; }
   };
 
-  BBAddrMap(uint64_t Addr, std::vector BBEntries)
-  : Addr(Addr), BBEntries(std::move(BBEntries)) {}
+  // Struct representing the BBAddrMap information for a contiguous range of
+  // basic blocks (a function or a basic block section).
+  struct BBRangeEntry {
+uint64_t BaseAddress;   // Base address of the range.

mtrofin wrote:

(paranoia) could you initialize BaseAddress at decl? easier to maintain and 
avoid uninitialized error issues (sure, they can also be compiler-detected, but 
3 extra characters don't hurt either)

same for the fields above

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


[lld] [llvm] [clang] Embed the command line arguments during LTO (PR #79390)

2024-01-25 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

> > I haven't checked closely yet, but it seems like you need to add tests.
> 
> Could you provide some guidance on what kind of tests to add and how to 
> actually run them locally? First I wanted to get the builtkite job to be 
> green, but it seems to be failing on some unrelated test where LLD cannot be 
> found...


You'd want to add tests under `lld/test[COFF|ELF|MachO|MinGW|wasm]`

To run tests locally - assuming you're in the root of the repo:

```
mkdir build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld" 
-DLLVM_ENABLE_ASSERTIONS=ON ../llvm
ninja check-all
```

Main pieces there are:
* the list under LLVM_ENABLE_PROJECTS - you want to make sure regression tests 
for thinlto + embed bitcode pass (e.g. 
`clang/test/CodeGen/thinlto_embed_bitcode.ll`), and those are under clang; and 
lld is self-explanatory.
* `ninja check-all`

More info 
[here](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm)

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-19 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin approved this pull request.

Thanks for adding license info!

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

> > Would it be also possible to remove the dependency on 
> > [Abseil](https://github.com/abseil/abseil-py)? None of the existing scripts 
> > in LLVM use it and I don't think we should be introducing this dependency. 
> > It looks like Abseil is only used for flag parsing, logging and testing; 
> > those should be straightforward to replace with standard libraries like 
> > `argparse`, `logging` or `unittest`.
> 
> Yes. My plan was to remove the dependency on abseil as well. My plan was to 
> get this landed with all the infrastructure setup and the code basically just 
> directly copied and then remove the abseil dependency in a follow-up patch so 
> that the different pieces get reviewed appropriately.

Ah, if you can drop the abseil dependency, the dependency problem for tests 
goes away. May be worth doing the abseil dropping bit in this patch, too?

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Mircea Trofin via cfe-commits


@@ -0,0 +1,6 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

mtrofin wrote:

Ack - thanks for clarifying the directory structure; looking around, there 
doesn't seem to be much of a precedent either; so... how about 
`llvm/utils/mlgo-utils/mlgo`? 

(tests moving to lit sounds perfect)

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-16 Thread Mircea Trofin via cfe-commits


@@ -0,0 +1,6 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

mtrofin wrote:

why do we need `mlgo/mlgo` - could we just do `mlgo/corpus` and 
`mlgo/tests/corpus` - this leaves it open to add later non-corpus related 
things if needed.

Shouldn't the tests go under `llvm/test/tools` like the other utils? There 
should be a way to disable them if python version is under 3.8.

Also the `lit.local.cfg` should probably go through the dependency list of the 
package and skip the tests if the packages aren't available. I assume we can do 
that off `pyproject.toml`

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-16 Thread Mircea Trofin via cfe-commits


@@ -0,0 +1,12 @@
+# MLGO Python Library
+
+This folder contains the MLGO python library. This library consists of telling

mtrofin wrote:

I wouldn't call it "the" MLGO python library, rather it's utilities for MLGO. 
Also please read the rest of the para (esp. first line)



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


[clang-tools-extra] [llvm] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-16 Thread Mircea Trofin via cfe-commits

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


[llvm] [clang-tools-extra] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-16 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin commented:

I'm assuming the files were drop-in copied from google/ml-compiler-opt, so no 
need to comment there; also that we would subsequently delete them from there 
and depend on this package. 

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


[llvm] [clang] [NFC][InstrProf] Refactor InstrProfiling lowering pass (PR #74970)

2023-12-10 Thread Mircea Trofin via cfe-commits

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


[clang] [llvm] [NFC][InstrProf] Refactor InstrProfiling lowering pass (PR #74970)

2023-12-10 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin updated 
https://github.com/llvm/llvm-project/pull/74970

>From 90893a3b3f71524947cb041b2a25d0a02a8956d7 Mon Sep 17 00:00:00 2001
From: Mircea Trofin 
Date: Sat, 9 Dec 2023 21:24:35 -0800
Subject: [PATCH 1/2] [NFC][InstrProf] Refactor InstrProfiling lowering pass

Akin other passes - refactored the name to `InstrProfilingLoweringPass`
to better communicate what it does, and split the pass part and the
transformation part to avoid needing to initialize object state during
`::run`.
---
 clang/lib/CodeGen/BackendUtil.cpp |   2 +-
 .../include/llvm/Transforms/Instrumentation.h |   3 +-
 .../Instrumentation/InstrProfiling.h  |  45 ---
 llvm/lib/Passes/PassBuilderPipelines.cpp  |   4 +-
 llvm/lib/Passes/PassRegistry.def  |   2 +-
 .../Instrumentation/InstrProfiling.cpp| 126 --
 .../Instrumentation/Instrumentation.cpp   |   2 +-
 7 files changed, 94 insertions(+), 90 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 8c666e2cb463c6..77455c075cab0d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -982,7 +982,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 getInstrProfOptions(CodeGenOpts, LangOpts))
   PB.registerPipelineStartEPCallback(
   [Options](ModulePassManager , OptimizationLevel Level) {
-MPM.addPass(InstrProfiling(*Options, false));
+MPM.addPass(InstrProfilingLoweringPass(*Options, false));
   });
 
 // TODO: Consider passing the MemoryProfileOutput to the pass builder via
diff --git a/llvm/include/llvm/Transforms/Instrumentation.h 
b/llvm/include/llvm/Transforms/Instrumentation.h
index bb1a0d446aa2ab..ea97ab2562a5b0 100644
--- a/llvm/include/llvm/Transforms/Instrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation.h
@@ -52,7 +52,8 @@ Comdat *getOrCreateFunctionComdat(Function , Triple );
 // Place global in a large section for x86-64 ELF binaries to mitigate
 // relocation overflow pressure. This can be be used for metadata globals that
 // aren't directly accessed by code, which has no performance impact.
-void setGlobalVariableLargeSection(Triple , GlobalVariable );
+void setGlobalVariableLargeSection(const Triple ,
+   GlobalVariable );
 
 // Insert GCOV profiling instrumentation
 struct GCOVOptions {
diff --git a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h 
b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
index c106e1651e8045..0d778288d78455 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
@@ -31,31 +31,45 @@ using LoadStorePair = std::pair;
 /// Instrumentation based profiling lowering pass. This pass lowers
 /// the profile instrumented code generated by FE or the IR based
 /// instrumentation pass.
-class InstrProfiling : public PassInfoMixin {
+class InstrProfilingLoweringPass
+: public PassInfoMixin {
+  const InstrProfOptions Options;
+  // Is this lowering for the context-sensitive instrumentation.
+  const bool IsCS;
+
 public:
-  InstrProfiling() : IsCS(false) {}
-  InstrProfiling(const InstrProfOptions , bool IsCS = false)
+  InstrProfilingLoweringPass() : IsCS(false) {}
+  InstrProfilingLoweringPass(const InstrProfOptions , bool IsCS = 
false)
   : Options(Options), IsCS(IsCS) {}
 
   PreservedAnalyses run(Module , ModuleAnalysisManager );
-  bool run(Module ,
-   std::function GetTLI);
+};
+class InstrProfiling final {
+public:
+  InstrProfiling(Module , const InstrProfOptions ,
+ std::function GetTLI,
+ bool IsCS)
+  : M(M), Options(Options), TT(Triple(M.getTargetTriple())), IsCS(IsCS),
+GetTLI(GetTLI) {}
+
+  bool lower();
 
 private:
-  InstrProfOptions Options;
-  Module *M;
-  Triple TT;
+  Module 
+  const InstrProfOptions Options;
+  const Triple TT;
+  // Is this lowering for the context-sensitive instrumentation.
+  const bool IsCS;
+
   std::function GetTLI;
   struct PerFunctionProfileData {
-uint32_t NumValueSites[IPVK_Last + 1];
+uint32_t NumValueSites[IPVK_Last + 1] = {};
 GlobalVariable *RegionCounters = nullptr;
 GlobalVariable *DataVar = nullptr;
 GlobalVariable *RegionBitmaps = nullptr;
 uint32_t NumBitmapBytes = 0;
 
-PerFunctionProfileData() {
-  memset(NumValueSites, 0, sizeof(uint32_t) * (IPVK_Last + 1));
-}
+PerFunctionProfileData() = default;
   };
   DenseMap ProfileDataMap;
   /// If runtime relocation is enabled, this maps functions to the load
@@ -64,11 +78,8 @@ class InstrProfiling : public PassInfoMixin {
   std::vector CompilerUsedVars;
   std::vector UsedVars;
   std::vector ReferencedNames;
-  GlobalVariable *NamesVar;
-  size_t NamesSize;
-
-  // Is this lowering for the context-sensitive instrumentation.
-  bool IsCS;
+  GlobalVariable 

[clang] [llvm] [NFC][InstrProf] Refactor InstrProfiling lowering pass (PR #74970)

2023-12-10 Thread Mircea Trofin via cfe-commits


@@ -31,31 +31,45 @@ using LoadStorePair = std::pair;
 /// Instrumentation based profiling lowering pass. This pass lowers
 /// the profile instrumented code generated by FE or the IR based
 /// instrumentation pass.
-class InstrProfiling : public PassInfoMixin {
+class InstrProfilingLoweringPass
+: public PassInfoMixin {
+  const InstrProfOptions Options;
+  // Is this lowering for the context-sensitive instrumentation.
+  const bool IsCS;
+
 public:
-  InstrProfiling() : IsCS(false) {}
-  InstrProfiling(const InstrProfOptions , bool IsCS = false)
+  InstrProfilingLoweringPass() : IsCS(false) {}
+  InstrProfilingLoweringPass(const InstrProfOptions , bool IsCS = 
false)
   : Options(Options), IsCS(IsCS) {}
 
   PreservedAnalyses run(Module , ModuleAnalysisManager );
-  bool run(Module ,
-   std::function GetTLI);
+};
+class InstrProfiling final {

mtrofin wrote:

Done, will move it to the cpp next.

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


[clang] [llvm] [NFC][InstrProf] Refactor InstrProfiling lowering pass (PR #74970)

2023-12-09 Thread Mircea Trofin via cfe-commits

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


[llvm] [clang] [NFC][InstrProf] Refactor InstrProfiling lowering pass (PR #74970)

2023-12-09 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin created 
https://github.com/llvm/llvm-project/pull/74970

Akin other passes - refactored the name to `InstrProfilingLoweringPass` to 
better communicate what it does, and split the pass part and the transformation 
part to avoid needing to initialize object state during `::run`.

>From 90893a3b3f71524947cb041b2a25d0a02a8956d7 Mon Sep 17 00:00:00 2001
From: Mircea Trofin 
Date: Sat, 9 Dec 2023 21:24:35 -0800
Subject: [PATCH] [NFC][InstrProf] Refactor InstrProfiling lowering pass

Akin other passes - refactored the name to `InstrProfilingLoweringPass`
to better communicate what it does, and split the pass part and the
transformation part to avoid needing to initialize object state during
`::run`.
---
 clang/lib/CodeGen/BackendUtil.cpp |   2 +-
 .../include/llvm/Transforms/Instrumentation.h |   3 +-
 .../Instrumentation/InstrProfiling.h  |  45 ---
 llvm/lib/Passes/PassBuilderPipelines.cpp  |   4 +-
 llvm/lib/Passes/PassRegistry.def  |   2 +-
 .../Instrumentation/InstrProfiling.cpp| 126 --
 .../Instrumentation/Instrumentation.cpp   |   2 +-
 7 files changed, 94 insertions(+), 90 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 8c666e2cb463c6..77455c075cab0d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -982,7 +982,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 getInstrProfOptions(CodeGenOpts, LangOpts))
   PB.registerPipelineStartEPCallback(
   [Options](ModulePassManager , OptimizationLevel Level) {
-MPM.addPass(InstrProfiling(*Options, false));
+MPM.addPass(InstrProfilingLoweringPass(*Options, false));
   });
 
 // TODO: Consider passing the MemoryProfileOutput to the pass builder via
diff --git a/llvm/include/llvm/Transforms/Instrumentation.h 
b/llvm/include/llvm/Transforms/Instrumentation.h
index bb1a0d446aa2ab..ea97ab2562a5b0 100644
--- a/llvm/include/llvm/Transforms/Instrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation.h
@@ -52,7 +52,8 @@ Comdat *getOrCreateFunctionComdat(Function , Triple );
 // Place global in a large section for x86-64 ELF binaries to mitigate
 // relocation overflow pressure. This can be be used for metadata globals that
 // aren't directly accessed by code, which has no performance impact.
-void setGlobalVariableLargeSection(Triple , GlobalVariable );
+void setGlobalVariableLargeSection(const Triple ,
+   GlobalVariable );
 
 // Insert GCOV profiling instrumentation
 struct GCOVOptions {
diff --git a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h 
b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
index c106e1651e8045..0d778288d78455 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
@@ -31,31 +31,45 @@ using LoadStorePair = std::pair;
 /// Instrumentation based profiling lowering pass. This pass lowers
 /// the profile instrumented code generated by FE or the IR based
 /// instrumentation pass.
-class InstrProfiling : public PassInfoMixin {
+class InstrProfilingLoweringPass
+: public PassInfoMixin {
+  const InstrProfOptions Options;
+  // Is this lowering for the context-sensitive instrumentation.
+  const bool IsCS;
+
 public:
-  InstrProfiling() : IsCS(false) {}
-  InstrProfiling(const InstrProfOptions , bool IsCS = false)
+  InstrProfilingLoweringPass() : IsCS(false) {}
+  InstrProfilingLoweringPass(const InstrProfOptions , bool IsCS = 
false)
   : Options(Options), IsCS(IsCS) {}
 
   PreservedAnalyses run(Module , ModuleAnalysisManager );
-  bool run(Module ,
-   std::function GetTLI);
+};
+class InstrProfiling final {
+public:
+  InstrProfiling(Module , const InstrProfOptions ,
+ std::function GetTLI,
+ bool IsCS)
+  : M(M), Options(Options), TT(Triple(M.getTargetTriple())), IsCS(IsCS),
+GetTLI(GetTLI) {}
+
+  bool lower();
 
 private:
-  InstrProfOptions Options;
-  Module *M;
-  Triple TT;
+  Module 
+  const InstrProfOptions Options;
+  const Triple TT;
+  // Is this lowering for the context-sensitive instrumentation.
+  const bool IsCS;
+
   std::function GetTLI;
   struct PerFunctionProfileData {
-uint32_t NumValueSites[IPVK_Last + 1];
+uint32_t NumValueSites[IPVK_Last + 1] = {};
 GlobalVariable *RegionCounters = nullptr;
 GlobalVariable *DataVar = nullptr;
 GlobalVariable *RegionBitmaps = nullptr;
 uint32_t NumBitmapBytes = 0;
 
-PerFunctionProfileData() {
-  memset(NumValueSites, 0, sizeof(uint32_t) * (IPVK_Last + 1));
-}
+PerFunctionProfileData() = default;
   };
   DenseMap ProfileDataMap;
   /// If runtime relocation is enabled, this maps functions to the load
@@ -64,11 +78,8 @@ class InstrProfiling : public PassInfoMixin {
   std::vector 

[clang] [flang] [llvm] [clang-tools-extra] [compiler-rt] [BPI] Reuse the AsmWriter's BB naming scheme in BranchProbabilityPrinterPass (PR #73593)

2023-12-02 Thread Mircea Trofin via cfe-commits

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


[llvm] [flang] [clang] [compiler-rt] [clang-tools-extra] [BPI] Reuse the AsmWriter's BB naming scheme in BranchProbabilityPrinterPass (PR #73593)

2023-12-01 Thread Mircea Trofin via cfe-commits

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


[clang-tools-extra] [flang] [clang] [llvm] [compiler-rt] [BPI] Reuse the AsmWriter's BB naming scheme in BranchProbabilityPrinterPass (PR #73593)

2023-12-01 Thread Mircea Trofin via cfe-commits

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


[clang-tools-extra] [flang] [clang] [llvm] [compiler-rt] [bpi] Reuse the AsmWriter's BB naming scheme (PR #73593)

2023-12-01 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

> Consider using `utils/update_analyze_test_checks.py` to create the check 
> lines...

Ack - I did for the new test, and updated the remaining tests - since now all 
the BB names have a preceding `%`.

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


[compiler-rt] [clang-tools-extra] [clang] [llvm] [flang] [bpi] Reuse the AsmWriter's BB naming scheme (PR #73593)

2023-12-01 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

> I'm not an expert on branch-probability facilities, but the test changes look 
> highly valuable,
> 
> It seems awkward to add an extra flag to the block-printer, as it introduces 
> a number of conditionals -- would it be possible to refactor as a dedicated 
> `printBlockName` method rather than an extra option for block printing?

I think @MatzeB's suggestion tackles this, ptal.

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


[clang] [clang-tools-extra] [llvm] [coro][pgo] Do not insert counters in the `suspend` block (PR #71262)

2023-11-15 Thread Mircea Trofin via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [coro][pgo] Do not insert counters in the `suspend` block (PR #71262)

2023-11-15 Thread Mircea Trofin via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [coro][pgo] Do not insert counters in the `suspend` block (PR #71262)

2023-11-15 Thread Mircea Trofin via cfe-commits

https://github.com/mtrofin updated 
https://github.com/llvm/llvm-project/pull/71262

>From 184936c339ea73ccfc4349e023ff165aa9f8392e Mon Sep 17 00:00:00 2001
From: Mircea Trofin 
Date: Fri, 3 Nov 2023 18:19:15 -0700
Subject: [PATCH 1/4] [coro][pgp] Do not insert counters in the `suspend` block

If we do, we can't lower the suspend call to a tail call. If this
happened in a loop, it can lead to stack overflow (this was encountered
in a benchmark, as an extreme case)

We can instrument the other 2 edges instead, as long as they also don't
point to the same basic block.
---
 .../llvm/Transforms/Instrumentation/CFGMST.h  | 65 +++
 .../Coroutines/coro-split-musttail.ll |  7 +-
 .../Coroutines/coro-split-musttail1.ll| 12 ++--
 .../Coroutines/coro-split-musttail10.ll   |  1 +
 .../Coroutines/coro-split-musttail11.ll   |  1 +
 .../Coroutines/coro-split-musttail12.ll   |  1 +
 .../Coroutines/coro-split-musttail13.ll   |  1 +
 .../Coroutines/coro-split-musttail2.ll|  1 +
 .../Coroutines/coro-split-musttail3.ll| 12 ++--
 .../Coroutines/coro-split-musttail4.ll|  1 +
 .../Coroutines/coro-split-musttail5.ll|  1 +
 .../Coroutines/coro-split-musttail6.ll|  1 +
 .../Coroutines/coro-split-musttail7.ll|  1 +
 13 files changed, 83 insertions(+), 22 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h 
b/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h
index 6ed8a6c6eaf0197..1c5b7ba6d0ed364 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h
@@ -19,6 +19,8 @@
 #include "llvm/Analysis/BlockFrequencyInfo.h"
 #include "llvm/Analysis/BranchProbabilityInfo.h"
 #include "llvm/Analysis/CFG.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/Support/BranchProbability.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -121,31 +123,70 @@ template  class CFGMST {
 
 static const uint32_t CriticalEdgeMultiplier = 1000;
 
+auto GetCoroSuspendSwitch =
+[&](const Instruction *TI) -> const SwitchInst * {
+  if (!F.isPresplitCoroutine())
+return nullptr;
+  if (auto *SWInst = dyn_cast(TI))
+if (auto *Intrinsic = dyn_cast(SWInst->getCondition()))
+  if (Intrinsic->getIntrinsicID() == Intrinsic::coro_suspend)
+return SWInst;
+  return nullptr;
+};
+
 for (BasicBlock  : F) {
   Instruction *TI = BB.getTerminator();
+  const SwitchInst *CoroSuspendSwitch = GetCoroSuspendSwitch(TI);
   uint64_t BBWeight =
   (BFI != nullptr ? BFI->getBlockFreq().getFrequency() : 2);
   uint64_t Weight = 2;
   if (int successors = TI->getNumSuccessors()) {
 for (int i = 0; i != successors; ++i) {
   BasicBlock *TargetBB = TI->getSuccessor(i);
-  bool Critical = isCriticalEdge(TI, i);
-  uint64_t scaleFactor = BBWeight;
-  if (Critical) {
-if (scaleFactor < UINT64_MAX / CriticalEdgeMultiplier)
-  scaleFactor *= CriticalEdgeMultiplier;
-else
-  scaleFactor = UINT64_MAX;
+  const bool Critical = isCriticalEdge(TI, i);
+  const bool IsCoroSuspendTarget =
+  CoroSuspendSwitch &&
+  CoroSuspendSwitch->getDefaultDest() == TargetBB;
+  // We must not add instrumentation to the BB representing the
+  // "suspend" path, else CoroSplit won't be able to lower
+  // llvm.coro.suspend to a tail call. We do want profiling info for
+  // the other branches (resume/destroy). So we do 2 things:
+  // 1. we prefer instrumenting those other edges by setting the weight
+  //of the "suspend" edge to max, and
+  // 2. we mark the edge as "Removed" to guarantee it is not considered
+  //for instrumentation. That could technically happen:
+  //(from test/Transforms/Coroutines/coro-split-musttail.ll)
+  //
+  // %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+  // switch i8 %suspend, label %exit [
+  //   i8 0, label %await.ready
+  //   i8 1, label %exit
+  // ]
+  if (IsCoroSuspendTarget) {
+Weight = UINT64_MAX;
+  } else {
+bool Critical = isCriticalEdge(TI, i);
+uint64_t scaleFactor = BBWeight;
+if (Critical) {
+  if (scaleFactor < UINT64_MAX / CriticalEdgeMultiplier)
+scaleFactor *= CriticalEdgeMultiplier;
+  else
+scaleFactor = UINT64_MAX;
+}
+if (BPI != nullptr)
+  Weight =
+  BPI->getEdgeProbability(, TargetBB).scale(scaleFactor);
+if (Weight == 0)
+  Weight++;
   }
-  if (BPI != nullptr)
-Weight = BPI->getEdgeProbability(, 

[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-02 Thread Mircea Trofin via cfe-commits

mtrofin wrote:

Nit: can you add in the description that this is a follow-up from the opaque 
pointer transition (having an explicit motivation helps read a patch). Thanks!

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


[clang] 255e7e1 - [UpdateTestChecks] Fix `update_*_test_checks.py` to add "unused" prefixes

2022-11-28 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2022-11-28T13:24:32-08:00
New Revision: 255e7e1c21eeb57b26585836a2e2d5a7f39e3cf3

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

LOG: [UpdateTestChecks] Fix `update_*_test_checks.py` to add "unused" prefixes

The support introduced in D124306 was only added to
update_llc_test_checks.py, but the motivating usecases (see
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
cover update_test_checks.py, update_cc_test_checks.py, and
update_analyze_test_checks.py, too.

Issue #59220.

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

Added: 

clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll.expected

Modified: 
clang/test/utils/update_cc_test_checks/prefix-never-matches.test
llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll

llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-loopvectorize-costmodel.ll.expected

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/function_name.ll.expected

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected

llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test
llvm/utils/UpdateTestChecks/common.py
llvm/utils/update_analyze_test_checks.py
llvm/utils/update_cc_test_checks.py
llvm/utils/update_test_checks.py

Removed: 




diff  --git 
a/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected
 
b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected
new file mode 100644
index 0..9dbd0045a158b
--- /dev/null
+++ 
b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected
@@ -0,0 +1,9 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O0 -o - %s | 
FileCheck %s -check-prefix=A
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O3 -o - %s | 
FileCheck %s -check-prefix=A
+
+int foo(int i ) {
+return 1;
+}
+ NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
+// A: {{.*}}

diff  --git a/clang/test/utils/update_cc_test_checks/prefix-never-matches.test 
b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
index 7100377337bca..f2afd04743482 100644
--- a/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
+++ b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
@@ -1,6 +1,3 @@
 # RUN: cp -f %S/Inputs/prefix-never-matches.cpp %t.cpp
-# RUN: %update_cc_test_checks %t.cpp 2>&1 | FileCheck %s
-# RUN: FileCheck --input-file=%t.cpp %s --check-prefix=OUTPUT
-
-# CHECK: WARNING: Prefix A had conflicting output
-# OUTPUT-NOT: A:
\ No newline at end of file
+# RUN: %update_cc_test_checks %t.cpp
+# RUN: 
diff  -u %t.cpp %S/Inputs/prefix-never-matches.cpp.expected

diff  --git a/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll 
b/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
index 5eaf311561355..a3c4182200bdd 100644
--- a/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
+++ b/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
@@ -1,8 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -passes=instcombine -data-layout="e-n8:16:32:64" -S %s | FileCheck 
%s --check-prefixes=CHECK-ALL
-; RUN: opt -passes=instcombine -data-layout="e-n8:16:32" -S %s | FileCheck %s 
--check-prefixes=CHECK-ALL
-; RUN: opt -passes=instcombine -data-layout="E-n8:16:32:64" -S %s | FileCheck 
%s --check-prefixes=CHECK-ALL
-; RUN: opt -passes=instcombine -data-layout="E-n8:16:32" -S %s | FileCheck %s 
--check-prefixes=CHECK-ALL
+; RUN: opt -passes=instcombine -data-layout="e-n8:16:32:64" -S %s | FileCheck 
%s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-64,CHECK-LE-64
+; RUN: opt -passes=instcombine -data-layout="e-n8:16:32" -S %s | FileCheck %s 
--check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-32,CHECK-LE-32
+; RUN: opt -passes=instcombine -data-layout="E-n8:16:32:64" -S %s | FileCheck 
%s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-64,CHECK-BE-64
+; RUN: opt -passes=instcombine -data-layout="E-n8:16:32" -S %s | FileCheck %s 
--check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-32,CHECK-BE-32
 
 define void @load-1byte-chunk-of-1byte-alloca(ptr %src, i64 %byteOff, ptr 
%escape) {
 ; 

[clang] afb4efd - Fix lack of cc1 flag in llvmcmd sections when assertions are enabled

2022-07-29 Thread Mircea Trofin via cfe-commits

Author: Aiden Grossman
Date: 2022-07-29T18:51:48-07:00
New Revision: afb4efd3bcc68ab95bf3c35183bedbdbf038356a

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

LOG: Fix lack of cc1 flag in llvmcmd sections when assertions are enabled

Currently when assertions are enabled, the cc1 flag is not
inserted into the llvmcmd section of object files with embedded
bitcode. This deviates from the normal behavior where this is
the first flag that is inserted. This error stems from incorrect
use of the function generateCC1CommandLine() which requires
manually adding in the -cc1 flag which is currently not done.

Reviewed By: jansvoboda11

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2dd96e68bb92f..82dcc2a59e0f9 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4544,7 +4544,10 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation ,
 return CreateFromArgsImpl(Invocation, CommandLineArgs, Diags, Argv0);
   },
   [](CompilerInvocation , SmallVectorImpl ,
- StringAllocator SA) { Invocation.generateCC1CommandLine(Args, SA); },
+ StringAllocator SA) {
+Args.push_back("-cc1");
+Invocation.generateCC1CommandLine(Args, SA);
+  },
   Invocation, DummyInvocation, CommandLineArgs, Diags, Argv0);
 }
 

diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index fe6785257e926..d4c6981df17c2 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -23,6 +23,7 @@ using namespace clang;
 using ::testing::Contains;
 using ::testing::HasSubstr;
 using ::testing::StrEq;
+using ::testing::StartsWith;
 
 namespace {
 class CommandLineTest : public ::testing::Test {
@@ -145,6 +146,26 @@ TEST_F(CommandLineTest, 
BoolOptionDefaultTrueSingleFlagPresent) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
 }
 
+TEST_F(CommandLineTest, CC1FlagPresentWhenDoingRoundTrip) {
+  const char *Args[] = {"-cc1", "-round-trip-args"};
+
+  ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+
+  ASSERT_THAT(std::string(Invocation.getCodeGenOpts().CmdArgs.begin(),
+  Invocation.getCodeGenOpts().CmdArgs.end()),
+  StartsWith("-cc1"));
+}
+
+TEST_F(CommandLineTest, CC1FlagPresentWhenNotDoingRoundTrip) {
+  const char *Args[] = {"-cc1", "-no-round-trip-args"};
+
+  ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+
+  ASSERT_THAT(std::string(Invocation.getCodeGenOpts().CmdArgs.begin(),
+  Invocation.getCodeGenOpts().CmdArgs.end()),
+  StartsWith("-cc1"));
+}
+
 TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagUnknownPresent) {
   const char *Args[] = {"-ftemp-file"};
 



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


[clang] cb21607 - [nfc][codegen] Move RegisterBank[Info].h under CodeGen

2022-03-01 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2022-03-01T21:53:25-08:00
New Revision: cb2160760e6768e306cf357be8dd5c4c007ef273

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

LOG: [nfc][codegen] Move RegisterBank[Info].h under CodeGen

This wraps up from D119053. The 2 headers are moved as described,
fixed file headers and include guards, updated all files where the old
paths were detected (simple grep through the repo), and `clang-format`-ed it 
all.

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

Added: 
llvm/include/llvm/CodeGen/RegisterBank.h
llvm/include/llvm/CodeGen/RegisterBankInfo.h

Modified: 
clang/docs/tools/clang-formatted-files.txt
llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h
llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
llvm/include/llvm/CodeGen/MachineRegisterInfo.h
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
llvm/lib/CodeGen/GlobalISel/Utils.cpp
llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/lib/CodeGen/MIRParser/MIRParser.cpp
llvm/lib/CodeGen/MIRPrinter.cpp
llvm/lib/CodeGen/MachineInstr.cpp
llvm/lib/CodeGen/MachineVerifier.cpp
llvm/lib/CodeGen/RegisterBank.cpp
llvm/lib/CodeGen/RegisterBankInfo.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp
llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.h
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.h
llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp
llvm/lib/Target/ARM/ARMRegisterBankInfo.h
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/Target/M68k/GISel/M68kRegisterBankInfo.cpp
llvm/lib/Target/M68k/GISel/M68kRegisterBankInfo.h
llvm/lib/Target/M68k/M68kSubtarget.h
llvm/lib/Target/Mips/MipsRegisterBankInfo.h
llvm/lib/Target/Mips/MipsSubtarget.h
llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.h
llvm/lib/Target/PowerPC/PPCSubtarget.h
llvm/lib/Target/RISCV/RISCVRegisterBankInfo.cpp
llvm/lib/Target/RISCV/RISCVRegisterBankInfo.h
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/lib/Target/X86/X86InstructionSelector.cpp
llvm/lib/Target/X86/X86RegisterBankInfo.cpp
llvm/lib/Target/X86/X86RegisterBankInfo.h

Removed: 
llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h
llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 231877144d28a..4a776de9bc1c6 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -4750,6 +4750,7 @@ llvm/include/llvm/CodeGen/NonRelocatableStringpool.h
 llvm/include/llvm/CodeGen/ParallelCG.h
 llvm/include/llvm/CodeGen/PBQPRAConstraint.h
 llvm/include/llvm/CodeGen/PreISelIntrinsicLowering.h
+llvm/include/llvm/CodeGen/RegisterBank.h
 llvm/include/llvm/CodeGen/RegisterClassInfo.h
 llvm/include/llvm/CodeGen/ReplaceWithVeclib.h
 llvm/include/llvm/CodeGen/ScheduleDAGMutation.h
@@ -4769,7 +4770,6 @@ llvm/include/llvm/CodeGen/GlobalISel/InlineAsmLowering.h
 llvm/include/llvm/CodeGen/GlobalISel/InstructionSelect.h
 llvm/include/llvm/CodeGen/GlobalISel/Legalizer.h
 llvm/include/llvm/CodeGen/GlobalISel/LostDebugLocObserver.h
-llvm/include/llvm/CodeGen/GlobalISel/RegisterBank.h
 llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
 llvm/include/llvm/CodeGen/PBQP/CostAllocator.h
 llvm/include/llvm/DebugInfo/DIContext.h

diff  --git a/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h 
b/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h
index bc9f952146c2d..8ae2335aedda4 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h
@@ -17,11 +17,11 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
-#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
 #include "llvm/CodeGen/GlobalISel/Utils.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineOperand.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/RegisterBankInfo.h"
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetOpcodes.h"
 #include "llvm/CodeGen/TargetRegisterInfo.h"

diff  --git a/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h 
b/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
index 45006eecfce6f..d0918485249dc 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
@@ -66,10 +66,10 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include 

[clang] 7d541eb - [inliner] Mandatory inlining decisions produce remarks

2021-10-05 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-10-05T14:01:25-07:00
New Revision: 7d541eb4d49b6a51a3568b9214fd8691e2d3

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

LOG: [inliner] Mandatory inlining decisions produce remarks

This also removes the need to disable the mandatory inlining phase in
tests.

In a departure from the previous remark, we don't output a 'cost' in
this case, because there's no such thing. We just report that inlining
happened because of the attribute.

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

Added: 
llvm/test/Transforms/Inline/inline-remark-mandatory.ll

Modified: 
clang/test/Frontend/optimization-remark-line-directive.c
clang/test/Frontend/optimization-remark-new-pm.c
clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
clang/test/Frontend/optimization-remark.c
llvm/include/llvm/Analysis/InlineAdvisor.h
llvm/lib/Analysis/InlineAdvisor.cpp
llvm/lib/Transforms/IPO/AlwaysInliner.cpp
llvm/lib/Transforms/IPO/Inliner.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp

Removed: 




diff  --git a/clang/test/Frontend/optimization-remark-line-directive.c 
b/clang/test/Frontend/optimization-remark-line-directive.c
index 13a197c109a5f..32b098916e6fe 100644
--- a/clang/test/Frontend/optimization-remark-line-directive.c
+++ b/clang/test/Frontend/optimization-remark-line-directive.c
@@ -6,7 +6,7 @@
 
 // The new PM inliner is not added to the default pipeline at O0, so we add
 // some optimizations to trigger it.
-// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 
-debug-info-kind=line-tables-only -emit-llvm-only -mllvm 
-mandatory-inlining-first=false -verify
+// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 
-debug-info-kind=line-tables-only -emit-llvm-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
 int foo(int x, int y) { return x + y; }

diff  --git a/clang/test/Frontend/optimization-remark-new-pm.c 
b/clang/test/Frontend/optimization-remark-new-pm.c
index e2c198a305303..1a9adae437ef4 100644
--- a/clang/test/Frontend/optimization-remark-new-pm.c
+++ b/clang/test/Frontend/optimization-remark-new-pm.c
@@ -1,8 +1,8 @@
 // Verify that remarks for the inliner appear. The remarks under the new PM 
will
 // be slightly 
diff erent than those emitted by the legacy PM. The new PM inliner
 // also doesnot appear to be added at O0, so we test at O1.
-// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline 
-Rpass-missed=inline -O1 -fexperimental-new-pass-manager -emit-llvm-only -mllvm 
-mandatory-inlining-first=false -verify
-// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline 
-Rpass-missed=inline -O1 -fexperimental-new-pass-manager -emit-llvm-only 
-debug-info-kind=line-tables-only -mllvm -mandatory-inlining-first=false -verify
+// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline 
-Rpass-missed=inline -O1 -fexperimental-new-pass-manager -emit-llvm-only -verify
+// RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline 
-Rpass-missed=inline -O1 -fexperimental-new-pass-manager -emit-llvm-only 
-debug-info-kind=line-tables-only -verify
 
 int foo(int x, int y) __attribute__((always_inline));
 int foo(int x, int y) { return x + y; }

diff  --git a/clang/test/Frontend/optimization-remark-with-hotness-new-pm.c 
b/clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
index 84fb44d86d126..7090055cc41ea 100644
--- a/clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
+++ b/clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
@@ -18,47 +18,47 @@
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
 // RUN: -fexperimental-new-pass-manager -O1 \
 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
-// RUN: -fdiagnostics-show-hotness -verify -mllvm 
-mandatory-inlining-first=false
+// RUN: -fdiagnostics-show-hotness -verify
 // The clang version of the previous test.
 // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \
 // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \
 // RUN: -fexperimental-new-pass-manager -O1 \
 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
-// RUN: -fdiagnostics-show-hotness -Xclang -verify -mllvm 
-mandatory-inlining-first=false
+// RUN: -fdiagnostics-show-hotness -Xclang -verify
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \
 // RUN: -fexperimental-new-pass-manager -O1 \
 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
 // RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \
-// RUN: -verify -mllvm 

[clang] 92ccc6c - Reapply "[NPM][CGSCC] FunctionAnalysisManagerCGSCCProxy: do not clear immutable function passes"

2021-03-18 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-03-18T09:44:34-07:00
New Revision: 92ccc6cb17a4fd1b9506bac51f2eb1a96f4cd345

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

LOG: Reapply "[NPM][CGSCC] FunctionAnalysisManagerCGSCCProxy: do not clear 
immutable function passes"

This reverts commit 11b70b9e3a7458b5b78c30020b56e8ca563a4801.

The bot failure was due to ArgumentPromotion deleting functions
without deleting their analyses. This was separately fixed in 4b1c807.

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Analysis/CGSCCPassManager.cpp
llvm/unittests/Analysis/CGSCCPassManagerTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 867203417754..1e9d5d4d2629 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -12,7 +12,7 @@
 ; RUN: %clang -target x86_64-grtev4-linux-gnu \
 ; RUN:   -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
 ; RUN:   -c -fthinlto-index=%t.o.thinlto.bc \
-; RUN:   -o %t.native.o -x ir %t.o 2>&1 | FileCheck 
-check-prefixes=CHECK-O,CHECK-O2 %s --dump-input=fail
+; RUN:   -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefix=CHECK-O %s 
--dump-input=fail
 
 ; RUN: %clang -target x86_64-grtev4-linux-gnu \
 ; RUN:   -O3 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
@@ -70,24 +70,19 @@
 ; CHECK-O: Starting CGSCC pass manager run.
 ; CHECK-O: Running pass: InlinerPass on (main)
 ; CHECK-O: Running pass: PostOrderFunctionAttrsPass on (main)
-; CHECK-O: Clearing all analysis results for: main
+; CHECK-O: Invalidating analysis: DominatorTreeAnalysis on main
+; CHECK-O: Invalidating analysis: BasicAA on main
+; CHECK-O: Invalidating analysis: AAManager on main
 ; CHECK-O3: Running pass: ArgumentPromotionPass on (main)
-; CHECK-O3: Running analysis: TargetIRAnalysis on main
 ; CHECK-O: Starting {{.*}}Function pass manager run.
 ; CHECK-O: Running pass: SROA on main
 ; These next two can appear in any order since they are accessed as parameters
 ; on the same call to SROA::runImpl
 ; CHECK-O-DAG: Running analysis: DominatorTreeAnalysis on main
-; CHECK-O-DAG: Running analysis: AssumptionAnalysis on main
 ; CHECK-O: Running pass: EarlyCSEPass on main
-; CHECK-O: Running analysis: TargetLibraryAnalysis on main
-; CHECK-O2: Running analysis: TargetIRAnalysis on main
 ; CHECK-O: Running analysis: MemorySSAAnalysis on main
 ; CHECK-O: Running analysis: AAManager on main
 ; CHECK-O: Running analysis: BasicAA on main
-; CHECK-O: Running analysis: ScopedNoAliasAA on main
-; CHECK-O: Running analysis: TypeBasedAA on main
-; CHECK-O: Running analysis: OuterAnalysisManagerProxy
 ; CHECK-O: Running pass: SpeculativeExecutionPass on main
 ; CHECK-O: Running pass: JumpThreadingPass on main
 ; CHECK-O: Running analysis: LazyValueAnalysis on main
@@ -96,7 +91,6 @@
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O3: Running pass: AggressiveInstCombinePass on main
 ; CHECK-O: Running pass: InstCombinePass on main
-; CHECK-O: Running analysis: OptimizationRemarkEmitterAnalysis on main
 ; CHECK-O: Running pass: LibCallsShrinkWrapPass on main
 ; CHECK-O: Running pass: TailCallElimPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main

diff  --git a/llvm/lib/Analysis/CGSCCPassManager.cpp 
b/llvm/lib/Analysis/CGSCCPassManager.cpp
index 9dc62b877ae2..eaaa3d09a7f2 100644
--- a/llvm/lib/Analysis/CGSCCPassManager.cpp
+++ b/llvm/lib/Analysis/CGSCCPassManager.cpp
@@ -720,7 +720,7 @@ bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
   auto PAC = PA.getChecker();
   if (!PAC.preserved() && 
!PAC.preservedSet>()) {
 for (LazyCallGraph::Node  : C)
-  FAM->clear(N.getFunction(), N.getFunction().getName());
+  FAM->invalidate(N.getFunction(), PA);
 
 return false;
   }

diff  --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp 
b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index 59ff97d0fc1a..ceaeaaf83e5d 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -1942,5 +1942,30 @@ TEST_F(CGSCCPassManagerTest, 
TestInsertionOfNewNonTrivialCallEdge) {
   ASSERT_TRUE(Ran);
 }
 
+TEST_F(CGSCCPassManagerTest, TestFunctionPassesAreQueriedForInvalidation) {
+  std::unique_ptr M = parseIR("define void @f() { ret void }");
+  CGSCCPassManager CGPM;
+  bool SCCCalled = false;
+  FunctionPassManager FPM;
+  int ImmRuns = 0;
+  FAM.registerPass([&] { return TestImmutableFunctionAnalysis(ImmRuns); });
+  FPM.addPass(RequireAnalysisPass());
+  CGPM.addPass(
+  LambdaSCCPass([&](LazyCallGraph::SCC , CGSCCAnalysisManager ,
+LazyCallGraph , 

[clang] 11b70b9 - Revert "[NPM][CGSCC] FunctionAnalysisManagerCGSCCProxy: do not clear immutable function passes"

2021-03-11 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-03-11T18:31:19-08:00
New Revision: 11b70b9e3a7458b5b78c30020b56e8ca563a4801

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

LOG: Revert "[NPM][CGSCC] FunctionAnalysisManagerCGSCCProxy: do not clear 
immutable function passes"

This reverts commit 5eaeb0fa67e57391f5584a3f67fdb131e93afda6.

It appears there are analyses that assume clearing - example:
https://lab.llvm.org/buildbot#builders/36/builds/5964

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Analysis/CGSCCPassManager.cpp
llvm/unittests/Analysis/CGSCCPassManagerTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 1e9d5d4d2629c..867203417754f 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -12,7 +12,7 @@
 ; RUN: %clang -target x86_64-grtev4-linux-gnu \
 ; RUN:   -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
 ; RUN:   -c -fthinlto-index=%t.o.thinlto.bc \
-; RUN:   -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefix=CHECK-O %s 
--dump-input=fail
+; RUN:   -o %t.native.o -x ir %t.o 2>&1 | FileCheck 
-check-prefixes=CHECK-O,CHECK-O2 %s --dump-input=fail
 
 ; RUN: %clang -target x86_64-grtev4-linux-gnu \
 ; RUN:   -O3 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
@@ -70,19 +70,24 @@
 ; CHECK-O: Starting CGSCC pass manager run.
 ; CHECK-O: Running pass: InlinerPass on (main)
 ; CHECK-O: Running pass: PostOrderFunctionAttrsPass on (main)
-; CHECK-O: Invalidating analysis: DominatorTreeAnalysis on main
-; CHECK-O: Invalidating analysis: BasicAA on main
-; CHECK-O: Invalidating analysis: AAManager on main
+; CHECK-O: Clearing all analysis results for: main
 ; CHECK-O3: Running pass: ArgumentPromotionPass on (main)
+; CHECK-O3: Running analysis: TargetIRAnalysis on main
 ; CHECK-O: Starting {{.*}}Function pass manager run.
 ; CHECK-O: Running pass: SROA on main
 ; These next two can appear in any order since they are accessed as parameters
 ; on the same call to SROA::runImpl
 ; CHECK-O-DAG: Running analysis: DominatorTreeAnalysis on main
+; CHECK-O-DAG: Running analysis: AssumptionAnalysis on main
 ; CHECK-O: Running pass: EarlyCSEPass on main
+; CHECK-O: Running analysis: TargetLibraryAnalysis on main
+; CHECK-O2: Running analysis: TargetIRAnalysis on main
 ; CHECK-O: Running analysis: MemorySSAAnalysis on main
 ; CHECK-O: Running analysis: AAManager on main
 ; CHECK-O: Running analysis: BasicAA on main
+; CHECK-O: Running analysis: ScopedNoAliasAA on main
+; CHECK-O: Running analysis: TypeBasedAA on main
+; CHECK-O: Running analysis: OuterAnalysisManagerProxy
 ; CHECK-O: Running pass: SpeculativeExecutionPass on main
 ; CHECK-O: Running pass: JumpThreadingPass on main
 ; CHECK-O: Running analysis: LazyValueAnalysis on main
@@ -91,6 +96,7 @@
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O3: Running pass: AggressiveInstCombinePass on main
 ; CHECK-O: Running pass: InstCombinePass on main
+; CHECK-O: Running analysis: OptimizationRemarkEmitterAnalysis on main
 ; CHECK-O: Running pass: LibCallsShrinkWrapPass on main
 ; CHECK-O: Running pass: TailCallElimPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main

diff  --git a/llvm/lib/Analysis/CGSCCPassManager.cpp 
b/llvm/lib/Analysis/CGSCCPassManager.cpp
index fe7b30315f9ee..0a05c3c875e08 100644
--- a/llvm/lib/Analysis/CGSCCPassManager.cpp
+++ b/llvm/lib/Analysis/CGSCCPassManager.cpp
@@ -720,7 +720,7 @@ bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
   auto PAC = PA.getChecker();
   if (!PAC.preserved() && 
!PAC.preservedSet>()) {
 for (LazyCallGraph::Node  : C)
-  FAM->invalidate(N.getFunction(), PA);
+  FAM->clear(N.getFunction(), N.getFunction().getName());
 
 return false;
   }

diff  --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp 
b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index ceaeaaf83e5d1..59ff97d0fc1a5 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -1942,30 +1942,5 @@ TEST_F(CGSCCPassManagerTest, 
TestInsertionOfNewNonTrivialCallEdge) {
   ASSERT_TRUE(Ran);
 }
 
-TEST_F(CGSCCPassManagerTest, TestFunctionPassesAreQueriedForInvalidation) {
-  std::unique_ptr M = parseIR("define void @f() { ret void }");
-  CGSCCPassManager CGPM;
-  bool SCCCalled = false;
-  FunctionPassManager FPM;
-  int ImmRuns = 0;
-  FAM.registerPass([&] { return TestImmutableFunctionAnalysis(ImmRuns); });
-  FPM.addPass(RequireAnalysisPass());
-  CGPM.addPass(
-  LambdaSCCPass([&](LazyCallGraph::SCC , CGSCCAnalysisManager ,
-LazyCallGraph , CGSCCUpdateResult ) {
-

[clang] 5eaeb0f - [NPM][CGSCC] FunctionAnalysisManagerCGSCCProxy: do not clear immutable function passes

2021-03-11 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-03-11T18:15:28-08:00
New Revision: 5eaeb0fa67e57391f5584a3f67fdb131e93afda6

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

LOG: [NPM][CGSCC] FunctionAnalysisManagerCGSCCProxy: do not clear immutable 
function passes

Check with the analysis result by calling invalidate instead of clear on
the analysis manager.

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Analysis/CGSCCPassManager.cpp
llvm/unittests/Analysis/CGSCCPassManagerTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 867203417754..1e9d5d4d2629 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -12,7 +12,7 @@
 ; RUN: %clang -target x86_64-grtev4-linux-gnu \
 ; RUN:   -O2 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
 ; RUN:   -c -fthinlto-index=%t.o.thinlto.bc \
-; RUN:   -o %t.native.o -x ir %t.o 2>&1 | FileCheck 
-check-prefixes=CHECK-O,CHECK-O2 %s --dump-input=fail
+; RUN:   -o %t.native.o -x ir %t.o 2>&1 | FileCheck -check-prefix=CHECK-O %s 
--dump-input=fail
 
 ; RUN: %clang -target x86_64-grtev4-linux-gnu \
 ; RUN:   -O3 -fexperimental-new-pass-manager -Xclang -fdebug-pass-manager \
@@ -70,24 +70,19 @@
 ; CHECK-O: Starting CGSCC pass manager run.
 ; CHECK-O: Running pass: InlinerPass on (main)
 ; CHECK-O: Running pass: PostOrderFunctionAttrsPass on (main)
-; CHECK-O: Clearing all analysis results for: main
+; CHECK-O: Invalidating analysis: DominatorTreeAnalysis on main
+; CHECK-O: Invalidating analysis: BasicAA on main
+; CHECK-O: Invalidating analysis: AAManager on main
 ; CHECK-O3: Running pass: ArgumentPromotionPass on (main)
-; CHECK-O3: Running analysis: TargetIRAnalysis on main
 ; CHECK-O: Starting {{.*}}Function pass manager run.
 ; CHECK-O: Running pass: SROA on main
 ; These next two can appear in any order since they are accessed as parameters
 ; on the same call to SROA::runImpl
 ; CHECK-O-DAG: Running analysis: DominatorTreeAnalysis on main
-; CHECK-O-DAG: Running analysis: AssumptionAnalysis on main
 ; CHECK-O: Running pass: EarlyCSEPass on main
-; CHECK-O: Running analysis: TargetLibraryAnalysis on main
-; CHECK-O2: Running analysis: TargetIRAnalysis on main
 ; CHECK-O: Running analysis: MemorySSAAnalysis on main
 ; CHECK-O: Running analysis: AAManager on main
 ; CHECK-O: Running analysis: BasicAA on main
-; CHECK-O: Running analysis: ScopedNoAliasAA on main
-; CHECK-O: Running analysis: TypeBasedAA on main
-; CHECK-O: Running analysis: OuterAnalysisManagerProxy
 ; CHECK-O: Running pass: SpeculativeExecutionPass on main
 ; CHECK-O: Running pass: JumpThreadingPass on main
 ; CHECK-O: Running analysis: LazyValueAnalysis on main
@@ -96,7 +91,6 @@
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O3: Running pass: AggressiveInstCombinePass on main
 ; CHECK-O: Running pass: InstCombinePass on main
-; CHECK-O: Running analysis: OptimizationRemarkEmitterAnalysis on main
 ; CHECK-O: Running pass: LibCallsShrinkWrapPass on main
 ; CHECK-O: Running pass: TailCallElimPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main

diff  --git a/llvm/lib/Analysis/CGSCCPassManager.cpp 
b/llvm/lib/Analysis/CGSCCPassManager.cpp
index 0a05c3c875e0..fe7b30315f9e 100644
--- a/llvm/lib/Analysis/CGSCCPassManager.cpp
+++ b/llvm/lib/Analysis/CGSCCPassManager.cpp
@@ -720,7 +720,7 @@ bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
   auto PAC = PA.getChecker();
   if (!PAC.preserved() && 
!PAC.preservedSet>()) {
 for (LazyCallGraph::Node  : C)
-  FAM->clear(N.getFunction(), N.getFunction().getName());
+  FAM->invalidate(N.getFunction(), PA);
 
 return false;
   }

diff  --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp 
b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index 59ff97d0fc1a..ceaeaaf83e5d 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -1942,5 +1942,30 @@ TEST_F(CGSCCPassManagerTest, 
TestInsertionOfNewNonTrivialCallEdge) {
   ASSERT_TRUE(Ran);
 }
 
+TEST_F(CGSCCPassManagerTest, TestFunctionPassesAreQueriedForInvalidation) {
+  std::unique_ptr M = parseIR("define void @f() { ret void }");
+  CGSCCPassManager CGPM;
+  bool SCCCalled = false;
+  FunctionPassManager FPM;
+  int ImmRuns = 0;
+  FAM.registerPass([&] { return TestImmutableFunctionAnalysis(ImmRuns); });
+  FPM.addPass(RequireAnalysisPass());
+  CGPM.addPass(
+  LambdaSCCPass([&](LazyCallGraph::SCC , CGSCCAnalysisManager ,
+LazyCallGraph , CGSCCUpdateResult ) {
+SCCCalled = true;
+return 

[clang] c4d6f27 - [NFC] Disallow unused prefixes under clang/test/Driver

2021-02-01 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-02-01T10:34:38-08:00
New Revision: c4d6f2707a1e6c4e9bd93480dd913121fef122b7

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

LOG: [NFC] Disallow unused prefixes under clang/test/Driver

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

Added: 


Modified: 
clang/test/Driver/amdgpu-macros.cl
clang/test/Driver/cuda-detect.cu
clang/test/Driver/fsanitize.c
clang/test/Driver/lit.local.cfg
clang/test/Driver/ps4-visibility-dllstorageclass.c
clang/test/Driver/rocm-device-libs.cl

Removed: 




diff  --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index e5611446eace..d708e29e1acf 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -67,52 +67,52 @@
 // AMDGCN-based processors.
 //
 
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx600 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX600,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx600
-// RUN: %clang -E -dM -target amdgcn -mcpu=tahiti %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX600,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx600
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx601 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX601,SLOW_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx601
-// RUN: %clang -E -dM -target amdgcn -mcpu=pitcairn %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX601,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx601
-// RUN: %clang -E -dM -target amdgcn -mcpu=verde %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX601,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx601
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx602 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX602,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx602
-// RUN: %clang -E -dM -target amdgcn -mcpu=hainan %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX602,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx602
-// RUN: %clang -E -dM -target amdgcn -mcpu=oland %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX602,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx602
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx700 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX700,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx700
-// RUN: %clang -E -dM -target amdgcn -mcpu=kaveri %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX700,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx700
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx701 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX701,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx701
-// RUN: %clang -E -dM -target amdgcn -mcpu=hawaii %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX701,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx701
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx702 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX702,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx702
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx703 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX703,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx703
-// RUN: %clang -E -dM -target amdgcn -mcpu=kabini %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX703,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx703
-// RUN: %clang -E -dM -target amdgcn -mcpu=mullins %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX703,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx703
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx704 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX704,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx704
-// RUN: %clang -E -dM -target amdgcn -mcpu=bonaire %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX704,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx704
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx705 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX705,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx705
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx801 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX801,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx801
-// RUN: %clang -E -dM -target amdgcn -mcpu=carrizo %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX801,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx801
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx802 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX802,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx802
-// RUN: %clang -E -dM -target amdgcn -mcpu=iceland %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX802,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx802
-// RUN: %clang -E -dM -target amdgcn -mcpu=tonga %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX802,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx802
-// RUN: %clang -E -dM -target amdgcn -mcpu=gfx803 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX803,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx803
-// RUN: %clang -E -dM -target amdgcn -mcpu=fiji %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,GFX803,SLOW_FMA %s -DWAVEFRONT_SIZE=64 -DCPU=gfx803
-// RUN: %clang -E -dM -target amdgcn 

[clang] cfcc111 - [NFC] Disallow unused prefixes under clang/test/CodeGenCXX

2021-01-28 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-01-28T09:47:21-08:00
New Revision: cfcc1110d7733ad6c275eefd1773d243a719f9f3

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

LOG: [NFC] Disallow unused prefixes under clang/test/CodeGenCXX

The only test that needed change had 'QUAL' as an unused prefix. The
rest of the changes are to simplify the prefix lists.

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

Added: 
clang/test/CodeGenCXX/lit.local.cfg

Modified: 
clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
index 935fded5e67c..4f85effdc700 100644
--- a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
+++ b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
@@ -1,19 +1,19 @@
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++98 | \
 // RUN:grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: 
"\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL
+// RUN:FileCheck %s --check-prefixes=CHECK,UNQUAL
 // RUN: %clang_cc1 -fblocks -debug-info-kind=line-tables-only -gcodeview 
-emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++98 | \
 // RUN:grep 'DISubprogram' | sed -e 's/.*name: "\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=QUAL
+// RUN:FileCheck %s
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++11 | \
 // RUN:grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: 
"\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL
+// RUN:FileCheck %s --check-prefixes=CHECK,UNQUAL
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null | \
 // RUN:grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: 
"\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL
+// RUN:FileCheck %s --check-prefixes=CHECK,UNQUAL
 
 void freefunc() { }
 // CHECK-DAG: "freefunc"

diff  --git a/clang/test/CodeGenCXX/lit.local.cfg 
b/clang/test/CodeGenCXX/lit.local.cfg
new file mode 100644
index ..c5bb8b60a52a
--- /dev/null
+++ b/clang/test/CodeGenCXX/lit.local.cfg
@@ -0,0 +1,9 @@
+# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
+from lit.llvm.subst import ToolSubst
+
+fc = ToolSubst('FileCheck', unresolved='fatal')
+# Insert this first. Then, we'll first update the blank FileCheck command; 
then,
+# the default substitution of FileCheck will replace it to its full path.
+config.substitutions.insert(0, (fc.regex,
+'FileCheck --allow-unused-prefixes=false'))
+



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


[clang] cfcc111 - [NFC] Disallow unused prefixes under clang/test/CodeGenCXX

2021-01-28 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-01-28T09:47:21-08:00
New Revision: cfcc1110d7733ad6c275eefd1773d243a719f9f3

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

LOG: [NFC] Disallow unused prefixes under clang/test/CodeGenCXX

The only test that needed change had 'QUAL' as an unused prefix. The
rest of the changes are to simplify the prefix lists.

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

Added: 
clang/test/CodeGenCXX/lit.local.cfg

Modified: 
clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
index 935fded5e67c..4f85effdc700 100644
--- a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
+++ b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
@@ -1,19 +1,19 @@
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++98 | \
 // RUN:grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: 
"\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL
+// RUN:FileCheck %s --check-prefixes=CHECK,UNQUAL
 // RUN: %clang_cc1 -fblocks -debug-info-kind=line-tables-only -gcodeview 
-emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++98 | \
 // RUN:grep 'DISubprogram' | sed -e 's/.*name: "\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=QUAL
+// RUN:FileCheck %s
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null -std=c++11 | \
 // RUN:grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: 
"\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL
+// RUN:FileCheck %s --check-prefixes=CHECK,UNQUAL
 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -gcodeview -emit-llvm %s \
 // RUN:   -o - -triple=x86_64-pc-win32 -Wno-new-returns-null | \
 // RUN:grep -E 'DISubprogram|DICompositeType' | sed -e 's/.*name: 
"\([^"]*\)".*/"\1"/' | \
-// RUN:FileCheck %s --check-prefix=CHECK --check-prefix=UNQUAL
+// RUN:FileCheck %s --check-prefixes=CHECK,UNQUAL
 
 void freefunc() { }
 // CHECK-DAG: "freefunc"

diff  --git a/clang/test/CodeGenCXX/lit.local.cfg 
b/clang/test/CodeGenCXX/lit.local.cfg
new file mode 100644
index ..c5bb8b60a52a
--- /dev/null
+++ b/clang/test/CodeGenCXX/lit.local.cfg
@@ -0,0 +1,9 @@
+# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
+from lit.llvm.subst import ToolSubst
+
+fc = ToolSubst('FileCheck', unresolved='fatal')
+# Insert this first. Then, we'll first update the blank FileCheck command; 
then,
+# the default substitution of FileCheck will replace it to its full path.
+config.substitutions.insert(0, (fc.regex,
+'FileCheck --allow-unused-prefixes=false'))
+



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


[clang] e8049dc - [NewPM][Inliner] Move the 'always inliner' case in the same CGSCC pass as 'regular' inliner

2021-01-15 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2021-01-15T17:59:38-08:00
New Revision: e8049dc3c8a46ccd75ce2a4f438d695d20feb660

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

LOG: [NewPM][Inliner] Move the 'always inliner' case in the same CGSCC pass as 
'regular' inliner

Expanding from D94808 - we ensure the same InlineAdvisor is used by both
InlinerPass instances. The notion of mandatory inlining is moved into
the core InlineAdvisor: advisors anyway have to handle that case, so
this change also factors out that a bit better.

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
clang/test/Frontend/optimization-remark-line-directive.c
clang/test/Frontend/optimization-remark-new-pm.c
clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
clang/test/Frontend/optimization-remark.c
llvm/include/llvm/Analysis/InlineAdvisor.h
llvm/include/llvm/Analysis/MLInlineAdvisor.h
llvm/include/llvm/Analysis/ReplayInlineAdvisor.h
llvm/include/llvm/Passes/PassBuilder.h
llvm/include/llvm/Transforms/IPO/Inliner.h
llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
llvm/lib/Analysis/InlineAdvisor.cpp
llvm/lib/Analysis/MLInlineAdvisor.cpp
llvm/lib/Analysis/ReplayInlineAdvisor.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/IPO/Inliner.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-pgo-preinline.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/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Transforms/Inline/inline_stats.ll
llvm/test/Transforms/Inline/optimization-remarks-with-hotness.ll
llvm/test/Transforms/Inline/optimization-remarks.ll
llvm/test/Transforms/Inline/pr46945.ll

Removed: 
llvm/test/Other/new-pm-module-inliner-wrapper.ll



diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 8fe53762837e..4c031db6734b 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -63,19 +63,10 @@
 ; CHECK-O: Running analysis: OuterAnalysisManagerProxy
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Finished {{.*}}Function pass manager run.
-; CHECK-O: Running pass: ModuleInlinerWrapperPass
-; CHECK-O: Running analysis: InlineAdvisorAnalysis
 ; CHECK-O: Running analysis: InnerAnalysisManagerProxy
 ; CHECK-O: Running analysis: LazyCallGraphAnalysis
 ; CHECK-O: Running analysis: FunctionAnalysisManagerCGSCCProxy on (main)
 ; CHECK-O: Running analysis: OuterAnalysisManagerProxy
-; CHECK-O: Running pass: InlinerPass on (main)
-; CHECK-O: Finished {{.*}}Module pass manager run
-; CHECK-O: Running pass: ModuleInlinerWrapperPass
-; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA
-; CHECK-O: Running analysis: GlobalsAA
-; CHECK-O: Running analysis: CallGraphAnalysis
-; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}ProfileSummaryAnalysis
 ; CHECK-O: Starting CGSCC pass manager run.
 ; CHECK-O: Running pass: InlinerPass on (main)
 ; CHECK-O: Running pass: PostOrderFunctionAttrsPass on (main)

diff  --git a/clang/test/Frontend/optimization-remark-line-directive.c 
b/clang/test/Frontend/optimization-remark-line-directive.c
index 5a2dc6754763..59f600125860 100644
--- a/clang/test/Frontend/optimization-remark-line-directive.c
+++ b/clang/test/Frontend/optimization-remark-line-directive.c
@@ -6,7 +6,7 @@
 
 // The new PM inliner is not added to the default pipeline at O0, so we add
 // some optimizations to trigger it.
-// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 
-debug-info-kind=line-tables-only -emit-llvm-only -verify -mllvm 
-mandatory-inlining-first=0
+// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 
-debug-info-kind=line-tables-only -emit-llvm-only -mllvm 
-mandatory-inlining-first=false -verify
 
 int foo(int x, int y) __attribute__((always_inline));
 int foo(int x, int y) { return x + y; }

diff  --git a/clang/test/Frontend/optimization-remark-new-pm.c 
b/clang/test/Frontend/optimization-remark-new-pm.c
index 79e83014589b..2d89059b13e6 100644
--- a/clang/test/Frontend/optimization-remark-new-pm.c
+++ b/clang/test/Frontend/optimization-remark-new-pm.c
@@ -1,8 +1,8 @@
 // Verify that remarks for the inliner appear. The remarks under the new PM 
will
 // be slightly 
diff erent than those emitted by the legacy PM. The new PM inliner
 // also doesnot appear to 

[clang] e2dc306 - [utils] Fix UpdateTestChecks case where 2 runs differ for last label

2020-12-15 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-12-15T07:16:54-08:00
New Revision: e2dc306b1ac71258e6ce40a66e778527f282c355

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

LOG: [utils] Fix UpdateTestChecks case where 2 runs differ for last label

Two RUN lines produce outputs that, each, have some common parts and
some different parts. The common parts are checked under label A. The
differing parts are associated to a function and checked under labels B
and C, respectivelly.
When build_function_body_dictionary is called for the first RUN line, it
will attribute the function body to labels A and C. When the second RUN
is passed to build_function_body_dictionary, it sees that the function
body under A is different from what it has. If in this second RUN line,
A were at the end of the prefixes list, A's body is still kept
associated with the first run's function.

When we output the function body (i.e. add_checks), we stop after
emitting for the first prefix matching that function. So we end up with
the wrong function body (first RUN's A-association).

There is no reason to special-case the last label in the prefixes list,
and the fix is to always clear a label association if we find a RUN line
where the body is different.

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

Added: 
clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp
clang/test/utils/update_cc_test_checks/prefix-never-matches.test

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-different-bodies-1.ll

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-different-bodies-2.ll

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-different-bodies-3.ll

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/prefix-never-matches.ll

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/common-label-different-bodies.test

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/prefix-never-matches.test

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll

llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test

Modified: 
llvm/utils/UpdateTestChecks/common.py
llvm/utils/update_test_prefix.py

Removed: 




diff  --git 
a/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp 
b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp
new file mode 100644
index ..75bd5b1249a7
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O0 -o - %s | 
FileCheck %s -check-prefix=A
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O3 -o - %s | 
FileCheck %s -check-prefix=A
+
+int foo(int i ) {
+return 1;
+}
\ No newline at end of file

diff  --git a/clang/test/utils/update_cc_test_checks/prefix-never-matches.test 
b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
new file mode 100644
index ..7100377337bc
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
@@ -0,0 +1,6 @@
+# RUN: cp -f %S/Inputs/prefix-never-matches.cpp %t.cpp
+# RUN: %update_cc_test_checks %t.cpp 2>&1 | FileCheck %s
+# RUN: FileCheck --input-file=%t.cpp %s --check-prefix=OUTPUT
+
+# CHECK: WARNING: Prefix A had conflicting output
+# OUTPUT-NOT: A:
\ No newline at end of file

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-1.ll 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-1.ll
new file mode 100644
index ..c5f2bc9ba5bc
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-1.ll
@@ -0,0 +1,11 @@
+; RUN: llc < %s -mtriple=i686-unknown-linux-gnu -mattr=+sse2 | FileCheck %s 
--check-prefixes=A,B
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s 
--allow-unused-prefixes=true --check-prefixes=C,A,UNUSED
+
+declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+; A: declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+
+define <2 x i64> @fold_v2i64() {
+entry:
+  %r = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> )
+  ret <2 x i64> %r
+}

diff  --git 
a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-2.ll 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-2.ll
new file mode 100644
index ..bc1990462d37
--- /dev/null
+++ 
b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/common-label-
diff erent-bodies-2.ll
@@ -0,0 +1,11 @@
+; RUN: llc < %s 

[clang] 5fe1026 - [llvm][inliner] Reuse the inliner pass to implement 'always inliner'

2020-11-30 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-11-30T12:03:39-08:00
New Revision: 5fe10263ab39be96e316f37272b85a72596a7928

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

LOG: [llvm][inliner] Reuse the inliner pass to implement 'always inliner'

Enable performing mandatory inlinings upfront, by reusing the same logic
as the full inliner, instead of the AlwaysInliner. This has the
following benefits:
- reduce code duplication - one inliner codebase
- open the opportunity to help the full inliner by performing additional
function passes after the mandatory inlinings, but before th full
inliner. Performing the mandatory inlinings first simplifies the problem
the full inliner needs to solve: less call sites, more contextualization, and,
depending on the additional function optimization passes run between the
2 inliners, higher accuracy of cost models / decision policies.

Note that this patch does not yet enable much in terms of post-always
inline function optimization.

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
clang/test/Frontend/optimization-remark-line-directive.c
clang/test/Frontend/optimization-remark-new-pm.c
clang/test/Frontend/optimization-remark-with-hotness-new-pm.c
clang/test/Frontend/optimization-remark.c
llvm/include/llvm/Analysis/InlineAdvisor.h
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Analysis/InlineAdvisor.cpp
llvm/lib/Analysis/MLInlineAdvisor.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/IPO/Inliner.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-module-inliner-wrapper.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/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Transforms/Inline/ML/bounds-checks-rewards.ll
llvm/test/Transforms/Inline/ML/bounds-checks.ll
llvm/test/Transforms/Inline/inline_stats.ll
llvm/test/Transforms/Inline/pr46945.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 3056bf45877a..75ea4064d6af 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -63,14 +63,19 @@
 ; CHECK-O: Running analysis: OuterAnalysisManagerProxy
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Finished {{.*}}Function pass manager run.
-; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA
-; CHECK-O: Running analysis: GlobalsAA
-; CHECK-O: Running analysis: CallGraphAnalysis
-; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}ProfileSummaryAnalysis
+; CHECK-O: Running pass: ModuleInlinerWrapperPass
+; CHECK-O: Running analysis: InlineAdvisorAnalysis
 ; CHECK-O: Running analysis: InnerAnalysisManagerProxy
 ; CHECK-O: Running analysis: LazyCallGraphAnalysis
 ; CHECK-O: Running analysis: FunctionAnalysisManagerCGSCCProxy on (main)
 ; CHECK-O: Running analysis: OuterAnalysisManagerProxy
+; CHECK-O: Running pass: InlinerPass on (main)
+; CHECK-O: Finished {{.*}}Module pass manager run
+; CHECK-O: Running pass: ModuleInlinerWrapperPass
+; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA
+; CHECK-O: Running analysis: GlobalsAA
+; CHECK-O: Running analysis: CallGraphAnalysis
+; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}ProfileSummaryAnalysis
 ; CHECK-O: Starting CGSCC pass manager run.
 ; CHECK-O: Running pass: InlinerPass on (main)
 ; CHECK-O: Running pass: PostOrderFunctionAttrsPass on (main)

diff  --git a/clang/test/Frontend/optimization-remark-line-directive.c 
b/clang/test/Frontend/optimization-remark-line-directive.c
index 095791e505f8..5a2dc6754763 100644
--- a/clang/test/Frontend/optimization-remark-line-directive.c
+++ b/clang/test/Frontend/optimization-remark-line-directive.c
@@ -6,7 +6,7 @@
 
 // The new PM inliner is not added to the default pipeline at O0, so we add
 // some optimizations to trigger it.
-// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 
-debug-info-kind=line-tables-only -emit-llvm-only -verify
+// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 
-debug-info-kind=line-tables-only -emit-llvm-only -verify -mllvm 
-mandatory-inlining-first=0
 
 int foo(int x, int y) __attribute__((always_inline));
 int foo(int x, int y) { return x + y; }

diff  --git a/clang/test/Frontend/optimization-remark-new-pm.c 
b/clang/test/Frontend/optimization-remark-new-pm.c
index 

[clang] 2482648 - thinlto_embed_bitcode.ll: clarify grep should treat input as text

2020-11-21 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-11-21T21:46:53-08:00
New Revision: 2482648a795afbe12774168bbbf70dc14c031267

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

LOG: thinlto_embed_bitcode.ll: clarify grep should treat input as text

The input to the test's use of grep should be treated as text, and
that's not the case on certain Linux distros. Added --text.

Added: 


Modified: 
clang/test/CodeGen/thinlto_embed_bitcode.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto_embed_bitcode.ll 
b/clang/test/CodeGen/thinlto_embed_bitcode.ll
index 6c7e36e7226b..971d4005435d 100644
--- a/clang/test/CodeGen/thinlto_embed_bitcode.ll
+++ b/clang/test/CodeGen/thinlto_embed_bitcode.ll
@@ -18,7 +18,7 @@
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t.o -x ir %t1.bc -c 
-fthinlto-index=%t.o.thinlto.bc -mllvm -lto-embed-bitcode=post-merge-pre-opt
 ; RUN: llvm-readelf -S %t.o | FileCheck %s 
--check-prefixes=CHECK-ELF,CHECK-ELF-CMD
 ; RUN: llvm-objcopy --dump-section=.llvmcmd=%t-embedded.cmd %t.o /dev/null
-; RUN: grep x86_64-unknown-linux-gnu %t-embedded.cmd | count 1
+; RUN: grep --text x86_64-unknown-linux-gnu %t-embedded.cmd | count 1
 ; RUN: llvm-objcopy --dump-section=.llvmbc=%t-embedded.bc %t.o /dev/null
 ; RUN: llvm-dis %t-embedded.bc -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-NOOPT
 ; We should only need the index and the post-thinlto merged module to generate 



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


[clang] 13aee94 - [ThinLTO] Fix empty .llvmcmd sections

2020-10-29 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-10-29T09:57:42-07:00
New Revision: 13aee94bc710bfa6277c1f07146c714ee65bf2de

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

LOG: [ThinLTO] Fix empty .llvmcmd sections

When passing -lto-embed-bitcode=post-merge-pre-opt, we were getting
empty .llvmcmd sections. It turns out that is because the
CodeGenOptions::CmdArgs field was only populated when clang saw
-fembed-bitcode={all|marker}.

This patch always populates the CodeGenOptions::CmdArgs. The overhead
of carrying through in memory in all cases is likely negligible in
the grand schema of things, and it keeps the using code simple.

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/thinlto_embed_bitcode.ll

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 5175063adb02..22579161b345 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1095,23 +1095,21 @@ static bool ParseCodeGenArgs(CodeGenOptions , 
ArgList , InputKind IK,
   // FIXME: For backend options that are not yet recorded as function
   // attributes in the IR, keep track of them so we can embed them in a
   // separate data section and use them when building the bitcode.
-  if (Opts.getEmbedBitcode() == CodeGenOptions::Embed_All) {
-for (const auto  : Args) {
-  // Do not encode output and input.
-  if (A->getOption().getID() == options::OPT_o ||
-  A->getOption().getID() == options::OPT_INPUT ||
-  A->getOption().getID() == options::OPT_x ||
-  A->getOption().getID() == options::OPT_fembed_bitcode ||
-  A->getOption().matches(options::OPT_W_Group))
-continue;
-  ArgStringList ASL;
-  A->render(Args, ASL);
-  for (const auto  : ASL) {
-StringRef ArgStr(arg);
-Opts.CmdArgs.insert(Opts.CmdArgs.end(), ArgStr.begin(), ArgStr.end());
-// using \00 to separate each commandline options.
-Opts.CmdArgs.push_back('\0');
-  }
+  for (const auto  : Args) {
+// Do not encode output and input.
+if (A->getOption().getID() == options::OPT_o ||
+A->getOption().getID() == options::OPT_INPUT ||
+A->getOption().getID() == options::OPT_x ||
+A->getOption().getID() == options::OPT_fembed_bitcode ||
+A->getOption().matches(options::OPT_W_Group))
+  continue;
+ArgStringList ASL;
+A->render(Args, ASL);
+for (const auto  : ASL) {
+  StringRef ArgStr(arg);
+  Opts.CmdArgs.insert(Opts.CmdArgs.end(), ArgStr.begin(), ArgStr.end());
+  // using \00 to separate each commandline options.
+  Opts.CmdArgs.push_back('\0');
 }
   }
 

diff  --git a/clang/test/CodeGen/thinlto_embed_bitcode.ll 
b/clang/test/CodeGen/thinlto_embed_bitcode.ll
index 5f7b9f632af3..6c7e36e7226b 100644
--- a/clang/test/CodeGen/thinlto_embed_bitcode.ll
+++ b/clang/test/CodeGen/thinlto_embed_bitcode.ll
@@ -17,12 +17,20 @@
 ; round-trip through compilation and ensure the objects are the same.
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t.o -x ir %t1.bc -c 
-fthinlto-index=%t.o.thinlto.bc -mllvm -lto-embed-bitcode=post-merge-pre-opt
 ; RUN: llvm-readelf -S %t.o | FileCheck %s 
--check-prefixes=CHECK-ELF,CHECK-ELF-CMD
+; RUN: llvm-objcopy --dump-section=.llvmcmd=%t-embedded.cmd %t.o /dev/null
+; RUN: grep x86_64-unknown-linux-gnu %t-embedded.cmd | count 1
 ; RUN: llvm-objcopy --dump-section=.llvmbc=%t-embedded.bc %t.o /dev/null
 ; RUN: llvm-dis %t-embedded.bc -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-NOOPT
 ; We should only need the index and the post-thinlto merged module to generate 
 ; the exact same .o as we originally did.
 ; RUN: rm %t1.bc %t2.bc
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t-redo.o -x ir 
%t-embedded.bc -c -fthinlto-index=%t.o.thinlto.bc -mllvm 
-lto-embed-bitcode=post-merge-pre-opt -mllvm -thinlto-assume-merged
+;
+; The resulting .o is almost the same, but the .llvmcmd section would be
+; 
diff erent because of the extra -thinlto-assume-merged.
+; A simple, meaningful comparison is to just compare the stripped objects.
+; RUN: llvm-strip --strip-all %t-redo.o 
+; RUN: llvm-strip --strip-all %t.o 
 ; RUN: 
diff  %t-redo.o %t.o
 
 ; CHECK-ELF:  .text   PROGBITS  [[#%x,OFF:]] [[#%x,SIZE:]] 
00 AX 0



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


[clang] 735ab4b - [ThinLTO] Fix .llvmcmd emission

2020-10-28 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-10-28T17:45:30-07:00
New Revision: 735ab4be35695df9f9da7ae8b584cec28eabf1fe

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

LOG: [ThinLTO] Fix .llvmcmd emission

llvm::EmbedBitcodeInModule needs (what used to be called) EmbedMarker
set, in order to emit .llvmcmd. EmbedMarker is really about embedding the
command line, so renamed the parameter accordingly, too.

This was not caught at test because the check-prefix was incorrect, but
FileCheck does not report that when multiple prefixes are provided. A
separate patch will address that.

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

Added: 


Modified: 
clang/test/CodeGen/thinlto_embed_bitcode.ll
llvm/include/llvm/Bitcode/BitcodeWriter.h
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/LTO/LTOBackend.cpp

Removed: 




diff  --git a/clang/test/CodeGen/thinlto_embed_bitcode.ll 
b/clang/test/CodeGen/thinlto_embed_bitcode.ll
index 183a23bb8399..5f7b9f632af3 100644
--- a/clang/test/CodeGen/thinlto_embed_bitcode.ll
+++ b/clang/test/CodeGen/thinlto_embed_bitcode.ll
@@ -9,14 +9,14 @@
 
 ; For the optimized case, we expect the inlining of foo into bar to happen.
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t-opt.o -x ir %t1.bc -c 
-fthinlto-index=%t.o.thinlto.bc -mllvm -lto-embed-bitcode=optimized
-; RUN: llvm-readelf -S %t-opt.o | FileCheck %s 
--check-prefixes=CHECK-ELF,CHECK-NO-CMD
+; RUN: llvm-readelf -S %t-opt.o | FileCheck %s 
--check-prefixes=CHECK-ELF,CHECK-ELF-NO-CMD
 ; RUN: llvm-objcopy --dump-section=.llvmbc=%t-embedded.bc %t-opt.o /dev/null
 ; RUN: llvm-dis %t-embedded.bc -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-OPT
 
 ; For the post-merge case, perform the embedded bitcode extraction, then
 ; round-trip through compilation and ensure the objects are the same.
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t.o -x ir %t1.bc -c 
-fthinlto-index=%t.o.thinlto.bc -mllvm -lto-embed-bitcode=post-merge-pre-opt
-; RUN: llvm-readelf -S %t.o | FileCheck %s --check-prefixes=CHECK-ELF,CHECK-CMD
+; RUN: llvm-readelf -S %t.o | FileCheck %s 
--check-prefixes=CHECK-ELF,CHECK-ELF-CMD
 ; RUN: llvm-objcopy --dump-section=.llvmbc=%t-embedded.bc %t.o /dev/null
 ; RUN: llvm-dis %t-embedded.bc -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-NOOPT
 ; We should only need the index and the post-thinlto merged module to generate 

diff  --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h 
b/llvm/include/llvm/Bitcode/BitcodeWriter.h
index 36c3cb5eb249..7ad2d37a2a35 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -158,11 +158,11 @@ class raw_ostream;
   /// pass an empty (default-initialized) MemoryBufferRef, and the 
serialization
   /// will be handled by this API. The same behavior happens if the provided 
Buf
   /// is not bitcode (i.e. if it's invalid data or even textual LLVM assembly).
-  /// If EmbedMarker is set, the command line is also exported in
+  /// If EmbedCmdline is set, the command line is also exported in
   /// the corresponding section (__LLVM,_cmdline / .llvmcmd) - even if CmdArgs
   /// were empty.
   void EmbedBitcodeInModule(Module , MemoryBufferRef Buf, bool EmbedBitcode,
-bool EmbedMarker,
+bool EmbedCmdline,
 const std::vector );
 
 } // end namespace llvm

diff  --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 02fa1ed67680..7dd38a13b0fc 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4834,7 +4834,7 @@ static const char *getSectionNameForCommandline(const 
Triple ) {
 }
 
 void llvm::EmbedBitcodeInModule(llvm::Module , llvm::MemoryBufferRef Buf,
-bool EmbedBitcode, bool EmbedMarker,
+bool EmbedBitcode, bool EmbedCmdline,
 const std::vector ) {
   // Save llvm.compiler.used and remove it.
   SmallVector UsedArray;
@@ -4892,7 +4892,7 @@ void llvm::EmbedBitcodeInModule(llvm::Module , 
llvm::MemoryBufferRef Buf,
   }
 
   // Skip if only bitcode needs to be embedded.
-  if (EmbedMarker) {
+  if (EmbedCmdline) {
 // Embed command-line options.
 ArrayRef CmdData(const_cast(CmdArgs.data()),
   CmdArgs.size());

diff  --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index f4da6d87f719..7f437a2af5f1 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -373,8 +373,7 @@ bool opt(const Config , TargetMachine *TM, unsigned 
Task, Module ,
   dbgs() << "Post-(Thin)LTO merge bitcode embedding was requested, but 
"
   

[clang] 6fa3554 - [NFC][ThinLTO] Change command line passing to EmbedBitcodeInModule

2020-10-28 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-10-28T12:33:39-07:00
New Revision: 6fa35541a0af9d5493e288f574896ee33a8eae92

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

LOG: [NFC][ThinLTO] Change command line passing to EmbedBitcodeInModule

Changing to pass by ref - less null checks to worry about.

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

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Bitcode/BitcodeWriter.h
llvm/include/llvm/LTO/LTOBackend.h
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/LTO/LTOBackend.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 0991582005b8..918411b818be 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1625,7 +1625,7 @@ static void runThinLTOBackend(
   if (Error E =
   thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
   ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
-  ModuleMap, )) {
+  ModuleMap, CGOpts.CmdArgs)) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });
@@ -1709,5 +1709,5 @@ void clang::EmbedBitcode(llvm::Module *M, const 
CodeGenOptions ,
   llvm::EmbedBitcodeInModule(
   *M, Buf, CGOpts.getEmbedBitcode() != CodeGenOptions::Embed_Marker,
   CGOpts.getEmbedBitcode() != CodeGenOptions::Embed_Bitcode,
-  );
+  CGOpts.CmdArgs);
 }

diff  --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h 
b/llvm/include/llvm/Bitcode/BitcodeWriter.h
index 74e9d103b7f3..36c3cb5eb249 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -152,14 +152,18 @@ class raw_ostream;
 const std::map
 *ModuleToSummariesForIndex = nullptr);
 
-  /// Save a copy of the llvm IR as data in the __LLVM,__bitcode section.
+  /// If EmbedBitcode is set, save a copy of the llvm IR as data in the
+  ///  __LLVM,__bitcode section (.llvmbc on non-MacOS).
   /// If available, pass the serialized module via the Buf parameter. If not,
   /// pass an empty (default-initialized) MemoryBufferRef, and the 
serialization
   /// will be handled by this API. The same behavior happens if the provided 
Buf
   /// is not bitcode (i.e. if it's invalid data or even textual LLVM assembly).
+  /// If EmbedMarker is set, the command line is also exported in
+  /// the corresponding section (__LLVM,_cmdline / .llvmcmd) - even if CmdArgs
+  /// were empty.
   void EmbedBitcodeInModule(Module , MemoryBufferRef Buf, bool EmbedBitcode,
 bool EmbedMarker,
-const std::vector *CmdArgs);
+const std::vector );
 
 } // end namespace llvm
 

diff  --git a/llvm/include/llvm/LTO/LTOBackend.h 
b/llvm/include/llvm/LTO/LTOBackend.h
index 63414b5c80dc..db3c8c092ef9 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -45,7 +45,7 @@ Error thinBackend(const Config , unsigned Task, AddStreamFn 
AddStream,
   const FunctionImporter::ImportMapTy ,
   const GVSummaryMapTy ,
   MapVector ,
-  const std::vector *CmdArgs = nullptr);
+  const std::vector  = 
std::vector());
 
 Error finalizeOptimizationRemarks(
 std::unique_ptr DiagOutputFile);

diff  --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index d64dcd33d1bf..7cfa45812855 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4819,7 +4819,7 @@ static const char *getSectionNameForCommandline(const 
Triple ) {
 
 void llvm::EmbedBitcodeInModule(llvm::Module , llvm::MemoryBufferRef Buf,
 bool EmbedBitcode, bool EmbedMarker,
-const std::vector *CmdArgs) {
+const std::vector ) {
   // Save llvm.compiler.used and remove it.
   SmallVector UsedArray;
   SmallPtrSet UsedGlobals;
@@ -4878,8 +4878,8 @@ void llvm::EmbedBitcodeInModule(llvm::Module , 
llvm::MemoryBufferRef Buf,
   // Skip if only bitcode needs to be embedded.
   if (EmbedMarker) {
 // Embed command-line options.
-ArrayRef CmdData(const_cast(CmdArgs->data()),
-  CmdArgs->size());
+ArrayRef CmdData(const_cast(CmdArgs.data()),
+  CmdArgs.size());
 llvm::Constant *CmdConstant =
 llvm::ConstantDataArray::get(M.getContext(), CmdData);
 GV = new llvm::GlobalVariable(M, CmdConstant->getType(), 

[clang] 2719287 - Add REQUIRES to embed-bitcode-noopt.ll

2020-09-23 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-09-23T10:13:09-07:00
New Revision: 271928792e8016109fdd909889dc6bb582aa6f46

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

LOG: Add REQUIRES to embed-bitcode-noopt.ll

Added: 


Modified: 
clang/test/Frontend/embed-bitcode-noopt.ll

Removed: 




diff  --git a/clang/test/Frontend/embed-bitcode-noopt.ll 
b/clang/test/Frontend/embed-bitcode-noopt.ll
index ecb676ded1bb..61016b4367e7 100644
--- a/clang/test/Frontend/embed-bitcode-noopt.ll
+++ b/clang/test/Frontend/embed-bitcode-noopt.ll
@@ -1,5 +1,6 @@
 ; Ensure calling bypassing the driver with -fembed-bitcode embeds bitcode pre-
 ; optimizations
+; REQUIRES: x86-registered-target
 
 ; RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -emit-obj %s -o %t.o 
-fembed-bitcode=all
 ; RUN: llvm-objcopy --dump-section=.llvmbc=%t.bc %t.o /dev/null



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


[clang] 437358b - [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt bitcode.

2020-09-23 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-09-23T09:35:28-07:00
New Revision: 437358be7179d570de070bbb9b2e1154db727f6d

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

LOG: [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt 
bitcode.

This is important to not regress because it allows us to capture 
pre-optimization
bitcode and options, and replay the full optimization pipeline.

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

Added: 
clang/test/Frontend/embed-bitcode-noopt.c
clang/test/Frontend/embed-bitcode-noopt.ll

Modified: 


Removed: 




diff  --git a/clang/test/Frontend/embed-bitcode-noopt.c 
b/clang/test/Frontend/embed-bitcode-noopt.c
new file mode 100644
index ..06ceaaf80710
--- /dev/null
+++ b/clang/test/Frontend/embed-bitcode-noopt.c
@@ -0,0 +1,30 @@
+// Ensure calling bypassing the driver with -fembed-bitcode embeds bitcode pre-
+// optimizations
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -O2 -emit-obj -triple=x86_64-unknown-linux-gnu -o %t.o 
-fembed-bitcode=all
+// RUN: llvm-objcopy --dump-section=.llvmbc=%t.bc %t.o /dev/null
+
+// Also check that the .llvmcmd section captures the optimization options.
+// RUN: llvm-dis %t.bc -o - | FileCheck %s --check-prefix=CHECK-BC
+// RUN: llvm-objcopy --dump-section=.llvmcmd=- %t.o /dev/null | FileCheck %s 
--check-prefix=CHECK-CMD
+
+// CHECK-BC-LABEL: define void @bar() #0 {
+// CHECK-BC-NEXT: entry:
+// CHECK-BC-NEXT: ret void
+// CHECK-BC-NEXT: }
+// CHECK-BC-LABEL: define void @foo() #1 {
+// CHECK-BC-NEXT: entry:
+// CHECK-BC-NEXT: call void @bar()
+// CHECK-BC-NEXT: ret void
+// CHECK-BC-NEXT: }
+// CHECK-BC-LABEL: attributes #0 = {{.*}} alwaysinline
+// CHECK-CMD: -O2
+
+__attribute__((always_inline)) void bar() {
+  return;
+}
+
+void foo() {
+  bar();
+  return;
+}

diff  --git a/clang/test/Frontend/embed-bitcode-noopt.ll 
b/clang/test/Frontend/embed-bitcode-noopt.ll
new file mode 100644
index ..ecb676ded1bb
--- /dev/null
+++ b/clang/test/Frontend/embed-bitcode-noopt.ll
@@ -0,0 +1,30 @@
+; Ensure calling bypassing the driver with -fembed-bitcode embeds bitcode pre-
+; optimizations
+
+; RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -emit-obj %s -o %t.o 
-fembed-bitcode=all
+; RUN: llvm-objcopy --dump-section=.llvmbc=%t.bc %t.o /dev/null
+
+; Also check that the .llvmcmd section captures the optimization options.
+; RUN: llvm-dis %t.bc -o - | FileCheck %s --check-prefix=CHECK-BC
+; RUN: llvm-objcopy --dump-section=.llvmcmd=- %t.o /dev/null | FileCheck %s 
--check-prefix=CHECK-CMD
+
+; CHECK-BC-LABEL: define void @bar() #0 {
+; CHECK-BC-NEXT:  ret void  
+; CHECK-BC-NEXT: }
+; CHECK-BC-LABEL: define void @foo() {
+; CHECK-BC-NEXT: call void @bar()
+; CHECK-BC-NEXT: ret void
+; CHECK-BC-NEXT: }
+; CHECK-BC-LABEL: attributes #0 = { alwaysinline }
+; CHECK-CMD: -O2
+
+define void @bar() #0 {
+ret void
+}
+
+define void @foo() {
+  call void @bar()
+  ret void
+}
+
+attributes #0 = { alwaysinline }



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


[clang] cf11238 - [ThinLTO] Option to bypass function importing.

2020-09-22 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-09-22T13:12:11-07:00
New Revision: cf112382ddd0d717edf0b8a3e5b061de925258e9

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

LOG: [ThinLTO] Option to bypass function importing.

This completes the circle, complementing -lto-embed-bitcode
(specifically, post-merge-pre-opt). Using -thinlto-assume-merged skips
function importing. The index file is still needed for the other data it
contains.

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

Added: 


Modified: 
clang/include/clang/CodeGen/BackendUtil.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CodeGenAction.cpp
clang/test/CodeGen/thinlto_embed_bitcode.ll
llvm/include/llvm/LTO/LTOBackend.h
llvm/lib/LTO/LTOBackend.cpp

Removed: 




diff  --git a/clang/include/clang/CodeGen/BackendUtil.h 
b/clang/include/clang/CodeGen/BackendUtil.h
index 01b1f5bbd6ee..43de07cc145b 100644
--- a/clang/include/clang/CodeGen/BackendUtil.h
+++ b/clang/include/clang/CodeGen/BackendUtil.h
@@ -45,11 +45,6 @@ namespace clang {
 
   void EmbedBitcode(llvm::Module *M, const CodeGenOptions ,
 llvm::MemoryBufferRef Buf);
-
-  llvm::Expected
-  FindThinLTOModule(llvm::MemoryBufferRef MBRef);
-  llvm::BitcodeModule *
-  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 01f7e239f790..44f0434f2021 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1497,29 +1497,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
 DwoOS->keep();
 }
 
-Expected clang::FindThinLTOModule(MemoryBufferRef MBRef) {
-  Expected> BMsOrErr = getBitcodeModuleList(MBRef);
-  if (!BMsOrErr)
-return BMsOrErr.takeError();
-
-  // The bitcode file may contain multiple modules, we want the one that is
-  // marked as being the ThinLTO module.
-  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
-return *Bm;
-
-  return make_error("Could not find module summary",
- inconvertibleErrorCode());
-}
-
-BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
-  for (BitcodeModule  : BMs) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return 
-  }
-  return nullptr;
-}
-
 static void runThinLTOBackend(
 DiagnosticsEngine , ModuleSummaryIndex *CombinedIndex, Module *M,
 const HeaderSearchOptions , const CodeGenOptions ,
@@ -1536,46 +1513,12 @@ static void runThinLTOBackend(
   // we should only invoke this using the individual indexes written out
   // via a WriteIndexesThinBackend.
   FunctionImporter::ImportMapTy ImportList;
-  for (auto  : *CombinedIndex) {
-// Ignore entries for undefined references.
-if (GlobalList.second.SummaryList.empty())
-  continue;
-
-auto GUID = GlobalList.first;
-for (auto  : GlobalList.second.SummaryList) {
-  // Skip the summaries for the importing module. These are included to
-  // e.g. record required linkage changes.
-  if (Summary->modulePath() == M->getModuleIdentifier())
-continue;
-  // Add an entry to provoke importing by thinBackend.
-  ImportList[Summary->modulePath()].insert(GUID);
-}
-  }
-
   std::vector> OwnedImports;
   MapVector ModuleMap;
+  if (!lto::loadReferencedModules(*M, *CombinedIndex, ImportList, ModuleMap,
+  OwnedImports))
+return;
 
-  for (auto  : ImportList) {
-ErrorOr> MBOrErr =
-llvm::MemoryBuffer::getFile(I.first());
-if (!MBOrErr) {
-  errs() << "Error loading imported file '" << I.first()
- << "': " << MBOrErr.getError().message() << "\n";
-  return;
-}
-
-Expected BMOrErr = FindThinLTOModule(**MBOrErr);
-if (!BMOrErr) {
-  handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase ) {
-errs() << "Error loading imported file '" << I.first()
-   << "': " << EIB.message() << '\n';
-  });
-  return;
-}
-ModuleMap.insert({I.first(), *BMOrErr});
-
-OwnedImports.push_back(std::move(*MBOrErr));
-  }
   auto AddStream = [&](size_t Task) {
 return std::make_unique(std::move(OS));
   };

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index eda4beff78b7..5ea2fc23ee11 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -35,6 +35,7 @@
 #include "llvm/IR/LLVMRemarkStreamer.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IRReader/IRReader.h"
+#include "llvm/LTO/LTOBackend.h"
 #include "llvm/Linker/Linker.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -1066,7 +1067,7 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
 

[clang] 8ea7ef8 - [ThinLTO] Relax thinlto_embed_bitcode.ll check

2020-09-15 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-09-15T22:42:22-07:00
New Revision: 8ea7ef8eda93aa144c339275fc6d9db2615a0118

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

LOG: [ThinLTO] Relax thinlto_embed_bitcode.ll check

Fixes fuscia test [1] - the thinlto annotations may not always be there.

[1] http://lab.llvm.org:8011/builders/fuchsia-x86_64-linux/builds/11312

Added: 


Modified: 
clang/test/CodeGen/thinlto_embed_bitcode.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto_embed_bitcode.ll 
b/clang/test/CodeGen/thinlto_embed_bitcode.ll
index 4efb525e5f3e..2d60e16e54e1 100644
--- a/clang/test/CodeGen/thinlto_embed_bitcode.ll
+++ b/clang/test/CodeGen/thinlto_embed_bitcode.ll
@@ -26,5 +26,5 @@
 ; CHECK:  define void @foo() 
 ; CHECK-OPT-NEXT:   ret void
 ; CHECK-NOOPT-NEXT: call void @bar()
-; CHECK-NOOPT: define available_externally void @bar() !thinlto_src_module !0 {
+; CHECK-NOOPT: define available_externally void @bar()
 ; CHECK-NOOPT-NEXT: ret void



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


[clang] 61fc10d - [ThinLTO] add post-thinlto-merge option to -lto-embed-bitcode

2020-09-15 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-09-15T15:56:11-07:00
New Revision: 61fc10d6a520f267e11009ce8fce88d73615796b

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

LOG: [ThinLTO] add post-thinlto-merge option to -lto-embed-bitcode

This will embed bitcode after (Thin)LTO merge, but before optimizations.
In the case the thinlto backend is called from clang, the .llvmcmd
section is also produced. Doing so in the case where the caller is the
linker doesn't yet have a motivation, and would require plumbing through
command line args.

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

Added: 
clang/test/CodeGen/Inputs/start-lib1.ll
clang/test/CodeGen/Inputs/start-lib2.ll
clang/test/CodeGen/thinlto_embed_bitcode.ll

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/LTO/LTOBackend.h
llvm/lib/LTO/LTOBackend.cpp
llvm/test/LTO/X86/Inputs/start-lib1.ll
llvm/test/LTO/X86/embed-bitcode.ll

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 5fc80d4fae71..01f7e239f790 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1647,9 +1647,10 @@ static void runThinLTOBackend(
 Conf.CGFileType = getCodeGenFileType(Action);
 break;
   }
-  if (Error E = thinBackend(
-  Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
-  ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) {
+  if (Error E =
+  thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
+  ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
+  ModuleMap, )) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });

diff  --git a/clang/test/CodeGen/Inputs/start-lib1.ll 
b/clang/test/CodeGen/Inputs/start-lib1.ll
new file mode 100644
index ..18b6ea25386f
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/start-lib1.ll
@@ -0,0 +1,9 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @bar()
+
+define void @foo() {
+  call void @bar()
+  ret void
+}

diff  --git a/clang/test/CodeGen/Inputs/start-lib2.ll 
b/clang/test/CodeGen/Inputs/start-lib2.ll
new file mode 100644
index ..68b3c8362808
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/start-lib2.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @bar() {
+  ret void
+}

diff  --git a/clang/test/CodeGen/thinlto_embed_bitcode.ll 
b/clang/test/CodeGen/thinlto_embed_bitcode.ll
new file mode 100644
index ..4efb525e5f3e
--- /dev/null
+++ b/clang/test/CodeGen/thinlto_embed_bitcode.ll
@@ -0,0 +1,30 @@
+; REQUIRES: x86-registered-target
+
+; check the -lto-embed-bitcode=post-thinlto-merge does not perform 
optimizations
+; we expect 't1' - i.e start-lib1.ll's products - have both foo and bar 
defined,
+; but the bar call is still made from foo.
+; RUN: opt -module-summary %p/Inputs/start-lib1.ll -o %t1.bc
+; RUN: opt -module-summary %p/Inputs/start-lib2.ll -o %t2.bc
+; RUN: llvm-lto -thinlto -o %t.o %t1.bc %t2.bc
+
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t.o -x ir %t1.bc -c 
-fthinlto-index=%t.o.thinlto.bc -mllvm -lto-embed-bitcode=post-merge-pre-opt
+; RUN: llvm-readelf -S %t.o | FileCheck %s --check-prefixes=CHECK-ELF,CHECK-CMD
+; RUN: llvm-objcopy --dump-section=.llvmbc=%t-embedded.bc %t.o /dev/null
+; RUN: llvm-dis %t-embedded.bc -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-NOOPT
+
+; For the optimized case, we expect the inlining of foo into bar to happen.
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t.o -x ir %t1.bc -c 
-fthinlto-index=%t.o.thinlto.bc -mllvm -lto-embed-bitcode=optimized
+; RUN: llvm-readelf -S %t.o | FileCheck %s 
--check-prefixes=CHECK-ELF,CHECK-NO-CMD
+; RUN: llvm-objcopy --dump-section=.llvmbc=%t-embedded.bc %t.o /dev/null
+; RUN: llvm-dis %t-embedded.bc -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-OPT
+
+; CHECK-ELF:  .text   PROGBITS  [[#%x,OFF:]] [[#%x,SIZE:]] 
00 AX 0
+; CHECK-ELF-NEXT: .llvmbc PROGBITS  [[#%x,OFF:]] [[#%x,SIZE:]] 
000
+; CHECK-ELF-CMD:  .llvmcmd
+; CHECK-ELF-NO-CMD-NOT: .llvmcmd
+
+; CHECK:  define void @foo() 
+; CHECK-OPT-NEXT:   ret void
+; CHECK-NOOPT-NEXT: call void @bar()
+; CHECK-NOOPT: define available_externally void @bar() !thinlto_src_module !0 {
+; CHECK-NOOPT-NEXT: ret void

diff  --git a/llvm/include/llvm/LTO/LTOBackend.h 
b/llvm/include/llvm/LTO/LTOBackend.h
index 0226e4a3fbf5..735969c47039 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ 

[clang] 7acfda6 - [llvm] Make new pass manager's OptimizationLevel a class

2020-01-16 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-01-16T09:00:56-08:00
New Revision: 7acfda633f1378344efde22bfed242dd56c26cdd

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

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

Summary:
The old pass manager separated speed optimization and size optimization
levels into two unsigned values. Coallescing both in an enum in the new
pass manager may lead to unintentional casts and comparisons.

In particular, taking a look at how the loop unroll passes were constructed
previously, the Os/Oz are now (==new pass manager) treated just like O3,
likely unintentionally.

This change disallows raw comparisons between optimization levels, to
avoid such unintended effects. As an effect, the O{s|z} behavior changes
for loop unrolling and loop unroll and jam, matching O2 rather than O3.

The change also parameterizes the threshold values used for loop
unrolling, primarily to aid testing.

Reviewers: tejohnson, davidxl

Reviewed By: tejohnson

Subscribers: zzheng, ychen, mehdi_amini, hiraditya, steven_wu, dexonsmith, 
dang, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 
llvm/test/Transforms/LoopUnroll/opt-levels.ll
llvm/test/Transforms/LoopUnrollAndJam/opt-levels.ll

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 0bfcab88a3a9..f379c103b694 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -924,7 +924,7 @@ static PassBuilder::OptimizationLevel mapToLevel(const 
CodeGenOptions ) {
 llvm_unreachable("Invalid optimization level!");
 
   case 1:
-return PassBuilder::O1;
+return PassBuilder::OptimizationLevel::O1;
 
   case 2:
 switch (Opts.OptimizeSize) {
@@ -932,17 +932,17 @@ static PassBuilder::OptimizationLevel mapToLevel(const 
CodeGenOptions ) {
   llvm_unreachable("Invalid optimization level for size!");
 
 case 0:
-  return PassBuilder::O2;
+  return PassBuilder::OptimizationLevel::O2;
 
 case 1:
-  return PassBuilder::Os;
+  return PassBuilder::OptimizationLevel::Os;
 
 case 2:
-  return PassBuilder::Oz;
+  return PassBuilder::OptimizationLevel::Oz;
 }
 
   case 3:
-return PassBuilder::O3;
+return PassBuilder::OptimizationLevel::O3;
   }
 }
 

diff  --git a/llvm/include/llvm/Passes/PassBuilder.h 
b/llvm/include/llvm/Passes/PassBuilder.h
index e7db8fd421fe..828ac004117e 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -143,11 +143,26 @@ class PassBuilder {
   ///
   /// This enumerates the LLVM-provided high-level optimization levels. Each
   /// level has a specific goal and rationale.
-  enum OptimizationLevel {
+  class OptimizationLevel final {
+unsigned SpeedLevel = 2;
+unsigned SizeLevel = 0;
+OptimizationLevel(unsigned SpeedLevel, unsigned SizeLevel)
+: SpeedLevel(SpeedLevel), SizeLevel(SizeLevel) {
+  // Check that only valid combinations are passed.
+  assert(SpeedLevel <= 3 &&
+ "Optimization level for speed should be 0, 1, 2, or 3");
+  assert(SizeLevel <= 2 &&
+ "Optimization level for size should be 0, 1, or 2");
+  assert((SizeLevel == 0 || SpeedLevel == 2) &&
+ "Optimize for size should be encoded with speedup level == 2");
+}
+
+  public:
+OptimizationLevel() = default;
 /// Disable as many optimizations as possible. This doesn't completely
 /// disable the optimizer in all cases, for example always_inline functions
 /// can be required to be inlined for correctness.
-O0,
+static const OptimizationLevel O0;
 
 /// Optimize quickly without destroying debuggability.
 ///
@@ -161,10 +176,9 @@ class PassBuilder {
 ///
 /// As an example, complex loop transformations such as versioning,
 /// vectorization, or fusion don't make sense here due to the degree to
-/// which the executed code 
diff ers from the source code, and the compile time
-/// cost.
-O1,
-
+/// which the executed code 
diff ers from the source code, and the compile
+/// time cost.
+static const OptimizationLevel O1;
 /// Optimize for fast execution as much as possible without triggering
 /// significant incremental compile time or code size growth.
 ///
@@ -181,8 +195,7 @@ class PassBuilder {
 ///
 /// This is expected to be a good default optimization level for the vast
 /// majority of users.
-O2,
-
+static