Skip to content

Commit fa9151e

Browse files
committed
Create new Opnd ListOpnd. Currently available only at lower and after.
Allows to set a list of dst and src.
1 parent 8c7f507 commit fa9151e

12 files changed

Lines changed: 390 additions & 94 deletions

File tree

lib/Backend/DbCheckPostLower.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ void DbCheckPostLower::Check(IR::Opnd *opnd)
221221
this->Check(opnd->AsIndirOpnd()->GetBaseOpnd());
222222
this->Check(opnd->AsIndirOpnd()->GetIndexOpnd());
223223
}
224+
else if (opnd->IsListOpnd())
225+
{
226+
opnd->AsListOpnd()->Map([&](int i, IR::Opnd* opnd) { this->Check(opnd); });
227+
}
224228
else if (opnd->IsSymOpnd() && opnd->AsSymOpnd()->m_sym->IsStackSym())
225229
{
226230
if (this->func->isPostRegAlloc)

lib/Backend/IR.cpp

Lines changed: 92 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,78 +2858,58 @@ Instr::GetOrCreateContinueLabel(const bool isHelper)
28582858
return label;
28592859
}
28602860

2861-
///----------------------------------------------------------------------------
2862-
///
2863-
/// Instr::FindRegUse
2864-
///
2865-
/// Search a reg use of the given sym. Return the RegOpnd that uses it.
2866-
///
2867-
///----------------------------------------------------------------------------
28682861

2869-
IR::RegOpnd *
2870-
Instr::FindRegUse(StackSym *sym)
2862+
IR::RegOpnd * Instr::FindRegUseSrc(StackSym *sym, IR::Opnd* src)
28712863
{
2872-
IR::Opnd *src1 = this->GetSrc1();
2864+
if (!src)
2865+
{
2866+
return nullptr;
2867+
}
2868+
if (src->IsRegOpnd())
2869+
{
2870+
RegOpnd *regOpnd = src->AsRegOpnd();
28732871

2874-
// Check src1
2875-
if (src1)
2872+
if (regOpnd->m_sym == sym)
2873+
{
2874+
return regOpnd;
2875+
}
2876+
}
2877+
else if (src->IsIndirOpnd())
28762878
{
2877-
if (src1->IsRegOpnd())
2879+
IR::IndirOpnd *indirOpnd = src->AsIndirOpnd();
2880+
RegOpnd * baseOpnd = indirOpnd->GetBaseOpnd();
2881+
if (baseOpnd != nullptr && baseOpnd->m_sym == sym)
28782882
{
2879-
RegOpnd *regOpnd = src1->AsRegOpnd();
2880-
2881-
if (regOpnd->m_sym == sym)
2882-
{
2883-
return regOpnd;
2884-
}
2883+
return baseOpnd;
28852884
}
2886-
else if (src1->IsIndirOpnd())
2885+
else if (indirOpnd->GetIndexOpnd() && indirOpnd->GetIndexOpnd()->m_sym == sym)
28872886
{
2888-
IndirOpnd * indirOpnd = src1->AsIndirOpnd();
2889-
RegOpnd * baseOpnd = indirOpnd->GetBaseOpnd();
2890-
if (baseOpnd != nullptr && baseOpnd->m_sym == sym)
2891-
{
2892-
return baseOpnd;
2893-
}
2894-
else if (indirOpnd->GetIndexOpnd() && indirOpnd->GetIndexOpnd()->m_sym == sym)
2895-
{
2896-
return indirOpnd->GetIndexOpnd();
2897-
}
2887+
return indirOpnd->GetIndexOpnd();
28982888
}
2899-
IR::Opnd *src2 = this->GetSrc2();
2900-
2901-
// Check src2
2902-
if (src2)
2889+
}
2890+
else if (src->IsListOpnd())
2891+
{
2892+
IR::ListOpnd* list = src->AsListOpnd();
2893+
for (int i = 0; i < list->Count(); ++i)
29032894
{
2904-
if (src2->IsRegOpnd())
2895+
IR::RegOpnd* reg = FindRegUseSrc(sym, list->Item(i));
2896+
if (reg)
29052897
{
2906-
RegOpnd *regOpnd = src2->AsRegOpnd();
2907-
2908-
if (regOpnd->m_sym == sym)
2909-
{
2910-
return regOpnd;
2911-
}
2912-
}
2913-
else if (src2->IsIndirOpnd())
2914-
{
2915-
IR::IndirOpnd *indirOpnd = src2->AsIndirOpnd();
2916-
RegOpnd * baseOpnd = indirOpnd->GetBaseOpnd();
2917-
if (baseOpnd != nullptr && baseOpnd->m_sym == sym)
2918-
{
2919-
return baseOpnd;
2920-
}
2921-
else if (indirOpnd->GetIndexOpnd() && indirOpnd->GetIndexOpnd()->m_sym == sym)
2922-
{
2923-
return indirOpnd->GetIndexOpnd();
2924-
}
2898+
return reg;
29252899
}
29262900
}
29272901
}
2902+
return nullptr;
2903+
}
29282904

