Skip to content

Commit

Permalink
Remove Simd.js code from ChakraCore - Part 1 (ifdef out)
Browse files Browse the repository at this point in the history
  • Loading branch information
agarwal-sandeep committed Jul 7, 2017
1 parent f9979fb commit 8789706
Show file tree
Hide file tree
Showing 92 changed files with 484 additions and 138 deletions.
8 changes: 8 additions & 0 deletions lib/Backend/BackwardPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,7 @@ BackwardPass::ProcessBailOutCopyProps(BailOutInfo * bailOutInfo, BVSparse<JitAre
float64StackSym = stackSym->GetFloat64EquivSym(nullptr);
Assert(float64StackSym);
}
#ifdef ENABLE_SIMDJS
// SIMD_JS
else if (bailOutInfo->liveSimd128F4Syms->Test(symId))
{
Expand All @@ -1787,6 +1788,7 @@ BackwardPass::ProcessBailOutCopyProps(BailOutInfo * bailOutInfo, BVSparse<JitAre
{
simd128StackSym = stackSym->GetSimd128I4EquivSym(nullptr);
}
#endif
else
{
Assert(bailOutInfo->liveVarSyms->Test(symId));
Expand Down Expand Up @@ -2345,17 +2347,21 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
// ToVars that can more easily be eliminated due to being dead stores.

#if DBG
#ifdef ENABLE_SIMDJS
// SIMD_JS
// Simd128 syms should be live in at most one form
tempBv->And(bailOutInfo->liveSimd128F4Syms, bailOutInfo->liveSimd128I4Syms);
#endif
Assert(tempBv->IsEmpty());

// Verify that all syms to restore are live in some fashion
tempBv->Minus(byteCodeUpwardExposedUsed, bailOutInfo->liveVarSyms);
tempBv->Minus(bailOutInfo->liveLosslessInt32Syms);
tempBv->Minus(bailOutInfo->liveFloat64Syms);
#ifdef ENABLE_SIMDJS
tempBv->Minus(bailOutInfo->liveSimd128F4Syms);
tempBv->Minus(bailOutInfo->liveSimd128I4Syms);
#endif
Assert(tempBv->IsEmpty());
#endif

Expand Down Expand Up @@ -2426,6 +2432,7 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
}
NEXT_BITSET_IN_SPARSEBV;

#ifdef ENABLE_SIMDJS
// SIMD_JS
tempBv->Or(bailOutInfo->liveSimd128F4Syms, bailOutInfo->liveSimd128I4Syms);
tempBv->And(byteCodeUpwardExposedUsed);
Expand All @@ -2447,6 +2454,7 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
byteCodeUpwardExposedUsed->Set(simd128Sym->m_id);
}
NEXT_BITSET_IN_SPARSEBV;
#endif
}
// Var
// Any remaining syms to restore will be restored from their var versions
Expand Down
42 changes: 41 additions & 1 deletion lib/Backend/BailOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ void BailOutRecord::DumpArgOffsets(uint count, int* offsets, int argOutSlotStart
bool isFloat64 = this->argOutOffsetInfo->argOutFloat64Syms->Test(argOutSlotStart + i) != 0;
bool isInt32 = this->argOutOffsetInfo->argOutLosslessInt32Syms->Test(argOutSlotStart + i) != 0;

#ifdef ENABLE_SIMDJS
// SIMD_JS
// Simd128 reside in Float64 regs
isFloat64 |= this->argOutOffsetInfo->argOutSimd128F4Syms->Test(argOutSlotStart + i) != 0;
Expand All @@ -405,7 +406,7 @@ void BailOutRecord::DumpArgOffsets(uint count, int* offsets, int argOutSlotStart
isFloat64 |= this->argOutOffsetInfo->argOutSimd128B4Syms->Test(argOutSlotStart + i) != 0;
isFloat64 |= this->argOutOffsetInfo->argOutSimd128B8Syms->Test(argOutSlotStart + i) != 0;
isFloat64 |= this->argOutOffsetInfo->argOutSimd128B16Syms->Test(argOutSlotStart + i) != 0;

#endif
Assert(!isFloat64 || !isInt32);

Output::Print(_u("%s #%3d: "), name, i + regSlotOffset);
Expand All @@ -424,6 +425,7 @@ void BailOutRecord::DumpLocalOffsets(uint count, int argOutSlotStart)
bool isFloat64 = row->isFloat;
bool isInt32 = row->isInt;

#ifdef ENABLE_SIMDJS
// SIMD_JS
// Simd values are in float64 regs
isFloat64 = isFloat64 || row->isSimd128F4;
Expand All @@ -436,6 +438,7 @@ void BailOutRecord::DumpLocalOffsets(uint count, int argOutSlotStart)
isFloat64 = isFloat64 || row->isSimd128B4;
isFloat64 = isFloat64 || row->isSimd128B8;
isFloat64 = isFloat64 || row->isSimd128B16;
#endif

Assert(!isFloat64 || !isInt32);

Expand Down Expand Up @@ -726,6 +729,7 @@ BailOutRecord::IsOffsetNativeIntOrFloat(uint offsetIndex, int argOutSlotStart, b
{
bool isFloat64 = this->argOutOffsetInfo->argOutFloat64Syms->Test(argOutSlotStart + offsetIndex) != 0;
bool isInt32 = this->argOutOffsetInfo->argOutLosslessInt32Syms->Test(argOutSlotStart + offsetIndex) != 0;
#ifdef ENABLE_SIMDJS
// SIMD_JS
bool isSimd128F4 = this->argOutOffsetInfo->argOutSimd128F4Syms->Test(argOutSlotStart + offsetIndex) != 0;
bool isSimd128I4 = this->argOutOffsetInfo->argOutSimd128I4Syms->Test(argOutSlotStart + offsetIndex) != 0;
Expand All @@ -737,13 +741,19 @@ BailOutRecord::IsOffsetNativeIntOrFloat(uint offsetIndex, int argOutSlotStart, b
bool isSimd128B4 = this->argOutOffsetInfo->argOutSimd128B4Syms->Test(argOutSlotStart + offsetIndex) != 0;
bool isSimd128B8 = this->argOutOffsetInfo->argOutSimd128B8Syms->Test(argOutSlotStart + offsetIndex) != 0;
bool isSimd128B16 = this->argOutOffsetInfo->argOutSimd128B16Syms->Test(argOutSlotStart + offsetIndex) != 0;
#endif

#ifdef ENABLE_SIMDJS
Assert(!isFloat64 || !isInt32 ||
!isSimd128F4 || !isSimd128I4 || !isSimd128I8 || !isSimd128I16 || !
!isSimd128U4 || !isSimd128U8 || !isSimd128U16);
#else
Assert(!isFloat64 || !isInt32);
#endif

*pIsFloat64 = isFloat64;
*pIsInt32 = isInt32;
#ifdef ENABLE_SIMDJS
*pIsSimd128F4 = isSimd128F4;
*pIsSimd128I4 = isSimd128I4;
*pIsSimd128I8 = isSimd128I8;
Expand All @@ -754,6 +764,19 @@ BailOutRecord::IsOffsetNativeIntOrFloat(uint offsetIndex, int argOutSlotStart, b
*pIsSimd128B4 = isSimd128B4;
*pIsSimd128B8 = isSimd128B8;
*pIsSimd128B16 = isSimd128B16;
#else
*pIsSimd128F4 = false;
*pIsSimd128I4 = false;
*pIsSimd128I8 = false;
*pIsSimd128I16 = false;
*pIsSimd128U4 = false;
*pIsSimd128U8 = false;
*pIsSimd128U16 = false;
*pIsSimd128B4 = false;
*pIsSimd128B8 = false;
*pIsSimd128B16 = false;
#endif

}

void
Expand Down Expand Up @@ -924,6 +947,7 @@ BailOutRecord::RestoreValue(IR::BailOutKind bailOutKind, Js::JavascriptCallStack
value = Js::JavascriptNumber::ToVar(int32Value, scriptContext);
BAILOUT_VERBOSE_TRACE(newInstance->function->GetFunctionBody(), bailOutKind, _u(", value: %10d (ToVar: 0x%p)"), int32Value, value);
}
#ifdef ENABLE_SIMDJS
// SIMD_JS
else if (isSimd128F4)
{
Expand Down Expand Up @@ -975,6 +999,7 @@ BailOutRecord::RestoreValue(IR::BailOutKind bailOutKind, Js::JavascriptCallStack
Assert(!value);
value = Js::JavascriptSIMDBool8x16::New(&simdValue, scriptContext);
}
#endif // #ifdef ENABLE_SIMDJS
else
{
BAILOUT_VERBOSE_TRACE(newInstance->function->GetFunctionBody(), bailOutKind, _u(", value: 0x%p"), value);
Expand Down Expand Up @@ -1005,10 +1030,19 @@ BailOutRecord::RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStac
{
globalBailOutRecordTable->IterateGlobalBailOutRecordTableRows(m_bailOutRecordId, [=](GlobalBailOutRecordDataRow *row) {
Assert(row->offset != 0);
#ifdef ENABLE_SIMDJS
RestoreValue(bailOutKind, layout, values, scriptContext, fromLoopBody, registerSaves, newInstance, pArgumentsObject,
argoutRestoreAddress, row->regSlot, row->offset, true, row->isFloat, row->isInt, row->isSimd128F4,
row->isSimd128I4, row->isSimd128I8, row->isSimd128I16, row->isSimd128U4, row->isSimd128U8, row->isSimd128U16,
row->isSimd128B4, row->isSimd128B8, row->isSimd128B16);
#else
// https://github.com/Microsoft/ChakraCore/issues/3274
// Change signature of RestoreValue if WASM simd doesn't use this
RestoreValue(bailOutKind, layout, values, scriptContext, fromLoopBody, registerSaves, newInstance, pArgumentsObject,
argoutRestoreAddress, row->regSlot, row->offset, true, row->isFloat, row->isInt, false,
false, false, false, false, false, false,
false, false, false);
#endif
});
}
else
Expand Down Expand Up @@ -2899,6 +2933,8 @@ void GlobalBailOutRecordDataTable::AddOrUpdateRow(JitArenaAllocator *allocator,
if(rowToUpdate->offset == offset &&
rowToUpdate->isInt == (unsigned)isInt &&
rowToUpdate->isFloat == (unsigned)isFloat &&

#ifdef ENABLE_SIMDJS
// SIMD_JS
rowToUpdate->isSimd128F4 == (unsigned) isSimd128F4 &&
rowToUpdate->isSimd128I4 == (unsigned) isSimd128I4 &&
Expand All @@ -2910,6 +2946,7 @@ void GlobalBailOutRecordDataTable::AddOrUpdateRow(JitArenaAllocator *allocator,
rowToUpdate->isSimd128B4 == (unsigned) isSimd128B4 &&
rowToUpdate->isSimd128B8 == (unsigned) isSimd128B8 &&
rowToUpdate->isSimd128B16 == (unsigned) isSimd128B16 &&
#endif

rowToUpdate->end + 1 == bailOutRecordId)
{
Expand All @@ -2930,6 +2967,8 @@ void GlobalBailOutRecordDataTable::AddOrUpdateRow(JitArenaAllocator *allocator,
rowToInsert->offset = offset;
rowToInsert->isFloat = isFloat;
rowToInsert->isInt = isInt;

#ifdef ENABLE_SIMDJS
// SIMD_JS
rowToInsert->isSimd128F4 = isSimd128F4;
rowToInsert->isSimd128I4 = isSimd128I4;
Expand All @@ -2941,6 +2980,7 @@ void GlobalBailOutRecordDataTable::AddOrUpdateRow(JitArenaAllocator *allocator,
rowToInsert->isSimd128B4 = isSimd128B4 ;
rowToInsert->isSimd128B8 = isSimd128B8 ;
rowToInsert->isSimd128B16 = isSimd128B16;
#endif
rowToInsert->regSlot = regSlot;
*lastUpdatedRowIndex = length++;
}
17 changes: 14 additions & 3 deletions lib/Backend/BailOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ class BailOutInfo
bailOutOffset(bailOutOffset), bailOutFunc(bailOutFunc),
byteCodeUpwardExposedUsed(nullptr), polymorphicCacheIndex((uint)-1), startCallCount(0), startCallInfo(nullptr), bailOutInstr(nullptr),
totalOutParamCount(0), argOutSyms(nullptr), bailOutRecord(nullptr), wasCloned(false), isInvertedBranch(false), sharedBailOutKind(true), outParamInlinedArgSlot(nullptr),
liveVarSyms(nullptr), liveLosslessInt32Syms(nullptr),
liveFloat64Syms(nullptr), liveSimd128F4Syms(nullptr),
liveVarSyms(nullptr), liveLosslessInt32Syms(nullptr), liveFloat64Syms(nullptr),
#ifdef ENABLE_SIMDJS
liveSimd128F4Syms(nullptr),
liveSimd128I4Syms(nullptr), liveSimd128I8Syms(nullptr), liveSimd128I16Syms(nullptr),
liveSimd128U4Syms(nullptr), liveSimd128U8Syms(nullptr), liveSimd128U16Syms(nullptr),
liveSimd128B4Syms(nullptr), liveSimd128B8Syms(nullptr), liveSimd128B16Syms(nullptr),
liveSimd128D2Syms(nullptr), branchConditionOpnd(nullptr),
liveSimd128D2Syms(nullptr),
#endif
branchConditionOpnd(nullptr),
stackLiteralBailOutInfoCount(0), stackLiteralBailOutInfo(nullptr)
{
Assert(bailOutOffset != Js::Constants::NoByteCodeOffset);
Expand Down Expand Up @@ -101,6 +104,7 @@ class BailOutInfo
BVSparse<JitArenaAllocator> * liveLosslessInt32Syms; // These are only the live int32 syms that fully represent the var-equivalent sym's value (see GlobOpt::FillBailOutInfo)
BVSparse<JitArenaAllocator> * liveFloat64Syms;

#ifdef ENABLE_SIMDJS
// SIMD_JS
BVSparse<JitArenaAllocator> * liveSimd128F4Syms;
BVSparse<JitArenaAllocator> * liveSimd128I4Syms;
Expand All @@ -113,6 +117,7 @@ class BailOutInfo
BVSparse<JitArenaAllocator> * liveSimd128B8Syms;
BVSparse<JitArenaAllocator> * liveSimd128B16Syms;
BVSparse<JitArenaAllocator> * liveSimd128D2Syms;
#endif

int * outParamOffsets;

Expand Down Expand Up @@ -283,6 +288,7 @@ class BailOutRecord
{
BVFixed * argOutFloat64Syms; // Used for float-type-specialized ArgOut symbols. Index = [0 .. BailOutInfo::totalOutParamCount].
BVFixed * argOutLosslessInt32Syms; // Used for int-type-specialized ArgOut symbols (which are native int and for bailout we need tagged ints).
#ifdef ENABLE_SIMDJS
// SIMD_JS
BVFixed * argOutSimd128F4Syms;
BVFixed * argOutSimd128I4Syms;
Expand All @@ -294,6 +300,7 @@ class BailOutRecord
BVFixed * argOutSimd128B4Syms;
BVFixed * argOutSimd128B8Syms;
BVFixed * argOutSimd128B16Syms;
#endif
uint * startCallOutParamCounts;
int * outParamOffsets;
uint startCallCount;
Expand All @@ -303,6 +310,7 @@ class BailOutRecord
{
FixupNativeDataPointer(argOutFloat64Syms, chunkList);
FixupNativeDataPointer(argOutLosslessInt32Syms, chunkList);
#ifdef ENABLE_SIMDJS
FixupNativeDataPointer(argOutSimd128F4Syms, chunkList);
FixupNativeDataPointer(argOutSimd128I4Syms, chunkList);
FixupNativeDataPointer(argOutSimd128I8Syms, chunkList);
Expand All @@ -313,6 +321,7 @@ class BailOutRecord
FixupNativeDataPointer(argOutSimd128B4Syms, chunkList);
FixupNativeDataPointer(argOutSimd128B8Syms, chunkList);
FixupNativeDataPointer(argOutSimd128B16Syms, chunkList);
#endif

// special handling for startCallOutParamCounts and outParamOffsets, becuase it points to middle of the allocation
uint* startCallOutParamCountsStart = startCallOutParamCounts - startCallIndex;
Expand Down Expand Up @@ -440,6 +449,7 @@ struct GlobalBailOutRecordDataRow
unsigned regSlot : 30;
unsigned isFloat : 1;
unsigned isInt : 1;
#ifdef ENABLE_SIMDJS
// SIMD_JS
unsigned isSimd128F4 : 1;
unsigned isSimd128I4 : 1;
Expand All @@ -451,6 +461,7 @@ struct GlobalBailOutRecordDataRow
unsigned isSimd128U4 : 1;
unsigned isSimd128U8 : 1;
unsigned isSimd128U16 : 1;
#endif
};

struct GlobalBailOutRecordDataTable
Expand Down
4 changes: 3 additions & 1 deletion lib/Backend/BailOutKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ BAIL_OUT_KIND(BailOutForGeneratorYield, 0)
BAIL_OUT_KIND(BailOutOnException, 0)
BAIL_OUT_KIND(BailOutOnEarlyExit, 0)

#ifdef ENABLE_SIMDJS
// SIMD_JS
BAIL_OUT_KIND(BailOutSimd128F4Only, 0)
BAIL_OUT_KIND(BailOutSimd128I4Only, 0)
BAIL_OUT_KIND(BailOutSimd128I8Only, 0)
BAIL_OUT_KIND(BailOutSimd128I16Only, 0)
BAIL_OUT_KIND(BailOutSimd128I16Only, 0)
BAIL_OUT_KIND(BailOutSimd128U4Only, 0)
BAIL_OUT_KIND(BailOutSimd128U8Only, 0)
BAIL_OUT_KIND(BailOutSimd128U16Only, 0)
Expand All @@ -61,6 +62,7 @@ BAIL_OUT_KIND(BailOutSimd128B8Only, 0)
BAIL_OUT_KIND(BailOutSimd128B16Only, 0)
BAIL_OUT_KIND(BailOutSimd128D2Only, 0)
BAIL_OUT_KIND(BailOutNoSimdTypeSpec, 0)
#endif

BAIL_OUT_KIND(BailOutKindEnd, 0)

Expand Down
15 changes: 13 additions & 2 deletions lib/Backend/FlowGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4575,6 +4575,7 @@ BasicBlock::MergePredBlocksValueMaps(GlobOpt* globOpt)
}
} NEXT_BITSET_IN_SPARSEBV;

#ifdef ENABLE_SIMDJS
// SIMD_JS
// Simd128 type-spec syms
BVSparse<JitArenaAllocator> tempBv2(globOpt->tempAlloc);
Expand Down Expand Up @@ -4642,6 +4643,8 @@ BasicBlock::MergePredBlocksValueMaps(GlobOpt* globOpt)
Assert(UNREACHED);
}
} NEXT_BITSET_IN_SPARSEBV;
#endif

tempBv->ClearAll();
}

Expand All @@ -4658,9 +4661,11 @@ BasicBlock::MergePredBlocksValueMaps(GlobOpt* globOpt)
BVSparse<JitArenaAllocator> tempBv3(globOpt->tempAlloc);
BVSparse<JitArenaAllocator> tempBv4(globOpt->tempAlloc);

#ifdef ENABLE_SIMDJS
// SIMD_JS
BVSparse<JitArenaAllocator> simd128F4SymsToUnbox(globOpt->tempAlloc);
BVSparse<JitArenaAllocator> simd128I4SymsToUnbox(globOpt->tempAlloc);
#endif

FOREACH_PREDECESSOR_EDGE_EDITING(edge, this, iter)
{
Expand Down Expand Up @@ -4694,17 +4699,20 @@ BasicBlock::MergePredBlocksValueMaps(GlobOpt* globOpt)

bool symIVNeedsSpecializing = (symIV && !pred->globOptData.liveInt32Syms->Test(symIV->m_id) && !tempBv3.Test(symIV->m_id));

#ifdef ENABLE_SIMDJS
// SIMD_JS
simd128F4SymsToUnbox.Minus(blockData.liveSimd128F4Syms, pred->globOptData.liveSimd128F4Syms);
simd128I4SymsToUnbox.Minus(blockData.liveSimd128I4Syms, pred->globOptData.liveSimd128I4Syms);

#endif

if (!globOpt->tempBv->IsEmpty() ||
!tempBv2.IsEmpty() ||
!tempBv3.IsEmpty() ||
!tempBv4.IsEmpty() ||
#ifdef ENABLE_SIMDJS
!simd128F4SymsToUnbox.IsEmpty() ||
!simd128I4SymsToUnbox.IsEmpty() ||
#endif
symIVNeedsSpecializing ||
symsRequiringCompensationToMergedValueInfoMap.Count() != 0)
{
Expand Down Expand Up @@ -4770,6 +4778,7 @@ BasicBlock::MergePredBlocksValueMaps(GlobOpt* globOpt)
globOpt->InsertValueCompensation(pred, symsRequiringCompensationToMergedValueInfoMap);
}

#ifdef ENABLE_SIMDJS
// SIMD_JS
if (!simd128F4SymsToUnbox.IsEmpty())
{
Expand All @@ -4780,6 +4789,7 @@ BasicBlock::MergePredBlocksValueMaps(GlobOpt* globOpt)
{
globOpt->ToTypeSpec(&simd128I4SymsToUnbox, pred, TySimd128I4, IR::BailOutSimd128I4Only);
}
#endif
}
} NEXT_PREDECESSOR_EDGE_EDITING;

Expand Down Expand Up @@ -4834,13 +4844,14 @@ BasicBlock::MergePredBlocksValueMaps(GlobOpt* globOpt)
loop->float64SymsOnEntry = JitAnew(globOpt->alloc, BVSparse<JitArenaAllocator>, globOpt->alloc);
loop->float64SymsOnEntry->Copy(this->globOptData.liveFloat64Syms);

#ifdef ENABLE_SIMDJS
// SIMD_JS
loop->simd128F4SymsOnEntry = JitAnew(globOpt->alloc, BVSparse<JitArenaAllocator>, globOpt->alloc);
loop->simd128F4SymsOnEntry->Copy(this->globOptData.liveSimd128F4Syms);

loop->simd128I4SymsOnEntry = JitAnew(globOpt->alloc, BVSparse<JitArenaAllocator>, globOpt->alloc);
loop->simd128I4SymsOnEntry->Copy(this->globOptData.liveSimd128I4Syms);

#endif

loop->liveFieldsOnEntry = JitAnew(globOpt->alloc, BVSparse<JitArenaAllocator>, globOpt->alloc);
loop->liveFieldsOnEntry->Copy(this->globOptData.liveFields);
Expand Down
Loading

0 comments on commit 8789706

Please sign in to comment.