From 9309d95b170ee7b605dbde114b88a57767cb48eb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 15 Apr 2019 05:27:32 -0400 Subject: [PATCH 1/2] ir/block: Default ctor and dtor in the cpp file Prevents potentially inlining allocation code everywhere. While we're at it, also explicitly delete/default the copy/move constructor/assignment operators to be explicit about them. --- src/frontend/ir/basic_block.cpp | 10 ++++++++++ src/frontend/ir/basic_block.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/frontend/ir/basic_block.cpp b/src/frontend/ir/basic_block.cpp index 998f7a3e..086d672d 100644 --- a/src/frontend/ir/basic_block.cpp +++ b/src/frontend/ir/basic_block.cpp @@ -20,6 +20,16 @@ namespace Dynarmic::IR { +Block::Block(const LocationDescriptor& location) + : location{location}, end_location{location}, + instruction_alloc_pool{std::make_unique(sizeof(Inst), 4096)} {} + +Block::~Block() = default; + +Block::Block(Block&&) = default; + +Block& Block::operator=(Block&&) = default; + void Block::AppendNewInst(Opcode opcode, std::initializer_list args) { PrependNewInst(end(), opcode, args); } diff --git a/src/frontend/ir/basic_block.h b/src/frontend/ir/basic_block.h index d28bcb25..eb27fd4d 100644 --- a/src/frontend/ir/basic_block.h +++ b/src/frontend/ir/basic_block.h @@ -39,8 +39,14 @@ public: using reverse_iterator = InstructionList::reverse_iterator; using const_reverse_iterator = InstructionList::const_reverse_iterator; - explicit Block(const LocationDescriptor& location) - : location(location), end_location(location) {} + explicit Block(const LocationDescriptor& location); + ~Block(); + + Block(const Block&) = delete; + Block& operator=(const Block&) = delete; + + Block(Block&&); + Block& operator=(Block&&); bool empty() const { return instructions.empty(); } size_type size() const { return instructions.size(); } @@ -145,7 +151,7 @@ private: /// List of instructions in this block. InstructionList instructions; /// Memory pool for instruction list - std::unique_ptr instruction_alloc_pool = std::make_unique(sizeof(Inst), 4096); + std::unique_ptr instruction_alloc_pool; /// Terminal instruction of this block. Terminal terminal = Term::Invalid{}; From 4fc531f71b139560b94c26f13799948990366183 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 15 Apr 2019 05:28:41 -0400 Subject: [PATCH 2/2] ir/basic_block: Forward declare headers where applicable Now that the constructor and destructors have been placed within the cpp file, we can forward declare the memory pool data structures. Now, a change to the memory pool code won't ripple across the entirety of the IR emitter. --- src/frontend/ir/basic_block.cpp | 4 +++- src/frontend/ir/basic_block.h | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/frontend/ir/basic_block.cpp b/src/frontend/ir/basic_block.cpp index 086d672d..02c6ce00 100644 --- a/src/frontend/ir/basic_block.cpp +++ b/src/frontend/ir/basic_block.cpp @@ -13,15 +13,17 @@ #include #include "common/assert.h" +#include "common/memory_pool.h" #include "frontend/A32/types.h" #include "frontend/A64/types.h" #include "frontend/ir/basic_block.h" +#include "frontend/ir/cond.h" #include "frontend/ir/opcodes.h" namespace Dynarmic::IR { Block::Block(const LocationDescriptor& location) - : location{location}, end_location{location}, + : location{location}, end_location{location}, cond{Cond::AL}, instruction_alloc_pool{std::make_unique(sizeof(Inst), 4096)} {} Block::~Block() = default; diff --git a/src/frontend/ir/basic_block.h b/src/frontend/ir/basic_block.h index eb27fd4d..ca91aacc 100644 --- a/src/frontend/ir/basic_block.h +++ b/src/frontend/ir/basic_block.h @@ -13,15 +13,18 @@ #include "common/common_types.h" #include "common/intrusive_list.h" -#include "common/memory_pool.h" -#include "frontend/ir/cond.h" #include "frontend/ir/location_descriptor.h" #include "frontend/ir/microinstruction.h" #include "frontend/ir/terminal.h" #include "frontend/ir/value.h" +namespace Dynarmic::Common { +class Pool; +} + namespace Dynarmic::IR { +enum class Cond; enum class Opcode; /** @@ -142,7 +145,7 @@ private: /// Description of the end location of this block LocationDescriptor end_location; /// Conditional to pass in order to execute this block - Cond cond = Cond::AL; + Cond cond; /// Block to execute next if `cond` did not pass. std::optional cond_failed = {}; /// Number of cycles this block takes to execute if the conditional fails.