Skip to content

Commit 0e37035

Browse files
committed
Refactor and clean up IRGenSIL::emitShadowCopy. (NFC)
1 parent b4e10da commit 0e37035

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,20 @@ class IRGenSILFunction :
617617
}
618618
}
619619

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+
620634
/// At -Onone, emit a shadow copy of an Address in an alloca, so the
621635
/// register allocator doesn't elide the dbg.value intrinsic when
622636
/// register pressure is high. There is a trade-off to this: With
@@ -626,28 +640,22 @@ class IRGenSILFunction :
626640
StringRef Name, unsigned ArgNo,
627641
Alignment Align = Alignment(0)) {
628642
auto Ty = Storage->getType();
643+
// Never emit shadow copies when optimizing, or if already on the stack.
629644
if (IGM.IRGen.Opts.Optimize ||
630645
isa<llvm::AllocaInst>(Storage) ||
631646
isa<llvm::UndefValue>(Storage) ||
632647
Ty == IGM.RefCountedPtrTy) // No debug info is emitted for refcounts.
633648
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.
646655
if (auto *Value = dyn_cast<llvm::Instruction>(Storage))
647656
ValueVariables.push_back({getActiveDominancePoint(), Value});
648657
return Storage;
649658
}
650-
}
651659

652660
if (Align.isZero())
653661
Align = IGM.getPointerAlignment();

0 commit comments

Comments
 (0)