/ bytecode / MethodOfGettingAValueProfile.h
MethodOfGettingAValueProfile.h
  1  /*
  2   * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
  3   *
  4   * Redistribution and use in source and binary forms, with or without
  5   * modification, are permitted provided that the following conditions
  6   * are met:
  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.
 12   *
 13   * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 17   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21   * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 24   */
 25  
 26  #pragma once
 27  
 28  // This is guarded by ENABLE_DFG_JIT only because it uses some value profiles
 29  // that are currently only used if the DFG is enabled (i.e. they are not
 30  // available in the profile-only configuration). Hopefully someday all of
 31  // these #if's will disappear...
 32  #if ENABLE(DFG_JIT)
 33  
 34  #include "BytecodeIndex.h"
 35  #include "GPRInfo.h"
 36  #include "Operands.h"
 37  #include "TagRegistersMode.h"
 38  
 39  namespace JSC {
 40  
 41  class UnaryArithProfile;
 42  class BinaryArithProfile;
 43  class CCallHelpers;
 44  class CodeBlock;
 45  class LazyOperandValueProfileKey;
 46  struct ValueProfile;
 47  
 48  class MethodOfGettingAValueProfile {
 49  public:
 50      MethodOfGettingAValueProfile()
 51          : m_kind(None)
 52      {
 53      }
 54      
 55      MethodOfGettingAValueProfile(ValueProfile* profile)
 56      {
 57          if (profile) {
 58              m_kind = Ready;
 59              u.profile = profile;
 60          } else
 61              m_kind = None;
 62      }
 63  
 64      MethodOfGettingAValueProfile(UnaryArithProfile* profile)
 65      {
 66          if (profile) {
 67              m_kind = UnaryArithProfileReady;
 68              u.unaryArithProfile = profile;
 69          } else
 70              m_kind = None;
 71      }
 72  
 73      MethodOfGettingAValueProfile(BinaryArithProfile* profile)
 74      {
 75          if (profile) {
 76              m_kind = BinaryArithProfileReady;
 77              u.binaryArithProfile = profile;
 78          } else
 79              m_kind = None;
 80      }
 81      
 82      static MethodOfGettingAValueProfile fromLazyOperand(
 83          CodeBlock*, const LazyOperandValueProfileKey&);
 84      
 85      explicit operator bool() const { return m_kind != None; }
 86  
 87      // The temporary register is only needed on 64-bits builds (for testing BigInt32).
 88      void emitReportValue(CCallHelpers&, JSValueRegs, GPRReg tempGPR, TagRegistersMode = HaveTagRegisters) const;
 89      void reportValue(JSValue);
 90  
 91  private:
 92      enum Kind {
 93          None,
 94          Ready,
 95          UnaryArithProfileReady,
 96          BinaryArithProfileReady,
 97          LazyOperand
 98      };
 99      
100      Kind m_kind;
101      union Data {
102          Data()
103              : profile(nullptr)
104          { }
105  
106          ValueProfile* profile;
107          UnaryArithProfile* unaryArithProfile;
108          BinaryArithProfile* binaryArithProfile;
109          struct {
110              CodeBlock* codeBlock;
111              BytecodeIndex bytecodeOffset;
112              Operand operand;
113          } lazyOperand;
114      } u;
115  };
116  
117  } // namespace JSC
118  
119  #endif // ENABLE(DFG_JIT)