platform/upstream/llvm.git
3 years agoADT: Use 'using' to inherit assign and append in SmallString
Duncan P. N. Exon Smith [Fri, 22 Jan 2021 00:53:26 +0000 (16:53 -0800)]
ADT: Use 'using' to inherit assign and append in SmallString

Rather than reimplement, use a `using` declaration to bring in
`SmallVectorImpl<char>`'s assign and append implementations in
`SmallString`.

The `SmallString` versions were missing reference invalidation
assertions from `SmallVector`. This patch also fixes a bug in
`llvm::FileCollector::addFileImpl`, which was a copy/paste from
`clang::ModuleDependencyCollector::copyToRoot`, both caught by the
no-longer-skipped assertions.

As a drive-by, this also sinks the `const SmallVectorImpl&` versions of
these methods down into `SmallVectorImpl`, since I imagine they'd be
useful elsewhere.

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

3 years ago[libomptarget] Build cuda plugin without cuda installed locally
Jon Chesterfield [Sat, 23 Jan 2021 00:15:03 +0000 (00:15 +0000)]
[libomptarget] Build cuda plugin without cuda installed locally

[libomptarget] Build cuda plugin without cuda installed locally

Compiles a new file, `plugins/cuda/dynamic_cuda/cuda.cpp`, to an object file that exposes the same symbols that the plugin presently uses from libcuda. The object file contains dlopen of libcuda and cached dlsym calls. Also provides a cuda.h containing the subset that is used.

This lets the cmake file choose between the system cuda and a dlopen shim, with no changes to rtl.cpp.

The corresponding change to amdgpu is postponed until after a refactor of the plugin to reduce the size of the hsa.h stub required

Reviewed By: jdoerfert

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

3 years agoChange static buffer to be BSS instead of DATA in HandlePacket_qSpeedTest
Jason Molenda [Sat, 23 Jan 2021 00:11:47 +0000 (16:11 -0800)]
Change static buffer to be BSS instead of DATA in HandlePacket_qSpeedTest

Having this 4MB buffer with a compile-time initialized string forced it
into the DATA section and it took up 4MB of space in the binary, which
accounts for like 80% of debugserver's footprint on disk.  Change it to
BSS and strcpy in the initial value at runtime instead.

<rdar://problem/73503892>

3 years ago[AMDGPU] Fix FP materialization/resolve with flat scratch
Stanislav Mekhanoshin [Fri, 22 Jan 2021 19:06:14 +0000 (11:06 -0800)]
[AMDGPU] Fix FP materialization/resolve with flat scratch

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

3 years agoChange materializeFrameBaseRegister() to return register
Stanislav Mekhanoshin [Fri, 22 Jan 2021 23:02:36 +0000 (15:02 -0800)]
Change materializeFrameBaseRegister() to return register

The only caller of this function is in the LocalStackSlotAllocation
and it creates base register of class returned by the target's
getPointerRegClass(). AMDGPU wants to use a different reg class
here so let materializeFrameBaseRegister to just create and return
whatever it wants.

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

3 years agoPR47682: Merge the DeclContext of a merged FunctionDecl before we inherit
Richard Smith [Fri, 22 Jan 2021 23:43:47 +0000 (15:43 -0800)]
PR47682: Merge the DeclContext of a merged FunctionDecl before we inherit
default arguments.

When a function is declared with a qualified name, its eventual semantic
DeclContext may differ from the scope specified by the qualifier if it
redeclares a function in an inline namespace. In this case, we need to
update the DeclContext to be that of the previous declaration, and we
need to do so before we decide whether to inherit default arguments from
that previous declaration, because we only inherit default arguments
from declarations in the same scope.

3 years ago[CodeComplete] Add ranged for loops code pattern.
Nathan James [Fri, 22 Jan 2021 23:40:35 +0000 (23:40 +0000)]
[CodeComplete] Add ranged for loops code pattern.

Add code pattersn for c++ `range for` loops and objective c `for...in` loops.

Reviewed By: kadircet

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

3 years ago[RGT][TextAPI] Remove a zero-trip loop and the assertions within it
Paul Robinson [Fri, 15 Jan 2021 17:11:31 +0000 (09:11 -0800)]
[RGT][TextAPI] Remove a zero-trip loop and the assertions within it

Found by the Rotten Green Tests project.

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

3 years ago[RGT] Don't use EXPECT* macros in a subprocess that exits by signalling
Paul Robinson [Fri, 15 Jan 2021 16:52:58 +0000 (08:52 -0800)]
[RGT] Don't use EXPECT* macros in a subprocess that exits by signalling

Found by the Rotten Green Tests project.

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

3 years ago[lldb] FixFileSystem::GetExternalPath for VFS API change
Jonas Devlieghere [Fri, 22 Jan 2021 23:04:11 +0000 (15:04 -0800)]
[lldb] FixFileSystem::GetExternalPath for VFS API change

3 years ago[RGT][ADT] Remove test assertion that will not be executed
Paul Robinson [Fri, 15 Jan 2021 16:29:35 +0000 (08:29 -0800)]
[RGT][ADT] Remove test assertion that will not be executed

Found by the Rotten Green Tests project.

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

3 years ago[RISCV] Add more cmov isel patterns to handle seteq/ne with a small non-zero immediate.
Craig Topper [Fri, 22 Jan 2021 21:53:37 +0000 (13:53 -0800)]
[RISCV] Add more cmov isel patterns to handle seteq/ne with a small non-zero immediate.

Similar to our free standing setcc patterns, we can use ADDI to
subtract the immediate from the other operand. Then the cmov
can check if the result is zero or non-zero.

Reviewed By: mundaym

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

3 years ago[mlir][Linalg] Make Fill operation work on tensors.
MaheshRavishankar [Fri, 22 Jan 2021 22:38:47 +0000 (14:38 -0800)]
[mlir][Linalg] Make Fill operation work on tensors.

