Commit Graph

407598 Commits

Author SHA1 Message Date
Nikolas Klauser 148ef80f89 [libc++] Add GCC workaround in std::char_traits<char>::length()
GCC currently does not allow `__builtin_strlen()` during constant evaluation. This PR adds a workaround in `std::char_traits<char>::length()`

Reviewed By: Quuxplusone, ldionne, #libc, Mordante

Spies: Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D115795
2021-12-16 14:27:51 +01:00
Paul Altin 9198d04c06 Allow disabling integer to floating-point narrowing conversions for cppcoreguidelines-narrowing-conversions
This change adds an option to disable warnings from the
cppcoreguidelines-narrowing-conversions check on integer to floating-
point conversions which may be narrowing.

An example of a case where this might be useful:
```
std::vector<double> v = {1, 2, 3, 4};
double mean = std::accumulate(v.cbegin(), v.cend(), 0.0) / v.size();
```
The conversion from std::size_t to double is technically narrowing on
64-bit systems, but v almost certainly does not have enough elements
for this to be a problem.

This option would allow the cppcoreguidelines-narrowing-conversions
check to be enabled on codebases which might otherwise turn it off
because of cases like the above.
2021-12-16 08:24:09 -05:00
Aaron Ballman a1879e52e3 Fix crash on invalid code involving late parsed inline methods
When parsing the following construct, we parse it as an erroneous
deduction guide declaration and correctly diagnose the issues with it.

template<class> struct B;
struct A { B() noexcept(false); };

However, we then go on to finish late parsing the declaration and this
expects that what we've parsed is a CXXMethodDecl. A
CXXDeductionGuideDecl is not a CXXMethodDecl (it's a FunctionDecl), and
so we assert on the cast.

This fixes the crash by switching from cast<> to dyn_cast<> and not
setting up a "this" scope when the declaration is not a CXXMethodDecl.

This fixes PR49735.
2021-12-16 07:58:51 -05:00
Pavel Labath 9d5e37ed8c [lldb] (Semi-automatically) format .swig files
I've found my recent ventures into the swig land painful because
of the strange way they are formatted. This patch attempts to alleviate
future headaches by formatting these files into something resembling the
normal llvm style.

Unfortunately, completely formatting these files automatically does not
work because clang format gets confused by swigs % syntax, so I have
employed a hybrid approach where I formatted blocks of c++ code with
clang-format and then manually massaged the code until it looked
reasonable (and compiled).

I don't expect these files to remain perfectly formatted (although, if
one's editor is configured to configure the current line/block on
request, one can get pretty good results by using it judiciously), but
at least it will prevent the (mangled form of the) old lldb style being
proliferated endlessly.

Differential Revision: https://reviews.llvm.org/D115736
2021-12-16 13:58:37 +01:00
Sjoerd Meijer 5b139a583d Revert "[FuncSpec] Decouple cost/benefit analysis, allowing sorting of candidates."
This reverts commit 20b03d6536.

This shows some failed tests on a bot with expensive checks enabled that I need
to look at.
2021-12-16 12:56:11 +00:00
Diego Caballero e0514fc200 [mlir] Fix Bazel build after 32fe1a8a25
Adding missing dependences.
2021-12-16 12:13:56 +00:00
Sjoerd Meijer 20b03d6536 [FuncSpec] Decouple cost/benefit analysis, allowing sorting of candidates.
This mostly is the same code that is refactored to decouple the cost and
benefit analysis. The biggest change is top-level function specializeFunctions
that now drives the transformation more like this:

  specializeFunctions() {
    Cost = getSpecializationCost(F);
    calculateGains(F, Cost);
    specializeFunction(F);
  }

while this is just a restructuring, it helps the functional change in
calculateGains. I.e., we now sort the candidates based on the expected
specialisation gain, which we didn't do before. For this, a book keeping struct
ArgInfo was introduced. If we have a list of N candidates, but we only want
specialise less than N as set by option -func-specialization-max-constants, we
sort the list and discard the candidates that give the least benefit.