2929-
// Check uses in dst
2930-
IR::Opnd *dst = this->GetDst();
29312905

2932-
if (dst != nullptr && dst->IsIndirOpnd())
2906+
IR::RegOpnd * Instr::FindRegUseDst(StackSym *sym, IR::Opnd* dst)
2907+
{
2908+
if (!dst)
2909+
{
2910+
return nullptr;
2911+
}
2912+
if (dst->IsIndirOpnd())
29332913
{
29342914
IR::IndirOpnd *indirOpnd = dst->AsIndirOpnd();
29352915
RegOpnd * baseOpnd = indirOpnd->GetBaseOpnd();
@@ -2942,7 +2922,47 @@ Instr::FindRegUse(StackSym *sym)
29422922
return indirOpnd->GetIndexOpnd();
29432923
}
29442924
}
2925+
else if (dst->IsListOpnd())
2926+
{
2927+
IR::ListOpnd* list = dst->AsListOpnd();
2928+
for (int i = 0; i < list->Count(); ++i)
2929+
{
2930+
IR::RegOpnd* reg = FindRegUseDst(sym, list->Item(i));
2931+
if (reg)
2932+
{
2933+
return reg;
2934+
}
2935+
}
2936+
}
2937+
return nullptr;
2938+
}
29452939

2940+
///----------------------------------------------------------------------------
2941+
///
2942+
/// Instr::FindRegUse
2943+
///
2944+
/// Search a reg use of the given sym. Return the RegOpnd that uses it.
2945+
///
2946+
///----------------------------------------------------------------------------
2947+
2948+
IR::RegOpnd *
2949+
Instr::FindRegUse(StackSym *sym)
2950+
{
2951+
IR::RegOpnd* reg = FindRegUseSrc(sym, this->GetSrc1());
2952+
if (reg)
2953+
{
2954+
return reg;
2955+
}
2956+
reg = FindRegUseSrc(sym, this->GetSrc2());
2957+
if (reg)
2958+
{
2959+
return reg;
2960+
}
2961+
reg = FindRegUseDst(sym, this->GetDst());
2962+
if (reg)
2963+
{
2964+
return reg;
2965+
}
29462966
return nullptr;
29472967
}
29482968

@@ -3357,6 +3377,16 @@ IR::Instr* Instr::GetArgOutSnapshot()
33573377
return instr;
33583378
}
33593379