Depends on D95109

3 years ago[Matrix] Propagate shape information through fneg
Francis Visoiu Mistrih [Fri, 22 Jan 2021 19:16:11 +0000 (11:16 -0800)]
[Matrix] Propagate shape information through fneg

Similar to binary operators like fadd/fmul/fsub, propagate shape info
through unary operators (fneg is the only one?).

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

3 years agoRevert "[AArch64][GlobalISel] Make G_USUBO legal and select it."
Mitch Phillips [Fri, 22 Jan 2021 19:50:35 +0000 (11:50 -0800)]
Revert "[AArch64][GlobalISel] Make G_USUBO legal and select it."

This reverts commit 3dedad475da45c05bc4f66cd14e9f44581edf0bc.

Broke UBSan on Android:
http://lab.llvm.org:8011/#/builders/77/builds/3082

More details at: https://reviews.llvm.org/D95032

3 years agoRevert "[AArch64][GlobalISel] Implement widenScalar for signed overflow"
Mitch Phillips [Fri, 22 Jan 2021 19:49:51 +0000 (11:49 -0800)]
Revert "[AArch64][GlobalISel] Implement widenScalar for signed overflow"

This reverts commit 541d98efa222b00e16c67348810898c2fa11f398.

Reason: Dependent patch 3dedad475da45c05bc4f66cd14e9f44581edf0bc broke
UBSan on Android: http://lab.llvm.org:8011/#/builders/77/builds/3082

3 years agoRevert "[GlobalISel] LegalizerHelper - Extract widenScalarAddoSubo method"
Mitch Phillips [Fri, 22 Jan 2021 22:25:31 +0000 (14:25 -0800)]
Revert "[GlobalISel] LegalizerHelper - Extract widenScalarAddoSubo method"

This reverts commit 2bb92bf451d7eb2c817f3e5403353e7c0c14d350.

Dependent patch broke UBSan on Android:
3dedad475da45c05bc4f66cd14e9f44581edf0bc

3 years ago[SimplifyCFG] FoldBranchToCommonDest(): re-lift restrictions on liveout uses of bonus...
Roman Lebedev [Fri, 22 Jan 2021 19:18:34 +0000 (22:18 +0300)]
[SimplifyCFG] FoldBranchToCommonDest(): re-lift restrictions on liveout uses of bonus instructions

I have previously tried doing that in
b33fbbaa34f0fe9fb16789afc72ae424c1825b69 / d38205144febf4dc42c9270c6aa3d978f1ef65e1,
but eventually it was pointed out that the approach taken there
was just broken wrt how the uses of bonus instructions are updated
to account for the fact that they should now use either bonus instruction
or the cloned bonus instruction. In particluar, all that manual handling
of PHI nodes in successors was just wrong.

But, the fix is actually much much simpler than my initial approach:
just tell SSAUpdate about both instances of bonus instruction,
and let it deal with all the PHI handling.

Alive2 confirms that the reproducers from the original bugs (@pr48450*)
are now handled correctly.

This effectively reverts commit 59560e85897afc50090b6c3d920bacfd28b49d06,
effectively relanding b33fbbaa34f0fe9fb16789afc72ae424c1825b69.

3 years ago[NFC][SimplifyCFG] PerformBranchToCommonDestFolding(): move instruction cloning to...
Roman Lebedev [Fri, 22 Jan 2021 20:35:30 +0000 (23:35 +0300)]
[NFC][SimplifyCFG] PerformBranchToCommonDestFolding(): move instruction cloning to after CFG update

This simplifies follow-up patch, and is NFC otherwise.

3 years ago[NFC][SimplifyCFG] fold-branch-to-common-dest.ll: reduce complexity of @pr48450*...
Roman Lebedev [Fri, 22 Jan 2021 19:13:56 +0000 (22:13 +0300)]
[NFC][SimplifyCFG] fold-branch-to-common-dest.ll: reduce complexity of @pr48450* test

We don't need that many iterations there,
having less iterations helps alive2 verify it.

3 years ago[NFC][SimplifyCFG] PerformBranchToCommonDestFolding(): fix instruction name preservation
Roman Lebedev [Fri, 22 Jan 2021 19:03:13 +0000 (22:03 +0300)]
[NFC][SimplifyCFG] PerformBranchToCommonDestFolding(): fix instruction name preservation

NewBonusInst just took name from BonusInst, so BonusInst has no name,
so BonusInst.getName() makes no sense.
So we need to ask NewBonusInst for the name.

3 years ago[VFS] Fix inconsistencies between relative paths and fallthrough.
Jonas Devlieghere [Fri, 22 Jan 2021 21:51:59 +0000 (13:51 -0800)]
[VFS] Fix inconsistencies between relative paths and fallthrough.

This patch addresses inconsistencies in the way fallthrough is handled
in the RedirectingFileSystem. Rather than trying to change the working
directory of the external filesystem, the RedirectingFileSystem will
canonicalize every path before handing it down. This guarantees that
relative paths are resolved relative to the RedirectingFileSystem's
working directory.

This allows us to have a strictly virtual working directory, and still
fallthrough for absolute paths, but not for relative paths that would
get resolved incorrectly at the lower layer (for example, in case of the
RealFileSystem, because the strictly virtual path does not exist).

Differential revision: https://reviews.llvm.org/D95188

3 years ago[GlobalISel] LegalizerHelper - Extract widenScalarAddoSubo method
Cassie Jones [Fri, 22 Jan 2021 21:36:58 +0000 (13:36 -0800)]
[GlobalISel] LegalizerHelper - Extract widenScalarAddoSubo method

The widenScalar implementation for signed and unsigned overflowing
operations were very similar: both are checked by truncating the result
and then re-sign/zero-extending it and checking that it matches the
computed operation.

Using a truncate + zero-extend for the unsigned case instead of manually
producing the AND instruction like before leads to an extra copy
instruction during legalization, but this should be harmless.

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

