js-frame-specialization.cc 2.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/compiler/js-frame-specialization.h"

#include "src/compiler/js-graph.h"
#include "src/compiler/linkage.h"
#include "src/frames-inl.h"

namespace v8 {
namespace internal {
namespace compiler {

Reduction JSFrameSpecialization::Reduce(Node* node) {
  switch (node->opcode()) {
    case IrOpcode::kOsrValue:
      return ReduceOsrValue(node);
19 20
    case IrOpcode::kOsrGuard:
      return ReduceOsrGuard(node);
21 22 23 24 25 26 27 28 29 30
    case IrOpcode::kParameter:
      return ReduceParameter(node);
    default:
      break;
  }
  return NoChange();
}

Reduction JSFrameSpecialization::ReduceOsrValue(Node* node) {
  DCHECK_EQ(IrOpcode::kOsrValue, node->opcode());
31
  Handle<Object> value;
32
  int index = OsrValueIndexOf(node->op());
33 34
  int const parameters_count = frame()->ComputeParametersCount() + 1;
  if (index == Linkage::kOsrContextSpillSlotIndex) {
35
    value = handle(frame()->context(), isolate());
36
  } else if (index >= parameters_count) {
37
    value = handle(frame()->GetExpression(index - parameters_count), isolate());
38 39
  } else {
    // The OsrValue index 0 is the receiver.
40 41 42
    value =
        handle(index ? frame()->GetParameter(index - 1) : frame()->receiver(),
               isolate());
43
  }
44
  return Replace(jsgraph()->Constant(value));
45 46
}

47 48 49 50 51 52
Reduction JSFrameSpecialization::ReduceOsrGuard(Node* node) {
  DCHECK_EQ(IrOpcode::kOsrGuard, node->opcode());
  ReplaceWithValue(node, node->InputAt(0),
                   NodeProperties::GetEffectInput(node));
  return Changed(node);
}
53 54 55

Reduction JSFrameSpecialization::ReduceParameter(Node* node) {
  DCHECK_EQ(IrOpcode::kParameter, node->opcode());
56
  Handle<Object> value;
57 58
  int const index = ParameterIndexOf(node->op());
  int const parameters_count = frame()->ComputeParametersCount() + 1;
59 60
  if (index == Linkage::kJSCallClosureParamIndex) {
    // The Parameter index references the closure.
61
    value = handle(frame()->function(), isolate());
62 63
  } else if (index == Linkage::GetJSCallArgCountParamIndex(parameters_count)) {
    // The Parameter index references the parameter count.
64
    value = handle(Smi::FromInt(parameters_count - 1), isolate());
65 66
  } else if (index == Linkage::GetJSCallContextParamIndex(parameters_count)) {
    // The Parameter index references the context.
67
    value = handle(frame()->context(), isolate());
68 69
  } else {
    // The Parameter index 0 is the receiver.
70 71 72
    value =
        handle(index ? frame()->GetParameter(index - 1) : frame()->receiver(),
               isolate());
73
  }
74
  return Replace(jsgraph()->Constant(value));
75 76 77 78 79 80 81 82
}


Isolate* JSFrameSpecialization::isolate() const { return jsgraph()->isolate(); }

}  // namespace compiler
}  // namespace internal
}  // namespace v8