platform/upstream/llvm.git
2 years ago[ELF] Support --oformat= beside Separate --oformat
Fangrui Song [Mon, 29 Nov 2021 02:44:23 +0000 (18:44 -0800)]
[ELF] Support --oformat= beside Separate --oformat

Both GNU ld's manpage and ours use --oformat= as the canonical form.
It's odd that we do not support it...

2 years ago[ELF][test] --oformat binary: Check that SIZEOF_HEADERS==0
Fangrui Song [Mon, 29 Nov 2021 02:33:55 +0000 (18:33 -0800)]
[ELF][test] --oformat binary: Check that SIZEOF_HEADERS==0

2 years agotest: add a lit configuration for Windows subdirectory
Saleem Abdulrasool [Mon, 29 Nov 2021 02:21:57 +0000 (18:21 -0800)]
test: add a lit configuration for Windows subdirectory

This adds a local configuration to the Windows subdirectory to filter
out the tests on non-Windows platforms using the lit filtering.

2 years ago[llvm] Use range-based for loops (NFC)
Kazu Hirata [Mon, 29 Nov 2021 02:14:49 +0000 (18:14 -0800)]
[llvm] Use range-based for loops (NFC)

2 years ago[mlir][python] Normalize asm-printing IR behavior.
Stella Laurenzo [Sun, 28 Nov 2021 23:33:03 +0000 (15:33 -0800)]
[mlir][python] Normalize asm-printing IR behavior.

While working on an integration, I found a lot of inconsistencies on IR printing and verification. It turns out that we were:
  * Only doing "soft fail" verification on IR printing of Operation, not of a Module.
  * Failed verification was interacting badly with binary=True IR printing (causing a TypeError trying to pass an `str` to a `bytes` based handle).
  * For systematic integrations, it is often desirable to control verification yourself so that you can explicitly handle errors.

This patch:
  * Trues up the "soft fail" semantics by having `Module.__str__` delegate to `Operation.__str__` vs having a shortcut implementation.
  * Fixes soft fail in the presence of binary=True (and adds an additional happy path test case to make sure the binary functionality works).
  * Adds an `assume_verified` boolean flag to the `print`/`get_asm` methods which disables internal verification, presupposing that the caller has taken care of it.

It turns out that we had a number of tests which were generating illegal IR but it wasn't being caught because they were doing a print on the `Module` vs operation. All except two were trivially fixed:
  * linalg/ops.py : Had two tests for direct constructing a Matmul incorrectly. Fixing them made them just like the next two tests so just deleted (no need to test the verifier only at this level).
  * linalg/opdsl/emit_structured_generic.py : Hand coded conv and pooling tests appear to be using illegal shaped inputs/outputs, causing a verification failure. I just used the `assume_verified=` flag to restore the original behavior and left a TODO. Will get someone who owns that to fix it properly in a followup (would also be nice to break this file up into multiple test modules as it is hard to tell exactly what is failing).

Notes to downstreams:
  * If, like some of our tests, you get verification failures after this patch, it is likely that your IR was always invalid and you will need to fix the root cause. To temporarily revert to prior (broken) behavior, replace calls like `print(module)` with `print(module.operation.get_asm(assume_verified=True))`.

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

2 years ago[ELF] Simplify/remove LinkerScript::output and advance. NFC
Fangrui Song [Mon, 29 Nov 2021 00:58:06 +0000 (16:58 -0800)]
[ELF] Simplify/remove LinkerScript::output and advance. NFC

2 years agoCompilation Database: Point Bazel users to a solution
Nathan Ridge [Mon, 29 Nov 2021 00:29:06 +0000 (19:29 -0500)]
Compilation Database: Point Bazel users to a solution

This doc lists ways of getting compilation databases out of some popular build systems for use with clangd and other tooling.

We built such a way for Bazel and just released it after a bunch of requests on GitHub. Thought I should propose that we add a link to help people find it and use clang tooling.

(This is my first revision submitted via LLVM Phabricator, so if I've messed something up, I'd really appreciate your help and patience. Asking for a review from Sam McCall, because I've had a great time working with him elsewhere on GitHub before and because I saw him in the Git history for this file.)

Reviewed By: sammccall

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

2 years ago[ELF] Remove unneeded getOutputSectionVA. NFC
Fangrui Song [Mon, 29 Nov 2021 00:17:10 +0000 (16:17 -0800)]
[ELF] Remove unneeded getOutputSectionVA. NFC

I attempted to remove it 1 or 2 year ago but kept it just to have a good
diagnostic in case the output section is nullptr (should be impossible).
It is long enough that we haven't seen such a case.

2 years ago[ELF] Inline InputSection::getOffset into callers and remove it. NFC
Fangrui Song [Mon, 29 Nov 2021 00:09:04 +0000 (16:09 -0800)]
[ELF] Inline InputSection::getOffset into callers and remove it. NFC

This is an unneeded abstraction which may cause confusion:
SectionBase::getOffset has the same name but hard codes -1 as the size of OutputSection.

2 years ago[Driver] Support PowerPC SPE musl dynamic linker name ld-musl-powerpc-sf.so.1
Patrick Oppenlander [Sun, 28 Nov 2021 23:39:55 +0000 (15:39 -0800)]
[Driver] Support PowerPC SPE musl dynamic linker name ld-musl-powerpc-sf.so.1

Musl treats PowerPC SPE as a soft-float target (as the PowerPC SPE ABI
is soft-float compatible).

Reviewed By: jhibbits, MaskRay

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

2 years ago[ELF] Replace one make_unique from r316378 with a stack object. NFC
Fangrui Song [Sun, 28 Nov 2021 23:32:29 +0000 (15:32 -0800)]
[ELF] Replace one make_unique from r316378 with a stack object. NFC

2 years ago[ELF] Simplify OutputSection::sectionIndex assignment. NFC
Fangrui Song [Sun, 28 Nov 2021 22:56:29 +0000 (14:56 -0800)]
[ELF] Simplify OutputSection::sectionIndex assignment. NFC

And improve comments.

2 years ago[ELF] Fix out-of-bounds write in memset(&Out::first, ...)
Fangrui Song [Sun, 28 Nov 2021 22:47:57 +0000 (14:47 -0800)]
[ELF] Fix out-of-bounds write in memset(&Out::first, ...)

Fix r285764: there is no guarantee that Out::first is placed before other
static data members of `struct Out`. After `bufferStart` was introduced, this
out-of-bounds write is destined in many compilers. It is likely benign, though.

And move `Out::elfHeader->size` assignment beside `Out::elfHeader->sectionIndex`

2 years ago[ELF] Simplify assignFileOffsets
Fangrui Song [Sun, 28 Nov 2021 21:44:41 +0000 (13:44 -0800)]
[ELF] Simplify assignFileOffsets

There is a difference with non-SHF_ALLOC SHT_NOBITS when off%sh_addralign!=0
which doesn't happen/matter in practice.

2 years ago[mlir] NFC - Move invalid.mlir tests to the proper dialects
Nicolas Vasilache [Sun, 28 Nov 2021 21:26:29 +0000 (21:26 +0000)]
[mlir] NFC - Move invalid.mlir tests to the proper dialects

2 years ago[AArch64] Avoid crashing on invalid -Wa,-march= values
Dimitry Andric [Sun, 28 Nov 2021 17:09:06 +0000 (18:09 +0100)]
[AArch64] Avoid crashing on invalid -Wa,-march= values

As reported in https://bugs.freebsd.org/260078, the gnutls Makefiles
pass -Wa,-march=all to compile a number of assembly files. Clang does
not support this -march value, but because of a mistake in handling
the arguments, an unitialized Arg pointer is dereferenced, which can
cause a segfault.

Work around this by adding a check if the local WaMArch variable is
initialized, and if so, using its value in the diagnostic message.

Reviewed By: tschuett

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

2 years ago[DSE] Use MapVector for IOLs
Nikita Popov [Sun, 28 Nov 2021 20:53:25 +0000 (21:53 +0100)]
[DSE] Use MapVector for IOLs

I'm not sure whether this can cause any actual non-determinism,
but at least it makes the DSE debug log non-deterministic, which
makes it harder to debug other non-determinism issues.

2 years ago[ELF] -z separate-*: Use max-page-size instead of common-page-size for text/non-SHF_A...
Fangrui Song [Sun, 28 Nov 2021 20:47:49 +0000 (12:47 -0800)]
[ELF] -z separate-*: Use max-page-size instead of common-page-size for text/non-SHF_ALLOC transition and writeTrapInstr

For -z separate-code and -z separate-loadable-segments:

When RW is present, the RX to RW transition is aligned with max-page-size.
When RW is absent, the RX to non-SHF_ALLOC transition should use max-page-size as well.

2 years ago[ELF] Simplify assignFileOffsets. NFC
Fangrui Song [Sun, 28 Nov 2021 19:43:59 +0000 (11:43 -0800)]
[ELF] Simplify assignFileOffsets. NFC

2 years ago[LV] Move code from widenGEP to VPWidenGEPRecipe (NFC).
Florian Hahn [Sun, 28 Nov 2021 18:29:18 +0000 (18:29 +0000)]
[LV] Move code from widenGEP to VPWidenGEPRecipe (NFC).

The code in widenGEP has already been transitioned to only rely on
information provided by VPWidenGEPRecipe directly.

Moving the code directly to VPWidenGEPRecipe::execute completes
the transition for the recipe.

It provides the following advantages:

1. Less indirection, easier to see what's going on.
2. Removes accesses to fields of ILV.

2) in particular ensures that no dependencies on
fields in ILV for GEP code generation are re-introduced.

Reviewed By: Ayal

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

2 years ago[llvm] Use range-based for loops (NFC)
Kazu Hirata [Sun, 28 Nov 2021 18:04:54 +0000 (10:04 -0800)]
[llvm] Use range-based for loops (NFC)

2 years ago[clang] Fix -Wreturn-type false positive in @try statements
Nico Weber [Fri, 26 Nov 2021 21:16:18 +0000 (16:16 -0500)]
[clang] Fix -Wreturn-type false positive in @try statements

After 04f30795f16638, -Wreturn-type has an effect on functions that
contain @try/@catch statements. CheckFallThrough() was missing
a case for ObjCAtTryStmts, leading to a false positive.

(What about the other two places in CheckFallThrough() that handle
CXXTryStmt but not ObjCAtTryStmts?

- I think the last use of CXXTryStmt is dead in practice: 04c6851cd made it so
  that calls never add edges to try bodies, and the CFG block for a try
  statement is always an empty block containing just the try element itself as
  terminator (the try body itself is part of the normal flow of the function
  and not connected to the block for the try statement itself. The try statment
  cfg block is only connected to the catch bodies, and only reachable from
  throw expressions within the try body.)

- The first use of CXXTryStmt might be important. It looks similar to
  the code that adds all cfg blocks for try statements as roots of
  the reachability graph for the reachability warnings, but I can't
  find a way to trigger it. So I'm omitting it for now. The CXXTryStmt
  code path seems to only be hit by try statements that are function
  bodies without a surrounding compound statements
  (`f() try { ... } catch ...`), and those don't exist for ObjC
  @try statements.
)

Fixes PR52473.

Differential Revfision: https://reviews.llvm.org/D114660

2 years ago[ARM] Add testing for various fptosi.sat patterns. NFC
David Green [Sun, 28 Nov 2021 16:36:17 +0000 (16:36 +0000)]
[ARM] Add testing for various fptosi.sat patterns. NFC

2 years ago[InstCombine] use decomposeBitTestICmp to make icmp (trunc X), C more consistent
Sanjay Patel [Sun, 28 Nov 2021 14:59:37 +0000 (09:59 -0500)]
[InstCombine] use decomposeBitTestICmp to make icmp (trunc X), C more consistent

This is a follow-on suggested in D112634.
Two folds that were added with that patch are subsumed in the call to
decomposeBitTestICmp, and two other folds are potentially inverted.

The deleted folds were very specialized by instcombine standards
because they were restricted to legal integer types based on the data
layout. This generalizes the canonical form independent of target/types.

This change has a reasonable chance of exposing regressions either in
IR or codegen, but I don't have any evidence for either of those yet.
A spot check of asm across several in-tree targets shows variations
that I expect are mostly neutral.

We have one improvement in an existing IR test that I noted with a
comment. Using mask ops might also make more code match with D114272.

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

2 years ago[InstCombine] reduce code duplication; NFC
Sanjay Patel [Sun, 28 Nov 2021 14:21:39 +0000 (09:21 -0500)]
[InstCombine] reduce code duplication; NFC

2 years ago[libc++] Add myself to the credits.
Mark de Wever [Sun, 28 Nov 2021 14:24:45 +0000 (15:24 +0100)]
[libc++] Add myself to the credits.

Noticed while updating the credits for the to_chars patch.

2 years ago[libc++] Remove support for Clang 9 and older.
Mark de Wever [Sun, 28 Nov 2021 12:17:04 +0000 (13:17 +0100)]
[libc++] Remove support for Clang 9 and older.

I encountered this while reviewing an unrelated patch. Will land after
the CI passes.

Reviewed By: #libc, Mordante

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

2 years ago[SCEV] Turn validity check in getExistingSCEV into assert (NFC).
Florian Hahn [Sun, 28 Nov 2021 12:00:55 +0000 (12:00 +0000)]
[SCEV] Turn validity check in getExistingSCEV into assert (NFC).

Now that we track users of SCEV expressions, we should be able to always
invalidate containing expressions.

With that, I think the case where a value gets removed but
SCEVs containing references to it should not be possible any longer.
Turn check into an assert.

This slightly reduces compile-time:

NewPM-O3: -0.27%
NewPM-ReleaseThinLTO: -0.21%
NewPM-ReleaseLTO-g: -0.26%

http://llvm-compile-time-tracker.com/compare.php?from=c3dc6b081da6ba503e67d260033f81f61eb38ea3&to=95a4a028b1f1dd0bc3d221435953b7d2c031b3d5&stat=instructions

Reviewed By: nikic

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

2 years ago[libc++][format] Adds formatting benchmarks.
Mark de Wever [Sun, 26 Sep 2021 15:11:42 +0000 (17:11 +0200)]
[libc++][format] Adds formatting benchmarks.

These benchmarks will be used to test the performance inpact of the next
set of optimization patches.

Reviewed By: ldionne, #libc

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

2 years ago[sanitizer] Remove storeIds and use padding of StackDepotNode
Vitaly Buka [Tue, 23 Nov 2021 23:41:25 +0000 (15:41 -0800)]
[sanitizer] Remove storeIds and use padding of StackDepotNode

Depends on D114489.

Reviewed By: morehouse, dvyukov

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

2 years ago[LV] Fix incorrectly marking a pointer indvar as 'scalar'.
Sander de Smalen [Sun, 21 Nov 2021 20:07:51 +0000 (20:07 +0000)]
[LV] Fix incorrectly marking a pointer indvar as 'scalar'.

collectLoopScalars should only add non-uniform nodes to the list if they
are used by a load/store instruction that is marked as CM_Scalarize.

Before this patch, the LV incorrectly marked pointer induction variables
as 'scalar' when they required to be widened by something else,
such as a compare instruction, and weren't used by a node marked as
'CM_Scalarize'. This case is covered by sve-widen-phi.ll.

This change also allows removing some code where the LV tried to
widen the PHI nodes with a stepvector, even though it was marked as
'scalarAfterVectorization'. Now that this code is more careful about
marking instructions that need widening as 'scalar', this code has
become redundant.

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

2 years agoNFC: Simplify sve-widen-phi.ll by unrolling once.
Sander de Smalen [Mon, 22 Nov 2021 15:50:39 +0000 (15:50 +0000)]
NFC: Simplify sve-widen-phi.ll by unrolling once.

The unroll factor > 1 has little value for what is being tested.

2 years ago[sanitizer] Switch StackStore from pointers to 32bit IDs
Vitaly Buka [Tue, 23 Nov 2021 20:35:39 +0000 (12:35 -0800)]
[sanitizer] Switch StackStore from pointers to 32bit IDs

Depends on D114488.

Reviewed By: morehouse, dvyukov, kstoimenov

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

2 years ago[mlir] Enable MLIRDialectUtilsTests
Chia-hung Duan [Sat, 27 Nov 2021 22:36:42 +0000 (22:36 +0000)]
[mlir] Enable MLIRDialectUtilsTests

Also remove `TooFewDims` test which tried to create an invalid AffineMap.
The creation of an invalid AffineMap is rejected by `willBeValidAffineMap`,
as a result we can deprecate the test.

Reviewed By: bondhugula

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

2 years ago[ARM] CSINC/CSINV patterns from CMOV
David Green [Sat, 27 Nov 2021 20:21:41 +0000 (20:21 +0000)]
[ARM] CSINC/CSINV patterns from CMOV

We sometimes end up generating CMOV with constant operands that can be
simplified to CSINC or CSINV under Arm-8.1m. This adds some simple
patterns for them.

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

2 years ago[Target] Use range-based for loops (NFC)
Kazu Hirata [Sat, 27 Nov 2021 19:16:18 +0000 (11:16 -0800)]
[Target] Use range-based for loops (NFC)

2 years ago[ARM] Fold away unnecessary CSET/CMPZ
David Green [Sat, 27 Nov 2021 19:07:16 +0000 (19:07 +0000)]
[ARM] Fold away unnecessary CSET/CMPZ

Codegen from expanded vector operations can end up with unnecessary
CMPZ/CSINC, of the form:
  CSXYZ A, B, C1 (CMPZ (CSINC 0, 0, C2, D), 0)

These can be converted to remove the CMPZ and CSINC, depending on the
condition.
  if C1==NE -> CSXYZ A, B, C2, D
  if C1==EQ -> CSXYZ A, B, NOT(C2), D

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

2 years ago[PowerPC] Regenerate ppc64-P9-vabsd.ll tests
Simon Pilgrim [Fri, 26 Nov 2021 22:30:22 +0000 (22:30 +0000)]
[PowerPC] Regenerate ppc64-P9-vabsd.ll tests

2 years ago[DwarfCompileUnit] Set parent DIE right after creating a local entity
Kristina Bessonova [Sat, 27 Nov 2021 15:56:40 +0000 (17:56 +0200)]
[DwarfCompileUnit] Set parent DIE right after creating a local entity

No functional changes intended.

Before this patch DwarfCompileUnit::createScopeChildrenDIE() and
DwarfCompileUnit::createAndAddScopeChildrenDIE() used to emit child subtrees
and then when all the children get created, attach them to a parent scope DIE.
However, when a DIE doesn't have a parent, all the requests for its unit DIE
fail.

Currently, this is not a big issue since it isn't usually needed to know unit DIE
for a local (function-scoped) entity. But once we introduce lexical blocks as
a valid scope for global variables (static locals) and type DIEs, any requests
for a unit DIE need to be guarded against local scope due to the potential
absence of the DIE's parent.

To avoid the aforementioned issue, this patch refactors a few DwarfCompileUnit
methods to support the idea of attaching a DIE to its parent as close to the
creation of this DIE as possible.

Reviewed By: ellis

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

2 years ago[SCEV] Simplify forgetSymbolicName() (NFCI)
Nikita Popov [Fri, 19 Nov 2021 17:57:15 +0000 (18:57 +0100)]
[SCEV] Simplify forgetSymbolicName() (NFCI)

With the recently introduced tracking as well as D113349, we can
greatly simplify forgetSymbolicName(). In fact, we can simply
replace it with forgetMemoizedResults().

What forgetSymbolicName() used to do is to walk the IR use-def
chain to find all SCEVs that mention the SymbolicName. However,
thanks to use tracking, we can now determine the relevant SCEVs
in a more direct way. D113349 is needed to also clear out the
actual IR to SCEV mapping in ValueExprMap.

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