Given a formal argument, this change results in selecting the best actual
argument(s). This is NFC'ish in that this shouldn't change the current output
(hence no test change here), but in follow ups starting with D115509, it
should and I want to go one step further and compare all functions and all
arguments, which will mostly build on top of this refactoring and change.

Differential Revision: https://reviews.llvm.org/D115458
2021-12-16 11:55:37 +00:00
Diego Caballero 32fe1a8a25 [mlir][GPU] Extend GPU kernel outlining to generate DL specification
This patch extends the GPU kernel outlining pass so that it can take in
an optional data layout specification that will be attached to the GPU
module operation generated. If the data layout specification is not provided
the default data layout is used instead.

Reviewed By: herhut, mehdi_amini

Differential Revision: https://reviews.llvm.org/D115722
2021-12-16 11:35:53 +00:00
Florian Hahn 59a85a7a52
[PPC] Update test after f5f421e0ee. 2021-12-16 11:28:54 +00:00
Nikita Popov 34eb715f61 [CodeGen] Avoid more pointer element type accesses 2021-12-16 12:03:11 +01:00
Florian Hahn f5f421e0ee
[SCEV] Apply loop guards in reverse order.
This patch updates applyLoopGuards to first collect all conditions and
then applies them in reverse order. This ensures the SCEVs with the
shortest dependency chains are constructed first, limiting the required
stack size.

This fixes a crash reported in D113578.

Note that the order conditions are applied can impact the accuracy of
the result, mostly due to missing min/max simplifications when
constructing SCEVs.

The changed test highlights the impact of the evaluation order. I will
follow up with a SCEV patch to improve min/max simplifications to get
the same results for both orders.
2021-12-16 10:52:37 +00:00
Nikita Popov 9fa15e0073 [CodeGen] Remove an unused MakeAddrLValue() overload (NFC)
This is unused and we should prefer the overloads accepting Address.
2021-12-16 11:49:20 +01:00
Paulo Matos c92d45913c [WebAssembly] Fix typechecking for else MCInst
When hitting an else clause the type Stack should be reset to as it was at the start of the if, without taking into account the Type inserted into the Stack during the then branch of the if.

Reviewed By: aardappel

Differential Revision: https://reviews.llvm.org/D115748
2021-12-16 11:18:01 +01:00
eopXD 6734be290b Revert "[LoopVersioning] Allow versionLoop to create plain branch inst when no runtime check is specified"
This reverts commit fbf6c8ac15.
2021-12-16 02:06:11 -08:00
Hsiangkai Wang 78415b5044 [RISCV] Precommit a test for vector copy conversion under implicit-def. 2021-12-16 18:04:38 +08:00
Jay Foad cce93b3397 [MachineVerifier] Undef subreg operands do not require subranges
D112556 added verification that the live interval for a subreg operand
must have subranges. This patch fixes a corner case, where if all subreg
operands for a particular register are undef uses then no subranges
are required. This matches how LiveIntervalCalc would build the live
intervals in the first place, since an undef use is not considered
to read the register.

Before this patch, CodeGen/AMDGPU/no-remat-indirect-mov.mir would fail
with -early-live-intervals:

 # After Live Interval Analysis
...
*** Bad machine code: Live interval for subreg operand has no subranges ***
- function:    index_vgpr_waterfall_loop
- basic block: %bb.1  (0x6a9a968) [352B;496B)
- instruction: 432B	%24:vgpr_32 = V_MOV_B32_e32 undef %18.sub0:vreg_512, implicit $exec, implicit %18:vreg_512, implicit $m0
- operand 1:   undef %18.sub0:vreg_512

