Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: src/interpreter/bytecode-pipeline.h

Issue 1947403002: [interpreter] Introduce bytecode generation pipeline. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate review comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/interpreter/bytecode-pipeline.h
diff --git a/src/interpreter/bytecode-pipeline.h b/src/interpreter/bytecode-pipeline.h
new file mode 100644
index 0000000000000000000000000000000000000000..81c13cc94364adade368a1ff00ab6b5704baa52d
--- /dev/null
+++ b/src/interpreter/bytecode-pipeline.h
@@ -0,0 +1,162 @@
+// Copyright 2015 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.
+
+#ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_
+#define V8_INTERPRETER_BYTECODE_PIPELINE_H_
+
+#include "src/interpreter/bytecode-register-allocator.h"
+#include "src/interpreter/bytecodes.h"
+#include "src/zone-containers.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+class BytecodeArrayBuilder;
+class SourcePositionTableBuilder;
+class TemporaryRegisterAllocator;
rmcilroy 2016/05/10 11:14:10 All these forward declarations seem to be unused.
oth 2016/05/11 13:17:31 Done.
+
+class BytecodeNodeAllocator;
+
+// Source code position information.
+class BytecodeSourceInfo final {
+ public:
+ static const int kUninitializedPosition = -1;
+
+ BytecodeSourceInfo(int position = kUninitializedPosition,
+ bool is_statement = false)
+ : source_position_(position), is_statement_(is_statement) {}
+
+ // Combine later source info with current.
+ void Update(const BytecodeSourceInfo& entry);
+
+ int source_position() const {
+ DCHECK(is_valid());
+ return source_position_;
+ }
+
+ bool is_statement() const { return is_valid() && is_statement_; }
+
+ bool is_valid() const { return source_position_ != kUninitializedPosition; }
+ void set_invalid() { source_position_ = kUninitializedPosition; }
+
+ bool operator==(const BytecodeSourceInfo& other) const {
+ return source_position_ == other.source_position_ &&
+ is_statement_ == other.is_statement_;
+ }
+ bool operator!=(const BytecodeSourceInfo& other) const {
+ return source_position_ != other.source_position_ ||
+ is_statement_ != other.is_statement_;
+ }
+
+ private:
+ int source_position_;
+ bool is_statement_;
+
+ DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo);
+};
+
+// A container for a generated bytecode, it's operands, and source information.
+// These must be allocated by a BytecodeNodeAllocator instance.
+class BytecodeNode final : ZoneObject {
+ public:
+ // Print to stream.
+ void Print(std::ostream& os);
+
+ // Return the size when this node is serialized to a bytecode array.
+ size_t Size() const;
+
+ // Return to node to allocator for re-use.
+ void Release();
+
+ Bytecode bytecode() const { return bytecode_; }
+ void set_bytecode(Bytecode bytecode);
+ void set_bytecode(Bytecode bytecode, uint32_t operand0,
+ OperandScale operand_scale);
+ void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
+ OperandScale operand_scale);
+ void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
+ uint32_t operand2, OperandScale operand_scale);
+ void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
+ uint32_t operand2, uint32_t operand3,
+ OperandScale operand_scale);
+
+ // Replaces the associated bytecode with an operand-compatible
+ // equivalent or Nop.
+ void replace_bytecode(Bytecode bytecode);
+
+ uint32_t* operands() { return operands_; }
+ const uint32_t* operands() const { return operands_; }
+
+ int operand_count() const { return Bytecodes::NumberOfOperands(bytecode_); }
+
+ OperandScale operand_scale() const { return operand_scale_; }
+
+ const BytecodeSourceInfo& source_info() const { return source_info_; }
+ BytecodeSourceInfo& source_info() { return source_info_; }
+
+ private:
+ static const int kInvalidPosition = kMinInt;
+ static const size_t kMaxOperands = 4;
+
+ friend class BytecodeNodeAllocator;
+ explicit BytecodeNode(BytecodeNodeAllocator* allocator);
+
+ Bytecode bytecode_;
+ uint32_t operands_[kMaxOperands];
+ OperandScale operand_scale_;
+ BytecodeSourceInfo source_info_;
+ BytecodeNodeAllocator* allocator_;
+ BytecodeNode* next_;
+
+ DISALLOW_COPY_AND_ASSIGN(BytecodeNode);
+};
+
+// Allocator for BytecodeNodes that zone allocates them when needed
+// and maintains a freelist to reduce number of allocations and limit
+// memory use.
+class BytecodeNodeAllocator final {
+ public:
+ explicit BytecodeNodeAllocator(Zone* zone)
+ : allocation_count_(0), free_list_(nullptr), zone_(zone) {}
+
+ BytecodeNode* Allocate();
+
+ private:
+ friend class BytecodeNode;
+ static const int kMaxDebugAllocations = 8;
+
+ void Release(BytecodeNode* node);
+
+ Zone* zone() const { return zone_; }
+
+ int allocation_count_;
+ BytecodeNode* free_list_;
+ Zone* zone_;
+
+ DISALLOW_COPY_AND_ASSIGN(BytecodeNodeAllocator);
+};
+
+// Interface for bytecode writers.
rmcilroy 2016/05/10 11:14:10 /bytecode writers/bytecode writer pipeline stages/
oth 2016/05/11 13:17:31 Done.
+class BytecodePipelineStage {
+ public:
+ virtual ~BytecodePipelineStage() {}
+
+ // Flush state for bytecode array offset calculation. Returns the
+ // current size of bytecode array.
+ virtual size_t FlushForOffset() = 0;
+
+ // Signal end of basic block.
+ virtual void LeaveBasicBlock() = 0;
+
+ // Write bytecode into pipeline. The callee owns node from here and
+ // the caller should not hold any references to it.
+ virtual void Write(BytecodeNode* node) = 0;
+};
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8
+
+#endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_

Powered by Google App Engine
This is Rietveld 408576698