@@ -759,44 +759,31 @@ class IRGenSILFunction :
759
759
Storage.getAlignment ());
760
760
}
761
761
762
- void emitShadowCopy (ArrayRef<llvm::Value *> vals , const SILDebugScope *Scope,
762
+ void emitShadowCopy (SILValue &SILVal , const SILDebugScope *Scope,
763
763
StringRef Name, unsigned ArgNo, bool IsAnonymous,
764
764
llvm::SmallVectorImpl<llvm::Value *> ©) {
765
+ Explosion e = getLoweredExplosion (SILVal);
766
+
765
767
// Only do this at -O0.
766
768
if (IGM.IRGen .Opts .shouldOptimize () || IsAnonymous) {
769
+ auto vals = e.claimAll ();
767
770
copy.append (vals.begin (), vals.end ());
768
771
return ;
769
772
}
770
773
771
774
// Single or empty values.
772
- if (vals.size () <= 1 ) {
775
+ if (e.size () <= 1 ) {
776
+ auto vals = e.claimAll ();
773
777
for (auto val : vals)
774
778
copy.push_back (emitShadowCopy (val, Scope, Name, ArgNo, IsAnonymous));
775
779
return ;
776
780
}
777
781
778
- // Create a single aggregate alloca for explosions.
779
- // TODO: why are we doing this instead of using the TypeInfo?
780
- llvm::StructType *aggregateType = [&] {
781
- SmallVector<llvm::Type *, 8 > eltTypes;
782
- for (auto val : vals)
783
- eltTypes.push_back (val->getType ());
784
- return llvm::StructType::get (IGM.LLVMContext , eltTypes);
785
- }();
786
-
787
- auto layout = IGM.DataLayout .getStructLayout (aggregateType);
788
- Alignment align (layout->getAlignment ());
789
-
790
- auto alloca = createAlloca (aggregateType, align, Name + " .debug" );
791
- ArtificialLocation AutoRestore (Scope, IGM.DebugInfo , Builder);
792
- size_t i = 0 ;
793
- for (auto val : vals) {
794
- auto addr = Builder.CreateStructGEP (alloca, i,
795
- Size (layout->getElementOffset (i)));
796
- Builder.CreateStore (val, addr);
797
- i++;
798
- }
799
- copy.push_back (alloca.getAddress ());
782
+ SILType Type = SILVal->getType ();
783
+ auto <I = cast<LoadableTypeInfo>(IGM.getTypeInfo (Type));
784
+ auto Alloca = LTI.allocateStack (*this , Type, " debug.copy" );
785
+ LTI.initialize (*this , e, Alloca.getAddress (), false /* isOutlined */ );
786
+ copy.push_back (Alloca.getAddressPointer ());
800
787
}
801
788
802
789
// / Determine whether a generic variable has been inlined.
@@ -3633,10 +3620,8 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
3633
3620
3634
3621
// Put the value into a stack slot at -Onone.
3635
3622
llvm::SmallVector<llvm::Value *, 8 > Copy;
3636
- Explosion e = getLoweredExplosion (SILVal);
3637
3623
unsigned ArgNo = i->getVarInfo ().ArgNo ;
3638
- emitShadowCopy (e.claimAll (), i->getDebugScope (), Name, ArgNo, IsAnonymous,
3639
- Copy);
3624
+ emitShadowCopy (SILVal, i->getDebugScope (), Name, ArgNo, IsAnonymous, Copy);
3640
3625
emitDebugVariableDeclaration (Copy, DbgTy, SILTy, i->getDebugScope (),
3641
3626
i->getDecl (), Name, ArgNo);
3642
3627
}
0 commit comments