Deduplicate and canonicalize all constants. (#3611)

Rather than producing multiple constants with the same value, fold all
instances of a given constant to the same constant instruction.

A future PR will use this to replace the current type canonicalization
system.
This commit is contained in:
Richard Smith
2024-01-18 21:42:19 +00:00
committed by GitHub
parent 62db3e9ad0
commit 29c294880d
142 changed files with 1603 additions and 1185 deletions
@@ -39,7 +39,8 @@ class C {
// CHECK:STDOUT: %.1: bool = bool_literal true [template]
// CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
// CHECK:STDOUT: %.4: bool = bool_literal true [template]
// CHECK:STDOUT: %C: type = class_type @C [template]
// CHECK:STDOUT: %.4: type = unbound_element_type C, <error> [template]
// CHECK:STDOUT: %.5: type = struct_type {.n: <error>} [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -47,14 +48,14 @@ class C {
// CHECK:STDOUT: %.loc17: i32 = block_arg <unexpected instblockref block5>
// CHECK:STDOUT: %x: i32 = bind_name x, %.loc17
// CHECK:STDOUT: %C.decl = class_decl @C, ()
// CHECK:STDOUT: %C: type = class_type @C [template]
// CHECK:STDOUT: %C: type = class_type @C [template = constants.%C]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: %.loc33: bool = bool_literal true [template = constants.%.4]
// CHECK:STDOUT: %.loc33: bool = bool_literal true [template = constants.%.1]
// CHECK:STDOUT: if %.loc33 br !if.expr.then else br !if.expr.else
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .n = <unexpected instref inst+25>
// CHECK:STDOUT: .n = <unexpected instref inst+27>
// CHECK:STDOUT: }
// CHECK:STDOUT:
+8 -7
View File
@@ -14,10 +14,11 @@ fn F(cond: bool) {
// CHECK:STDOUT: --- struct.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = ptr_type {.a: i32, .b: i32} [template]
// CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
// CHECK:STDOUT: %.4: type = tuple_type () [template]
// CHECK:STDOUT: %.1: type = struct_type {.a: i32, .b: i32} [template]
// CHECK:STDOUT: %.2: type = ptr_type {.a: i32, .b: i32} [template]
// CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.4: i32 = int_literal 2 [template]
// CHECK:STDOUT: %.5: type = tuple_type () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
@@ -30,11 +31,11 @@ fn F(cond: bool) {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F(%cond: bool) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc10_27: type = struct_type {.a: i32, .b: i32} [template]
// CHECK:STDOUT: %.loc10_27: type = struct_type {.a: i32, .b: i32} [template = constants.%.1]
// CHECK:STDOUT: %a.var: ref {.a: i32, .b: i32} = var a
// CHECK:STDOUT: %a: ref {.a: i32, .b: i32} = bind_name a, %a.var
// CHECK:STDOUT: %.loc10_37: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: %.loc10_45: i32 = int_literal 2 [template = constants.%.3]
// CHECK:STDOUT: %.loc10_37: i32 = int_literal 1 [template = constants.%.3]
// CHECK:STDOUT: %.loc10_45: i32 = int_literal 2 [template = constants.%.4]
// CHECK:STDOUT: %.loc10_46.1: {.a: i32, .b: i32} = struct_literal (%.loc10_37, %.loc10_45)
// CHECK:STDOUT: %.loc10_46.2: ref i32 = struct_access %a.var, element0
// CHECK:STDOUT: %.loc10_46.3: init i32 = initialize_from %.loc10_37 to %.loc10_46.2