2 years ago[SCEV] Simplify invalidation after BE count calculation (NFCI)
Nikita Popov [Sat, 27 Nov 2021 15:17:09 +0000 (16:17 +0100)]
[SCEV] Simplify invalidation after BE count calculation (NFCI)

After backedge taken counts have been calculated, we want to
invalidate all addrecs and dependent expressions in the loop,
because we might compute better results with the newly available
backedge taken counts. Previously this was done with a forgetLoop()
style use-def walk. With recent improvements to SCEV invalidation,
we can instead directly invalidate any SCEVs using addrecs in this
loop. This requires a great deal less subtlety to avoid invalidating
more than necessary, and in particular gets rid of the hack from
D113349. The change is similar to D114263 in spirit.

2 years ago[ARM] Extra testing for v2i1 types. NFC
David Green [Sat, 27 Nov 2021 13:21:09 +0000 (13:21 +0000)]
[ARM] Extra testing for v2i1 types. NFC

This adds extra tests for various operations from making the v2i1 type
legal.

2 years ago[DSE] Optimize defining access of defs while walking upwards.
Florian Hahn [Sat, 27 Nov 2021 13:04:28 +0000 (13:04 +0000)]
[DSE] Optimize defining access of defs while walking upwards.

This patch extends the code that walks memory defs upwards to find
clobbering accesses to also try to optimize the clobbering defining
access.

