From 0ef44d5022c89c5f3fbd7f3de5ee8ff3be03cc55 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 12 Apr 2025 16:25:59 -0700 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?= =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5-bogner [skip ci] --- .../Target/RISCV/AsmParser/RISCVAsmParser.cpp | 28 ++----------------- .../RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 4 +-- .../MCTargetDesc/RISCVELFObjectWriter.cpp | 2 +- .../RISCV/MCTargetDesc/RISCVFixupKinds.h | 2 +- .../RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp | 5 ++-- .../Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp | 5 +--- .../Target/RISCV/MCTargetDesc/RISCVMCExpr.h | 1 - llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td | 2 +- llvm/test/MC/RISCV/xqcilb-invalid.s | 4 +-- llvm/test/MC/RISCV/xqcilb-relocations.s | 22 ++++----------- 10 files changed, 18 insertions(+), 57 deletions(-) diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 55f1a90b2a01a..952587171ffce 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -591,16 +591,7 @@ struct RISCVOperand final : public MCParsedAsmOperand { (VK == RISCVMCExpr::VK_CALL || VK == RISCVMCExpr::VK_CALL_PLT); } - bool isPseudoQCJumpSymbol() const { - int64_t Imm; - // Must be of 'immediate' type but not a constant. - if (!isImm() || evaluateConstantImm(getImm(), Imm)) - return false; - - RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None; - return RISCVAsmParser::classifySymbolRef(getImm(), VK) && - VK == RISCVMCExpr::VK_QC_E_JUMP_PLT; - } + bool isPseudoQCJumpSymbol() const { return isBareSymbol(); } bool isPseudoJumpSymbol() const { int64_t Imm; @@ -2157,25 +2148,10 @@ ParseStatus RISCVAsmParser::parsePseudoQCJumpSymbol(OperandVector &Operands) { std::string Identifier(getTok().getIdentifier()); SMLoc E = getTok().getEndLoc(); - - if (getLexer().peekTok().is(AsmToken::At)) { - Lex(); - Lex(); - SMLoc PLTLoc = getLoc(); - StringRef PLT; - E = getTok().getEndLoc(); - if (getParser().parseIdentifier(PLT) || PLT != "plt") - return Error(PLTLoc, - "'@plt' is the only valid operand for this instruction"); - } else { - Lex(); - } - - RISCVMCExpr::Specifier Kind = RISCVMCExpr::VK_QC_E_JUMP_PLT; + Lex(); MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier); Res = MCSymbolRefExpr::create(Sym, getContext()); - Res = RISCVMCExpr::create(Res, Kind, getContext()); Operands.push_back(RISCVOperand::createImm(Res, S, E, isRV64())); return ParseStatus::Success; } diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp index 49c8c6957aa34..3fa52ddc344e7 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -95,7 +95,7 @@ RISCVAsmBackend::getFixupKindInfo(MCFixupKind Kind) const { {"fixup_riscv_qc_e_branch", 0, 48, MCFixupKindInfo::FKF_IsPCRel}, {"fixup_riscv_qc_e_32", 16, 32, 0}, {"fixup_riscv_qc_abs20_u", 12, 20, 0}, - {"fixup_riscv_qc_e_jump_plt", 0, 48, MCFixupKindInfo::FKF_IsPCRel}, + {"fixup_riscv_qc_e_jump", 0, 48, MCFixupKindInfo::FKF_IsPCRel}, }; static_assert((std::size(Infos)) == RISCV::NumTargetFixupKinds, "Not all fixup kinds added to Infos array"); @@ -576,7 +576,7 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value, Value = (Bit19 << 31) | (Bit14_0 << 16) | (Bit18_15 << 12); return Value; } - case RISCV::fixup_riscv_qc_e_jump_plt: { + case RISCV::fixup_riscv_qc_e_jump: { if (!isInt<32>(Value)) Ctx.reportError(Fixup.getLoc(), "fixup value out of range"); if (Value & 0x1) diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp index 59dc79b57b456..1b994d120ae74 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp @@ -119,7 +119,7 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx, return ELF::R_RISCV_CALL_PLT; case RISCV::fixup_riscv_qc_e_branch: return ELF::R_RISCV_QC_E_BRANCH; - case RISCV::fixup_riscv_qc_e_jump_plt: + case RISCV::fixup_riscv_qc_e_jump: return ELF::R_RISCV_QC_E_JUMP_PLT; } } diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h index 596c4eb5fffaa..a7ed21bf76908 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h @@ -85,7 +85,7 @@ enum Fixups { // 20-bit fixup for symbol references in the 32-bit qc.li instruction fixup_riscv_qc_abs20_u, // 32-bit fixup for symbol references in the 48-bit qc.j/qc.jal instructions - fixup_riscv_qc_e_jump_plt, + fixup_riscv_qc_e_jump, // Used as a sentinel, must be the last fixup_riscv_invalid, diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp index f324907d49fd9..15e405a430d87 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp @@ -685,9 +685,6 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo, case RISCVMCExpr::VK_QC_ABS20: FixupKind = RISCV::fixup_riscv_qc_abs20_u; break; - case RISCVMCExpr::VK_QC_E_JUMP_PLT: - FixupKind = RISCV::fixup_riscv_qc_e_jump_plt; - break; } } else if (Kind == MCExpr::SymbolRef || Kind == MCExpr::Binary) { // FIXME: Sub kind binary exprs have chance of underflow. @@ -705,6 +702,8 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo, FixupKind = RISCV::fixup_riscv_qc_e_branch; } else if (MIFrm == RISCVII::InstFormatQC_EAI) { FixupKind = RISCV::fixup_riscv_qc_e_32; + } else if (MIFrm == RISCVII::InstFormatQC_EJ) { + FixupKind = RISCV::fixup_riscv_qc_e_jump; } } diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp index 99f72620f97ed..d6650e156c8b3 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp @@ -34,8 +34,7 @@ const RISCVMCExpr *RISCVMCExpr::create(const MCExpr *Expr, Specifier S, void RISCVMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { Specifier S = getSpecifier(); - bool HasVariant = ((S != VK_None) && (S != VK_CALL) && (S != VK_CALL_PLT) && - (S != VK_QC_E_JUMP_PLT)); + bool HasVariant = ((S != VK_None) && (S != VK_CALL) && (S != VK_CALL_PLT)); if (HasVariant) OS << '%' << getSpecifierName(S) << '('; @@ -168,8 +167,6 @@ StringRef RISCVMCExpr::getSpecifierName(Specifier S) { return "pltpcrel"; case VK_QC_ABS20: return "qc.abs20"; - case VK_QC_E_JUMP_PLT: - return "qc_e_jump_plt"; } llvm_unreachable("Invalid ELF symbol kind"); } diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h index d60879d34dc17..e0aa7ff244521 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h @@ -44,7 +44,6 @@ class RISCVMCExpr : public MCTargetExpr { VK_TLSDESC_ADD_LO, VK_TLSDESC_CALL, VK_QC_ABS20, - VK_QC_E_JUMP_PLT }; private: diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td index 4ac17c8283866..b899c18785538 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td @@ -158,7 +158,7 @@ def PseudoQCJumpSymbol : AsmOperandClass { let RenderMethod = "addImmOperands"; let DiagnosticType = "InvalidPseudoQCJumpSymbol"; let DiagnosticString = "operand must be a valid jump target"; - let ParserMethod = "parsePseudoQCJumpSymbol"; + let ParserMethod = "parseBareSymbol"; } def pseudo_qc_jump_symbol : Operand { diff --git a/llvm/test/MC/RISCV/xqcilb-invalid.s b/llvm/test/MC/RISCV/xqcilb-invalid.s index 10d456c8ac0aa..652c3f6163430 100644 --- a/llvm/test/MC/RISCV/xqcilb-invalid.s +++ b/llvm/test/MC/RISCV/xqcilb-invalid.s @@ -23,5 +23,5 @@ qc.e.jal 2147483649 # CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcilb' (Qualcomm uC Long Branch Extension) qc.e.jal 2147483640 -# CHECK: :[[@LINE+1]]:12: error: '@plt' is the only valid operand for this instruction -qc.e.j foo@rlt +# CHECK: :[[@LINE+1]]:11: error: unexpected token +qc.e.j foo@plt diff --git a/llvm/test/MC/RISCV/xqcilb-relocations.s b/llvm/test/MC/RISCV/xqcilb-relocations.s index a475cde3f6bfd..3e6410615156a 100644 --- a/llvm/test/MC/RISCV/xqcilb-relocations.s +++ b/llvm/test/MC/RISCV/xqcilb-relocations.s @@ -13,42 +13,32 @@ qc.e.j foo # RELOC: R_RISCV_CUSTOM195 foo 0x0 # INSTR: qc.e.j foo -# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_qc_e_jump_plt - -qc.e.j foo@plt -# RELOC: R_RISCV_CUSTOM195 foo 0x0 -# INSTR: qc.e.j foo -# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_qc_e_jump_plt - -qc.e.jal foo@plt -# RELOC: R_RISCV_CUSTOM195 foo 0x0 -# INSTR: qc.e.jal foo -# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_qc_e_jump_plt +# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_qc_e_jump qc.e.jal foo # RELOC: R_RISCV_CUSTOM195 foo 0x0 # INSTR: qc.e.jal foo -# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_qc_e_jump_plt +# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_qc_e_jump # Check that a label in a different section is handled similar to an undefined symbol qc.e.j .bar # RELOC: R_RISCV_CUSTOM195 .bar 0x0 # INSTR: qc.e.j .bar -# FIXUP: fixup A - offset: 0, value: .bar, kind: fixup_riscv_qc_e_jump_plt +# FIXUP: fixup A - offset: 0, value: .bar, kind: fixup_riscv_qc_e_jump qc.e.jal .bar # RELOC: R_RISCV_CUSTOM195 .bar 0x0 # INSTR: qc.e.jal .bar -# FIXUP: fixup A - offset: 0, value: .bar, kind: fixup_riscv_qc_e_jump_plt +# FIXUP: fixup A - offset: 0, value: .bar, kind: fixup_riscv_qc_e_jump # Check that jumps to a defined symbol are handled correctly qc.e.j .L1 # INSTR:qc.e.j .L1 -# FIXUP: fixup A - offset: 0, value: .L1, kind: fixup_riscv_qc_e_jump_plt +# FIXUP: fixup A - offset: 0, value: .L1, kind: fixup_riscv_qc_e_jump qc.e.jal .L1 # INSTR:qc.e.jal .L1 -# FIXUP: fixup A - offset: 0, value: .L1, kind: fixup_riscv_qc_e_jump_plt +# FIXUP: fixup A - offset: 0, value: .L1, kind: fixup_riscv_qc_e_jump .L1: ret From 3579f7d24a771f4c02e796a2ac9b91024b3c6ce9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 12 Apr 2025 16:27:14 -0700 Subject: [PATCH 2/2] . Created using spr 1.3.5-bogner --- llvm/test/MC/RISCV/function-call-invalid.s | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/test/MC/RISCV/function-call-invalid.s b/llvm/test/MC/RISCV/function-call-invalid.s index d429c4e27ba14..17d02015a6949 100644 --- a/llvm/test/MC/RISCV/function-call-invalid.s +++ b/llvm/test/MC/RISCV/function-call-invalid.s @@ -11,3 +11,4 @@ call %hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call %lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call foo, bar # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call foo@pls # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored @plt) is disallowed +call foo@3 # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored @plt) is disallowed