V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
machine-graph.h
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/compiler/common-node-cache.h"
10 #include "src/compiler/common-operator.h"
11 #include "src/compiler/graph.h"
12 #include "src/compiler/machine-operator.h"
13 #include "src/globals.h"
14 #include "src/runtime/runtime.h"
15 
16 namespace v8 {
17 namespace internal {
18 namespace 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.
23 class V8_EXPORT_PRIVATE MachineGraph : public NON_EXPORTED_BASE(ZoneObject) {
24  public:
26  MachineOperatorBuilder* machine)
27  : graph_(graph), common_(common), machine_(machine), cache_(zone()) {}
28 
29  // Creates a Int32Constant node, usually canonicalized.
30  Node* Int32Constant(int32_t value);
31  Node* Uint32Constant(uint32_t value) {
32  return Int32Constant(bit_cast<int32_t>(value));
33  }
34 
35  // Creates a Int64Constant node, usually canonicalized.
36  Node* Int64Constant(int64_t value);
37  Node* Uint64Constant(uint64_t value) {
38  return Int64Constant(bit_cast<int64_t>(value));
39  }
40 
41  // Creates a Int32Constant/Int64Constant node, depending on the word size of
42  // the target machine.
43  // TODO(turbofan): Code using Int32Constant/Int64Constant to store pointer
44  // constants is probably not serializable.
45  Node* IntPtrConstant(intptr_t value);
46 
47  Node* RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode);
48  Node* RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode);
49  Node* RelocatableIntPtrConstant(intptr_t value, RelocInfo::Mode rmode);
50 
51  // Creates a Float32Constant node, usually canonicalized.
52  Node* Float32Constant(float value);
53 
54  // Creates a Float64Constant node, usually canonicalized.
55  Node* Float64Constant(double value);
56 
57  // Creates a PointerConstant node.
58  Node* PointerConstant(intptr_t value);
59  template <typename T>
60  Node* PointerConstant(T* value) {
61  return PointerConstant(bit_cast<intptr_t>(value));
62  }
63 
64  // Creates an ExternalConstant node, usually canonicalized.
65  Node* ExternalConstant(ExternalReference ref);
66  Node* ExternalConstant(Runtime::FunctionId function_id);
67 
68  // Global cache of the dead node.
69  Node* Dead() {
70  return Dead_ ? Dead_ : Dead_ = graph_->NewNode(common_->Dead());
71  }
72 
73  CommonOperatorBuilder* common() const { return common_; }
74  MachineOperatorBuilder* machine() const { return machine_; }
75  Graph* graph() const { return graph_; }
76  Zone* zone() const { return graph()->zone(); }
77 
78  protected:
79  Graph* graph_;
80  CommonOperatorBuilder* common_;
81  MachineOperatorBuilder* machine_;
82  CommonNodeCache cache_;
83  Node* Dead_ = nullptr;
84 
85  DISALLOW_COPY_AND_ASSIGN(MachineGraph);
86 };
87 
88 } // namespace compiler
89 } // namespace internal
90 } // namespace v8
91 
92 #endif // V8_COMPILER_MACHINE_GRAPH_H_
Definition: libplatform.h:13