3 years ago[RISCV] Add B extension tests to make sure RV64 only instructions aren't accepted...
Craig Topper [Fri, 22 Jan 2021 21:30:12 +0000 (13:30 -0800)]
[RISCV] Add B extension tests to make sure RV64 only instructions aren't accepted in RV32.

Add tests to make sure common instructions are accepted in RV64
and not just RV32.

Reviewed By: asb, frasercrmck

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

3 years ago[lld-macho] Ignore -lto_library
Jez Ng [Fri, 22 Jan 2021 21:48:50 +0000 (16:48 -0500)]
[lld-macho] Ignore -lto_library

Just getting rid of some logspew as I test LLD under existing build
systems.

Reviewed By: #lld-macho, smeenai

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

3 years ago[gn build] Port 622eaa4a4cea
LLVM GN Syncbot [Fri, 22 Jan 2021 21:40:40 +0000 (21:40 +0000)]
[gn build] Port 622eaa4a4cea

3 years ago[Inline] Precommit tests for dead calls and willreturn.
Florian Hahn [Tue, 5 Jan 2021 18:46:17 +0000 (18:46 +0000)]
[Inline] Precommit tests for dead calls and willreturn.

precommit tests for D94106.

3 years ago[RISCV] Add isel patterns for SH*ADD(.UW)
Craig Topper [Fri, 22 Jan 2021 20:54:02 +0000 (12:54 -0800)]
[RISCV] Add isel patterns for SH*ADD(.UW)

This adds an initial set of patterns for these instructions. Its
more complicated that I would like for the sh*add.uw instructions
because there is no guaranteed canonicalization for shl/and with
constants.

Reviewed By: asb

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

3 years ago[Analysis] Support AIX vec_malloc routines
Shimin Cui [Fri, 22 Jan 2021 20:59:29 +0000 (15:59 -0500)]
[Analysis] Support AIX vec_malloc routines

This is to support the memory routines vec_malloc, vec_calloc, vec_realloc, and vec_free. These routines manage memory that is 16-byte aligned. And they are only available on AIX.

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

3 years ago[InstSimplify] Add willreturn to more libcall tests (NFC)
Nikita Popov [Fri, 22 Jan 2021 20:55:34 +0000 (21:55 +0100)]
[InstSimplify] Add willreturn to more libcall tests (NFC)

Annotate more math libcalls with willreturn. The attribute would
have been added by the InferFuncAttrs.

3 years ago[mlir][Linalg] Disable fusion of tensor_reshape op by expansion when unit-dims are...
MaheshRavishankar [Fri, 22 Jan 2021 20:53:27 +0000 (12:53 -0800)]
[mlir][Linalg] Disable fusion of tensor_reshape op by expansion when unit-dims are involved

Fusion of generic/indexed_generic operations with tensor_reshape by
expansion when the latter just adds/removes unit-dimensions is
disabled since it just adds unit-trip count loops.

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

3 years ago[RISCV] Update B extension version to 0.93.
Craig Topper [Fri, 22 Jan 2021 20:24:55 +0000 (12:24 -0800)]
[RISCV] Update B extension version to 0.93.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Add xperm.* instructions to Zbp extension.
Craig Topper [Fri, 22 Jan 2021 20:16:32 +0000 (12:16 -0800)]
[RISCV] Add xperm.* instructions to Zbp extension.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Add support for rev8 and orc.b to Zbb.
Craig Topper [Fri, 22 Jan 2021 20:07:13 +0000 (12:07 -0800)]
[RISCV] Add support for rev8 and orc.b to Zbb.

These instructions use a portion of the encodings for grevi and
gorci. The full encodings are only supported with Zbp. Note,
rev8 has a different encoding between rv32 and rv64.

Zbb is closer to being finalized that Zbp which has motivated
some decisions in this patch.

I'm treating rev8 and orc.b as separate instructions when
either Zbb or Zbp is enabled. This allows us to print to suggest
that either feature needs to be enabled to support these mnemonics.
I had tried to put HasStdExtZbbAndNotZbp on the Zbb instructions,
but that caused a diagnostic that said Zbp is required if neither
feature is enabled. We should really mention Zbb since its closer
to final.

This does require extra isel patterns for the different cases so
that bswap will always print as rev8 in assembly listing since
we can't use an InstAlias.

llvm-objdump disassembling should always pick the rev8 or orc.b
instructions. llvm-mc parsing and printing text will not convert
the grevi/gorci spellings to rev8/gorc.b. We could probably fix
this with a special case in processInstruction in the assembly
parser if it its important.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Add zext.h instruction to Zbb.
Craig Topper [Fri, 22 Jan 2021 19:58:03 +0000 (11:58 -0800)]
[RISCV] Add zext.h instruction to Zbb.

zext.h uses the same encoding as pack rd, rs, x0 in rv32 and
packw rd, rs, x0 in rv64. Encodings without x0 as the second source
are not valid in Zbb.

I've added two new instructions with these specific encodings with
predicates that enable them when either Zbb or Zbp is enabled.

The pack spelling will only be accepted with Zbp. The disassembler
will use the zext.h instruction when either feature is enabled.

Using the pack spelling will print as pack when llvm-mc is
emitting text. We could fix this with some custom code in
processInstruction if this is important, but I'm not sure it is.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Move pack instructions to Zbp extension only.
Craig Topper [Fri, 22 Jan 2021 19:47:36 +0000 (11:47 -0800)]
[RISCV] Move pack instructions to Zbp extension only.

Zext.h will need to come back to Zbb, but that only uses specific
encodings of pack.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Change zext.w to be an alias of add.uw rd, rs1, x0 instead of pack.
Craig Topper [Fri, 22 Jan 2021 19:42:18 +0000 (11:42 -0800)]
[RISCV] Change zext.w to be an alias of add.uw rd, rs1, x0 instead of pack.

