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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-26 03:53:23 +08:00
|
|
|
#include "MCTargetDesc/PPCFixupKinds.h"
|
2017-01-13 08:58:58 +08:00
|
|
|
#include "PPCInstrInfo.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2017-01-13 08:58:58 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2015-03-11 06:03:14 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.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"
|
2013-03-27 04:08:20 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2017-01-13 08:58:58 +08:00
|
|
|
#include "llvm/MC/MCFixup.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/MCInst.h"
|
2017-01-13 08:58:58 +08:00
|
|
|
#include "llvm/MC/MCInstrDesc.h"
|
2012-10-25 20:27:42 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2015-05-16 05:58:42 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2017-01-13 08:58:58 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2015-06-04 23:03:02 +08:00
|
|
|
#include "llvm/Support/EndianStream.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"
|
2017-01-13 08:58:58 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-01-13 08:58:58 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
|
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;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "mccodeemitter"
|
|
|
|
|
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
|
|
|
STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
|
|
|
|
|
|
|
|
namespace {
|
2012-09-16 01:09:36 +08:00
|
|
|
|
2017-01-13 08:58:58 +08:00
|
|
|
class PPCMCCodeEmitter : public MCCodeEmitter {
|
2014-02-02 14:12:27 +08:00
|
|
|
const MCInstrInfo &MCII;
|
2013-03-27 04:08:20 +08:00
|
|
|
const MCContext &CTX;
|
2014-03-25 02:16:09 +08:00
|
|
|
bool IsLittleEndian;
|
2012-10-25 20:27:42 +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
|
|
|
public:
|
2015-03-11 06:03:14 +08:00
|
|
|
PPCMCCodeEmitter(const MCInstrInfo &mcii, MCContext &ctx)
|
|
|
|
: MCII(mcii), CTX(ctx),
|
|
|
|
IsLittleEndian(ctx.getAsmInfo()->isLittleEndian()) {}
|
2017-01-13 08:58:58 +08:00
|
|
|
PPCMCCodeEmitter(const PPCMCCodeEmitter &) = delete;
|
|
|
|
void operator=(const PPCMCCodeEmitter &) = delete;
|
|
|
|
~PPCMCCodeEmitter() override = default;
|
2010-11-15 13:19:25 +08:00
|
|
|
|
2010-11-15 14:09:35 +08:00
|
|
|
unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2010-11-15 14:09:35 +08:00
|
|
|
unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2013-06-24 19:03:33 +08:00
|
|
|
unsigned getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2013-06-24 19:03:33 +08:00
|
|
|
unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2013-06-26 21:49:15 +08:00
|
|
|
unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) 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,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2010-11-15 16:02:41 +08:00
|
|
|
unsigned getMemRIXEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2016-03-08 11:49:13 +08:00
|
|
|
unsigned getMemRIX16Encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2014-08-09 00:43:49 +08:00
|
|
|
unsigned getSPE8DisEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
|
|
|
unsigned getSPE4DisEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
|
|
|
unsigned getSPE2DisEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2012-12-05 00:18:08 +08:00
|
|
|
unsigned getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2013-07-03 05:31:04 +08:00
|
|
|
unsigned getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2010-11-15 13:19:25 +08:00
|
|
|
unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
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
|
|
|
/// 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,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) 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
|
|
|
|
|
|
|
// 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,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const;
|
2017-01-13 08:58:58 +08:00
|
|
|
|
2015-05-16 03:13:16 +08:00
|
|
|
void encodeInstruction(const MCInst &MI, raw_ostream &OS,
|
2014-01-29 07:13:07 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
2014-04-29 15:57:37 +08:00
|
|
|
const MCSubtargetInfo &STI) const override {
|
Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
emission of instructions that don't satisfy their predicates. One deliberate
use is the SYNC instruction where the version with an operand is correctly
defined as requiring MIPS32 while the version without an operand is defined
as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
MCCodeEmitter infrastructure.
Patches for ARM and Mips will follow.
Depends on D25617
Reviewers: tstellarAMD, jmolloy
Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D25618
llvm-svn: 287439
2016-11-19 21:05:44 +08:00
|
|
|
verifyInstructionPredicates(MI,
|
|
|
|
computeAvailableFeatures(STI.getFeatureBits()));
|
|
|
|
|
2013-09-17 01:25:12 +08:00
|
|
|
unsigned Opcode = MI.getOpcode();
|
2014-02-02 14:12:27 +08:00
|
|
|
const MCInstrDesc &Desc = MCII.get(Opcode);
|
2013-09-17 01:25:12 +08:00
|
|
|
|
2014-01-29 07:13:18 +08:00
|
|
|
uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, STI);
|
2012-10-25 22:29:13 +08:00
|
|
|
|
2014-03-25 02:16:09 +08:00
|
|
|
// Output the constant in big/little endian byte order.
|
2014-02-02 14:12:27 +08:00
|
|
|
unsigned Size = Desc.getSize();
|
2014-06-18 23:37:07 +08:00
|
|
|
switch (Size) {
|
2016-04-29 05:24:37 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
2014-06-18 23:37:07 +08:00
|
|
|
case 4:
|
|
|
|
if (IsLittleEndian) {
|
2015-06-04 23:03:02 +08:00
|
|
|
support::endian::Writer<support::little>(OS).write<uint32_t>(Bits);
|
2014-06-18 23:37:07 +08:00
|
|
|
} else {
|
2015-06-04 23:03:02 +08:00
|
|
|
support::endian::Writer<support::big>(OS).write<uint32_t>(Bits);
|
2014-03-25 02:16:09 +08:00
|
|
|
}
|
2014-06-18 23:37:07 +08:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
// If we emit a pair of instructions, the first one is
|
|
|
|
// always in the top 32 bits, even on little-endian.
|
|
|
|
if (IsLittleEndian) {
|
2015-06-04 23:03:02 +08:00
|
|
|
uint64_t Swapped = (Bits << 32) | (Bits >> 32);
|
|
|
|
support::endian::Writer<support::little>(OS).write<uint64_t>(Swapped);
|
2014-06-18 23:37:07 +08:00
|
|
|
} else {
|
2015-06-04 23:03:02 +08:00
|
|
|
support::endian::Writer<support::big>(OS).write<uint64_t>(Bits);
|
2014-03-25 02:16:09 +08:00
|
|
|
}
|
2014-06-18 23:37:07 +08:00
|
|
|
break;
|
|
|
|
default:
|
2017-01-13 08:58:58 +08:00
|
|
|
llvm_unreachable("Invalid instruction size");
|
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
|
|
|
}
|
|
|
|
|
|
|
|
++MCNumEmitted; // Keep track of the # of mi's emitted.
|
|
|
|
}
|
Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
emission of instructions that don't satisfy their predicates. One deliberate
use is the SYNC instruction where the version with an operand is correctly
defined as requiring MIPS32 while the version without an operand is defined
as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
MCCodeEmitter infrastructure.
Patches for ARM and Mips will follow.
Depends on D25617
Reviewers: tstellarAMD, jmolloy
Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D25618
llvm-svn: 287439
2016-11-19 21:05:44 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint64_t computeAvailableFeatures(const FeatureBitset &FB) const;
|
|
|
|
void verifyInstructionPredicates(const MCInst &MI,
|
|
|
|
uint64_t AvailableFeatures) 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
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
2015-03-11 06:03:14 +08:00
|
|
|
|
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,
|
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) {
|
2015-03-11 06:03:14 +08:00
|
|
|
return new PPCMCCodeEmitter(MCII, 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,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2010-11-15 13:57:53 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2014-01-29 07:13:18 +08:00
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
|
2010-11-15 13:57:53 +08:00
|
|
|
|
|
|
|
// Add a fixup for the branch target.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
|
2010-11-15 13:57:53 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_br24));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-15 14:09:35 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getCondBrEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2010-11-15 14:09:35 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2014-01-29 07:13:18 +08:00
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
|
2010-11-15 14:09:35 +08:00
|
|
|
|
2010-11-15 14:12:22 +08:00
|
|
|
// Add a fixup for the branch target.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
|
2010-11-15 14:12:22 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_brcond14));
|
2010-11-15 14:09:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:03:33 +08:00
|
|
|
unsigned PPCMCCodeEmitter::
|
|
|
|
getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2013-06-24 19:03:33 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2014-01-29 07:13:18 +08:00
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
|
2013-06-24 19:03:33 +08:00
|
|
|
|
|
|
|
// Add a fixup for the branch target.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
|
2013-06-24 19:03:33 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_br24abs));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PPCMCCodeEmitter::
|
|
|
|
getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2013-06-24 19:03:33 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2014-01-29 07:13:18 +08:00
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
|
2013-06-24 19:03:33 +08:00
|
|
|
|
|
|
|
// Add a fixup for the branch target.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
|
2013-06-24 19:03:33 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_brcond14abs));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-26 21:49:15 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getImm16Encoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2010-11-15 14:33:39 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2014-01-29 07:13:18 +08:00
|
|
|
if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
|
2010-11-15 14:33:39 +08:00
|
|
|
|
2013-06-26 21:49:15 +08:00
|
|
|
// Add a fixup for the immediate field.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(IsLittleEndian? 0 : 2, MO.getExpr(),
|
2013-05-17 20:37:21 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_half16));
|
2010-11-15 14:33:39 +08:00
|
|
|
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,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) 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
|
|
|
// 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());
|
2014-01-29 07:13:18 +08:00
|
|
|
unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI) << 16;
|
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
|
|
|
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
if (MO.isImm())
|
2014-01-29 07:13:18 +08:00
|
|
|
return (getMachineOpValue(MI, MO, Fixups, STI) & 0xFFFF) | RegBits;
|
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
|
|
|
|
|
|
|
// Add a fixup for the displacement field.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(IsLittleEndian? 0 : 2, MO.getExpr(),
|
2013-05-17 20:37:21 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_half16));
|
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,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) 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());
|
2014-01-29 07:13:18 +08:00
|
|
|
unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI) << 14;
|
2010-11-15 16:02:41 +08:00
|
|
|
|
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())
|
2014-01-29 07:13:18 +08:00
|
|
|
return ((getMachineOpValue(MI, MO, Fixups, STI) >> 2) & 0x3FFF) | RegBits;
|
2010-11-15 14:33:39 +08:00
|
|
|
|
PowerPC: Simplify handling of fixups.
MCTargetDesc/PPCMCCodeEmitter.cpp current has code like:
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));
This is a problem for the asm parser, since it requires knowledge of
the ABI / 64-bit mode to be set up. However, more fundamentally,
at this point we shouldn't make such distinctions anyway; in an assembler
file, it always ought to be possible to e.g. generate TOC relocations even
when the main ABI is one that doesn't use TOC.
Fortunately, this is actually completely unnecessary; that code was added
to decide whether to generate TOC relocations, but that information is in
fact already encoded in the VariantKind of the underlying symbol.
This commit therefore merges those fixup types into one, and then decides
which relocation to use based on the VariantKind.
No changes in generated code.
llvm-svn: 178007
2013-03-26 18:56:47 +08:00
|
|
|
// Add a fixup for the displacement field.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(IsLittleEndian? 0 : 2, MO.getExpr(),
|
2013-05-17 20:37:21 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_half16ds));
|
2010-11-15 16:02:41 +08:00
|
|
|
return RegBits;
|
2010-11-15 14:33:39 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 11:49:13 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getMemRIX16Encoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
|
|
|
// Encode (imm, reg) as a memrix16, which has the low 12-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, STI) << 12;
|
|
|
|
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
assert(MO.isImm());
|
|
|
|
|
|
|
|
return ((getMachineOpValue(MI, MO, Fixups, STI) >> 4) & 0xFFF) | RegBits;
|
|
|
|
}
|
2010-11-15 14:09:35 +08:00
|
|
|
|
2014-08-09 00:43:49 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getSPE8DisEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI)
|
|
|
|
const {
|
|
|
|
// Encode (imm, reg) as a spe8dis, which has the low 5-bits of (imm / 8)
|
|
|
|
// as the displacement and the next 5 bits as the register #.
|
|
|
|
assert(MI.getOperand(OpNo+1).isReg());
|
|
|
|
uint32_t RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI) << 5;
|
|
|
|
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
assert(MO.isImm());
|
|
|
|
uint32_t Imm = getMachineOpValue(MI, MO, Fixups, STI) >> 3;
|
|
|
|
return reverseBits(Imm | RegBits) >> 22;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PPCMCCodeEmitter::getSPE4DisEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI)
|
|
|
|
const {
|
|
|
|
// Encode (imm, reg) as a spe4dis, which has the low 5-bits of (imm / 4)
|
|
|
|
// as the displacement and the next 5 bits as the register #.
|
|
|
|
assert(MI.getOperand(OpNo+1).isReg());
|
|
|
|
uint32_t RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI) << 5;
|
|
|
|
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
assert(MO.isImm());
|
|
|
|
uint32_t Imm = getMachineOpValue(MI, MO, Fixups, STI) >> 2;
|
|
|
|
return reverseBits(Imm | RegBits) >> 22;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PPCMCCodeEmitter::getSPE2DisEncoding(const MCInst &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI)
|
|
|
|
const {
|
|
|
|
// Encode (imm, reg) as a spe2dis, which has the low 5-bits of (imm / 2)
|
|
|
|
// as the displacement and the next 5 bits as the register #.
|
|
|
|
assert(MI.getOperand(OpNo+1).isReg());
|
|
|
|
uint32_t RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI) << 5;
|
|
|
|
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
|
|
|
assert(MO.isImm());
|
|
|
|
uint32_t Imm = getMachineOpValue(MI, MO, Fixups, STI) >> 1;
|
|
|
|
return reverseBits(Imm | RegBits) >> 22;
|
|
|
|
}
|
|
|
|
|
2012-12-05 00:18:08 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2012-12-05 00:18:08 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2014-01-29 07:13:18 +08:00
|
|
|
if (MO.isReg()) return getMachineOpValue(MI, MO, Fixups, STI);
|
2012-12-05 00:18:08 +08:00
|
|
|
|
|
|
|
// Add a fixup for the TLS register, which simply provides a relocation
|
|
|
|
// hint to the linker that this statement is part of a relocation sequence.
|
|
|
|
// Return the thread-pointer register's encoding.
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
|
2013-07-05 20:22:36 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_nofixup));
|
2015-09-16 00:17:27 +08:00
|
|
|
const Triple &TT = STI.getTargetTriple();
|
|
|
|
bool isPPC64 = TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le;
|
2013-12-22 18:45:37 +08:00
|
|
|
return CTX.getRegisterInfo()->getEncodingValue(isPPC64 ? PPC::X13 : PPC::R2);
|
2012-12-05 00:18:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-03 05:31:04 +08:00
|
|
|
unsigned PPCMCCodeEmitter::getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2013-07-03 05:31:04 +08:00
|
|
|
// For special TLS calls, we need two fixups; one for the branch target
|
|
|
|
// (__tls_get_addr), which we create via getDirectBrEncoding as usual,
|
|
|
|
// and one for the TLSGD or TLSLD symbol, which is emitted here.
|
|
|
|
const MCOperand &MO = MI.getOperand(OpNo+1);
|
2015-05-16 03:13:05 +08:00
|
|
|
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
|
2013-07-03 05:31:04 +08:00
|
|
|
(MCFixupKind)PPC::fixup_ppc_nofixup));
|
2014-01-29 07:13:18 +08:00
|
|
|
return getDirectBrEncoding(MI, OpNo, Fixups, STI);
|
2013-07-03 05:31:04 +08:00
|
|
|
}
|
|
|
|
|
2010-11-15 13:19:25 +08:00
|
|
|
unsigned PPCMCCodeEmitter::
|
|
|
|
get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2010-11-15 13:19:25 +08:00
|
|
|
const MCOperand &MO = MI.getOperand(OpNo);
|
2013-07-04 01:59:07 +08:00
|
|
|
assert((MI.getOpcode() == PPC::MTOCRF || MI.getOpcode() == PPC::MTOCRF8 ||
|
[PowerPC] Always use mfocrf if available
When accessing just a single CR register, it is always preferable to
use mfocrf instead of mfcr, if the former is available on the CPU.
Current code makes that distinction in many, but not all places
where a single CR register value is retrieved. One missing
location is PPCRegisterInfo::lowerCRSpilling.
To fix this and make this simpler in the future, this patch changes
the bulk of the back-end to always assume mfocrf is available and
simply generate it when needed.
On machines that actually do not support mfocrf, the instruction
is replaced by mfcr at the very end, in EmitInstruction.
This has the additional benefit that we no longer need the
MFCRpseud hack, since before EmitInstruction we always have
a MFOCRF instruction pattern, which already models data flow
as required.
The patch also adds the MFOCRF8 version of the instruction,
which was missing so far.
Except for the PPCRegisterInfo::lowerCRSpilling case, no change
in generated code intended.
llvm-svn: 185556
2013-07-04 01:05:42 +08:00
|
|
|
MI.getOpcode() == PPC::MFOCRF || MI.getOpcode() == PPC::MFOCRF8) &&
|
2010-11-15 13:19:25 +08:00
|
|
|
(MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7));
|
2013-06-18 15:20:20 +08:00
|
|
|
return 0x80 >> CTX.getRegisterInfo()->getEncodingValue(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,
|
2014-01-29 07:13:18 +08:00
|
|
|
SmallVectorImpl<MCFixup> &Fixups,
|
|
|
|
const MCSubtargetInfo &STI) const {
|
2010-11-15 13:19:25 +08:00
|
|
|
if (MO.isReg()) {
|
2013-07-04 01:59:07 +08:00
|
|
|
// MTOCRF/MFOCRF should go through get_crbitm_encoding for the CR operand.
|
2010-11-16 08:57:32 +08:00
|
|
|
// The GPR operand should come through here though.
|
2013-07-04 01:59:07 +08:00
|
|
|
assert((MI.getOpcode() != PPC::MTOCRF && MI.getOpcode() != PPC::MTOCRF8 &&
|
[PowerPC] Always use mfocrf if available
When accessing just a single CR register, it is always preferable to
use mfocrf instead of mfcr, if the former is available on the CPU.
Current code makes that distinction in many, but not all places
where a single CR register value is retrieved. One missing
location is PPCRegisterInfo::lowerCRSpilling.
To fix this and make this simpler in the future, this patch changes
the bulk of the back-end to always assume mfocrf is available and
simply generate it when needed.
On machines that actually do not support mfocrf, the instruction
is replaced by mfcr at the very end, in EmitInstruction.
This has the additional benefit that we no longer need the
MFCRpseud hack, since before EmitInstruction we always have
a MFOCRF instruction pattern, which already models data flow
as required.
The patch also adds the MFOCRF8 version of the instruction,
which was missing so far.
Except for the PPCRegisterInfo::lowerCRSpilling case, no change
in generated code intended.
llvm-svn: 185556
2013-07-04 01:05:42 +08:00
|
|
|
MI.getOpcode() != PPC::MFOCRF && MI.getOpcode() != PPC::MFOCRF8) ||
|
2010-11-16 08:55:51 +08:00
|
|
|
MO.getReg() < PPC::CR0 || MO.getReg() > PPC::CR7);
|
2016-10-04 14:59:23 +08:00
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
unsigned Encode = CTX.getRegisterInfo()->getEncodingValue(Reg);
|
|
|
|
|
|
|
|
if ((MCII.get(MI.getOpcode()).TSFlags & PPCII::UseVSXReg))
|
|
|
|
if (PPCInstrInfo::isVRRegister(Reg))
|
|
|
|
Encode += 32;
|
|
|
|
|
|
|
|
return Encode;
|
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
|
|
|
}
|
|
|
|
|
Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
emission of instructions that don't satisfy their predicates. One deliberate
use is the SYNC instruction where the version with an operand is correctly
defined as requiring MIPS32 while the version without an operand is defined
as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
MCCodeEmitter infrastructure.
Patches for ARM and Mips will follow.
Depends on D25617
Reviewers: tstellarAMD, jmolloy
Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D25618
llvm-svn: 287439
2016-11-19 21:05:44 +08:00
|
|
|
#define ENABLE_INSTR_PREDICATE_VERIFIER
|
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"
|