js-heap-copy-reducer.cc 4.83 KB
Newer Older
1 2 3 4 5
// Copyright 2018 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-heap-copy-reducer.h"
6

7 8
#include "src/compiler/common-operator.h"
#include "src/compiler/js-heap-broker.h"
9
#include "src/compiler/js-operator.h"
10
#include "src/compiler/node-properties.h"
11
#include "src/compiler/simplified-operator.h"
12 13 14
#include "src/heap/factory-inl.h"
#include "src/objects/map.h"
#include "src/objects/scope-info.h"
15 16 17 18 19

namespace v8 {
namespace internal {
namespace compiler {

20 21 22
// In the functions below, we call the ObjectRef (or subclass) constructor in
// order to trigger serialization if not yet done.

23 24 25 26 27 28 29
JSHeapCopyReducer::JSHeapCopyReducer(JSHeapBroker* broker) : broker_(broker) {}

JSHeapBroker* JSHeapCopyReducer::broker() { return broker_; }

Reduction JSHeapCopyReducer::Reduce(Node* node) {
  switch (node->opcode()) {
    case IrOpcode::kHeapConstant: {
30 31
      ObjectRef object(broker(), HeapConstantOf(node->op()));
      if (object.IsJSFunction()) object.AsJSFunction().Serialize();
32
      if (object.IsJSObject()) object.AsJSObject().SerializeObjectCreateMap();
33
      if (object.IsModule()) object.AsModule().Serialize();
34
      if (object.IsContext()) object.AsContext().SerializeContextChain();
35 36
      break;
    }
37 38 39 40 41 42
    case IrOpcode::kJSCreateArray: {
      CreateArrayParameters const& p = CreateArrayParametersOf(node->op());
      Handle<AllocationSite> site;
      if (p.site().ToHandle(&site)) AllocationSiteRef(broker(), site);
      break;
    }
43 44 45 46 47 48 49
    case IrOpcode::kJSCreateArguments: {
      Node* const frame_state = NodeProperties::GetFrameStateInput(node);
      FrameStateInfo state_info = FrameStateInfoOf(frame_state->op());
      SharedFunctionInfoRef shared(broker(),
                                   state_info.shared_info().ToHandleChecked());
      break;
    }
50
    case IrOpcode::kJSCreateBlockContext: {
51 52 53 54 55 56
      ScopeInfoRef(broker(), ScopeInfoOf(node->op()));
      break;
    }
    case IrOpcode::kJSCreateBoundFunction: {
      CreateBoundFunctionParameters const& p =
          CreateBoundFunctionParametersOf(node->op());
57 58 59 60 61
      MapRef(broker(), p.map());
      break;
    }
    case IrOpcode::kJSCreateCatchContext: {
      ScopeInfoRef(broker(), ScopeInfoOf(node->op()));
62 63
      break;
    }
64 65 66
    case IrOpcode::kJSCreateClosure: {
      CreateClosureParameters const& p = CreateClosureParametersOf(node->op());
      SharedFunctionInfoRef(broker(), p.shared_info());
67
      FeedbackCellRef(broker(), p.feedback_cell());
68 69 70
      HeapObjectRef(broker(), p.code());
      break;
    }
71 72
    case IrOpcode::kJSCreateEmptyLiteralArray: {
      FeedbackParameter const& p = FeedbackParameterOf(node->op());
73
      FeedbackVectorRef(broker(), p.feedback().vector()).SerializeSlots();
74 75
      break;
    }
76 77 78 79 80 81
    case IrOpcode::kJSCreateFunctionContext: {
      CreateFunctionContextParameters const& p =
          CreateFunctionContextParametersOf(node->op());
      ScopeInfoRef(broker(), p.scope_info());
      break;
    }
82 83 84
    case IrOpcode::kJSCreateLiteralArray:
    case IrOpcode::kJSCreateLiteralObject: {
      CreateLiteralParameters const& p = CreateLiteralParametersOf(node->op());
85 86 87 88 89 90
      FeedbackVectorRef(broker(), p.feedback().vector()).SerializeSlots();
      break;
    }
    case IrOpcode::kJSCreateLiteralRegExp: {
      CreateLiteralParameters const& p = CreateLiteralParametersOf(node->op());
      FeedbackVectorRef(broker(), p.feedback().vector()).SerializeSlots();
91 92
      break;
    }
93 94 95 96
    case IrOpcode::kJSCreateWithContext: {
      ScopeInfoRef(broker(), ScopeInfoOf(node->op()));
      break;
    }
97 98 99 100 101 102
    case IrOpcode::kJSLoadNamed:
    case IrOpcode::kJSStoreNamed: {
      NamedAccess const& p = NamedAccessOf(node->op());
      NameRef(broker(), p.name());
      break;
    }
103 104 105 106 107 108 109 110 111 112 113 114 115 116
    case IrOpcode::kStoreField:
    case IrOpcode::kLoadField: {
      FieldAccess access = FieldAccessOf(node->op());
      Handle<Map> map_handle;
      if (access.map.ToHandle(&map_handle)) {
        MapRef(broker(), map_handle);
      }
      Handle<Name> name_handle;
      if (access.name.ToHandle(&name_handle)) {
        NameRef(broker(), name_handle);
      }
      break;
    }
    case IrOpcode::kMapGuard: {
117
      ZoneHandleSet<Map> const& maps = MapGuardMapsOf(node->op());
118 119 120 121 122 123
      for (Handle<Map> map : maps) {
        MapRef(broker(), map);
      }
      break;
    }
    case IrOpcode::kCheckMaps: {
124
      ZoneHandleSet<Map> const& maps = CheckMapsParametersOf(node->op()).maps();
125 126 127 128 129 130
      for (Handle<Map> map : maps) {
        MapRef(broker(), map);
      }
      break;
    }
    case IrOpcode::kCompareMaps: {
131
      ZoneHandleSet<Map> const& maps = CompareMapsParametersOf(node->op());
132 133 134 135 136 137
      for (Handle<Map> map : maps) {
        MapRef(broker(), map);
      }
      break;
    }

138 139 140 141 142 143 144 145 146
    default:
      break;
  }
  return NoChange();
}

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