Skip to content

Commit 07c7bce

Browse files
committed
Small data-structure packing cleanup.
Cleanup simd bits in Lifetime. Sym type for regalloc. Use sym type to allocate register type. Add assert to dbcheck to ensure sym type consistency. Free srcs/dst during instr->Remove().
1 parent 50ce23e commit 07c7bce

10 files changed

Lines changed: 60 additions & 18 deletions

File tree

lib/Backend/DbCheckPostLower.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ void DbCheckPostLower::Check(IR::RegOpnd *regOpnd)
262262
#endif
263263
}
264264
}
265+
266+
if (regOpnd->GetSym())
267+
{
268+
StackSym *sym = regOpnd->GetSym()->AsStackSym();
269+
IRType tySym = sym->GetType();
270+
IRType tyReg = regOpnd->GetType();
271+
272+
if (!IRType_IsSimd(tySym))
273+
{
274+
Assert((IRType_IsNativeIntOrVar(tySym) && IRType_IsNativeIntOrVar(tyReg))
275+
|| (IRType_IsFloat(tySym) && IRType_IsFloat(tyReg)));
276+
277+
Assert(TySize[tySym] >= TySize[tyReg] || this->func->isPostRegAlloc);
278+
}
279+
}
265280
}
266281

267282
#endif // DBG

lib/Backend/IR.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ Instr::Free()
359359
return;
360360
}
361361
Assert(this->m_func->GetTopFunc()->allowRemoveBailOutArgInstr || !stackSym->m_isBailOutReferenced);
362-
stackSym->m_instrDef = nullptr;
363362
}
364363
else
365364
{
@@ -373,6 +372,15 @@ Instr::Free()
373372
|| (stackSym->m_isEncodedConstant && stackSym->constantValue != 0));
374373
}
375374
}
375+
this->FreeDst();
376+
}
377+
if (this->GetSrc1())
378+
{
379+
this->FreeSrc1();
380+
if (this->GetSrc2())
381+
{
382+
this->FreeSrc2();
383+
}
376384
}
377385

378386
ClearBailOutInfo();
@@ -2155,17 +2163,23 @@ Instr::UnlinkDst()
21552163
}
21562164
}
21572165

2166+
if (stackSym && stackSym->m_isSingleDef)
2167+
{
2168+
if (stackSym->m_instrDef == this)
2169+
{
2170+
stackSym->m_instrDef = nullptr;
2171+
}
2172+
else
2173+
{
2174+
Assert(oldDst->isFakeDst);
2175+
}
2176+
}
21582177
#if DBG
21592178
if (oldDst->isFakeDst)
21602179
{
21612180
oldDst->isFakeDst = false;
21622181
}
21632182
#endif
2164-
if (stackSym && stackSym->m_isSingleDef)
2165-
{
2166-
AssertMsg(stackSym->m_instrDef == this, "m_instrDef incorrectly set");
2167-
stackSym->m_instrDef = nullptr;
2168-
}
21692183

21702184
oldDst->UnUse();
21712185
this->m_dst = nullptr;
@@ -2217,7 +2231,7 @@ Instr::ReplaceDst(Opnd * newDst)
22172231
Instr *
22182232
Instr::SinkDst(Js::OpCode assignOpcode, RegNum regNum, IR::Instr *insertAfterInstr)
22192233
{
2220-
return SinkDst(assignOpcode, StackSym::New(TyVar, m_func), regNum, insertAfterInstr);
2234+
return SinkDst(assignOpcode, StackSym::New(this->GetDst()->GetType(), m_func), regNum, insertAfterInstr);
22212235
}
22222236

22232237
Instr *
@@ -4559,7 +4573,7 @@ PragmaInstr::Dump(IRDumpFlags flags)
45594573
{
45604574
functionBody = ((Js::FunctionBody*)m_func->GetJITFunctionBody()->GetAddr());
45614575
}
4562-
if (functionBody)
4576+
if (functionBody && !functionBody->GetUtf8SourceInfo()->GetIsLibraryCode())
45634577
{
45644578
functionBody->PrintStatementSourceLine(this->m_statementIndex);
45654579
}

lib/Backend/IR.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,6 @@ class Instr
456456
void SetBailOutKind_NoAssert(const IR::BailOutKind bailOutKind);
457457

