@@ -534,7 +534,7 @@ class IRGenSILFunction :
534
534
setLoweredValue (tokenResult, std::move (state));
535
535
}
536
536
537
- LoweredValue &getUndefLoweredValue (SILType t) {
537
+ LoweredValue &getUndefLoweredValue (SILType t, IRBuilder *b = nullptr ) {
538
538
auto found = LoweredUndefs.find (t);
539
539
if (found != LoweredUndefs.end ())
540
540
return found->second ;
@@ -554,7 +554,11 @@ class IRGenSILFunction :
554
554
for (auto &elt : schema) {
555
555
assert (!elt.isAggregate ()
556
556
&& " 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);
558
562
}
559
563
LoweredUndefs.insert ({t, LoweredValue (e)});
560
564
break ;
@@ -568,9 +572,9 @@ class IRGenSILFunction :
568
572
569
573
// / Get the LoweredValue corresponding to the given SIL value, which must
570
574
// / have been lowered.
571
- LoweredValue &getLoweredValue (SILValue v) {
575
+ LoweredValue &getLoweredValue (SILValue v, IRBuilder *b = nullptr ) {
572
576
if (isa<SILUndef>(v))
573
- return getUndefLoweredValue (v->getType ());
577
+ return getUndefLoweredValue (v->getType (), b );
574
578
575
579
auto foundValue = LoweredValues.find (v);
576
580
assert (foundValue != LoweredValues.end () &&
@@ -580,8 +584,8 @@ class IRGenSILFunction :
580
584
581
585
// / Get the Address of a SIL value of address type, which must have been
582
586
// / 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 ();
585
589
}
586
590
587
591
StackAddress getLoweredStackAddress (SILValue v) {
@@ -602,8 +606,8 @@ class IRGenSILFunction :
602
606
}
603
607
// / Create an Explosion containing the unmanaged LLVM values lowered from a
604
608
// / 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 ());
607
611
}
608
612
609
613
// / Get the lowered value for the given value of optional type in a
@@ -4680,7 +4684,7 @@ static llvm::BasicBlock *emitBBMapForSwitchEnum(
4680
4684
}
4681
4685
4682
4686
void IRGenSILFunction::visitSwitchEnumInst (SwitchEnumInst *inst) {
4683
- Explosion value = getLoweredExplosion (inst->getOperand ());
4687
+ Explosion value = getLoweredExplosion (inst->getOperand (), &Builder );
4684
4688
4685
4689
// Map the SIL dest bbs to their LLVM bbs.
4686
4690
SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
@@ -4701,7 +4705,7 @@ void IRGenSILFunction::visitSwitchEnumInst(SwitchEnumInst *inst) {
4701
4705
4702
4706
Builder.emitBlock (waypointBB);
4703
4707
4704
- Explosion inValue = getLoweredExplosion (inst->getOperand ());
4708
+ Explosion inValue = getLoweredExplosion (inst->getOperand (), &Builder );
4705
4709
Explosion projected;
4706
4710
emitProjectLoadableEnum (*this , inst->getOperand ()->getType (),
4707
4711
inValue, casePair.first , projected);
@@ -4716,7 +4720,7 @@ void IRGenSILFunction::visitSwitchEnumInst(SwitchEnumInst *inst) {
4716
4720
4717
4721
void
4718
4722
IRGenSILFunction::visitSwitchEnumAddrInst (SwitchEnumAddrInst *inst) {
4719
- Address value = getLoweredAddress (inst->getOperand ());
4723
+ Address value = getLoweredAddress (inst->getOperand (), &Builder );
4720
4724
4721
4725
// Map the SIL dest bbs to their LLVM bbs.
4722
4726
SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
@@ -4932,12 +4936,12 @@ void IRGenSILFunction::visitSelectEnumInst(SelectEnumInst *inst) {
4932
4936
(inst->getNumCases () == 2 && !inst->hasDefault ())) {
4933
4937
// If this is testing for one case, do simpler codegen. This is
4934
4938
// particularly common when testing optionals.
4935
- Explosion value = getLoweredExplosion (inst->getEnumOperand ());
4939
+ Explosion value = getLoweredExplosion (inst->getEnumOperand (), &Builder );
4936
4940
auto isTrue = EIS.emitValueCaseTest (*this , value, inst->getCase (0 ).first );
4937
4941
emitSingleEnumMemberSelectResult (*this , SelectEnumOperation (inst), isTrue,
4938
4942
result);
4939
4943
} else {
4940
- Explosion value = getLoweredExplosion (inst->getEnumOperand ());
4944
+ Explosion value = getLoweredExplosion (inst->getEnumOperand (), &Builder );
4941
4945
4942
4946
// Map the SIL dest bbs to their LLVM bbs.
4943
4947
SmallVector<std::pair<EnumElementDecl*, llvm::BasicBlock*>, 4 > dests;
@@ -4956,7 +4960,7 @@ void IRGenSILFunction::visitSelectEnumInst(SelectEnumInst *inst) {
4956
4960
}
4957
4961
4958
4962
void IRGenSILFunction::visitSelectEnumAddrInst (SelectEnumAddrInst *inst) {
4959
- Address value = getLoweredAddress (inst->getEnumOperand ());
4963
+ Address value = getLoweredAddress (inst->getEnumOperand (), &Builder );
4960
4964
auto seo = SelectEnumOperation (inst);
4961
4965
Explosion result;
4962
4966
@@ -5065,7 +5069,7 @@ void IRGenSILFunction::visitCondBranchInst(swift::CondBranchInst *i) {
5065
5069
LoweredBB &trueBB = getLoweredBB (i->getTrueBB ());
5066
5070
LoweredBB &falseBB = getLoweredBB (i->getFalseBB ());
5067
5071
llvm::Value *condValue =
5068
- getLoweredExplosion (i->getCondition ()).claimNext ();
5072
+ getLoweredExplosion (i->getCondition (), &Builder ).claimNext ();
5069
5073
5070
5074
addIncomingSILArgumentsToPHINodes (*this , trueBB, i->getTrueArgs ());
5071
5075
addIncomingSILArgumentsToPHINodes (*this , falseBB, i->getFalseArgs ());
0 commit comments