@@ -567,8 +567,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
567
567
// Location for the SubExpr.
568
568
// Since SubExpr is of complex type, visiting it results in a pointer
569
569
// anyway, so we just create a temporary pointer variable.
570
- unsigned SubExprOffset = allocateLocalPrimitive (
571
- SubExpr, PT_Ptr, /* IsConst=*/ true , /* IsExtended= */ false );
570
+ unsigned SubExprOffset =
571
+ allocateLocalPrimitive ( SubExpr, PT_Ptr, /* IsConst=*/ true );
572
572
if (!this ->visit (SubExpr))
573
573
return false ;
574
574
if (!this ->emitSetLocal (PT_Ptr, SubExprOffset, CE))
@@ -611,8 +611,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
611
611
612
612
const auto *VT = CE->getType ()->getAs <VectorType>();
613
613
PrimType ElemT = classifyPrim (SubExpr->getType ());
614
- unsigned ElemOffset = allocateLocalPrimitive (
615
- SubExpr, ElemT, /* IsConst=*/ true , /* IsExtended= */ false );
614
+ unsigned ElemOffset =
615
+ allocateLocalPrimitive ( SubExpr, ElemT, /* IsConst=*/ true );
616
616
617
617
// Prepare a local variable for the scalar value.
618
618
if (!this ->visit (SubExpr))
@@ -1104,7 +1104,7 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
1104
1104
PrimType ResultElemT = this ->classifyComplexElementType (E->getType ());
1105
1105
unsigned ResultOffset = ~0u ;
1106
1106
if (!DiscardResult)
1107
- ResultOffset = this ->allocateLocalPrimitive (E, PT_Ptr, true , false );
1107
+ ResultOffset = this ->allocateLocalPrimitive (E, PT_Ptr, /* IsConst= */ true );
1108
1108
1109
1109
// Save result pointer in ResultOffset
1110
1110
if (!this ->DiscardResult ) {
@@ -1178,14 +1178,14 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
1178
1178
1179
1179
// Evaluate LHS and save value to LHSOffset.
1180
1180
if (LHSType->isAnyComplexType ()) {
1181
- LHSOffset = this ->allocateLocalPrimitive (LHS, PT_Ptr, true , false );
1181
+ LHSOffset = this ->allocateLocalPrimitive (LHS, PT_Ptr, /* IsConst= */ true );
1182
1182
if (!this ->visit (LHS))
1183
1183
return false ;
1184
1184
if (!this ->emitSetLocal (PT_Ptr, LHSOffset, E))
1185
1185
return false ;
1186
1186
} else {
1187
1187
PrimType LHST = classifyPrim (LHSType);
1188
- LHSOffset = this ->allocateLocalPrimitive (LHS, LHST, true , false );
1188
+ LHSOffset = this ->allocateLocalPrimitive (LHS, LHST, /* IsConst= */ true );
1189
1189
if (!this ->visit (LHS))
1190
1190
return false ;
1191
1191
if (!this ->emitSetLocal (LHST, LHSOffset, E))
@@ -1195,14 +1195,14 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
1195
1195
// Same with RHS.
1196
1196
unsigned RHSOffset;
1197
1197
if (RHSType->isAnyComplexType ()) {
1198
- RHSOffset = this ->allocateLocalPrimitive (RHS, PT_Ptr, true , false );
1198
+ RHSOffset = this ->allocateLocalPrimitive (RHS, PT_Ptr, /* IsConst= */ true );
1199
1199
if (!this ->visit (RHS))
1200
1200
return false ;
1201
1201
if (!this ->emitSetLocal (PT_Ptr, RHSOffset, E))
1202
1202
return false ;
1203
1203
} else {
1204
1204
PrimType RHST = classifyPrim (RHSType);
1205
- RHSOffset = this ->allocateLocalPrimitive (RHS, RHST, true , false );
1205
+ RHSOffset = this ->allocateLocalPrimitive (RHS, RHST, /* IsConst= */ true );
1206
1206
if (!this ->visit (RHS))
1207
1207
return false ;
1208
1208
if (!this ->emitSetLocal (RHST, RHSOffset, E))
@@ -1342,14 +1342,16 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
1342
1342
PrimType ResultElemT = this ->classifyVectorElementType (E->getType ());
1343
1343
1344
1344
// Evaluate LHS and save value to LHSOffset.
1345
- unsigned LHSOffset = this ->allocateLocalPrimitive (LHS, PT_Ptr, true , false );
1345
+ unsigned LHSOffset =
1346
+ this ->allocateLocalPrimitive (LHS, PT_Ptr, /* IsConst=*/ true );
1346
1347
if (!this ->visit (LHS))
1347
1348
return false ;
1348
1349
if (!this ->emitSetLocal (PT_Ptr, LHSOffset, E))
1349
1350
return false ;
1350
1351
1351
1352
// Evaluate RHS and save value to RHSOffset.
1352
- unsigned RHSOffset = this ->allocateLocalPrimitive (RHS, PT_Ptr, true , false );
1353
+ unsigned RHSOffset =
1354
+ this ->allocateLocalPrimitive (RHS, PT_Ptr, /* IsConst=*/ true );
1353
1355
if (!this ->visit (RHS))
1354
1356
return false ;
1355
1357
if (!this ->emitSetLocal (PT_Ptr, RHSOffset, E))
@@ -2710,8 +2712,8 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr(
2710
2712
// For everyhing else, use local variables.
2711
2713
if (SubExprT) {
2712
2714
bool IsConst = SubExpr->getType ().isConstQualified ();
2713
- unsigned LocalIndex = allocateLocalPrimitive (E, *SubExprT, IsConst,
2714
- /* IsExtended= */ true );
2715
+ unsigned LocalIndex =
2716
+ allocateLocalPrimitive (E, *SubExprT, IsConst, E-> getExtendingDecl () );
2715
2717
if (!this ->visit (SubExpr))
2716
2718
return false ;
2717
2719
if (!this ->emitSetLocal (*SubExprT, LocalIndex, E))
@@ -2781,7 +2783,7 @@ bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
2781
2783
unsigned LocalIndex;
2782
2784
2783
2785
if (T)
2784
- LocalIndex = this ->allocateLocalPrimitive (Init, *T, false , false );
2786
+ LocalIndex = this ->allocateLocalPrimitive (Init, *T, /* IsConst= */ false );
2785
2787
else if (std::optional<unsigned > MaybeIndex = this ->allocateLocal (Init))
2786
2788
LocalIndex = *MaybeIndex;
2787
2789
else
@@ -3337,8 +3339,8 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
3337
3339
PrimType SizeT = classifyPrim (Stripped->getType ());
3338
3340
3339
3341
// Save evaluated array size to a variable.
3340
- unsigned ArrayLen = allocateLocalPrimitive (
3341
- Stripped, SizeT, /* IsConst= */ false , /* IsExtended =*/ false );
3342
+ unsigned ArrayLen =
3343
+ allocateLocalPrimitive ( Stripped, SizeT, /* IsConst=*/ false );
3342
3344
if (!this ->visit (Stripped))
3343
3345
return false ;
3344
3346
if (!this ->emitSetLocal (SizeT, ArrayLen, E))
@@ -3417,8 +3419,8 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
3417
3419
}
3418
3420
3419
3421
// Create loop variables.
3420
- unsigned Iter = allocateLocalPrimitive (
3421
- Stripped, SizeT, /* IsConst= */ false , /* IsExtended =*/ false );
3422
+ unsigned Iter =
3423
+ allocateLocalPrimitive ( Stripped, SizeT, /* IsConst=*/ false );
3422
3424
if (!this ->emitConst (StaticInitElems, SizeT, E))
3423
3425
return false ;
3424
3426
if (!this ->emitSetLocal (SizeT, Iter, E))
@@ -3669,8 +3671,8 @@ template <class Emitter>
3669
3671
bool Compiler<Emitter>::VisitAddrLabelExpr(const AddrLabelExpr *E) {
3670
3672
assert (E->getType ()->isVoidPointerType ());
3671
3673
3672
- unsigned Offset = allocateLocalPrimitive (
3673
- E->getLabel (), PT_Ptr, /* IsConst=*/ true , /* IsExtended= */ false );
3674
+ unsigned Offset =
3675
+ allocateLocalPrimitive ( E->getLabel (), PT_Ptr, /* IsConst=*/ true );
3674
3676
3675
3677
return this ->emitGetLocal (PT_Ptr, Offset, E);
3676
3678
}
@@ -3685,7 +3687,8 @@ bool Compiler<Emitter>::VisitConvertVectorExpr(const ConvertVectorExpr *E) {
3685
3687
QualType SrcType = Src->getType ();
3686
3688
PrimType SrcElemT = classifyVectorElementType (SrcType);
3687
3689
3688
- unsigned SrcOffset = this ->allocateLocalPrimitive (Src, PT_Ptr, true , false );
3690
+ unsigned SrcOffset =
3691
+ this ->allocateLocalPrimitive (Src, PT_Ptr, /* IsConst=*/ true );
3689
3692
if (!this ->visit (Src))
3690
3693
return false ;
3691
3694
if (!this ->emitSetLocal (PT_Ptr, SrcOffset, E))
@@ -3728,8 +3731,8 @@ bool Compiler<Emitter>::VisitShuffleVectorExpr(const ShuffleVectorExpr *E) {
3728
3731
// Save both input vectors to a local variable.
3729
3732
unsigned VectorOffsets[2 ];
3730
3733
for (unsigned I = 0 ; I != 2 ; ++I) {
3731
- VectorOffsets[I] = this -> allocateLocalPrimitive (
3732
- Vecs[I], PT_Ptr, /* IsConst=*/ true , /* IsExtended= */ false );
3734
+ VectorOffsets[I] =
3735
+ this -> allocateLocalPrimitive ( Vecs[I], PT_Ptr, /* IsConst=*/ true );
3733
3736
if (!this ->visit (Vecs[I]))
3734
3737
return false ;
3735
3738
if (!this ->emitSetLocal (PT_Ptr, VectorOffsets[I], E))
@@ -3781,8 +3784,7 @@ bool Compiler<Emitter>::VisitExtVectorElementExpr(
3781
3784
}
3782
3785
3783
3786
// Create a local variable for the base.
3784
- unsigned BaseOffset = allocateLocalPrimitive (Base, PT_Ptr, /* IsConst=*/ true ,
3785
- /* IsExtended=*/ false );
3787
+ unsigned BaseOffset = allocateLocalPrimitive (Base, PT_Ptr, /* IsConst=*/ true );
3786
3788
if (!this ->visit (Base))
3787
3789
return false ;
3788
3790
if (!this ->emitSetLocal (PT_Ptr, BaseOffset, E))
@@ -4194,9 +4196,8 @@ bool Compiler<Emitter>::emitConst(const APSInt &Value, const Expr *E) {
4194
4196
}
4195
4197
4196
4198
template <class Emitter >
4197
- unsigned Compiler<Emitter>::allocateLocalPrimitive(DeclTy &&Src, PrimType Ty,
4198
- bool IsConst,
4199
- bool IsExtended) {
4199
+ unsigned Compiler<Emitter>::allocateLocalPrimitive(
4200
+ DeclTy &&Src, PrimType Ty, bool IsConst, const ValueDecl *ExtendingDecl) {
4200
4201
// Make sure we don't accidentally register the same decl twice.
4201
4202
if (const auto *VD =
4202
4203
dyn_cast_if_present<ValueDecl>(Src.dyn_cast <const Decl *>())) {
@@ -4213,7 +4214,10 @@ unsigned Compiler<Emitter>::allocateLocalPrimitive(DeclTy &&Src, PrimType Ty,
4213
4214
Scope::Local Local = this ->createLocal (D);
4214
4215
if (auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast <const Decl *>()))
4215
4216
Locals.insert ({VD, Local});
4216
- VarScope->add (Local, IsExtended);
4217
+ if (ExtendingDecl)
4218
+ VarScope->addExtended (Local, ExtendingDecl);
4219
+ else
4220
+ VarScope->add (Local, false );
4217
4221
return Local.Offset ;
4218
4222
}
4219
4223
@@ -4781,7 +4785,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
4781
4785
// decl as the function pointer.
4782
4786
const Expr *Callee = E->getCallee ();
4783
4787
CalleeOffset =
4784
- this ->allocateLocalPrimitive (Callee, PT_MemberPtr, true , false );
4788
+ this ->allocateLocalPrimitive (Callee, PT_MemberPtr, /* IsConst= */ true );
4785
4789
if (!this ->visit (Callee))
4786
4790
return false ;
4787
4791
if (!this ->emitSetLocal (PT_MemberPtr, *CalleeOffset, E))
@@ -4803,7 +4807,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
4803
4807
return this ->emitKill (E);
4804
4808
} else if (!FuncDecl) {
4805
4809
const Expr *Callee = E->getCallee ();
4806
- CalleeOffset = this ->allocateLocalPrimitive (Callee, PT_FnPtr, true , false );
4810
+ CalleeOffset =
4811
+ this ->allocateLocalPrimitive (Callee, PT_FnPtr, /* IsConst=*/ true );
4807
4812
if (!this ->visit (Callee))
4808
4813
return false ;
4809
4814
if (!this ->emitSetLocal (PT_FnPtr, *CalleeOffset, E))
@@ -5405,7 +5410,8 @@ bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
5405
5410
5406
5411
LabelTy EndLabel = this ->getLabel ();
5407
5412
OptLabelTy DefaultLabel = std::nullopt;
5408
- unsigned CondVar = this ->allocateLocalPrimitive (Cond, CondT, true , false );
5413
+ unsigned CondVar =
5414
+ this ->allocateLocalPrimitive (Cond, CondT, /* IsConst=*/ true );
5409
5415
5410
5416
if (const auto *CondInit = S->getInit ())
5411
5417
if (!visitStmt (CondInit))
@@ -6068,7 +6074,8 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) {
6068
6074
// The offset of the temporary, if we created one.
6069
6075
unsigned SubExprOffset = ~0u ;
6070
6076
auto createTemp = [=, &SubExprOffset]() -> bool {
6071
- SubExprOffset = this ->allocateLocalPrimitive (SubExpr, PT_Ptr, true , false );
6077
+ SubExprOffset =
6078
+ this ->allocateLocalPrimitive (SubExpr, PT_Ptr, /* IsConst=*/ true );
6072
6079
if (!this ->visit (SubExpr))
6073
6080
return false ;
6074
6081
return this ->emitSetLocal (PT_Ptr, SubExprOffset, E);
@@ -6182,7 +6189,7 @@ bool Compiler<Emitter>::VisitVectorUnaryOperator(const UnaryOperator *E) {
6182
6189
6183
6190
// The offset of the temporary, if we created one.
6184
6191
unsigned SubExprOffset =
6185
- this ->allocateLocalPrimitive (SubExpr, PT_Ptr, true , false );
6192
+ this ->allocateLocalPrimitive (SubExpr, PT_Ptr, /* IsConst= */ true );
6186
6193
if (!this ->visit (SubExpr))
6187
6194
return false ;
6188
6195
if (!this ->emitSetLocal (PT_Ptr, SubExprOffset, E))
@@ -6555,16 +6562,15 @@ bool Compiler<Emitter>::emitComplexComparison(const Expr *LHS, const Expr *RHS,
6555
6562
if (LHS->getType ()->isAnyComplexType ()) {
6556
6563
LHSIsComplex = true ;
6557
6564
ElemT = classifyComplexElementType (LHS->getType ());
6558
- LHSOffset = allocateLocalPrimitive (LHS, PT_Ptr, /* IsConst=*/ true ,
6559
- /* IsExtended=*/ false );
6565
+ LHSOffset = allocateLocalPrimitive (LHS, PT_Ptr, /* IsConst=*/ true );
6560
6566
if (!this ->visit (LHS))
6561
6567
return false ;
6562
6568
if (!this ->emitSetLocal (PT_Ptr, LHSOffset, E))
6563
6569
return false ;
6564
6570
} else {
6565
6571
LHSIsComplex = false ;
6566
6572
PrimType LHST = classifyPrim (LHS->getType ());
6567
- LHSOffset = this ->allocateLocalPrimitive (LHS, LHST, true , false );
6573
+ LHSOffset = this ->allocateLocalPrimitive (LHS, LHST, /* IsConst= */ true );
6568
6574
if (!this ->visit (LHS))
6569
6575
return false ;
6570
6576
if (!this ->emitSetLocal (LHST, LHSOffset, E))
@@ -6576,16 +6582,15 @@ bool Compiler<Emitter>::emitComplexComparison(const Expr *LHS, const Expr *RHS,
6576
6582
if (RHS->getType ()->isAnyComplexType ()) {
6577
6583
RHSIsComplex = true ;
6578
6584
ElemT = classifyComplexElementType (RHS->getType ());
6579
- RHSOffset = allocateLocalPrimitive (RHS, PT_Ptr, /* IsConst=*/ true ,
6580
- /* IsExtended=*/ false );
6585
+ RHSOffset = allocateLocalPrimitive (RHS, PT_Ptr, /* IsConst=*/ true );
6581
6586
if (!this ->visit (RHS))
6582
6587
return false ;
6583
6588
if (!this ->emitSetLocal (PT_Ptr, RHSOffset, E))
6584
6589
return false ;
6585
6590
} else {
6586
6591
RHSIsComplex = false ;
6587
6592
PrimType RHST = classifyPrim (RHS->getType ());
6588
- RHSOffset = this ->allocateLocalPrimitive (RHS, RHST, true , false );
6593
+ RHSOffset = this ->allocateLocalPrimitive (RHS, RHST, /* IsConst= */ true );
6589
6594
if (!this ->visit (RHS))
6590
6595
return false ;
6591
6596
if (!this ->emitSetLocal (RHST, RHSOffset, E))
@@ -6762,8 +6767,8 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
6762
6767
if (!this ->visit (SubExpr))
6763
6768
return false ;
6764
6769
} else if (std::optional<PrimType> FromT = classify (SubExpr)) {
6765
- unsigned TempOffset = allocateLocalPrimitive (
6766
- SubExpr, *FromT, /* IsConst=*/ true , /* IsExtended= */ false );
6770
+ unsigned TempOffset =
6771
+ allocateLocalPrimitive ( SubExpr, *FromT, /* IsConst=*/ true );
6767
6772
if (!this ->visit (SubExpr))
6768
6773
return false ;
6769
6774
if (!this ->emitSetLocal (*FromT, TempOffset, E))
0 commit comments