Commit Graph

283 Commits

Author SHA1 Message Date
Matthias Krüger
b1d1e99c22
Rollup merge of #113780 - dtolnay:printkindpath, r=b-naber
Support `--print KIND=PATH` command line syntax

As is already done for `--emit KIND=PATH` and `-L KIND=PATH`.

In the discussion of #110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o` path to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`.

I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](d43cf3a51a/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system.

From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse". 31eda6f7c3/src/cargo/core/compiler/build_context/target_info.rs (L242) (FYI `@weihanglo` as you dealt with this recently in https://github.com/rust-lang/cargo/pull/11633.)

Mentioning reviewers active in #110785: `@fee1-dead` `@jyn514` `@bjorn3`
2023-07-21 06:52:28 +02:00
Matthias Krüger
2734b5ada9
Rollup merge of #113723 - khei4:khei4/llvm-stats, r=oli-obk,nikic
Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics.

This resurrects PR https://github.com/rust-lang/rust/pull/104000, which has sat idle for a while. And I want to see the effect of stack-move optimizations on LLVM (like https://reviews.llvm.org/D153453) :).

I have applied the changes requested by `@oli-obk` and `@nagisa`  https://github.com/rust-lang/rust/pull/104000#discussion_r1014625377 and https://github.com/rust-lang/rust/pull/104000#discussion_r1014642482 in the latest commits.

r? `@oli-obk`

-----

LLVM has a neat [statistics](https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option) feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too.

-----
(Edit: fix broken link
(Edit2: fix segmentation fault and use malloc

If `rustc` is built with
```toml
[llvm]
assertions = true
```
Then you can see like
```
rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
         3 aa                           - Number of MayAlias results
       193 aa                           - Number of MustAlias results
       531 aa                           - Number of NoAlias results
...
```

And the current default build emits only
```
$ rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
$
```
This might be better to emit the message to tell assertion flag necessity, but now I can't find how to do that...
2023-07-21 06:52:27 +02:00
David Tolnay
815a114974
Implement printing to file in PassWrapper 2023-07-20 11:04:31 -07:00
khei4
c7bf20dfdc address feedback from nikic and oli-obk https://github.com/rust-lang/rust/pull/113723/files
use slice memcpy rather than strcpy and write it on stdout

use println on failure

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2023-07-20 16:53:06 +09:00
bors
c4e6fe9240 Auto merge of #113714 - Kobzol:ci-cmake, r=nikic
CI: build CMake 3.20 to support LLVM 17

LLVM 17 will require CMake at least 3.20, so we have to go back to building our own CMake on the Linux x64 dist builder.

r? `@nikic`
2023-07-17 15:46:43 +00:00
Jakub Beránek
e95caa7b72 Link to execinfo on NetBSD 2023-07-17 08:30:54 +02:00
khei4
4d307c4822 print on rustc_codegen_llvm and rename malloc and cpy c_char 2023-07-17 00:37:52 +09:00
Patrick Walton
2d47816cba rustc_llvm: Add a -Z print-llvm-stats option to expose LLVM statistics.
LLVM has a neat [statistics] feature that tracks how often optimizations kick
in. It's very handy for optimization work. Since we expose the LLVM pass
timings, I thought it made sense to expose the LLVM statistics too.

[statistics]: https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option
2023-07-16 22:56:04 +09:00
bors
ffb9b61294 Auto merge of #113430 - Zalathar:hash, r=b-naber
Remove `LLVMRustCoverageHashCString`

Coverage has two FFI functions for computing the hash of a byte string. One takes a ptr/len pair (`LLVMRustCoverageHashByteArray`), and the other takes a NUL-terminated C string (`LLVMRustCoverageHashCString`).

But on closer inspection, the C string version is unnecessary. The calling-side code converts a Rust `&str` into a `CString`, and the C++ code then immediately turns it back into a ptr/len string before actually hashing it. So we can just call the ptr/len version directly instead.

---

This PR also fixes a bug in the C++ declaration of `LLVMRustCoverageHashByteArray`. It should be `size_t`, since that's what is declared and passed on the Rust side, and it's what `StrRef`'s constructor expects to receive on the callee side.
2023-07-16 01:56:23 +00:00
Krasimir Georgiev
6ddf9128b2 llvm-wrapper: update for LLVM API change
No functional changes intended.

Adds an include for llvm::SmallString. Previously, this must have been
implicitly provided by some of the existing headers. With recent LLVM
changes, not anymore:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/20776#01895448-44a4-4a1e-8407-9d41d0186132/209-690
2023-07-14 12:10:29 +00:00
Zalathar
352d031599 Remove LLVMRustCoverageHashCString
Coverage has two FFI functions for computing the hash of a byte string. One
takes a ptr/len pair, and the other takes a NUL-terminated C string.

But on closer inspection, the C string version is unnecessary. The calling-side
code converts a Rust `&str` into a C string, and the C++ code then immediately
turns it back into a ptr/len string before actually hashing it.
2023-07-13 11:31:15 +10:00
Zalathar
7292608e21 Fix the length parameter type of LLVMRustCoverageHashByteArray
The Rust-side declaration uses `libc::size_t` for the number of bytes, but the
C++ declaration was using `unsigned` instead of `size_t`.
2023-07-13 11:31:15 +10:00
Krasimir Georgiev
71958da485 llvm-wrapper: adapt for LLVM API change
Adapts the wrapper for LLVM commit
546ec641b4.

Found by the experimental rust + LLVM @ HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/20723#01894922-ed5d-4830-81f6-a27fb82ec8c7/210-645
2023-07-12 09:30:31 +00:00
Jubilee Young
0726c7826b Reuse LLVMConstInBoundsGEP2
We have had LLVM 14 as our minimum for a bit now.
2023-07-10 00:20:56 -07:00
fee1-dead
e461502e06
Rollup merge of #112791 - WaffleLapkin:wag_the_llvm, r=cuviper
llvm ffi: Expose `CallInst->setTailCallKind`

This is needed for the explicit tail calls experiment.
2023-07-06 09:20:31 +08:00
Jakub Beránek
62728c7aaf
Add rustc option to output LLVM optimization remarks to YAML files 2023-07-02 13:41:36 +02:00
Maybe Waffle
bf5eaa4550 llvm ffi: Expose CallInst->setTailCallKind 2023-06-30 16:31:45 +00:00
Wesley Wiser
019d75b44e Add SafeStack support to rustc
Adds support for LLVM [SafeStack] which provides backward edge control
flow protection by separating the stack into two parts: data which is
only accessed in provable safe ways is allocated on the normal stack
(the "safe stack") and all other data is placed in a separate allocation
(the "unsafe stack").

SafeStack support is enabled by passing `-Zsanitizer=safestack`.

[SafeStack]: https://clang.llvm.org/docs/SafeStack.html
2023-05-26 15:18:54 -04:00
bors
77fb0cd3aa Auto merge of #111364 - cuviper:unhack-thinlto, r=nikic
Remove the ThinLTO CU hack

This reverts #46722, commit e0ab5d5feb.

Since #111167, commit 10b69dde3f, we are
generating DWARF subprograms in a way that is meant to be more compatible
with LLVM's expectations, so hopefully we don't need this workaround
rewriting CUs anymore.
2023-05-18 01:35:41 +00:00
Evgeniy A. Dushistov
6b58ff5cdf Usage of atomic counters for llvm code coverage 2023-05-12 01:40:04 +03:00
Zalathar
9addf0651c Correctly mark parameter RustMappingRegions as pointer-to-const
The regions don't need to be mutable because we pass a copy of them to LLVM
instead, and this matches the `*const` in the Rust-side signature.
2023-05-09 18:43:12 +10:00
Zalathar
7cab196e7c Isolate coverage FFI type layouts from their underlying LLVM C++ types 2023-05-09 18:08:32 +10:00
Josh Stone
c836c24994 Remove the ThinLTO CU hack
This reverts #46722, commit e0ab5d5feb.

Since #111167, commit 10b69dde3f, we are
generating DWARF subprograms in a way that is meant to be more compatible
with LLVM's expectations, so hopefully we don't need this workaround
rewriting CUs anymore.
2023-05-08 10:34:15 -07:00
Matthias Krüger
ecc0615967
Rollup merge of #111274 - cuviper:print-target-cpus, r=Mark-Simulacrum
Expand the LLVM coverage of `--print target-cpus`

We've been relying on a custom patch to add `MCSubtargetInfo::getCPUTable`
for `rustc --print target-cpus`, and just printing that it's not supported
on external LLVM builds. LLVM `main` now has `getAllProcessorDescriptions`
that can replace ours, so now we try to use that. In addition, the fallback
path can at least print the native and default cpu options.

There were also some mismatches in the function signatures here between
`LLVM_RUSTLLVM` and otherwise; this is now mitigated by sharing these
functions and only using cpp to adjust the function bodies.
2023-05-06 23:32:03 +02:00
Matthias Krüger
f440999bb2
Rollup merge of #111167 - cuviper:type-decl-disubprogram, r=michaelwoerister
debuginfo: split method declaration and definition

When we're adding a method to a type DIE, we only want a DW_AT_declaration
there, because LLVM LTO can't unify type definitions when a child DIE is a
full subprogram definition. Now the subprogram definition gets added at the
CU level with a specification link back to the abstract declaration.

Both GCC and Clang write debuginfo this way for C++ class methods.

Fixes #109730.
Fixes #109934.
2023-05-06 13:30:05 +02:00
Josh Stone
67ae38a336 Expand the LLVM coverage of --print target-cpus
We've been relying on a custom patch to add `MCSubtargetInfo::getCPUTable`
for `rustc --print target-cpus`, and just printing that it's not supported
on external LLVM builds. LLVM `main` now has `getAllProcessorDescriptions`
that can replace ours, so now we try to use that. In addition, the fallback
path can at least print the native and default cpu options.

There were also some mismatches in the function signatures here between
`LLVM_RUSTLLVM` and otherwise; this is now mitigated by sharing these
functions and only using cpp to adjust the function bodies.
2023-05-05 17:27:59 -07:00
James Dietz
cb74cd524f change expect() to unwrap_or_else() and update msg 2023-05-04 20:29:38 -04:00
James Dietz
9aa596a014 moved default CPU message inline 2023-05-04 20:29:38 -04:00
James Dietz
ea17aa9141 --print target-cpus shows default target cpu, updated docs 2023-05-04 20:29:38 -04:00
Josh Stone
10b69dde3f debuginfo: split method declaration and definition
When we're adding a method to a type DIE, we only want a DW_AT_declaration
there, because LLVM LTO can't unify type definitions when a child DIE is a
full subprogram definition. Now the subprogram definition gets added at the
CU level with a specification link back to the abstract declaration.
2023-05-03 15:52:31 -07:00
Tim Neumann
047ed32148 [LLVM17] Adapt to ExplicitEmulatedTLS removal. 2023-04-24 08:45:15 +00:00
Matthias Krüger
12a539f484
Rollup merge of #110668 - ehuss:fix-native-cpu-list, r=cuviper
Fix printing native CPU on cross-compiled compiler.

If `rustc` is cross-compiled from a different host, then the "native" entry in `rustc --print=target-cpus` would not appear. There is a check in the printing code that will avoid printing the "native" entry if the user has passed `--target`. However, that check was comparing the `--target` value with the `LLVM_TARGET_TRIPLE` which is the triple of the host that `rustc` was built on (the "build" target in Rust lingo), not the target it was being built for (the "host" in Rust lingo). This fixes it to use the target that LLVM was built for (which I'm pretty sure this is the correct function to determine that).

This fixes the cpu listing for aarch64-apple-darwin which is built on CI using the x86_64-apple-darwin host.
2023-04-23 20:06:32 +02:00
Eric Huss
e4e4110dc6 Fix printing native CPU on cross-compiled compiler. 2023-04-23 09:35:56 -07:00
Qiu Chaofan
1a44694713 Remove deprecated LLVM any_isa 2023-04-20 10:44:41 +08:00
Qiu Chaofan
7037ff99af Recognize AIX style archive kind 2023-04-19 11:10:47 +08:00
Josh Soref
e09d0d2a29 Spelling - compiler
* account
* achieved
* advising
* always
* ambiguous
* analysis
* annotations
* appropriate
* build
* candidates
* cascading
* category
* character
* clarification
* compound
* conceptually
* constituent
* consts
* convenience
* corresponds
* debruijn
* debug
* debugable
* debuggable
* deterministic
* discriminant
* display
* documentation
* doesn't
* ellipsis
* erroneous
* evaluability
* evaluate
* evaluation
* explicitly
* fallible
* fulfill
* getting
* has
* highlighting
* illustrative
* imported
* incompatible
* infringing
* initialized
* into
* intrinsic
* introduced
* javascript
* liveness
* metadata
* monomorphization
* nonexistent
* nontrivial
* obligation
* obligations
* offset
* opaque
* opportunities
* opt-in
* outlive
* overlapping
* paragraph
* parentheses
* poisson
* precisely
* predecessors
* predicates
* preexisting
* propagated
* really
* reentrant
* referent
* responsibility
* rustonomicon
* shortcircuit
* simplifiable
* simplifications
* specify
* stabilized
* structurally
* suggestibility
* translatable
* transmuting
* two
* unclosed
* uninhabited
* visibility
* volatile
* workaround

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-17 16:09:18 -04:00
Michael Goulet
4a24aab220
Rollup merge of #96971 - zhaixiaojuan:master, r=wesleywiser
Initial support for loongarch64-unknown-linux-gnu

Hi, We hope to add a new port in rust for LoongArch.

LoongArch intro
LoongArch is a RISC style ISA which is independently designed by Loongson
Technology in China. It is divided into two versions, the 32-bit version (LA32)
and the 64-bit version (LA64). LA64 applications have application-level
backward binary compatibility with LA32 applications. LoongArch is composed of
a basic part (Loongson Base) and an expanded part. The expansion part includes
Loongson Binary Translation (LBT), Loongson VirtualiZation (LVZ), Loongson SIMD
EXtension (LSX) and Loongson Advanced SIMD EXtension(LASX).

Currently the LA464 processor core supports LoongArch ISA and the Loongson
3A5000 processor integrates 4 64-bit LA464 cores. LA464 is a four-issue 64-bit
high-performance processor core. It can be used as a single core for high-end
embedded and desktop applications, or as a basic processor core to form an
on-chip multi-core system for server and high-performance machine applications.

Documentations:
ISA:
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html
ABI:
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
More docs can be found at:
https://loongson.github.io/LoongArch-Documentation/README-EN.html

Since last year, we have locally adapted two versions of rust, rust1.41 and rust1.57, and completed the test locally.
I'm not sure if I'm submitting all the patches at once, so I split up the patches and here's one of the commits
2023-04-11 20:28:45 -07:00
Nilstrieb
4b4948c2e3 Remove identity casts 2023-04-09 23:22:14 +02:00
bors
dd2b19539e Auto merge of #109862 - klensy:llvm-dd, r=nikic
llvm: replace some deprecated functions, add fixmes

Replace some deprecated llvm functions, add FIXME's (for simpler future work), replace some rust custom functions with llvm ones.
2023-04-08 15:57:59 +00:00
klensy
c0bc00174f review 2023-04-05 15:08:17 +03:00
klensy
f41e711b7e replace
LLVMRustBuildIntCast -> LLVMBuildIntCast2
LLVMRustAddHandler -> LLVMAddHandler
2023-04-04 15:12:36 +03:00
klensy
cc77ae07a9 Use existing llvm methods, instead of rust wrappers for:
LLVMRustBuildCleanupPad -> LLVMBuildCleanupPad
LLVMRustBuildCleanupRet -> LLVMBuildCleanupRet
LLVMRustBuildCatchPad -> LLVMBuildCatchPad
LLVMRustBuildCatchRet -> LLVMBuildCatchRet
LLVMRustBuildCatchSwitch -> LLVMBuildCatchSwitch
2023-04-04 15:12:36 +03:00
klensy
076116bb4c replace LLVMRustAppendModuleInlineAsm with LLVMAppendModuleInlineAsm, LLVMRustMetadataTypeInContext with LLVMMetadataTypeInContext 2023-04-04 15:12:35 +03:00
klensy
c53a9faa6f replace LLVMRustMetadataAsValue with LLVMMetadataAsValue 2023-04-04 15:12:35 +03:00
klensy
7d6181e4d8 add bunch of fixmes: currently there exist some functions that accept LLVMValueRef, some that accept LLVMMetadataRef, and replacing one with another not always possible without explicit convertion 2023-04-04 15:12:33 +03:00
zhaixiaojuan
ccf5417799 Enable loongarch64 LLVM target 2023-04-04 17:05:08 +08:00
Julia Tatz
0504a33383 Preserve, clarify, and extend debug information
`-Cdebuginfo=1` was never line tables only and
can't be due to backwards compatibility issues.
This was clarified and an option for line tables only
was added. Additionally an option for line info
directives only was added, which is well needed for
some targets. The debug info options should now
behave the same as clang's debug info options.
2023-03-31 07:28:39 -04:00
bors
cf32b9de1e Auto merge of #109720 - Dylan-DPC:rollup-u564m8s, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #108335 (rustdoc + rustdoc-json support for `feature(non_lifetime_binders)`)
 - #109534 (rustdoc: Unsupport importing `doc(primitive)` and `doc(keyword)` modules)
 - #109659 (llvm-wrapper: adapt for LLVM API change)
 - #109664 (Use span of placeholders in format_args!() expansion.)
 - #109683 (Check for overflow in `assemble_candidates_after_normalizing_self_ty`)
 - #109713 (Fix mismatched punctuation in Debug impl of AttrId)
 - #109718 (Rename `IndexVec::last` → `last_index`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-29 09:45:26 +00:00
Amanieu d'Antras
e3968be331 Add OpenHarmony targets
- `aarch64-unknown-linux-ohos`
- `armv7-unknown-linux-ohos`
2023-03-28 16:01:13 +01:00
Krasimir Georgiev
684e7a5461 llvm-wrapper: adapt for LLVM API change
Adapts the wrapper for the LLVM commit 377e1311d5.
2023-03-27 11:12:47 +00:00