//===- subzero/src/IceAssemblerMIPS32.cpp - MIPS32 Assembler --------------===// // // The Subzero Code Generator // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// /// /// \file /// \brief Implements the Assembler class for MIPS32. /// //===----------------------------------------------------------------------===// #include "IceAssemblerMIPS32.h" #include "IceCfgNode.h" #include "IceRegistersMIPS32.h" #include "IceUtils.h" namespace { using namespace Ice; using namespace Ice::MIPS32; // Offset modifier to current PC for next instruction. static constexpr IOffsetT kPCReadOffset = 4; // Mask to pull out PC offset from branch instruction. static constexpr int kBranchOffsetBits = 16; static constexpr IOffsetT kBranchOffsetMask = 0x0000ffff; } // end of anonymous namespace namespace Ice { namespace MIPS32 { void AssemblerMIPS32::emitTextInst(const std::string &Text, SizeT InstSize) { AssemblerFixup *F = createTextFixup(Text, InstSize); emitFixup(F); for (SizeT I = 0; I < InstSize; ++I) { AssemblerBuffer::EnsureCapacity ensured(&Buffer); Buffer.emit(0); } } namespace { // TEQ $0, $0 - Trap if equal static constexpr uint8_t TrapBytesRaw[] = {0x00, 0x00, 0x00, 0x34}; const auto TrapBytes = llvm::ArrayRef(TrapBytesRaw, llvm::array_lengthof(TrapBytesRaw)); } // end of anonymous namespace llvm::ArrayRef AssemblerMIPS32::getNonExecBundlePadding() const { return TrapBytes; } void AssemblerMIPS32::trap() { AssemblerBuffer::EnsureCapacity ensured(&Buffer); for (const uint8_t &Byte : reverse_range(TrapBytes)) Buffer.emit(Byte); } void AssemblerMIPS32::nop() { emitInst(0); } void AssemblerMIPS32::padWithNop(intptr_t Padding) { constexpr intptr_t InstWidth = sizeof(IValueT); assert(Padding % InstWidth == 0 && "Padding not multiple of instruction size"); for (intptr_t i = 0; i < Padding; i += InstWidth) nop(); } Label *AssemblerMIPS32::getOrCreateLabel(SizeT Number, LabelVector &Labels) { Label *L = nullptr; if (Number == Labels.size()) { L = new (this->allocate