2014-10-03 21:18:11 +08:00
|
|
|
//===-- HexagonMCCodeEmitter.cpp - Hexagon Target Descriptions ------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Hexagon.h"
|
|
|
|
#include "MCTargetDesc/HexagonBaseInfo.h"
|
|
|
|
#include "MCTargetDesc/HexagonMCCodeEmitter.h"
|
2015-02-20 03:00:00 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCTargetDesc.h"
|
2014-10-03 21:18:11 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "mccodeemitter"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace Hexagon;
|
|
|
|
|
|
|
|
STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// \brief 10.6 Instruction Packets
|
2014-10-05 12:54:54 +08:00
|
|
|
/// Possible values for instruction packet parse field.
|
2014-10-03 21:18:11 +08:00
|
|
|
enum class ParseField { duplex = 0x0, last0 = 0x1, last1 = 0x2, end = 0x3 };
|
|
|
|
/// \brief Returns the packet bits based on instruction position.
|
2015-02-20 05:10:50 +08:00
|
|
|
uint32_t getPacketBits(MCInst const &HMI) {
|
2014-10-03 21:18:11 +08:00
|
|
|
unsigned const ParseFieldOffset = 14;
|
2015-02-20 05:10:50 +08:00
|
|
|
ParseField Field = HexagonMCInstrInfo::isPacketEnd(HMI) ? ParseField::end : ParseField::last0;
|
2014-11-04 08:14:36 +08:00
|
|
|
return static_cast <uint32_t> (Field) << ParseFieldOffset;
|
2014-10-03 21:18:11 +08:00
|
|
|
}
|
|
|
|
void emitLittleEndian(uint64_t Binary, raw_ostream &OS) {
|
|
|
|
OS << static_cast<uint8_t>((Binary >> 0x00) & 0xff);
|
|
|
|
OS << static_cast<uint8_t>((Binary >> 0x08) & 0xff);
|
|
|
|
OS << static_cast<uint8_t>((Binary >> 0x10) & 0xff);
|
|
|
|
OS << static_cast<uint8_t>((Binary >> 0x18) & 0xff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HexagonMCCodeEmitter::HexagonMCCodeEmitter(MCInstrInfo const &aMII,
|
|
|
|
MCSubtargetInfo const &aMST,
|
|
|
|
MCContext &aMCT)
|
2015-02-20 03:00:00 +08:00
|
|
|
: MST(aMST), MCT(aMCT), MCII (aMII) {}
|
2014-10-03 21:18:11 +08:00
|
|
|
|
|
|
|
void HexagonMCCodeEmitter::EncodeInstruction(MCInst const &MI, raw_ostream &OS,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
MCSubtargetInfo const &STI) const {
|
2015-02-20 05:10:50 +08:00
|
|
|
uint64_t Binary = getBinaryCodeForInstr(MI, Fixups, STI) | getPacketBits(MI);
|
|
|
|
assert(HexagonMCInstrInfo::getDesc(MCII, MI).getSize() == 4 &&
|
2015-02-20 03:00:00 +08:00
|
|
|
"All instructions should be 32bit");
|
2015-02-22 17:58:29 +08:00
|
|
|
(void)&MCII;
|
2014-10-03 21:18:11 +08:00
|
|
|
emitLittleEndian(Binary, OS);
|
|
|
|
++MCNumEmitted;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
HexagonMCCodeEmitter::getMachineOpValue(MCInst const &MI, MCOperand const &MO,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
MCSubtargetInfo const &STI) const {
|
|
|
|
if (MO.isReg())
|
|
|
|
return MCT.getRegisterInfo()->getEncodingValue(MO.getReg());
|
|
|
|
if (MO.isImm())
|
|
|
|
return static_cast<unsigned>(MO.getImm());
|
2015-01-01 01:14:35 +08:00
|
|
|
llvm_unreachable("Only Immediates and Registers implemented right now");
|
2014-10-03 21:18:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MCSubtargetInfo const &HexagonMCCodeEmitter::getSubtargetInfo() const {
|
|
|
|
return MST;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCCodeEmitter *llvm::createHexagonMCCodeEmitter(MCInstrInfo const &MII,
|
|
|
|
MCRegisterInfo const &MRI,
|
|
|
|
MCSubtargetInfo const &MST,
|
|
|
|
MCContext &MCT) {
|
|
|
|
return new HexagonMCCodeEmitter(MII, MST, MCT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "HexagonGenMCCodeEmitter.inc"
|