DFGArgumentPosition.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2012, 2013 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. #ifndef DFGArgumentPosition_h
  26. #define DFGArgumentPosition_h
  27. #include "DFGDoubleFormatState.h"
  28. #include "DFGVariableAccessData.h"
  29. #include "DFGVariableAccessDataDump.h"
  30. #include "SpeculatedType.h"
  31. namespace JSC { namespace DFG {
  32. class ArgumentPosition {
  33. public:
  34. ArgumentPosition()
  35. : m_prediction(SpecNone)
  36. , m_doubleFormatState(EmptyDoubleFormatState)
  37. , m_isProfitableToUnbox(false)
  38. , m_shouldNeverUnbox(false)
  39. {
  40. }
  41. void addVariable(VariableAccessData* variable)
  42. {
  43. m_variables.append(variable);
  44. }
  45. bool mergeShouldNeverUnbox(bool shouldNeverUnbox)
  46. {
  47. return checkAndSet(m_shouldNeverUnbox, m_shouldNeverUnbox | shouldNeverUnbox);
  48. }
  49. bool mergeArgumentPredictionAwareness()
  50. {
  51. bool changed = false;
  52. for (unsigned i = 0; i < m_variables.size(); ++i) {
  53. VariableAccessData* variable = m_variables[i]->find();
  54. changed |= mergeSpeculation(m_prediction, variable->argumentAwarePrediction());
  55. changed |= mergeDoubleFormatState(m_doubleFormatState, variable->doubleFormatState());
  56. changed |= mergeShouldNeverUnbox(variable->shouldNeverUnbox());
  57. }
  58. if (!changed)
  59. return false;
  60. changed = false;
  61. for (unsigned i = 0; i < m_variables.size(); ++i) {
  62. VariableAccessData* variable = m_variables[i]->find();
  63. changed |= variable->mergeArgumentAwarePrediction(m_prediction);
  64. changed |= variable->mergeDoubleFormatState(m_doubleFormatState);
  65. changed |= variable->mergeShouldNeverUnbox(m_shouldNeverUnbox);
  66. }
  67. return changed;
  68. }
  69. bool mergeArgumentUnboxingAwareness()
  70. {
  71. bool changed = false;
  72. for (unsigned i = 0; i < m_variables.size(); ++i) {
  73. VariableAccessData* variable = m_variables[i]->find();
  74. changed |= checkAndSet(m_isProfitableToUnbox, m_isProfitableToUnbox | variable->isProfitableToUnbox());
  75. }
  76. if (!changed)
  77. return false;
  78. changed = false;
  79. for (unsigned i = 0; i < m_variables.size(); ++i) {
  80. VariableAccessData* variable = m_variables[i]->find();
  81. changed |= variable->mergeIsProfitableToUnbox(m_isProfitableToUnbox);
  82. }
  83. return changed;
  84. }
  85. bool shouldUnboxIfPossible() const { return m_isProfitableToUnbox && !m_shouldNeverUnbox; }
  86. SpeculatedType prediction() const { return m_prediction; }
  87. DoubleFormatState doubleFormatState() const { return m_doubleFormatState; }
  88. bool shouldUseDoubleFormat() const
  89. {
  90. return doubleFormatState() == UsingDoubleFormat && shouldUnboxIfPossible();
  91. }
  92. void dump(PrintStream& out, Graph* graph)
  93. {
  94. for (unsigned i = 0; i < m_variables.size(); ++i) {
  95. VariableAccessData* variable = m_variables[i]->find();
  96. int operand = variable->operand();
  97. if (i)
  98. out.print(" ");
  99. if (operandIsArgument(operand))
  100. out.print("arg", operandToArgument(operand), "(", VariableAccessDataDump(*graph, variable), ")");
  101. else
  102. out.print("r", operand, "(", VariableAccessDataDump(*graph, variable), ")");
  103. }
  104. out.print("\n");
  105. }
  106. private:
  107. SpeculatedType m_prediction;
  108. DoubleFormatState m_doubleFormatState;
  109. bool m_isProfitableToUnbox;
  110. bool m_shouldNeverUnbox;
  111. Vector<VariableAccessData*, 2> m_variables;
  112. };
  113. } } // namespace JSC::DFG
  114. #endif // DFGArgumentPosition_h