Commit 2da710ce by John Porto

Enables llvm dyn_cast for Assemblers.

IceCfg::getAssembler() is a template that simply static_casts the CFG's assembler. This could potentially be problematic in the future, so we enabled the (relatively) cheap llvm dyn_cast operator for Assemblers. This CL also renames assembler_mips32.h to IceAssemblerMIPS32.h. BUG= R=stichnot@chromium.org Review URL: https://codereview.chromium.org/1211863004.
parent 40df458a
...@@ -144,11 +144,18 @@ private: ...@@ -144,11 +144,18 @@ private:
}; };
class Assembler { class Assembler {
Assembler() = delete;
Assembler(const Assembler &) = delete; Assembler(const Assembler &) = delete;
Assembler &operator=(const Assembler &) = delete; Assembler &operator=(const Assembler &) = delete;
public: public:
Assembler() : Allocator(), Buffer(*this) {} enum AssemblerKind {
Asm_ARM32,
Asm_MIPS32,
Asm_X8632,
Asm_X8664,
};
virtual ~Assembler() = default; virtual ~Assembler() = default;
// Allocate a chunk of bytes using the per-Assembler allocator. // Allocate a chunk of bytes using the per-Assembler allocator.
...@@ -203,7 +210,15 @@ public: ...@@ -203,7 +210,15 @@ public:
void setPreliminary(bool Value) { Preliminary = Value; } void setPreliminary(bool Value) { Preliminary = Value; }
bool getPreliminary() const { return Preliminary; } bool getPreliminary() const { return Preliminary; }
AssemblerKind getKind() const { return Kind; }
protected:
explicit Assembler(AssemblerKind Kind)
: Kind(Kind), Allocator(), Buffer(*this) {}
private: private:
const AssemblerKind Kind;
ArenaAllocator<32 * 1024> Allocator; ArenaAllocator<32 * 1024> Allocator;
// FunctionName and IsInternal are transferred from the original Cfg // FunctionName and IsInternal are transferred from the original Cfg
// object, since the Cfg object may be deleted by the time the // object, since the Cfg object may be deleted by the time the
......
...@@ -34,7 +34,8 @@ class AssemblerARM32 : public Assembler { ...@@ -34,7 +34,8 @@ class AssemblerARM32 : public Assembler {
AssemblerARM32 &operator=(const AssemblerARM32 &) = delete; AssemblerARM32 &operator=(const AssemblerARM32 &) = delete;
public: public:
explicit AssemblerARM32(bool use_far_branches = false) : Assembler() { explicit AssemblerARM32(bool use_far_branches = false)
: Assembler(Asm_ARM32) {
// This mode is only needed and implemented for MIPS and ARM. // This mode is only needed and implemented for MIPS and ARM.
assert(!use_far_branches); assert(!use_far_branches);
(void)use_far_branches; (void)use_far_branches;
...@@ -68,6 +69,10 @@ public: ...@@ -68,6 +69,10 @@ public:
(void)Kind; (void)Kind;
llvm_unreachable("Not yet implemented."); llvm_unreachable("Not yet implemented.");
} }
static bool classof(const Assembler *Asm) {
return Asm->getKind() == Asm_ARM32;
}
}; };
} // end of namespace ARM32 } // end of namespace ARM32
......
//===- subzero/src/assembler_mips.h - Assembler for MIPS --------*- C++ -*-===// //===- subzero/src/IceAssemblerMIPS32.h - Assembler for MIPS ----*- 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
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef SUBZERO_SRC_ASSEMBLER_MIPS32_H #ifndef SUBZERO_SRC_ICEASSEMBLERMIPS32_H
#define SUBZERO_SRC_ASSEMBLER_MIPS32_H #define SUBZERO_SRC_ICEASSEMBLERMIPS32_H
#include "IceAssembler.h" #include "IceAssembler.h"
#include "IceDefs.h" #include "IceDefs.h"
...@@ -34,7 +34,8 @@ class AssemblerMIPS32 : public Assembler { ...@@ -34,7 +34,8 @@ class AssemblerMIPS32 : public Assembler {
AssemblerMIPS32 &operator=(const AssemblerMIPS32 &) = delete; AssemblerMIPS32 &operator=(const AssemblerMIPS32 &) = delete;
public: public:
explicit AssemblerMIPS32(bool use_far_branches = false) : Assembler() { explicit AssemblerMIPS32(bool use_far_branches = false)
: Assembler(Asm_MIPS32) {
// This mode is only needed and implemented for MIPS32 and ARM. // This mode is only needed and implemented for MIPS32 and ARM.
assert(!use_far_branches); assert(!use_far_branches);
(void)use_far_branches; (void)use_far_branches;
...@@ -67,9 +68,13 @@ public: ...@@ -67,9 +68,13 @@ public:
(void)Kind; (void)Kind;
llvm::report_fatal_error("Not yet implemented."); llvm::report_fatal_error("Not yet implemented.");
} }
static bool classof(const Assembler *Asm) {
return Asm->getKind() == Asm_MIPS32;
}
}; };
} // end of namespace MIPS32 } // end of namespace MIPS32
} // end of namespace Ice } // end of namespace Ice
#endif // SUBZERO_SRC_ASSEMBLER_MIPS32_H #endif // SUBZERO_SRC_ICEASSEMBLERMIPS32_H
...@@ -337,7 +337,8 @@ class AssemblerX8632 : public Assembler { ...@@ -337,7 +337,8 @@ class AssemblerX8632 : public Assembler {
AssemblerX8632 &operator=(const AssemblerX8632 &) = delete; AssemblerX8632 &operator=(const AssemblerX8632 &) = delete;
public: public:
explicit AssemblerX8632(bool use_far_branches = false) : Assembler() { explicit AssemblerX8632(bool use_far_branches = false)
: Assembler(Asm_X8632) {
// This mode is only needed and implemented for MIPS and ARM. // This mode is only needed and implemented for MIPS and ARM.
assert(!use_far_branches); assert(!use_far_branches);
(void)use_far_branches; (void)use_far_branches;
...@@ -377,6 +378,10 @@ public: ...@@ -377,6 +378,10 @@ public:
return Kind == llvm::ELF::R_386_PC32; return Kind == llvm::ELF::R_386_PC32;
} }
static bool classof(const Assembler *Asm) {
return Asm->getKind() == Asm_X8632;
}
// Operations to emit GPR instructions (and dispatch on operand type). // Operations to emit GPR instructions (and dispatch on operand type).
typedef void (AssemblerX8632::*TypedEmitGPR)(Type, GPRRegister); typedef void (AssemblerX8632::*TypedEmitGPR)(Type, GPRRegister);
typedef void (AssemblerX8632::*TypedEmitAddr)(Type, const Address &); typedef void (AssemblerX8632::*TypedEmitAddr)(Type, const Address &);
......
...@@ -25,7 +25,8 @@ class AssemblerX8664 final : public Assembler { ...@@ -25,7 +25,8 @@ class AssemblerX8664 final : public Assembler {
AssemblerX8664 &operator=(const AssemblerX8664 &) = delete; AssemblerX8664 &operator=(const AssemblerX8664 &) = delete;
public: public:
explicit AssemblerX8664(bool use_far_branches = false) : Assembler() { explicit AssemblerX8664(bool use_far_branches = false)
: Assembler(Asm_X8664) {
assert(!use_far_branches); assert(!use_far_branches);
(void)use_far_branches; (void)use_far_branches;
llvm::report_fatal_error("Not yet implemented"); llvm::report_fatal_error("Not yet implemented");
...@@ -40,6 +41,10 @@ public: ...@@ -40,6 +41,10 @@ public:
llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const override; llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const override;
void bindCfgNodeLabel(SizeT NodeNumber) override; void bindCfgNodeLabel(SizeT NodeNumber) override;
bool fixupIsPCRel(FixupKind Kind) const override; bool fixupIsPCRel(FixupKind Kind) const override;
static bool classof(const Assembler *Asm) {
return Asm->getKind() == Asm_X8664;
}
}; };
} // end of namespace X8664 } // end of namespace X8664
......
...@@ -127,7 +127,7 @@ public: ...@@ -127,7 +127,7 @@ public:
VariablesMetadata *getVMetadata() const { return VMetadata.get(); } VariablesMetadata *getVMetadata() const { return VMetadata.get(); }
Liveness *getLiveness() const { return Live.get(); } Liveness *getLiveness() const { return Live.get(); }
template <typename T = Assembler> T *getAssembler() const { template <typename T = Assembler> T *getAssembler() const {
return static_cast<T *>(TargetAssembler.get()); return llvm::dyn_cast<T>(TargetAssembler.get());
} }
Assembler *releaseAssembler() { return TargetAssembler.release(); } Assembler *releaseAssembler() { return TargetAssembler.release(); }
std::unique_ptr<VariableDeclarationList> getGlobalInits() { std::unique_ptr<VariableDeclarationList> getGlobalInits() {
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#include "IceTargetLowering.h" #include "IceTargetLowering.h"
#include "IceAssemblerARM32.h" #include "IceAssemblerARM32.h"
#include "IceAssemblerMIPS32.h"
#include "IceAssemblerX8632.h" #include "IceAssemblerX8632.h"
#include "IceAssemblerX8664.h" #include "IceAssemblerX8664.h"
#include "assembler_mips32.h"
#include "IceCfg.h" // setError() #include "IceCfg.h" // setError()
#include "IceCfgNode.h" #include "IceCfgNode.h"
#include "IceGlobalInits.h" #include "IceGlobalInits.h"
...@@ -519,9 +519,8 @@ void TargetDataLowering::emitGlobal(const VariableDeclaration &Var, ...@@ -519,9 +519,8 @@ void TargetDataLowering::emitGlobal(const VariableDeclaration &Var,
Var.getInitializers()) { Var.getInitializers()) {
switch (Init->getKind()) { switch (Init->getKind()) {
case VariableDeclaration::Initializer::DataInitializerKind: { case VariableDeclaration::Initializer::DataInitializerKind: {
const auto &Data = const auto &Data = llvm::cast<VariableDeclaration::DataInitializer>(
llvm::cast<VariableDeclaration::DataInitializer>(Init.get()) Init.get())->getContents();
->getContents();
for (SizeT i = 0; i < Init->getNumBytes(); ++i) { for (SizeT i = 0; i < Init->getNumBytes(); ++i) {
Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
} }
......
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