Differential Revision: https://reviews.llvm.org/D115360
2021-12-16 09:49:27 +00:00
Diego Caballero 0ca00c3538 [mlir][vector] Remove default value in populateVectorMultiReductionLoweringPatterns
Having a default value for the lowering strategy of the multi-reduction op has proven
to be unexpected by users. This patch is dropping the default value so that users have
to explicitly choose the lowering strategy to be applied.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D115805
2021-12-16 09:45:34 +00:00
Nikita Popov a8c2ba105d [Inline] Disable deferred inlining
After the switch to the new pass manager, we have observed multiple
instances of catastrophic inlining, where the inliner produces huge
functions with many hundreds of thousands of instructions from small
input IR. We were forced to back out the switch to the new pass
manager for this reason. This patch fixes at least one of the root
cause issues.

LLVM uses a bottom-up inliner, and the fact that functions are processed
bottom-up is not just a question of optimality -- it is an imporant
requirement to prevent runaway inlining. The premise of the current
inlining approach and cost model is that after all calls inside a function
have been inlined, it may get large enough that inlining it into its
callers is no longer considered profitable. This safeguard does not
exist if inlining doesn't happen bottom-up, as inlining the callees,
and their callees, and their callees etc. will always seem individually
profitable, and the inliner can easily flatten the whole call tree.

There are instances where we necessarily have to deviate from bottom-up
inlining: When inlining in an SCC there is no natural "bottom", so
inlining effectively happens top-down. This requires special care,
and the inliner avoids exponential blowup by ensuring that functions
in the SCC grow in a balanced way and will eventually hit the threshold.

However, there is one instance where the inlining advisor explicitly
violates the bottom-up principle: Deferred inlining tries to "defer"
inlining a call if it determines that inlining the caller into all
its call-sites would be more profitable. Something very important to
understand about deferred inlining is that it doesn't make one inlining
choice in place of another -- it effectively chooses to do both. If we
have a call chain A -> B -> C and cost modelling tells us that inlining
B -> C is profitable, but we defer this and instead inline A -> B first,
then we'll now have a call A -> C, and the cost model will (a few special
cases notwithstanding) still tell us that this is profitable. So the end
result is that we inlined *both* B and C, even though under the usual
cost model function B would have been too large to further inline after
C has been integrated into it.

Because deferred inlining violates the bottom-up invariant of the inliner,
it can result in exponential inlining. The exponential-deferred-inlining.ll
test case illustrates this on a simple example (see
https://gist.github.com/nikic/1262b5f7d27278e1b34a190ae10947f5 for a
much more catastrophic case with about 5000x size blowup). If the call
chain A -> B -> C is not a chain but a tree of calls, then we end up
deferring inlining across the tree and end up flattening everything into
the root node.

This patch proposes to address this by disabling deferred inlining
entirely (currently still behind an option). Beyond the issue of
exponential inlining, I don't think that the whole concept makes sense,
at least as long as deferred inlining still ends up inlining both call
edges.

I believe the motivation for having deferred inlining in the first place
is that you might have a small wrapper function with local linkage that
could be eliminated if inlined. This would automatically happen if there
was a single caller, due to the large "last call to local" bonus. However,
this bonus is not extended if there are multiple callers, even if we
would eventually end up inlining into all of them (if the bonus were
extended).

Now, unlike the normal inlining cost model, the deferred inlining cost
model does look at all callers, and will extend the "last call to local"
bonus if it determines that we could inline all of them as long as we
defer the current inlining decision. This makes very little sense.
The "last call to local" bonus doesn't really cost model anything.
It's basically an "infinite" bonus that ensures we always inline the
last call to a local. The fact that it's not literally infinite just
prevents inlining of huge functions, which can easily result in
scalability issues. I very much doubt that it was an intentional
cost-modelling choice to say that getting rid of a small local function
is worth adding 15000 instructions elsewhere, yet this is exactly how
this value is getting used here.

The main alternative I see to complete removal is to change deferred
inlining to an actual either/or decision. That is, to mark deferred
calls as noinline so we're actually trading off one inlining decision
against another, and not just adding a side-channel to the cost model
to do both.