458458
public:
459-
// used only for SIMD Ld/St from typed arrays.
460-
// we keep these here to avoid increase in number of opcodes and to not use ExtendedArgs
461-
uint8 dataWidth;
462459

463460
#ifdef BAILOUT_INJECTION
464461
uint bailOutByteCodeLocation;
@@ -473,6 +470,11 @@ class Instr
473470
Js::OpCode m_opcode;
474471
uint8 ignoreOverflowBitCount; // Number of bits after which ovf matters. Currently used for MULs.
475472

473+
// used only for SIMD Ld/St from typed arrays.
474+
// we keep these here to avoid increase in number of opcodes and to not use ExtendedArgs
475+
uint8 dataWidth;
476+
477+
476478
bool isFsBased : 1; // TEMP : just for BS testing
477479
bool dstIsTempNumber : 1;
478480
bool dstIsTempNumberTransferred : 1;

lib/Backend/IRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ IRBuilder::Build()
437437
// those as if they are local for the value of the with statement
438438
this->m_ldSlots = BVFixed::New<JitArenaAllocator>(m_func->GetJITFunctionBody()->GetLocalsCount(), m_tempAlloc);
439439
this->m_stSlots = BVFixed::New<JitArenaAllocator>(m_func->GetJITFunctionBody()->GetFirstTmpReg(), m_tempAlloc);
440-
this->m_loopBodyRetIPSym = StackSym::New(TyInt32, this->m_func);
440+
this->m_loopBodyRetIPSym = StackSym::New(TyMachReg, this->m_func);
441441
#if DBG
442442
if (m_func->GetJITFunctionBody()->GetTempCount() != 0)
443443
{

lib/Backend/IRType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ bool IRType_IsNativeInt(IRType type)
4747
}
4848
bool IRType_IsInt64(IRType type) { return type == TyInt64 || type == TyUint64; }
4949

