[JSC] Move generic data structures out of B3
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Aug 2016 19:35:41 +0000 (19:35 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Aug 2016 19:35:41 +0000 (19:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161155

Reviewed by Saam Barati.

Source/JavaScriptCore:

Move B3's good generic data structures to WTF.
They can be used for the other kind of basic blocks and nodes.
For example, the generator patch[1] will make BytecodeBasicBlock usable with these structures.

[1]: https://bugs.webkit.org/show_bug.cgi?id=152723

* JavaScriptCore.xcodeproj/project.pbxproj:
* b3/B3BasicBlockUtils.h:
* b3/B3BlockWorklist.h:
* b3/B3CFG.h:
* b3/B3DuplicateTails.cpp:
* b3/B3FixSSA.cpp:
* b3/B3FixSSA.h:
* b3/B3IndexMap.h:
(JSC::B3::IndexMap::IndexMap): Deleted.
(JSC::B3::IndexMap::resize): Deleted.
(JSC::B3::IndexMap::clear): Deleted.
(JSC::B3::IndexMap::size): Deleted.
(JSC::B3::IndexMap::operator[]): Deleted.
* b3/B3IndexSet.h:
(JSC::B3::IndexSet::IndexSet): Deleted.
(JSC::B3::IndexSet::add): Deleted.
(JSC::B3::IndexSet::addAll): Deleted.
(JSC::B3::IndexSet::remove): Deleted.
(JSC::B3::IndexSet::contains): Deleted.
(JSC::B3::IndexSet::size): Deleted.
(JSC::B3::IndexSet::isEmpty): Deleted.
(JSC::B3::IndexSet::Iterable::Iterable): Deleted.
(JSC::B3::IndexSet::Iterable::iterator::iterator): Deleted.
(JSC::B3::IndexSet::Iterable::iterator::operator*): Deleted.
(JSC::B3::IndexSet::Iterable::iterator::operator++): Deleted.
(JSC::B3::IndexSet::Iterable::iterator::operator==): Deleted.
(JSC::B3::IndexSet::Iterable::iterator::operator!=): Deleted.
(JSC::B3::IndexSet::Iterable::begin): Deleted.
(JSC::B3::IndexSet::Iterable::end): Deleted.
(JSC::B3::IndexSet::values): Deleted.
(JSC::B3::IndexSet::indices): Deleted.
(JSC::B3::IndexSet::dump): Deleted.
* b3/B3LowerToAir.cpp:
* b3/B3PhiChildren.h:
* b3/B3Procedure.h:
(JSC::B3::Procedure::iterator::iterator): Deleted.
(JSC::B3::Procedure::iterator::operator*): Deleted.
(JSC::B3::Procedure::iterator::operator++): Deleted.
(JSC::B3::Procedure::iterator::operator==): Deleted.
(JSC::B3::Procedure::iterator::operator!=): Deleted.
(JSC::B3::Procedure::iterator::findNext): Deleted.
* b3/B3ReduceDoubleToFloat.cpp:
* b3/B3ReduceStrength.cpp:
* b3/B3SSACalculator.h:
* b3/B3UseCounts.h:
* b3/air/AirCode.h:
* b3/air/AirEliminateDeadCode.cpp:
* b3/air/AirFixObviousSpills.cpp:
* b3/air/AirFixPartialRegisterStalls.cpp:
* b3/air/AirGenerate.cpp:
* b3/air/AirGenerationContext.h:
* b3/air/AirLiveness.h:
* b3/air/AirSpillEverything.cpp:

Source/WTF:

Add IndexSet, IndexMap, and IndexedContainerIterator.

* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/IndexMap.h: Copied from Source/JavaScriptCore/b3/B3IndexMap.h.
(WTF::IndexMap::IndexMap):
(WTF::IndexMap::resize):
(WTF::IndexMap::clear):
(WTF::IndexMap::size):
(WTF::IndexMap::operator[]):
* wtf/IndexSet.h: Renamed from Source/JavaScriptCore/b3/B3IndexSet.h.
(WTF::IndexSet::IndexSet):
(WTF::IndexSet::add):
(WTF::IndexSet::addAll):
(WTF::IndexSet::remove):
(WTF::IndexSet::contains):
(WTF::IndexSet::size):
(WTF::IndexSet::isEmpty):
(WTF::IndexSet::Iterable::Iterable):
(WTF::IndexSet::Iterable::iterator::iterator):
(WTF::IndexSet::Iterable::iterator::operator*):
(WTF::IndexSet::Iterable::iterator::operator++):
(WTF::IndexSet::Iterable::iterator::operator==):
(WTF::IndexSet::Iterable::iterator::operator!=):
(WTF::IndexSet::Iterable::begin):
(WTF::IndexSet::Iterable::end):
(WTF::IndexSet::values):
(WTF::IndexSet::indices):
(WTF::IndexSet::dump):
* wtf/IndexedContainerIterator.h: Renamed from Source/JavaScriptCore/b3/B3IndexMap.h.
(WTF::IndexedContainerIterator::IndexedContainerIterator):
(WTF::IndexedContainerIterator::operator++):
(WTF::IndexedContainerIterator::operator==):
(WTF::IndexedContainerIterator::operator!=):
(WTF::IndexedContainerIterator::findNext):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204920 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/b3/B3BasicBlockUtils.h
Source/JavaScriptCore/b3/B3BlockWorklist.h
Source/JavaScriptCore/b3/B3CFG.h
Source/JavaScriptCore/b3/B3DuplicateTails.cpp
Source/JavaScriptCore/b3/B3FixSSA.cpp
Source/JavaScriptCore/b3/B3FixSSA.h
Source/JavaScriptCore/b3/B3LowerToAir.cpp
Source/JavaScriptCore/b3/B3PhiChildren.h
Source/JavaScriptCore/b3/B3Procedure.h
Source/JavaScriptCore/b3/B3ReduceDoubleToFloat.cpp
Source/JavaScriptCore/b3/B3ReduceStrength.cpp
Source/JavaScriptCore/b3/B3SSACalculator.h
Source/JavaScriptCore/b3/B3UseCounts.h
Source/JavaScriptCore/b3/air/AirCode.h
Source/JavaScriptCore/b3/air/AirEliminateDeadCode.cpp
Source/JavaScriptCore/b3/air/AirFixObviousSpills.cpp
Source/JavaScriptCore/b3/air/AirFixPartialRegisterStalls.cpp
Source/JavaScriptCore/b3/air/AirGenerate.cpp
Source/JavaScriptCore/b3/air/AirGenerationContext.h
Source/JavaScriptCore/b3/air/AirLiveness.h
Source/JavaScriptCore/b3/air/AirSpillEverything.cpp
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/IndexMap.h [moved from Source/JavaScriptCore/b3/B3IndexMap.h with 93% similarity]
Source/WTF/wtf/IndexSet.h [moved from Source/JavaScriptCore/b3/B3IndexSet.h with 97% similarity]
Source/WTF/wtf/IndexedContainerIterator.h [new file with mode: 0644]

index 5b35805..8414d64 100644 (file)
@@ -1,3 +1,70 @@
+2016-08-24  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Move generic data structures out of B3
+        https://bugs.webkit.org/show_bug.cgi?id=161155
+
+        Reviewed by Saam Barati.
+
+        Move B3's good generic data structures to WTF.
+        They can be used for the other kind of basic blocks and nodes.
+        For example, the generator patch[1] will make BytecodeBasicBlock usable with these structures.
+
+        [1]: https://bugs.webkit.org/show_bug.cgi?id=152723
+
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * b3/B3BasicBlockUtils.h:
+        * b3/B3BlockWorklist.h:
+        * b3/B3CFG.h:
+        * b3/B3DuplicateTails.cpp:
+        * b3/B3FixSSA.cpp:
+        * b3/B3FixSSA.h:
+        * b3/B3IndexMap.h:
+        (JSC::B3::IndexMap::IndexMap): Deleted.
+        (JSC::B3::IndexMap::resize): Deleted.
+        (JSC::B3::IndexMap::clear): Deleted.
+        (JSC::B3::IndexMap::size): Deleted.
+        (JSC::B3::IndexMap::operator[]): Deleted.
+        * b3/B3IndexSet.h:
+        (JSC::B3::IndexSet::IndexSet): Deleted.
+        (JSC::B3::IndexSet::add): Deleted.
+        (JSC::B3::IndexSet::addAll): Deleted.
+        (JSC::B3::IndexSet::remove): Deleted.
+        (JSC::B3::IndexSet::contains): Deleted.
+        (JSC::B3::IndexSet::size): Deleted.
+        (JSC::B3::IndexSet::isEmpty): Deleted.
+        (JSC::B3::IndexSet::Iterable::Iterable): Deleted.
+        (JSC::B3::IndexSet::Iterable::iterator::iterator): Deleted.
+        (JSC::B3::IndexSet::Iterable::iterator::operator*): Deleted.
+        (JSC::B3::IndexSet::Iterable::iterator::operator++): Deleted.
+        (JSC::B3::IndexSet::Iterable::iterator::operator==): Deleted.
+        (JSC::B3::IndexSet::Iterable::iterator::operator!=): Deleted.
+        (JSC::B3::IndexSet::Iterable::begin): Deleted.
+        (JSC::B3::IndexSet::Iterable::end): Deleted.
+        (JSC::B3::IndexSet::values): Deleted.
+        (JSC::B3::IndexSet::indices): Deleted.
+        (JSC::B3::IndexSet::dump): Deleted.
+        * b3/B3LowerToAir.cpp:
+        * b3/B3PhiChildren.h:
+        * b3/B3Procedure.h:
+        (JSC::B3::Procedure::iterator::iterator): Deleted.
+        (JSC::B3::Procedure::iterator::operator*): Deleted.
+        (JSC::B3::Procedure::iterator::operator++): Deleted.
+        (JSC::B3::Procedure::iterator::operator==): Deleted.
+        (JSC::B3::Procedure::iterator::operator!=): Deleted.
+        (JSC::B3::Procedure::iterator::findNext): Deleted.
+        * b3/B3ReduceDoubleToFloat.cpp:
+        * b3/B3ReduceStrength.cpp:
+        * b3/B3SSACalculator.h:
+        * b3/B3UseCounts.h:
+        * b3/air/AirCode.h:
+        * b3/air/AirEliminateDeadCode.cpp:
+        * b3/air/AirFixObviousSpills.cpp:
+        * b3/air/AirFixPartialRegisterStalls.cpp:
+        * b3/air/AirGenerate.cpp:
+        * b3/air/AirGenerationContext.h:
+        * b3/air/AirLiveness.h:
+        * b3/air/AirSpillEverything.cpp:
+
 2016-08-24  Filip Pizlo  <fpizlo@apple.com>
 
         Unreviewed, roll out r204901, r204897, r204866, r204856, r204854.
index ea03cb6..a1d983d 100644 (file)
                0FEC85181BDACDAC0080FF74 /* B3Generate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FEC84CE1BDACDAC0080FF74 /* B3Generate.cpp */; };
                0FEC85191BDACDAC0080FF74 /* B3Generate.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEC84CF1BDACDAC0080FF74 /* B3Generate.h */; };
                0FEC851A1BDACDAC0080FF74 /* B3GenericFrequentedBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEC84D01BDACDAC0080FF74 /* B3GenericFrequentedBlock.h */; };
