@@ -389,10 +389,6 @@ class IRGenSILFunction :
389
389
// / Keeps track of the mapping of source variables to -O0 shadow copy allocas.
390
390
llvm::SmallDenseMap<StackSlotKey, Address, 8 > ShadowStackSlots;
391
391
llvm::SmallDenseMap<Decl *, SmallString<4 >, 8 > AnonymousVariables;
392
- // / To avoid inserting elements into ValueDomPoints twice.
393
- llvm::SmallDenseSet<llvm::Instruction *, 8 > ValueVariables;
394
- // / Holds the DominancePoint of values that are storage for a source variable.
395
- SmallVector<std::pair<llvm::Instruction *, DominancePoint>, 8 > ValueDomPoints;
396
392
unsigned NumAnonVars = 0 ;
397
393
398
394
// / Accumulative amount of allocated bytes on the stack. Used to limit the
@@ -661,78 +657,6 @@ class IRGenSILFunction :
661
657
return Name;
662
658
}
663
659
664
- // / Try to emit an inline assembly gadget which extends the lifetime of
665
- // / \p Var. Returns whether or not this was successful.
666
- bool emitLifetimeExtendingUse (llvm::Value *Var) {
667
- llvm::Type *ArgTys;
668
- auto *Ty = Var->getType ();
669
- // Vectors, Pointers and Floats are expected to fit into a register.
670
- if (Ty->isPointerTy () || Ty->isFloatingPointTy () || Ty->isVectorTy ())
671
- ArgTys = {Ty};
672
- else {
673
- // If this is not a scalar or vector type, we can't handle it.
674
- if (isa<llvm::CompositeType>(Ty))
675
- return false ;
676
- // The storage is guaranteed to be no larger than the register width.
677
- // Extend the storage so it would fit into a register.
678
- llvm::Type *IntTy;
679
- switch (IGM.getClangASTContext ().getTargetInfo ().getRegisterWidth ()) {
680
- case 64 :
681
- IntTy = IGM.Int64Ty ;
682
- break ;
683
- case 32 :
684
- IntTy = IGM.Int32Ty ;
685
- break ;
686
- default :
687
- llvm_unreachable (" unsupported register width" );
688
- }
689
- ArgTys = {IntTy};
690
- Var = Builder.CreateZExtOrBitCast (Var, IntTy);
691
- }
692
- // Emit an empty inline assembler expression depending on the register.
693
- auto *AsmFnTy = llvm::FunctionType::get (IGM.VoidTy , ArgTys, false );
694
- auto *InlineAsm = llvm::InlineAsm::get (AsmFnTy, " " , " r" , true );
695
- Builder.CreateAsmCall (InlineAsm, Var);
696
- return true ;
697
- }
698
-
699
- // / At -Onone, forcibly keep all LLVM values that are tracked by
700
- // / debug variables alive by inserting an empty inline assembler
701
- // / expression depending on the value in the blocks dominated by the
702
- // / value.
703
- void emitDebugVariableRangeExtension (const SILBasicBlock *CurBB) {
704
- if (IGM.IRGen .Opts .shouldOptimize ())
705
- return ;
706
- for (auto &Variable : ValueDomPoints) {
707
- llvm::Instruction *Var = Variable.first ;
708
- DominancePoint VarDominancePoint = Variable.second ;
709
- if (getActiveDominancePoint () == VarDominancePoint ||
710
- isActiveDominancePointDominatedBy (VarDominancePoint)) {
711
- bool ExtendedLifetime = emitLifetimeExtendingUse (Var);
712
- if (!ExtendedLifetime)
713
- continue ;
714
-
715
- // Propagate dbg.values for Var into the current basic block. Note
716
- // that this shouldn't be necessary. LiveDebugValues should be doing
717
- // this but can't in general because it currently only tracks register
718
- // locations.
719
- llvm::BasicBlock *BB = Var->getParent ();
720
- llvm::BasicBlock *CurBB = Builder.GetInsertBlock ();
721
- if (BB == CurBB)
722
- // The current basic block must be a successor of the dbg.value().
723
- continue ;
724
-
725
- llvm::SmallVector<llvm::DbgValueInst *, 4 > DbgValues;
726
- llvm::findDbgValues (DbgValues, Var);
727
- for (auto *DVI : DbgValues)
728
- if (DVI->getParent () == BB)
729
- IGM.DebugInfo ->getBuilder ().insertDbgValueIntrinsic (
730
- DVI->getValue (), DVI->getVariable (), DVI->getExpression (),
731
- DVI->getDebugLoc (), &*CurBB->getFirstInsertionPt ());
732
- }
733
- }
734
- }
735
-
736
660
// / To make it unambiguous whether a `var` binding has been initialized,
737
661
// / zero-initialize the shadow copy alloca. LLDB uses the first pointer-sized
738
662
// / field to recognize to detect uninitizialized variables. This can be
@@ -757,16 +681,17 @@ class IRGenSILFunction :
757
681
758
682
// / Account for bugs in LLVM.
759
683
// /
684
+ // / - When a variable is spilled into a stack slot, LiveDebugValues fails to
685
+ // / recognize a restore of that slot for a different variable.
686
+ // /
760
687
// / - The LLVM type legalizer currently doesn't update debug
761
688
// / intrinsics when a large value is split up into smaller
762
689
// / pieces. Note that this heuristic as a bit too conservative
763
690
// / on 32-bit targets as it will also fire for doubles.
764
691
// /
765
692
// / - CodeGen Prepare may drop dbg.values pointing to PHI instruction.
766
693
bool needsShadowCopy (llvm::Value *Storage) {
767
- return (IGM.DataLayout .getTypeSizeInBits (Storage->getType ()) >
768
- IGM.getClangASTContext ().getTargetInfo ().getRegisterWidth ()) ||
769
- isa<llvm::PHINode>(Storage);
694
+ return !isa<llvm::Constant>(Storage);
770
695
}
771
696
772
697
// / Unconditionally emit a stack shadow copy of an \c llvm::Value.
@@ -800,27 +725,10 @@ class IRGenSILFunction :
800
725
if (IGM.IRGen .Opts .DisableDebuggerShadowCopies ||
801
726
IGM.IRGen .Opts .shouldOptimize () || IsAnonymous ||
802
727
isa<llvm::AllocaInst>(Storage) || isa<llvm::UndefValue>(Storage) ||
803
- Storage->getType () == IGM.RefCountedPtrTy )
728
+ Storage->getType () == IGM.RefCountedPtrTy || ! needsShadowCopy (Storage) )
804
729
return Storage;
805
730
806
- // Always emit shadow copies for function arguments.
807
- if (VarInfo.ArgNo == 0 )
808
- // Otherwise only if debug value range extension is not feasible.
809
- if (!needsShadowCopy (Storage)) {
810
- // Mark for debug value range extension unless this is a constant, or
811
- // unless it's not possible to emit lifetime-extending uses for this.
812
- if (auto *Value = dyn_cast<llvm::Instruction>(Storage)) {
813
- // Emit a use at the start of the storage lifetime to force early
814
- // materialization. This makes variables available for inspection as
815
- // soon as they are defined.
816
- bool ExtendedLifetime = emitLifetimeExtendingUse (Value);
817
- if (ExtendedLifetime)
818
- if (ValueVariables.insert (Value).second )
819
- ValueDomPoints.push_back ({Value, getActiveDominancePoint ()});
820
- }
821
-
822
- return Storage;
823
- }
731
+ // Emit a shadow copy.
824
732
return emitShadowCopy (Storage, Scope, VarInfo, Align);
825
733
}
826
734
@@ -1900,9 +1808,6 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
1900
1808
IGM.DebugInfo ->setCurrentLoc (
1901
1809
Builder, DS, RegularLocation::getAutoGeneratedLocation ());
1902
1810
}
1903
-
1904
- if (isa<TermInst>(&I))
1905
- emitDebugVariableRangeExtension (BB);
1906
1811
}
1907
1812
visit (&I);
1908
1813
}
0 commit comments