forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64149 - eddyb:llvm-var-names, r=rkruppe
rustc_codegen_llvm: give names to non-alloca variable values. These names only matter when looking at LLVM IR, but they can help. When one value is used for multiple variables, I decided to combine the names. I chose `,` as a separator but maybe `=` or ` ` (space) are more appropriate. (LLVM names can contain any characters - if necessary they end up having quotes) As an example, this function: ```rust #[no_mangle] pub fn test(a: u32, b: u32) -> u32 { let c = a + b; let d = c; let e = d * a; e } ``` Used to produce this LLVM IR: ```llvm define i32 @test(i32 %a, i32 %b) unnamed_addr #0 { start: %0 = add i32 %a, %b %1 = mul i32 %0, %a ret i32 %1 } ``` But after this PR you get this: ```llvm define i32 @test(i32 %a, i32 %b) unnamed_addr #0 { start: %"c,d" = add i32 %a, %b %e = mul i32 %"c,d", %a ret i32 %e } ``` cc @nagisa @rkruppe
- Loading branch information
Showing
6 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// compile-flags: -O -C no-prepopulate-passes | ||
|
||
#![crate_type = "lib"] | ||
|
||
// CHECK-LABEL: define i32 @test(i32 %a, i32 %b) | ||
#[no_mangle] | ||
pub fn test(a: u32, b: u32) -> u32 { | ||
let c = a + b; | ||
// CHECK: %c = add i32 %a, %b | ||
let d = c; | ||
let e = d * a; | ||
// CHECK-NEXT: %e = mul i32 %c, %a | ||
e | ||
// CHECK-NEXT: ret i32 %e | ||
} |