Apart from fixing the catastrophic inlining case, the effect on rustc
is a modest compile-time improvement on average (up to 8% for a
parsing-type crate, where tree-like calls are expected) and pretty
neutral where run-time performance is concerned (mix of small wins
and losses, usually in the sub-1% category).

Differential Revision: https://reviews.llvm.org/D115497
2021-12-16 09:59:50 +01:00
Jan Svoboda f66803457e [clang][deps] Squash caches for original and minimized files
The minimizing and caching filesystem used by the dependency scanner keeps minimized and original files in separate caches.

This setup is not well suited for dealing with files that are sometimes minimized and sometimes not. Such files are being stat-ed and read twice, which is wasteful and also means the two versions of the file can get "out of sync".

This patch squashes the two caches together. When a file is stat-ed or read, its original contents are populated. If a file needs to be minimized, we give the minimizer the already loaded contents instead of reading the file again.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D115346
2021-12-16 09:57:21 +01:00
Lang Hames 02fc8d5c9e [ORC] Add custom object interface support to StaticLibaryDefinitionGenerator.
This adds a GetObjectFileInterface callback member to
StaticLibraryDefinitionGenerator, and adds an optional argument for initializing
that member to StaticLibraryDefinitionGenerator's named constructors. If not
supplied, it will default to getObjectFileInterface from ObjectFileInterface.h.

To enable testing a `-hidden-l<x>` option is added to the llvm-jitlink tool.
This allows archives to be loaded with all contained symbol visibilities demoted
to hidden.

The ObjectLinkingLayer::setOverrideObjectFlagsWithResponsibilityFlags method is
(belatedly) hooked up, and enabled in llvm-jitlink when `-hidden-l<x>` is used
so that the demotion is also applied at symbol resolution time (avoiding any
"mismatched symbol flags" crashes).
2021-12-16 19:46:51 +11:00
Lang Hames 3eeeb6ec93 [llvm-jitlink] Fix a typo. 2021-12-16 19:46:51 +11:00
Lang Hames 7ba32b12de [llvm-jitlink] Remove unused struct member. 2021-12-16 19:46:50 +11:00
Yueh-Ting Chen fbf6c8ac15 [LoopVersioning] Allow versionLoop to create plain branch inst when no runtime check is specified
After this function call, the LLVM IR would look like the following:

```
if (true)
  /* NonVersionedLoop */
else
  /* VersionedLoop */
```

Reviewed By: Whitney

Differential Revision: https://reviews.llvm.org/D104631
2021-12-16 00:41:29 -08:00
Nikita Popov 68cb111f3a [llvm-c] Make LLVMConstGEP/LLVMConstInBoundsGEP opaque pointer compatible
Weirdly, the opaque pointer compatible variants LLVMConstGEP2 and
LLVMConstInBoundsGEP2 were already declared in the header, but not
actually implemented. This adds the missing implementations and
deprecates the incompatible functions.

Differential Revision: https://reviews.llvm.org/D115787
2021-12-16 09:38:52 +01:00
Marek Kurdej 27818f01fe [clang-format] Fix tabs when using BreakBeforeTernaryOperators=false.
Fixes https://github.com/llvm/llvm-project/issues/52724.

This is rather a workaround than a correct fix. To properly fix it, we'd need to find a better way to tell when not to decrease the StartOfTokenColumn.

Reviewed By: MyDeveloperDay, owenpan

Differential Revision: https://reviews.llvm.org/D115803
2021-12-16 09:28:00 +01:00
Fangrui Song 8617996ac1 [ELF] maybeReportUndefined: move sym.isUndefined() check to the caller. NFC
Avoid a function call in the majority of cases.
2021-12-16 00:27:19 -08:00
Nikita Popov 6bca9a428e [CodeGen] Store ElementType in LValue
Store the pointer element type inside LValue so that we can
preserve it when converting it back into an Address. Storing the
pointer element type might not be strictly required here in that
we could probably re-derive it from the QualType (which would
require CGF access though), but storing it seems like the simpler
solution.

