@@ -534,7 +534,7 @@ class IRGenSILFunction :
534534 setLoweredValue (tokenResult, std::move (state));
535535 }
536536
537- LoweredValue &getUndefLoweredValue (SILType t) {
537+ LoweredValue &getUndefLoweredValue (SILType t, IRBuilder *b = nullptr ) {
538538 auto found = LoweredUndefs.find (t);
539539 if (found != LoweredUndefs.end ())
540540 return found->second ;
@@ -554,7 +554,11 @@ class IRGenSILFunction :
554554 for (auto &elt : schema) {
555555 assert (!elt.isAggregate ()
556556 && " non-scalar element in loadable type schema?!" );
557- e.add (llvm::UndefValue::get (elt.getScalarType ()));
557+ llvm::Value *undef = llvm::UndefValue::get (elt.getScalarType ());
558+ if (b) {
559+ undef = b->CreateFreeze (undef);
560+ }
561+ e.add (undef);
558562 }
559563 LoweredUndefs.insert ({t, LoweredValue (e)});
560564 break ;
@@ -568,9 +572,9 @@ class IRGenSILFunction :
568572
569573 // / Get the LoweredValue corresponding to the given SIL value, which must
570574 // / have been lowered.
571- LoweredValue &getLoweredValue (SILValue v) {
575+ LoweredValue &getLoweredValue (SILValue v, IRBuilder *b = nullptr ) {
572576 if (isa<SILUndef>(v))
573- return getUndefLoweredValue (v->getType ());
577+ return getUndefLoweredValue (v->getType (), b );
574578
575579 auto foundValue = LoweredValues.find (v);
576580 assert (foundValue != LoweredValues.end () &&
@@ -580,8 +584,8 @@ class IRGenSILFunction :
580584
581585 // / Get the Address of a SIL value of address type, which must have been
582586 // / lowered.
583- Address getLoweredAddress (SILValue v) {
584- return getLoweredValue (v).getAnyAddress ();
587+ Address getLoweredAddress (SILValue v, IRBuilder *b = nullptr ) {
588+ return getLoweredValue (v, b ).getAnyAddress ();
585589 }
586590
587591 StackAddress getLoweredStackAddress (SILValue v) {
@@ -602,8 +606,8 @@ class IRGenSILFunction :
602606 }
603607 // / Create an Explosion containing the unmanaged LLVM values lowered from a
604608 // / SIL value.
605- Explosion getLoweredExplosion (SILValue v) {
606- return getLoweredValue (v).getExplosion (*this , v->getType ());
609+ Explosion getLoweredExplosion (SILValue v, IRBuilder *b = nullptr ) {
610+ return getLoweredValue (v, b ).getExplosion (*this , v->getType ());
607611 }
608612
609613 // / Get the lowered value for the given value of optional type in a
@@ -4680,7 +4684,7 @@ static llvm::BasicBlock *emitBBMapForSwitchEnum(
46804684}
46814685
46824686void IRGenSILFunction::visitSwitchEnumInst (SwitchEnumInst *inst) {
4683- Explosion value = getLoweredExplosion (inst->getOperand ());
4687+ Explosion value = getLoweredExplosion (inst->getOperand (), &Builder );
46844688
46854689 // Map the SIL dest bbs to their LLVM bbs.
46864690 SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
@@ -4701,7 +4705,7 @@ void IRGenSILFunction::visitSwitchEnumInst(SwitchEnumInst *inst) {
47014705
47024706 Builder.emitBlock (waypointBB);
47034707
4704- Explosion inValue = getLoweredExplosion (inst->getOperand ());
4708+ Explosion inValue = getLoweredExplosion (inst->getOperand (), &Builder );
47054709 Explosion projected;
47064710 emitProjectLoadableEnum (*this , inst->getOperand ()->getType (),
47074711 inValue, casePair.first , projected);
@@ -4716,7 +4720,7 @@ void IRGenSILFunction::visitSwitchEnumInst(SwitchEnumInst *inst) {
47164720
47174721void
47184722IRGenSILFunction::visitSwitchEnumAddrInst (SwitchEnumAddrInst *inst) {
4719- Address value = getLoweredAddress (inst->getOperand ());
4723+ Address value = getLoweredAddress (inst->getOperand (), &Builder );
47204724
47214725 // Map the SIL dest bbs to their LLVM bbs.
47224726 SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
@@ -4932,12 +4936,12 @@ void IRGenSILFunction::visitSelectEnumInst(SelectEnumInst *inst) {
49324936 (inst->getNumCases () == 2 && !inst->hasDefault ())) {
49334937 // If this is testing for one case, do simpler codegen. This is
49344938 // particularly common when testing optionals.
4935- Explosion value = getLoweredExplosion (inst->getEnumOperand ());
4939+ Explosion value = getLoweredExplosion (inst->getEnumOperand (), &Builder );
49364940 auto isTrue = EIS.emitValueCaseTest (*this , value, inst->getCase (0 ).first );
49374941 emitSingleEnumMemberSelectResult (*this , SelectEnumOperation (inst), isTrue,
49384942 result);
49394943 } else {
4940- Explosion value = getLoweredExplosion (inst->getEnumOperand ());
4944+ Explosion value = getLoweredExplosion (inst->getEnumOperand (), &Builder );
49414945
49424946 // Map the SIL dest bbs to their LLVM bbs.
49434947 SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
@@ -4956,7 +4960,7 @@ void IRGenSILFunction::visitSelectEnumInst(SelectEnumInst *inst) {
49564960}
49574961
49584962void IRGenSILFunction::visitSelectEnumAddrInst (SelectEnumAddrInst *inst) {
4959- Address value = getLoweredAddress (inst->getEnumOperand ());
4963+ Address value = getLoweredAddress (inst->getEnumOperand (), &Builder );
49604964 auto seo = SelectEnumOperation (inst);
49614965 Explosion result;
49624966
@@ -5065,7 +5069,7 @@ void IRGenSILFunction::visitCondBranchInst(swift::CondBranchInst *i) {
50655069 LoweredBB &trueBB = getLoweredBB (i->getTrueBB ());
50665070 LoweredBB &falseBB = getLoweredBB (i->getFalseBB ());
50675071 llvm::Value *condValue =
5068- getLoweredExplosion (i->getCondition ()).claimNext ();
5072+ getLoweredExplosion (i->getCondition (), &Builder ).claimNext ();
50695073
50705074 addIncomingSILArgumentsToPHINodes (*this , trueBB, i->getTrueArgs ());
50715075 addIncomingSILArgumentsToPHINodes (*this , falseBB, i->getFalseArgs ());
0 commit comments