about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2021-02-26Rollup merge of #82535 - wesleywiser:wip_codegen_thread_names, r=nagisaGuillaume Gomez-47/+77
Set codegen thread names Set names on threads spawned during codegen. Various debugging and profiling tools can take advantage of this to show a more useful identifier for threads. For example, gdb will show thread names in `info threads`: ``` (gdb) info threads Id Target Id Frame 1 Thread 0x7fffefa7ec40 (LWP 2905) "rustc" __pthread_clockjoin_ex (threadid=140737214134016, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145 2 Thread 0x7fffefa7b700 (LWP 2957) "rustc" 0x00007ffff125eaa8 in llvm::X86_MC::initLLVMToSEHAndCVRegMapping(llvm::MCRegisterInfo*) () from /home/wesley/.rustup/toolchains/stage1/lib/librustc_driver-f866439e29074957.so 3 Thread 0x7fffeef0f700 (LWP 3116) "rustc" futex_wait_cancelable (private=0, expected=0, futex_word=0x7fffe8602ac8) at ../sysdeps/nptl/futex-internal.h:183 * 4 Thread 0x7fffeed0e700 (LWP 3123) "rustc" rustc_codegen_ssa::back::write::spawn_work (cgcx=..., work=...) at /home/wesley/code/rust/rust/compiler/rustc_codegen_ssa/src/back/write.rs:1573 6 Thread 0x7fffe113b700 (LWP 3150) "opt foof.7rcbfp" 0x00007ffff2940e62 in llvm::CallGraph::populateCallGraphNode(llvm::CallGraphNode*) () from /home/wesley/.rustup/toolchains/stage1/lib/librustc_driver-f866439e29074957.so 8 Thread 0x7fffe0d39700 (LWP 3158) "opt foof.7rcbfp" 0x00007fffefe8998e in malloc_consolidate (av=av@entry=0x7ffe2c000020) at malloc.c:4492 9 Thread 0x7fffe0f3a700 (LWP 3162) "opt foof.7rcbfp" 0x00007fffefef27c4 in __libc_open64 (file=0x7fffe0f38608 "foof.foof.7rcbfp3g-cgu.6.rcgu.o", oflag=524865) at ../sysdeps/unix/sysv/linux/open64.c:48 (gdb) ``` and Windows Performance Analyzer will also show this information when profiling: ![image](https://user-images.githubusercontent.com/831192/109231017-d311f780-7793-11eb-8072-ab836a830e90.png)
2021-02-26Rollup merge of #82456 - klensy:or-else, r=estebankGuillaume Gomez-1/+1
Replaced some unwrap_or and map_or with lazy variants Replaced some `unwrap_or` and `map_or` with `unwrap_or_else` and `map_or_else`.
2021-02-25Set codegen thread namesWesley Wiser-47/+77
For example, gdb: ``` (gdb) info threads Id Target Id Frame 1 Thread 0x7fffefa7ec40 (LWP 2905) "rustc" __pthread_clockjoin_ex (threadid=140737214134016, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145 2 Thread 0x7fffefa7b700 (LWP 2957) "rustc" 0x00007ffff125eaa8 in llvm::X86_MC::initLLVMToSEHAndCVRegMapping(llvm::MCRegisterInfo*) () from /home/wesley/.rustup/toolchains/stage1/lib/librustc_driver-f866439e29074957.so 3 Thread 0x7fffeef0f700 (LWP 3116) "rustc" futex_wait_cancelable (private=0, expected=0, futex_word=0x7fffe8602ac8) at ../sysdeps/nptl/futex-internal.h:183 * 4 Thread 0x7fffeed0e700 (LWP 3123) "rustc" rustc_codegen_ssa::back::write::spawn_work (cgcx=..., work=...) at /home/wesley/code/rust/rust/compiler/rustc_codegen_ssa/src/back/write.rs:1573 6 Thread 0x7fffe113b700 (LWP 3150) "opt foof.7rcbfp" 0x00007ffff2940e62 in llvm::CallGraph::populateCallGraphNode(llvm::CallGraphNode*) () from /home/wesley/.rustup/toolchains/stage1/lib/librustc_driver-f866439e29074957.so 8 Thread 0x7fffe0d39700 (LWP 3158) "opt foof.7rcbfp" 0x00007fffefe8998e in malloc_consolidate (av=av@entry=0x7ffe2c000020) at malloc.c:4492 9 Thread 0x7fffe0f3a700 (LWP 3162) "opt foof.7rcbfp" 0x00007fffefef27c4 in __libc_open64 (file=0x7fffe0f38608 "foof.foof.7rcbfp3g-cgu.6.rcgu.o", oflag=524865) at ../sysdeps/unix/sysv/linux/open64.c:48 (gdb) ```
2021-02-25Rollup merge of #82214 - est31:no_to_string, r=oli-obkDylan DPC-5/+5
Remove redundant to_string calls
2021-02-23replaced some unwrap_or with unwrap_or_elseklensy-1/+1
2021-02-23Auto merge of #82127 - tgnottingham:tune-ahead-of-time-codegen, r=varkorbors-9/+64
rustc_codegen_ssa: tune codegen according to available concurrency This change tunes ahead-of-time codegening according to the amount of concurrency available, rather than according to the number of CPUs on the system. This can lower memory usage by reducing the number of compiled LLVM modules in memory at once, particularly across several rustc instances. Previously, each rustc instance would assume that it should codegen ahead of time to meet the demand of number-of-CPUs workers. But often, a rustc instance doesn't have nearly that much concurrency available to it, because the concurrency availability is split, via the jobserver, across all active rustc instances spawned by the driving cargo process, and is further limited by the `-j` flag argument. Therefore, each rustc might have had several times the number of LLVM modules in memory than it really needed to meet demand. If the modules were large, the effect on memory usage would be noticeable. With this change, the required amount of ahead-of-time codegen scales up with the actual number of workers running within a rustc instance. Note that the number of workers running can be less than the actual concurrency available to a rustc instance. However, if more concurrency is actually available, workers are spun up quickly as job tokens are acquired, and the ahead-of-time codegen scales up quickly as well.
2021-02-23Auto merge of #82102 - nagisa:nagisa/fix-dwo-name, r=davidtwcobors-1/+1
Set path of the compile unit to the source directory As part of the effort to implement split dwarf debug info, we ended up setting the compile unit location to the output directory rather than the source directory. Furthermore, it seems like we failed to remap the prefixes for this as well! The desired behaviour is to instead set the `DW_AT_GNU_dwo_name` to a path relative to compiler's working directory. This still allows debuggers to find the split dwarf files, while not changing the behaviour of the code that is compiling with regular debug info, and not changing the compiler's behaviour with regards to reproducibility. Fixes #82074 cc `@alexcrichton` `@davidtwco`
2021-02-23Rollup merge of #82091 - henryboisdequin:use-place-ref-more, r=RalfJungDylan DPC-1/+1
use PlaceRef abstractions more consistently Addresses this [comment](https://github.com/rust-lang/rust/pull/80865/files#r558978715) Associated issue: #80647 r? ```@RalfJung```
2021-02-22Rollup merge of #82367 - matthiaskrgr:wraps, r=petrochenkovYuki Okushi-4/+4
remove redundant option/result wrapping of return values If a function always returns `Ok(something)`, we can return `something` directly and remove the corresponding error handling in the callers. clippy::unnecessary_wraps
2021-02-21rustc_codegen_ssa: remove unneeded wrapping of return type of ↵Matthias Krüger-4/+4
execute_copy_from_cache_work_item (always returns Ok(..))
2021-02-21Rollup merge of #81966 - deg4uss3r:degausser/aarch64_apple_ios_sim, r=shepmasterYuki Okushi-0/+1
Add new `rustc` target for Arm64 machines that can target the iphonesimulator This PR lands a new target (`aarch64-apple-ios-sim`) that targets arm64 iphone simulator, previously unreachable from Apple Silicon machines. resolves #81632 r? `@shepmaster`
2021-02-19added aarch64_apple_ios_sim as a rustc targetRicky (deg4uss3r)-0/+1
2021-02-19Use a QueryContext for try_mark_green.Camille GILLOT-1/+1
2021-02-17Rollup merge of #81898 - ↵Dylan DPC-5/+25
nanguye2496:nanguye2496/fix_str_and_slice_visualization, r=varkor Fix debug information for function arguments of type &str or slice. Issue details: When lowering MIR to LLVM IR, the compiler decomposes every &str and slice argument into a data pointer and a usize. Then, the original argument is reconstructed from the pointer and the usize arguments in the body of the function that owns it. Since the original argument is declared in the body of a function, it should be marked as a LocalVariable instead of an ArgumentVairable. This confusion causes MSVC debuggers unable to visualize &str and slice arguments correctly. (See https://github.com/rust-lang/rust/issues/81894 for more details). Fix details: Making sure that the debug variable for every &str and slice argument is marked as LocalVariable instead of ArgumentVariable in computing_per_local_var_debug_info. This change has been verified on VS Code debugger, VS debugger, WinDbg and LLDB.
2021-02-17Rollup merge of #82105 - nagisa:nagisa/ensure-removed, r=petrochenkovGuillaume Gomez-11/+14
Don't fail to remove files if they are missing In the backend we may want to remove certain temporary files, but in certain other situations these files might not be produced in the first place. We don't exactly care about that, and the intent is really that these files are gone after a certain point in the backend. Here we unify the backend file removing calls to use `ensure_removed` which will attempt to delete a file, but will not fail if it does not exist (anymore). The tradeoff to this approach is, of course, that we may miss instances were we are attempting to remove files at wrong paths due to some bug – compilation would silently succeed but the temporary files would remain there somewhere.
2021-02-17Remove redundant to_string callsest31-5/+5
2021-02-16Auto merge of #81611 - cjgillot:meowner, r=estebankbors-2/+2
Only store a LocalDefId in some HIR nodes Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef. As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`. This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
2021-02-16make `visit_projection` take a `PlaceRef`Henry Boisdequin-1/+1
2021-02-16avoid full-slicing slicesMatthias Krüger-1/+1
If we already have a slice, there is no need to get another full-range slice from that, just use the original. clippy::redundant_slicing
2021-02-15rustc_codegen_ssa: tune codegen according to available concurrencyTyson Nottingham-9/+64
This change tunes ahead-of-time codegening according to the amount of concurrency available, rather than according to the number of CPUs on the system. This can lower memory usage by reducing the number of compiled LLVM modules in memory at once, particularly across several rustc instances. Previously, each rustc instance would assume that it should codegen ahead of time to meet the demand of number-of-CPUs workers. But often, a rustc instance doesn't have nearly that much concurrency available to it, because the concurrency availability is split, via the jobserver, across all active rustc instances spawned by the driving cargo process, and is further limited by the `-j` flag argument. Therefore, each rustc might have had several times the number of LLVM modules in memory than it really needed to meet demand. If the modules were large, the effect on memory usage would be noticeable. With this change, the required amount of ahead-of-time codegen scales up with the actual number of workers running within a rustc instance. Note that the number of workers running can be less than the actual concurrency available to a rustc instance. However, if more concurrency is actually available, workers are spun up quickly as job tokens are acquired, and the ahead-of-time codegen scales up quickly as well.
2021-02-15Use an ItemId inside mir::GlobalAsm.Camille GILLOT-2/+2
2021-02-14Don't fail to remove files if they are missingSimonas Kazlauskas-11/+14
In the backend we may want to remove certain temporary files, but in certain other situations these files might not be produced in the first place. We don't exactly care about that, and the intent is really that these files are gone after a certain point in the backend. Here we unify the backend file removing calls to use `ensure_removed` which will attempt to delete a file, but will not fail if it does not exist (anymore). The tradeoff to this approach is, of course, that we may miss instances were we are attempting to remove files at wrong paths due to some bug – compilation would silently succeed but the temporary files would remain there somewhere.
2021-02-14Set path of the compile unit to the source directorySimonas Kazlauskas-1/+1
As part of the effort to implement split dwarf debug info, we ended up setting the compile unit location to the output directory rather than the source directory. Furthermore, it seems like we failed to remap the prefixes for this as well! The desired behaviour is to instead set the `DW_AT_GNU_dwo_name` to a path relative to compiler's working directory. This still allows debuggers to find the split dwarf files, while not changing the behaviour of the code that is compiling with regular debug info, and not changing the compiler's behaviour with regards to reproducibility. Fixes #82074
2021-02-09Set the kind for local variables created by &str and slice arguments to ↵Nam Nguyen-5/+25
LocalVariable
2021-02-07HWASan supportTri Vo-0/+3
2021-02-03rustc_codegen_ssa: tune codegen scheduling to reduce memory usageTyson Nottingham-7/+19
For better throughput during parallel processing by LLVM, we used to sort CGUs largest to smallest. This would lead to better thread utilization by, for example, preventing a large CGU from being processed last and having only one LLVM thread working while the rest remained idle. However, this strategy would lead to high memory usage, as it meant the LLVM-IR for all of the largest CGUs would be resident in memory at once. Instead, we can compromise by ordering CGUs such that the largest and smallest are first, second largest and smallest are next, etc. If there are large size variations, this can reduce memory usage significantly.
2021-02-01Rollup merge of #81536 - tgnottingham:time-passes-rss, r=oli-obkJonas Schievink-2/+12
Indicate both start and end of pass RSS in time-passes output Previously, only the end of pass RSS was indicated. This could easily lead one to believe that the change in RSS from one pass to the next was attributable to the second pass, when in fact it occurred between the end of the first pass and the start of the second. Also, improve alignment of columns. Sample of output: ``` time: 0.739; rss: 607MB -> 637MB item_types_checking time: 8.429; rss: 637MB -> 775MB item_bodies_checking time: 11.063; rss: 470MB -> 775MB type_check_crate time: 0.232; rss: 775MB -> 777MB match_checking time: 0.139; rss: 777MB -> 779MB liveness_and_intrinsic_checking time: 0.372; rss: 775MB -> 779MB misc_checking_2 time: 8.188; rss: 779MB -> 1019MB MIR_borrow_checking time: 0.062; rss: 1019MB -> 1021MB MIR_effect_checking ```
2021-01-31Auto merge of #81327 - RalfJung:codegen-no-const-fail, r=oli-obkbors-21/+17
codegen: assume constants cannot fail to evaluate https://github.com/rust-lang/rust/pull/80579 landed, so we can finally remove this old hack from codegen and instead assume that consts never fail to evaluate. :) r? `@oli-obk`
2021-01-30codegen: assume constants cannot fail to evaluateRalf Jung-21/+17
also don't submit code to LLVM when the session has errors
2021-01-29Indicate both start and end of pass RSS in time-passes outputTyson Nottingham-2/+12
Previously, only the end of pass RSS was indicated. This could easily lead one to believe that the change in RSS from one pass to the next was attributable to the second pass, when in fact it occurred between the end of the first pass and the start of the second. Also, improve alignment of columns.
2021-01-29Rollup merge of #81333 - RalfJung:const-err-simplify, r=oli-obkYuki Okushi-6/+1
clean up some const error reporting around promoteds These are some error reporting simplifications enabled by https://github.com/rust-lang/rust/pull/80579. Further simplifications are possible but could be blocked on making `const_err` a hard error. r? ``````@oli-obk``````
2021-01-29Rollup merge of #80215 - visigoth:issue-80202-fix, r=estebankYuki Okushi-2/+7
Use -target when linking binaries for Mac Catalyst When running `rustc` with `-target x86_64-apple-ios-macabi`, the linker eventually gets run with `-arch x86_64`, because the linker back end splits the LLVM target triple and uses the first token as the target architecture. However, this does not work for the Mac Catalyst ABI, which is a separate target from Darwin. Specifying the full target triple with `-target` allows Mac Catalyst binaries to link and run. closes #80202
2021-01-29Rollup merge of #79570 - alexcrichton:split-debuginfo, r=bjorn3Yuki Okushi-48/+56
rustc: Stabilize `-Zrun-dsymutil` as `-Csplit-debuginfo` This commit adds a new stable codegen option to rustc, `-Csplit-debuginfo`. The old `-Zrun-dsymutil` flag is deleted and now subsumed by this stable flag. Additionally `-Zsplit-dwarf` is also subsumed by this flag but still requires `-Zunstable-options` to actually activate. The `-Csplit-debuginfo` flag takes one of three values: * `off` - This indicates that split-debuginfo from the final artifact is not desired. This is not supported on Windows and is the default on Unix platforms except macOS. On macOS this means that `dsymutil` is not executed. * `packed` - This means that debuginfo is desired in one location separate from the main executable. This is the default on Windows (`*.pdb`) and macOS (`*.dSYM`). On other Unix platforms this subsumes `-Zsplit-dwarf=single` and produces a `*.dwp` file. * `unpacked` - This means that debuginfo will be roughly equivalent to object files, meaning that it's throughout the build directory rather than in one location (often the fastest for local development). This is not the default on any platform and is not supported on Windows. Each target can indicate its own default preference for how debuginfo is handled. Almost all platforms default to `off` except for Windows and macOS which default to `packed` for historical reasons. Some equivalencies for previous unstable flags with the new flags are: * `-Zrun-dsymutil=yes` -> `-Csplit-debuginfo=packed` * `-Zrun-dsymutil=no` -> `-Csplit-debuginfo=unpacked` * `-Zsplit-dwarf=single` -> `-Csplit-debuginfo=packed` * `-Zsplit-dwarf=split` -> `-Csplit-debuginfo=unpacked` Note that `-Csplit-debuginfo` still requires `-Zunstable-options` for non-macOS platforms since split-dwarf support was *just* implemented in rustc. There's some more rationale listed on #79361, but the main gist of the motivation for this commit is that `dsymutil` can take quite a long time to execute in debug builds and provides little benefit. This means that incremental compile times appear that much worse on macOS because the compiler is constantly running `dsymutil` over every single binary it produces during `cargo build` (even build scripts!). Ideally rustc would switch to not running `dsymutil` by default, but that's a problem left to get tackled another day. Closes #79361
2021-01-28rustc: Stabilize `-Zrun-dsymutil` as `-Csplit-debuginfo`Alex Crichton-48/+56
This commit adds a new stable codegen option to rustc, `-Csplit-debuginfo`. The old `-Zrun-dsymutil` flag is deleted and now subsumed by this stable flag. Additionally `-Zsplit-dwarf` is also subsumed by this flag but still requires `-Zunstable-options` to actually activate. The `-Csplit-debuginfo` flag takes one of three values: * `off` - This indicates that split-debuginfo from the final artifact is not desired. This is not supported on Windows and is the default on Unix platforms except macOS. On macOS this means that `dsymutil` is not executed. * `packed` - This means that debuginfo is desired in one location separate from the main executable. This is the default on Windows (`*.pdb`) and macOS (`*.dSYM`). On other Unix platforms this subsumes `-Zsplit-dwarf=single` and produces a `*.dwp` file. * `unpacked` - This means that debuginfo will be roughly equivalent to object files, meaning that it's throughout the build directory rather than in one location (often the fastest for local development). This is not the default on any platform and is not supported on Windows. Each target can indicate its own default preference for how debuginfo is handled. Almost all platforms default to `off` except for Windows and macOS which default to `packed` for historical reasons. Some equivalencies for previous unstable flags with the new flags are: * `-Zrun-dsymutil=yes` -> `-Csplit-debuginfo=packed` * `-Zrun-dsymutil=no` -> `-Csplit-debuginfo=unpacked` * `-Zsplit-dwarf=single` -> `-Csplit-debuginfo=packed` * `-Zsplit-dwarf=split` -> `-Csplit-debuginfo=unpacked` Note that `-Csplit-debuginfo` still requires `-Zunstable-options` for non-macOS platforms since split-dwarf support was *just* implemented in rustc. There's some more rationale listed on #79361, but the main gist of the motivation for this commit is that `dsymutil` can take quite a long time to execute in debug builds and provides little benefit. This means that incremental compile times appear that much worse on macOS because the compiler is constantly running `dsymutil` over every single binary it produces during `cargo build` (even build scripts!). Ideally rustc would switch to not running `dsymutil` by default, but that's a problem left to get tackled another day. Closes #79361
2021-01-28Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakisYuki Okushi-12/+8
Refractor a few more types to `rustc_type_ir` In the continuation of #79169, ~~blocked on that PR~~. This PR: - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance` - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler. ~~I will split up that commit to make this easier to review and to have a better commit history.~~ EDIT: done, I split the PR in commits of 200-ish lines each r? `````@nikomatsakis````` cc `````@jackh726`````
2021-01-27Rollup merge of #81369 - tgnottingham:codegen-to-llvm-ir-wall-time, r=lcnrYuki Okushi-17/+14
rustc_codegen_ssa: use wall time for codegen_to_LLVM_IR time-passes entry Use elapsed wall time spent on codegen_to_LLVM_IR for all CGUs as a whole, rather than the sum for each CGU (the distinction matters for parallel builds, where some CGUs are processed in parallel).
2021-01-24rustc_codegen_ssa: use wall time for codegen_to_LLVM_IR time-passes entryTyson Nottingham-17/+14
Use elapsed wall time spent on codegen_to_LLVM_IR for all CGUs as a whole, rather than the sum for each CGU (the distinction matters for parallel builds, where some CGUs are processed in parallel).
2021-01-24Rollup merge of #81297 - ↵Jonas Schievink-3/+2
bjorn3:no_extern_backend_optimization_level_query_provider, r=cjgillot Don't provide backend_optimization_level query for extern crates Fixes #71291
2021-01-24Rollup merge of #80933 - rcvalle:fix-sysroot-option, r=nagisaJonas Schievink-7/+21
Fix sysroot option not being honored across rustc Change link_sanitizer_runtime() to check if the sanitizer library exists in the specified/session sysroot, and if it doesn't exist, use the default sysroot. (See #79253.)
2021-01-24clean up some const error reporting around promotedsRalf Jung-6/+1
2021-01-23Rollup merge of #81072 - RalfJung:place-ref-ty, r=oli-obkJonas Schievink-2/+2
PlaceRef::ty: use method call syntax
2021-01-23Don't provide backend_optimization_level query for extern cratesbjorn3-3/+2
2021-01-20Auto merge of #81118 - ojeda:metadata-obj, r=nagisabors-4/+2
Skip linking if it is not required This allows to use `--emit=metadata,obj` and other metadata + non-link combinations. Fixes #81117.
2021-01-19Fix sysroot option not being honored across rustcRamon de C Valle-7/+21
Change link_sanitizer_runtime() to check if the sanitizer library exists in the specified/session sysroot, and if it doesn't exist, use the default sysroot.
2021-01-18Use ty::{IntTy,UintTy,FloatTy} in rustcLeSeulArtichaut-12/+8
2021-01-17Skip linking if it is not requiredMiguel Ojeda-4/+2
This allows to use `--emit=metadata,obj` and other metadata + non-link combinations. Fixes #81117. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-17Rollup merge of #80983 - bjorn3:no_dup_is_dllimport_foreign_item, r=nagisaMara Bos-27/+0
Remove is_dllimport_foreign_item definition from cg_ssa It overwrites the definition from rustc_metadata. cc https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/query.20provided.20twice/near/218927806 Marked as draft to test if this breaks anything.
2021-01-16PlaceRef::ty: use method call syntaxRalf Jung-2/+2
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-1/+1
2021-01-13Remove is_dllimport_foreign_item def from cg_ssabjorn3-27/+0
It overwrites the definition from rustc_metadata