v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
machine-graph.h
Go to the documentation of this file.
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
15#include "src/runtime/runtime.h"
16
17namespace v8 {
18namespace internal {
19namespace compiler {
20
21// Implements a facade on a TFGraph, enhancing the graph with machine-specific
22// notions, including a builder for common and machine operators, as well
23// as caching primitive constants.
25 public:
28 : graph_(graph),
29 common_(common),
30 machine_(machine),
31 cache_(zone()),
32 call_counts_(zone()) {}
33 MachineGraph(const MachineGraph&) = delete;
35
36 // Creates a new (unique) Int32Constant node.
37 Node* UniqueInt32Constant(int32_t value);
38
39 Node* UniqueInt64Constant(int64_t value);
40
41 // Creates an Int32Constant node, usually canonicalized.
42 Node* Int32Constant(int32_t value);
43 Node* Uint32Constant(uint32_t value) {
44 return Int32Constant(base::bit_cast<int32_t>(value));
45 }
46
47 // Creates a Int64Constant node, usually canonicalized.
48 Node* Int64Constant(int64_t value);
49 Node* Uint64Constant(uint64_t value) {
50 return Int64Constant(base::bit_cast<int64_t>(value));
51 }
52
53 // Creates an Int32Constant/Int64Constant node, depending on the word size of
54 // the target machine.
55 // TODO(turbofan): Code using Int32Constant/Int64Constant to store pointer
56 // constants is probably not serializable.
57 Node* IntPtrConstant(intptr_t value);
58 Node* UintPtrConstant(uintptr_t value);
59 Node* UniqueIntPtrConstant(intptr_t value);
60
61 Node* TaggedIndexConstant(intptr_t value);
62
63 Node* RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode);
64 Node* RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode);
65 Node* RelocatableIntPtrConstant(intptr_t value, RelocInfo::Mode rmode);
66 Node* RelocatableWasmBuiltinCallTarget(Builtin builtin);
67
68 // Creates a Float32Constant node, usually canonicalized.
69 Node* Float32Constant(float value);
70
71 // Creates a Float64Constant node, usually canonicalized.
72 Node* Float64Constant(double value);
73
74 // Creates a PointerConstant node.
75 Node* PointerConstant(intptr_t value);
76 template <typename T>
77 Node* PointerConstant(T* value) {
78 return PointerConstant(reinterpret_cast<intptr_t>(value));
79 }
80
81 // Creates an ExternalConstant node, usually canonicalized.
82 Node* ExternalConstant(ExternalReference ref);
83 Node* ExternalConstant(Runtime::FunctionId function_id);
84
85 // Global cache of the dead node.
87 return Dead_ ? Dead_ : Dead_ = graph_->NewNode(common_->Dead());
88 }
89
90 // Store and retrieve call count information.
91 void StoreCallCount(NodeId call_id, int count) {
92 call_counts_.Put(call_id, count);
93 }
94 int GetCallCount(NodeId call_id) { return call_counts_.Get(call_id); }
95 // Use this to keep the number of map rehashings to a minimum.
96 void ReserveCallCounts(size_t num_call_instructions) {
97 call_counts_.Reserve(num_call_instructions);
98 }
99
100 CommonOperatorBuilder* common() const { return common_; }
101 MachineOperatorBuilder* machine() const { return machine_; }
102 TFGraph* graph() const { return graph_; }
103 Zone* zone() const { return graph()->zone(); }
104
105 protected:
111 Node* Dead_ = nullptr;
112};
113
114} // namespace compiler
115} // namespace internal
116} // namespace v8
117
118#endif // V8_COMPILER_MACHINE_GRAPH_H_
TFGraph * graph
MachineGraph & operator=(const MachineGraph &)=delete
MachineGraph(TFGraph *graph, CommonOperatorBuilder *common, MachineOperatorBuilder *machine)
Node * Uint64Constant(uint64_t value)
NodeAuxDataMap< int, -1 > call_counts_
void StoreCallCount(NodeId call_id, int count)
CommonOperatorBuilder * common() const
MachineOperatorBuilder * machine() const
MachineOperatorBuilder * machine_
MachineGraph(const MachineGraph &)=delete
Node * Uint32Constant(uint32_t value)
void ReserveCallCounts(size_t num_call_instructions)
#define NON_EXPORTED_BASE(code)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
TFGraph * graph_