The global register case is special and does not store an element
type, as the value is not a pointer type in that case and it's not
possible to create an Address from it.

This is the main remaining part from D103465.

Differential Revision: https://reviews.llvm.org/D115791
2021-12-16 09:23:33 +01:00
Vitaly Buka c209b7e3d5 [sanitizer] Update global_symbols.txt 2021-12-16 00:15:20 -08:00
Fangrui Song 101407bfaa [ELF] parseSymbolVersion: remove unussed pos == 0 check 2021-12-15 23:59:55 -08:00
LLVM GN Syncbot c42decb033 [gn build] Port db5aceb979 2021-12-16 07:22:17 +00:00
Mircea Trofin db5aceb979 [NFC] Expose the ReleaseModeModelRunner
The type was pretty much generic, just needed a bit of parameterization.

Differential Revision: https://reviews.llvm.org/D115764
2021-12-15 23:21:58 -08:00
jacquesguan 7dfbf0b60f [RISCV] Fold (and (not (srl X, C)), 1) to (xor (bexti X, C), 1) when have Zbs extension.
When have Zbs extension, we could use bexti to fold (and (not (srl X, C)), 1) to (xor (bexti X, C), 1).

Differential Revision: https://reviews.llvm.org/D115629
2021-12-16 15:01:05 +08:00
Fangrui Song 60f5614931 [ELF] SharedFile::parse: cache symbols size for a loop. NFC 2021-12-15 22:45:28 -08:00
Siva Chandra Reddy 2cf203d9f6 [libc] Disable signal.h API and its users.
The signal.h header file from LLVM libc is incorrect. The signal API and
its users will be enabled once signal.h is fixed.
2021-12-16 05:52:28 +00:00
Fangrui Song 7b265e9791 [ELF] Move -l -L canonical and --library-path --library aliases
Everyone uses -l -L instead of the long option counterparts.
Make help messages attach to -L -l and (--reproduce) use them for response.txt
command line options.
2021-12-15 21:49:53 -08:00
eopXD ecb3ae524e [LoopIdiom] Use utility from SE instead of local rewriter
ScalarEvolution::applyLoopGuards shall do the work.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D115784
2021-12-15 20:46:49 -08:00
River Riddle e76043ac64 [PDLL] Fix GCC5 build after D115093 2021-12-16 03:49:34 +00:00
River Riddle 3164ae9746 [PDLL] Fix windows build after D115093 2021-12-16 03:24:08 +00:00
Ellis Hoag b68061a3f7 [dwarf][NFC] Move expandBundle() to MachO.h
The function `expandBundle()` is defined both in `llvm-dwarfdump.cpp` and
`llvm-gsymutil.cpp` in the exact same way. Reduce code duplication by
moving this function to the `MachOObjectFile` class.

Reviewed By: jhenderson, clayborg

Differential Revision: https://reviews.llvm.org/D115418
2021-12-15 19:08:56 -08:00
jacquesguan d3c2ad154e [RISCV] Fix whole vector register move instruction's vector register constraint.
According to the v-spec, the source and destination VR of vmv<nr>r.v should be aligned for the VR group size.

Differential Revision: https://reviews.llvm.org/D115720
2021-12-16 10:58:55 +08:00
Matthias Springer ec8628b1d6 [mlir][linalg][bufferize][NFC] Pass BufferizationState into all op interface methods
This allows op interface implementations to make decisions based on dialect-specific bufferization state.

This is in preparation of fixing conflict detection of CallOps in ModuleBufferization.