This didn't make it into the published 0.93 spec, but it was the
intention.

But it is in the tex source as of this commit
https://github.com/riscv/riscv-bitmanip/commit/d172f029c074d47026a0c0d0f12d8b475c86a472

This means zext.w now requires Zba. Not sure if we should still use
pack if Zbp is enabled and Zba isn't. I'll leave that for the future
when pack is closer to being final.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Modify add.uw patterns to put the masked operand in rs1 to match 0.93 bitmani...
Craig Topper [Fri, 22 Jan 2021 19:33:47 +0000 (11:33 -0800)]
[RISCV] Modify add.uw patterns to put the masked operand in rs1 to match 0.93 bitmanip spec.

The 0.93 spec has this implementation for add.uw

uint_xlen_t adduw(uint_xlen_t rs1, uint_xlen_t rs2) {
  uint_xlen_t rs1u = (uint32_t)rs1;
  return rs1u + rs2;
}

The 0.92 spec had the usages of rs1 and rs2 swapped.

Reviewed By: frasercrmck, asb

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

3 years ago[RISCV] Rename Zbs instructions to start with just 'b' instead of 'sb' to match 0...
Craig Topper [Fri, 22 Jan 2021 19:32:33 +0000 (11:32 -0800)]
[RISCV] Rename Zbs instructions to start with just 'b' instead of 'sb' to match 0.93 bitmanip spec.

Also renamed Zbe instructions to resolve name conflict even though
that change is in the 0.94 draft.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Move Shift Ones instructions from Zbb to Zbp to match 0.93 bitmanip spec.
Craig Topper [Fri, 22 Jan 2021 19:24:07 +0000 (11:24 -0800)]
[RISCV] Move Shift Ones instructions from Zbb to Zbp to match 0.93 bitmanip spec.

It's not really clear in the spec that these are in Zbp now, but
that's what I've gather from previous commits to the spec. I've
file an issue to get it documented properly.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Add SH*ADD(.UW) instructions to Zba extension based on 0.93 bitmanip spec.
Craig Topper [Fri, 22 Jan 2021 19:22:49 +0000 (11:22 -0800)]
[RISCV] Add SH*ADD(.UW) instructions to Zba extension based on 0.93 bitmanip spec.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Add Zba feature and move add.uw and slli.uw to it.
Craig Topper [Fri, 22 Jan 2021 18:58:06 +0000 (10:58 -0800)]
[RISCV] Add Zba feature and move add.uw and slli.uw to it.

Still need to add SH*ADD instructions.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Rename mnemonics slliu.w->slli.uw and addu.w->add.uw to match 0.93 bitmanip...
Craig Topper [Fri, 22 Jan 2021 18:57:00 +0000 (10:57 -0800)]
[RISCV] Rename mnemonics slliu.w->slli.uw and addu.w->add.uw to match 0.93 bitmanip spec.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Swap encodings of max and minu to match 0.93 bitmanip spec.
Craig Topper [Fri, 22 Jan 2021 18:47:12 +0000 (10:47 -0800)]
[RISCV] Swap encodings of max and minu to match 0.93 bitmanip spec.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Remove addiwu, addwu, subwu, subuw, clmulw, clmulrw, clmulhw to match 0.93...
Craig Topper [Fri, 22 Jan 2021 18:37:11 +0000 (10:37 -0800)]
[RISCV] Remove addiwu, addwu, subwu, subuw, clmulw, clmulrw, clmulhw to match 0.93 bitmanip spec.

Reviewed By: asb, frasercrmck

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

3 years ago[RISCV] Rename pcnt->cpop to match 0.93 bitmanip spec.
Craig Topper [Fri, 22 Jan 2021 18:23:46 +0000 (10:23 -0800)]
[RISCV] Rename pcnt->cpop to match 0.93 bitmanip spec.

This is the first of multiple patches to bring our 0.92
implementation up to 0.93.

Reviewed By: asb, frasercrmck

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

3 years ago[Tests] Add willreturn to libcalls in some tests
Nikita Popov [Fri, 22 Jan 2021 20:06:06 +0000 (21:06 +0100)]
[Tests] Add willreturn to libcalls in some tests

Willreturn would be inferred by FuncAttrs for these. Annotate them
to preserve test behavior in the future.

3 years ago[NewPM][AMDGPU] Skip adding CGSCCOptimizerLate callbacks at O0
Arthur Eubanks [Fri, 22 Jan 2021 18:47:10 +0000 (10:47 -0800)]
[NewPM][AMDGPU] Skip adding CGSCCOptimizerLate callbacks at O0

The legacy PM's EP_CGSCCOptimizerLate was only used under not-O0.

Fixes clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp under the new PM.

Reviewed By: arsenm

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

3 years ago[libc++] Introduce __bits
Thorsten Schütt [Mon, 18 Jan 2021 12:21:00 +0000 (13:21 +0100)]
[libc++] Introduce __bits

It has the low-level bit fiddling operations from bit. It eliminates a cyclic dependency between __bit_reference, bits, and vector. I want to exploit this in later patches.

Reviewed By: #libc, ldionne

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

