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
@@ -14,6 +14,10 @@ fn F(T:! type, U:! type) {
// CHECK:STDOUT: --- fail_type_param_mismatch.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = ptr_type T [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.F = %F} [template]
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
@@ -22,7 +26,7 @@ fn F(T:! type, U:! type) {
// CHECK:STDOUT: fn @F(%T: type, %U: type) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %T.ref: type = name_ref T, %T [symbolic = %T]
// CHECK:STDOUT: %.loc8: type = ptr_type T [template]
// CHECK:STDOUT: %.loc8: type = ptr_type T [template = constants.%.1]
// CHECK:STDOUT: %p.var: ref T* = var p
// CHECK:STDOUT: %p: ref T* = bind_name p, %p.var
// CHECK:STDOUT: %U.ref: type = name_ref U, %U [symbolic = %U]
@@ -11,6 +11,10 @@ fn F(T:! type) {
// CHECK:STDOUT: --- type_param.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: type = ptr_type T [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.F = %F} [template]
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
@@ -19,7 +23,7 @@ fn F(T:! type) {
// CHECK:STDOUT: fn @F(%T: type) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %T.ref.loc8: type = name_ref T, %T [symbolic = %T]
// CHECK:STDOUT: %.loc8: type = ptr_type T [template]
// CHECK:STDOUT: %.loc8: type = ptr_type T [template = constants.%.1]
// CHECK:STDOUT: %p.var: ref T* = var p
// CHECK:STDOUT: %p: ref T* = bind_name p, %p.var
// CHECK:STDOUT: %T.ref.loc9: type = name_ref T, %T [symbolic = %T]