Commit f76fd377 by Jan Voung

Subzero: Do class definition cleanups for assembler files too.

Similar to https://codereview.chromium.org/656123003/, but cover some of the assembler files which were avoided to avoid conflicts. BUG=none R=stichnot@chromium.org Review URL: https://codereview.chromium.org/643903006
parent 198b2948
//===- subzero/src/IceMemoryRegion.cpp - Memory region --------------------===//
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
// //
// Modified by the Subzero authors. // Modified by the Subzero authors.
// //
//===- subzero/src/IceMemoryRegion.cpp - Memory region --------------------===// //===----------------------------------------------------------------------===//
// //
// The Subzero Code Generator // The Subzero Code Generator
// //
......
//===- subzero/src/IceMemoryRegion.h - Memory region ------------*- C++ -*-===//
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
// //
// Modified by the Subzero authors. // Modified by the Subzero authors.
// //
//===- subzero/src/IceMemoryRegion.h - Memory region ------------*- C++ -*-===// //===----------------------------------------------------------------------===//
// //
// The Subzero Code Generator // The Subzero Code Generator
// //
...@@ -30,14 +31,10 @@ namespace Ice { ...@@ -30,14 +31,10 @@ namespace Ice {
// of the region. // of the region.
class MemoryRegion { class MemoryRegion {
public: public:
MemoryRegion(const MemoryRegion &other) = default;
MemoryRegion &operator=(const MemoryRegion &other) = default;
MemoryRegion() : pointer_(NULL), size_(0) {} MemoryRegion() : pointer_(NULL), size_(0) {}
MemoryRegion(void *pointer, size_t size) : pointer_(pointer), size_(size) {} MemoryRegion(void *pointer, size_t size) : pointer_(pointer), size_(size) {}
MemoryRegion(const MemoryRegion &other) { *this = other; }
MemoryRegion &operator=(const MemoryRegion &other) {
pointer_ = other.pointer_;
size_ = other.size_;
return *this;
}
void *pointer() const { return pointer_; } void *pointer() const { return pointer_; }
size_t size() const { return size_; } size_t size() const { return size_; }
......
//===- subzero/src/assembler.cpp - Assembler base class -------------------===//
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
// //
// Modified by the Subzero authors. // Modified by the Subzero authors.
// //
//===- subzero/src/assembler.cpp - Assembler base class -------------------===// //===----------------------------------------------------------------------===//
// //
// The Subzero Code Generator // The Subzero Code Generator
// //
...@@ -27,7 +28,7 @@ static uintptr_t NewContents(Assembler &assembler, intptr_t capacity) { ...@@ -27,7 +28,7 @@ static uintptr_t NewContents(Assembler &assembler, intptr_t capacity) {
return result; return result;
} }
#if defined(DEBUG) #ifndef NDEBUG
AssemblerBuffer::EnsureCapacity::EnsureCapacity(AssemblerBuffer *buffer) { AssemblerBuffer::EnsureCapacity::EnsureCapacity(AssemblerBuffer *buffer) {
if (buffer->cursor() >= buffer->limit()) if (buffer->cursor() >= buffer->limit())
buffer->ExtendCapacity(); buffer->ExtendCapacity();
...@@ -53,7 +54,7 @@ AssemblerBuffer::EnsureCapacity::~EnsureCapacity() { ...@@ -53,7 +54,7 @@ AssemblerBuffer::EnsureCapacity::~EnsureCapacity() {
intptr_t delta = gap_ - ComputeGap(); intptr_t delta = gap_ - ComputeGap();
assert(delta <= kMinimumGap); assert(delta <= kMinimumGap);
} }
#endif #endif // !NDEBUG
AssemblerBuffer::AssemblerBuffer(Assembler &assembler) : assembler_(assembler) { AssemblerBuffer::AssemblerBuffer(Assembler &assembler) : assembler_(assembler) {
const intptr_t OneKB = 1024; const intptr_t OneKB = 1024;
...@@ -61,10 +62,10 @@ AssemblerBuffer::AssemblerBuffer(Assembler &assembler) : assembler_(assembler) { ...@@ -61,10 +62,10 @@ AssemblerBuffer::AssemblerBuffer(Assembler &assembler) : assembler_(assembler) {
contents_ = NewContents(assembler_, kInitialBufferCapacity); contents_ = NewContents(assembler_, kInitialBufferCapacity);
cursor_ = contents_; cursor_ = contents_;
limit_ = ComputeLimit(contents_, kInitialBufferCapacity); limit_ = ComputeLimit(contents_, kInitialBufferCapacity);
#if defined(DEBUG) #ifndef NDEBUG
has_ensured_capacity_ = false; has_ensured_capacity_ = false;
fixups_processed_ = false; fixups_processed_ = false;
#endif #endif // !NDEBUG
// Verify internal state. // Verify internal state.
assert(Capacity() == kInitialBufferCapacity); assert(Capacity() == kInitialBufferCapacity);
...@@ -93,9 +94,9 @@ void AssemblerBuffer::FinalizeInstructions(const MemoryRegion &instructions) { ...@@ -93,9 +94,9 @@ void AssemblerBuffer::FinalizeInstructions(const MemoryRegion &instructions) {
// Process fixups in the instructions. // Process fixups in the instructions.
ProcessFixups(instructions); ProcessFixups(instructions);
#if defined(DEBUG) #ifndef NDEBUG
fixups_processed_ = true; fixups_processed_ = true;
#endif #endif // !NDEBUG
} }
void AssemblerBuffer::ExtendCapacity() { void AssemblerBuffer::ExtendCapacity() {
......
//===- subzero/src/assembler.h - Integrated assembler -----------*- C++ -*-===//
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
// //
// Modified by the Subzero authors. // Modified by the Subzero authors.
// //
//===- subzero/src/assembler.h - Integrated assembler -----------*- C++ -*-===// //===----------------------------------------------------------------------===//
// //
// The Subzero Code Generator // The Subzero Code Generator
// //
...@@ -40,6 +41,9 @@ class MemoryRegion; ...@@ -40,6 +41,9 @@ class MemoryRegion;
// information that needs to be processed before finalizing the code // information that needs to be processed before finalizing the code
// into executable memory. // into executable memory.
class AssemblerFixup { class AssemblerFixup {
AssemblerFixup(const AssemblerFixup &) = delete;
AssemblerFixup &operator=(const AssemblerFixup &) = delete;
public: public:
virtual void Process(const MemoryRegion &region, intptr_t position) = 0; virtual void Process(const MemoryRegion &region, intptr_t position) = 0;
...@@ -64,13 +68,14 @@ private: ...@@ -64,13 +68,14 @@ private:
void set_position(intptr_t position) { position_ = position; } void set_position(intptr_t position) { position_ = position; }
AssemblerFixup(const AssemblerFixup &) = delete;
AssemblerFixup &operator=(const AssemblerFixup &) = delete;
friend class AssemblerBuffer; friend class AssemblerBuffer;
}; };
// Assembler buffers are used to emit binary code. They grow on demand. // Assembler buffers are used to emit binary code. They grow on demand.
class AssemblerBuffer { class AssemblerBuffer {
AssemblerBuffer(const AssemblerBuffer &) = delete;
AssemblerBuffer &operator=(const AssemblerBuffer &) = delete;
public: public:
AssemblerBuffer(Assembler &); AssemblerBuffer(Assembler &);
~AssemblerBuffer(); ~AssemblerBuffer();
...@@ -118,8 +123,11 @@ public: ...@@ -118,8 +123,11 @@ public:
// AssemblerBuffer::EnsureCapacity ensured(&buffer); // AssemblerBuffer::EnsureCapacity ensured(&buffer);
// ... emit bytes for single instruction ... // ... emit bytes for single instruction ...
#if defined(DEBUG) #ifndef NDEBUG
class EnsureCapacity { class EnsureCapacity {
EnsureCapacity(const EnsureCapacity &) = delete;
EnsureCapacity &operator=(const EnsureCapacity &) = delete;
public: public:
explicit EnsureCapacity(AssemblerBuffer *buffer); explicit EnsureCapacity(AssemblerBuffer *buffer);
~EnsureCapacity(); ~EnsureCapacity();
...@@ -133,8 +141,11 @@ public: ...@@ -133,8 +141,11 @@ public:
bool has_ensured_capacity_; bool has_ensured_capacity_;
bool HasEnsuredCapacity() const { return has_ensured_capacity_; } bool HasEnsuredCapacity() const { return has_ensured_capacity_; }
#else #else // NDEBUG
class EnsureCapacity { class EnsureCapacity {
EnsureCapacity(const EnsureCapacity &) = delete;
EnsureCapacity &operator=(const EnsureCapacity &) = delete;
public: public:
explicit EnsureCapacity(AssemblerBuffer *buffer) { explicit EnsureCapacity(AssemblerBuffer *buffer) {
if (buffer->cursor() >= buffer->limit()) if (buffer->cursor() >= buffer->limit())
...@@ -146,7 +157,7 @@ public: ...@@ -146,7 +157,7 @@ public:
// asserting that the user of the assembler buffer has ensured the // asserting that the user of the assembler buffer has ensured the
// capacity needed for emitting, we add a dummy method in non-debug mode. // capacity needed for emitting, we add a dummy method in non-debug mode.
bool HasEnsuredCapacity() const { return true; } bool HasEnsuredCapacity() const { return true; }
#endif #endif // NDEBUG
// Returns the position in the instruction stream. // Returns the position in the instruction stream.
intptr_t GetPosition() const { return cursor_ - contents_; } intptr_t GetPosition() const { return cursor_ - contents_; }
...@@ -165,9 +176,9 @@ private: ...@@ -165,9 +176,9 @@ private:
uintptr_t limit_; uintptr_t limit_;
Assembler &assembler_; Assembler &assembler_;
std::vector<AssemblerFixup *> fixups_; std::vector<AssemblerFixup *> fixups_;
#if defined(DEBUG) #ifndef NDEBUG
bool fixups_processed_; bool fixups_processed_;
#endif #endif // !NDEBUG
uintptr_t cursor() const { return cursor_; } uintptr_t cursor() const { return cursor_; }
uintptr_t limit() const { return limit_; } uintptr_t limit() const { return limit_; }
...@@ -191,6 +202,9 @@ private: ...@@ -191,6 +202,9 @@ private:
}; };
class Assembler { class Assembler {
Assembler(const Assembler &) = delete;
Assembler &operator=(const Assembler &) = delete;
public: public:
Assembler() {} Assembler() {}
~Assembler() {} ~Assembler() {}
...@@ -212,9 +226,6 @@ public: ...@@ -212,9 +226,6 @@ public:
private: private:
llvm::BumpPtrAllocator Allocator; llvm::BumpPtrAllocator Allocator;
Assembler(const Assembler &) = delete;
Assembler &operator=(const Assembler &) = delete;
}; };
} // end of namespace Ice } // end of namespace Ice
......
//===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===//
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
// //
// Modified by the Subzero authors. // Modified by the Subzero authors.
// //
//===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===// //===----------------------------------------------------------------------===//
// //
// The Subzero Code Generator // The Subzero Code Generator
// //
...@@ -26,6 +27,9 @@ namespace Ice { ...@@ -26,6 +27,9 @@ namespace Ice {
namespace x86 { namespace x86 {
class DirectCallRelocation : public AssemblerFixup { class DirectCallRelocation : public AssemblerFixup {
DirectCallRelocation(const DirectCallRelocation &) = delete;
DirectCallRelocation &operator=(const DirectCallRelocation &) = delete;
public: public:
static DirectCallRelocation *create(Assembler *Asm, FixupKind Kind, static DirectCallRelocation *create(Assembler *Asm, FixupKind Kind,
const ConstantRelocatable *Sym) { const ConstantRelocatable *Sym) {
...@@ -2320,6 +2324,11 @@ void AssemblerX86::xchg(Type Ty, const Address &addr, GPRRegister reg) { ...@@ -2320,6 +2324,11 @@ void AssemblerX86::xchg(Type Ty, const Address &addr, GPRRegister reg) {
EmitOperand(reg, addr); EmitOperand(reg, addr);
} }
void AssemblerX86::EmitSegmentOverride(uint8_t prefix) {
AssemblerBuffer::EnsureCapacity ensured(&buffer_);
EmitUint8(prefix);
}
void AssemblerX86::Align(intptr_t alignment, intptr_t offset) { void AssemblerX86::Align(intptr_t alignment, intptr_t offset) {
assert(llvm::isPowerOf2_32(alignment)); assert(llvm::isPowerOf2_32(alignment));
intptr_t pos = offset + buffer_.GetPosition(); intptr_t pos = offset + buffer_.GetPosition();
......
//===- subzero/src/assembler_ia32.h - Assembler for x86-32 ------*- C++ -*-===//
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
// //
// Modified by the Subzero authors. // Modified by the Subzero authors.
// //
//===- subzero/src/assembler_ia32.h - Assembler for x86-32 ----------------===// //===----------------------------------------------------------------------===//
// //
// The Subzero Code Generator // The Subzero Code Generator
// //
...@@ -45,6 +46,9 @@ const int MAX_NOP_SIZE = 8; ...@@ -45,6 +46,9 @@ const int MAX_NOP_SIZE = 8;
enum ScaleFactor { TIMES_1 = 0, TIMES_2 = 1, TIMES_4 = 2, TIMES_8 = 3 }; enum ScaleFactor { TIMES_1 = 0, TIMES_2 = 1, TIMES_4 = 2, TIMES_8 = 3 };
class DisplacementRelocation : public AssemblerFixup { class DisplacementRelocation : public AssemblerFixup {
DisplacementRelocation(const DisplacementRelocation &) = delete;
DisplacementRelocation &operator=(const DisplacementRelocation &) = delete;
public: public:
static DisplacementRelocation *create(Assembler *Asm, FixupKind Kind, static DisplacementRelocation *create(Assembler *Asm, FixupKind Kind,
const ConstantRelocatable *Sym) { const ConstantRelocatable *Sym) {
...@@ -61,17 +65,15 @@ public: ...@@ -61,17 +65,15 @@ public:
private: private:
DisplacementRelocation(FixupKind Kind, const ConstantRelocatable *Sym) DisplacementRelocation(FixupKind Kind, const ConstantRelocatable *Sym)
: AssemblerFixup(Kind, Sym) {} : AssemblerFixup(Kind, Sym) {}
DisplacementRelocation(const DisplacementRelocation &) = delete;
DisplacementRelocation &operator=(const DisplacementRelocation &) = delete;
}; };
class Immediate { class Immediate {
Immediate(const Immediate &) = delete;
Immediate &operator=(const Immediate &) = delete;
public: public:
explicit Immediate(int32_t value) : value_(value), fixup_(NULL) {} explicit Immediate(int32_t value) : value_(value), fixup_(NULL) {}
explicit Immediate(const Immediate &other)
: value_(other.value_), fixup_(other.fixup_) {}
explicit Immediate(AssemblerFixup *fixup) explicit Immediate(AssemblerFixup *fixup)
: value_(fixup->value()->getOffset()), fixup_(fixup) { : value_(fixup->value()->getOffset()), fixup_(fixup) {
// Use the Offset in the "value" for now. If the symbol is part of // Use the Offset in the "value" for now. If the symbol is part of
...@@ -98,6 +100,17 @@ private: ...@@ -98,6 +100,17 @@ private:
class Operand { class Operand {
public: public:
Operand(const Operand &other) : length_(other.length_), fixup_(other.fixup_) {
memmove(&encoding_[0], &other.encoding_[0], other.length_);
}
Operand &operator=(const Operand &other) {
length_ = other.length_;
fixup_ = other.fixup_;
memmove(&encoding_[0], &other.encoding_[0], other.length_);
return *this;
}
uint8_t mod() const { return (encoding_at(0) >> 6) & 3; } uint8_t mod() const { return (encoding_at(0) >> 6) & 3; }
GPRRegister rm() const { GPRRegister rm() const {
...@@ -128,17 +141,6 @@ public: ...@@ -128,17 +141,6 @@ public:
AssemblerFixup *fixup() const { return fixup_; } AssemblerFixup *fixup() const { return fixup_; }
Operand(const Operand &other) : length_(other.length_), fixup_(other.fixup_) {
memmove(&encoding_[0], &other.encoding_[0], other.length_);
}
Operand &operator=(const Operand &other) {
length_ = other.length_;
fixup_ = other.fixup_;
memmove(&encoding_[0], &other.encoding_[0], other.length_);
return *this;
}
protected: protected:
Operand() : length_(0), fixup_(NULL) {} // Needed by subclass Address. Operand() : length_(0), fixup_(NULL) {} // Needed by subclass Address.
...@@ -194,6 +196,13 @@ private: ...@@ -194,6 +196,13 @@ private:
class Address : public Operand { class Address : public Operand {
public: public:
Address(const Address &other) : Operand(other) {}
Address &operator=(const Address &other) {
Operand::operator=(other);
return *this;
}
Address(GPRRegister base, int32_t disp) { Address(GPRRegister base, int32_t disp) {
if (disp == 0 && base != RegX8632::Encoded_Reg_ebp) { if (disp == 0 && base != RegX8632::Encoded_Reg_ebp) {
SetModRM(0, base); SetModRM(0, base);
...@@ -236,13 +245,6 @@ public: ...@@ -236,13 +245,6 @@ public:
} }
} }
Address(const Address &other) : Operand(other) {}
Address &operator=(const Address &other) {
Operand::operator=(other);
return *this;
}
static Address Absolute(const uintptr_t addr) { static Address Absolute(const uintptr_t addr) {
Address result; Address result;
result.SetModRM(0, RegX8632::Encoded_Reg_ebp); result.SetModRM(0, RegX8632::Encoded_Reg_ebp);
...@@ -270,13 +272,16 @@ private: ...@@ -270,13 +272,16 @@ private:
}; };
class Label { class Label {
Label(const Label &) = delete;
Label &operator=(const Label &) = delete;
public: public:
Label() : position_(0), num_unresolved_(0) { Label() : position_(0), num_unresolved_(0) {
#ifdef DEBUG #ifndef NDEBUG
for (int i = 0; i < kMaxUnresolvedBranches; i++) { for (int i = 0; i < kMaxUnresolvedBranches; i++) {
unresolved_near_positions_[i] = -1; unresolved_near_positions_[i] = -1;
} }
#endif // DEBUG #endif // !NDEBUG
} }
~Label() { ~Label() {
...@@ -346,11 +351,12 @@ private: ...@@ -346,11 +351,12 @@ private:
intptr_t unresolved_near_positions_[kMaxUnresolvedBranches]; intptr_t unresolved_near_positions_[kMaxUnresolvedBranches];
friend class AssemblerX86; friend class AssemblerX86;
Label(const Label &) = delete;
Label &operator=(const Label &) = delete;
}; };
class AssemblerX86 : public Assembler { class AssemblerX86 : public Assembler {
AssemblerX86(const AssemblerX86 &) = delete;
AssemblerX86 &operator=(const AssemblerX86 &) = delete;
public: public:
explicit AssemblerX86(bool use_far_branches = false) : buffer_(*this) { explicit AssemblerX86(bool use_far_branches = false) : buffer_(*this) {
// This mode is only needed and implemented for MIPS and ARM. // This mode is only needed and implemented for MIPS and ARM.
...@@ -800,7 +806,7 @@ public: ...@@ -800,7 +806,7 @@ public:
cmpxchg(Ty, address, reg); cmpxchg(Ty, address, reg);
} }
void EmitSegmentOverride(uint8_t prefix) { EmitUint8(prefix); } void EmitSegmentOverride(uint8_t prefix);
intptr_t PreferredLoopAlignment() { return 16; } intptr_t PreferredLoopAlignment() { return 16; }
void Align(intptr_t alignment, intptr_t offset); void Align(intptr_t alignment, intptr_t offset);
...@@ -843,9 +849,6 @@ private: ...@@ -843,9 +849,6 @@ private:
GPRRegister shifter); GPRRegister shifter);
AssemblerBuffer buffer_; AssemblerBuffer buffer_;
AssemblerX86(const AssemblerX86 &) = delete;
AssemblerX86 &operator=(const AssemblerX86 &) = delete;
}; };
inline void AssemblerX86::EmitUint8(uint8_t value) { inline void AssemblerX86::EmitUint8(uint8_t value) {
......
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