@@ -617,6 +617,20 @@ class IRGenSILFunction :
617
617
}
618
618
}
619
619
620
+ // / Account for bugs in LLVM.
621
+ // /
622
+ // / - The LLVM type legalizer currently doesn't update debug
623
+ // / intrinsics when a large value is split up into smaller
624
+ // / pieces. Note that this heuristic as a bit too conservative
625
+ // / on 32-bit targets as it will also fire for doubles.
626
+ // /
627
+ // / - CodeGen Prepare may drop dbg.values pointing to PHI instruction.
628
+ bool needsShadowCopy (llvm::Value *Storage) {
629
+ return (IGM.DataLayout .getTypeSizeInBits (Storage->getType ()) >
630
+ IGM.getClangASTContext ().getTargetInfo ().getRegisterWidth ()) ||
631
+ isa<llvm::PHINode>(Storage);
632
+ }
633
+
620
634
// / At -Onone, emit a shadow copy of an Address in an alloca, so the
621
635
// / register allocator doesn't elide the dbg.value intrinsic when
622
636
// / register pressure is high. There is a trade-off to this: With
@@ -626,28 +640,22 @@ class IRGenSILFunction :
626
640
StringRef Name, unsigned ArgNo,
627
641
Alignment Align = Alignment(0 )) {
628
642
auto Ty = Storage->getType ();
643
+ // Never emit shadow copies when optimizing, or if already on the stack.
629
644
if (IGM.IRGen .Opts .Optimize ||
630
645
isa<llvm::AllocaInst>(Storage) ||
631
646
isa<llvm::UndefValue>(Storage) ||
632
647
Ty == IGM.RefCountedPtrTy ) // No debug info is emitted for refcounts.
633
648
return Storage;
634
- if (ArgNo == 0 ) {
635
- // Account for bugs in LLVM.
636
- //
637
- // - The LLVM type legalizer currently doesn't update debug
638
- // intrinsics when a large value is split up into smaller
639
- // pieces. Note that this heuristic as a bit too conservative
640
- // on 32-bit targets as it will also fire for doubles.
641
- //
642
- // - CodeGen Prepare may drop dbg.values pointing to PHI instruction.
643
- if (IGM.DataLayout .getTypeSizeInBits (Storage->getType ()) <=
644
- IGM.getClangASTContext ().getTargetInfo ().getRegisterWidth () &&
645
- !isa<llvm::PHINode>(Storage)) {
649
+
650
+ // Always emit shadow copies for function arguments.
651
+ if (ArgNo == 0 )
652
+ // Otherwise only if debug value range extension is not feasible.
653
+ if (!needsShadowCopy (Storage)) {
654
+ // Mark for debug value range extension unless this is a constant.
646
655
if (auto *Value = dyn_cast<llvm::Instruction>(Storage))
647
656
ValueVariables.push_back ({getActiveDominancePoint (), Value});
648
657
return Storage;
649
658
}
650
- }
651
659
652
660
if (Align.isZero ())
653
661
Align = IGM.getPointerAlignment ();
0 commit comments