3380+
bool Instr::OpndHasAnyImplicitCalls(IR::Opnd* opnd, bool isSrc)
3381+
{
3382+
return opnd && (
3383+
(opnd->IsSymOpnd() && opnd->AsSymOpnd()->m_sym->IsPropertySym()) ||
3384+
opnd->IsIndirOpnd() ||
3385+
(isSrc && !opnd->GetValueType().IsPrimitive()) ||
3386+
(opnd->IsListOpnd() && opnd->AsListOpnd()->Any([isSrc](IR::Opnd* lOpnd) { return OpndHasAnyImplicitCalls(lOpnd, isSrc); }))
3387+
);
3388+
}
3389+
33603390
bool Instr::HasAnyImplicitCalls() const
33613391
{
33623392
// there can be no implicit calls in asm.js
@@ -3370,40 +3400,11 @@ bool Instr::HasAnyImplicitCalls() const
33703400
}
33713401
if (OpCodeAttr::OpndHasImplicitCall(this->m_opcode))
33723402
{
3373-
if (this->m_dst &&
3374-
((this->m_dst->IsSymOpnd() && this->m_dst->AsSymOpnd()->m_sym->IsPropertySym()) ||
3375-
this->m_dst->IsIndirOpnd()))
3376-
{
3377-
return true;
3378-
}
3379-
3380-
IR::Opnd *src1 = this->GetSrc1();
3381-
if (src1)
3382-
{
3383-
if ((src1->IsSymOpnd() && src1->AsSymOpnd()->m_sym->IsPropertySym()) || src1->IsIndirOpnd())
3384-
{
3385-
return true;
3386-
}
3387-
3388-
if (!src1->GetValueType().IsPrimitive())
3389-
{
3390-
return true;
3391-
}
3392-
3393-
IR::Opnd *src2 = this->GetSrc2();
3394-
if (src2)
3395-
{
3396-
if ((src2->IsSymOpnd() && src2->AsSymOpnd()->m_sym->IsPropertySym()) || src2->IsIndirOpnd())
3397-
{
3398-
return true;
3399-
}
3400-
3401-
if (!src2->GetValueType().IsPrimitive())
3402-
{
3403-
return true;
3404-
}
3405-
}
3406-
}
3403+
return (
3404+
OpndHasAnyImplicitCalls(this->GetDst(), false) ||
3405+
OpndHasAnyImplicitCalls(this->GetSrc1(), true) ||
3406+
OpndHasAnyImplicitCalls(this->GetSrc2(), true)
3407+
);
34073408
}
34083409

34093410
return false;

lib/Backend/IR.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class Instr
211211
bool ShouldCheckForIntOverflow() const;
212212
bool ShouldCheckFor32BitOverflow() const;
213213
bool ShouldCheckForNon32BitOverflow() const;
214+
static bool OpndHasAnyImplicitCalls(IR::Opnd* opnd, bool isSrc);
214215
bool HasAnyImplicitCalls() const;
215216
bool HasAnySideEffects() const;
216217
bool AreAllOpndInt64() const;
@@ -270,6 +271,8 @@ class Instr
270271
IR::Instr * GetPrevRealInstrOrLabel() const;
271272
IR::Instr * GetInsertBeforeByteCodeUsesInstr();
272273
IR::LabelInstr *GetOrCreateContinueLabel(const bool isHelper = false);
274+
static RegOpnd *FindRegUseSrc(StackSym *sym, IR::Opnd*);
275+
static RegOpnd *FindRegUseDst(StackSym *sym, IR::Opnd*);
273276
RegOpnd * FindRegUse(StackSym *sym);
274277
static RegOpnd *FindRegUseInRange(StackSym *sym, Instr *instrBegin, Instr *instrEnd);
275278
RegOpnd * FindRegDef(StackSym *sym);

lib/Backend/LinearScan.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,16 @@ LinearScan::SetUses(IR::Instr *instr, IR::Opnd *opnd)
11171117
}
11181118
}
11191119
break;
1120+
1121+
case IR::OpndKindList:
1122+
{
1123+
opnd->AsListOpnd()->Map([&](int i, IR::Opnd* opnd)
1124+
{
1125+
this->SetUses(instr, opnd);
1126+
});
1127+
}
1128+
break;
1129+
11201130
case IR::OpndKindIntConst:
11211131
case IR::OpndKindAddr:
11221132
this->linearScanMD.LegalizeConstantUse(instr, opnd);

0 commit comments

Comments
 (0)