Skip to content

Commit 5b9c206

Browse files
committed
Optimizer: remove don't use locationOfNextNonMetaInstruction for getting Builder locations from instructions
This does not work in some situations.
1 parent 63cb683 commit 5b9c206

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -489,22 +489,6 @@ private extension Instruction {
489489
}
490490
return nil
491491
}
492-
493-
/// Returns the next interesting location. As it is impossible to set a
494-
/// breakpoint on a meta instruction, those are skipped.
495-
/// However, we don't want to take a location with different inlining
496-
/// information than this instruction, so in that case, we will return the
497-
/// location of the meta instruction. If the meta instruction is the only
498-
/// instruction in the basic block, we also take its location.
499-
var locationOfNextNonMetaInstruction: Location {
500-
let location = self.location
501-
guard !location.isInlined,
502-
let nextLocation = nextNonMetaInstruction?.location,
503-
!nextLocation.isInlined else {
504-
return location
505-
}
506-
return nextLocation
507-
}
508492
}
509493

510494
extension Builder {
@@ -524,7 +508,7 @@ extension Builder {
524508
init(before insPnt: Instruction, _ context: some MutatingContext) {
525509
context.verifyIsTransforming(function: insPnt.parentFunction)
526510
self.init(insertAt: .before(insPnt),
527-
location: insPnt.locationOfNextNonMetaInstruction,
511+
location: insPnt.location,
528512
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
529513
}
530514

@@ -556,7 +540,7 @@ extension Builder {
556540
/// TODO: this is incorrect for terminator instructions. Instead use `Builder.insert(after:location:_:insertFunc)`
557541
/// from OptUtils.swift. Rename this to afterNonTerminator.
558542
init(after insPnt: Instruction, _ context: some MutatingContext) {
559-
self.init(after: insPnt, location: insPnt.locationOfNextNonMetaInstruction, context)
543+
self.init(after: insPnt, location: insPnt.location, context)
560544
}
561545

562546
/// Creates a builder which inserts at the end of `block`, using a custom `location`.
@@ -580,7 +564,7 @@ extension Builder {
580564
context.verifyIsTransforming(function: block.parentFunction)
581565
let firstInst = block.instructions.first!
582566
self.init(insertAt: .before(firstInst),
583-
location: firstInst.locationOfNextNonMetaInstruction,
567+
location: firstInst.location,
584568
context.notifyInstructionChanged, context._bridged.asNotificationHandler())
585569
}
586570

test/DebugInfo/simplify_checked_cast_br.sil

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class X : B {}
1313
// CHECK: %0 = alloc_ref
1414
// CHECK-NEXT: checked_cast_br X in %0 : $X
1515
// CHECK: bb2([[A:%.*]] : @owned $X):
16-
// CHECK-NEXT: [[U:%.*]] = upcast [[A]] : $X to $B, loc "takethis":1:1
17-
// CHECK-NEXT: [[E:%.*]] = init_existential_ref [[U]] {{.+}}, loc "takethis":1:1
18-
// CHECK-NEXT: debug_value [[E]] : $AnyObject, let, name "me", loc "ignore-this-meta-inst":1:1
16+
// CHECK-NEXT: [[U:%.*]] = upcast [[A]] : $X to $B, loc "dv":1:1
17+
// CHECK-NEXT: [[E:%.*]] = init_existential_ref [[U]] {{.+}}, loc "dv":1:1
18+
// CHECK-NEXT: debug_value [[E]] : $AnyObject, let, name "me", loc "dv":1:1
1919
// CHECK-NEXT: destroy_value [[E]] : $AnyObject, loc "takethis":1:1
2020
// CHECK: } // end sil function 'test_ossa'
2121
sil [ossa] @test_ossa : $@convention(thin) () -> @owned X {
@@ -30,7 +30,7 @@ bb1(%5 : @owned $X):
3030
return %5 : $X
3131

3232
bb2(%7 : @owned $AnyObject):
33-
debug_value %7 : $AnyObject, let, name "me", loc "ignore-this-meta-inst":1:1
33+
debug_value %7 : $AnyObject, let, name "me", loc "dv":1:1
3434
destroy_value %7: $AnyObject, loc "takethis":1:1
3535
unreachable
3636
}

0 commit comments

Comments
 (0)