Skip to content

Commit

Permalink
[VM] Extract common code from Assembler to new AssemblerBase base class
Browse files Browse the repository at this point in the history
Issue dart-lang#33274

Change-Id: Ie7189081b3acac53a80a399b1353261c2312da79
Reviewed-on: https://dart-review.googlesource.com/c/81641
Commit-Queue: Martin Kustermann <[email protected]>
Reviewed-by: Vyacheslav Egorov <[email protected]>
  • Loading branch information
mkustermann authored and [email protected] committed Oct 29, 2018
1 parent 01082f9 commit e2243df
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 304 deletions.
12 changes: 6 additions & 6 deletions assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,31 @@ void AssemblerBuffer::EmitObject(const Object& object) {
}

// Shared macros are implemented here.
void Assembler::Unimplemented(const char* message) {
void AssemblerBase::Unimplemented(const char* message) {
const char* format = "Unimplemented: %s";
const intptr_t len = Utils::SNPrint(NULL, 0, format, message);
char* buffer = reinterpret_cast<char*>(malloc(len + 1));
Utils::SNPrint(buffer, len + 1, format, message);
Stop(buffer);
}

void Assembler::Untested(const char* message) {
void AssemblerBase::Untested(const char* message) {
const char* format = "Untested: %s";
const intptr_t len = Utils::SNPrint(NULL, 0, format, message);
char* buffer = reinterpret_cast<char*>(malloc(len + 1));
Utils::SNPrint(buffer, len + 1, format, message);
Stop(buffer);
}

void Assembler::Unreachable(const char* message) {
void AssemblerBase::Unreachable(const char* message) {
const char* format = "Unreachable: %s";
const intptr_t len = Utils::SNPrint(NULL, 0, format, message);
char* buffer = reinterpret_cast<char*>(malloc(len + 1));
Utils::SNPrint(buffer, len + 1, format, message);
Stop(buffer);
}

void Assembler::Comment(const char* format, ...) {
void AssemblerBase::Comment(const char* format, ...) {
if (EmittingComments()) {
char buffer[1024];

Expand All @@ -212,11 +212,11 @@ void Assembler::Comment(const char* format, ...) {
}
}

bool Assembler::EmittingComments() {
bool AssemblerBase::EmittingComments() {
return FLAG_code_comments || FLAG_disassemble || FLAG_disassemble_optimized;
}

const Code::Comments& Assembler::GetCodeComments() const {
const Code::Comments& AssemblerBase::GetCodeComments() const {
Code::Comments& comments = Code::Comments::New(comments_.length());

for (intptr_t i = 0; i < comments_.length(); i++) {
Expand Down
71 changes: 71 additions & 0 deletions assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,77 @@ class ObjectPoolWrapper : public ValueObject {

enum RestorePP { kRestoreCallerPP, kKeepCalleePP };

class AssemblerBase : public ValueObject {
public:
explicit AssemblerBase(ObjectPoolWrapper* object_pool_wrapper)
: prologue_offset_(-1),
has_single_entry_point_(true),
object_pool_wrapper_(object_pool_wrapper) {}
virtual ~AssemblerBase() {}

intptr_t CodeSize() const { return buffer_.Size(); }

uword CodeAddress(intptr_t offset) { return buffer_.Address(offset); }

ObjectPoolWrapper& object_pool_wrapper() { return *object_pool_wrapper_; }

intptr_t prologue_offset() const { return prologue_offset_; }
bool has_single_entry_point() const { return has_single_entry_point_; }

void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
static bool EmittingComments();

const Code::Comments& GetCodeComments() const;

void Unimplemented(const char* message);
void Untested(const char* message);
void Unreachable(const char* message);
virtual void Stop(const char* message) = 0;

void FinalizeInstructions(const MemoryRegion& region) {
buffer_.FinalizeInstructions(region);
}

// Count the fixups that produce a pointer offset, without processing
// the fixups.
intptr_t CountPointerOffsets() const { return buffer_.CountPointerOffsets(); }

const ZoneGrowableArray<intptr_t>& GetPointerOffsets() const {
return buffer_.pointer_offsets();
}

RawObjectPool* MakeObjectPool() {
if (object_pool_wrapper_ != nullptr) {
return object_pool_wrapper_->MakeObjectPool();
}
return nullptr;
}

protected:
AssemblerBuffer buffer_; // Contains position independent code.
int32_t prologue_offset_;
bool has_single_entry_point_;

private:
class CodeComment : public ZoneAllocated {
public:
CodeComment(intptr_t pc_offset, const String& comment)
: pc_offset_(pc_offset), comment_(comment) {}

intptr_t pc_offset() const { return pc_offset_; }
const String& comment() const { return comment_; }

private:
intptr_t pc_offset_;
const String& comment_;

DISALLOW_COPY_AND_ASSIGN(CodeComment);
};

GrowableArray<CodeComment*> comments_;
ObjectPoolWrapper* object_pool_wrapper_;
};

} // namespace dart

#if defined(TARGET_ARCH_IA32)
Expand Down
62 changes: 3 additions & 59 deletions assembler_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,12 @@ class FieldAddress : public Address {
}
};

class Assembler : public ValueObject {
class Assembler : public AssemblerBase {
public:
explicit Assembler(ObjectPoolWrapper* object_pool_wrapper,
bool use_far_branches = false)
: buffer_(),
object_pool_wrapper_(object_pool_wrapper),
prologue_offset_(-1),
has_single_entry_point_(true),
: AssemblerBase(object_pool_wrapper),
use_far_branches_(use_far_branches),
comments_(),
constant_pool_allowed_(false) {}

~Assembler() {}
Expand All @@ -364,25 +360,6 @@ class Assembler : public ValueObject {
}

// Misc. functionality
intptr_t CodeSize() const { return buffer_.Size(); }
intptr_t prologue_offset() const { return prologue_offset_; }
bool has_single_entry_point() const { return has_single_entry_point_; }

// Count the fixups that produce a pointer offset, without processing
// the fixups. On ARM there are no pointers in code.
intptr_t CountPointerOffsets() const { return 0; }

const ZoneGrowableArray<intptr_t>& GetPointerOffsets() const {
ASSERT(buffer_.pointer_offsets().length() == 0); // No pointers in code.
return buffer_.pointer_offsets();
}

ObjectPoolWrapper& object_pool_wrapper() { return *object_pool_wrapper_; }

RawObjectPool* MakeObjectPool() {
return object_pool_wrapper_->MakeObjectPool();
}

bool use_far_branches() const {
return FLAG_use_far_branches || use_far_branches_;
}
Expand All @@ -393,24 +370,12 @@ class Assembler : public ValueObject {
void set_use_far_branches(bool b) { use_far_branches_ = b; }
#endif // TESTING || DEBUG

void FinalizeInstructions(const MemoryRegion& region) {
buffer_.FinalizeInstructions(region);
}

// Debugging and bringup support.
void Breakpoint() { bkpt(0); }
void Stop(const char* message);
void Unimplemented(const char* message);
void Untested(const char* message);
void Unreachable(const char* message);
void Stop(const char* message) override;

static void InitializeMemoryWithBreakpoints(uword data, intptr_t length);

void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
static bool EmittingComments();

const Code::Comments& GetCodeComments() const;

static const char* RegisterName(Register reg);

static const char* FpuRegisterName(FpuRegister reg);
Expand Down Expand Up @@ -1160,10 +1125,6 @@ class Assembler : public ValueObject {
static int32_t DecodeBranchOffset(int32_t inst);

private:
AssemblerBuffer buffer_; // Contains position independent code.
ObjectPoolWrapper* object_pool_wrapper_;
int32_t prologue_offset_;
bool has_single_entry_point_;
bool use_far_branches_;

// If you are thinking of using one or both of these instructions directly,
Expand All @@ -1176,23 +1137,6 @@ class Assembler : public ValueObject {

void BranchLink(const ExternalLabel* label);

class CodeComment : public ZoneAllocated {
public:
CodeComment(intptr_t pc_offset, const String& comment)
: pc_offset_(pc_offset), comment_(comment) {}

intptr_t pc_offset() const { return pc_offset_; }
const String& comment() const { return comment_; }

private:
intptr_t pc_offset_;
const String& comment_;

DISALLOW_COPY_AND_ASSIGN(CodeComment);
};

GrowableArray<CodeComment*> comments_;

bool constant_pool_allowed_;

void LoadObjectHelper(Register rd,
Expand Down
6 changes: 1 addition & 5 deletions assembler_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ DEFINE_FLAG(bool, use_far_branches, false, "Always use far branches");

Assembler::Assembler(ObjectPoolWrapper* object_pool_wrapper,
bool use_far_branches)
: buffer_(),
object_pool_wrapper_(object_pool_wrapper),
prologue_offset_(-1),
has_single_entry_point_(true),
: AssemblerBase(object_pool_wrapper),
use_far_branches_(use_far_branches),
comments_(),
constant_pool_allowed_(false) {}

void Assembler::InitializeMemoryWithBreakpoints(uword data, intptr_t length) {
Expand Down
53 changes: 2 additions & 51 deletions assembler_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class Operand : public ValueObject {
friend class Assembler;
};

class Assembler : public ValueObject {
class Assembler : public AssemblerBase {
public:
explicit Assembler(ObjectPoolWrapper* object_pool_wrapper,
bool use_far_branches = false);
Expand Down Expand Up @@ -459,49 +459,20 @@ class Assembler : public ValueObject {
}

// Misc. functionality
intptr_t CodeSize() const { return buffer_.Size(); }
intptr_t prologue_offset() const { return prologue_offset_; }
bool has_single_entry_point() const { return has_single_entry_point_; }

// Count the fixups that produce a pointer offset, without processing
// the fixups. On ARM64 there are no pointers in code.
intptr_t CountPointerOffsets() const { return 0; }

const ZoneGrowableArray<intptr_t>& GetPointerOffsets() const {
ASSERT(buffer_.pointer_offsets().length() == 0); // No pointers in code.
return buffer_.pointer_offsets();
}

ObjectPoolWrapper& object_pool_wrapper() { return *object_pool_wrapper_; }

RawObjectPool* MakeObjectPool() {
return object_pool_wrapper_->MakeObjectPool();
}

bool use_far_branches() const {
return FLAG_use_far_branches || use_far_branches_;
}

void set_use_far_branches(bool b) { use_far_branches_ = b; }

void FinalizeInstructions(const MemoryRegion& region) {
buffer_.FinalizeInstructions(region);
}

// Debugging and bringup support.
void Breakpoint() { brk(0); }
void Stop(const char* message);
void Unimplemented(const char* message);
void Untested(const char* message);
void Unreachable(const char* message);
void Stop(const char* message) override;

static void InitializeMemoryWithBreakpoints(uword data, intptr_t length);

void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
static bool EmittingComments();

const Code::Comments& GetCodeComments() const;

static const char* RegisterName(Register reg);

static const char* FpuRegisterName(FpuRegister reg);
Expand Down Expand Up @@ -1625,29 +1596,9 @@ class Assembler : public ValueObject {
OperandSize sz);

private:
AssemblerBuffer buffer_; // Contains position independent code.
ObjectPoolWrapper* object_pool_wrapper_;
int32_t prologue_offset_;
bool has_single_entry_point_;
bool use_far_branches_;

class CodeComment : public ZoneAllocated {
public:
CodeComment(intptr_t pc_offset, const String& comment)
: pc_offset_(pc_offset), comment_(comment) {}

intptr_t pc_offset() const { return pc_offset_; }
const String& comment() const { return comment_; }

private:
intptr_t pc_offset_;
const String& comment_;

DISALLOW_COPY_AND_ASSIGN(CodeComment);
};

GrowableArray<CodeComment*> comments_;

bool constant_pool_allowed_;

void LoadWordFromPoolOffsetFixed(Register dst, uint32_t offset);
Expand Down
Loading

0 comments on commit e2243df

Please sign in to comment.