We should be able to find set the optimized access of our starting def
(KillingDef), if the following holds:

 1. It is the first call of getDomMemoryDef for KillingDef (so Current
    ==  KillingDef->getDefiningAccess().
 2. No potentially aliasing defs are skipped.

Then if a (partly) aliasing def is encountered, it can be used as
optimized access for KillingDef. No further optimizations can be
applied to KillingDef.

I'd appreciate a careful look, as the existing documentation is not too
clear on what is expected for optimized accesses.

The motivation for this patch is to use the optimized accesses to cover
more cases of redundant stores as follow-up to D111727.

Reviewed By: nikic

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

2 years ago[NVPTX][AsmPrinter] Avoid removing globals before calling AsmPrinter::doFinalization()
Kristina Bessonova [Sat, 27 Nov 2021 12:02:34 +0000 (14:02 +0200)]
[NVPTX][AsmPrinter] Avoid removing globals before calling AsmPrinter::doFinalization()

Instead of removing globals from a module, we, it seems, can just override
AsmPrinter::emitGlobalVariable() to do nothing as NVPTXAsmPrinter already
emitted globals by this time and we don't want to do it twice.

Reviewed By: tra

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

2 years agoReland [SCEV] Fix and validate ValueExprMap/ExprValueMap consistency
Nikita Popov [Sat, 30 Oct 2021 19:40:14 +0000 (21:40 +0200)]
Reland [SCEV] Fix and validate ValueExprMap/ExprValueMap consistency

Relative to the previous landing attempt, this introduces an additional
flag on forgetMemoizedResults() to not remove SCEVUnknown phis from
the value map. The invalidation after BECount calculation wants to
leave these alone and skips them in its own use-def walk, but we can
still end up invalidating them via forgetMemoizedResults() if there
is another IR value with the same SCEV. This is intended as a temporary
workaround only, and the need for this should go away once the
getBackedgeTakenInfo() invalidation is refactored in the spirit of
D114263.

-----

This adds validation for consistency of ValueExprMap and
ExprValueMap, and fixes identified issues:

* Addrec construction directly wrote to ValueExprMap in a few places,
  without updating ExprValueMap. Add a helper to ensures they stay
  consistent. The adjustment in forgetSymbolicName() explicitly
  drops the old value from the map, so that we don't rely on it
  being overwritten.
* forgetMemoizedResultsImpl() was dropping the SCEV from
  ExprValueMap, but not dropping the corresponding entries from
  ValueExprMap.

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

2 years ago[ARM] implement support for ALU/LDR PC-relative group relocations
Ard Biesheuvel [Sat, 27 Nov 2021 09:26:37 +0000 (10:26 +0100)]
[ARM] implement support for ALU/LDR PC-relative group relocations

Currently, LLD does not support the complete set of ARM group relocations.
Given that I intend to start using these in the Linux kernel [0], let's add
support for these.

This implements the group processing as documented in the ELF psABI. Notably,
this means support is dropped for very far symbol references that also carry a
small component, where the immediate is rotated in such a way that only part of
it wraps to the other end of the 32-bit word. To me, it seems unlikely that
this is something anyone could be relying on, but of course I could be wrong.

[0] https://lore.kernel.org/r/20211122092816.2865873-8-ardb@kernel.org/

Reviewed By: peter.smith, MaskRay

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

2 years ago[test] Use -passes syntax in Feature/OperandBundles lit tests
Bjorn Pettersson [Thu, 18 Nov 2021 15:55:39 +0000 (16:55 +0100)]
[test] Use -passes syntax in Feature/OperandBundles lit tests

Simply use the new PM syntax instead of the deprecated legacy PM
syntax when specifying the opt pipeline in some regression tests.

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

2 years ago[test] Use -passes in lit tests for the UpdateTestChecks tool
Bjorn Pettersson [Thu, 18 Nov 2021 15:51:19 +0000 (16:51 +0100)]
[test] Use -passes in lit tests for the UpdateTestChecks tool

The UpdateTestChecks tool itself does not care about which pass
manager that is used in the opt invocation. So the lit tests that
are verifying the behavior of the UpdateTestChecks tool is updated
to use the new-PM syntax (-passes=) when specifying the pass pipeline
in the test cases that are used for verifying the UpdateTestChecks
tool.

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

2 years ago[test] Use -passes syntax when specifying pipeline in some more tests
Bjorn Pettersson [Thu, 18 Nov 2021 09:14:04 +0000 (10:14 +0100)]
[test] Use -passes syntax when specifying pipeline in some more tests

The legacy PM is deprecated, so update a bunch of lit tests running
opt to use the new PM syntax when specifying the pipeline.
In this patch focus has been put on test cases for ConstantMerge,
ConstraintElimination, CorrelatedValuePropagation, GlobalDCE,
GlobalOpt, SCCP, TailCallElim and PredicateInfo.

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

2 years ago[RISCV] Emit DWARF location expression for RVV stack objects.
Hsiangkai Wang [Wed, 4 Aug 2021 08:10:05 +0000 (16:10 +0800)]
[RISCV] Emit DWARF location expression for RVV stack objects.

VLENB is the length of a vector register in bytes. We use
<vscale x 64 bits> to represent one vector register. The dwarf offset is
VLENB * scalable_offset / 8.

For the mask vector, it occupies one vector register.

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

2 years ago[Target] Use range-based for loops (NFC)
Kazu Hirata [Sat, 27 Nov 2021 05:21:17 +0000 (21:21 -0800)]
[Target] Use range-based for loops (NFC)

2 years agoFixed broken build under GCC 5.4.
Stanislav Funiak [Sat, 27 Nov 2021 03:33:27 +0000 (09:03 +0530)]
Fixed broken build under GCC 5.4.

This diff fixes broken build caused by D108550. Under GCC 5, auto lambdas that capture this require `this->` for member calls.

Reviewed By: bondhugula

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

2 years ago[ELF][test] Test that .o definition does not inherit .so STV_PROTECTED
Fangrui Song [Fri, 26 Nov 2021 23:00:10 +0000 (15:00 -0800)]
[ELF][test] Test that .o definition does not inherit .so STV_PROTECTED

Test %t2.so %t.o beside %t.o %t2.so

2 years ago[libcxx][NFC] Add tests for associative containers key_comp and value_comp
Konstantin Boyarinov [Fri, 26 Nov 2021 22:24:16 +0000 (01:24 +0300)]
[libcxx][NFC] Add tests for associative containers key_comp and value_comp

Add missing tests to improve associative containers code coverage:
 - Tests for key_comp() and value_comp() observers
 - Tests for std::map and std::multimap value_compare member class

Reviewed by: ldionne, rarutyun, #libc

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

2 years ago[ELF] Simplify Symbol::extract. NFC
Fangrui Song [Fri, 26 Nov 2021 22:10:55 +0000 (14:10 -0800)]
[ELF] Simplify Symbol::extract. NFC

2 years ago[sanitizer] Switch StackStore to 8 MiB blocks
Vitaly Buka [Fri, 19 Nov 2021 03:39:45 +0000 (19:39 -0800)]
[sanitizer] Switch StackStore to 8 MiB blocks

Larger blocks are more convenient for compressions.
Blocks are allocated with MmapNoReserveOrDie to save some memory.

Also it's 15% faster on StackDepotBenchmarkSuite

Depends on D114464.

Reviewed By: morehouse

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

2 years ago[InstSimplify] Fold X {lshr,udiv} C <u X --> true for nonzero X, non-identity C
Erik Desjardins [Fri, 26 Nov 2021 21:25:08 +0000 (16:25 -0500)]
[InstSimplify] Fold X {lshr,udiv} C <u X --> true for nonzero X, non-identity C

This eliminates the bounds check in Rust code like

pub fn mid(data: &[i32]) -> i32 {
  if data.is_empty() { return 0; }
  return data[data.len()/2];
}

(from https://blog.sigplan.org/2021/11/18/undefined-behavior-deserves-a-better-reputation/)

Alive proofs:
lshr https://alive2.llvm.org/ce/z/nyTu8D
udiv https://alive2.llvm.org/ce/z/CNUZH7

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

2 years ago[compiler-rt][CMake] Support powerpcspe build
Patrick Oppenlander [Fri, 26 Nov 2021 21:29:06 +0000 (13:29 -0800)]
[compiler-rt][CMake] Support powerpcspe build

Reviewed By: jhibbits, MaskRay

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

2 years ago[compiler-rt][CMake] Support powerpc32 on Linux
Patrick Oppenlander [Fri, 26 Nov 2021 21:28:20 +0000 (13:28 -0800)]
[compiler-rt][CMake] Support powerpc32 on Linux

Reviewed By: MaskRay

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

2 years agoRevert "[SCEV] Fix and validate ValueExprMap/ExprValueMap consistency"
Nikita Popov [Fri, 26 Nov 2021 21:17:27 +0000 (22:17 +0100)]
Revert "[SCEV] Fix and validate ValueExprMap/ExprValueMap consistency"

This reverts commit bee8dcda1f01831808885ea23f9ac1467ce660f5.

Some sanitizer buildbots fail with:
> Attempt to use a SCEVCouldNotCompute object!

For example:
https://lab.llvm.org/buildbot/#/builders/85/builds/7020/steps/9/logs/stdio

2 years ago[InstSimplify] baseline tests for icmp of lshr/udiv fold (NFC)
Erik Desjardins [Fri, 26 Nov 2021 20:42:15 +0000 (15:42 -0500)]
[InstSimplify] baseline tests for icmp of lshr/udiv fold (NFC)

Precommits tests for https://reviews.llvm.org/D114279

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

2 years ago[flang] Fix reversed comparison in RESHAPE() runtime
Peter Klausler [Tue, 23 Nov 2021 21:37:15 +0000 (13:37 -0800)]
[flang] Fix reversed comparison in RESHAPE() runtime

RESHAPE() fails inappropriately at runtime if the source array
is larger than the result -- which is perfectly valid -- because
of an obviously reversed comparison of their numbers of elements
is activating the runtime asserts meant for the opposite case
(source smaller than result).

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

2 years ago[mlir] Fix a warning
Kazu Hirata [Fri, 26 Nov 2021 20:27:11 +0000 (12:27 -0800)]
[mlir] Fix a warning

This patch fixes:

  mlir/lib/IR/MLIRContext.cpp:1020:3: error: use of the 'nodiscard'
  attribute is a C++17 extension [-Werror,-Wc++17-extensions]

2 years ago[DAG] Restore dropped condition
Nikita Popov [Fri, 26 Nov 2021 20:18:54 +0000 (21:18 +0100)]
[DAG] Restore dropped condition

This was dropped in fcee33bd5a35786d905a40f42ed28d5a988d75eb,
presumably accidentally.

2 years ago[SCEV] Fix and validate ValueExprMap/ExprValueMap consistency
Nikita Popov [Sat, 30 Oct 2021 19:40:14 +0000 (21:40 +0200)]
[SCEV] Fix and validate ValueExprMap/ExprValueMap consistency

Relative to the previous landing attempt, this makes
insertValueToMap() resilient against the value already being
present in the map -- previously I only checked this for the
createSimpleAffineAddRec() case, but the same issue can also
occur for the general createNodeForPHI(). In both cases, the
addrec may be constructed and added to the map in a recursive
query trying to create said addrec. In this case, this happens
due to the invalidation when the BE count is computed, which
ends up clearing out the symbolic name as well.

-----

This adds validation for consistency of ValueExprMap and
ExprValueMap, and fixes identified issues:

* Addrec construction directly wrote to ValueExprMap in a few places,
  without updating ExprValueMap. Add a helper to ensures they stay
  consistent. The adjustment in forgetSymbolicName() explicitly
  drops the old value from the map, so that we don't rely on it
  being overwritten.
* forgetMemoizedResultsImpl() was dropping the SCEV from
  ExprValueMap, but not dropping the corresponding entries from
  ValueExprMap.

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

2 years ago[ELF][PPC64] Make --power10-stubs/--no-power10-stubs proper aliases for --power10...
Fangrui Song [Fri, 26 Nov 2021 19:51:45 +0000 (11:51 -0800)]
[ELF][PPC64] Make --power10-stubs/--no-power10-stubs proper aliases for --power10-stubs={auto,no}

This allows --power10-stubs= and --[no-]power10-stubs to override each other
(they are position dependent in GNU ld).

Also improve --help messages and the manpage.

Note: GNU ld's default "auto" mode uses heuristics to decide whether Power10
instructions are used. Arguably it is a design mistake of R_PPC64_REL24_NOTOC
(acked by the relevant folks on a libc-alpha discussion). We don't implement
"auto", so the default --power10-stubs is the same as "yes".

2 years ago[MLIR] Avoid creation of buggy affine maps when incorrect values of number of dimensi...
Arnab Dutta [Fri, 26 Nov 2021 19:06:09 +0000 (00:36 +0530)]
[MLIR] Avoid creation of buggy affine maps when incorrect values of number of dimensions and number of symbols are provided.

We check whether the maximum index of dimensional identifier present
in the result expressions is less than dimCount (number of dimensional
identifiers) argument passed in the AffineMap::get() and the maximum index
of symbolic identifier present in the result expressions is less than
symbolCount (number of symbolic identifiers) argument passed in AffineMap::get().

Reviewed By: nicolasvasilache, bondhugula

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

2 years ago[MLIR] Prevent creation of buggy affine map after linearizing collapsed dimensions...
Arnab Dutta [Fri, 26 Nov 2021 18:49:45 +0000 (00:19 +0530)]
[MLIR] Prevent creation of buggy affine map after linearizing collapsed dimensions of source map

Initially we were passing wrong numSymbols argument while calling
AffineMap::get() for creaating affine map with linearized result
expressions. The main problems was the number of symbols of the newly
to be created map may be different from that of the source map, as
new symbolic identifiers may be introduced while creating strided layout
linearized expressions.

Reviewed By: nicolasvasilache, bondhugula

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

2 years ago[ELF] Rename fetch to extract
Fangrui Song [Fri, 26 Nov 2021 18:58:50 +0000 (10:58 -0800)]
[ELF] Rename fetch to extract

The canonical term is "extract" (GNU ld documentation, Solaris's `-z *extract`
options). Avoid inventing a term and match --why-extract. (ld64 prefers "load"
but the word is overloaded too much)

Mostly MFC, except for --help messages and the header row in
--print-archive-stats output.

2 years ago[DAG] Pull out repeated isLittleEndian() calls. NFC.
Simon Pilgrim [Fri, 26 Nov 2021 18:41:47 +0000 (18:41 +0000)]
[DAG] Pull out repeated isLittleEndian() calls. NFC.

2 years ago[MLIR] Allow `Idempotent` trait to be applied to binary ops.
Chris Jones [Fri, 26 Nov 2021 18:22:13 +0000 (18:22 +0000)]
[MLIR] Allow `Idempotent` trait to be applied to binary ops.

Add `Idempotent` trait to `arith.{andi,ori}`.

Reviewed By: mehdi_amini

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

2 years ago[libc++] Trigger rebuild of the Docker image so we get a new nightly Clang
Louis Dionne [Fri, 26 Nov 2021 17:57:00 +0000 (12:57 -0500)]
[libc++] Trigger rebuild of the Docker image so we get a new nightly Clang

2 years ago[mlir][Vector] Support 0-D vectors in `BroadcastOp`
Michal Terepeta [Fri, 26 Nov 2021 17:17:13 +0000 (17:17 +0000)]
[mlir][Vector] Support 0-D vectors in `BroadcastOp`

This changes the op to produce `AnyVectorOfAnyRank` following mostly the code for 1-D vectors.

Depends On D114598

Reviewed By: nicolasvasilache

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

2 years ago[mlir][Standard] Support 0-D vectors in `SplatOp`
Michal Terepeta [Fri, 26 Nov 2021 16:44:01 +0000 (16:44 +0000)]
[mlir][Standard] Support 0-D vectors in `SplatOp`

This changes the op to produce `AnyVectorOfAnyRank` and implements this by just
inserting the element (skipping the shuffle that we do for the 1-D case).

Depends On D114549

Reviewed By: nicolasvasilache

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

2 years ago[MLIR] Simplex: fix a bug when rolling back a Simplex with no solutions
Arjun P [Fri, 26 Nov 2021 15:07:04 +0000 (20:37 +0530)]
[MLIR] Simplex: fix a bug when rolling back a Simplex with no solutions

Previously, when adding a constraint to a Simplex that is already marked
as having no solutions (marked empty), the Simplex would be marked empty again,
and a second UnmarkEmpty entry would be pushed to the undo log. When rolling
back, Simplex should be unmarked empty only after rolling back past the
creation of the first constraint that made it empty.

Reviewed By: Groverkss

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

2 years ago[llvm-cov][NFC] Add missing character to fix docs buildbot break.
Zarko Todorovski [Fri, 26 Nov 2021 16:57:10 +0000 (11:57 -0500)]
[llvm-cov][NFC] Add missing character to fix docs buildbot break.

2 years ago[libc] Make string entrypoints mutualy exclusive.
Siva Chandra Reddy [Fri, 26 Nov 2021 16:29:22 +0000 (16:29 +0000)]
[libc] Make string entrypoints mutualy exclusive.

For example, strcpy does not pull memcpy now.

Reviewed By: gchatelet

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

2 years ago[Target] Use range-based for loops (NFC)
Kazu Hirata [Fri, 26 Nov 2021 16:23:00 +0000 (08:23 -0800)]
[Target] Use range-based for loops (NFC)

2 years ago[MLIR] Simplex::pivot: also update the redundant rows when pivoting
Arjun P [Fri, 26 Nov 2021 10:59:55 +0000 (16:29 +0530)]
[MLIR] Simplex::pivot: also update the redundant rows when pivoting

Previously, the pivot function would only update the non-redundant rows when
pivoting. This is incorrect because in some cases, when rolling back past a
`detectRedundant` call, the basis being used could be different from that which
was used at the time of returning from the `detectRedundant` call. Therefore,
it is important to update the redundant rows as well during pivots. This could
also be triggered by pivots that occur when testing successive constraints for
being redundant in `detectRedundant` after some initial constraints are marked redundant.

Reviewed By: Groverkss

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

2 years ago[LLVM][llvm-cov] Inclusive language: rename option -name-whitelist to -name-allowlist
Zarko Todorovski [Fri, 26 Nov 2021 12:02:21 +0000 (07:02 -0500)]
[LLVM][llvm-cov] Inclusive language: rename option -name-whitelist to -name-allowlist

Renamed the option for llvm-cov and changed variable names to use more
inclusive terms. Also changed the binary for the test.

Reviewed By: alanphipps

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

2 years ago[libc++] Properly handle errors happening during Lit configuration
Louis Dionne [Tue, 16 Nov 2021 17:35:42 +0000 (12:35 -0500)]
[libc++] Properly handle errors happening during Lit configuration

Instead of silently swallowing errors that happen during Lit configuration
(for example trying to obtain compiler macros but compiling fails), raise
an exception with some amount of helpful information.

This should avoid the possibility of silently configuring Lit in a bogus
way, and also provides more helpful information when things fail.

Note that this requires a bit more finesse around how we handle some
failing configuration checks that we would previously return None for.

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

2 years ago[libc++] Add missing __format__ attributes
Louis Dionne [Tue, 16 Nov 2021 20:22:10 +0000 (15:22 -0500)]
[libc++] Add missing __format__ attributes

-Wformat-nonliteral was turned on in https://reviews.llvm.org/D112927,
however we forgot to apply some __format__ attributes in Linux specific
code paths, which led to warnings when building on Linux. This patch
addresses that oversight.

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

2 years agoRevert "Reland "[lldb] Remove non address bits when looking up memory regions""
David Spickett [Fri, 26 Nov 2021 15:16:03 +0000 (15:16 +0000)]
Revert "Reland "[lldb] Remove non address bits when looking up memory regions""

This reverts commit fac3f20de55769d028bd92220e74f22fa57dd4b2.

I found this has broken how we detect the last memory region in
GetMemoryRegions/"memory region" command.

When you're debugging an AArch64 system with pointer authentication,
the ABI plugin will remove the top bit from the end address of the last
user mapped area.

(lldb)
[0x0000fffffffdf000-0x0001000000000000) rw- [stack]

ABI plugin removes anything above the 48th bit (48 bit virtual addresses
by default on AArch64, leaving an address of 0.

(lldb)
[0x0000000000000000-0x0000000000400000) ---

You get back a mapping for 0 and get into an infinite loop.

2 years ago[clangd] IncludeCleaner: Attribute symbols from non self-contained headers to their...
Kirill Bobyrev [Fri, 26 Nov 2021 15:20:40 +0000 (16:20 +0100)]
[clangd] IncludeCleaner: Attribute symbols from non self-contained headers to their parents

When a symbol comes from the non self-contained header, we recursively uplift
the file we consider used to the first includer that has a header guard. We
need to do this while we still have FileIDs because every time a non
self-contained header is included, it gets a new FileID but is later
deduplicated by HeaderID and it's not possible to understand where it was
included from.

Based on D114370.

Reviewed By: sammccall

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

2 years ago[SLP]Improve analysis/emission of vector operands for alternate nodes.
Alexey Bataev [Wed, 17 Nov 2021 16:42:33 +0000 (08:42 -0800)]
[SLP]Improve analysis/emission of vector operands for alternate nodes.

Compiler has an analysis for perfect diamond matching but it does not
support nodes with main/alternate opcodes. The problem is that the
scalars themselves are different and might not match directly with other
nodes, but operands and main/alternate opcodes might match and compiler
might reuse some previously emitted vector instructions. Need to include
this analysis in the cost model and actual vector instructions emission
process.

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

2 years ago[pstl] Fix incorrect usage of std::invoke_result
Ruslan Arutyunyan [Fri, 26 Nov 2021 13:37:31 +0000 (16:37 +0300)]
[pstl] Fix incorrect usage of std::invoke_result

std::invoke_result takes function object type and arguments separately
(unlike std::result_of) so, std::invoke_result_t<F()> usage is
incorrect.

On the other hand, we don't need std::invoke() semantics here at all. So
just simplifying the code without extra dependency and use trailing
return type as the fix.

Reviewed By: MikeDvorskiy

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

2 years ago[mlir][OpenMP] Add support for SIMD modifier
Mats Petersson [Wed, 26 May 2021 09:35:45 +0000 (10:35 +0100)]
[mlir][OpenMP] Add support for SIMD modifier

Add support for SIMD modifier in OpenMP worksharing loops.

Reviewed By: ftynse

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

2 years ago[SLP][NFC]Add a test for gathered instructions in loop, NFC.
Alexey Bataev [Fri, 26 Nov 2021 13:51:51 +0000 (05:51 -0800)]
[SLP][NFC]Add a test for gathered instructions in loop, NFC.

2 years ago[Bug 49018][lldb] Fix incorrect help text for 'memory write' command
Venkata Ramanaiah Nalamothu [Fri, 26 Nov 2021 10:28:14 +0000 (15:58 +0530)]
[Bug 49018][lldb] Fix incorrect help text for 'memory write' command

Certain commands like 'memory write', 'register read' etc all use
the OptionGroupFormat options but the help usage text for those
options is not customized to those commands.

One such example is:

  (lldb) help memory read
           -s <byte-size> ( --size <byte-size> )
               The size in bytes to use when displaying with the selected format.
  (lldb) help memory write
   -s <byte-size> ( --size <byte-size> )
               The size in bytes to use when displaying with the selected format.

This patch allows such commands to overwrite the help text for the options
in the OptionGroupFormat group as needed and fixes help text of memory write.

llvm.org/pr49018.

Reviewed By: DavidSpickett

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

2 years ago[SCEV] Turn check in createSimpleAffineAddRec to assertion. (NFC)
Florian Hahn [Fri, 26 Nov 2021 13:23:48 +0000 (13:23 +0000)]
[SCEV] Turn check in createSimpleAffineAddRec to assertion. (NFC)

Accum is guaranteed to be defined outside L (via Loop::isLoopInvariant
checks above). I think that should guarantee that the more powerful
ScalarEvolution::isLoopInvariant also determines that the value is loop
invariant.

Reviewed By: nikic

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

2 years ago[mlir][linalg][bufferize][NFC] InsertSliceOp no-copy detection as PostAnalysis
Matthias Springer [Fri, 26 Nov 2021 13:13:28 +0000 (22:13 +0900)]
[mlir][linalg][bufferize][NFC] InsertSliceOp no-copy detection as PostAnalysis

There is special logic for InsertSliceOp to check if a memcpy is needed. This change extracts that piece of code and makes it a PostAnalysisStep.

The purpose of this change is to untangle `bufferize` from BufferizationAliasInfo. (Not fully there yet.)

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

2 years ago[clangd] Record information about non self-contained headers in IncludeStructure
Kirill Bobyrev [Fri, 26 Nov 2021 13:12:35 +0000 (14:12 +0100)]
[clangd] Record information about non self-contained headers in IncludeStructure

This will be useful for IncludeCleaner.

Reviewed By: sammccall

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

2 years agoProvide a definition for OperationPosition::kDown
Benjamin Kramer [Fri, 26 Nov 2021 13:07:48 +0000 (14:07 +0100)]
Provide a definition for OperationPosition::kDown

This isn't necessary in C++17, but C++14 still requires it.

2 years ago[PDL] fix unused variable warning in Release builds
Benjamin Kramer [Fri, 26 Nov 2021 13:11:29 +0000 (14:11 +0100)]
[PDL] fix unused variable warning in Release builds

2 years ago[tsan] Relax atexit5.cpp a bit more so it's not as dependent on the standard library...
Benjamin Kramer [Fri, 26 Nov 2021 13:01:40 +0000 (14:01 +0100)]
[tsan] Relax atexit5.cpp a bit more so it's not as dependent on the standard library implementation

2 years ago[clang][deps] NFC: Extract function
Jan Svoboda [Fri, 26 Nov 2021 12:39:25 +0000 (13:39 +0100)]
[clang][deps] NFC: Extract function

This commits extracts a couple of nested conditions into a separate function with early returns, making the control flow easier to understand.

2 years agoAdded line numbers to the debug output of PDL bytecode.
Stanislav Funiak [Fri, 26 Nov 2021 12:39:04 +0000 (18:09 +0530)]
Added line numbers to the debug output of PDL bytecode.

This is a small diff that splits out the debug output for PDL bytecode. When running bytecode with debug output on, it is useful to know the line numbers where the PDLIntepr operations are performed. Usually, these are in a single MLIR file, so it's sufficient to print out the line number rather than the entire location (which tends to be quite verbose). This debug output is gated by `LLVM_DEBUG` rather than `#ifndef NDEBUG` to make it easier to test.

Reviewed By: rriddle

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

2 years agoMulti-root PDL matching using upward traversals.
Stanislav Funiak [Fri, 26 Nov 2021 12:38:50 +0000 (18:08 +0530)]
Multi-root PDL matching using upward traversals.

This is commit 4 of 4 for the multi-root matching in PDL, discussed in https://llvm.discourse.group/t/rfc-multi-root-pdl-patterns-for-kernel-matching/4148 (topic flagged for review).

This PR integrates the various components (root ordering algorithm, nondeterministic execution of PDL bytecode) to implement multi-root PDL matching. The main idea is for the pattern to specify mulitple candidate roots. The PDL-to-PDLInterp lowering selects one of these roots and "hangs" the pattern from this root, traversing the edges downwards (from operation to its operands) when possible and upwards (from values to its uses) when needed. The root is selected by invoking the optimal matching multiple times, once for each candidate root, and the connectors are determined form the optimal matching. The costs in the directed graph are equal to the number of upward edges that need to be traversed when connecting the given two candidate roots. It can be shown that, for this choice of the cost function, "hanging" the pattern an inner node is no better than from the optimal root.

The following three main additions were implemented as a part of this PR:
1. OperationPos predicate has been extended to allow tracing the operation accepting a value (the opposite of operation defining a value).
2. Predicate checking if two values are not equal - this is useful to ensure that we do not traverse the edge back downwards after we traversed it upwards.
3. Function for for building the cost graph among the candidate roots.
4. Updated buildPredicateList, building the predicates optimal branching has been determined.

Testing: unit tests (an integration test to follow once the stack of commits has landed)

Reviewed By: rriddle

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

2 years agoImplementation of the root ordering algorithm
Stanislav Funiak [Fri, 26 Nov 2021 12:38:42 +0000 (18:08 +0530)]
Implementation of the root ordering algorithm

This is commit 3 of 4 for the multi-root matching in PDL, discussed in https://llvm.discourse.group/t/rfc-multi-root-pdl-patterns-for-kernel-matching/4148 (topic flagged for review).

We form a graph over the specified roots, provided in `pdl.rewrite`, where two roots are connected by a directed edge if the target root can be connected (via a chain of operations) in the underlying pattern to the source root. We place a restriction that the path connecting the two candidate roots must only contain the nodes in the subgraphs underneath these two roots. The cost of an edge is the smallest number of upward traversals (edges) required to go from the source to the target root, and the connector is a `Value` in the intersection of the two subtrees rooted at the source and target root that results in that smallest number of such upward traversals. Optimal root ordering is then formulated as the problem of finding a spanning arborescence (i.e., a directed spanning tree) of minimal weight.

In order to determine the spanning arborescence (directed spanning tree) of minimum weight, we use the [Edmonds' algorithm](https://en.wikipedia.org/wiki/Edmonds%27_algorithm). The worst-case computational complexity of this algorithm is O(_N_^3) for a single root, where _N_ is the number of specified roots. The `pdl`-to-`pdl_interp` lowering calls this algorithm as a subroutine _N_ times (once for each candidate root), so the overall complexity of root ordering is O(_N_^4). If needed, this complexity could be reduced to O(_N_^3) with a more efficient algorithm. However, note that the underlying implementation is very efficient, and _N_ in our instances tends to be very small (<10). Therefore, we believe that the proposed (asymptotically suboptimal) implementation will suffice for now.

Testing: a unit test of the algorithm

Reviewed By: rriddle

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

2 years agoIntroduced iterative bytecode execution.
Stanislav Funiak [Fri, 26 Nov 2021 12:38:34 +0000 (18:08 +0530)]
Introduced iterative bytecode execution.

This is commit 2 of 4 for the multi-root matching in PDL, discussed in https://llvm.discourse.group/t/rfc-multi-root-pdl-patterns-for-kernel-matching/4148 (topic flagged for review).

This commit implements the features needed for the execution of the new operations pdl_interp.get_accepting_ops, pdl_interp.choose_op:
1. The implementation of the generation and execution of the two ops.
2. The addition of Stack of bytecode positions within the ByteCodeExecutor. This is needed because in pdl_interp.choose_op, we iterate over the values returned by pdl_interp.get_accepting_ops until we reach finalize. When we reach finalize, we need to return back to the position marked in the stack.
3. The functionality to extend the lifetime of values that cross the nondeterministic choice. The existing bytecode generator allocates the values to memory positions by representing the liveness of values as a collection of disjoint intervals over the matcher positions. This is akin to register allocation, and substantially reduces the footprint of the bytecode executor. However, because with iterative operation pdl_interp.choose_op, execution "returns" back, so any values whose original liveness cross the nondeterminstic choice must have their lifetime executed until finalize.

Testing: pdl-bytecode.mlir test

Reviewed By: rriddle, Mogball

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