Commit f91e8046 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Improve memory layout of Node class.

Also gets rid of the reinterpret_cast on this.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/828803004

Cr-Commit-Position: refs/heads/master@{#26103}
parent 9fbe8721
...@@ -12,15 +12,15 @@ namespace compiler { ...@@ -12,15 +12,15 @@ namespace compiler {
Node* Node::New(Zone* zone, NodeId id, const Operator* op, int input_count, Node* Node::New(Zone* zone, NodeId id, const Operator* op, int input_count,
Node** inputs, bool has_extensible_inputs) { Node** inputs, bool has_extensible_inputs) {
size_t node_size = sizeof(Node); size_t node_size = sizeof(Node) - sizeof(Input);
int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0; int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0;
size_t inputs_size = (input_count + reserve_input_count) * sizeof(Input); size_t inputs_size = std::max<size_t>(
(input_count + reserve_input_count) * sizeof(Input), sizeof(InputDeque*));
size_t uses_size = input_count * sizeof(Use); size_t uses_size = input_count * sizeof(Use);
int size = static_cast<int>(node_size + inputs_size + uses_size); int size = static_cast<int>(node_size + inputs_size + uses_size);
void* buffer = zone->New(size); void* buffer = zone->New(size);
Node* result = new (buffer) Node(id, op, input_count, reserve_input_count); Node* result = new (buffer) Node(id, op, input_count, reserve_input_count);
Input* input = Input* input = result->inputs_.static_;
reinterpret_cast<Input*>(reinterpret_cast<char*>(buffer) + node_size);
Use* use = Use* use =
reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size); reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size);
...@@ -175,9 +175,7 @@ Node::Node(NodeId id, const Operator* op, int input_count, ...@@ -175,9 +175,7 @@ Node::Node(NodeId id, const Operator* op, int input_count,
ReservedInputCountField::encode(reserved_input_count) | ReservedInputCountField::encode(reserved_input_count) |
HasAppendableInputsField::encode(false)), HasAppendableInputsField::encode(false)),
first_use_(nullptr), first_use_(nullptr),
last_use_(nullptr) { last_use_(nullptr) {}
inputs_.static_ = reinterpret_cast<Input*>(this + 1);
}
void Node::EnsureAppendableInputs(Zone* zone) { void Node::EnsureAppendableInputs(Zone* zone) {
......
...@@ -168,12 +168,13 @@ class Node FINAL { ...@@ -168,12 +168,13 @@ class Node FINAL {
inline void EnsureAppendableInputs(Zone* zone); inline void EnsureAppendableInputs(Zone* zone);
Input* GetInputRecordPtr(int index) const { Input* GetInputRecordPtr(int index) {
if (has_appendable_inputs()) { return has_appendable_inputs() ? &((*inputs_.appendable_)[index])
return &((*inputs_.appendable_)[index]); : &inputs_.static_[index];
} else { }
return &inputs_.static_[index]; const Input* GetInputRecordPtr(int index) const {
} return has_appendable_inputs() ? &((*inputs_.appendable_)[index])
: &inputs_.static_[index];
} }
inline void AppendUse(Use* const use); inline void AppendUse(Use* const use);
...@@ -224,16 +225,16 @@ class Node FINAL { ...@@ -224,16 +225,16 @@ class Node FINAL {
Mark mark_; Mark mark_;
NodeId const id_; NodeId const id_;
unsigned bit_field_; unsigned bit_field_;
Use* first_use_;
Use* last_use_;
union { union {
// When a node is initially allocated, it uses a static buffer to hold its // When a node is initially allocated, it uses a static buffer to hold its
// inputs under the assumption that the number of outputs will not increase. // inputs under the assumption that the number of outputs will not increase.
// When the first input is appended, the static buffer is converted into a // When the first input is appended, the static buffer is converted into a
// deque to allow for space-efficient growing. // deque to allow for space-efficient growing.
Input* static_; Input static_[1];
InputDeque* appendable_; InputDeque* appendable_;
} inputs_; } inputs_;
Use* first_use_;
Use* last_use_;
friend class Edge; friend class Edge;
friend class NodeMarkerBase; friend class NodeMarkerBase;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment