Unify instruction naming between SemIR and LLVM IR (#3898)

Factor out `SemIR::InstNamer` and also use it when lowering to LLVM IR.
Automatically name all instructions created with our `IRBuilder` based
on the name computed by the `InstNamer`, and likewise name basic blocks
using the label generated by the `InstNamer`.

Move some of the existing naming logic out from lower into `InstNamer`
so that it's also used in SemIR. In particular, we now name call
instructions after their callee, or after the builtin name for calls to
builtins.

Computing and adding these names isn't completely free. This instruction
naming is designed to be optional, so that we can turn it off for builds
where the LLVM IR will only be converted to assembly and won't be seen
by a human, but so far it's enabled unconditionally. We can tune that
later as needed.
This commit is contained in:
Richard Smith
2024-04-19 02:19:30 +00:00
committed by GitHub
parent 5964795f34
commit 3776c068de
225 changed files with 2835 additions and 2455 deletions
+3 -3
View File
@@ -78,9 +78,9 @@ fn G() -> i32 {
// CHECK:STDOUT: %.loc12_11.1: init [i32; 3] = converted %.loc12_20.1, %.loc12_20.12 [template = constants.%.8]
// CHECK:STDOUT: %.loc12_11.2: ref [i32; 3] = temporary %.loc12_20.2, %.loc12_11.1
// CHECK:STDOUT: %.loc12_11.3: [i32; 3] = bind_value %.loc12_11.2
// CHECK:STDOUT: %.loc12_11.4: init i32 = call %F.ref(%.loc12_11.3, %.loc12_23)
// CHECK:STDOUT: %.loc12_25.1: i32 = value_of_initializer %.loc12_11.4
// CHECK:STDOUT: %.loc12_25.2: i32 = converted %.loc12_11.4, %.loc12_25.1
// CHECK:STDOUT: %F.call: init i32 = call %F.ref(%.loc12_11.3, %.loc12_23)
// CHECK:STDOUT: %.loc12_25.1: i32 = value_of_initializer %F.call
// CHECK:STDOUT: %.loc12_25.2: i32 = converted %F.call, %.loc12_25.1
// CHECK:STDOUT: return %.loc12_25.2
// CHECK:STDOUT: }
// CHECK:STDOUT: