]>
git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/BytecodeKills.h
6e504a6d0501a3be4567f0cc68ee187919c0805a
   2  * Copyright (C) 2015 Apple Inc. All rights reserved. 
   4  * Redistribution and use in source and binary forms, with or without 
   5  * modification, are permitted provided that the following conditions 
   7  * 1. Redistributions of source code must retain the above copyright 
   8  *    notice, this list of conditions and the following disclaimer. 
   9  * 2. Redistributions in binary form must reproduce the above copyright 
  10  *    notice, this list of conditions and the following disclaimer in the 
  11  *    documentation and/or other materials provided with the distribution. 
  13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 
  14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
  15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 
  17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
  20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
  21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
  23  * THE POSSIBILITY OF SUCH DAMAGE. 
  26 #ifndef BytecodeKills_h 
  27 #define BytecodeKills_h 
  29 #include "CodeBlock.h" 
  30 #include <wtf/FastBitVector.h> 
  34 class BytecodeLivenessAnalysis
; 
  39         : m_codeBlock(nullptr) 
  43     // By convention, we say that non-local operands are never killed. 
  44     bool operandIsKilled(unsigned bytecodeIndex
, int operand
) const 
  46         ASSERT_WITH_SECURITY_IMPLICATION(bytecodeIndex 
< m_codeBlock
->instructions().size()); 
  47         VirtualRegister 
reg(operand
); 
  49             return m_killSets
[bytecodeIndex
].contains(operand
); 
  53     bool operandIsKilled(Instruction
* instruction
, int operand
) const 
  55         return operandIsKilled(instruction 
- m_codeBlock
->instructions().begin(), operand
); 
  58     template<typename Functor
> 
  59     void forEachOperandKilledAt(unsigned bytecodeIndex
, const Functor
& functor
) const 
  61         ASSERT_WITH_SECURITY_IMPLICATION(bytecodeIndex 
< m_codeBlock
->instructions().size()); 
  62         m_killSets
[bytecodeIndex
].forEachLocal( 
  63             [&] (unsigned local
) { 
  64                 functor(virtualRegisterForLocal(local
)); 
  68     template<typename Functor
> 
  69     void forEachOperandKilledAt(Instruction
* pc
, const Functor
& functor
) const 
  71         forEachOperandKilledAt(pc 
- m_codeBlock
->instructions().begin(), functor
); 
  75     friend class BytecodeLivenessAnalysis
; 
  90         void add(unsigned local
) 
  97                 ASSERT(oneItem() != local
); 
  98                 Vector
<unsigned>* vector 
= new Vector
<unsigned>(); 
  99                 vector
->append(oneItem()); 
 100                 vector
->append(local
); 
 104             ASSERT(!vector()->contains(local
)); 
 105             vector()->append(local
); 
 108         template<typename Functor
> 
 109         void forEachLocal(const Functor
& functor
) 
 117             for (unsigned local 
: *vector()) 
 121         bool contains(unsigned expectedLocal
) 
 126                 return oneItem() == expectedLocal
; 
 127             for (unsigned local 
: *vector()) { 
 128                 if (local 
== expectedLocal
) 
 140         bool hasOneItem() const 
 145         unsigned oneItem() const 
 150         void setOneItem(unsigned value
) 
 152             m_word 
= (value 
<< 1) | 1; 
 155         bool hasVector() const 
 157             return !isEmpty() && !hasOneItem(); 
 160         Vector
<unsigned>* vector() 
 162             return bitwise_cast
<Vector
<unsigned>*>(m_word
); 
 165         void setVector(Vector
<unsigned>* value
) 
 167             m_word 
= bitwise_cast
<uintptr_t>(value
); 
 173     CodeBlock
* m_codeBlock
; 
 174     std::unique_ptr
<KillSet
[]> m_killSets
; 
 179 #endif // BytecodeKills_h