3 years ago[CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC
Bjorn Pettersson [Tue, 19 Jan 2021 14:24:20 +0000 (15:24 +0100)]
[CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC

Most of CGExprConstant.cpp is using the CharUnits abstraction
and is using getCharWidth() (directly of indirectly) when converting
between size of a char and size in bits. This patch is making that
abstraction more consistent by adding CharTy to the CodeGenTypeCache
(honoring getCharWidth() when mapping from char to LLVM IR types,
instead of using Int8Ty directly).

Reviewed By: rjmccall

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

3 years ago[CodeGen] Use getCharWidth() more consistently in CGRecordLowering. NFC
Bjorn Pettersson [Tue, 19 Jan 2021 14:32:35 +0000 (15:32 +0100)]
[CodeGen] Use getCharWidth() more consistently in CGRecordLowering. NFC

When using getByteArrayType the requested size is calculated in
char units, but the type used for the array was hardcoded to the
Int8Ty. This patch is using getCharWIdth a bit more consistently
by using getIntNTy in combination with getCharWidth, instead
of explictly using getInt8Ty.

Reviewed By: rjmccall

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

3 years ago[mlir][OpFormatGen] Add support for anchoring optional groups with types
River Riddle [Fri, 22 Jan 2021 20:07:07 +0000 (12:07 -0800)]
[mlir][OpFormatGen] Add support for anchoring optional groups with types

This revision adds support for using either operand or result types to anchor an optional group. It also removes the arbitrary restriction that type directives must refer to variables in the same group, which is overly limiting for a declarative format syntax.

Fixes PR#48784

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

3 years agoRemove obsolete TODOs
Julian Lettner [Fri, 22 Jan 2021 20:01:54 +0000 (12:01 -0800)]
Remove obsolete TODOs

Remove a few of my own TODOs that I will not have time to fix from lit
code.

3 years ago[SimplifyLibCalls] Skip unused calls in sincos transform
Nikita Popov [Fri, 22 Jan 2021 19:44:44 +0000 (20:44 +0100)]
[SimplifyLibCalls] Skip unused calls in sincos transform

If the call result is unused, we should let it get DCEd rather
than replacing it. Also, don't try to replace an existing sincos
with another one (unless it's as part of combining sin and cos).

This avoids an infinite combine loop if the calls are not DCEd
as expected, which can happen with D94106 and lack of willreturn
annotation in hand-crafted IR.

3 years ago[libc++] Bring back mach_absolute_time implementation of steady_clock
Louis Dionne [Thu, 21 Jan 2021 22:53:29 +0000 (17:53 -0500)]
[libc++] Bring back mach_absolute_time implementation of steady_clock

This is meant to unblock Chrome, as discussed in https://llvm.org/D74489.

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

3 years agoAdd more explicit assert for failures
Jacques Pienaar [Fri, 22 Jan 2021 19:45:25 +0000 (11:45 -0800)]
Add more explicit assert for failures

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

3 years ago[mlir][Linalg] Extend tile+fuse to work on Linalg operation on tensors.
MaheshRavishankar [Fri, 22 Jan 2021 19:32:50 +0000 (11:32 -0800)]
[mlir][Linalg] Extend tile+fuse to work on Linalg operation on tensors.

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

3 years ago[NFC][libc++] Update the implementation status.
Mark de Wever [Fri, 22 Jan 2021 19:24:33 +0000 (20:24 +0100)]
[NFC][libc++] Update the implementation status.

During the review of https://reviews.llvm.org/D93912 we failed to notice
the implementation status wasn't updated. This rectifies the issue.

3 years ago[mlir][Linalg] NFC: Refactor LinalgDependenceGraphElem to allow
MaheshRavishankar [Fri, 22 Jan 2021 19:19:03 +0000 (11:19 -0800)]
[mlir][Linalg] NFC: Refactor LinalgDependenceGraphElem to allow
representing dependence from producer result to consumer.

With Linalg on tensors the dependence between operations can be from
the result of the producer to the consumer. This change just does a
NFC refactoring of the LinalgDependenceGraphElem to allow representing
both OpResult and OpOperand*.

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

3 years ago[CSSPGO] LTO option for pseudo probe
Hongtao Yu [Wed, 20 Jan 2021 17:24:43 +0000 (09:24 -0800)]
[CSSPGO] LTO option for pseudo probe

Adding a lld option to support emitting pseudo probe metadata in LTO mode.

Reviewed By: MaskRay, wmi, wenlei

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

3 years ago[flang][nfc] Fix comments, remove needless API, tweak script
peter klausler [Thu, 21 Jan 2021 22:59:43 +0000 (14:59 -0800)]
[flang][nfc] Fix comments, remove needless API, tweak script

* Remove an unimplemented and unused member function declaration
* Remove a misleading comment about an unrelated constraint number
* Fix a comment
* Add f18 crash message to "flang" driver script

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

3 years ago[SystemZ][z/OS] Fix No such file or directory expression error matching in lit tests...
Abhina Sreeskantharajan [Fri, 22 Jan 2021 18:54:01 +0000 (13:54 -0500)]
[SystemZ][z/OS] Fix No such file or directory expression error matching in lit tests - continued

This is a continuation of https://reviews.llvm.org/D94239. I missed some other spellings of the same error.

Reviewed By: muiez

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

3 years ago[flang] Correct shape analysis for transformational intrinsic functions
peter klausler [Thu, 14 Jan 2021 20:54:31 +0000 (12:54 -0800)]
[flang] Correct shape analysis for transformational intrinsic functions

Correct the analysis of references to transformational intrinsic
functions that have different semantics based on the presence or
absence of a DIM= argument; add shape analysis for UNPACK().

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

3 years ago[InstCombine] narrow abs with sign-extended input
Sanjay Patel [Fri, 22 Jan 2021 18:33:21 +0000 (13:33 -0500)]
[InstCombine] narrow abs with sign-extended input

In the motivating cases from https://llvm.org/PR48816 ,
we have a trailing trunc. But that is not required to
reduce the abs width:
https://alive2.llvm.org/ce/z/ECaz-p
...as long as we clear the int-min-is-poison bit (nsw).

We have some existing tests that are affected, and I'm
not sure what the overall implications are, but in general
we favor narrowing operations over preserving nsw/nuw.

If that causes problems, we could restrict this transform
based on type (shouldChangeType() and/or vector vs. scalar).

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

3 years ago[InstCombine] add tests for abs(sext X); NFC
Sanjay Patel [Fri, 22 Jan 2021 15:02:51 +0000 (10:02 -0500)]
[InstCombine] add tests for abs(sext X); NFC

https://llvm.org/PR48816

3 years ago[mlir][spirv] Define spv.IsNan/spv.IsInf and add lowerings
Lei Zhang [Fri, 22 Jan 2021 18:08:00 +0000 (13:08 -0500)]
[mlir][spirv] Define spv.IsNan/spv.IsInf and add lowerings

spv.Ordered/spv.Unordered are meant for OpenCL Kernel capability.
For Vulkan Shader capability, we should use spv.IsNan to check
whether a number is NaN.

Add a new pattern for converting `std.cmpf ord|uno` to spv.IsNan
and bumped the pattern converting to spv.Ordered/spv.Unordered
to a higher benefit. The SPIR-V target environment will properly
select between these two patterns.

Reviewed By: mravishankar

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

3 years ago[flang] Remove some needless operations in expr rewriting
peter klausler [Thu, 21 Jan 2021 22:38:42 +0000 (14:38 -0800)]
[flang] Remove some needless operations in expr rewriting

Expressions emitted to module files and error messages
sometimes contain conversions of integer results of inquiry
intrinsics; these are usually not needed, and can conflict
with "int" in the user's namespace.  Improve folding so that
these conversions don't appear, and do some other clean-up
in adjacent code.

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

3 years ago[mlir][spirv] Fix script for availability autogen and refresh ops
Lei Zhang [Fri, 22 Jan 2021 18:03:59 +0000 (13:03 -0500)]
[mlir][spirv] Fix script for availability autogen and refresh ops

Previously we only autogen the availability for ops that are
direct instantiating `SPV_Op` and expected other subclasses of
`SPV_Op` to define aggregated availability for all ops. This is
quite error prone and we can miss capabilities for certain ops.
Also it's arguable to have multiple levels of subclasses and try
to deduplicate too much: having the availability directly in the
op can be quite explicit and clear. A few extra lines of
declarative code is fine.

Reviewed By: mravishankar

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

3 years ago[LLDB] Fix how ObjCBOOLSummaryProvider deals with BOOL
Shafik Yaghmour [Fri, 22 Jan 2021 18:04:04 +0000 (10:04 -0800)]
[LLDB] Fix how ObjCBOOLSummaryProvider deals with BOOL

ObjCBOOLSummaryProvider was incorrectly treating BOOL as unsigned and this is now fixed.
Also adding tests for one bit bit-fields of BOOL and unsigned char.

3 years ago[mlir] Add coro intrinsics operations to LLVM dialect
Eugene Zhulenev [Fri, 22 Jan 2021 17:11:26 +0000 (09:11 -0800)]
[mlir] Add coro intrinsics operations to LLVM dialect

This PR only has coro intrinsics needed for the Async to LLVM lowering. Will add other intrinsics as needed in the followup PRs.

Reviewed By: mehdi_amini

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

3 years ago[llvm-mca] Adding local lit config file for X86 targets
Wolfgang Pieb [Fri, 22 Jan 2021 17:51:59 +0000 (09:51 -0800)]
[llvm-mca] Adding local lit config file for X86 targets

3 years ago[libc++] Fix broken build when merging libc++abi into libc++ on Apple
Louis Dionne [Fri, 22 Jan 2021 17:39:17 +0000 (12:39 -0500)]
[libc++] Fix broken build when merging libc++abi into libc++ on Apple

3 years ago[OpenMP] libomp: properly initialize buckets in __kmp_dephash_extend
Joseph Schuchart [Fri, 22 Jan 2021 17:29:31 +0000 (20:29 +0300)]
[OpenMP] libomp: properly initialize buckets in __kmp_dephash_extend

The buckets are initialized in __kmp_dephash_create but when they are extended
the memory is allocated but not NULL'd, potentially leaving some buckets
uninitialized after all entries have been copied into the new allocation.
This commit makes sure the buckets are properly initialized with NULL before
copying the entries.

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

3 years ago[ELF] --wrap: retain __wrap_foo if foo is defined in an object/bitcode file
Fangrui Song [Fri, 22 Jan 2021 17:20:29 +0000 (09:20 -0800)]
[ELF] --wrap: retain __wrap_foo if foo is defined in an object/bitcode file

If foo is referenced in any object file, bitcode file or shared object,
`__wrap_foo` should be retained as the redirection target of sym
(f96ff3c0f8ebd941b3f6b345164c3d858b781484).

If the object file defining foo has foo references, we cannot easily distinguish
the case from cases where foo is not referenced (we haven't scanned
relocations). Retain `__wrap_foo` because we choose to wrap sym references
regardless of whether sym is defined to keep non-LTO/LTO/relocatable links' behaviors similar
https://sourceware.org/bugzilla/show_bug.cgi?id=26358 .

If foo is defined in a shared object, `__wrap_foo` can still be omitted
(`wrap-dynamic-undef.s`).

Reviewed By: andrewng

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

3 years ago[mlir][StandardOps] Fix typos in the td file.
Hanhan Wang [Fri, 22 Jan 2021 17:02:44 +0000 (09:02 -0800)]
[mlir][StandardOps] Fix typos in the td file.

- Fix arguments name for subview and subtensor.
- Fix a typo in a comment of subtensor's method.

Reviewed By: nicolasvasilache

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

3 years ago[MLIR] Add support for extracting an integer sample point (if one exists) from an...
Arjun P [Fri, 22 Jan 2021 15:34:05 +0000 (21:04 +0530)]
[MLIR] Add support for extracting an integer sample point (if one exists) from an unbounded FlatAffineConstraints.

With this, we have complete support for finding integer sample points in FlatAffineConstraints.

Reviewed By: ftynse

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

3 years ago[HIP] Support __managed__ attribute
Yaxun (Sam) Liu [Thu, 15 Oct 2020 12:38:46 +0000 (08:38 -0400)]
[HIP] Support __managed__ attribute

This patch implements codegen for __managed__ variable attribute for HIP.

Diagnostics will be added later.

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

3 years ago[SystemZ][z/OS] Fix No such file or directory expression error
Abhina Sreeskantharajan [Fri, 22 Jan 2021 16:41:36 +0000 (11:41 -0500)]
[SystemZ][z/OS] Fix No such file or directory expression error

On z/OS, the following error message is not matched correctly in lit tests. This patch updates the CHECK expression to match the end period successfully.
```
EDC5129I No such file or directory.
```

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

3 years ago[X86][AVX] canonicalizeLaneShuffleWithRepeatedOps - handle vperm2x128(movddup(x)...
Simon Pilgrim [Fri, 22 Jan 2021 16:05:19 +0000 (16:05 +0000)]
[X86][AVX] canonicalizeLaneShuffleWithRepeatedOps - handle vperm2x128(movddup(x),movddup(y)) cases

Fold vperm2x128(movddup(x),movddup(y)) -> movddup(vperm2x128(x,y))

3 years ago[X86][AVX] canonicalizeLaneShuffleWithRepeatedOps - handle unary vperm2x128(permute...
Simon Pilgrim [Fri, 22 Jan 2021 15:47:06 +0000 (15:47 +0000)]
[X86][AVX] canonicalizeLaneShuffleWithRepeatedOps - handle unary vperm2x128(permute/shift(x,c),undef) cases

Fold vperm2x128(permute/shift(x,c),undef) -> permute/shift(vperm2x128(x,undef),c)

3 years ago[X86][AVX] combineTargetShuffle - simplify the X86ISD::VPERM2X128 subvector matching
Simon Pilgrim [Fri, 22 Jan 2021 15:20:11 +0000 (15:20 +0000)]
[X86][AVX] combineTargetShuffle - simplify the X86ISD::VPERM2X128 subvector matching

Simplify vperm2x128(concat(X,Y),concat(Z,W)) folding.

Use collectConcatOps / ISD::INSERT_SUBVECTOR to find the source subvectors instead of hardcoded immediate matching.

3 years ago[flang] Fix typo in error message
Peter Steinfeld [Fri, 22 Jan 2021 15:09:23 +0000 (07:09 -0800)]
[flang] Fix typo in error message

The title says it all.

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

3 years ago[LoopUnswitch] Fix logic to avoid unswitching with atomic loads.
Florian Hahn [Fri, 22 Jan 2021 15:03:17 +0000 (15:03 +0000)]
[LoopUnswitch] Fix logic to avoid unswitching with atomic loads.

The existing code did not deal with atomic loads correctly. Such loads
are represented as MemoryDefs. Bail out on any MemoryAccess that is not
a MemoryUse.

3 years ago[LoopUnswitch] Add test cases with atomic loads & call
Florian Hahn [Fri, 22 Jan 2021 15:00:31 +0000 (15:00 +0000)]
[LoopUnswitch] Add test cases with atomic loads & call

3 years ago[coro.async] Make sure we process async coroutines
Arnold Schwaighofer [Thu, 21 Jan 2021 16:41:37 +0000 (08:41 -0800)]
[coro.async] Make sure we process async coroutines

Because we were not looking for the llvm.coro.id.async intrinsic in the
early coro pass which triggers follow-up passes we relied on the
llvm.coro.end intrinsic being present. This might not be the case in
functions that end in unreachable code.

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

3 years ago[libomptarget][devicertl] Drop templated atomic functions
Jon Chesterfield [Fri, 22 Jan 2021 14:48:22 +0000 (14:48 +0000)]
[libomptarget][devicertl] Drop templated atomic functions

[libomptarget][devicertl] Drop templated atomic functions

The five __kmpc_atomic templates are instantiated a total of seven times.
This change replaces the template with explictly typed functions, which
have the same prototype for amdgcn and nvptx, and implements them with
the same code presently in use.

Rolls in the accepted but not yet landed D95085.

The unsigned long long type can be replaced with uint64_t when replacing
the cuda function. Until then, clang warns on casting a pointer to one to
a pointer to the other.

Reviewed By: tianshilei1992

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

3 years agoRevert "[NFCI-ish][SimplifyCFG] FoldBranchToCommonDest(): really don't deal with...
Roman Lebedev [Fri, 22 Jan 2021 14:37:11 +0000 (17:37 +0300)]
Revert "[NFCI-ish][SimplifyCFG] FoldBranchToCommonDest(): really don't deal with uncond branches"

Does not build in XCode:
http://green.lab.llvm.org/green/job/clang-stage1-RA/17963/consoleFull#-1704658317a1ca8a51-895e-46c6-af87-ce24fa4cd561

This reverts commit aabed3718ae25476c0f6b7e70c83ba4658f00e5c.

3 years ago[InstCombine] Fold `(~x) | y` --> `~(x & (~y))` iff it is free to do so
Roman Lebedev [Fri, 22 Jan 2021 09:58:45 +0000 (12:58 +0300)]
[InstCombine] Fold `(~x) | y` --> `~(x & (~y))` iff it is free to do so

Iff we know we can get rid of the inversions in the new pattern,
we can thus get rid of the inversion in the old pattern,
this decreasing instruction count.

Note that we could position this transformation as just hoisting
of the `not` (still, iff y is freely negatible), but the test changes
show a number of regressions, so let's not do that.

3 years ago[InstCombine] Fold `(~x) & y` --> `~(x | (~y))` iff it is free to do so
Roman Lebedev [Fri, 22 Jan 2021 09:57:52 +0000 (12:57 +0300)]
[InstCombine] Fold `(~x) & y` --> `~(x | (~y))` iff it is free to do so

Iff we know we can get rid of the inversions in the new pattern,
we can thus get rid of the inversion in the old pattern,
this decreasing instruction count.

3 years ago[NFC][InstCombine] Add tests for `(~x) &/| y` --> `~(x |/& (~y))` fold
Roman Lebedev [Fri, 22 Jan 2021 09:54:16 +0000 (12:54 +0300)]
[NFC][InstCombine] Add tests for `(~x) &/| y` --> `~(x |/& (~y))` fold

Iff y is free to invert, and the users of the expression can be updated,
we can undo De-Morgan fold, and immediately get rid of the `not` op.

3 years ago[NFC][InstCombine] Extract freelyInvertAllUsersOf() out of canonicalizeICmpPredicate()
Roman Lebedev [Fri, 22 Jan 2021 09:51:40 +0000 (12:51 +0300)]
[NFC][InstCombine] Extract freelyInvertAllUsersOf() out of canonicalizeICmpPredicate()

I'd like to use it in an upcoming fold.

3 years ago[NFC][SimplifyCFG] FoldBranchToCommonDest(): extract the actual transform into helper...
Roman Lebedev [Thu, 21 Jan 2021 18:32:20 +0000 (21:32 +0300)]
[NFC][SimplifyCFG] FoldBranchToCommonDest(): extract the actual transform into helper function

I'm intentionally structuring it this way, so that the actual fold only
does the fold, and no legality/correctness checks, all of which must be
done by the caller. This allows for the fold code to be more compact
and more easily grokable.

3 years ago[NFC][SimplifyCFG] FoldBranchToCommonDest(): extract check for destination sharing...
Roman Lebedev [Thu, 21 Jan 2021 18:24:06 +0000 (21:24 +0300)]
[NFC][SimplifyCFG] FoldBranchToCommonDest(): extract check for destination sharing into a helper function

As a follow-up, i'll extract the actual transform into a function,
and this helper will be called from both places,
so this avoids code duplication.

3 years ago[NFC][SimplifyCFG] FoldBranchToCommonDest(): somewhat better structure weight updatin...
Roman Lebedev [Thu, 21 Jan 2021 17:49:26 +0000 (20:49 +0300)]
[NFC][SimplifyCFG] FoldBranchToCommonDest(): somewhat better structure weight updating code

Hoist the successor updating out of the code that deals with branch
weight updating, and hoist the 'has weights' check from the latter,
making code more consistent and easier to follow.

3 years ago[NFC][SimplifyCFG] FoldBranchToCommonDest(): unclutter Cond/CondInPred handling
Roman Lebedev [Thu, 21 Jan 2021 17:21:55 +0000 (20:21 +0300)]
[NFC][SimplifyCFG] FoldBranchToCommonDest(): unclutter Cond/CondInPred handling

We don't need those variables, we can just get the final value directly.

3 years ago[NFCI-ish][SimplifyCFG] FoldBranchToCommonDest(): really don't deal with uncond branches
Roman Lebedev [Thu, 21 Jan 2021 20:23:52 +0000 (23:23 +0300)]
[NFCI-ish][SimplifyCFG] FoldBranchToCommonDest(): really don't deal with uncond branches

While we already ignore uncond branches, we could still potentially
end up with a conditional branches with identical destinations
due to the visitation order, or because we were called as an utility.
But if we have such a disguised uncond branch,
we still probably shouldn't deal with it here.

3 years ago[SimplifyCFG] FoldBranchToCommonDest(): don't deal with unconditional branches
Roman Lebedev [Thu, 21 Jan 2021 16:45:41 +0000 (19:45 +0300)]
[SimplifyCFG] FoldBranchToCommonDest(): don't deal with unconditional branches

The case where BB ends with an unconditional branch,
and has a single predecessor w/ conditional branch
to BB and a single successor of BB is exactly the pattern
SpeculativelyExecuteBB() transform deals with.
(and in this case they both allow speculating only a single instruction)

Well, or FoldTwoEntryPHINode(), if the final block
has only those two predecessors.

Here, in FoldBranchToCommonDest(), only a weird subset of that
transform is supported, and it's glued on the side in a weird way.
  In particular, it took me a bit to understand that the Cond
isn't actually a branch condition in that case, but just the value
we allow to speculate (otherwise it reads as a miscompile to me).
  Additionally, this only supports for the speculated instruction
to be an ICmp.

So let's just unclutter FoldBranchToCommonDest(), and leave
this transform up to SpeculativelyExecuteBB(). As far as i can tell,
this shouldn't really impact optimization potential, but if it does,
improving SpeculativelyExecuteBB() will be more beneficial anyways.

Notably, this only affects a single test,
but EarlyCSE should have run beforehand in the pipeline,
and then FoldTwoEntryPHINode() would have caught it.

This reverts commit rL158392 / commit d33f4efbfdef6ffccf212ab3e40a7673589085fd.

3 years ago[clang][ASTImporter] Add support for importing CXXFoldExpr.
Balázs Kéri [Fri, 22 Jan 2021 11:39:21 +0000 (12:39 +0100)]
[clang][ASTImporter] Add support for importing CXXFoldExpr.

Reviewed By: shafik, martong

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

3 years ago[ARM] Disable sign extended SSAT pattern recognition.
David Green [Fri, 22 Jan 2021 14:07:48 +0000 (14:07 +0000)]
[ARM] Disable sign extended SSAT pattern recognition.

I may have given bad advice, and skipping sext_inreg when matching SSAT
patterns is not valid on it's own. It at least needs to sext_inreg the
input again, but as far as I can tell is still only valid based on
demanded bits. For the moment disable that part of the combine,
hopefully reimplementing it in the future more correctly.

3 years agoAvoid fragile type lookups in GDB pretty printer
Moritz Sichert [Mon, 11 Jan 2021 14:55:20 +0000 (15:55 +0100)]
Avoid fragile type lookups in GDB pretty printer

Instead of using the type llvm::StringMapEntry<{stringified_value_type}>
use only the base class llvm::StringMapEntryBase and calculate the
offsets of the member variables manually. The approach with stringifying
the name of the value type is pretty fragile as it can easily break with
local and dependent types.

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