Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
//===-- PPCMCCodeEmitter.cpp - Convert PPC code to machine code -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the PPCMCCodeEmitter class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "mccodeemitter"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "MCTargetDesc/PPCMCTargetDesc.h"
|
2011-07-26 03:53:23 +08:00
|
|
|
#include "MCTargetDesc/PPCBaseInfo.h"
|
|
|
|
#include "MCTargetDesc/PPCFixupKinds.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
2012-10-25 20:27:42 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class PPCMCCodeEmitter : public MCCodeEmitter {
|
2012-09-16 01:09:36 +08:00
|
|
|
PPCMCCodeEmitter(const PPCMCCodeEmitter &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const PPCMCCodeEmitter &) LLVM_DELETED_FUNCTION;
|
|
|
|
|
2012-10-25 20:27:42 +08:00
|
|
|
const MCSubtargetInfo &STI;
|
|
|
|
Triple TT;
|
|
|
|
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
public:
|
2011-07-11 11:57:24 +08:00
|
|
|
PPCMCCodeEmitter(const MCInstrInfo &mcii, const MCSubtargetInfo &sti,
|
2012-10-25 20:27:42 +08:00
|
|
|
MCContext &ctx)
|
|
|
|
: STI(sti), TT(STI.getTargetTriple()) {
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~PPCMCCodeEmitter() {}
|
2010-11-15 13:19:25 +08:00
|
|
|
|
2012-10-25 20:27:42 +08:00
|
|
|
bool is64BitMode() const {
|
|
|
|
return (STI.getFeatureBits() & PPC::Feature64Bit) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSVR4ABI() const {
|
|
|
|
return TT.isMacOSX() == 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 14:09:35 +08:00
|
|
|
unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
|
|
|
unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
2010-11-15 14:33:39 +08:00
|
|
|
unsigned getHA16Encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
|
|
|
unsigned getLO16Encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
split out an encoder for memri operands, allowing a relocation to be plopped
into the immediate field. This allows us to encode stuff like this:
lbz r3, lo16(__ZL4init)(r4) ; globalopt.cpp:5
; encoding: [0x88,0x64,A,A]
; fixup A - offset: 0, value: lo16(__ZL4init), kind: fixup_ppc_lo16
stw r3, lo16(__ZL1s)(r5) ; globalopt.cpp:6
; encoding: [0x90,0x65,A,A]
; fixup A - offset: 0, value: lo16(__ZL1s), kind: fixup_ppc_lo16
With this, we should have a completely function MCCodeEmitter for PPC, wewt.
llvm-svn: 119134
2010-11-15 16:22:03 +08:00
|
|
|
unsigned getMemRIEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
2010-11-15 16:02:41 +08:00
|
|
|
unsigned getMemRIXEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
2010-11-15 13:19:25 +08:00
|
|
|
unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
|
|
|
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
/// getMachineOpValue - Return binary encoding of operand. If the machine
|
|
|
|
/// operand requires relocation, record the relocation and return zero.
|
|
|
|
unsigned getMachineOpValue(const MCInst &MI,const MCOperand &MO,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
|
|
|
|
|
|
|
// getBinaryCodeForInstr - TableGen'erated function for getting the
|
|
|
|
// binary encoding for an instruction.
|
2012-01-25 02:37:29 +08:00
|
|
|
uint64_t getBinaryCodeForInstr(const MCInst &MI,
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const;
|
|
|
|
void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
2012-10-25 22:29:13 +08:00
|
|
|
uint64_t Bits = getBinaryCodeForInstr(MI, Fixups);
|
|
|
|
|
|
|
|
// BL8_NOPELF and BLA8_NOP_ELF is both size of 8 bacause of the
|
|
|
|
// following 'nop'.
|
|
|
|
unsigned Size = 4; // FIXME: Have Desc.getSize() return the correct value!
|
|
|
|
unsigned Opcode = MI.getOpcode();
|
|
|
|
if (Opcode == PPC::BL8_NOP_ELF || Opcode == PPC::BLA8_NOP_ELF)
|
|
|
|
Size = 8;
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
|
|
|
|
// Output the constant in big endian byte order.
|
2012-10-25 22:29:13 +08:00
|
|
|
int ShiftValue = (Size * 8) - 8;
|
|
|
|
for (unsigned i = 0; i != Size; ++i) {
|
|
|
|
OS << (char)(Bits >> ShiftValue);
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
Bits <<= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
++MCNumEmitted; // Keep track of the # of mi's emitted.
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2011-07-11 11:57:24 +08:00
|
|
|
MCCodeEmitter *llvm::createPPCMCCodeEmitter(const MCInstrInfo &MCII,
|
2012-05-16 01:35:52 +08:00
|
|
|
const MCRegisterInfo &MRI,
|
2011-07-11 11:57:24 +08:00
|
|
|
const MCSubtargetInfo &STI,
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
MCContext &Ctx) {
|
2011-07-11 11:57:24 +08:00
|
|
|
return new PPCMCCodeEmitter(MCII, STI, Ctx);
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
}
|
|
|
|
|
2010-11-15 13:57:53 +08:00
|
|
|
unsigned PPCMCCodeEmitter::
|
2010-11-15 14:09:35 +08:00
|
|
|
getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
2010-11-15 13:57:53 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups);
|
|
|
|
|
|
|
|
// Add a fixup for the branch target.
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_br24));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 14:09:35 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getCondBrEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups);
|
|
|
|
|
2010-11-15 14:12:22 +08:00
|
|
|
// Add a fixup for the branch target.
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_brcond14));
|
2010-11-15 14:09:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 14:33:39 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getHA16Encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups);
|
|
|
|
|
|
|
|
// Add a fixup for the branch target.
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_ha16));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PPCMCCodeEmitter::getLO16Encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups);
|
|
|
|
|
|
|
|
// Add a fixup for the branch target.
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_lo16));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
split out an encoder for memri operands, allowing a relocation to be plopped
into the immediate field. This allows us to encode stuff like this:
lbz r3, lo16(__ZL4init)(r4) ; globalopt.cpp:5
; encoding: [0x88,0x64,A,A]
; fixup A - offset: 0, value: lo16(__ZL4init), kind: fixup_ppc_lo16
stw r3, lo16(__ZL1s)(r5) ; globalopt.cpp:6
; encoding: [0x90,0x65,A,A]
; fixup A - offset: 0, value: lo16(__ZL1s), kind: fixup_ppc_lo16
With this, we should have a completely function MCCodeEmitter for PPC, wewt.
llvm-svn: 119134
2010-11-15 16:22:03 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getMemRIEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
|
|
|
// Encode (imm, reg) as a memri, which has the low 16-bits as the
|
|
|
|
// displacement and the next 5 bits as the register #.
|
|
|
|
assert(MI.getOperand(OpNo+1).isReg());
|
|
|
|
unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups) << 16;
|
|
|
|
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
if (MO.isImm())
|
|
|
|
return (getMachineOpValue(MI, MO, Fixups) & 0xFFFF) | RegBits;
|
|
|
|
|
|
|
|
// Add a fixup for the displacement field.
|
2012-10-25 20:27:42 +08:00
|
|
|
if (isSVR4ABI() && is64BitMode())
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_toc16));
|
|
|
|
else
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_lo16));
|
split out an encoder for memri operands, allowing a relocation to be plopped
into the immediate field. This allows us to encode stuff like this:
lbz r3, lo16(__ZL4init)(r4) ; globalopt.cpp:5
; encoding: [0x88,0x64,A,A]
; fixup A - offset: 0, value: lo16(__ZL4init), kind: fixup_ppc_lo16
stw r3, lo16(__ZL1s)(r5) ; globalopt.cpp:6
; encoding: [0x90,0x65,A,A]
; fixup A - offset: 0, value: lo16(__ZL1s), kind: fixup_ppc_lo16
With this, we should have a completely function MCCodeEmitter for PPC, wewt.
llvm-svn: 119134
2010-11-15 16:22:03 +08:00
|
|
|
return RegBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-15 16:02:41 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getMemRIXEncoding(const MCInst &MI, unsigned OpNo,
|
2010-11-15 14:33:39 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
2010-11-15 16:02:41 +08:00
|
|
|
// Encode (imm, reg) as a memrix, which has the low 14-bits as the
|
|
|
|
// displacement and the next 5 bits as the register #.
|
split out an encoder for memri operands, allowing a relocation to be plopped
into the immediate field. This allows us to encode stuff like this:
lbz r3, lo16(__ZL4init)(r4) ; globalopt.cpp:5
; encoding: [0x88,0x64,A,A]
; fixup A - offset: 0, value: lo16(__ZL4init), kind: fixup_ppc_lo16
stw r3, lo16(__ZL1s)(r5) ; globalopt.cpp:6
; encoding: [0x90,0x65,A,A]
; fixup A - offset: 0, value: lo16(__ZL1s), kind: fixup_ppc_lo16
With this, we should have a completely function MCCodeEmitter for PPC, wewt.
llvm-svn: 119134
2010-11-15 16:22:03 +08:00
|
|
|
assert(MI.getOperand(OpNo+1).isReg());
|
2010-11-15 16:02:41 +08:00
|
|
|
unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups) << 14;
|
|
|
|
|
2010-11-15 14:33:39 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2010-11-15 16:02:41 +08:00
|
|
|
if (MO.isImm())
|
|
|
|
return (getMachineOpValue(MI, MO, Fixups) & 0x3FFF) | RegBits;
|
2010-11-15 14:33:39 +08:00
|
|
|
|
|
|
|
// Add a fixup for the branch target.
|
2012-10-25 20:27:42 +08:00
|
|
|
if (isSVR4ABI() && is64BitMode())
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_toc16_ds));
|
|
|
|
else
|
|
|
|
Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
|
|
|
|
(MCFixupKind)PPC::fixup_ppc_lo14));
|
2010-11-15 16:02:41 +08:00
|
|
|
return RegBits;
|
2010-11-15 14:33:39 +08:00
|
|
|
}
|
|
|
|
|
2010-11-15 14:09:35 +08:00
|
|
|
|
2010-11-15 13:19:25 +08:00
|
|
|
unsigned PPCMCCodeEmitter::
|
|
|
|
get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2012-10-09 02:25:11 +08:00
|
|
|
assert((MI.getOpcode() == PPC::MTCRF ||
|
|
|
|
MI.getOpcode() == PPC::MFOCRF ||
|
|
|
|
MI.getOpcode() == PPC::MTCRF8) &&
|
2010-11-15 13:19:25 +08:00
|
|
|
(MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7));
|
2011-07-26 03:53:23 +08:00
|
|
|
return 0x80 >> getPPCRegisterNumbering(MO.getReg());
|
2010-11-15 13:19:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
unsigned PPCMCCodeEmitter::
|
|
|
|
getMachineOpValue(const MCInst &MI, const MCOperand &MO,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups) const {
|
2010-11-15 13:19:25 +08:00
|
|
|
if (MO.isReg()) {
|
2010-11-16 08:57:32 +08:00
|
|
|
// MTCRF/MFOCRF should go through get_crbitm_encoding for the CR operand.
|
|
|
|
// The GPR operand should come through here though.
|
2010-11-16 08:55:51 +08:00
|
|
|
assert((MI.getOpcode() != PPC::MTCRF && MI.getOpcode() != PPC::MFOCRF) ||
|
|
|
|
MO.getReg() < PPC::CR0 || MO.getReg() > PPC::CR7);
|
2011-07-26 03:53:23 +08:00
|
|
|
return getPPCRegisterNumbering(MO.getReg());
|
2010-11-15 13:19:25 +08:00
|
|
|
}
|
add basic encoding support for immediates and registers, allowing us
to encode all of these instructions correctly (for example):
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x01,0x00,0x08]
stwu r1, -64(r1) ; encoding: [0x94,0x21,0xff,0xc0]
llvm-svn: 119118
2010-11-15 12:51:55 +08:00
|
|
|
|
split out an encoder for memri operands, allowing a relocation to be plopped
into the immediate field. This allows us to encode stuff like this:
lbz r3, lo16(__ZL4init)(r4) ; globalopt.cpp:5
; encoding: [0x88,0x64,A,A]
; fixup A - offset: 0, value: lo16(__ZL4init), kind: fixup_ppc_lo16
stw r3, lo16(__ZL1s)(r5) ; globalopt.cpp:6
; encoding: [0x90,0x65,A,A]
; fixup A - offset: 0, value: lo16(__ZL1s), kind: fixup_ppc_lo16
With this, we should have a completely function MCCodeEmitter for PPC, wewt.
llvm-svn: 119134
2010-11-15 16:22:03 +08:00
|
|
|
assert(MO.isImm() &&
|
|
|
|
"Relocation required in an instruction that we cannot encode!");
|
|
|
|
return MO.getImm();
|
Implement a basic MCCodeEmitter for PPC. This doesn't handle
fixups yet, and doesn't handle actually encoding operand values,
but this is enough for llc -show-mc-encoding to show the base
instruction encoding information, e.g.:
mflr r0 ; encoding: [0x7c,0x08,0x02,0xa6]
stw r0, 8(r1) ; encoding: [0x90,0x00,0x00,0x00]
stwu r1, -64(r1) ; encoding: [0x94,0x00,0x00,0x00]
Ltmp0:
lhz r4, 4(r3) ; encoding: [0xa0,0x00,0x00,0x00]
cmplwi cr0, r4, 8 ; encoding: [0x28,0x00,0x00,0x00]
beq cr0, LBB0_2 ; encoding: [0x40,0x00,0x00,0x00]
llvm-svn: 119116
2010-11-15 12:16:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "PPCGenMCCodeEmitter.inc"
|