Avoid recursion in InstNamer::CollectNamesInBlock (#4706)

Use a deque to maintain the set of instructions to be walked over. so
that the loop can append more instructions (with their related scope)
during iteration without requiring recursion.

---------

Co-authored-by: jonmeow <jperkins@google.com>
This commit is contained in:
Dana Jansens
2024-12-20 16:12:06 +00:00
committed by GitHub
co-authored by jonmeow
parent aca862ceff
commit 6cb660f5ad
92 changed files with 974 additions and 955 deletions
+12 -12
View File
@@ -321,11 +321,11 @@ import library "extern_api";
// CHECK:STDOUT: %i32.loc6_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template = constants.%struct_type.c]
// CHECK:STDOUT: %c.param: %tuple.type.2 = value_param runtime_param0
// CHECK:STDOUT: %.loc6_14.3: type = splice_block %.loc6_14.2 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %.loc6_14.1: type = splice_block %.loc6_14.3 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %int_32.loc6_10: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc6_10: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %.loc6_14.1: %tuple.type.1 = tuple_literal (%i32.loc6_10)
// CHECK:STDOUT: %.loc6_14.2: type = converted %.loc6_14.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: %.loc6_14.2: %tuple.type.1 = tuple_literal (%i32.loc6_10)
// CHECK:STDOUT: %.loc6_14.3: type = converted %.loc6_14.2, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.2 = bind_name c, %c.param
// CHECK:STDOUT: %return.param: ref %struct_type.c = out_param runtime_param1
@@ -414,11 +414,11 @@ import library "extern_api";
// CHECK:STDOUT: %i32.loc6_60: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template = constants.%struct_type.c]
// CHECK:STDOUT: %c.param: %tuple.type.2 = value_param runtime_param0
// CHECK:STDOUT: %.loc6_49.3: type = splice_block %.loc6_49.2 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %.loc6_49.1: type = splice_block %.loc6_49.3 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %int_32.loc6_45: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc6_45: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %.loc6_49.1: %tuple.type.1 = tuple_literal (%i32.loc6_45)
// CHECK:STDOUT: %.loc6_49.2: type = converted %.loc6_49.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: %.loc6_49.2: %tuple.type.1 = tuple_literal (%i32.loc6_45)
// CHECK:STDOUT: %.loc6_49.3: type = converted %.loc6_49.2, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.2 = bind_name c, %c.param
// CHECK:STDOUT: %return.param: ref %struct_type.c = out_param runtime_param1
@@ -643,11 +643,11 @@ import library "extern_api";
// CHECK:STDOUT: %i32.loc32_32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template = constants.%struct_type.c]
// CHECK:STDOUT: %c.param: %tuple.type.2 = value_param runtime_param0
// CHECK:STDOUT: %.loc32_21.3: type = splice_block %.loc32_21.2 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %.loc32_21.1: type = splice_block %.loc32_21.3 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %int_32.loc32_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc32_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %.loc32_21.1: %tuple.type.1 = tuple_literal (%i32.loc32_17)
// CHECK:STDOUT: %.loc32_21.2: type = converted %.loc32_21.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: %.loc32_21.2: %tuple.type.1 = tuple_literal (%i32.loc32_17)
// CHECK:STDOUT: %.loc32_21.3: type = converted %.loc32_21.2, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.2 = bind_name c, %c.param
// CHECK:STDOUT: %return.param: ref %struct_type.c = out_param runtime_param1
@@ -793,11 +793,11 @@ import library "extern_api";
// CHECK:STDOUT: %i32.loc8_32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [template = constants.%struct_type.c]
// CHECK:STDOUT: %c.param: %tuple.type.2 = value_param runtime_param0
// CHECK:STDOUT: %.loc8_21.3: type = splice_block %.loc8_21.2 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %.loc8_21.1: type = splice_block %.loc8_21.3 [template = constants.%tuple.type.2] {
// CHECK:STDOUT: %int_32.loc8_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32.loc8_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %.loc8_21.1: %tuple.type.1 = tuple_literal (%i32.loc8_17)
// CHECK:STDOUT: %.loc8_21.2: type = converted %.loc8_21.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: %.loc8_21.2: %tuple.type.1 = tuple_literal (%i32.loc8_17)
// CHECK:STDOUT: %.loc8_21.3: type = converted %.loc8_21.2, constants.%tuple.type.2 [template = constants.%tuple.type.2]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.2 = bind_name c, %c.param
// CHECK:STDOUT: %return.param: ref %struct_type.c = out_param runtime_param1
@@ -90,9 +90,9 @@ fn E() {}
// CHECK:STDOUT: %x.param_patt: %empty_tuple.type = value_param_pattern %x.patt, runtime_param0
// CHECK:STDOUT: } {
// CHECK:STDOUT: %x.param.loc21: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc21_10.3: type = splice_block %.loc21_10.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc21_10.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc21_10.2: type = converted %.loc21_10.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc21_10.1: type = splice_block %.loc21_10.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc21_10.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc21_10.3: type = converted %.loc21_10.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %x.loc21: %empty_tuple.type = bind_name x, %x.param.loc21
// CHECK:STDOUT: }
@@ -101,9 +101,9 @@ fn E() {}
// CHECK:STDOUT: %x.param_patt: %empty_tuple.type = value_param_pattern %x.patt, runtime_param0
// CHECK:STDOUT: } {
// CHECK:STDOUT: %x.param.loc29: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc29_10.3: type = splice_block %.loc29_10.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc29_10.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc29_10.2: type = converted %.loc29_10.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc29_10.1: type = splice_block %.loc29_10.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc29_10.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc29_10.3: type = converted %.loc29_10.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %x.loc29: %empty_tuple.type = bind_name x, %x.param.loc29
// CHECK:STDOUT: }
@@ -113,9 +113,9 @@ fn E() {}
// CHECK:STDOUT: %x.param_patt: %empty_tuple.type = value_param_pattern %x.patt, runtime_param0
// CHECK:STDOUT: } {
// CHECK:STDOUT: %x.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc39_10.3: type = splice_block %.loc39_10.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc39_10.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc39_10.2: type = converted %.loc39_10.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc39_10.1: type = splice_block %.loc39_10.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc39_10.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc39_10.3: type = converted %.loc39_10.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %x: %empty_tuple.type = bind_name x, %x.param
// CHECK:STDOUT: }