-               0FEC851B1BDACDAC0080FF74 /* B3IndexMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEC84D11BDACDAC0080FF74 /* B3IndexMap.h */; };
-               0FEC851C1BDACDAC0080FF74 /* B3IndexSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEC84D21BDACDAC0080FF74 /* B3IndexSet.h */; };
                0FEC851D1BDACDAC0080FF74 /* B3LowerToAir.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FEC84D31BDACDAC0080FF74 /* B3LowerToAir.cpp */; };
                0FEC851E1BDACDAC0080FF74 /* B3LowerToAir.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEC84D41BDACDAC0080FF74 /* B3LowerToAir.h */; };
                0FEC851F1BDACDAC0080FF74 /* B3MemoryValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FEC84D51BDACDAC0080FF74 /* B3MemoryValue.cpp */; };
                0FEC84CE1BDACDAC0080FF74 /* B3Generate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3Generate.cpp; path = b3/B3Generate.cpp; sourceTree = "<group>"; };
                0FEC84CF1BDACDAC0080FF74 /* B3Generate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3Generate.h; path = b3/B3Generate.h; sourceTree = "<group>"; };
                0FEC84D01BDACDAC0080FF74 /* B3GenericFrequentedBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3GenericFrequentedBlock.h; path = b3/B3GenericFrequentedBlock.h; sourceTree = "<group>"; };
-               0FEC84D11BDACDAC0080FF74 /* B3IndexMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3IndexMap.h; path = b3/B3IndexMap.h; sourceTree = "<group>"; };
-               0FEC84D21BDACDAC0080FF74 /* B3IndexSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3IndexSet.h; path = b3/B3IndexSet.h; sourceTree = "<group>"; };
                0FEC84D31BDACDAC0080FF74 /* B3LowerToAir.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3LowerToAir.cpp; path = b3/B3LowerToAir.cpp; sourceTree = "<group>"; };
                0FEC84D41BDACDAC0080FF74 /* B3LowerToAir.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3LowerToAir.h; path = b3/B3LowerToAir.h; sourceTree = "<group>"; };
                0FEC84D51BDACDAC0080FF74 /* B3MemoryValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3MemoryValue.cpp; path = b3/B3MemoryValue.cpp; sourceTree = "<group>"; };
                                0FEC84D01BDACDAC0080FF74 /* B3GenericFrequentedBlock.h */,
                                0FEC85BF1BE167A00080FF74 /* B3HeapRange.cpp */,
                                0FEC85C01BE167A00080FF74 /* B3HeapRange.h */,
