@@ -389,10 +389,6 @@ class IRGenSILFunction :
389389 // / Keeps track of the mapping of source variables to -O0 shadow copy allocas.
390390 llvm::SmallDenseMap<StackSlotKey, Address, 8 > ShadowStackSlots;
391391 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;
396392 unsigned NumAnonVars = 0 ;
397393
398394 // / Accumulative amount of allocated bytes on the stack. Used to limit the
@@ -661,78 +657,6 @@ class IRGenSILFunction :
661657 return Name;
662658 }
663659
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-
736660 // / To make it unambiguous whether a `var` binding has been initialized,
737661 // / zero-initialize the shadow copy alloca. LLDB uses the first pointer-sized
738662 // / field to recognize to detect uninitizialized variables. This can be
@@ -757,16 +681,17 @@ class IRGenSILFunction :
757681
758682 // / Account for bugs in LLVM.
759683 // /
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+ // /
760687 // / - The LLVM type legalizer currently doesn't update debug
761688 // / intrinsics when a large value is split up into smaller
762689 // / pieces. Note that this heuristic as a bit too conservative
763690 // / on 32-bit targets as it will also fire for doubles.
764691 // /
765692 // / - CodeGen Prepare may drop dbg.values pointing to PHI instruction.
766693 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);
770695 }
771696
772697 // / Unconditionally emit a stack shadow copy of an \c llvm::Value.
@@ -800,27 +725,10 @@ class IRGenSILFunction :
800725 if (IGM.IRGen .Opts .DisableDebuggerShadowCopies ||
801726 IGM.IRGen .Opts .shouldOptimize () || IsAnonymous ||
802727 isa<llvm::AllocaInst>(Storage) || isa<llvm::UndefValue>(Storage) ||
803- Storage->getType () == IGM.RefCountedPtrTy )
728+ Storage->getType () == IGM.RefCountedPtrTy || ! needsShadowCopy (Storage) )
804729 return Storage;
805730
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.
824732 return emitShadowCopy (Storage, Scope, VarInfo, Align);
825733 }
826734
@@ -1900,9 +1808,6 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
19001808 IGM.DebugInfo ->setCurrentLoc (
19011809 Builder, DS, RegularLocation::getAutoGeneratedLocation ());
19021810 }
1903-
1904- if (isa<TermInst>(&I))
1905- emitDebugVariableRangeExtension (BB);
19061811 }
19071812 visit (&I);
19081813 }
0 commit comments