mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:34:45 +01:00
Add a separate store for computed constant values. (#3362)
This moves the instructions generated for type values out of the block in which they happen to first be referenced, and into shared storage.
This commit is contained in:
@@ -9,6 +9,10 @@ fn F() -> i32 {
|
||||
return *&*&n;
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.loc9: type = ptr_type i32
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "address_of_deref.carbon" {
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F
|
||||
// CHECK:STDOUT: }
|
||||
@@ -20,9 +24,8 @@ fn F() -> i32 {
|
||||
// CHECK:STDOUT: %.loc8: i32 = int_literal 0
|
||||
// CHECK:STDOUT: assign %n.var, %.loc8
|
||||
// CHECK:STDOUT: %n.ref: ref i32 = name_reference "n", %n
|
||||
// CHECK:STDOUT: %.loc9_13.1: type = ptr_type i32
|
||||
// CHECK:STDOUT: %.loc9_13.2: i32* = address_of %n.ref
|
||||
// CHECK:STDOUT: %.loc9_12: ref i32 = dereference %.loc9_13.2
|
||||
// CHECK:STDOUT: %.loc9_13: i32* = address_of %n.ref
|
||||
// CHECK:STDOUT: %.loc9_12: ref i32 = dereference %.loc9_13
|
||||
// CHECK:STDOUT: %.loc9_11: i32* = address_of %.loc9_12
|
||||
// CHECK:STDOUT: %.loc9_10.1: ref i32 = dereference %.loc9_11
|
||||
// CHECK:STDOUT: %.loc9_10.2: i32 = bind_value %.loc9_10.1
|
||||
|
||||
@@ -16,14 +16,20 @@ fn F() {
|
||||
var t1: i32* = &t[1];
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.loc8: type = ptr_type {.a: i32, .b: i32}
|
||||
// CHECK:STDOUT: %.loc14_19.1: type = tuple_type (type, type)
|
||||
// CHECK:STDOUT: %.loc14_19.2: type = tuple_type (i32, i32)
|
||||
// CHECK:STDOUT: %.loc14_19.3: type = ptr_type (i32, i32)
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "address_of_lvalue.carbon" {
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %.loc8_27.1: type = struct_type {.a: i32, .b: i32}
|
||||
// CHECK:STDOUT: %.loc8_27.2: type = ptr_type {.a: i32, .b: i32}
|
||||
// CHECK:STDOUT: %.loc8_27: type = struct_type {.a: i32, .b: i32}
|
||||
// CHECK:STDOUT: %s.var: ref {.a: i32, .b: i32} = var "s"
|
||||
// CHECK:STDOUT: %s: ref {.a: i32, .b: i32} = bind_name "s", %s.var
|
||||
// CHECK:STDOUT: %.loc8_37: i32 = int_literal 1
|
||||
@@ -56,10 +62,7 @@ fn F() {
|
||||
// CHECK:STDOUT: %.loc12_19: ref i32 = struct_access %s.ref.loc12, member1
|
||||
// CHECK:STDOUT: %.loc12_17: i32* = address_of %.loc12_19
|
||||
// CHECK:STDOUT: assign %r.var, %.loc12_17
|
||||
// CHECK:STDOUT: %.loc14_19.1: type = tuple_type (type, type)
|
||||
// CHECK:STDOUT: %.loc14_19.2: (type, type) = tuple_literal (i32, i32)
|
||||
// CHECK:STDOUT: %.loc14_19.3: type = tuple_type (i32, i32)
|
||||
// CHECK:STDOUT: %.loc14_19.4: type = ptr_type (i32, i32)
|
||||
// CHECK:STDOUT: %.loc14_19: (type, type) = tuple_literal (i32, i32)
|
||||
// CHECK:STDOUT: %t.var: ref (i32, i32) = var "t"
|
||||
// CHECK:STDOUT: %t: ref (i32, i32) = bind_name "t", %t.var
|
||||
// CHECK:STDOUT: %.loc14_24: i32 = int_literal 1
|
||||
|
||||
@@ -18,6 +18,11 @@ fn Test() {
|
||||
&(&undeclared);
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.loc11: type = ptr_type <error>
|
||||
// CHECK:STDOUT: %.loc18: type = ptr_type <error>*
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "fail_address_of_error.carbon" {
|
||||
// CHECK:STDOUT: %Test: <function> = fn_decl @Test
|
||||
// CHECK:STDOUT: }
|
||||
@@ -25,11 +30,9 @@ fn Test() {
|
||||
// CHECK:STDOUT: fn @Test() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %undeclared.ref.loc11: <error> = name_reference "undeclared", <error>
|
||||
// CHECK:STDOUT: %.loc11_3.1: type = ptr_type <error>
|
||||
// CHECK:STDOUT: %.loc11_3.2: <error>* = address_of %undeclared.ref.loc11
|
||||
// CHECK:STDOUT: %.loc11: <error>* = address_of %undeclared.ref.loc11
|
||||
// CHECK:STDOUT: %undeclared.ref.loc18: <error> = name_reference "undeclared", <error>
|
||||
// CHECK:STDOUT: %.loc18_5: <error>* = address_of %undeclared.ref.loc18
|
||||
// CHECK:STDOUT: %.loc18_3.1: type = ptr_type <error>*
|
||||
// CHECK:STDOUT: %.loc18_3.2: <error>** = address_of %.loc18_5
|
||||
// CHECK:STDOUT: %.loc18_3: <error>** = address_of %.loc18_5
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
+18
-15
@@ -82,6 +82,17 @@ fn AddressOfParameter(param: i32) {
|
||||
var param_addr: i32* = ¶m;
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.loc15: type = ptr_type i32
|
||||
// CHECK:STDOUT: %.loc19: type = ptr_type bool
|
||||
// CHECK:STDOUT: %.loc23: type = ptr_type f64
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: %.loc31_9: type = tuple_type (i32, i32)
|
||||
// CHECK:STDOUT: %.loc31_3: type = ptr_type (i32, i32)
|
||||
// CHECK:STDOUT: %.loc35: type = ptr_type {.a: i32}
|
||||
// CHECK:STDOUT: %.loc64: type = ptr_type type
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "fail_address_of_value.carbon" {
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G
|
||||
// CHECK:STDOUT: %H: <function> = fn_decl @H
|
||||
@@ -100,27 +111,20 @@ fn AddressOfParameter(param: i32) {
|
||||
// CHECK:STDOUT: fn @AddressOfLiteral() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %.loc15_4: i32 = int_literal 0
|
||||
// CHECK:STDOUT: %.loc15_3.1: type = ptr_type i32
|
||||
// CHECK:STDOUT: %.loc15_3.2: i32* = address_of %.loc15_4
|
||||
// CHECK:STDOUT: %.loc15_3: i32* = address_of %.loc15_4
|
||||
// CHECK:STDOUT: %.loc19_4: bool = bool_literal true
|
||||
// CHECK:STDOUT: %.loc19_3.1: type = ptr_type bool
|
||||
// CHECK:STDOUT: %.loc19_3.2: bool* = address_of %.loc19_4
|
||||
// CHECK:STDOUT: %.loc19_3: bool* = address_of %.loc19_4
|
||||
// CHECK:STDOUT: %.loc23_4: f64 = real_literal 10e-1
|
||||
// CHECK:STDOUT: %.loc23_3.1: type = ptr_type f64
|
||||
// CHECK:STDOUT: %.loc23_3.2: f64* = address_of %.loc23_4
|
||||
// CHECK:STDOUT: %.1: type = ptr_type String
|
||||
// CHECK:STDOUT: %.loc23_3: f64* = address_of %.loc23_4
|
||||
// CHECK:STDOUT: %.loc27_4: String = string_literal "Hello"
|
||||
// CHECK:STDOUT: %.loc27_3: String* = address_of %.loc27_4
|
||||
// CHECK:STDOUT: %.loc31_5: i32 = int_literal 1
|
||||
// CHECK:STDOUT: %.loc31_8: i32 = int_literal 2
|
||||
// CHECK:STDOUT: %.loc31_9.1: type = tuple_type (i32, i32)
|
||||
// CHECK:STDOUT: %.loc31_9.2: (i32, i32) = tuple_literal (%.loc31_5, %.loc31_8)
|
||||
// CHECK:STDOUT: %.loc31_3.1: type = ptr_type (i32, i32)
|
||||
// CHECK:STDOUT: %.loc31_3.2: (i32, i32)* = address_of %.loc31_9.2
|
||||
// CHECK:STDOUT: %.loc31_9: (i32, i32) = tuple_literal (%.loc31_5, %.loc31_8)
|
||||
// CHECK:STDOUT: %.loc31_3: (i32, i32)* = address_of %.loc31_9
|
||||
// CHECK:STDOUT: %.loc35_10: i32 = int_literal 5
|
||||
// CHECK:STDOUT: %.loc35_11: {.a: i32} = struct_literal (%.loc35_10)
|
||||
// CHECK:STDOUT: %.loc35_3.1: type = ptr_type {.a: i32}
|
||||
// CHECK:STDOUT: %.loc35_3.2: {.a: i32}* = address_of %.loc35_11
|
||||
// CHECK:STDOUT: %.loc35_3: {.a: i32}* = address_of %.loc35_11
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -152,8 +156,7 @@ fn AddressOfParameter(param: i32) {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @AddressOfType() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %.loc64_3.1: type = ptr_type type
|
||||
// CHECK:STDOUT: %.loc64_3.2: type* = address_of i32
|
||||
// CHECK:STDOUT: %.loc64: type* = address_of i32
|
||||
// CHECK:STDOUT: %.loc68_5: type = const_type i32
|
||||
// CHECK:STDOUT: %.loc68_14: type = ptr_type const i32
|
||||
// CHECK:STDOUT: %.loc68_3: type* = address_of %.loc68_14
|
||||
|
||||
@@ -19,6 +19,11 @@ fn Deref(n: i32) {
|
||||
*{};
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.loc15: type = tuple_type ()
|
||||
// CHECK:STDOUT: %.loc19: type = struct_type {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "fail_dereference_not_pointer.carbon" {
|
||||
// CHECK:STDOUT: %Deref: <function> = fn_decl @Deref
|
||||
// CHECK:STDOUT: }
|
||||
@@ -27,13 +32,11 @@ fn Deref(n: i32) {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %n.ref: i32 = name_reference "n", %n
|
||||
// CHECK:STDOUT: %.loc11: ref <error> = dereference %n.ref
|
||||
// CHECK:STDOUT: %.loc15_5.1: type = tuple_type ()
|
||||
// CHECK:STDOUT: %.loc15_5.2: () = tuple_literal ()
|
||||
// CHECK:STDOUT: %.loc15_5.3: () = tuple_value %.loc15_5.2, ()
|
||||
// CHECK:STDOUT: %.loc15_3: ref <error> = dereference %.loc15_5.3
|
||||
// CHECK:STDOUT: %.loc19_5.1: type = struct_type {}
|
||||
// CHECK:STDOUT: %.loc19_5.2: {} = struct_literal ()
|
||||
// CHECK:STDOUT: %.loc19_5.3: {} = struct_value %.loc19_5.2, ()
|
||||
// CHECK:STDOUT: %.loc19_3: ref <error> = dereference %.loc19_5.3
|
||||
// CHECK:STDOUT: %.loc15_5.1: () = tuple_literal ()
|
||||
// CHECK:STDOUT: %.loc15_5.2: () = tuple_value %.loc15_5.1, ()
|
||||
// CHECK:STDOUT: %.loc15_3: ref <error> = dereference %.loc15_5.2
|
||||
// CHECK:STDOUT: %.loc19_5.1: {} = struct_literal ()
|
||||
// CHECK:STDOUT: %.loc19_5.2: {} = struct_value %.loc19_5.1, ()
|
||||
// CHECK:STDOUT: %.loc19_3: ref <error> = dereference %.loc19_5.2
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
@@ -11,6 +11,10 @@ fn ConstMismatch(p: const {}*) -> const ({}*) {
|
||||
return p;
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.loc7: type = struct_type {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file "fail_type_mismatch.carbon" {
|
||||
// CHECK:STDOUT: %ConstMismatch: <function> = fn_decl @ConstMismatch
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
Reference in New Issue
Block a user