-                               0FEC84D11BDACDAC0080FF74 /* B3IndexMap.h */,
-                               0FEC84D21BDACDAC0080FF74 /* B3IndexSet.h */,
                                DC69B99A1D15F90F002E3C00 /* B3InferSwitches.cpp */,
                                DC69B99B1D15F90F002E3C00 /* B3InferSwitches.h */,
                                0FEC85B41BE1462F0080FF74 /* B3InsertionSet.cpp */,
                                0FEC85C31BE167A00080FF74 /* B3HeapRange.h in Headers */,
                                26718BA51BE99F780052017B /* AirIteratedRegisterCoalescing.h in Headers */,
                                0F96303C1D4192CD005609D9 /* DestructionMode.h in Headers */,
-                               0FEC851B1BDACDAC0080FF74 /* B3IndexMap.h in Headers */,
-                               0FEC851C1BDACDAC0080FF74 /* B3IndexSet.h in Headers */,
                                0FEC85BA1BE1462F0080FF74 /* B3InsertionSet.h in Headers */,
                                0FEC85BB1BE1462F0080FF74 /* B3InsertionSetInlines.h in Headers */,
                                0FEC851E1BDACDAC0080FF74 /* B3LowerToAir.h in Headers */,
index 4a71767..32a59fc 100644 (file)
@@ -28,8 +28,8 @@
 
 #if ENABLE(B3_JIT)
 
