diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:44:32 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:44:32 +0000 |
commit | 5a5ac124e1efaf208671f01c46edb15f29ed2a0b (patch) | |
tree | a6140557876943cdd800ee997c9317283394b22c /lib/Target/Hexagon/MCTargetDesc | |
parent | f03b5bed27d0d2eafd68562ce14f8b5e3f1f0801 (diff) |
Vendor import of llvm trunk r238337:vendor/llvm/llvm-trunk-r238337
Notes
Notes:
svn path=/vendor/llvm/dist/; revision=283625
svn path=/vendor/llvm/llvm-trunk-r238337/; revision=283626; tag=vendor/llvm/llvm-trunk-r238337
Diffstat (limited to 'lib/Target/Hexagon/MCTargetDesc')
15 files changed, 1031 insertions, 422 deletions
diff --git a/lib/Target/Hexagon/MCTargetDesc/CMakeLists.txt b/lib/Target/Hexagon/MCTargetDesc/CMakeLists.txt index 2a6124ee0c5a..4c987ed32a64 100644 --- a/lib/Target/Hexagon/MCTargetDesc/CMakeLists.txt +++ b/lib/Target/Hexagon/MCTargetDesc/CMakeLists.txt @@ -4,7 +4,7 @@ add_llvm_library(LLVMHexagonDesc HexagonInstPrinter.cpp HexagonMCAsmInfo.cpp HexagonMCCodeEmitter.cpp - HexagonMCInst.cpp + HexagonMCInstrInfo.cpp HexagonMCTargetDesc.cpp ) diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp index bdccf880d65f..155aa9ef9557 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp @@ -57,7 +57,7 @@ public: ELFHexagonAsmBackend(Target const &T, uint8_t OSABI) : HexagonAsmBackend(T), OSABI(OSABI) {} - MCObjectWriter *createObjectWriter(raw_ostream &OS) const override { + MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override { StringRef CPU("HexagonV4"); return createHexagonELFObjectWriter(OS, OSABI, CPU); } diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonBaseInfo.h b/lib/Target/Hexagon/MCTargetDesc/HexagonBaseInfo.h index 8e02f799d7e4..6a72f205e9d3 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonBaseInfo.h +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonBaseInfo.h @@ -70,7 +70,7 @@ namespace HexagonII { PostInc = 6 // Post increment addressing mode }; - enum MemAccessSize { + enum class MemAccessSize { NoMemAccess = 0, // Not a memory acces instruction. ByteAccess = 1, // Byte access instruction (memb). HalfWordAccess = 2, // Half word access instruction (memh). diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp index 56c9dc712a6e..fde935b2758b 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp @@ -11,6 +11,7 @@ #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" #define DEBUG_TYPE "hexagon-elf-writer" @@ -26,8 +27,8 @@ private: public: HexagonELFObjectWriter(uint8_t OSABI, StringRef C); - virtual unsigned GetRelocType(MCValue const &Target, MCFixup const &Fixup, - bool IsPCRel) const override; + unsigned GetRelocType(MCValue const &Target, MCFixup const &Fixup, + bool IsPCRel) const override; }; } @@ -54,9 +55,9 @@ unsigned HexagonELFObjectWriter::GetRelocType(MCValue const &/*Target*/, return Type; } -MCObjectWriter *llvm::createHexagonELFObjectWriter(raw_ostream &OS, +MCObjectWriter *llvm::createHexagonELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI, StringRef CPU) { MCELFObjectTargetWriter *MOTW = new HexagonELFObjectWriter(OSABI, CPU); return createELFObjectWriter(MOTW, OS, /*IsLittleEndian*/ true); -}
\ No newline at end of file +} diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonFixupKinds.h b/lib/Target/Hexagon/MCTargetDesc/HexagonFixupKinds.h new file mode 100644 index 000000000000..4bbfbec883c4 --- /dev/null +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonFixupKinds.h @@ -0,0 +1,137 @@ +//===-- HexagonFixupKinds.h - Hexagon Specific Fixup Entries --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_HEXAGON_HEXAGONFIXUPKINDS_H +#define LLVM_HEXAGON_HEXAGONFIXUPKINDS_H + +#include "llvm/MC/MCFixup.h" + +namespace llvm { +namespace Hexagon { +enum Fixups { + // Branch fixups for R_HEX_B{22,15,7}_PCREL. + fixup_Hexagon_B22_PCREL = FirstTargetFixupKind, + fixup_Hexagon_B15_PCREL, + fixup_Hexagon_B7_PCREL, + fixup_Hexagon_LO16, + fixup_Hexagon_HI16, + fixup_Hexagon_32, + fixup_Hexagon_16, + fixup_Hexagon_8, + fixup_Hexagon_GPREL16_0, + fixup_Hexagon_GPREL16_1, + fixup_Hexagon_GPREL16_2, + fixup_Hexagon_GPREL16_3, + fixup_Hexagon_HL16, + fixup_Hexagon_B13_PCREL, + fixup_Hexagon_B9_PCREL, + fixup_Hexagon_B32_PCREL_X, + fixup_Hexagon_32_6_X, + fixup_Hexagon_B22_PCREL_X, + fixup_Hexagon_B15_PCREL_X, + fixup_Hexagon_B13_PCREL_X, + fixup_Hexagon_B9_PCREL_X, + fixup_Hexagon_B7_PCREL_X, + fixup_Hexagon_16_X, + fixup_Hexagon_12_X, + fixup_Hexagon_11_X, + fixup_Hexagon_10_X, + fixup_Hexagon_9_X, + fixup_Hexagon_8_X, + fixup_Hexagon_7_X, + fixup_Hexagon_6_X, + fixup_Hexagon_32_PCREL, + fixup_Hexagon_COPY, + fixup_Hexagon_GLOB_DAT, + fixup_Hexagon_JMP_SLOT, + fixup_Hexagon_RELATIVE, + fixup_Hexagon_PLT_B22_PCREL, + fixup_Hexagon_GOTREL_LO16, + fixup_Hexagon_GOTREL_HI16, + fixup_Hexagon_GOTREL_32, + fixup_Hexagon_GOT_LO16, + fixup_Hexagon_GOT_HI16, + fixup_Hexagon_GOT_32, + fixup_Hexagon_GOT_16, + fixup_Hexagon_DTPMOD_32, + fixup_Hexagon_DTPREL_LO16, + fixup_Hexagon_DTPREL_HI16, + fixup_Hexagon_DTPREL_32, + fixup_Hexagon_DTPREL_16, + fixup_Hexagon_GD_PLT_B22_PCREL, + fixup_Hexagon_LD_PLT_B22_PCREL, + fixup_Hexagon_GD_GOT_LO16, + fixup_Hexagon_GD_GOT_HI16, + fixup_Hexagon_GD_GOT_32, + fixup_Hexagon_GD_GOT_16, + fixup_Hexagon_LD_GOT_LO16, + fixup_Hexagon_LD_GOT_HI16, + fixup_Hexagon_LD_GOT_32, + fixup_Hexagon_LD_GOT_16, + fixup_Hexagon_IE_LO16, + fixup_Hexagon_IE_HI16, + fixup_Hexagon_IE_32, + fixup_Hexagon_IE_16, + fixup_Hexagon_IE_GOT_LO16, + fixup_Hexagon_IE_GOT_HI16, + fixup_Hexagon_IE_GOT_32, + fixup_Hexagon_IE_GOT_16, + fixup_Hexagon_TPREL_LO16, + fixup_Hexagon_TPREL_HI16, + fixup_Hexagon_TPREL_32, + fixup_Hexagon_TPREL_16, + fixup_Hexagon_6_PCREL_X, + fixup_Hexagon_GOTREL_32_6_X, + fixup_Hexagon_GOTREL_16_X, + fixup_Hexagon_GOTREL_11_X, + fixup_Hexagon_GOT_32_6_X, + fixup_Hexagon_GOT_16_X, + fixup_Hexagon_GOT_11_X, + fixup_Hexagon_DTPREL_32_6_X, + fixup_Hexagon_DTPREL_16_X, + fixup_Hexagon_DTPREL_11_X, + fixup_Hexagon_GD_GOT_32_6_X, + fixup_Hexagon_GD_GOT_16_X, + fixup_Hexagon_GD_GOT_11_X, + fixup_Hexagon_LD_GOT_32_6_X, + fixup_Hexagon_LD_GOT_16_X, + fixup_Hexagon_LD_GOT_11_X, + fixup_Hexagon_IE_32_6_X, + fixup_Hexagon_IE_16_X, + fixup_Hexagon_IE_GOT_32_6_X, + fixup_Hexagon_IE_GOT_16_X, + fixup_Hexagon_IE_GOT_11_X, + fixup_Hexagon_TPREL_32_6_X, + fixup_Hexagon_TPREL_16_X, + fixup_Hexagon_TPREL_11_X, + + LastTargetFixupKind, + NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind +}; +enum FixupBitmaps : unsigned { + Word8 = 0xff, + Word16 = 0xffff, + Word32 = 0xffffffff, + Word32_LO = 0x00c03fff, + Word32_HL = 0x0, // Not Implemented + Word32_GP = 0x0, // Not Implemented + Word32_B7 = 0x00001f18, + Word32_B9 = 0x003000fe, + Word32_B13 = 0x00202ffe, + Word32_B15 = 0x00df20fe, + Word32_B22 = 0x01ff3ffe, + Word32_R6 = 0x000007e0, + Word32_U6 = 0x0, // Not Implemented + Word32_U16 = 0x0, // Not Implemented + Word32_X26 = 0x0fff3fff +}; +} // namespace Hexagon +} // namespace llvm + +#endif // LLVM_HEXAGON_HEXAGONFIXUPKINDS_H diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp index 5c6f0363f78a..15cda717cf1c 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp @@ -14,7 +14,7 @@ #include "HexagonAsmPrinter.h" #include "Hexagon.h" #include "HexagonInstPrinter.h" -#include "MCTargetDesc/HexagonMCInst.h" +#include "MCTargetDesc/HexagonMCInstrInfo.h" #include "llvm/ADT/StringExtras.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCExpr.h" @@ -73,50 +73,46 @@ StringRef HexagonInstPrinter::getOpcodeName(unsigned Opcode) const { return MII.getName(Opcode); } -StringRef HexagonInstPrinter::getRegName(unsigned RegNo) const { - return getRegisterName(RegNo); +void HexagonInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { + OS << getRegisterName(RegNo); } -void HexagonInstPrinter::printInst(const MCInst *MI, raw_ostream &O, - StringRef Annot) { - printInst((const HexagonMCInst*)(MI), O, Annot); -} - -void HexagonInstPrinter::printInst(const HexagonMCInst *MI, raw_ostream &O, - StringRef Annot) { +void HexagonInstPrinter::printInst(MCInst const *MI, raw_ostream &O, + StringRef Annot, + const MCSubtargetInfo &STI) { const char startPacket = '{', endPacket = '}'; // TODO: add outer HW loop when it's supported too. if (MI->getOpcode() == Hexagon::ENDLOOP0) { // Ending a harware loop is different from ending an regular packet. - assert(MI->isPacketEnd() && "Loop-end must also end the packet"); + assert(HexagonMCInstrInfo::isPacketEnd(*MI) && "Loop-end must also end the packet"); - if (MI->isPacketBegin()) { + if (HexagonMCInstrInfo::isPacketBegin(*MI)) { // There must be a packet to end a loop. // FIXME: when shuffling is always run, this shouldn't be needed. - HexagonMCInst Nop; + MCInst Nop; StringRef NoAnnot; Nop.setOpcode (Hexagon::A2_nop); - Nop.setPacketBegin (MI->isPacketBegin()); - printInst (&Nop, O, NoAnnot); + HexagonMCInstrInfo::setPacketBegin (Nop, HexagonMCInstrInfo::isPacketBegin(*MI)); + printInst (&Nop, O, NoAnnot, STI); } // Close the packet. - if (MI->isPacketEnd()) + if (HexagonMCInstrInfo::isPacketEnd(*MI)) O << PacketPadding << endPacket; printInstruction(MI, O); } else { // Prefix the insn opening the packet. - if (MI->isPacketBegin()) + if (HexagonMCInstrInfo::isPacketBegin(*MI)) O << PacketPadding << startPacket << '\n'; printInstruction(MI, O); // Suffix the insn closing the packet. - if (MI->isPacketEnd()) + if (HexagonMCInstrInfo::isPacketEnd(*MI)) // Suffix the packet in a new line always, since the GNU assembler has // issues with a closing brace on the same line as CONST{32,64}. O << '\n' << PacketPadding << endPacket; @@ -130,7 +126,7 @@ void HexagonInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, const MCOperand& MO = MI->getOperand(OpNo); if (MO.isReg()) { - O << getRegisterName(MO.getReg()); + printRegName(O, MO.getReg()); } else if(MO.isExpr()) { O << *MO.getExpr(); } else if(MO.isImm()) { @@ -192,7 +188,7 @@ void HexagonInstPrinter::printMEMriOperand(const MCInst *MI, unsigned OpNo, const MCOperand& MO0 = MI->getOperand(OpNo); const MCOperand& MO1 = MI->getOperand(OpNo + 1); - O << getRegisterName(MO0.getReg()); + printRegName(O, MO0.getReg()); O << " + #" << MO1.getImm(); } @@ -201,7 +197,8 @@ void HexagonInstPrinter::printFrameIndexOperand(const MCInst *MI, unsigned OpNo, const MCOperand& MO0 = MI->getOperand(OpNo); const MCOperand& MO1 = MI->getOperand(OpNo + 1); - O << getRegisterName(MO0.getReg()) << ", #" << MO1.getImm(); + printRegName(O, MO0.getReg()); + O << ", #" << MO1.getImm(); } void HexagonInstPrinter::printGlobalOperand(const MCInst *MI, unsigned OpNo, @@ -252,3 +249,17 @@ void HexagonInstPrinter::printSymbol(const MCInst *MI, unsigned OpNo, printOperand(MI, OpNo, O); O << ')'; } + +void HexagonInstPrinter::printExtBrtarget(const MCInst *MI, unsigned OpNo, + raw_ostream &O) const { + const MCOperand &MO = MI->getOperand(OpNo); + const MCInstrDesc &MII = getMII().get(MI->getOpcode()); + + assert((isExtendable(MII.TSFlags) || isExtended(MII.TSFlags)) && + "Expecting an extendable operand"); + + if (MO.isExpr() || isExtended(MII.TSFlags)) { + O << "##"; + } + printOperand(MI, OpNo, O); +} diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h b/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h index 55ae95cd06df..3fedaed8fbf9 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h @@ -18,20 +18,18 @@ #include "llvm/MC/MCInstrInfo.h" namespace llvm { - class HexagonMCInst; - class HexagonInstPrinter : public MCInstPrinter { public: - explicit HexagonInstPrinter(const MCAsmInfo &MAI, - const MCInstrInfo &MII, - const MCRegisterInfo &MRI) + explicit HexagonInstPrinter(MCAsmInfo const &MAI, + MCInstrInfo const &MII, + MCRegisterInfo const &MRI) : MCInstPrinter(MAI, MII, MRI), MII(MII) {} - void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot) override; - void printInst(const HexagonMCInst *MI, raw_ostream &O, StringRef Annot); + void printInst(MCInst const *MI, raw_ostream &O, StringRef Annot, + const MCSubtargetInfo &STI) override; virtual StringRef getOpcodeName(unsigned Opcode) const; void printInstruction(const MCInst *MI, raw_ostream &O); - StringRef getRegName(unsigned RegNo) const; + void printRegName(raw_ostream &OS, unsigned RegNo) const override; static const char *getRegisterName(unsigned RegNo); void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) const; @@ -58,6 +56,7 @@ namespace llvm { void printGlobalOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) const; void printJumpTable(const MCInst *MI, unsigned OpNo, raw_ostream &O) const; + void printExtBrtarget(const MCInst *MI, unsigned OpNo, raw_ostream &O) const; void printConstantPool(const MCInst *MI, unsigned OpNo, raw_ostream &O) const; diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp index 487872a1f5dd..ae3953abba10 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.cpp @@ -9,8 +9,9 @@ #include "Hexagon.h" #include "MCTargetDesc/HexagonBaseInfo.h" +#include "MCTargetDesc/HexagonFixupKinds.h" #include "MCTargetDesc/HexagonMCCodeEmitter.h" -#include "MCTargetDesc/HexagonMCInst.h" +#include "MCTargetDesc/HexagonMCInstrInfo.h" #include "MCTargetDesc/HexagonMCTargetDesc.h" #include "llvm/ADT/Statistic.h" #include "llvm/MC/MCCodeEmitter.h" @@ -35,10 +36,11 @@ namespace { /// Possible values for instruction packet parse field. enum class ParseField { duplex = 0x0, last0 = 0x1, last1 = 0x2, end = 0x3 }; /// \brief Returns the packet bits based on instruction position. -uint32_t getPacketBits(HexagonMCInst const &HMI) { +uint32_t getPacketBits(MCInst const &HMI) { unsigned const ParseFieldOffset = 14; - ParseField Field = HMI.isPacketEnd() ? ParseField::end : ParseField::last0; - return static_cast <uint32_t> (Field) << ParseFieldOffset; + ParseField Field = HexagonMCInstrInfo::isPacketEnd(HMI) ? ParseField::end + : ParseField::last0; + return static_cast<uint32_t>(Field) << ParseFieldOffset; } void emitLittleEndian(uint64_t Binary, raw_ostream &OS) { OS << static_cast<uint8_t>((Binary >> 0x00) & 0xff); @@ -49,20 +51,455 @@ void emitLittleEndian(uint64_t Binary, raw_ostream &OS) { } HexagonMCCodeEmitter::HexagonMCCodeEmitter(MCInstrInfo const &aMII, - MCSubtargetInfo const &aMST, MCContext &aMCT) - : MST(aMST), MCT(aMCT) {} + : MCT(aMCT), MCII(aMII), Addend(new unsigned(0)), + Extended(new bool(false)) {} -void HexagonMCCodeEmitter::EncodeInstruction(MCInst const &MI, raw_ostream &OS, +void HexagonMCCodeEmitter::encodeInstruction(MCInst const &MI, raw_ostream &OS, SmallVectorImpl<MCFixup> &Fixups, MCSubtargetInfo const &STI) const { - HexagonMCInst const &HMB = static_cast<HexagonMCInst const &>(MI); - uint64_t Binary = getBinaryCodeForInstr(HMB, Fixups, STI) | getPacketBits(HMB); - assert(HMB.getDesc().getSize() == 4 && "All instructions should be 32bit"); + uint64_t Binary = getBinaryCodeForInstr(MI, Fixups, STI) | getPacketBits(MI); + assert(HexagonMCInstrInfo::getDesc(MCII, MI).getSize() == 4 && + "All instructions should be 32bit"); + (void)&MCII; emitLittleEndian(Binary, OS); ++MCNumEmitted; } +static Hexagon::Fixups getFixupNoBits(MCInstrInfo const &MCII, const MCInst &MI, + const MCOperand &MO, + const MCSymbolRefExpr::VariantKind kind) { + const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc(MCII, MI); + unsigned insnType = llvm::HexagonMCInstrInfo::getType(MCII, MI); + + if (insnType == HexagonII::TypePREFIX) { + switch (kind) { + case llvm::MCSymbolRefExpr::VK_GOTOFF: + return Hexagon::fixup_Hexagon_GOTREL_32_6_X; + case llvm::MCSymbolRefExpr::VK_GOT: + return Hexagon::fixup_Hexagon_GOT_32_6_X; + case llvm::MCSymbolRefExpr::VK_TPREL: + return Hexagon::fixup_Hexagon_TPREL_32_6_X; + case llvm::MCSymbolRefExpr::VK_DTPREL: + return Hexagon::fixup_Hexagon_DTPREL_32_6_X; + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT: + return Hexagon::fixup_Hexagon_GD_GOT_32_6_X; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT: + return Hexagon::fixup_Hexagon_LD_GOT_32_6_X; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE: + return Hexagon::fixup_Hexagon_IE_32_6_X; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT: + return Hexagon::fixup_Hexagon_IE_GOT_32_6_X; + default: + if (MCID.isBranch()) + return Hexagon::fixup_Hexagon_B32_PCREL_X; + else + return Hexagon::fixup_Hexagon_32_6_X; + } + } else if (MCID.isBranch()) + return (Hexagon::fixup_Hexagon_B13_PCREL); + + switch (MCID.getOpcode()) { + case Hexagon::HI: + case Hexagon::A2_tfrih: + switch (kind) { + case llvm::MCSymbolRefExpr::VK_GOT: + return Hexagon::fixup_Hexagon_GOT_HI16; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + return Hexagon::fixup_Hexagon_GOTREL_HI16; + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT: + return Hexagon::fixup_Hexagon_GD_GOT_HI16; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT: + return Hexagon::fixup_Hexagon_LD_GOT_HI16; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE: + return Hexagon::fixup_Hexagon_IE_HI16; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT: + return Hexagon::fixup_Hexagon_IE_GOT_HI16; + case llvm::MCSymbolRefExpr::VK_TPREL: + return Hexagon::fixup_Hexagon_TPREL_HI16; + case llvm::MCSymbolRefExpr::VK_DTPREL: + return Hexagon::fixup_Hexagon_DTPREL_HI16; + default: + return Hexagon::fixup_Hexagon_HI16; + } + + case Hexagon::LO: + case Hexagon::A2_tfril: + switch (kind) { + case llvm::MCSymbolRefExpr::VK_GOT: + return Hexagon::fixup_Hexagon_GOT_LO16; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + return Hexagon::fixup_Hexagon_GOTREL_LO16; + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT: + return Hexagon::fixup_Hexagon_GD_GOT_LO16; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT: + return Hexagon::fixup_Hexagon_LD_GOT_LO16; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE: + return Hexagon::fixup_Hexagon_IE_LO16; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT: + return Hexagon::fixup_Hexagon_IE_GOT_LO16; + case llvm::MCSymbolRefExpr::VK_TPREL: + return Hexagon::fixup_Hexagon_TPREL_LO16; + case llvm::MCSymbolRefExpr::VK_DTPREL: + return Hexagon::fixup_Hexagon_DTPREL_LO16; + default: + return Hexagon::fixup_Hexagon_LO16; + } + + // The only relocs left should be GP relative: + default: + if (MCID.mayStore() || MCID.mayLoad()) { + for (const uint16_t *ImpUses = MCID.getImplicitUses(); *ImpUses; + ++ImpUses) { + if (*ImpUses == Hexagon::GP) { + switch (HexagonMCInstrInfo::getAccessSize(MCII, MI)) { + case HexagonII::MemAccessSize::ByteAccess: + return fixup_Hexagon_GPREL16_0; + case HexagonII::MemAccessSize::HalfWordAccess: + return fixup_Hexagon_GPREL16_1; + case HexagonII::MemAccessSize::WordAccess: + return fixup_Hexagon_GPREL16_2; + case HexagonII::MemAccessSize::DoubleWordAccess: + return fixup_Hexagon_GPREL16_3; + default: + llvm_unreachable("unhandled fixup"); + } + } + } + } else + llvm_unreachable("unhandled fixup"); + } + + return LastTargetFixupKind; +} + +unsigned HexagonMCCodeEmitter::getExprOpValue(const MCInst &MI, + const MCOperand &MO, + const MCExpr *ME, + SmallVectorImpl<MCFixup> &Fixups, + const MCSubtargetInfo &STI) const + +{ + int64_t Res; + + if (ME->EvaluateAsAbsolute(Res)) + return Res; + + MCExpr::ExprKind MK = ME->getKind(); + if (MK == MCExpr::Constant) { + return cast<MCConstantExpr>(ME)->getValue(); + } + if (MK == MCExpr::Binary) { + unsigned Res; + Res = getExprOpValue(MI, MO, cast<MCBinaryExpr>(ME)->getLHS(), Fixups, STI); + Res += + getExprOpValue(MI, MO, cast<MCBinaryExpr>(ME)->getRHS(), Fixups, STI); + return Res; + } + + assert(MK == MCExpr::SymbolRef); + + Hexagon::Fixups FixupKind = + Hexagon::Fixups(Hexagon::fixup_Hexagon_TPREL_LO16); + const MCSymbolRefExpr *MCSRE = static_cast<const MCSymbolRefExpr *>(ME); + const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc(MCII, MI); + unsigned bits = HexagonMCInstrInfo::getExtentBits(MCII, MI) - + HexagonMCInstrInfo::getExtentAlignment(MCII, MI); + const MCSymbolRefExpr::VariantKind kind = MCSRE->getKind(); + + DEBUG(dbgs() << "----------------------------------------\n"); + DEBUG(dbgs() << "Opcode Name: " << HexagonMCInstrInfo::getName(MCII, MI) + << "\n"); + DEBUG(dbgs() << "Opcode: " << MCID.getOpcode() << "\n"); + DEBUG(dbgs() << "Relocation bits: " << bits << "\n"); + DEBUG(dbgs() << "Addend: " << *Addend << "\n"); + DEBUG(dbgs() << "----------------------------------------\n"); + + switch (bits) { + default: + DEBUG(dbgs() << "unrecognized bit count of " << bits << '\n'); + break; + + case 32: + switch (kind) { + case llvm::MCSymbolRefExpr::VK_Hexagon_PCREL: + FixupKind = Hexagon::fixup_Hexagon_32_PCREL; + break; + case llvm::MCSymbolRefExpr::VK_GOT: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_GOT_32_6_X + : Hexagon::fixup_Hexagon_GOT_32; + break; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_GOTREL_32_6_X + : Hexagon::fixup_Hexagon_GOTREL_32; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_GD_GOT_32_6_X + : Hexagon::fixup_Hexagon_GD_GOT_32; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_LD_GOT_32_6_X + : Hexagon::fixup_Hexagon_LD_GOT_32; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_IE_32_6_X + : Hexagon::fixup_Hexagon_IE_32; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_IE_GOT_32_6_X + : Hexagon::fixup_Hexagon_IE_GOT_32; + break; + case llvm::MCSymbolRefExpr::VK_TPREL: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_TPREL_32_6_X + : Hexagon::fixup_Hexagon_TPREL_32; + break; + case llvm::MCSymbolRefExpr::VK_DTPREL: + FixupKind = *Extended ? Hexagon::fixup_Hexagon_DTPREL_32_6_X + : Hexagon::fixup_Hexagon_DTPREL_32; + break; + default: + FixupKind = + *Extended ? Hexagon::fixup_Hexagon_32_6_X : Hexagon::fixup_Hexagon_32; + break; + } + break; + + case 22: + switch (kind) { + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_PLT: + FixupKind = Hexagon::fixup_Hexagon_GD_PLT_B22_PCREL; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_PLT: + FixupKind = Hexagon::fixup_Hexagon_LD_PLT_B22_PCREL; + break; + default: + if (MCID.isBranch() || MCID.isCall()) { + FixupKind = *Extended ? Hexagon::fixup_Hexagon_B22_PCREL_X + : Hexagon::fixup_Hexagon_B22_PCREL; + } else { + errs() << "unrecognized relocation, bits: " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + } + break; + + case 16: + if (*Extended) { + switch (kind) { + default: + FixupKind = Hexagon::fixup_Hexagon_16_X; + break; + case llvm::MCSymbolRefExpr::VK_GOT: + FixupKind = Hexagon::fixup_Hexagon_GOT_16_X; + break; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + FixupKind = Hexagon::fixup_Hexagon_GOTREL_16_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT: + FixupKind = Hexagon::fixup_Hexagon_GD_GOT_16_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT: + FixupKind = Hexagon::fixup_Hexagon_LD_GOT_16_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE: + FixupKind = Hexagon::fixup_Hexagon_IE_16_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT: + FixupKind = Hexagon::fixup_Hexagon_IE_GOT_16_X; + break; + case llvm::MCSymbolRefExpr::VK_TPREL: + FixupKind = Hexagon::fixup_Hexagon_TPREL_16_X; + break; + case llvm::MCSymbolRefExpr::VK_DTPREL: + FixupKind = Hexagon::fixup_Hexagon_DTPREL_16_X; + break; + } + } else + switch (kind) { + default: + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + break; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + if ((MCID.getOpcode() == Hexagon::HI) || + (MCID.getOpcode() == Hexagon::LO_H)) + FixupKind = Hexagon::fixup_Hexagon_GOTREL_HI16; + else + FixupKind = Hexagon::fixup_Hexagon_GOTREL_LO16; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_GPREL: + FixupKind = Hexagon::fixup_Hexagon_GPREL16_0; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_LO16: + FixupKind = Hexagon::fixup_Hexagon_LO16; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_HI16: + FixupKind = Hexagon::fixup_Hexagon_HI16; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT: + FixupKind = Hexagon::fixup_Hexagon_GD_GOT_16; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT: + FixupKind = Hexagon::fixup_Hexagon_LD_GOT_16; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT: + FixupKind = Hexagon::fixup_Hexagon_IE_GOT_16; + break; + case llvm::MCSymbolRefExpr::VK_TPREL: + FixupKind = Hexagon::fixup_Hexagon_TPREL_16; + break; + case llvm::MCSymbolRefExpr::VK_DTPREL: + FixupKind = Hexagon::fixup_Hexagon_DTPREL_16; + break; + } + break; + + case 15: + if (MCID.isBranch() || MCID.isCall()) + FixupKind = *Extended ? Hexagon::fixup_Hexagon_B15_PCREL_X + : Hexagon::fixup_Hexagon_B15_PCREL; + break; + + case 13: + if (MCID.isBranch()) + FixupKind = Hexagon::fixup_Hexagon_B13_PCREL; + else { + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + + case 12: + if (*Extended) + switch (kind) { + default: + FixupKind = Hexagon::fixup_Hexagon_12_X; + break; + // There isn't a GOT_12_X, both 11_X and 16_X resolve to 6/26 + case llvm::MCSymbolRefExpr::VK_GOT: + FixupKind = Hexagon::fixup_Hexagon_GOT_16_X; + break; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + FixupKind = Hexagon::fixup_Hexagon_GOTREL_16_X; + break; + } + else { + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + + case 11: + if (*Extended) + switch (kind) { + default: + FixupKind = Hexagon::fixup_Hexagon_11_X; + break; + case llvm::MCSymbolRefExpr::VK_GOT: + FixupKind = Hexagon::fixup_Hexagon_GOT_11_X; + break; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + FixupKind = Hexagon::fixup_Hexagon_GOTREL_11_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT: + FixupKind = Hexagon::fixup_Hexagon_GD_GOT_11_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT: + FixupKind = Hexagon::fixup_Hexagon_LD_GOT_11_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT: + FixupKind = Hexagon::fixup_Hexagon_IE_GOT_11_X; + break; + case llvm::MCSymbolRefExpr::VK_TPREL: + FixupKind = Hexagon::fixup_Hexagon_TPREL_11_X; + break; + case llvm::MCSymbolRefExpr::VK_DTPREL: + FixupKind = Hexagon::fixup_Hexagon_DTPREL_11_X; + break; + } + else { + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + + case 10: + if (*Extended) + FixupKind = Hexagon::fixup_Hexagon_10_X; + break; + + case 9: + if (MCID.isBranch() || + (llvm::HexagonMCInstrInfo::getType(MCII, MI) == HexagonII::TypeCR)) + FixupKind = *Extended ? Hexagon::fixup_Hexagon_B9_PCREL_X + : Hexagon::fixup_Hexagon_B9_PCREL; + else if (*Extended) + FixupKind = Hexagon::fixup_Hexagon_9_X; + else { + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + + case 8: + if (*Extended) + FixupKind = Hexagon::fixup_Hexagon_8_X; + else { + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + + case 7: + if (MCID.isBranch() || + (llvm::HexagonMCInstrInfo::getType(MCII, MI) == HexagonII::TypeCR)) + FixupKind = *Extended ? Hexagon::fixup_Hexagon_B7_PCREL_X + : Hexagon::fixup_Hexagon_B7_PCREL; + else if (*Extended) + FixupKind = Hexagon::fixup_Hexagon_7_X; + else { + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + + case 6: + if (*Extended) { + switch (kind) { + default: + FixupKind = Hexagon::fixup_Hexagon_6_X; + break; + case llvm::MCSymbolRefExpr::VK_Hexagon_PCREL: + FixupKind = Hexagon::fixup_Hexagon_6_PCREL_X; + break; + // This is part of an extender, GOT_11 is a + // Word32_U6 unsigned/truncated reloc. + case llvm::MCSymbolRefExpr::VK_GOT: + FixupKind = Hexagon::fixup_Hexagon_GOT_11_X; + break; + case llvm::MCSymbolRefExpr::VK_GOTOFF: + FixupKind = Hexagon::fixup_Hexagon_GOTREL_11_X; + break; + } + } else { + errs() << "unrecognized relocation, bits " << bits << "\n"; + errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n"; + } + break; + + case 0: + FixupKind = getFixupNoBits(MCII, MI, MO, kind); + break; + } + + MCFixup fixup = + MCFixup::create(*Addend, MO.getExpr(), MCFixupKind(FixupKind)); + Fixups.push_back(fixup); + // All of the information is in the fixup. + return (0); +} + unsigned HexagonMCCodeEmitter::getMachineOpValue(MCInst const &MI, MCOperand const &MO, SmallVectorImpl<MCFixup> &Fixups, @@ -71,18 +508,16 @@ HexagonMCCodeEmitter::getMachineOpValue(MCInst const &MI, MCOperand const &MO, return MCT.getRegisterInfo()->getEncodingValue(MO.getReg()); if (MO.isImm()) return static_cast<unsigned>(MO.getImm()); - llvm_unreachable("Only Immediates and Registers implemented right now"); -} -MCSubtargetInfo const &HexagonMCCodeEmitter::getSubtargetInfo() const { - return MST; + // MO must be an ME. + assert(MO.isExpr()); + return getExprOpValue(MI, MO, MO.getExpr(), Fixups, STI); } MCCodeEmitter *llvm::createHexagonMCCodeEmitter(MCInstrInfo const &MII, MCRegisterInfo const &MRI, - MCSubtargetInfo const &MST, MCContext &MCT) { - return new HexagonMCCodeEmitter(MII, MST, MCT); + return new HexagonMCCodeEmitter(MII, MCT); } #include "HexagonGenMCCodeEmitter.inc" diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.h b/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.h index 96048adf34b7..939380af1013 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.h +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCCodeEmitter.h @@ -26,16 +26,22 @@ namespace llvm { class HexagonMCCodeEmitter : public MCCodeEmitter { - MCSubtargetInfo const &MST; MCContext &MCT; + MCInstrInfo const &MCII; + std::unique_ptr<unsigned> Addend; + std::unique_ptr<bool> Extended; + + // helper routine for getMachineOpValue() + unsigned getExprOpValue(const MCInst &MI, const MCOperand &MO, + const MCExpr *ME, SmallVectorImpl<MCFixup> &Fixups, + const MCSubtargetInfo &STI) const; public: - HexagonMCCodeEmitter(MCInstrInfo const &aMII, MCSubtargetInfo const &aMST, - MCContext &aMCT); + HexagonMCCodeEmitter(MCInstrInfo const &aMII, MCContext &aMCT); MCSubtargetInfo const &getSubtargetInfo() const; - void EncodeInstruction(MCInst const &MI, raw_ostream &OS, + void encodeInstruction(MCInst const &MI, raw_ostream &OS, SmallVectorImpl<MCFixup> &Fixups, MCSubtargetInfo const &STI) const override; @@ -51,8 +57,8 @@ public: MCSubtargetInfo const &STI) const; private: - HexagonMCCodeEmitter(HexagonMCCodeEmitter const &) LLVM_DELETED_FUNCTION; - void operator=(HexagonMCCodeEmitter const &) LLVM_DELETED_FUNCTION; + HexagonMCCodeEmitter(HexagonMCCodeEmitter const &) = delete; + void operator=(HexagonMCCodeEmitter const &) = delete; }; // class HexagonMCCodeEmitter } // namespace llvm diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInst.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInst.cpp deleted file mode 100644 index d8b9a2567eeb..000000000000 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInst.cpp +++ /dev/null @@ -1,223 +0,0 @@ -//===- HexagonMCInst.cpp - Hexagon sub-class of MCInst --------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This class extends MCInst to allow some Hexagon VLIW annotations. -// -//===----------------------------------------------------------------------===// - -#include "HexagonInstrInfo.h" -#include "MCTargetDesc/HexagonBaseInfo.h" -#include "MCTargetDesc/HexagonMCInst.h" -#include "MCTargetDesc/HexagonMCTargetDesc.h" - -using namespace llvm; - -std::unique_ptr <MCInstrInfo const> HexagonMCInst::MCII; - -HexagonMCInst::HexagonMCInst() : MCInst() {} -HexagonMCInst::HexagonMCInst(MCInstrDesc const &mcid) : MCInst() {} - -void HexagonMCInst::AppendImplicitOperands(MCInst &MCI) { - MCI.addOperand(MCOperand::CreateImm(0)); - MCI.addOperand(MCOperand::CreateInst(nullptr)); -} - -std::bitset<16> HexagonMCInst::GetImplicitBits(MCInst const &MCI) { - SanityCheckImplicitOperands(MCI); - std::bitset<16> Bits(MCI.getOperand(MCI.getNumOperands() - 2).getImm()); - return Bits; -} - -void HexagonMCInst::SetImplicitBits(MCInst &MCI, std::bitset<16> Bits) { - SanityCheckImplicitOperands(MCI); - MCI.getOperand(MCI.getNumOperands() - 2).setImm(Bits.to_ulong()); -} - -void HexagonMCInst::setPacketBegin(bool f) { - std::bitset<16> Bits(GetImplicitBits(*this)); - Bits.set(packetBeginIndex, f); - SetImplicitBits(*this, Bits); -} - -bool HexagonMCInst::isPacketBegin() const { - std::bitset<16> Bits(GetImplicitBits(*this)); - return Bits.test(packetBeginIndex); -} - -void HexagonMCInst::setPacketEnd(bool f) { - std::bitset<16> Bits(GetImplicitBits(*this)); - Bits.set(packetEndIndex, f); - SetImplicitBits(*this, Bits); -} - -bool HexagonMCInst::isPacketEnd() const { - std::bitset<16> Bits(GetImplicitBits(*this)); - return Bits.test(packetEndIndex); -} - -void HexagonMCInst::resetPacket() { - setPacketBegin(false); - setPacketEnd(false); -} - -// Return the slots used by the insn. -unsigned HexagonMCInst::getUnits(const HexagonTargetMachine *TM) const { - const HexagonInstrInfo *QII = TM->getSubtargetImpl()->getInstrInfo(); - const InstrItineraryData *II = - TM->getSubtargetImpl()->getInstrItineraryData(); - const InstrStage *IS = - II->beginStage(QII->get(this->getOpcode()).getSchedClass()); - - return (IS->getUnits()); -} - -MCInstrDesc const& HexagonMCInst::getDesc() const { return (MCII->get(getOpcode())); } - -// Return the Hexagon ISA class for the insn. -unsigned HexagonMCInst::getType() const { - const uint64_t F = getDesc().TSFlags; - - return ((F >> HexagonII::TypePos) & HexagonII::TypeMask); -} - -// Return whether the insn is an actual insn. -bool HexagonMCInst::isCanon() const { - return (!getDesc().isPseudo() && !isPrefix() && - getType() != HexagonII::TypeENDLOOP); -} - -// Return whether the insn is a prefix. -bool HexagonMCInst::isPrefix() const { - return (getType() == HexagonII::TypePREFIX); -} - -// Return whether the insn is solo, i.e., cannot be in a packet. -bool HexagonMCInst::isSolo() const { - const uint64_t F = getDesc().TSFlags; - return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask); -} - -// Return whether the insn is a new-value consumer. -bool HexagonMCInst::isNewValue() const { - const uint64_t F = getDesc().TSFlags; - return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask); -} - -// Return whether the instruction is a legal new-value producer. -bool HexagonMCInst::hasNewValue() const { - const uint64_t F = getDesc().TSFlags; - return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask); -} - -// Return the operand that consumes or produces a new value. -const MCOperand &HexagonMCInst::getNewValue() const { - const uint64_t F = getDesc().TSFlags; - const unsigned O = - (F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask; - const MCOperand &MCO = getOperand(O); - - assert((isNewValue() || hasNewValue()) && MCO.isReg()); - return (MCO); -} - -// Return whether the instruction needs to be constant extended. -// 1) Always return true if the instruction has 'isExtended' flag set. -// -// isExtendable: -// 2) For immediate extended operands, return true only if the value is -// out-of-range. -// 3) For global address, always return true. - -bool HexagonMCInst::isConstExtended(void) const { - if (isExtended()) - return true; - - if (!isExtendable()) - return false; - - short ExtOpNum = getCExtOpNum(); - int MinValue = getMinValue(); - int MaxValue = getMaxValue(); - const MCOperand &MO = getOperand(ExtOpNum); - - // We could be using an instruction with an extendable immediate and shoehorn - // a global address into it. If it is a global address it will be constant - // extended. We do this for COMBINE. - // We currently only handle isGlobal() because it is the only kind of - // object we are going to end up with here for now. - // In the future we probably should add isSymbol(), etc. - if (MO.isExpr()) - return true; - - // If the extendable operand is not 'Immediate' type, the instruction should - // have 'isExtended' flag set. - assert(MO.isImm() && "Extendable operand must be Immediate type"); - - int ImmValue = MO.getImm(); - return (ImmValue < MinValue || ImmValue > MaxValue); -} - -// Return whether the instruction must be always extended. -bool HexagonMCInst::isExtended(void) const { - const uint64_t F = getDesc().TSFlags; - return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask; -} - -// Return true if the instruction may be extended based on the operand value. -bool HexagonMCInst::isExtendable(void) const { - const uint64_t F = getDesc().TSFlags; - return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask; -} - -// Return number of bits in the constant extended operand. -unsigned HexagonMCInst::getBitCount(void) const { - const uint64_t F = getDesc().TSFlags; - return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask); -} - -// Return constant extended operand number. -unsigned short HexagonMCInst::getCExtOpNum(void) const { - const uint64_t F = getDesc().TSFlags; - return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask); -} - -// Return whether the operand can be constant extended. -bool HexagonMCInst::isOperandExtended(const unsigned short OperandNum) const { - const uint64_t F = getDesc().TSFlags; - return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) == - OperandNum; -} - -// Return the min value that a constant extendable operand can have -// without being extended. -int HexagonMCInst::getMinValue(void) const { - const uint64_t F = getDesc().TSFlags; - unsigned isSigned = - (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask; - unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask; - - if (isSigned) // if value is signed - return -1U << (bits - 1); - else - return 0; -} - -// Return the max value that a constant extendable operand can have -// without being extended. -int HexagonMCInst::getMaxValue(void) const { - const uint64_t F = getDesc().TSFlags; - unsigned isSigned = - (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask; - unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask; - - if (isSigned) // if value is signed - return ~(-1U << (bits - 1)); - else - return ~(-1U << bits); -} diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInst.h b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInst.h deleted file mode 100644 index ce9a8db5ac44..000000000000 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInst.h +++ /dev/null @@ -1,108 +0,0 @@ -//===- HexagonMCInst.h - Hexagon sub-class of MCInst ----------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This class extends MCInst to allow some VLIW annotations. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINST_H -#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINST_H - -#include "HexagonTargetMachine.h" -#include "llvm/MC/MCInst.h" -#include <memory> - -extern "C" void LLVMInitializeHexagonTargetMC(); -namespace llvm { -class MCOperand; - -class HexagonMCInst : public MCInst { - friend void ::LLVMInitializeHexagonTargetMC(); - // Used to access TSFlags - static std::unique_ptr <MCInstrInfo const> MCII; - -public: - explicit HexagonMCInst(); - HexagonMCInst(const MCInstrDesc &mcid); - - static void AppendImplicitOperands(MCInst &MCI); - static std::bitset<16> GetImplicitBits(MCInst const &MCI); - static void SetImplicitBits(MCInst &MCI, std::bitset<16> Bits); - static void SanityCheckImplicitOperands(MCInst const &MCI) { - assert(MCI.getNumOperands() >= 2 && "At least the two implicit operands"); - assert(MCI.getOperand(MCI.getNumOperands() - 1).isInst() && - "Implicit bits and flags"); - assert(MCI.getOperand(MCI.getNumOperands() - 2).isImm() && - "Parent pointer"); - } - - void setPacketBegin(bool Y); - bool isPacketBegin() const; - static const size_t packetBeginIndex = 0; - void setPacketEnd(bool Y); - bool isPacketEnd() const; - static const size_t packetEndIndex = 1; - void resetPacket(); - - // Return the slots used by the insn. - unsigned getUnits(const HexagonTargetMachine *TM) const; - - // Return the Hexagon ISA class for the insn. - unsigned getType() const; - - MCInstrDesc const &getDesc() const; - - // Return whether the insn is an actual insn. - bool isCanon() const; - - // Return whether the insn is a prefix. - bool isPrefix() const; - - // Return whether the insn is solo, i.e., cannot be in a packet. - bool isSolo() const; - - // Return whether the instruction needs to be constant extended. - bool isConstExtended() const; - - // Return constant extended operand number. - unsigned short getCExtOpNum(void) const; - - // Return whether the insn is a new-value consumer. - bool isNewValue() const; - - // Return whether the instruction is a legal new-value producer. - bool hasNewValue() const; - - // Return the operand that consumes or produces a new value. - const MCOperand &getNewValue() const; - - // Return number of bits in the constant extended operand. - unsigned getBitCount(void) const; - -private: - // Return whether the instruction must be always extended. - bool isExtended() const; - - // Return true if the insn may be extended based on the operand value. - bool isExtendable() const; - - // Return true if the operand can be constant extended. - bool isOperandExtended(const unsigned short OperandNum) const; - - // Return the min value that a constant extendable operand can have - // without being extended. - int getMinValue() const; - - // Return the max value that a constant extendable operand can have - // without being extended. - int getMaxValue() const; -}; -} - -#endif diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp new file mode 100644 index 000000000000..93c7a0d98bf2 --- /dev/null +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp @@ -0,0 +1,248 @@ +//===- HexagonMCInstrInfo.cpp - Hexagon sub-class of MCInst ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This class extends MCInstrInfo to allow Hexagon specific MCInstr queries +// +//===----------------------------------------------------------------------===// + +#include "HexagonMCInstrInfo.h" +#include "HexagonBaseInfo.h" + +namespace llvm { +void HexagonMCInstrInfo::AppendImplicitOperands(MCInst &MCI) { + MCI.addOperand(MCOperand::createImm(0)); + MCI.addOperand(MCOperand::createInst(nullptr)); +} + +HexagonII::MemAccessSize +HexagonMCInstrInfo::getAccessSize(MCInstrInfo const &MCII, MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + + return (HexagonII::MemAccessSize((F >> HexagonII::MemAccessSizePos) & + HexagonII::MemAccesSizeMask)); +} + +unsigned HexagonMCInstrInfo::getBitCount(MCInstrInfo const &MCII, + MCInst const &MCI) { + uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask); +} + +// Return constant extended operand number. +unsigned short HexagonMCInstrInfo::getCExtOpNum(MCInstrInfo const &MCII, + MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask); +} + +MCInstrDesc const &HexagonMCInstrInfo::getDesc(MCInstrInfo const &MCII, + MCInst const &MCI) { + return (MCII.get(MCI.getOpcode())); +} + +unsigned HexagonMCInstrInfo::getExtentAlignment(MCInstrInfo const &MCII, + MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::ExtentAlignPos) & HexagonII::ExtentAlignMask); +} + +unsigned HexagonMCInstrInfo::getExtentBits(MCInstrInfo const &MCII, + MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask); +} + +std::bitset<16> HexagonMCInstrInfo::GetImplicitBits(MCInst const &MCI) { + SanityCheckImplicitOperands(MCI); + std::bitset<16> Bits(MCI.getOperand(MCI.getNumOperands() - 2).getImm()); + return Bits; +} + +// Return the max value that a constant extendable operand can have +// without being extended. +int HexagonMCInstrInfo::getMaxValue(MCInstrInfo const &MCII, + MCInst const &MCI) { + uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + unsigned isSigned = + (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask; + unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask; + + if (isSigned) // if value is signed + return ~(-1U << (bits - 1)); + else + return ~(-1U << bits); +} + +// Return the min value that a constant extendable operand can have +// without being extended. +int HexagonMCInstrInfo::getMinValue(MCInstrInfo const &MCII, + MCInst const &MCI) { + uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + unsigned isSigned = + (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask; + unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask; + + if (isSigned) // if value is signed + return -1U << (bits - 1); + else + return 0; +} + +char const *HexagonMCInstrInfo::getName(MCInstrInfo const &MCII, + MCInst const &MCI) { + return MCII.getName(MCI.getOpcode()); +} + +// Return the operand that consumes or produces a new value. +MCOperand const &HexagonMCInstrInfo::getNewValue(MCInstrInfo const &MCII, + MCInst const &MCI) { + uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + unsigned const O = + (F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask; + MCOperand const &MCO = MCI.getOperand(O); + + assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) || + HexagonMCInstrInfo::hasNewValue(MCII, MCI)) && + MCO.isReg()); + return (MCO); +} + +// Return the Hexagon ISA class for the insn. +unsigned HexagonMCInstrInfo::getType(MCInstrInfo const &MCII, + MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + + return ((F >> HexagonII::TypePos) & HexagonII::TypeMask); +} + +// Return whether the instruction is a legal new-value producer. +bool HexagonMCInstrInfo::hasNewValue(MCInstrInfo const &MCII, + MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask); +} + +// Return whether the insn is an actual insn. +bool HexagonMCInstrInfo::isCanon(MCInstrInfo const &MCII, MCInst const &MCI) { + return (!HexagonMCInstrInfo::getDesc(MCII, MCI).isPseudo() && + !HexagonMCInstrInfo::isPrefix(MCII, MCI) && + HexagonMCInstrInfo::getType(MCII, MCI) != HexagonII::TypeENDLOOP); +} + +// Return whether the instruction needs to be constant extended. +// 1) Always return true if the instruction has 'isExtended' flag set. +// +// isExtendable: +// 2) For immediate extended operands, return true only if the value is +// out-of-range. +// 3) For global address, always return true. + +bool HexagonMCInstrInfo::isConstExtended(MCInstrInfo const &MCII, + MCInst const &MCI) { + if (HexagonMCInstrInfo::isExtended(MCII, MCI)) + return true; + + if (!HexagonMCInstrInfo::isExtendable(MCII, MCI)) + return false; + + short ExtOpNum = HexagonMCInstrInfo::getCExtOpNum(MCII, MCI); + int MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI); + int MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI); + MCOperand const &MO = MCI.getOperand(ExtOpNum); + + // We could be using an instruction with an extendable immediate and shoehorn + // a global address into it. If it is a global address it will be constant + // extended. We do this for COMBINE. + // We currently only handle isGlobal() because it is the only kind of + // object we are going to end up with here for now. + // In the future we probably should add isSymbol(), etc. + if (MO.isExpr()) + return true; + + // If the extendable operand is not 'Immediate' type, the instruction should + // have 'isExtended' flag set. + assert(MO.isImm() && "Extendable operand must be Immediate type"); + + int ImmValue = MO.getImm(); + return (ImmValue < MinValue || ImmValue > MaxValue); +} + +// Return true if the instruction may be extended based on the operand value. +bool HexagonMCInstrInfo::isExtendable(MCInstrInfo const &MCII, + MCInst const &MCI) { + uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask; +} + +// Return whether the instruction must be always extended. +bool HexagonMCInstrInfo::isExtended(MCInstrInfo const &MCII, + MCInst const &MCI) { + uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask; +} + +// Return whether the insn is a new-value consumer. +bool HexagonMCInstrInfo::isNewValue(MCInstrInfo const &MCII, + MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask); +} + +// Return whether the operand can be constant extended. +bool HexagonMCInstrInfo::isOperandExtended(MCInstrInfo const &MCII, + MCInst const &MCI, + unsigned short OperandNum) { + uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) == + OperandNum; +} + +bool HexagonMCInstrInfo::isPacketBegin(MCInst const &MCI) { + std::bitset<16> Bits(GetImplicitBits(MCI)); + return Bits.test(packetBeginIndex); +} + +bool HexagonMCInstrInfo::isPacketEnd(MCInst const &MCI) { + std::bitset<16> Bits(GetImplicitBits(MCI)); + return Bits.test(packetEndIndex); +} + +// Return whether the insn is a prefix. +bool HexagonMCInstrInfo::isPrefix(MCInstrInfo const &MCII, MCInst const &MCI) { + return (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypePREFIX); +} + +// Return whether the insn is solo, i.e., cannot be in a packet. +bool HexagonMCInstrInfo::isSolo(MCInstrInfo const &MCII, MCInst const &MCI) { + const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; + return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask); +} + +void HexagonMCInstrInfo::resetPacket(MCInst &MCI) { + setPacketBegin(MCI, false); + setPacketEnd(MCI, false); +} + +void HexagonMCInstrInfo::SetImplicitBits(MCInst &MCI, std::bitset<16> Bits) { + SanityCheckImplicitOperands(MCI); + MCI.getOperand(MCI.getNumOperands() - 2).setImm(Bits.to_ulong()); +} + +void HexagonMCInstrInfo::setPacketBegin(MCInst &MCI, bool f) { + std::bitset<16> Bits(GetImplicitBits(MCI)); + Bits.set(packetBeginIndex, f); + SetImplicitBits(MCI, Bits); +} + +void HexagonMCInstrInfo::setPacketEnd(MCInst &MCI, bool f) { + std::bitset<16> Bits(GetImplicitBits(MCI)); + Bits.set(packetEndIndex, f); + SetImplicitBits(MCI, Bits); +} +} diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h new file mode 100644 index 000000000000..082c80d5ac05 --- /dev/null +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h @@ -0,0 +1,122 @@ +//===- HexagonMCInstrInfo.cpp - Hexagon sub-class of MCInst ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Utility functions for Hexagon specific MCInst queries +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H +#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H + +#include "llvm/MC/MCInst.h" +#include "llvm/MC/MCInstrInfo.h" + +#include <bitset> + +namespace llvm { +class MCInstrDesc; +class MCInstrInfo; +class MCInst; +class MCOperand; +namespace HexagonII { +enum class MemAccessSize; +} +namespace HexagonMCInstrInfo { +void AppendImplicitOperands(MCInst &MCI); + +// Return memory access size +HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII, + MCInst const &MCI); + +// Return number of bits in the constant extended operand. +unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return constant extended operand number. +unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI); + +MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return the implicit alignment of the extendable operand +unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return the number of logical bits of the extendable operand +unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI); + +std::bitset<16> GetImplicitBits(MCInst const &MCI); + +// Return the max value that a constant extendable operand can have +// without being extended. +int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return the min value that a constant extendable operand can have +// without being extended. +int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return instruction name +char const *getName(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return the operand that consumes or produces a new value. +MCOperand const &getNewValue(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return the Hexagon ISA class for the insn. +unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return whether the instruction is a legal new-value producer. +bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return whether the insn is an actual insn. +bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return whether the instruction needs to be constant extended. +bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return true if the insn may be extended based on the operand value. +bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return whether the instruction must be always extended. +bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return whether the insn is a new-value consumer. +bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return true if the operand can be constant extended. +bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI, + unsigned short OperandNum); + +bool isPacketBegin(MCInst const &MCI); + +bool isPacketEnd(MCInst const &MCI); + +// Return whether the insn is a prefix. +bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI); + +// Return whether the insn is solo, i.e., cannot be in a packet. +bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI); + +static const size_t packetBeginIndex = 0; +static const size_t packetEndIndex = 1; + +void resetPacket(MCInst &MCI); + +inline void SanityCheckImplicitOperands(MCInst const &MCI) { + assert(MCI.getNumOperands() >= 2 && "At least the two implicit operands"); + assert(MCI.getOperand(MCI.getNumOperands() - 1).isInst() && + "Implicit bits and flags"); + assert(MCI.getOperand(MCI.getNumOperands() - 2).isImm() && "Parent pointer"); +} + +void SetImplicitBits(MCInst &MCI, std::bitset<16> Bits); + +void setPacketBegin(MCInst &MCI, bool Y); + +void setPacketEnd(MCInst &MCI, bool Y); +} +} + +#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp index ae5a22bdb01b..59395e230fa9 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -14,7 +14,6 @@ #include "HexagonMCTargetDesc.h" #include "HexagonMCAsmInfo.h" #include "MCTargetDesc/HexagonInstPrinter.h" -#include "MCTargetDesc/HexagonMCInst.h" #include "llvm/MC/MCCodeGenInfo.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCInstrInfo.h" @@ -36,7 +35,7 @@ using namespace llvm; #define GET_REGINFO_MC_DESC #include "HexagonGenRegisterInfo.inc" -static MCInstrInfo *createHexagonMCInstrInfo() { +MCInstrInfo *llvm::createHexagonMCInstrInfo() { MCInstrInfo *X = new MCInstrInfo(); InitHexagonMCInstrInfo(X); return X; @@ -48,15 +47,6 @@ static MCRegisterInfo *createHexagonMCRegisterInfo(StringRef TT) { return X; } -static MCStreamer * -createHexagonELFStreamer(MCContext &Context, MCAsmBackend &MAB, - raw_ostream &OS, MCCodeEmitter *CE, - bool RelaxAll) { - MCELFStreamer *ES = new MCELFStreamer(Context, MAB, OS, CE); - return ES; -} - - static MCSubtargetInfo * createHexagonMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS) { MCSubtargetInfo *X = new MCSubtargetInfo(); @@ -76,32 +66,25 @@ static MCAsmInfo *createHexagonMCAsmInfo(const MCRegisterInfo &MRI, return MAI; } -static MCStreamer *createMCStreamer(Target const &T, StringRef TT, - MCContext &Context, MCAsmBackend &MAB, - raw_ostream &OS, MCCodeEmitter *Emitter, - MCSubtargetInfo const &STI, bool RelaxAll) { - MCStreamer *ES = createHexagonELFStreamer(Context, MAB, OS, Emitter, RelaxAll); - new MCTargetStreamer(*ES); - return ES; -} - - static MCCodeGenInfo *createHexagonMCCodeGenInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL) { MCCodeGenInfo *X = new MCCodeGenInfo(); // For the time being, use static relocations, since there's really no // support for PIC yet. - X->InitMCCodeGenInfo(Reloc::Static, CM, OL); + X->initMCCodeGenInfo(Reloc::Static, CM, OL); return X; } -static MCInstPrinter *createHexagonMCInstPrinter(const Target &T, + +static MCInstPrinter *createHexagonMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, - const MCRegisterInfo &MRI, - const MCSubtargetInfo &STI) { - return new HexagonInstPrinter(MAI, MII, MRI); + const MCRegisterInfo &MRI) { + if (SyntaxVariant == 0) + return(new HexagonInstPrinter(MAI, MII, MRI)); + else + return nullptr; } // Force static initialization. @@ -116,7 +99,6 @@ extern "C" void LLVMInitializeHexagonTargetMC() { // Register the MC instruction info. TargetRegistry::RegisterMCInstrInfo(TheHexagonTarget, createHexagonMCInstrInfo); - HexagonMCInst::MCII.reset (createHexagonMCInstrInfo()); // Register the MC register info. TargetRegistry::RegisterMCRegInfo(TheHexagonTarget, @@ -137,7 +119,4 @@ extern "C" void LLVMInitializeHexagonTargetMC() { // Register the asm backend TargetRegistry::RegisterMCAsmBackend(TheHexagonTarget, createHexagonAsmBackend); - - // Register the obj streamer - TargetRegistry::RegisterMCObjectStreamer(TheHexagonTarget, createMCStreamer); } diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h b/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h index 02fd5161d24a..de63fd271aea 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h @@ -27,20 +27,22 @@ class MCSubtargetInfo; class Target; class StringRef; class raw_ostream; +class raw_pwrite_stream; extern Target TheHexagonTarget; +MCInstrInfo *createHexagonMCInstrInfo(); + MCCodeEmitter *createHexagonMCCodeEmitter(MCInstrInfo const &MCII, MCRegisterInfo const &MRI, - MCSubtargetInfo const &MST, MCContext &MCT); MCAsmBackend *createHexagonAsmBackend(Target const &T, MCRegisterInfo const &MRI, StringRef TT, StringRef CPU); -MCObjectWriter *createHexagonELFObjectWriter(raw_ostream &OS, uint8_t OSABI, - StringRef CPU); +MCObjectWriter *createHexagonELFObjectWriter(raw_pwrite_stream &OS, + uint8_t OSABI, StringRef CPU); } // End llvm namespace |