33#define DEBUG_TYPE "loongarch-asm-parser"
39 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
40 bool is64Bit()
const {
return getSTI().hasFeature(LoongArch::Feature64Bit); }
41 bool has32S()
const {
return getSTI().hasFeature(LoongArch::Feature32S); }
43 assert(getParser().getStreamer().getTargetStreamer() &&
44 "do not have a target streamer");
59 SMLoc &EndLoc)
override;
64 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
67 bool MatchingInlineAsm)
override;
69 unsigned checkTargetMatchPredicate(
MCInst &Inst)
override;
72 unsigned Kind)
override;
86#define GET_ASSEMBLER_HEADER
87#include "LoongArchGenAsmMatcher.inc"
97 bool parseDirectiveOption();
98 bool parseDirectiveDtpRelWord();
99 bool parseDirectiveDtpRelDWord();
104 setAvailableFeatures(
109 void clearFeatureBits(
uint64_t Feature, StringRef FeatureString) {
111 MCSubtargetInfo &STI = copySTI();
112 setAvailableFeatures(
117 void pushFeatureBits() {
118 FeatureBitStack.push_back(getSTI().getFeatureBits());
121 bool popFeatureBits() {
122 if (FeatureBitStack.empty())
125 FeatureBitset FeatureBits = FeatureBitStack.pop_back_val();
126 copySTI().setFeatureBits(FeatureBits);
127 setAvailableFeatures(ComputeAvailableFeatures(FeatureBits));
134 void emitLAInstSeq(MCRegister DestReg, MCRegister TmpReg,
135 const MCExpr *Symbol, SmallVectorImpl<Inst> &Insts,
136 SMLoc IDLoc, MCStreamer &Out,
bool RelaxHint =
false);
139 void emitLoadAddressAbs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
142 void emitLoadAddressPcrel(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
144 void emitLoadAddressPcrelLarge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
147 void emitLoadAddressGot(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
149 void emitLoadAddressGotLarge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
152 void emitLoadAddressTLSLE(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
155 void emitLoadAddressTLSIE(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
157 void emitLoadAddressTLSIELarge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
160 void emitLoadAddressTLSLD(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
162 void emitLoadAddressTLSLDLarge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
165 void emitLoadAddressTLSGD(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
167 void emitLoadAddressTLSGDLarge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
170 void emitLoadAddressTLSDesc(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
172 void emitLoadAddressTLSDescLarge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
175 void emitLoadImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
178 void emitFuncCall(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
bool IsTailCall,
182 enum LoongArchMatchResultTy {
183 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
184 Match_RequiresMsbNotLessThanLsb,
185 Match_RequiresOpnd2NotR0R1,
186 Match_RequiresAMORdDifferRkRj,
187 Match_RequiresLAORdDifferRj,
188 Match_RequiresLAORdR4,
189#define GET_OPERAND_DIAGNOSTIC_TYPES
190#include "LoongArchGenAsmMatcher.inc"
191#undef GET_OPERAND_DIAGNOSTIC_TYPES
194 static bool classifySymbolRef(
const MCExpr *Expr,
197 LoongArchAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &Parser,
198 const MCInstrInfo &MII)
199 : MCTargetAsmParser(STI, MII) {
206 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
226 SMLoc StartLoc, EndLoc;
234 LoongArchOperand(KindTy K) : MCParsedAsmOperand(), Kind(
K) {}
236 bool isToken()
const override {
return Kind == KindTy::Token; }
237 bool isReg()
const override {
return Kind == KindTy::Register; }
238 bool isImm()
const override {
return Kind == KindTy::Immediate; }
239 bool isMem()
const override {
return false; }
241 return Kind == KindTy::Register &&
242 getLoongArchMCRegisterClass(LoongArch::GPRRegClassID)
243 .contains(
Reg.RegNum);
246 static bool evaluateConstantImm(
const MCExpr *Expr, int64_t &
Imm,
249 VK =
LE->getSpecifier();
254 Imm =
CE->getValue();
261 template <
unsigned N,
int P = 0>
bool isUImm()
const {
267 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
272 template <
unsigned N,
unsigned S = 0>
bool isSImm()
const {
278 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
283 bool isBareSymbol()
const {
287 if (!isImm() || evaluateConstantImm(
getImm(),
Imm, VK))
289 return LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
293 bool isTPRelAddSymbol()
const {
297 if (!isImm() || evaluateConstantImm(
getImm(),
Imm, VK))
299 return LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
300 VK == ELF::R_LARCH_TLS_LE_ADD_R;
303 bool isUImm1()
const {
return isUImm<1>(); }
304 bool isUImm2()
const {
return isUImm<2>(); }
305 bool isUImm2plus1()
const {
return isUImm<2, 1>(); }
306 bool isUImm3()
const {
return isUImm<3>(); }
307 bool isUImm4()
const {
return isUImm<4>(); }
308 bool isSImm5()
const {
return isSImm<5>(); }
309 bool isUImm5()
const {
return isUImm<5>(); }
310 bool isUImm6()
const {
return isUImm<6>(); }
311 bool isUImm7()
const {
return isUImm<7>(); }
312 bool isSImm8()
const {
return isSImm<8>(); }
313 bool isSImm8lsl1()
const {
return isSImm<8, 1>(); }
314 bool isSImm8lsl2()
const {
return isSImm<8, 2>(); }
315 bool isSImm8lsl3()
const {
return isSImm<8, 3>(); }
316 bool isUImm8()
const {
return isUImm<8>(); }
317 bool isSImm9lsl3()
const {
return isSImm<9, 3>(); }
318 bool isSImm10()
const {
return isSImm<10>(); }
319 bool isSImm10lsl2()
const {
return isSImm<10, 2>(); }
320 bool isSImm11lsl1()
const {
return isSImm<11, 1>(); }
321 bool isSImm12()
const {
return isSImm<12>(); }
323 bool isSImm12addlike()
const {
329 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
332 VK == ELF::R_LARCH_GOT_PC_LO12 || VK == ELF::R_LARCH_TLS_IE_PC_LO12 ||
333 VK == ELF::R_LARCH_TLS_LE_LO12_R || VK == ELF::R_LARCH_TLS_DESC_LD ||
334 VK == ELF::R_LARCH_TLS_DESC_PC_LO12 || VK == ELF::R_LARCH_PCADD_LO12 ||
335 VK == ELF::R_LARCH_GOT_PCADD_LO12 ||
336 VK == ELF::R_LARCH_TLS_IE_PCADD_LO12 ||
337 VK == ELF::R_LARCH_TLS_LD_PCADD_LO12 ||
338 VK == ELF::R_LARCH_TLS_GD_PCADD_LO12 ||
339 VK == ELF::R_LARCH_TLS_DESC_PCADD_LO12;
342 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
346 bool isSImm12lu52id()
const {
352 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
355 VK == ELF::R_LARCH_PCALA64_HI12 || VK == ELF::R_LARCH_GOT64_HI12 ||
356 VK == ELF::R_LARCH_GOT64_PC_HI12 || VK == ELF::R_LARCH_TLS_LE64_HI12 ||
357 VK == ELF::R_LARCH_TLS_IE64_HI12 ||
358 VK == ELF::R_LARCH_TLS_IE64_PC_HI12 ||
359 VK == ELF::R_LARCH_TLS_DESC64_HI12 ||
360 VK == ELF::R_LARCH_TLS_DESC64_PC_HI12;
363 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
367 bool isUImm12()
const {
return isUImm<12>(); }
369 bool isUImm12ori()
const {
375 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
378 VK == ELF::R_LARCH_PCALA_LO12 || VK == ELF::R_LARCH_GOT_LO12 ||
379 VK == ELF::R_LARCH_GOT_PC_LO12 || VK == ELF::R_LARCH_TLS_LE_LO12 ||
380 VK == ELF::R_LARCH_TLS_IE_LO12 || VK == ELF::R_LARCH_TLS_IE_PC_LO12 ||
381 VK == ELF::R_LARCH_TLS_DESC_LO12;
384 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
388 bool isSImm13()
const {
return isSImm<13>(); }
389 bool isUImm14()
const {
return isUImm<14>(); }
390 bool isUImm15()
const {
return isUImm<15>(); }
392 bool isSImm14lsl2()
const {
return isSImm<14, 2>(); }
393 bool isSImm16()
const {
return isSImm<16>(); }
395 bool isSImm16lsl2()
const {
401 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
404 VK == ELF::R_LARCH_PCALA_LO12 || VK == ELF::R_LARCH_TLS_DESC_CALL;
407 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
411 bool isSImm20()
const {
return isSImm<20>(); }
413 bool isSImm20pcalau12i()
const {
419 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
422 VK == ELF::R_LARCH_GOT_PC_HI20 || VK == ELF::R_LARCH_TLS_IE_PC_HI20 ||
423 VK == ELF::R_LARCH_TLS_LD_PC_HI20 ||
424 VK == ELF::R_LARCH_TLS_GD_PC_HI20 ||
425 VK == ELF::R_LARCH_TLS_DESC_PC_HI20;
428 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
432 bool isSImm20lu12iw()
const {
438 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
441 VK == ELF::R_LARCH_GOT_HI20 || VK == ELF::R_LARCH_TLS_GD_HI20 ||
442 VK == ELF::R_LARCH_TLS_LD_HI20 || VK == ELF::R_LARCH_TLS_IE_HI20 ||
443 VK == ELF::R_LARCH_TLS_LE_HI20 || VK == ELF::R_LARCH_TLS_LE_HI20_R ||
444 VK == ELF::R_LARCH_TLS_DESC_HI20;
447 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
451 bool isSImm20lu32id()
const {
457 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
460 VK == ELF::R_LARCH_PCALA64_LO20 || VK == ELF::R_LARCH_GOT64_LO20 ||
461 VK == ELF::R_LARCH_GOT64_PC_LO20 || VK == ELF::R_LARCH_TLS_IE64_LO20 ||
462 VK == ELF::R_LARCH_TLS_IE64_PC_LO20 ||
463 VK == ELF::R_LARCH_TLS_LE64_LO20 ||
464 VK == ELF::R_LARCH_TLS_DESC64_PC_LO20 ||
465 VK == ELF::R_LARCH_TLS_DESC64_LO20;
469 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
473 bool isSImm20pcaddu12i()
const {
479 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
482 VK == ELF::R_LARCH_PCADD_HI20 || VK == ELF::R_LARCH_GOT_PCADD_HI20 ||
483 VK == ELF::R_LARCH_TLS_IE_PCADD_HI20 ||
484 VK == ELF::R_LARCH_TLS_LD_PCADD_HI20 ||
485 VK == ELF::R_LARCH_TLS_GD_PCADD_HI20 ||
486 VK == ELF::R_LARCH_TLS_DESC_PCADD_HI20;
490 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
494 bool isSImm20pcaddu18i()
const {
500 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
506 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
510 bool isSImm20pcaddi()
const {
516 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
518 VK == ELF::R_LARCH_PCREL20_S2 ||
519 VK == ELF::R_LARCH_TLS_LD_PCREL20_S2 ||
520 VK == ELF::R_LARCH_TLS_GD_PCREL20_S2 ||
521 VK == ELF::R_LARCH_TLS_DESC_PCREL20_S2;
524 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
528 bool isSImm21lsl2()
const {
534 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
538 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
542 bool isSImm26Operand()
const {
548 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
552 : LoongArchAsmParser::classifySymbolRef(
getImm(), VK) &&
556 bool isImm32()
const {
return isSImm<32>() || isUImm<32>(); }
557 bool isImm64()
const {
562 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm, VK);
567 SMLoc getStartLoc()
const override {
return StartLoc; }
569 SMLoc getEndLoc()
const override {
return EndLoc; }
571 MCRegister
getReg()
const override {
572 assert(Kind == KindTy::Register &&
"Invalid type access!");
576 const MCExpr *
getImm()
const {
577 assert(Kind == KindTy::Immediate &&
"Invalid type access!");
582 assert(Kind == KindTy::Token &&
"Invalid type access!");
586 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
595 case KindTy::Immediate:
598 case KindTy::Register:
607 static std::unique_ptr<LoongArchOperand> createToken(StringRef Str, SMLoc S) {
608 auto Op = std::make_unique<LoongArchOperand>(KindTy::Token);
615 static std::unique_ptr<LoongArchOperand> createReg(MCRegister
Reg, SMLoc S,
617 auto Op = std::make_unique<LoongArchOperand>(KindTy::Register);
618 Op->Reg.RegNum =
Reg;
624 static std::unique_ptr<LoongArchOperand> createImm(
const MCExpr *Val, SMLoc S,
626 auto Op = std::make_unique<LoongArchOperand>(KindTy::Immediate);
633 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
641 void addRegOperands(MCInst &Inst,
unsigned N)
const {
642 assert(
N == 1 &&
"Invalid number of operands!");
645 void addImmOperands(MCInst &Inst,
unsigned N)
const {
646 assert(
N == 1 &&
"Invalid number of operands!");
652#define GET_REGISTER_MATCHER
653#define GET_SUBTARGET_FEATURE_NAME
654#define GET_MATCHER_IMPLEMENTATION
655#define GET_MNEMONIC_SPELL_CHECKER
656#include "LoongArchGenAsmMatcher.inc"
665 assert(!(RegNo >= LoongArch::F0_64 && RegNo <= LoongArch::F31_64));
667 static_assert(LoongArch::F0 < LoongArch::F0_64,
668 "FPR matching must be updated");
669 if (RegNo == LoongArch::NoRegister)
672 return RegNo == LoongArch::NoRegister;
677 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
678 return Error(getLoc(),
"invalid register name");
680 if (!getLoongArchMCRegisterClass(LoongArch::GPRRegClassID).
contains(
Reg) &&
681 !getLoongArchMCRegisterClass(LoongArch::FPR32RegClassID).
contains(
Reg))
682 return Error(getLoc(),
"invalid register name");
687ParseStatus LoongArchAsmParser::tryParseRegister(MCRegister &
Reg,
690 const AsmToken &Tok = getParser().getTok();
706bool LoongArchAsmParser::classifySymbolRef(
const MCExpr *Expr,
711 Kind = RE->getSpecifier();
712 Expr = RE->getSubExpr();
727 StringRef
Name = getLexer().getTok().getIdentifier();
730 if (RegNo == LoongArch::NoRegister)
736 Operands.push_back(LoongArchOperand::createReg(RegNo, S,
E));
746 switch (getLexer().getKind()) {
758 if (getParser().parseExpression(Res,
E))
762 return parseOperandWithModifier(
Operands);
765 Operands.push_back(LoongArchOperand::createImm(Res, S,
E));
775 return Error(getLoc(),
"expected '%' for operand modifier");
780 return Error(getLoc(),
"expected valid identifier for operand modifier");
781 StringRef
Identifier = getParser().getTok().getIdentifier();
784 return Error(getLoc(),
"invalid relocation specifier");
788 return Error(getLoc(),
"expected '('");
791 const MCExpr *SubExpr;
792 if (getParser().parseParenExpression(SubExpr,
E))
796 Operands.push_back(LoongArchOperand::createImm(ModExpr, S,
E));
805 return parseOperandWithModifier(
Operands);
811 if (getParser().parseIdentifier(Identifier))
818 Operands.push_back(LoongArchOperand::createImm(Res, S,
E));
824 if (!parseRegister(
Operands).isSuccess())
831 SMLoc ImmStart = getLoc();
832 if (getParser().parseIntToken(ImmVal,
"expected optional integer offset"))
835 return Error(ImmStart,
"optional integer offset must be 0");
843 StringRef Mnemonic) {
847 MatchOperandParserImpl(
Operands, Mnemonic,
true);
853 if (parseRegister(
Operands).isSuccess() ||
858 return Error(getLoc(),
"unknown operand");
861bool LoongArchAsmParser::parseInstruction(ParseInstructionInfo &Info,
862 StringRef Name, SMLoc NameLoc,
865 Operands.push_back(LoongArchOperand::createToken(Name, NameLoc));
884 SMLoc Loc = getLexer().getLoc();
885 getParser().eatToEndOfStatement();
886 return Error(Loc,
"unexpected token");
889void LoongArchAsmParser::emitLAInstSeq(MCRegister DestReg, MCRegister TmpReg,
890 const MCExpr *Symbol,
891 SmallVectorImpl<Inst> &Insts,
892 SMLoc IDLoc, MCStreamer &Out,
896 for (LoongArchAsmParser::Inst &Inst : Insts) {
897 unsigned Opc = Inst.Opc;
899 const LoongArchMCExpr *
LE =
904 case LoongArch::PCADDU12I:
906 Out.emitLabel(PCALabel);
908 case LoongArch::PCALAU12I:
909 case LoongArch::LU12I_W:
910 Out.emitInstruction(MCInstBuilder(
Opc).addReg(DestReg).addExpr(LE),
914 case LoongArch::ADDI_W:
915 case LoongArch::LD_W:
916 case LoongArch::LD_D: {
919 MCInstBuilder(
Opc).addReg(DestReg).addReg(DestReg).addImm(0),
922 }
else if (VK == ELF::R_LARCH_TLS_DESC_LD) {
923 Out.emitInstruction(MCInstBuilder(
Opc)
924 .addReg(LoongArch::R1)
929 }
else if (VK == ELF::R_LARCH_PCADD_LO12 ||
930 VK == ELF::R_LARCH_GOT_PCADD_LO12 ||
931 VK == ELF::R_LARCH_TLS_IE_PCADD_LO12 ||
932 VK == ELF::R_LARCH_TLS_LD_PCADD_LO12 ||
933 VK == ELF::R_LARCH_TLS_GD_PCADD_LO12 ||
934 VK == ELF::R_LARCH_TLS_DESC_PCADD_LO12) {
936 MCInstBuilder(
Opc).addReg(DestReg).addReg(DestReg).addExpr(
938 VK, Ctx, RelaxHint)),
943 MCInstBuilder(
Opc).addReg(DestReg).addReg(DestReg).addExpr(LE),
947 case LoongArch::LU32I_D:
948 Out.emitInstruction(MCInstBuilder(
Opc)
949 .addReg(DestReg == TmpReg ? DestReg : TmpReg)
950 .addReg(DestReg == TmpReg ? DestReg : TmpReg)
954 case LoongArch::LU52I_D:
956 MCInstBuilder(
Opc).addReg(TmpReg).addReg(TmpReg).addExpr(LE),
959 case LoongArch::ADDI_D:
963 .addReg(DestReg == TmpReg ? TmpReg : LoongArch::R0)
967 case LoongArch::ADD_D:
968 case LoongArch::LDX_D:
970 MCInstBuilder(
Opc).addReg(DestReg).addReg(DestReg).addReg(TmpReg),
973 case LoongArch::JIRL:
974 Out.emitInstruction(MCInstBuilder(
Opc)
975 .addReg(LoongArch::R1)
976 .addReg(LoongArch::R1)
984void LoongArchAsmParser::emitLoadAddressAbs(MCInst &Inst, SMLoc IDLoc,
1003 LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_MARK_LA));
1005 LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_ABS_LO12));
1009 LoongArchAsmParser::Inst(LoongArch::LU32I_D, ELF::R_LARCH_ABS64_LO20));
1011 LoongArchAsmParser::Inst(LoongArch::LU52I_D, ELF::R_LARCH_ABS64_HI12));
1014 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out);
1017void LoongArchAsmParser::emitLoadAddressPcrel(MCInst &Inst, SMLoc IDLoc,
1032 unsigned PCAI = has32S() ? LoongArch::PCALAU12I : LoongArch::PCADDU12I;
1033 unsigned ADDI =
is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
1035 has32S() ? ELF::R_LARCH_PCALA_HI20 : ELF::R_LARCH_PCADD_HI20;
1037 has32S() ? ELF::R_LARCH_PCALA_LO12 : ELF::R_LARCH_PCADD_LO12;
1039 Insts.push_back(LoongArchAsmParser::Inst(PCAI, PCAIRel));
1040 Insts.push_back(LoongArchAsmParser::Inst(ADDI, ADDIRel));
1042 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out,
1046void LoongArchAsmParser::emitLoadAddressPcrelLarge(MCInst &Inst, SMLoc IDLoc,
1061 LoongArchAsmParser::Inst(LoongArch::PCALAU12I, ELF::R_LARCH_PCALA_HI20));
1063 LoongArchAsmParser::Inst(LoongArch::ADDI_D, ELF::R_LARCH_PCALA_LO12));
1065 LoongArchAsmParser::Inst(LoongArch::LU32I_D, ELF::R_LARCH_PCALA64_LO20));
1067 LoongArchAsmParser::Inst(LoongArch::LU52I_D, ELF::R_LARCH_PCALA64_HI12));
1068 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::ADD_D));
1070 emitLAInstSeq(DestReg, TmpReg, Symbol, Insts, IDLoc, Out);
1073void LoongArchAsmParser::emitLoadAddressGot(MCInst &Inst, SMLoc IDLoc,
1079 unsigned PCAI = has32S() ? LoongArch::PCALAU12I : LoongArch::PCADDU12I;
1080 unsigned LD =
is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
1082 has32S() ? ELF::R_LARCH_GOT_PC_HI20 : ELF::R_LARCH_GOT_PCADD_HI20;
1084 has32S() ? ELF::R_LARCH_GOT_PC_LO12 : ELF::R_LARCH_GOT_PCADD_LO12;
1086 if (getSTI().
hasFeature(LoongArch::LaGlobalWithAbs)) {
1100 LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_GOT_HI20));
1102 LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_GOT_LO12));
1105 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU32I_D,
1106 ELF::R_LARCH_GOT64_LO20));
1107 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU52I_D,
1108 ELF::R_LARCH_GOT64_HI12));
1110 Insts.push_back(LoongArchAsmParser::Inst(LD));
1111 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out);
1122 Insts.push_back(LoongArchAsmParser::Inst(PCAI, PCAIRel));
1123 Insts.push_back(LoongArchAsmParser::Inst(LD, LDRel));
1125 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out,
1129void LoongArchAsmParser::emitLoadAddressGotLarge(MCInst &Inst, SMLoc IDLoc,
1144 LoongArchAsmParser::Inst(LoongArch::PCALAU12I, ELF::R_LARCH_GOT_PC_HI20));
1146 LoongArchAsmParser::Inst(LoongArch::ADDI_D, ELF::R_LARCH_GOT_PC_LO12));
1148 LoongArchAsmParser::Inst(LoongArch::LU32I_D, ELF::R_LARCH_GOT64_PC_LO20));
1150 LoongArchAsmParser::Inst(LoongArch::LU52I_D, ELF::R_LARCH_GOT64_PC_HI12));
1151 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LDX_D));
1153 emitLAInstSeq(DestReg, TmpReg, Symbol, Insts, IDLoc, Out);
1156void LoongArchAsmParser::emitLoadAddressTLSLE(MCInst &Inst, SMLoc IDLoc,
1167 LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_TLS_LE_HI20));
1169 LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_TLS_LE_LO12));
1171 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out);
1174void LoongArchAsmParser::emitLoadAddressTLSIE(MCInst &Inst, SMLoc IDLoc,
1180 unsigned PCAI = has32S() ? LoongArch::PCALAU12I : LoongArch::PCADDU12I;
1181 unsigned LD =
is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
1183 has32S() ? ELF::R_LARCH_TLS_IE_PC_HI20 : ELF::R_LARCH_TLS_IE_PCADD_HI20;
1185 has32S() ? ELF::R_LARCH_TLS_IE_PC_LO12 : ELF::R_LARCH_TLS_IE_PCADD_LO12;
1187 if (getSTI().
hasFeature(LoongArch::LaGlobalWithAbs)) {
1201 LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_TLS_IE_HI20));
1203 LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_TLS_IE_LO12));
1206 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU32I_D,
1207 ELF::R_LARCH_TLS_IE64_LO20));
1208 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU52I_D,
1209 ELF::R_LARCH_TLS_IE64_HI12));
1211 Insts.push_back(LoongArchAsmParser::Inst(LD));
1212 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out);
1224 Insts.push_back(LoongArchAsmParser::Inst(PCAI, PCAIRel));
1225 Insts.push_back(LoongArchAsmParser::Inst(LD, LDRel));
1227 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out,
1231void LoongArchAsmParser::emitLoadAddressTLSIELarge(MCInst &Inst, SMLoc IDLoc,
1245 Insts.
push_back(LoongArchAsmParser::Inst(LoongArch::PCALAU12I,
1246 ELF::R_LARCH_TLS_IE_PC_HI20));
1248 LoongArchAsmParser::Inst(LoongArch::ADDI_D, ELF::R_LARCH_TLS_IE_PC_LO12));
1249 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU32I_D,
1250 ELF::R_LARCH_TLS_IE64_PC_LO20));
1251 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU52I_D,
1252 ELF::R_LARCH_TLS_IE64_PC_HI12));
1253 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LDX_D));
1255 emitLAInstSeq(DestReg, TmpReg, Symbol, Insts, IDLoc, Out);
1258void LoongArchAsmParser::emitLoadAddressTLSLD(MCInst &Inst, SMLoc IDLoc,
1264 unsigned PCAI = has32S() ? LoongArch::PCALAU12I : LoongArch::PCADDU12I;
1265 unsigned ADDI =
is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
1267 has32S() ? ELF::R_LARCH_TLS_LD_PC_HI20 : ELF::R_LARCH_TLS_LD_PCADD_HI20;
1269 has32S() ? ELF::R_LARCH_GOT_PC_LO12 : ELF::R_LARCH_TLS_LD_PCADD_LO12;
1271 if (getSTI().
hasFeature(LoongArch::LaGlobalWithAbs)) {
1283 LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_TLS_LD_HI20));
1285 LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_GOT_LO12));
1288 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU32I_D,
1289 ELF::R_LARCH_GOT64_LO20));
1290 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU52I_D,
1291 ELF::R_LARCH_GOT64_HI12));
1293 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out);
1305 Insts.push_back(LoongArchAsmParser::Inst(PCAI, PCAIRel));
1306 Insts.push_back(LoongArchAsmParser::Inst(ADDI, ADDIRel));
1308 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out,
1312void LoongArchAsmParser::emitLoadAddressTLSLDLarge(MCInst &Inst, SMLoc IDLoc,
1326 Insts.
push_back(LoongArchAsmParser::Inst(LoongArch::PCALAU12I,
1327 ELF::R_LARCH_TLS_LD_PC_HI20));
1329 LoongArchAsmParser::Inst(LoongArch::ADDI_D, ELF::R_LARCH_GOT_PC_LO12));
1331 LoongArchAsmParser::Inst(LoongArch::LU32I_D, ELF::R_LARCH_GOT64_PC_LO20));
1333 LoongArchAsmParser::Inst(LoongArch::LU52I_D, ELF::R_LARCH_GOT64_PC_HI12));
1334 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::ADD_D));
1336 emitLAInstSeq(DestReg, TmpReg, Symbol, Insts, IDLoc, Out);
1339void LoongArchAsmParser::emitLoadAddressTLSGD(MCInst &Inst, SMLoc IDLoc,
1345 unsigned PCAI = has32S() ? LoongArch::PCALAU12I : LoongArch::PCADDU12I;
1346 unsigned ADDI =
is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
1348 has32S() ? ELF::R_LARCH_TLS_GD_PC_HI20 : ELF::R_LARCH_TLS_GD_PCADD_HI20;
1350 has32S() ? ELF::R_LARCH_GOT_PC_LO12 : ELF::R_LARCH_TLS_GD_PCADD_LO12;
1352 if (getSTI().
hasFeature(LoongArch::LaGlobalWithAbs)) {
1364 LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_TLS_GD_HI20));
1366 LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_GOT_LO12));
1369 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU32I_D,
1370 ELF::R_LARCH_GOT64_LO20));
1371 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU52I_D,
1372 ELF::R_LARCH_GOT64_HI12));
1374 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out);
1386 Insts.push_back(LoongArchAsmParser::Inst(PCAI, PCAIRel));
1387 Insts.push_back(LoongArchAsmParser::Inst(ADDI, ADDIRel));
1389 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out,
1393void LoongArchAsmParser::emitLoadAddressTLSGDLarge(MCInst &Inst, SMLoc IDLoc,
1407 Insts.
push_back(LoongArchAsmParser::Inst(LoongArch::PCALAU12I,
1408 ELF::R_LARCH_TLS_GD_PC_HI20));
1410 LoongArchAsmParser::Inst(LoongArch::ADDI_D, ELF::R_LARCH_GOT_PC_LO12));
1412 LoongArchAsmParser::Inst(LoongArch::LU32I_D, ELF::R_LARCH_GOT64_PC_LO20));
1414 LoongArchAsmParser::Inst(LoongArch::LU52I_D, ELF::R_LARCH_GOT64_PC_HI12));
1415 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::ADD_D));
1417 emitLAInstSeq(DestReg, TmpReg, Symbol, Insts, IDLoc, Out);
1420void LoongArchAsmParser::emitLoadAddressTLSDesc(MCInst &Inst, SMLoc IDLoc,
1425 unsigned PCAI = has32S() ? LoongArch::PCALAU12I : LoongArch::PCADDU12I;
1426 unsigned ADDI =
is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
1427 unsigned LD =
is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
1428 unsigned PCAIRel = has32S() ? ELF::R_LARCH_TLS_DESC_PC_HI20
1429 : ELF::R_LARCH_TLS_DESC_PCADD_HI20;
1430 unsigned ADDIRel = has32S() ? ELF::R_LARCH_TLS_DESC_PC_LO12
1431 : ELF::R_LARCH_TLS_DESC_PCADD_LO12;
1434 if (getSTI().
hasFeature(LoongArch::LaGlobalWithAbs)) {
1449 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU12I_W,
1450 ELF::R_LARCH_TLS_DESC_HI20));
1452 LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_TLS_DESC_LO12));
1455 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU32I_D,
1456 ELF::R_LARCH_TLS_DESC64_LO20));
1457 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU52I_D,
1458 ELF::R_LARCH_TLS_DESC64_HI12));
1461 Insts.push_back(LoongArchAsmParser::Inst(LD, ELF::R_LARCH_TLS_DESC_LD));
1463 LoongArchAsmParser::Inst(LoongArch::JIRL, ELF::R_LARCH_TLS_DESC_CALL));
1465 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out);
1481 Insts.
push_back(LoongArchAsmParser::Inst(PCAI, PCAIRel));
1482 Insts.push_back(LoongArchAsmParser::Inst(ADDI, ADDIRel));
1483 Insts.push_back(LoongArchAsmParser::Inst(LD, ELF::R_LARCH_TLS_DESC_LD));
1485 LoongArchAsmParser::Inst(LoongArch::JIRL, ELF::R_LARCH_TLS_DESC_CALL));
1487 emitLAInstSeq(DestReg, DestReg, Symbol, Insts, IDLoc, Out,
1491void LoongArchAsmParser::emitLoadAddressTLSDescLarge(MCInst &Inst, SMLoc IDLoc,
1507 Insts.
push_back(LoongArchAsmParser::Inst(LoongArch::PCALAU12I,
1508 ELF::R_LARCH_TLS_DESC_PC_HI20));
1509 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::ADDI_D,
1510 ELF::R_LARCH_TLS_DESC_PC_LO12));
1511 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU32I_D,
1512 ELF::R_LARCH_TLS_DESC64_PC_LO20));
1513 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::LU52I_D,
1514 ELF::R_LARCH_TLS_DESC64_PC_HI12));
1515 Insts.push_back(LoongArchAsmParser::Inst(LoongArch::ADD_D));
1517 LoongArchAsmParser::Inst(LoongArch::LD_D, ELF::R_LARCH_TLS_DESC_LD));
1519 LoongArchAsmParser::Inst(LoongArch::JIRL, ELF::R_LARCH_TLS_DESC_CALL));
1521 emitLAInstSeq(DestReg, TmpReg, Symbol, Insts, IDLoc, Out);
1524void LoongArchAsmParser::emitLoadImm(MCInst &Inst, SMLoc IDLoc,
1528 MCRegister SrcReg = LoongArch::R0;
1530 if (Inst.
getOpcode() == LoongArch::PseudoLI_W)
1535 case LoongArch::LU12I_W:
1536 Out.emitInstruction(
1537 MCInstBuilder(Inst.Opc).addReg(DestReg).addImm(Inst.Imm), getSTI());
1539 case LoongArch::ADDI_W:
1540 case LoongArch::ORI:
1541 case LoongArch::LU32I_D:
1542 case LoongArch::LU52I_D:
1543 case LoongArch::SLLI_D:
1544 Out.emitInstruction(
1545 MCInstBuilder(Inst.Opc).addReg(DestReg).addReg(SrcReg).addImm(
1549 case LoongArch::BSTRINS_D:
1550 Out.emitInstruction(MCInstBuilder(Inst.Opc)
1554 .addImm(Inst.Imm >> 32)
1555 .addImm(Inst.Imm & 0xFF),
1565void LoongArchAsmParser::emitFuncCall(MCInst &Inst, SMLoc IDLoc,
1566 MCStreamer &Out,
bool IsTailCall,
1587 MCRegister ScratchReg =
1589 unsigned PCAI = IsCall36 ? LoongArch::PCADDU18I : LoongArch::PCADDU12I;
1590 unsigned Rel = IsCall36 ? ELF::R_LARCH_CALL36 : ELF::R_LARCH_CALL30;
1593 const LoongArchMCExpr *
LE =
1596 Out.emitInstruction(MCInstBuilder(PCAI).addReg(ScratchReg).addExpr(LE),
1598 Out.emitInstruction(
1599 MCInstBuilder(LoongArch::JIRL)
1600 .addReg(IsTailCall ? MCRegister(LoongArch::R0) : ScratchReg)
1606bool LoongArchAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
1613 case LoongArch::PseudoLA_ABS:
1614 case LoongArch::PseudoLA_ABS_LARGE:
1615 emitLoadAddressAbs(Inst, IDLoc, Out);
1617 case LoongArch::PseudoLA_PCREL:
1618 emitLoadAddressPcrel(Inst, IDLoc, Out);
1620 case LoongArch::PseudoLA_PCREL_LARGE:
1621 emitLoadAddressPcrelLarge(Inst, IDLoc, Out);
1623 case LoongArch::PseudoLA_GOT:
1624 emitLoadAddressGot(Inst, IDLoc, Out);
1626 case LoongArch::PseudoLA_GOT_LARGE:
1627 emitLoadAddressGotLarge(Inst, IDLoc, Out);
1629 case LoongArch::PseudoLA_TLS_LE:
1630 emitLoadAddressTLSLE(Inst, IDLoc, Out);
1632 case LoongArch::PseudoLA_TLS_IE:
1633 emitLoadAddressTLSIE(Inst, IDLoc, Out);
1635 case LoongArch::PseudoLA_TLS_IE_LARGE:
1636 emitLoadAddressTLSIELarge(Inst, IDLoc, Out);
1638 case LoongArch::PseudoLA_TLS_LD:
1639 emitLoadAddressTLSLD(Inst, IDLoc, Out);
1641 case LoongArch::PseudoLA_TLS_LD_LARGE:
1642 emitLoadAddressTLSLDLarge(Inst, IDLoc, Out);
1644 case LoongArch::PseudoLA_TLS_GD:
1645 emitLoadAddressTLSGD(Inst, IDLoc, Out);
1647 case LoongArch::PseudoLA_TLS_GD_LARGE:
1648 emitLoadAddressTLSGDLarge(Inst, IDLoc, Out);
1650 case LoongArch::PseudoLA_TLS_DESC:
1651 emitLoadAddressTLSDesc(Inst, IDLoc, Out);
1653 case LoongArch::PseudoLA_TLS_DESC_LARGE:
1654 emitLoadAddressTLSDescLarge(Inst, IDLoc, Out);
1656 case LoongArch::PseudoLI_W:
1657 case LoongArch::PseudoLI_D:
1658 emitLoadImm(Inst, IDLoc, Out);
1660 case LoongArch::PseudoCALL:
1661 emitFuncCall(Inst, IDLoc, Out,
false,
1664 case LoongArch::PseudoCALL30:
1665 emitFuncCall(Inst, IDLoc, Out,
false,
false);
1667 case LoongArch::PseudoCALL36:
1668 emitFuncCall(Inst, IDLoc, Out,
false,
true);
1670 case LoongArch::PseudoTAIL:
1671 emitFuncCall(Inst, IDLoc, Out,
true,
is64Bit());
1673 case LoongArch::PseudoTAIL30:
1674 emitFuncCall(Inst, IDLoc, Out,
true,
false);
1676 case LoongArch::PseudoTAIL36:
1677 emitFuncCall(Inst, IDLoc, Out,
true,
true);
1680 Out.emitInstruction(Inst, getSTI());
1684unsigned LoongArchAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
1686 const MCInstrDesc &MCID = MII.
get(
Opc);
1694 if ((Rd == Rk || Rd == Rj) && Rd != LoongArch::R0)
1695 return Match_RequiresAMORdDifferRkRj;
1698 case LoongArch::PseudoLA_TLS_DESC:
1699 case LoongArch::PseudoLA_TLS_DESC_LARGE: {
1701 if (Rd != LoongArch::R4)
1702 return Match_RequiresLAORdR4;
1705 case LoongArch::PseudoLA_PCREL_LARGE:
1706 case LoongArch::PseudoLA_GOT_LARGE:
1707 case LoongArch::PseudoLA_TLS_IE_LARGE:
1708 case LoongArch::PseudoLA_TLS_LD_LARGE:
1709 case LoongArch::PseudoLA_TLS_GD_LARGE: {
1713 return Match_RequiresLAORdDifferRj;
1716 case LoongArch::CSRXCHG:
1717 case LoongArch::GCSRXCHG: {
1719 if (Rj == LoongArch::R0 || Rj == LoongArch::R1)
1720 return Match_RequiresOpnd2NotR0R1;
1721 return Match_Success;
1723 case LoongArch::BSTRINS_W:
1724 case LoongArch::BSTRINS_D:
1725 case LoongArch::BSTRPICK_W:
1726 case LoongArch::BSTRPICK_D: {
1729 (
Opc == LoongArch::BSTRINS_W ||
Opc == LoongArch::BSTRINS_D)
1733 (
Opc == LoongArch::BSTRINS_W ||
Opc == LoongArch::BSTRINS_D)
1737 return Match_RequiresMsbNotLessThanLsb;
1738 return Match_Success;
1742 return Match_Success;
1746LoongArchAsmParser::validateTargetOperandClass(
const MCParsedAsmOperand &AsmOp,
1748 const LoongArchOperand &
Op =
static_cast<const LoongArchOperand &
>(AsmOp);
1750 return Match_InvalidOperand;
1752 MCRegister
Reg =
Op.getReg();
1753 if (Kind == MCK_GPRNoR0R1 && (
Reg == LoongArch::R0 ||
Reg == LoongArch::R1))
1754 return Match_RequiresOpnd2NotR0R1;
1756 return Match_InvalidOperand;
1759bool LoongArchAsmParser::generateImmOutOfRangeError(
1761 const Twine &
Msg =
"immediate must be an integer in the range") {
1762 SMLoc ErrorLoc = ((LoongArchOperand &)*
Operands[ErrorInfo]).getStartLoc();
1766bool LoongArchAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1770 bool MatchingInlineAsm) {
1772 FeatureBitset MissingFeatures;
1774 auto Result = MatchInstructionImpl(
Operands, Inst, ErrorInfo, MissingFeatures,
1780 return processInstruction(Inst, IDLoc,
Operands, Out);
1781 case Match_MissingFeature: {
1782 assert(MissingFeatures.
any() &&
"Unknown missing features!");
1783 bool FirstFeature =
true;
1784 std::string
Msg =
"instruction requires the following:";
1785 for (
unsigned Feature : MissingFeatures) {
1786 Msg += FirstFeature ?
" " :
", ";
1788 FirstFeature =
false;
1792 case Match_MnemonicFail: {
1793 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1794 std::string Suggestion = LoongArchMnemonicSpellCheck(
1796 return Error(IDLoc,
"unrecognized instruction mnemonic" + Suggestion);
1798 case Match_InvalidOperand: {
1799 SMLoc ErrorLoc = IDLoc;
1800 if (ErrorInfo != ~0ULL) {
1802 return Error(ErrorLoc,
"too few operands for instruction");
1804 ErrorLoc = ((LoongArchOperand &)*
Operands[ErrorInfo]).getStartLoc();
1805 if (ErrorLoc == SMLoc())
1808 return Error(ErrorLoc,
"invalid operand for instruction");
1815 if (Result > FIRST_TARGET_MATCH_RESULT_TY) {
1816 SMLoc ErrorLoc = IDLoc;
1817 if (ErrorInfo != ~0ULL && ErrorInfo >=
Operands.size())
1818 return Error(ErrorLoc,
"too few operands for instruction");
1824 case Match_RequiresMsbNotLessThanLsb: {
1825 SMLoc ErrorStart =
Operands[3]->getStartLoc();
1826 return Error(ErrorStart,
"msb is less than lsb",
1827 SMRange(ErrorStart,
Operands[4]->getEndLoc()));
1829 case Match_RequiresOpnd2NotR0R1:
1830 return Error(
Operands[2]->getStartLoc(),
"must not be $r0 or $r1");
1831 case Match_RequiresAMORdDifferRkRj:
1833 "$rd must be different from both $rk and $rj");
1834 case Match_RequiresLAORdDifferRj:
1835 return Error(
Operands[1]->getStartLoc(),
"$rd must be different from $rj");
1836 case Match_RequiresLAORdR4:
1837 return Error(
Operands[1]->getStartLoc(),
"$rd must be $r4");
1838 case Match_InvalidUImm1:
1839 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1841 case Match_InvalidUImm2:
1842 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1844 case Match_InvalidUImm2plus1:
1845 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1,
1847 case Match_InvalidUImm3:
1848 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1850 case Match_InvalidUImm4:
1851 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1853 case Match_InvalidUImm5:
1854 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1856 case Match_InvalidUImm6:
1857 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1859 case Match_InvalidUImm7:
1860 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1862 case Match_InvalidUImm8:
1863 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1865 case Match_InvalidUImm12:
1866 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1868 case Match_InvalidUImm12ori:
1869 return generateImmOutOfRangeError(
1872 "operand must be a symbol with modifier (e.g. %abs_lo12) or an "
1873 "integer in the range");
1874 case Match_InvalidUImm14:
1875 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1877 case Match_InvalidUImm15:
1878 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0,
1880 case Match_InvalidSImm5:
1881 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 4),
1883 case Match_InvalidSImm8:
1884 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 7),
1886 case Match_InvalidSImm8lsl1:
1887 return generateImmOutOfRangeError(
1888 Operands, ErrorInfo, -(1 << 8), (1 << 8) - 2,
1889 "immediate must be a multiple of 2 in the range");
1890 case Match_InvalidSImm8lsl2:
1891 return generateImmOutOfRangeError(
1892 Operands, ErrorInfo, -(1 << 9), (1 << 9) - 4,
1893 "immediate must be a multiple of 4 in the range");
1894 case Match_InvalidSImm10:
1895 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 9),
1897 case Match_InvalidSImm8lsl3:
1898 return generateImmOutOfRangeError(
1899 Operands, ErrorInfo, -(1 << 10), (1 << 10) - 8,
1900 "immediate must be a multiple of 8 in the range");
1901 case Match_InvalidSImm9lsl3:
1902 return generateImmOutOfRangeError(
1903 Operands, ErrorInfo, -(1 << 11), (1 << 11) - 8,
1904 "immediate must be a multiple of 8 in the range");
1905 case Match_InvalidSImm10lsl2:
1906 return generateImmOutOfRangeError(
1907 Operands, ErrorInfo, -(1 << 11), (1 << 11) - 4,
1908 "immediate must be a multiple of 4 in the range");
1909 case Match_InvalidSImm11lsl1:
1910 return generateImmOutOfRangeError(
1911 Operands, ErrorInfo, -(1 << 11), (1 << 11) - 2,
1912 "immediate must be a multiple of 2 in the range");
1913 case Match_InvalidSImm12:
1914 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 11),
1916 case Match_InvalidSImm12addlike:
1917 return generateImmOutOfRangeError(
1920 "operand must be a symbol with modifier (e.g. %pc_lo12) or an integer "
1922 case Match_InvalidSImm12lu52id:
1923 return generateImmOutOfRangeError(
1926 "operand must be a symbol with modifier (e.g. %pc64_hi12) or an "
1927 "integer in the range");
1928 case Match_InvalidSImm13:
1929 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 12),
1931 case Match_InvalidSImm14lsl2:
1932 return generateImmOutOfRangeError(
1933 Operands, ErrorInfo, -(1 << 15), (1 << 15) - 4,
1934 "immediate must be a multiple of 4 in the range");
1935 case Match_InvalidSImm16:
1936 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 15),
1938 case Match_InvalidSImm16lsl2:
1939 return generateImmOutOfRangeError(
1940 Operands, ErrorInfo, -(1 << 17), (1 << 17) - 4,
1941 "operand must be a symbol with modifier (e.g. %b16) or an integer "
1943 case Match_InvalidSImm20:
1944 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 19),
1946 case Match_InvalidSImm20lu12iw:
1947 return generateImmOutOfRangeError(
1950 "operand must be a symbol with modifier (e.g. %abs_hi20) or an integer "
1952 case Match_InvalidSImm20lu32id:
1953 return generateImmOutOfRangeError(
1956 "operand must be a symbol with modifier (e.g. %abs64_lo20) or an "
1957 "integer in the range");
1958 case Match_InvalidSImm20pcalau12i:
1959 return generateImmOutOfRangeError(
1962 "operand must be a symbol with modifier (e.g. %pc_hi20) or an integer "
1964 case Match_InvalidSImm20pcaddu12i:
1965 return generateImmOutOfRangeError(
1968 "operand must be a symbol with modifier (e.g. %call30 or %pcadd_hi20) "
1969 "or an integer in the range");
1970 case Match_InvalidSImm20pcaddu18i:
1971 return generateImmOutOfRangeError(
1974 "operand must be a symbol with modifier (e.g. %call36) or an integer "
1976 case Match_InvalidSImm20pcaddi:
1977 return generateImmOutOfRangeError(
1980 "operand must be a symbol with modifier (e.g. %pcrel_20) or an integer "
1982 case Match_InvalidSImm21lsl2:
1983 return generateImmOutOfRangeError(
1984 Operands, ErrorInfo, -(1 << 22), (1 << 22) - 4,
1985 "operand must be a symbol with modifier (e.g. %b21) or an integer "
1987 case Match_InvalidSImm26Operand:
1988 return generateImmOutOfRangeError(
1989 Operands, ErrorInfo, -(1 << 27), (1 << 27) - 4,
1990 "operand must be a bare symbol name or an immediate must be a multiple "
1991 "of 4 in the range");
1992 case Match_InvalidImm32: {
1993 SMLoc ErrorLoc = ((LoongArchOperand &)*
Operands[ErrorInfo]).getStartLoc();
1994 return Error(ErrorLoc,
"operand must be a 32 bit immediate");
1996 case Match_InvalidImm64: {
1997 SMLoc ErrorLoc = ((LoongArchOperand &)*
Operands[ErrorInfo]).getStartLoc();
1998 return Error(ErrorLoc,
"operand must be a 64 bit immediate");
2000 case Match_InvalidBareSymbol: {
2001 SMLoc ErrorLoc = ((LoongArchOperand &)*
Operands[ErrorInfo]).getStartLoc();
2002 return Error(ErrorLoc,
"operand must be a bare symbol name");
2004 case Match_InvalidTPRelAddSymbol: {
2005 SMLoc ErrorLoc = ((LoongArchOperand &)*
Operands[ErrorInfo]).getStartLoc();
2006 return Error(ErrorLoc,
"operand must be a symbol with %le_add_r modifier");
2012bool LoongArchAsmParser::parseDirectiveOption() {
2013 MCAsmParser &Parser = getParser();
2015 AsmToken Tok = Parser.
getTok();
2023 if (Option ==
"push") {
2027 getTargetStreamer().emitDirectiveOptionPush();
2032 if (Option ==
"pop") {
2037 getTargetStreamer().emitDirectiveOptionPop();
2038 if (popFeatureBits())
2039 return Error(StartLoc,
".option pop with no .option push");
2044 if (Option ==
"relax") {
2048 getTargetStreamer().emitDirectiveOptionRelax();
2049 setFeatureBits(LoongArch::FeatureRelax,
"relax");
2053 if (Option ==
"norelax") {
2057 getTargetStreamer().emitDirectiveOptionNoRelax();
2058 clearFeatureBits(LoongArch::FeatureRelax,
"relax");
2064 "unknown option, expected 'push', 'pop', 'relax' or 'norelax'");
2069bool LoongArchAsmParser::parseDirectiveDtpRelWord() {
2070 const MCExpr *
Value;
2071 if (getParser().parseExpression(
Value))
2073 getTargetStreamer().emitDTPRel32Value(
Value);
2077bool LoongArchAsmParser::parseDirectiveDtpRelDWord() {
2078 const MCExpr *
Value;
2079 if (getParser().parseExpression(
Value))
2081 getTargetStreamer().emitDTPRel64Value(
Value);
2085ParseStatus LoongArchAsmParser::parseDirective(AsmToken DirectiveID) {
2086 if (DirectiveID.
getString() ==
".option")
2087 return parseDirectiveOption();
2089 if (DirectiveID.
getString() ==
".dtprelword")
2090 return parseDirectiveDtpRelWord();
2092 if (DirectiveID.
getString() ==
".dtpreldword")
2093 return parseDirectiveDtpRelDWord();
static MCRegister MatchRegisterName(StringRef Name)
static const char * getSubtargetFeatureName(uint64_t Val)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static MCRegister MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
bpf unwind BPF Unwind Lower
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool matchRegisterNameHelper(const MCSubtargetInfo &STI, MCRegister &Reg, StringRef Name)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
#define LLVM_EXTERNAL_VISIBILITY
static bool matchRegisterNameHelper(MCRegister &RegNo, StringRef Name)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLoongArchAsmParser()
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
Promote Memory to Register
static bool isGPR(MCRegister Reg, const MCRegisterInfo &MRI)
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
static bool isUImm2(const MachineOperand &MO)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)
static bool is64Bit(const char *name)
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Base class for user error types.
static const char * getRegisterName(MCRegister Reg)
static const LoongArchMCExpr * create(const MCExpr *Expr, uint16_t S, MCContext &Ctx, bool Hint=false)
void printExpr(raw_ostream &, const MCExpr &) const
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
LLVM_ABI MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
const MCOperand & getOperand(unsigned i) const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
Wrapper class representing physical registers and target specific virtual registers.
Streaming machine code generation interface.
MCTargetStreamer * getTargetStreamer()
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Target specific streamer interface.
MCStreamer & getStreamer()
uint32_t getSpecifier() const
Ternary parse status returned by various parse* methods.
static constexpr StatusTy Failure
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isAMCAS(uint64_t TSFlags)
static bool isSubjectToAMORdConstraint(uint64_t TSFlags)
InstSeq generateInstSeq(int64_t Val)
uint16_t parseSpecifier(StringRef name)
@ CE
Windows NT (Windows on ARM)
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheLoongArch64Target()
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Target & getTheLoongArch32Target()
DWARFExpression::Operation Op
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...