50+
bool IRType_IsNativeIntOrVar(IRType type)
51+
{
52+
return IRType_IsNativeInt(type) || type == TyVar;
53+
}
54+
5055
bool IRType_IsSimd(IRType type)
5156
{
5257
return TyBaseType[type] == IRBaseType_Simd;

lib/Backend/IRType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern bool IRType_IsUnsignedInt(IRType type);
2929
extern bool IRType_IsFloat(IRType type);
3030
extern bool IRType_IsNative(IRType type);
3131
extern bool IRType_IsNativeInt(IRType type);
32+
extern bool IRType_IsNativeIntOrVar(IRType type);
3233
extern bool IRType_IsInt64(IRType type);
3334
extern bool IRType_IsSimd(IRType type);
3435
extern bool IRType_IsSimd128(IRType type);

lib/Backend/LinearScan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,7 +3353,7 @@ LinearScan::InsertLoad(IR::Instr *instr, StackSym *sym, RegNum reg)
33533353
else
33543354
{
33553355
StackSym * oldSym = sym;
3356-
sym = StackSym::New(TyVar, this->func);
3356+
sym = StackSym::New(sym->GetType(), this->func);
33573357
sym->m_isConst = true;
33583358
sym->m_isIntConst = oldSym->m_isIntConst;
33593359
sym->m_isInt64Const = oldSym->m_isInt64Const;
@@ -4182,7 +4182,7 @@ LinearScan::ReconcileRegContent(Lifetime ** branchRegContent, Lifetime **labelRe
41824182
}
41834183
else
41844184
{
4185-
Assert(type == TyFloat64 || IRType_IsSimd128(type));
4185+
Assert(type == TyFloat64 || IRType_IsSimd(type));
41864186

41874187
FOREACH_FLOAT_REG(regIter)
41884188
{
@@ -4611,7 +4611,7 @@ LinearScan::SaveRegContent(IR::Instr *instr)
46114611

46124612
bool LinearScan::RegsAvailable(IRType type)
46134613
{
4614-
if (IRType_IsFloat(type) || IRType_IsSimd128(type))
4614+
if (IRType_IsFloat(type) || IRType_IsSimd(type))
46154615
{
46164616
return (this->floatRegUsedCount < FLOAT_REG_COUNT);
46174617
}

lib/Backend/Lower.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11545,6 +11545,7 @@ Lowerer::LowerBailOnNotStackArgs(IR::Instr * instr)
1154511545
{
1154611546
//BailOut if the number of actuals (except "this" argument) is greater than or equal to 15.
1154711547
IR::RegOpnd* ldLenDstOpnd = IR::RegOpnd::New(TyUint32, instr->m_func);
11548+
const IR::AutoReuseOpnd autoReuseldLenDstOpnd(ldLenDstOpnd, instr->m_func);
1154811549
IR::Instr* ldLen = IR::Instr::New(Js::OpCode::LdLen_A, ldLenDstOpnd, instr->m_func);
1154911550
ldLenDstOpnd->SetValueType(ValueType::GetTaggedInt()); //LdLen_A works only on stack arguments
1155011551
instr->InsertBefore(ldLen);
@@ -19535,7 +19536,8 @@ Lowerer::GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsIn
1953519536
IR::RegOpnd* stackArgs = stackArgsInstr->GetSrc1()->AsRegOpnd();
1953619537

1953719538
IR::RegOpnd* ldLenDstOpnd = IR::RegOpnd::New(TyMachReg, func);
19538-
IR::Instr* ldLen = IR::Instr::New(Js::OpCode::LdLen_A, ldLenDstOpnd ,stackArgs, func);
19539+
const IR::AutoReuseOpnd autoReuseLdLenDstOpnd(ldLenDstOpnd, func);
19540+
IR::Instr* ldLen = IR::Instr::New(Js::OpCode::LdLen_A, ldLenDstOpnd, stackArgs, func);
1953919541
ldLenDstOpnd->SetValueType(ValueType::GetTaggedInt()); /*LdLen_A works only on stack arguments*/
1954019542
callInstr->InsertBefore(ldLen);
1954119543
GenerateFastRealStackArgumentsLdLen(ldLen);
@@ -19563,6 +19565,7 @@ Lowerer::GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsIn
1956319565

1956419566
IR::IndirOpnd *nthArgument = IR::IndirOpnd::New(stackArgs, ldLenDstOpnd, TyMachReg, func);
1956519567
IR::RegOpnd* ldElemDstOpnd = IR::RegOpnd::New(TyMachReg,func);
19568+
const IR::AutoReuseOpnd autoReuseldElemDstOpnd(ldElemDstOpnd, func);
1956619569
IR::Instr* ldElem = IR::Instr::New(Js::OpCode::LdElemI_A, ldElemDstOpnd, nthArgument, func);
1956719570
callInstr->InsertBefore(ldElem);
1956819571
GenerateFastStackArgumentsLdElemI(ldElem);
@@ -19586,6 +19589,7 @@ Lowerer::GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsIn
1958619589

1958719590
nthArgument = IR::IndirOpnd::New(stackArgs, ldLenDstOpnd, TyMachReg, func);
1958819591
ldElemDstOpnd = IR::RegOpnd::New(TyMachReg,func);
19592+
const IR::AutoReuseOpnd autoReuseldElemDstOpnd2(ldElemDstOpnd, func);
1958919593
ldElem = IR::Instr::New(Js::OpCode::LdElemI_A, ldElemDstOpnd, nthArgument, func);
1959019594
callInstr->InsertBefore(ldElem);
1959119595
GenerateFastStackArgumentsLdElemI(ldElem);
@@ -22531,6 +22535,7 @@ Lowerer::GenerateFastCmTypeOf(IR::Instr *compare, IR::RegOpnd *object, IR::IntCo
2253122535
else // Other primitive types don't need helper
2253222536
{
2253322537
typeOf->Remove();
22538+
dst = compare->UnlinkDst()->AsRegOpnd();
2253422539
compare->Remove();
2253522540
*pfNoLower = true;
2253622541
}

lib/Backend/LowerMDShared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9409,7 +9409,7 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
94099409

94109410
void LowererMD::GenerateFastInlineBuiltInMathAbs(IR::Instr* inlineInstr)
94119411
{
9412-
IR::Opnd* src = inlineInstr->GetSrc1();
9412+
IR::Opnd* src = inlineInstr->GetSrc1()->Copy(this->m_func);
94139413
IR::Opnd* dst = inlineInstr->UnlinkDst();
94149414
Assert(src);
94159415
IR::Instr* tmpInstr;

lib/Backend/amd64/Reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define RA_BYTEABLE 0x8
1212

1313

14-
enum RegNum {
14+
enum RegNum : BYTE {
1515
#define REGDAT(Name, Listing, Encode, Type, BitVec) Reg ## Name,
1616
#include "RegList.h"
1717
RegNumCount,

0 commit comments

Comments
 (0)