Changeset 131087 in webkit for trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
- Timestamp:
- Oct 11, 2012, 12:36:04 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
r130826 r131087 41 41 #include <wtf/HashMap.h> 42 42 #include <wtf/MathExtras.h> 43 44 namespace JSC { namespace DFG { 45 46 class ConstantBufferKey { 47 public: 48 ConstantBufferKey() 49 : m_codeBlock(0) 50 , m_index(0) 51 { 52 } 53 54 ConstantBufferKey(WTF::HashTableDeletedValueType) 55 : m_codeBlock(0) 56 , m_index(1) 57 { 58 } 59 60 ConstantBufferKey(CodeBlock* codeBlock, unsigned index) 61 : m_codeBlock(codeBlock) 62 , m_index(index) 63 { 64 } 65 66 bool operator==(const ConstantBufferKey& other) const 67 { 68 return m_codeBlock == other.m_codeBlock 69 && m_index == other.m_index; 70 } 71 72 unsigned hash() const 73 { 74 return WTF::PtrHash<CodeBlock*>::hash(m_codeBlock) ^ m_index; 75 } 76 77 bool isHashTableDeletedValue() const 78 { 79 return !m_codeBlock && m_index; 80 } 81 82 CodeBlock* codeBlock() const { return m_codeBlock; } 83 unsigned index() const { return m_index; } 84 85 private: 86 CodeBlock* m_codeBlock; 87 unsigned m_index; 88 }; 89 90 struct ConstantBufferKeyHash { 91 static unsigned hash(const ConstantBufferKey& key) { return key.hash(); } 92 static bool equal(const ConstantBufferKey& a, const ConstantBufferKey& b) 93 { 94 return a == b; 95 } 96 97 static const bool safeToCompareToEmptyOrDeleted = true; 98 }; 99 100 } } // namespace JSC::DFG 101 102 namespace WTF { 103 104 template<typename T> struct DefaultHash; 105 template<> struct DefaultHash<JSC::DFG::ConstantBufferKey> { 106 typedef JSC::DFG::ConstantBufferKeyHash Hash; 107 }; 108 109 template<typename T> struct HashTraits; 110 template<> struct HashTraits<JSC::DFG::ConstantBufferKey> : SimpleClassHashTraits<JSC::DFG::ConstantBufferKey> { }; 111 112 } // namespace WTF 43 113 44 114 namespace JSC { namespace DFG { … … 1053 1123 Vector<PhiStackEntry, 16> m_localPhiStack; 1054 1124 1125 HashMap<ConstantBufferKey, unsigned> m_constantBufferCache; 1126 1055 1127 struct InlineStackEntry { 1056 1128 ByteCodeParser* m_byteCodeParser; … … 1071 1143 Vector<unsigned> m_identifierRemap; 1072 1144 Vector<unsigned> m_constantRemap; 1145 Vector<unsigned> m_constantBufferRemap; 1073 1146 1074 1147 // Blocks introduced by this code block, which need successor linking. … … 1897 1970 int startConstant = currentInstruction[2].u.operand; 1898 1971 int numConstants = currentInstruction[3].u.operand; 1899 set(currentInstruction[1].u.operand, addToGraph(NewArrayBuffer, OpInfo( startConstant), OpInfo(numConstants)));1972 set(currentInstruction[1].u.operand, addToGraph(NewArrayBuffer, OpInfo(m_inlineStackTop->m_constantBufferRemap[startConstant]), OpInfo(numConstants))); 1900 1973 NEXT_OPCODE(op_new_array_buffer); 1901 1974 } … … 3252 3325 m_identifierRemap.resize(codeBlock->numberOfIdentifiers()); 3253 3326 m_constantRemap.resize(codeBlock->numberOfConstantRegisters()); 3327 m_constantBufferRemap.resize(codeBlock->numberOfConstantBuffers()); 3254 3328 3255 3329 for (size_t i = 0; i < codeBlock->numberOfIdentifiers(); ++i) { … … 3280 3354 for (unsigned i = 0; i < codeBlock->numberOfGlobalResolveInfos(); ++i) 3281 3355 byteCodeParser->m_codeBlock->addGlobalResolveInfo(std::numeric_limits<unsigned>::max()); 3356 for (unsigned i = 0; i < codeBlock->numberOfConstantBuffers(); ++i) { 3357 // If we inline the same code block multiple times, we don't want to needlessly 3358 // duplicate its constant buffers. 3359 HashMap<ConstantBufferKey, unsigned>::iterator iter = 3360 byteCodeParser->m_constantBufferCache.find(ConstantBufferKey(codeBlock, i)); 3361 if (iter != byteCodeParser->m_constantBufferCache.end()) { 3362 m_constantBufferRemap[i] = iter->value; 3363 continue; 3364 } 3365 Vector<JSValue>& buffer = codeBlock->constantBufferAsVector(i); 3366 unsigned newIndex = byteCodeParser->m_codeBlock->addConstantBuffer(buffer); 3367 m_constantBufferRemap[i] = newIndex; 3368 byteCodeParser->m_constantBufferCache.add(ConstantBufferKey(codeBlock, i), newIndex); 3369 } 3282 3370 3283 3371 m_callsiteBlockHeadNeedsLinking = true; … … 3295 3383 m_identifierRemap.resize(codeBlock->numberOfIdentifiers()); 3296 3384 m_constantRemap.resize(codeBlock->numberOfConstantRegisters()); 3385 m_constantBufferRemap.resize(codeBlock->numberOfConstantBuffers()); 3297 3386 3298 3387 for (size_t i = 0; i < codeBlock->numberOfIdentifiers(); ++i) … … 3300 3389 for (size_t i = 0; i < codeBlock->numberOfConstantRegisters(); ++i) 3301 3390 m_constantRemap[i] = i + FirstConstantRegisterIndex; 3391 for (size_t i = 0; i < codeBlock->numberOfConstantBuffers(); ++i) 3392 m_constantBufferRemap[i] = i; 3302 3393 3303 3394 m_callsiteBlockHeadNeedsLinking = false;
Note:
See TracChangeset
for help on using the changeset viewer.