1// Copyright 2018 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef V8_COMPILER_MACHINE_GRAPH_H_ 6#define V8_COMPILER_MACHINE_GRAPH_H_ 7 8#include "src/base/compiler-specific.h" 9#include "src/common/globals.h" 10#include "src/compiler/common-node-cache.h" 11#include "src/compiler/common-operator.h" 12#include "src/compiler/graph.h" 13#include "src/compiler/machine-operator.h" 14#include "src/runtime/runtime.h" 15 16namespace v8 { 17namespace internal { 18namespace compiler { 19 20// Implements a facade on a Graph, enhancing the graph with machine-specific 21// notions, including a builder for common and machine operators, as well 22// as caching primitive constants. 23class V8_EXPORT_PRIVATE MachineGraph : public NON_EXPORTED_BASE(ZoneObject) { 24 public: 25 MachineGraph(Graph* graph, CommonOperatorBuilder* common, 26 MachineOperatorBuilder* machine) 27 : graph_(graph), common_(common), machine_(machine), cache_(zone()) {} 28 MachineGraph(const MachineGraph&) = delete; 29 MachineGraph& operator=(const MachineGraph&) = delete; 30 31 // Creates a Int32Constant node, usually canonicalized. 32 Node* Int32Constant(int32_t value); 33 Node* Uint32Constant(uint32_t value) { 34 return Int32Constant(bit_cast<int32_t>(value)); 35 } 36 37 // Creates a Int64Constant node, usually canonicalized. 38 Node* Int64Constant(int64_t value); 39 Node* Uint64Constant(uint64_t value) { 40 return Int64Constant(bit_cast<int64_t>(value)); 41 } 42 43 // Creates a Int32Constant/Int64Constant node, depending on the word size of 44 // the target machine. 45 // TODO(turbofan): Code using Int32Constant/Int64Constant to store pointer 46 // constants is probably not serializable. 47 Node* IntPtrConstant(intptr_t value); 48 Node* UintPtrConstant(uintptr_t value); 49 50 Node* TaggedIndexConstant(intptr_t value); 51 52 Node* RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode); 53 Node* RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode); 54 Node* RelocatableIntPtrConstant(intptr_t value, RelocInfo::Mode rmode); 55 56 // Creates a Float32Constant node, usually canonicalized. 57 Node* Float32Constant(float value); 58 59 // Creates a Float64Constant node, usually canonicalized. 60 Node* Float64Constant(double value); 61 62 // Creates a PointerConstant node. 63 Node* PointerConstant(intptr_t value); 64 template <typename T> 65 Node* PointerConstant(T* value) { 66 return PointerConstant(bit_cast<intptr_t>(value)); 67 } 68 69 // Creates an ExternalConstant node, usually canonicalized. 70 Node* ExternalConstant(ExternalReference ref); 71 Node* ExternalConstant(Runtime::FunctionId function_id); 72 73 // Global cache of the dead node. 74 Node* Dead() { 75 return Dead_ ? Dead_ : Dead_ = graph_->NewNode(common_->Dead()); 76 } 77 78 CommonOperatorBuilder* common() const { return common_; } 79 MachineOperatorBuilder* machine() const { return machine_; } 80 Graph* graph() const { return graph_; } 81 Zone* zone() const { return graph()->zone(); } 82 83 protected: 84 Graph* graph_; 85 CommonOperatorBuilder* common_; 86 MachineOperatorBuilder* machine_; 87 CommonNodeCache cache_; 88 Node* Dead_ = nullptr; 89}; 90 91} // namespace compiler 92} // namespace internal 93} // namespace v8 94 95#endif // V8_COMPILER_MACHINE_GRAPH_H_ 96