js-frame-specialization.cc 2.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// 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);
    case IrOpcode::kParameter:
      return ReduceParameter(node);
    default:
      break;
  }
  return NoChange();
}

Reduction JSFrameSpecialization::ReduceOsrValue(Node* node) {
28 29 30
  // JSFrameSpecialization should never run on interpreted frames, since the
  // code below assumes standard stack frame layouts.
  DCHECK(!frame()->is_interpreted());
31
  DCHECK_EQ(IrOpcode::kOsrValue, node->opcode());
32
  Handle<Object> value;
33
  int index = OsrValueIndexOf(node->op());
34 35
  int const parameters_count = frame()->ComputeParametersCount() + 1;
  if (index == Linkage::kOsrContextSpillSlotIndex) {
36
    value = handle(frame()->context(), isolate());
37
  } else if (index >= parameters_count) {
38
    value = handle(frame()->GetExpression(index - parameters_count), isolate());
39 40
  } else {
    // The OsrValue index 0 is the receiver.
41 42 43
    value =
        handle(index ? frame()->GetParameter(index - 1) : frame()->receiver(),
               isolate());
44
  }
45
  return Replace(jsgraph()->Constant(value));
46 47 48 49
}

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


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

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