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