diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc')
7 files changed, 100 insertions, 69 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp index 83c44e0682ce..5a9ecfe74ecc 100644 --- a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp +++ b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp @@ -255,12 +255,6 @@ namespace { } } - bool mayNeedRelaxation(const MCInst &Inst, - const MCSubtargetInfo &STI) const override { - // FIXME. - return false; - } - /// fixupNeedsRelaxation - Target specific predicate for whether a given /// fixup requires the associated instruction to be relaxed. bool fixupNeedsRelaxation(const MCFixup &Fixup, diff --git a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp index f6728a070736..8e4621946008 100644 --- a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp +++ b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp @@ -141,24 +141,34 @@ void SparcInstPrinter::printOperand(const MCInst *MI, int opNum, void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &O, const char *Modifier) { - printOperand(MI, opNum, STI, O); - // If this is an ADD operand, emit it like normal operands. if (Modifier && !strcmp(Modifier, "arith")) { + printOperand(MI, opNum, STI, O); O << ", "; - printOperand(MI, opNum+1, STI, O); + printOperand(MI, opNum + 1, STI, O); return; } - const MCOperand &MO = MI->getOperand(opNum+1); - if (MO.isReg() && MO.getReg() == SP::G0) - return; // don't print "+%g0" - if (MO.isImm() && MO.getImm() == 0) - return; // don't print "+0" + const MCOperand &Op1 = MI->getOperand(opNum); + const MCOperand &Op2 = MI->getOperand(opNum + 1); + + bool PrintedFirstOperand = false; + if (Op1.isReg() && Op1.getReg() != SP::G0) { + printOperand(MI, opNum, STI, O); + PrintedFirstOperand = true; + } - O << "+"; + // Skip the second operand iff it adds nothing (literal 0 or %g0) and we've + // already printed the first one + const bool SkipSecondOperand = + PrintedFirstOperand && ((Op2.isReg() && Op2.getReg() == SP::G0) || + (Op2.isImm() && Op2.getImm() == 0)); - printOperand(MI, opNum+1, STI, O); + if (!SkipSecondOperand) { + if (PrintedFirstOperand) + O << '+'; + printOperand(MI, opNum + 1, STI, O); + } } void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum, diff --git a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h index 11587f165ef2..91b78bd03fc3 100644 --- a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h +++ b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h @@ -31,6 +31,7 @@ public: bool isV9(const MCSubtargetInfo &STI) const; // Autogenerated by tblgen. + std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override; void printInstruction(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O); bool printAliasInstr(const MCInst *MI, uint64_t Address, diff --git a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp index 7e908011bd50..9f8522541332 100644 --- a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp +++ b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp @@ -22,6 +22,7 @@ #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" @@ -68,13 +69,15 @@ public: unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const; - unsigned getCallTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const; unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const; + unsigned getSImm13OpValue(const MCInst &MI, unsigned OpNo, + SmallVectorImpl<MCFixup> &Fixups, + const MCSubtargetInfo &STI) const; unsigned getBranchPredTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const; @@ -146,20 +149,50 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO, return 0; } +unsigned +SparcMCCodeEmitter::getSImm13OpValue(const MCInst &MI, unsigned OpNo, + SmallVectorImpl<MCFixup> &Fixups, + const MCSubtargetInfo &STI) const { + const MCOperand &MO = MI.getOperand(OpNo); + + if (MO.isImm()) + return MO.getImm(); + + assert(MO.isExpr() && + "getSImm13OpValue expects only expressions or an immediate"); + + const MCExpr *Expr = MO.getExpr(); + + // Constant value, no fixup is needed + if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) + return CE->getValue(); + + MCFixupKind Kind; + if (const SparcMCExpr *SExpr = dyn_cast<SparcMCExpr>(Expr)) { + Kind = MCFixupKind(SExpr->getFixupKind()); + } else { + bool IsPic = Ctx.getObjectFileInfo()->isPositionIndependent(); + Kind = IsPic ? MCFixupKind(Sparc::fixup_sparc_got13) + : MCFixupKind(Sparc::fixup_sparc_13); + } + + Fixups.push_back(MCFixup::create(0, Expr, Kind)); + return 0; +} + unsigned SparcMCCodeEmitter:: getCallTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const { const MCOperand &MO = MI.getOperand(OpNo); - if (MO.isReg() || MO.isImm()) - return getMachineOpValue(MI, MO, Fixups, STI); + const MCExpr *Expr = MO.getExpr(); + const SparcMCExpr *SExpr = dyn_cast<SparcMCExpr>(Expr); if (MI.getOpcode() == SP::TLS_CALL) { // No fixups for __tls_get_addr. Will emit for fixups for tls_symbol in // encodeInstruction. #ifndef NDEBUG // Verify that the callee is actually __tls_get_addr. - const SparcMCExpr *SExpr = dyn_cast<SparcMCExpr>(MO.getExpr()); assert(SExpr && SExpr->getSubExpr()->getKind() == MCExpr::SymbolRef && "Unexpected expression in TLS_CALL"); const MCSymbolRefExpr *SymExpr = cast<MCSymbolRefExpr>(SExpr->getSubExpr()); @@ -169,15 +202,8 @@ getCallTargetOpValue(const MCInst &MI, unsigned OpNo, return 0; } - MCFixupKind fixupKind = (MCFixupKind)Sparc::fixup_sparc_call30; - - if (const SparcMCExpr *SExpr = dyn_cast<SparcMCExpr>(MO.getExpr())) { - if (SExpr->getKind() == SparcMCExpr::VK_Sparc_WPLT30) - fixupKind = (MCFixupKind)Sparc::fixup_sparc_wplt30; - } - - Fixups.push_back(MCFixup::create(0, MO.getExpr(), fixupKind)); - + MCFixupKind Kind = MCFixupKind(SExpr->getFixupKind()); + Fixups.push_back(MCFixup::create(0, Expr, Kind)); return 0; } diff --git a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp index 00f319fc37e1..b84ecf074455 100644 --- a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp +++ b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp @@ -41,46 +41,46 @@ void SparcMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { bool SparcMCExpr::printVariantKind(raw_ostream &OS, VariantKind Kind) { - bool closeParen = true; switch (Kind) { - case VK_Sparc_None: closeParen = false; break; - case VK_Sparc_LO: OS << "%lo("; break; - case VK_Sparc_HI: OS << "%hi("; break; - case VK_Sparc_H44: OS << "%h44("; break; - case VK_Sparc_M44: OS << "%m44("; break; - case VK_Sparc_L44: OS << "%l44("; break; - case VK_Sparc_HH: OS << "%hh("; break; - case VK_Sparc_HM: OS << "%hm("; break; + case VK_Sparc_None: return false; + case VK_Sparc_LO: OS << "%lo("; return true; + case VK_Sparc_HI: OS << "%hi("; return true; + case VK_Sparc_H44: OS << "%h44("; return true; + case VK_Sparc_M44: OS << "%m44("; return true; + case VK_Sparc_L44: OS << "%l44("; return true; + case VK_Sparc_HH: OS << "%hh("; return true; + case VK_Sparc_HM: OS << "%hm("; return true; // FIXME: use %pc22/%pc10, if system assembler supports them. - case VK_Sparc_PC22: OS << "%hi("; break; - case VK_Sparc_PC10: OS << "%lo("; break; + case VK_Sparc_PC22: OS << "%hi("; return true; + case VK_Sparc_PC10: OS << "%lo("; return true; // FIXME: use %got22/%got10, if system assembler supports them. - case VK_Sparc_GOT22: OS << "%hi("; break; - case VK_Sparc_GOT10: OS << "%lo("; break; - case VK_Sparc_GOT13: closeParen = false; break; - case VK_Sparc_13: closeParen = false; break; - case VK_Sparc_WPLT30: closeParen = false; break; - case VK_Sparc_R_DISP32: OS << "%r_disp32("; break; - case VK_Sparc_TLS_GD_HI22: OS << "%tgd_hi22("; break; - case VK_Sparc_TLS_GD_LO10: OS << "%tgd_lo10("; break; - case VK_Sparc_TLS_GD_ADD: OS << "%tgd_add("; break; - case VK_Sparc_TLS_GD_CALL: OS << "%tgd_call("; break; - case VK_Sparc_TLS_LDM_HI22: OS << "%tldm_hi22("; break; - case VK_Sparc_TLS_LDM_LO10: OS << "%tldm_lo10("; break; - case VK_Sparc_TLS_LDM_ADD: OS << "%tldm_add("; break; - case VK_Sparc_TLS_LDM_CALL: OS << "%tldm_call("; break; - case VK_Sparc_TLS_LDO_HIX22: OS << "%tldo_hix22("; break; - case VK_Sparc_TLS_LDO_LOX10: OS << "%tldo_lox10("; break; - case VK_Sparc_TLS_LDO_ADD: OS << "%tldo_add("; break; - case VK_Sparc_TLS_IE_HI22: OS << "%tie_hi22("; break; - case VK_Sparc_TLS_IE_LO10: OS << "%tie_lo10("; break; - case VK_Sparc_TLS_IE_LD: OS << "%tie_ld("; break; - case VK_Sparc_TLS_IE_LDX: OS << "%tie_ldx("; break; - case VK_Sparc_TLS_IE_ADD: OS << "%tie_add("; break; - case VK_Sparc_TLS_LE_HIX22: OS << "%tle_hix22("; break; - case VK_Sparc_TLS_LE_LOX10: OS << "%tle_lox10("; break; + case VK_Sparc_GOT22: OS << "%hi("; return true; + case VK_Sparc_GOT10: OS << "%lo("; return true; + case VK_Sparc_GOT13: return false; + case VK_Sparc_13: return false; + case VK_Sparc_WDISP30: return false; + case VK_Sparc_WPLT30: return false; + case VK_Sparc_R_DISP32: OS << "%r_disp32("; return true; + case VK_Sparc_TLS_GD_HI22: OS << "%tgd_hi22("; return true; + case VK_Sparc_TLS_GD_LO10: OS << "%tgd_lo10("; return true; + case VK_Sparc_TLS_GD_ADD: OS << "%tgd_add("; return true; + case VK_Sparc_TLS_GD_CALL: OS << "%tgd_call("; return true; + case VK_Sparc_TLS_LDM_HI22: OS << "%tldm_hi22("; return true; + case VK_Sparc_TLS_LDM_LO10: OS << "%tldm_lo10("; return true; + case VK_Sparc_TLS_LDM_ADD: OS << "%tldm_add("; return true; + case VK_Sparc_TLS_LDM_CALL: OS << "%tldm_call("; return true; + case VK_Sparc_TLS_LDO_HIX22: OS << "%tldo_hix22("; return true; + case VK_Sparc_TLS_LDO_LOX10: OS << "%tldo_lox10("; return true; + case VK_Sparc_TLS_LDO_ADD: OS << "%tldo_add("; return true; + case VK_Sparc_TLS_IE_HI22: OS << "%tie_hi22("; return true; + case VK_Sparc_TLS_IE_LO10: OS << "%tie_lo10("; return true; + case VK_Sparc_TLS_IE_LD: OS << "%tie_ld("; return true; + case VK_Sparc_TLS_IE_LDX: OS << "%tie_ldx("; return true; + case VK_Sparc_TLS_IE_ADD: OS << "%tie_add("; return true; + case VK_Sparc_TLS_LE_HIX22: OS << "%tle_hix22("; return true; + case VK_Sparc_TLS_LE_LOX10: OS << "%tle_lox10("; return true; } - return closeParen; + llvm_unreachable("Unhandled SparcMCExpr::VariantKind"); } SparcMCExpr::VariantKind SparcMCExpr::parseVariantKind(StringRef name) @@ -137,6 +137,7 @@ Sparc::Fixups SparcMCExpr::getFixupKind(SparcMCExpr::VariantKind Kind) { case VK_Sparc_GOT13: return Sparc::fixup_sparc_got13; case VK_Sparc_13: return Sparc::fixup_sparc_13; case VK_Sparc_WPLT30: return Sparc::fixup_sparc_wplt30; + case VK_Sparc_WDISP30: return Sparc::fixup_sparc_call30; case VK_Sparc_TLS_GD_HI22: return Sparc::fixup_sparc_tls_gd_hi22; case VK_Sparc_TLS_GD_LO10: return Sparc::fixup_sparc_tls_gd_lo10; case VK_Sparc_TLS_GD_ADD: return Sparc::fixup_sparc_tls_gd_add; @@ -205,10 +206,8 @@ void SparcMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const { MCSymbol *Symbol = Asm.getContext().getOrCreateSymbol("__tls_get_addr"); Asm.registerSymbol(*Symbol); auto ELFSymbol = cast<MCSymbolELF>(Symbol); - if (!ELFSymbol->isBindingSet()) { + if (!ELFSymbol->isBindingSet()) ELFSymbol->setBinding(ELF::STB_GLOBAL); - ELFSymbol->setExternal(true); - } LLVM_FALLTHROUGH; } case VK_Sparc_TLS_GD_HI22: diff --git a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h index c2467faca257..76603530e521 100644 --- a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h +++ b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h @@ -38,6 +38,7 @@ public: VK_Sparc_GOT13, VK_Sparc_13, VK_Sparc_WPLT30, + VK_Sparc_WDISP30, VK_Sparc_R_DISP32, VK_Sparc_TLS_GD_HI22, VK_Sparc_TLS_GD_LO10, diff --git a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp index fb2bcdc6c91b..9531e3105fe2 100644 --- a/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp +++ b/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp @@ -68,7 +68,7 @@ static MCSubtargetInfo * createSparcMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { if (CPU.empty()) CPU = (TT.getArch() == Triple::sparcv9) ? "v9" : "v8"; - return createSparcMCSubtargetInfoImpl(TT, CPU, FS); + return createSparcMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS); } static MCTargetStreamer * |