Differential Revision: https://reviews.llvm.org/D115705
2021-12-16 11:45:13 +09:00
minglotus-6 4ab5527c15 [ThinLTO] Ignore unreachable virtual functions in WPD in thin LTO.
Differential Revision: https://reviews.llvm.org/D115648
2021-12-16 02:24:20 +00:00
Fangrui Song 159b948e43 [ELF] ObjFile<ELFT>::initializeSymbols: don't call Allocate when firstGlobal==0
Calling `Allocate` with 0 size (when .symtab is absent, e.g.
`invalid/mips-invalid-options-descriptor.test`) may return a nullptr, which will
crash with -fsanitize=null (the underlying `Allocate` function is
LLVM_ATTRIBUTE_RETURNS_NONNULL).
2021-12-15 18:21:48 -08:00
River Riddle 3ee44cb775 [PDLL] Add a `rewrite` statement to enable complex rewrites
The `rewrite` statement allows for rewriting a given root
operation with a block of nested rewriters. The root operation is
not implicitly erased or replaced, and any transformations to it
must be expressed within the nested rewrite block. The inner body
may contain any number of other rewrite statements, variables, or
expressions.

Differential Revision: https://reviews.llvm.org/D115299
2021-12-16 02:08:13 +00:00
River Riddle 12eebb8e37 [PDLL] Add a `replace` rewrite statement for replacing operations
This statement acts as a companion to the existing `erase`
statement, and is the corresponding PDLL construct for the
`PatternRewriter::replaceOp` C++ API. This statement replaces a
given operation with a set of values.

Differential Revision: https://reviews.llvm.org/D115298
2021-12-16 02:08:13 +00:00
River Riddle f62a57a3f0 [PDLL] Add support for tuple types and expressions
Tuples are used to group multiple elements into a single
compound value. The values in a tuple can be of any type, and
do not need to be of the same type. There is also no limit to
the number of elements held by a tuple.

Tuples will be used to support multiple results from
Constraints and Rewrites (added in a followup), and will also
make it easier to support more complex primitives (such as
range based maps that can operate on multiple values).

Differential Revision: https://reviews.llvm.org/D115297
2021-12-16 02:08:13 +00:00
River Riddle 02670c3f38 [PDLL] Add support for `op` Operation expressions
An operation expression in PDLL represents an MLIR operation. In
the match section of a pattern, this expression models one of
the input operations to the pattern. In the rewrite section of
a pattern, this expression models one of the operations to
create. The general structure of the operation expression is very
similar to that of the "generic form" of textual MLIR assembly:

```
let root = op<my_dialect.foo>(operands: ValueRange) {attr = attr: Attr} -> (resultTypes: TypeRange);
```

For now we only model the components that are within PDL, as PDL
gains support for blocks and regions so will this expression.

Differential Revision: https://reviews.llvm.org/D115296
2021-12-16 02:08:12 +00:00
River Riddle d7e7fdf3aa [PDLL] Add support for literal Attribute and Type expressions
This allows for using literal attributes and types within PDLL,
which simplifies building both constraints and rewriters. For
example, checking if an attribute is true is as simple as
`attr<"true">`.

Differential Revision: https://reviews.llvm.org/D115295
2021-12-16 02:08:12 +00:00
River Riddle 322691ab63 [PDLL] Add support for parsing pattern metadata
This allows for overriding the metadata of a pattern and
providing information such as the benefit, bounded recursion,
and more in the future.

Differential Revision: https://reviews.llvm.org/D115294
2021-12-16 02:08:12 +00:00
River Riddle 11d26bd143 [mlir][PDLL] Add an initial frontend for PDLL
This is a new pattern rewrite frontend designed from the ground
up to support MLIR constructs, and to target PDL. This frontend
language was proposed in https://llvm.discourse.group/t/rfc-pdll-a-new-declarative-rewrite-frontend-for-mlir/4798

This commit starts sketching out the base structure of the
frontend, and is intended to be a minimal starting point for
building up the language. It essentially contains support for
defining a pattern, variables, and erasing an operation. The
features mentioned in the proposal RFC (including IDE support)
will be added incrementally in followup commits.

I intend to upstream the documentation for the language in a
followup when a bit more of the pieces have been landed.

Differential Revision: https://reviews.llvm.org/D115093
2021-12-16 02:08:12 +00:00