From 93205e395f777c1dd81d3f164cf9a4aec4bde45f Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 13 Apr 2016 11:59:46 +0100 Subject: Move Assemblers to the Arena. And clean up some APIs to return std::unique_ptr<> instead of raw pointers that don't communicate ownership. Change-Id: I3017302307a0253d661240750298802fb0d9585e --- compiler/utils/assembler.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'compiler/utils/assembler.h') diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h index 414ea7e660..4ea85a2c18 100644 --- a/compiler/utils/assembler.h +++ b/compiler/utils/assembler.h @@ -22,6 +22,8 @@ #include "arch/instruction_set.h" #include "arch/instruction_set_features.h" #include "arm/constants_arm.h" +#include "base/arena_allocator.h" +#include "base/arena_object.h" #include "base/logging.h" #include "base/macros.h" #include "debug/dwarf/debug_frame_opcode_writer.h" @@ -60,7 +62,7 @@ class AssemblerFixup { }; // Parent of all queued slow paths, emitted during finalization -class SlowPath { +class SlowPath : public DeletableArenaObject { public: SlowPath() : next_(nullptr) {} virtual ~SlowPath() {} @@ -85,9 +87,13 @@ class SlowPath { class AssemblerBuffer { public: - AssemblerBuffer(); + explicit AssemblerBuffer(ArenaAllocator* arena); ~AssemblerBuffer(); + ArenaAllocator* GetArena() { + return arena_; + } + // Basic support for emitting, loading, and storing. template void Emit(T value) { CHECK(HasEnsuredCapacity()); @@ -235,6 +241,7 @@ class AssemblerBuffer { // for a single, fast space check per instruction. static const int kMinimumGap = 32; + ArenaAllocator* arena_; uint8_t* contents_; uint8_t* cursor_; uint8_t* limit_; @@ -338,10 +345,12 @@ class DebugFrameOpCodeWriterForAssembler FINAL std::vector delayed_advance_pcs_; }; -class Assembler { +class Assembler : public DeletableArenaObject { public: - static Assembler* Create(InstructionSet instruction_set, - const InstructionSetFeatures* instruction_set_features = nullptr); + static std::unique_ptr Create( + ArenaAllocator* arena, + InstructionSet instruction_set, + const InstructionSetFeatures* instruction_set_features = nullptr); // Finalize the code; emit slow paths, fixup branches, add literal pool, etc. virtual void FinalizeCode() { buffer_.EmitSlowPaths(this); } @@ -504,7 +513,11 @@ class Assembler { DebugFrameOpCodeWriterForAssembler& cfi() { return cfi_; } protected: - Assembler() : buffer_(), cfi_(this) {} + explicit Assembler(ArenaAllocator* arena) : buffer_(arena), cfi_(this) {} + + ArenaAllocator* GetArena() { + return buffer_.GetArena(); + } AssemblerBuffer buffer_; -- cgit v1.2.3-59-g8ed1b