Diff
Modified: trunk/Source/_javascript_Core/CMakeLists.txt (293145 => 293146)
--- trunk/Source/_javascript_Core/CMakeLists.txt 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/CMakeLists.txt 2022-04-21 05:28:31 UTC (rev 293146)
@@ -867,6 +867,7 @@
jit/RegisterAtOffsetList.h
jit/RegisterMap.h
jit/RegisterSet.h
+ jit/ScratchRegisterAllocator.h
jit/Snippet.h
jit/SnippetParams.h
jit/SnippetReg.h
@@ -873,7 +874,6 @@
jit/SnippetSlowPathCalls.h
jit/SpillRegistersMode.h
jit/TagRegistersMode.h
- jit/TempRegisterSet.h
jit/ThunkGenerator.h
llint/LLIntOpcode.h
Modified: trunk/Source/_javascript_Core/ChangeLog (293145 => 293146)
--- trunk/Source/_javascript_Core/ChangeLog 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/ChangeLog 2022-04-21 05:28:31 UTC (rev 293146)
@@ -1,5 +1,34 @@
2022-04-20 Yusuke Suzuki <[email protected]>
+ [JSC] Remove TempRegisterSet
+ https://bugs.webkit.org/show_bug.cgi?id=239578
+
+ Reviewed by Mark Lam.
+
+ We can always use RegisterSet. TempRegisterSet can save several bytes, but we have no code using TempRegisterSet in
+ heap-allocated class, so this does not make sense anymore. Instead of TempRegisterSet, we should consistently use
+ ScratchRegisterAllocator.
+
+ * CMakeLists.txt:
+ * _javascript_Core.xcodeproj/project.pbxproj:
+ * Sources.txt:
+ * jit/AssemblyHelpers.cpp:
+ (JSC::AssemblyHelpers::copyLLIntBaselineCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer):
+ * jit/AssemblyHelpers.h:
+ (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer):
+ (JSC::AssemblyHelpers::copyLLIntBaselineCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): Deleted.
+ * jit/RegisterSet.h:
+ * jit/ScratchRegisterAllocator.cpp:
+ (JSC::ScratchRegisterAllocator::lock):
+ (JSC::ScratchRegisterAllocator::allocateScratch):
+ (JSC::ScratchRegisterAllocator::preserveReusedRegistersByPushing):
+ (JSC::ScratchRegisterAllocator::restoreReusedRegistersByPopping):
+ * jit/ScratchRegisterAllocator.h:
+ * jit/TempRegisterSet.cpp: Removed.
+ * jit/TempRegisterSet.h: Removed.
+
+2022-04-20 Yusuke Suzuki <[email protected]>
+
Fix GPRInfo inconsistency in unlinked DFG bringup
https://bugs.webkit.org/show_bug.cgi?id=239573
Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (293145 => 293146)
--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2022-04-21 05:28:31 UTC (rev 293146)
@@ -186,7 +186,6 @@
0F24E54317EA9F5900ABB217 /* FPRInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F24E53E17EA9F5900ABB217 /* FPRInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F24E54417EA9F5900ABB217 /* GPRInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F24E53F17EA9F5900ABB217 /* GPRInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F24E54D17EE274900ABB217 /* JITOperations.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F24E54617EE274900ABB217 /* JITOperations.h */; settings = {ATTRIBUTES = (Private, ); }; };
- 0F24E54F17EE274900ABB217 /* TempRegisterSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F24E54817EE274900ABB217 /* TempRegisterSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F24E55217EE274900ABB217 /* ScratchRegisterAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F24E54B17EE274900ABB217 /* ScratchRegisterAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F24E55617F0B71C00ABB217 /* InlineCallFrameSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F24E55417F0B71C00ABB217 /* InlineCallFrameSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F256C361627B0AD007F2783 /* DFGCallArrayAllocatorSlowPathGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F256C341627B0AA007F2783 /* DFGCallArrayAllocatorSlowPathGenerator.h */; };
@@ -2602,7 +2601,6 @@
0F24E53F17EA9F5900ABB217 /* GPRInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPRInfo.h; sourceTree = "<group>"; };
0F24E54517EE274900ABB217 /* JITOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITOperations.cpp; sourceTree = "<group>"; };
0F24E54617EE274900ABB217 /* JITOperations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITOperations.h; sourceTree = "<group>"; };
- 0F24E54817EE274900ABB217 /* TempRegisterSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TempRegisterSet.h; sourceTree = "<group>"; };
0F24E54B17EE274900ABB217 /* ScratchRegisterAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScratchRegisterAllocator.h; sourceTree = "<group>"; };
0F24E55317F0B71C00ABB217 /* InlineCallFrameSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineCallFrameSet.cpp; sourceTree = "<group>"; };
0F24E55417F0B71C00ABB217 /* InlineCallFrameSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineCallFrameSet.h; sourceTree = "<group>"; };
@@ -3191,7 +3189,6 @@
0FC20CB718556A3500C9E954 /* DFGSSALoweringPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGSSALoweringPhase.cpp; path = dfg/DFGSSALoweringPhase.cpp; sourceTree = "<group>"; };
0FC20CB818556A3500C9E954 /* DFGSSALoweringPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGSSALoweringPhase.h; path = dfg/DFGSSALoweringPhase.h; sourceTree = "<group>"; };
0FC314101814559100033232 /* RegisterSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegisterSet.h; sourceTree = "<group>"; };
- 0FC314111814559100033232 /* TempRegisterSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TempRegisterSet.cpp; sourceTree = "<group>"; };
0FC3141418146D7000033232 /* RegisterSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RegisterSet.cpp; sourceTree = "<group>"; };
0FC3CCF519ADA410006AC72A /* DFGBlockMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGBlockMap.h; path = dfg/DFGBlockMap.h; sourceTree = "<group>"; };
0FC3CCF619ADA410006AC72A /* DFGBlockMapInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGBlockMapInlines.h; path = dfg/DFGBlockMapInlines.h; sourceTree = "<group>"; };
@@ -6672,8 +6669,6 @@
A7FF647A18C52E8500B55307 /* SpillRegistersMode.h */,
DC7997811CDE9F9E004D4A09 /* TagRegistersMode.cpp */,
DC7997821CDE9F9E004D4A09 /* TagRegistersMode.h */,
- 0FC314111814559100033232 /* TempRegisterSet.cpp */,
- 0F24E54817EE274900ABB217 /* TempRegisterSet.h */,
0F572D4D16879FDB00E57FBD /* ThunkGenerator.h */,
A7386552118697B400540279 /* ThunkGenerators.cpp */,
A7386553118697B400540279 /* ThunkGenerators.h */,
@@ -11162,7 +11157,6 @@
E30E8A5626DE2E4800DA4915 /* TemporalTimeZone.h in Headers */,
E30E8A5726DE2E4800DA4915 /* TemporalTimeZoneConstructor.h in Headers */,
E30E8A5426DE2E4800DA4915 /* TemporalTimeZonePrototype.h in Headers */,
- 0F24E54F17EE274900ABB217 /* TempRegisterSet.h in Headers */,
0F44A7B420BF68D90022B171 /* TerminatedCodeOrigin.h in Headers */,
0FA2C17C17D7CF84009D015F /* TestRunnerUtils.h in Headers */,
FE3422121D6B81C30032BE88 /* ThrowScope.h in Headers */,
Modified: trunk/Source/_javascript_Core/Sources.txt (293145 => 293146)
--- trunk/Source/_javascript_Core/Sources.txt 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/Sources.txt 2022-04-21 05:28:31 UTC (rev 293146)
@@ -674,7 +674,6 @@
jit/SetupVarargsFrame.cpp
jit/SlowPathCall.cpp
jit/TagRegistersMode.cpp
-jit/TempRegisterSet.cpp
jit/ThunkGenerators.cpp
llint/LLIntCLoop.cpp
Modified: trunk/Source/_javascript_Core/jit/AssemblyHelpers.cpp (293145 => 293146)
--- trunk/Source/_javascript_Core/jit/AssemblyHelpers.cpp 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/jit/AssemblyHelpers.cpp 2022-04-21 05:28:31 UTC (rev 293146)
@@ -1296,15 +1296,17 @@
spooler.finalizeFPR();
}
-void AssemblyHelpers::copyLLIntBaselineCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer(EntryFrame*& topEntryFrame, const TempRegisterSet& usedRegisters)
+void AssemblyHelpers::copyLLIntBaselineCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer(EntryFrame*& topEntryFrame, const RegisterSet& usedRegisters)
{
#if NUMBER_OF_CALLEE_SAVES_REGISTERS > 0
// Copy saved calleeSaves on stack or unsaved calleeSaves in register to vm calleeSave buffer
- GPRReg destBufferGPR = usedRegisters.getFreeGPR(0);
- GPRReg temp1 = usedRegisters.getFreeGPR(1);
- FPRReg fpTemp1 = usedRegisters.getFreeFPR(0);
- GPRReg temp2 = usedRegisters.getFreeGPR(2);
- FPRReg fpTemp2 = usedRegisters.getFreeFPR(1);
+ ScratchRegisterAllocator allocator(usedRegisters);
+ GPRReg destBufferGPR = allocator.allocateScratchGPR();
+ GPRReg temp1 = allocator.allocateScratchGPR();
+ FPRReg fpTemp1 = allocator.allocateScratchFPR();
+ GPRReg temp2 = allocator.allocateScratchGPR();
+ FPRReg fpTemp2 = allocator.allocateScratchFPR();
+ RELEASE_ASSERT(!allocator.didReuseRegisters());
loadPtr(&topEntryFrame, destBufferGPR);
addPtr(TrustedImm32(EntryFrame::calleeSaveRegistersBufferOffset()), destBufferGPR);
Modified: trunk/Source/_javascript_Core/jit/AssemblyHelpers.h (293145 => 293146)
--- trunk/Source/_javascript_Core/jit/AssemblyHelpers.h 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/jit/AssemblyHelpers.h 2022-04-21 05:28:31 UTC (rev 293146)
@@ -40,6 +40,7 @@
#include "MarkedSpace.h"
#include "RegisterAtOffsetList.h"
#include "RegisterSet.h"
+#include "ScratchRegisterAllocator.h"
#include "StackAlignment.h"
#include "TagRegistersMode.h"
#include "TypeofType.h"
@@ -396,8 +397,9 @@
void copyCalleeSavesToEntryFrameCalleeSavesBuffer(EntryFrame*& topEntryFrame)
{
#if NUMBER_OF_CALLEE_SAVES_REGISTERS > 0
- const TempRegisterSet& usedRegisters = { RegisterSet::stubUnavailableRegisters() };
- GPRReg temp1 = usedRegisters.getFreeGPR(0);
+ ScratchRegisterAllocator allocator(RegisterSet::stubUnavailableRegisters());
+ GPRReg temp1 = allocator.allocateScratchGPR();
+ RELEASE_ASSERT(!allocator.didReuseRegisters());
copyCalleeSavesToEntryFrameCalleeSavesBuffer(topEntryFrame, temp1);
#else
UNUSED_PARAM(topEntryFrame);
@@ -418,7 +420,7 @@
void restoreCalleeSavesFromVMEntryFrameCalleeSavesBuffer(GPRReg vmGPR, GPRReg scratchGPR);
void restoreCalleeSavesFromVMEntryFrameCalleeSavesBufferImpl(GPRReg entryFrame, const RegisterSet& skipList);
- void copyLLIntBaselineCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer(EntryFrame*&, const TempRegisterSet& usedRegisters = { RegisterSet::stubUnavailableRegisters() });
+ void copyLLIntBaselineCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer(EntryFrame*&, const RegisterSet& usedRegisters = RegisterSet::stubUnavailableRegisters());
void emitMaterializeTagCheckRegisters()
{
Modified: trunk/Source/_javascript_Core/jit/RegisterSet.h (293145 => 293146)
--- trunk/Source/_javascript_Core/jit/RegisterSet.h 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/jit/RegisterSet.h 2022-04-21 05:28:31 UTC (rev 293146)
@@ -30,7 +30,6 @@
#include "GPRInfo.h"
#include "MacroAssembler.h"
#include "Reg.h"
-#include "TempRegisterSet.h"
#include <wtf/Bitmap.h>
namespace JSC {
Modified: trunk/Source/_javascript_Core/jit/ScratchRegisterAllocator.cpp (293145 => 293146)
--- trunk/Source/_javascript_Core/jit/ScratchRegisterAllocator.cpp 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/jit/ScratchRegisterAllocator.cpp 2022-04-21 05:28:31 UTC (rev 293146)
@@ -46,10 +46,7 @@
{
if (reg == InvalidGPRReg)
return;
- unsigned index = GPRInfo::toIndex(reg);
- if (index == GPRInfo::InvalidIndex)
- return;
- m_lockedRegisters.setGPRByIndex(index);
+ m_lockedRegisters.set(reg);
}
void ScratchRegisterAllocator::lock(FPRReg reg)
@@ -56,10 +53,7 @@
{
if (reg == InvalidFPRReg)
return;
- unsigned index = FPRInfo::toIndex(reg);
- if (index == FPRInfo::InvalidIndex)
- return;
- m_lockedRegisters.setFPRByIndex(index);
+ m_lockedRegisters.set(reg);
}
void ScratchRegisterAllocator::lock(JSValueRegs regs)
@@ -73,7 +67,7 @@
{
// First try to allocate a register that is totally free.
for (unsigned i = 0; i < BankInfo::numberOfRegisters; ++i) {
- typename BankInfo::RegisterType reg = BankInfo::toRegister(i);
+ auto reg = BankInfo::toRegister(i);
if (!m_lockedRegisters.get(reg)
&& !m_usedRegisters.get(reg)
&& !m_scratchRegisters.get(reg)) {
@@ -85,7 +79,7 @@
// Since that failed, try to allocate a register that is not yet
// locked or used for scratch.
for (unsigned i = 0; i < BankInfo::numberOfRegisters; ++i) {
- typename BankInfo::RegisterType reg = BankInfo::toRegister(i);
+ auto reg = BankInfo::toRegister(i);
if (!m_lockedRegisters.get(reg) && !m_scratchRegisters.get(reg)) {
m_scratchRegisters.set(reg);
m_numberOfReusedRegisters++;
@@ -110,12 +104,14 @@
RegisterSet registersToSpill;
for (unsigned i = 0; i < FPRInfo::numberOfRegisters; ++i) {
FPRReg reg = FPRInfo::toRegister(i);
- if (m_scratchRegisters.getFPRByIndex(i) && m_usedRegisters.get(reg))
+ ASSERT(reg != InvalidFPRReg);
+ if (m_scratchRegisters.get(reg) && m_usedRegisters.get(reg))
registersToSpill.set(reg);
}
for (unsigned i = 0; i < GPRInfo::numberOfRegisters; ++i) {
GPRReg reg = GPRInfo::toRegister(i);
- if (m_scratchRegisters.getGPRByIndex(i) && m_usedRegisters.get(reg))
+ ASSERT(reg != InvalidGPRReg);
+ if (m_scratchRegisters.get(reg) && m_usedRegisters.get(reg))
registersToSpill.set(reg);
}
@@ -134,12 +130,14 @@
RegisterSet registersToFill;
for (unsigned i = GPRInfo::numberOfRegisters; i--;) {
GPRReg reg = GPRInfo::toRegister(i);
- if (m_scratchRegisters.getGPRByIndex(i) && m_usedRegisters.get(reg))
+ ASSERT(reg != InvalidGPRReg);
+ if (m_scratchRegisters.get(reg) && m_usedRegisters.get(reg))
registersToFill.set(reg);
}
for (unsigned i = FPRInfo::numberOfRegisters; i--;) {
FPRReg reg = FPRInfo::toRegister(i);
- if (m_scratchRegisters.getFPRByIndex(i) && m_usedRegisters.get(reg))
+ ASSERT(reg != InvalidFPRReg);
+ if (m_scratchRegisters.get(reg) && m_usedRegisters.get(reg))
registersToFill.set(reg);
}
Modified: trunk/Source/_javascript_Core/jit/ScratchRegisterAllocator.h (293145 => 293146)
--- trunk/Source/_javascript_Core/jit/ScratchRegisterAllocator.h 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/jit/ScratchRegisterAllocator.h 2022-04-21 05:28:31 UTC (rev 293146)
@@ -28,7 +28,6 @@
#if ENABLE(JIT)
#include "RegisterSet.h"
-#include "TempRegisterSet.h"
namespace JSC {
@@ -96,8 +95,8 @@
private:
RegisterSet m_usedRegisters;
- TempRegisterSet m_lockedRegisters;
- TempRegisterSet m_scratchRegisters;
+ RegisterSet m_lockedRegisters;
+ RegisterSet m_scratchRegisters;
unsigned m_numberOfReusedRegisters;
};
Deleted: trunk/Source/_javascript_Core/jit/TempRegisterSet.cpp (293145 => 293146)
--- trunk/Source/_javascript_Core/jit/TempRegisterSet.cpp 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/jit/TempRegisterSet.cpp 2022-04-21 05:28:31 UTC (rev 293146)
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "TempRegisterSet.h"
-
-#if ENABLE(ASSEMBLER)
-
-#include "RegisterSet.h"
-
-namespace JSC {
-
-TempRegisterSet::TempRegisterSet(const RegisterSet& other)
-{
- clearAll();
-
- for (unsigned i = GPRInfo::numberOfRegisters; i--;) {
- GPRReg reg = GPRInfo::toRegister(i);
- if (other.get(reg))
- set(reg);
- }
- for (unsigned i = FPRInfo::numberOfRegisters; i--;) {
- FPRReg reg = FPRInfo::toRegister(i);
- if (other.get(reg))
- set(reg);
- }
-}
-
-} // namespace JSC
-
-#endif // ENABLE(ASSEMBLER)
Deleted: trunk/Source/_javascript_Core/jit/TempRegisterSet.h (293145 => 293146)
--- trunk/Source/_javascript_Core/jit/TempRegisterSet.h 2022-04-21 04:51:39 UTC (rev 293145)
+++ trunk/Source/_javascript_Core/jit/TempRegisterSet.h 2022-04-21 05:28:31 UTC (rev 293146)
@@ -1,219 +0,0 @@
-/*
- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(ASSEMBLER)
-
-#include "FPRInfo.h"
-#include "GPRInfo.h"
-
-namespace JSC {
-
-class RegisterSet;
-
-class TempRegisterSet {
-public:
- TempRegisterSet()
- {
- clearAll();
- }
-
- TempRegisterSet(const RegisterSet&);
-
- void set(GPRReg reg)
- {
- setBit(GPRInfo::toIndex(reg));
- }
-
- void set(JSValueRegs regs)
- {
- if (regs.tagGPR() != InvalidGPRReg)
- set(regs.tagGPR());
- set(regs.payloadGPR());
- }
-
- void setGPRByIndex(unsigned index)
- {
- ASSERT(index < GPRInfo::numberOfRegisters);
- setBit(index);
- }
-
- void clear(GPRReg reg)
- {
- clearBit(GPRInfo::toIndex(reg));
- }
-
- bool get(GPRReg reg) const
- {
- return getBit(GPRInfo::toIndex(reg));
- }
-
- bool getGPRByIndex(unsigned index) const
- {
- ASSERT(index < GPRInfo::numberOfRegisters);
- return getBit(index);
- }
-
- // Return the index'th free GPR.
- GPRReg getFreeGPR(unsigned index = 0) const
- {
- for (unsigned i = GPRInfo::numberOfRegisters; i--;) {
- if (!getGPRByIndex(i) && !index--)
- return GPRInfo::toRegister(i);
- }
- return InvalidGPRReg;
- }
-
- void set(FPRReg reg)
- {
- setBit(GPRInfo::numberOfRegisters + FPRInfo::toIndex(reg));
- }
-
- void setFPRByIndex(unsigned index)
- {
- ASSERT(index < FPRInfo::numberOfRegisters);
- setBit(GPRInfo::numberOfRegisters + index);
- }
-
- void clear(FPRReg reg)
- {
- clearBit(GPRInfo::numberOfRegisters + FPRInfo::toIndex(reg));
- }
-
- bool get(FPRReg reg) const
- {
- return getBit(GPRInfo::numberOfRegisters + FPRInfo::toIndex(reg));
- }
-
- bool getFPRByIndex(unsigned index) const
- {
- ASSERT(index < FPRInfo::numberOfRegisters);
- return getBit(GPRInfo::numberOfRegisters + index);
- }
-
- // Return the index'th free FPR.
- FPRReg getFreeFPR(unsigned index = 0) const
- {
- for (unsigned i = FPRInfo::numberOfRegisters; i--;) {
- if (!getFPRByIndex(i) && !index--)
- return FPRInfo::toRegister(i);
- }
- return InvalidFPRReg;
- }
-
- template<typename BankInfo>
- void setByIndex(unsigned index)
- {
- set(BankInfo::toRegister(index));
- }
-
- template<typename BankInfo>
- bool getByIndex(unsigned index)
- {
- return get(BankInfo::toRegister(index));
- }
-
- unsigned numberOfSetGPRs() const
- {
- unsigned result = 0;
- for (unsigned i = GPRInfo::numberOfRegisters; i--;) {
- if (!getBit(i))
- continue;
- result++;
- }
- return result;
- }
-
- unsigned numberOfSetFPRs() const
- {
- unsigned result = 0;
- for (unsigned i = FPRInfo::numberOfRegisters; i--;) {
- if (!getBit(GPRInfo::numberOfRegisters + i))
- continue;
- result++;
- }
- return result;
- }
-
- unsigned numberOfSetRegisters() const
- {
- unsigned result = 0;
- for (unsigned i = totalNumberOfRegisters; i--;) {
- if (!getBit(i))
- continue;
- result++;
- }
- return result;
- }
-
-private:
- void clearAll()
- {
- for (unsigned i = numberOfBytesInTempRegisterSet; i--;)
- m_set[i] = 0;
- }
-
- void setBit(unsigned i)
- {
- ASSERT(i < totalNumberOfRegisters);
- m_set[i >> 3] |= (1 << (i & 7));
- }
-
- void clearBit(unsigned i)
- {
- ASSERT(i < totalNumberOfRegisters);
- m_set[i >> 3] &= ~(1 << (i & 7));
- }
-
- bool getBit(unsigned i) const
- {
- ASSERT(i < totalNumberOfRegisters);
- return !!(m_set[i >> 3] & (1 << (i & 7)));
- }
-
- static constexpr unsigned totalNumberOfRegisters =
- GPRInfo::numberOfRegisters + FPRInfo::numberOfRegisters;
-
- static constexpr unsigned numberOfBytesInTempRegisterSet =
- (totalNumberOfRegisters + 7) >> 3;
-
- uint8_t m_set[numberOfBytesInTempRegisterSet];
-};
-
-} // namespace JSC
-
-#else // ENABLE(ASSEMBLER) -> so if JIT is disabled
-
-namespace JSC {
-
-// Define TempRegisterSet to something, to make it easier to refer to this type in code that
-// make be compiled when the JIT is disabled.
-
-struct TempRegisterSet { };
-
-} // namespace JSC
-
-#endif // ENABLE(ASSEMBLER)