-#include "B3IndexSet.h"
 #include <wtf/GraphNodeWorklist.h>
+#include <wtf/IndexSet.h>
 #include <wtf/Vector.h>
 
 namespace JSC { namespace B3 {
index af7ee2c..9e6be4b 100644 (file)
 
 #if ENABLE(B3_JIT)
 
-#include "B3BasicBlock.h"
-#include "B3IndexSet.h"
 #include <wtf/GraphNodeWorklist.h>
+#include <wtf/IndexSet.h>
 #include <wtf/Vector.h>
 
 namespace JSC { namespace B3 {
 
+class BasicBlock;
+
 typedef GraphNodeWorklist<BasicBlock*, IndexSet<BasicBlock>> BlockWorklist;
 
 // When you say BlockWith<int> you should read it as "block with an int".
index 58c40b1..904ab3f 100644 (file)
@@ -29,9 +29,9 @@
 #if ENABLE(B3_JIT)
 
 #include "B3BasicBlock.h"
-#include "B3IndexMap.h"
-#include "B3IndexSet.h"
 #include "B3Procedure.h"
+#include <wtf/IndexMap.h>
+#include <wtf/IndexSet.h>
 
 namespace JSC { namespace B3 {
 
index 8a8434b..95492bc 100644 (file)
 #include "B3BreakCriticalEdges.h"
 #include "B3Dominators.h"
 #include "B3FixSSA.h"
-#include "B3IndexSet.h"
 #include "B3InsertionSetInlines.h"
 #include "B3PhaseScope.h"
 #include "B3ProcedureInlines.h"
 #include "B3SwitchValue.h"
 #include "B3UpsilonValue.h"
 #include "B3ValueInlines.h"
+#include <wtf/IndexSet.h>
 
 namespace JSC { namespace B3 {
 
index f4b0122..730c2c8 100644 (file)
@@ -31,7 +31,6 @@
 #include "B3BasicBlockInlines.h"
 #include "B3BreakCriticalEdges.h"
 #include "B3Dominators.h"
-#include "B3IndexSet.h"
 #include "B3InsertionSetInlines.h"
 #include "B3PhaseScope.h"
 #include "B3ProcedureInlines.h"
@@ -41,6 +40,7 @@
 #include "B3Variable.h"
 #include "B3VariableValue.h"
 #include <wtf/CommaPrinter.h>
+#include <wtf/IndexSet.h>
 
 namespace JSC { namespace B3 {
 
index 662e49d..8859276 100644 (file)
@@ -28,8 +28,9 @@
 
 #if ENABLE(B3_JIT)
 
-#include "B3IndexSet.h"
 #include "B3Value.h"
+#include <wtf/IndexSet.h>
+#include <wtf/Vector.h>
 
 namespace JSC { namespace B3 {
 
index 312d937..a6b6ae1 100644 (file)
@@ -40,8 +40,6 @@
 #include "B3CheckSpecial.h"
 #include "B3Commutativity.h"
 #include "B3Dominators.h"
-#include "B3IndexMap.h"
-#include "B3IndexSet.h"
 #include "B3MemoryValue.h"
 #include "B3PatchpointSpecial.h"
 #include "B3PatchpointValue.h"
@@ -55,6 +53,8 @@
 #include "B3ValueInlines.h"
 #include "B3Variable.h"
 #include "B3VariableValue.h"
+#include <wtf/IndexMap.h>
+#include <wtf/IndexSet.h>
 #include <wtf/ListDump.h>
 
 #if COMPILER(GCC) && ASSERT_DISABLED
index cdf368f..e11fcbe 100644 (file)
 
 #if ENABLE(B3_JIT)
 
-#include "B3IndexMap.h"
 #include "B3Procedure.h"
 #include "B3UpsilonValue.h"
 #include <wtf/GraphNodeWorklist.h>
+#include <wtf/IndexMap.h>
 
 namespace JSC { namespace B3 {
 
index 576413e..e2e134d 100644 (file)
@@ -40,6 +40,7 @@
 #include <wtf/Bag.h>
 #include <wtf/FastMalloc.h>
 #include <wtf/HashSet.h>
+#include <wtf/IndexedContainerIterator.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/PrintStream.h>
 #include <wtf/SharedTask.h>
@@ -133,53 +134,7 @@ public:
     BasicBlock* at(unsigned index) const { return m_blocks[index].get(); }
     BasicBlock* operator[](unsigned index) const { return at(index); }
 
-    class iterator {
-    public:
-        iterator()
-            : m_procedure(nullptr)
-            , m_index(0)
-        {
-        }
-
-        iterator(const Procedure& procedure, unsigned index)
-            : m_procedure(&procedure)
-            , m_index(findNext(index))
-        {
-        }
-
-        BasicBlock* operator*()
-        {
-            return m_procedure->at(m_index);
-        }
-
-        iterator& operator++()
-        {
-            m_index = findNext(m_index + 1);
-            return *this;
-        }
-
-        bool operator==(const iterator& other) const
-        {
-            ASSERT(m_procedure == other.m_procedure);
-            return m_index == other.m_index;
-        }
-        
-        bool operator!=(const iterator& other) const
-        {
-            return !(*this == other);
-        }
-
-    private:
-        unsigned findNext(unsigned index)
-        {
-            while (index < m_procedure->size() && !m_procedure->at(index))
-                index++;
-            return index;
-        }
-
-        const Procedure* m_procedure;
-        unsigned m_index;
-    };
+    typedef WTF::IndexedContainerIterator<Procedure> iterator;
 
     iterator begin() const { return iterator(*this, 0); }
     iterator end() const { return iterator(*this, size()); }
index bd7cd09..8ece389 100644 (file)
 #if ENABLE(B3_JIT)
 
 #include "B3BasicBlock.h"
-#include "B3IndexSet.h"
 #include "B3InsertionSetInlines.h"
 #include "B3PhaseScope.h"
 #include "B3UseCounts.h"
 #include "B3ValueInlines.h"
+#include <wtf/IndexSet.h>
 
 namespace JSC { namespace B3 {
 
index 4cbf252..0bd1ea0 100644 (file)
@@ -32,7 +32,6 @@
 #include "B3BlockInsertionSet.h"
 #include "B3ComputeDivisionMagic.h"
 #include "B3Dominators.h"
-#include "B3IndexSet.h"
 #include "B3InsertionSetInlines.h"
 #include "B3MemoryValue.h"
 #include "B3PhaseScope.h"
@@ -48,6 +47,7 @@
 #include "B3VariableValue.h"
 #include <wtf/GraphNodeWorklist.h>
 #include <wtf/HashMap.h>
+#include <wtf/IndexSet.h>
 
 namespace JSC { namespace B3 {
 
index f576682..1e96282 100644 (file)
@@ -29,9 +29,9 @@
 #if ENABLE(B3_JIT)
 
 #include "B3Dominators.h"
-#include "B3IndexMap.h"
 #include "B3ProcedureInlines.h"
 #include <wtf/Bag.h>
+#include <wtf/IndexMap.h>
 #include <wtf/SegmentedVector.h>
 
 namespace JSC { namespace B3 {
index a59d58a..6e9e482 100644 (file)
@@ -28,8 +28,8 @@
 
 #if ENABLE(B3_JIT)
 
-#include "B3IndexMap.h"
 #include "B3Value.h"
+#include <wtf/IndexMap.h>
 
 namespace JSC { namespace B3 {
 
index 64a745d..f19efb2 100644 (file)
 #include "AirSpecial.h"
 #include "AirStackSlot.h"
 #include "AirTmp.h"
-#include "B3IndexMap.h"
 #include "B3SparseCollection.h"
 #include "CCallHelpers.h"
 #include "RegisterAtOffsetList.h"
 #include "StackAlignment.h"
+#include <wtf/IndexMap.h>
 
 namespace JSC { namespace B3 {
 
index 3663eaa..ca36af9 100644 (file)
@@ -31,7 +31,7 @@
 #include "AirCode.h"
 #include "AirInstInlines.h"
 #include "AirPhaseScope.h"
-#include "B3IndexSet.h"
+#include <wtf/IndexSet.h>
 
 namespace JSC { namespace B3 { namespace Air {
 
index 71d990f..babd173 100644 (file)
@@ -32,7 +32,7 @@
 #include "AirCode.h"
 #include "AirInstInlines.h"
 #include "AirPhaseScope.h"
-#include "B3IndexMap.h"
+#include <wtf/IndexMap.h>
 #include <wtf/ListDump.h>
 
 namespace JSC { namespace B3 { namespace Air {
index ed7b80a..5399799 100644 (file)
@@ -34,9 +34,9 @@
 #include "AirInst.h"
 #include "AirInstInlines.h"
 #include "AirPhaseScope.h"
-#include "B3IndexMap.h"
-#include "B3IndexSet.h"
 #include "MacroAssembler.h"
+#include <wtf/IndexMap.h>
+#include <wtf/IndexSet.h>
 #include <wtf/Vector.h>
 
 namespace JSC { namespace B3 { namespace Air {
index 4118412..0a18ada 100644 (file)
 #include "AirSpillEverything.h"
 #include "AirValidate.h"
 #include "B3Common.h"
-#include "B3IndexMap.h"
 #include "B3Procedure.h"
 #include "B3TimingScope.h"
 #include "B3ValueInlines.h"
 #include "CCallHelpers.h"
 #include "DisallowMacroScratchRegisterUsage.h"
 #include "LinkBuffer.h"
+#include <wtf/IndexMap.h>
 
 namespace JSC { namespace B3 { namespace Air {
 
index eca907f..7dc6e0d 100644 (file)
@@ -29,9 +29,9 @@
 #if ENABLE(B3_JIT)
 
 #include "AirBasicBlock.h"
-#include "B3IndexMap.h"
 #include "CCallHelpers.h"
 #include <wtf/Box.h>
+#include <wtf/IndexMap.h>
 #include <wtf/SharedTask.h>
 #include <wtf/Vector.h>
 
index ac118aa..f01460a 100644 (file)
@@ -33,8 +33,8 @@
 #include "AirInstInlines.h"
 #include "AirStackSlot.h"
 #include "AirTmpInlines.h"
-#include "B3IndexMap.h"
-#include "B3IndexSet.h"
+#include <wtf/IndexMap.h>
+#include <wtf/IndexSet.h>
 #include <wtf/IndexSparseSet.h>
 #include <wtf/ListDump.h>
 
index 3a0636d..1676705 100644 (file)
@@ -35,7 +35,7 @@
 #include "AirLiveness.h"
 #include "AirPhaseScope.h"
 #include "AirRegisterPriority.h"
-#include "B3IndexMap.h"
+#include <wtf/IndexMap.h>
 
 namespace JSC { namespace B3 { namespace Air {
 
index 37e20a4..be09038 100644 (file)
@@ -1,3 +1,46 @@
+2016-08-24  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Move generic data structures out of B3
+        https://bugs.webkit.org/show_bug.cgi?id=161155
+
+        Reviewed by Saam Barati.
+
+        Add IndexSet, IndexMap, and IndexedContainerIterator.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/IndexMap.h: Copied from Source/JavaScriptCore/b3/B3IndexMap.h.
+        (WTF::IndexMap::IndexMap):
+        (WTF::IndexMap::resize):
+        (WTF::IndexMap::clear):
+        (WTF::IndexMap::size):
+        (WTF::IndexMap::operator[]):
+        * wtf/IndexSet.h: Renamed from Source/JavaScriptCore/b3/B3IndexSet.h.
+        (WTF::IndexSet::IndexSet):
+        (WTF::IndexSet::add):
+        (WTF::IndexSet::addAll):
+        (WTF::IndexSet::remove):
+        (WTF::IndexSet::contains):
+        (WTF::IndexSet::size):
+        (WTF::IndexSet::isEmpty):
+        (WTF::IndexSet::Iterable::Iterable):
+        (WTF::IndexSet::Iterable::iterator::iterator):
+        (WTF::IndexSet::Iterable::iterator::operator*):
+        (WTF::IndexSet::Iterable::iterator::operator++):
+        (WTF::IndexSet::Iterable::iterator::operator==):
+        (WTF::IndexSet::Iterable::iterator::operator!=):
+        (WTF::IndexSet::Iterable::begin):
+        (WTF::IndexSet::Iterable::end):
+        (WTF::IndexSet::values):
+        (WTF::IndexSet::indices):
+        (WTF::IndexSet::dump):
+        * wtf/IndexedContainerIterator.h: Renamed from Source/JavaScriptCore/b3/B3IndexMap.h.
+        (WTF::IndexedContainerIterator::IndexedContainerIterator):
+        (WTF::IndexedContainerIterator::operator++):
+        (WTF::IndexedContainerIterator::operator==):
+        (WTF::IndexedContainerIterator::operator!=):
+        (WTF::IndexedContainerIterator::findNext):
+
 2016-08-24  Andreas Kling  <akling@apple.com>
 
         Add WTF::isFastMallocEnabled().
index 91eb723..6e585a8 100644 (file)
                FE8925B01D00DAEC0046907E /* Indenter.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8925AF1D00DAEC0046907E /* Indenter.h */; };
                FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDACD3B1630F83F00C69634 /* StackStats.cpp */; };
                FEDACD3E1630F83F00C69634 /* StackStats.h in Headers */ = {isa = PBXBuildFile; fileRef = FEDACD3C1630F83F00C69634 /* StackStats.h */; };
+               C8B0E1A1E01A486EB95E0D11 /* IndexSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 3137E1D7DBD84AC38FAE4D34 /* IndexSet.h */; };
+               C916B975F02F4F7E8B4AB12D /* IndexMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B43383A5D0B463C9433D933 /* IndexMap.h */; };
+               4B2680DD9B974402899ED572 /* IndexedContainerIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C67C542589348E285B49699 /* IndexedContainerIterator.h */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                FE8925AF1D00DAEC0046907E /* Indenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Indenter.h; sourceTree = "<group>"; };
                FEDACD3B1630F83F00C69634 /* StackStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackStats.cpp; sourceTree = "<group>"; };
                FEDACD3C1630F83F00C69634 /* StackStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackStats.h; sourceTree = "<group>"; };
+               3137E1D7DBD84AC38FAE4D34 /* IndexSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IndexSet.h; path = IndexSet.h; sourceTree = "<group>"; };
+               5B43383A5D0B463C9433D933 /* IndexMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IndexMap.h; path = IndexMap.h; sourceTree = "<group>"; };
+               9C67C542589348E285B49699 /* IndexedContainerIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IndexedContainerIterator.h; path = IndexedContainerIterator.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                E4A0AD381A96245500536DF6 /* WorkQueue.h */,
                                A8A4737A151A825B004123FF /* WTFThreadData.cpp */,
                                A8A4737B151A825B004123FF /* WTFThreadData.h */,
+                               3137E1D7DBD84AC38FAE4D34 /* IndexSet.h */,
+                               5B43383A5D0B463C9433D933 /* IndexMap.h */,
+                               9C67C542589348E285B49699 /* IndexedContainerIterator.h */,
                        );
                        path = wtf;
                        sourceTree = "<group>";
                                A8A47446151A825B004123FF /* WTFString.h in Headers */,
                                A8A47487151A825B004123FF /* WTFThreadData.h in Headers */,
                                CE73E02519DCB7AB00580D5C /* XPCSPI.h in Headers */,
+                               C8B0E1A1E01A486EB95E0D11 /* IndexSet.h in Headers */,
+                               C916B975F02F4F7E8B4AB12D /* IndexMap.h in Headers */,
+                               4B2680DD9B974402899ED572 /* IndexedContainerIterator.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 6ca893d..867999e 100644 (file)
@@ -45,6 +45,10 @@ set(WTF_HEADERS
     HashTable.h
     HashTraits.h
     HexNumber.h
+    IndexMap.h
+    IndexSet.h
+    IndexSparseSet.h
+    IndexedContainerIterator.h
     IteratorAdaptors.h
     IteratorRange.h
     ListHashSet.h
similarity index 93%
rename from Source/JavaScriptCore/b3/B3IndexMap.h
rename to Source/WTF/wtf/IndexMap.h
index 2aa339f..02d6101 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef B3IndexMap_h
-#define B3IndexMap_h
-
-#if ENABLE(B3_JIT)
+#pragma once
 
 #include <wtf/Vector.h>
 
-namespace JSC { namespace B3 {
+namespace WTF {
 
 // This is a map for keys that have an index(). It's super efficient for BasicBlocks. It's only
 // efficient for Values if you don't create too many of these maps, since Values can have very
@@ -80,8 +77,6 @@ private:
     Vector<Value> m_vector;
 };
 
-} } // namespace JSC::B3
-
-#endif // ENABLE(B3_JIT)
+} // namespace WTF
 
-#endif // B3IndexMap_h
+using WTF::IndexMap;
similarity index 97%
rename from Source/JavaScriptCore/b3/B3IndexSet.h
rename to Source/WTF/wtf/IndexSet.h
index ab9b2b4..61bd04f 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef B3IndexSet_h
-#define B3IndexSet_h
+#pragma once
 
 #include <wtf/BitVector.h>
 #include <wtf/CommaPrinter.h>
 
-namespace JSC { namespace B3 {
+namespace WTF {
 
 // This is a set for things that have an index(). It's super efficient for BasicBlocks. It's only
 // efficient for Values if you don't create too many of these sets, since Values can have very sparse
@@ -159,7 +158,6 @@ private:
     BitVector m_set;
 };
 
-} } // namespace JSC::B3
-
-#endif // B3IndexSet_h
+} // namespace WTF
 
+using WTF::IndexSet;
diff --git a/Source/WTF/wtf/IndexedContainerIterator.h b/Source/WTF/wtf/IndexedContainerIterator.h
new file mode 100644 (file)
index 0000000..3e9b9e3
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2015-2016 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
+
+#include <type_traits>
+
+namespace WTF {
+
+template<class Container>
+class IndexedContainerIterator {
+public:
+    IndexedContainerIterator()
+        : m_container(nullptr)
+        , m_index(0)
+    {
+    }
+
+    IndexedContainerIterator(const Container& container, unsigned index)
+        : m_container(&container)
+        , m_index(findNext(index))
+    {
+    }
+
+    auto operator*() -> typename std::result_of<decltype(&Container::at)(const Container, unsigned)>::type
+    {
+        return m_container->at(m_index);
+    }
+
+    IndexedContainerIterator& operator++()
+    {
+        m_index = findNext(m_index + 1);
+        return *this;
+    }
+
+    bool operator==(const IndexedContainerIterator& other) const
+    {
+        ASSERT(m_container == other.m_container);
+        return m_index == other.m_index;
+    }
+
+    bool operator!=(const IndexedContainerIterator& other) const
+    {
+        return !(*this == other);
+    }
+
+private:
+    unsigned findNext(unsigned index)
+    {
+        while (index < m_container->size() && !m_container->at(index))
+            index++;
+        return index;
+    }
+
+    const Container* m_container;
+    unsigned m_index;
+};
+
+} // namespace WTF