40 switch (
E->getKind()) {
43 return Res < 0 ? -1 : Res;
50 if (Name ==
"lt")
return 0;
51 if (Name ==
"gt")
return 1;
52 if (Name ==
"eq")
return 2;
53 if (Name ==
"so")
return 3;
54 if (Name ==
"un")
return 3;
56 if (Name ==
"cr0")
return 0;
57 if (Name ==
"cr1")
return 1;
58 if (Name ==
"cr2")
return 2;
59 if (Name ==
"cr3")
return 3;
60 if (Name ==
"cr4")
return 4;
61 if (Name ==
"cr5")
return 5;
62 if (Name ==
"cr6")
return 6;
63 if (Name ==
"cr7")
return 7;
77 if (LHSVal < 0 || RHSVal < 0)
86 return Res < 0 ? -1 : Res;
106 void Warning(SMLoc L,
const Twine &Msg) { getParser().
Warning(L, Msg); }
108 bool isPPC64()
const {
return IsPPC64; }
110 MCRegister matchRegisterName(int64_t &IntVal);
112 bool parseRegister(MCRegister &
Reg, SMLoc &StartLoc, SMLoc &EndLoc)
override;
113 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
114 SMLoc &EndLoc)
override;
116 const MCExpr *extractSpecifier(
const MCExpr *
E,
118 bool parseExpression(
const MCExpr *&EVal);
122 bool parseDirectiveWord(
unsigned Size, AsmToken
ID);
123 bool parseDirectiveTC(
unsigned Size, AsmToken
ID);
124 bool parseDirectiveMachine(SMLoc L);
125 bool parseDirectiveAbiVersion(SMLoc L);
126 bool parseDirectiveLocalEntry(SMLoc L);
127 bool parseGNUAttribute(SMLoc L);
129 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
132 bool MatchingInlineAsm)
override;
139#define GET_ASSEMBLER_HEADER
140#include "PPCGenAsmMatcher.inc"
149 IsPPC64(STI.getTargetTriple().isPPC64()) {
151 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
154 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
157 bool ParseDirective(AsmToken DirectiveID)
override;
159 unsigned validateTargetOperandClass(MCParsedAsmOperand &
Op,
160 unsigned Kind)
override;
162 const MCExpr *applySpecifier(
const MCExpr *
E, uint32_t,
163 MCContext &Ctx)
override;
177 SMLoc StartLoc, EndLoc;
200 const MCSymbolRefExpr *Sym;
207 struct TLSRegOp TLSReg;
210 PPCOperand(KindTy K, MCContext &Ctx) : Kind(
K), Ctx(Ctx) {}
213 PPCOperand(
const PPCOperand &o) : MCParsedAsmOperand(), Ctx(
o.Ctx) {
215 StartLoc =
o.StartLoc;
223 case ContextImmediate:
237 void operator delete(
void *
p) { ::operator
delete(
p); }
240 SMLoc getStartLoc()
const override {
return StartLoc; }
243 SMLoc getEndLoc()
const override {
return EndLoc; }
247 SMRange getLocRange()
const {
return SMRange(StartLoc, EndLoc); }
250 bool isPPC64()
const {
return IsPPC64; }
253 bool isMemOpBase()
const {
return Kind == Immediate &&
Imm.IsMemOpBase; }
256 assert(Kind == Immediate &&
"Invalid access!");
259 int64_t getImmS16Context()
const {
260 assert((Kind == Immediate || Kind == ContextImmediate) &&
262 if (Kind == Immediate)
264 return static_cast<int16_t
>(
Imm.Val);
266 int64_t getImmU16Context()
const {
267 assert((Kind == Immediate || Kind == ContextImmediate) &&
272 const MCExpr *
getExpr()
const {
273 assert(Kind == Expression &&
"Invalid access!");
277 int64_t getExprCRVal()
const {
278 assert(Kind == Expression &&
"Invalid access!");
282 const MCExpr *getTLSReg()
const {
283 assert(Kind == TLSRegister &&
"Invalid access!");
290 assert(isRegNumber() &&
"Invalid access!");
291 return (
unsigned)
Imm.Val;
294 unsigned getFpReg()
const {
295 assert(isEvenRegNumber() &&
"Invalid access!");
296 return (
unsigned)(
Imm.Val >> 1);
299 unsigned getVSReg()
const {
300 assert(isVSRegNumber() &&
"Invalid access!");
301 return (
unsigned)
Imm.Val;
304 unsigned getACCReg()
const {
305 assert(isACCRegNumber() &&
"Invalid access!");
306 return (
unsigned)
Imm.Val;
309 unsigned getDMRROWReg()
const {
310 assert(isDMRROWRegNumber() &&
"Invalid access!");
311 return (
unsigned)
Imm.Val;
314 unsigned getDMRROWpReg()
const {
315 assert(isDMRROWpRegNumber() &&
"Invalid access!");
316 return (
unsigned)
Imm.Val;
319 unsigned getDMRReg()
const {
320 assert(isDMRRegNumber() &&
"Invalid access!");
321 return (
unsigned)
Imm.Val;
324 unsigned getDMRpReg()
const {
325 assert(isDMRpRegNumber() &&
"Invalid access!");
326 return (
unsigned)
Imm.Val;
329 unsigned getVSRpEvenReg()
const {
330 assert(isVSRpEvenRegNumber() &&
"Invalid access!");
331 return (
unsigned)
Imm.Val >> 1;
334 unsigned getG8pReg()
const {
335 assert(isEvenRegNumber() &&
"Invalid access!");
336 return (
unsigned)
Imm.Val;
339 unsigned getCCReg()
const {
340 assert(isCCRegNumber() &&
"Invalid access!");
341 return (
unsigned) (Kind == Immediate ?
Imm.Val : Expr.CRVal);
344 unsigned getCRBit()
const {
345 assert(isCRBitNumber() &&
"Invalid access!");
346 return (
unsigned) (Kind == Immediate ?
Imm.Val : Expr.CRVal);
349 unsigned getCRBitMask()
const {
350 assert(isCRBitMask() &&
"Invalid access!");
354 bool isToken()
const override {
return Kind == Token; }
355 bool isImm()
const override {
356 return Kind == Immediate || Kind == Expression;
359 template <u
int64_t N>
bool isUImm()
const {
362 template <u
int64_t N>
bool isSImm()
const {
365 bool isU6ImmX2()
const {
return isUImm<6>() && (
getImm() & 1) == 0; }
366 bool isU7ImmX4()
const {
return isUImm<7>() && (
getImm() & 3) == 0; }
367 bool isU8ImmX8()
const {
return isUImm<8>() && (
getImm() & 7) == 0; }
369 bool isU16Imm()
const {
return isExtImm<16>(
false, 1); }
370 bool isS16Imm()
const {
return isExtImm<16>(
true, 1); }
371 bool isS16ImmX4()
const {
return isExtImm<16>(
true, 4); }
372 bool isS16ImmX16()
const {
return isExtImm<16>(
true, 16); }
373 bool isS17Imm()
const {
return isExtImm<17>(
true, 1); }
374 bool isS32Imm()
const {
376 return Kind == Expression || isSImm<32>();
378 bool isS34Imm()
const {
381 return Kind == Expression || isSImm<34>();
383 bool isS34ImmX16()
const {
384 return Kind == Expression || (isSImm<34>() && (
getImm() & 15) == 0);
387 bool isHashImmX8()
const {
391 return (Kind == Immediate &&
getImm() <= -8 &&
getImm() >= -512 &&
395 bool isTLSReg()
const {
return Kind == TLSRegister; }
396 bool isDirectBr()
const {
397 if (Kind == Expression)
399 if (Kind != Immediate)
413 bool isCondBr()
const {
return Kind == Expression ||
416 bool isImmZero()
const {
return Kind == Immediate &&
getImm() == 0; }
417 bool isRegNumber()
const {
return Kind == Immediate &&
isUInt<5>(
getImm()); }
418 bool isACCRegNumber()
const {
421 bool isDMRROWRegNumber()
const {
424 bool isDMRROWpRegNumber()
const {
427 bool isDMRRegNumber()
const {
430 bool isDMRpRegNumber()
const {
433 bool isVSRpEvenRegNumber()
const {
436 bool isVSRegNumber()
const {
439 bool isCCRegNumber()
const {
return (Kind == Expression
443 bool isCRBitNumber()
const {
return (Kind == Expression
448 bool isEvenRegNumber()
const {
return isRegNumber() && (
getImm() & 1) == 0; }
450 bool isCRBitMask()
const {
454 bool isATBitsAsHint()
const {
return false; }
455 bool isMem()
const override {
return false; }
456 bool isReg()
const override {
return false; }
458 void addRegOperands(MCInst &Inst,
unsigned N)
const {
462 void addRegGPRCOperands(MCInst &Inst,
unsigned N)
const {
463 assert(
N == 1 &&
"Invalid number of operands!");
467 void addRegGPRC_NOR0Operands(MCInst &Inst,
unsigned N)
const {
468 assert(
N == 1 &&
"Invalid number of operands!");
472 void addRegG8RCOperands(MCInst &Inst,
unsigned N)
const {
473 assert(
N == 1 &&
"Invalid number of operands!");
477 void addRegG8RC_NOX0Operands(MCInst &Inst,
unsigned N)
const {
478 assert(
N == 1 &&
"Invalid number of operands!");
482 void addRegG8pRCOperands(MCInst &Inst,
unsigned N)
const {
483 assert(
N == 1 &&
"Invalid number of operands!");
487 void addRegGxRCOperands(MCInst &Inst,
unsigned N)
const {
489 addRegG8RCOperands(Inst,
N);
491 addRegGPRCOperands(Inst,
N);
494 void addRegGxRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
496 addRegG8RC_NOX0Operands(Inst,
N);
498 addRegGPRC_NOR0Operands(Inst,
N);
501 void addRegF4RCOperands(MCInst &Inst,
unsigned N)
const {
502 assert(
N == 1 &&
"Invalid number of operands!");
506 void addRegF8RCOperands(MCInst &Inst,
unsigned N)
const {
507 assert(
N == 1 &&
"Invalid number of operands!");
511 void addRegFpRCOperands(MCInst &Inst,
unsigned N)
const {
512 assert(
N == 1 &&
"Invalid number of operands!");
516 void addRegVFRCOperands(MCInst &Inst,
unsigned N)
const {
517 assert(
N == 1 &&
"Invalid number of operands!");
521 void addRegVRRCOperands(MCInst &Inst,
unsigned N)
const {
522 assert(
N == 1 &&
"Invalid number of operands!");
526 void addRegVSRCOperands(MCInst &Inst,
unsigned N)
const {
527 assert(
N == 1 &&
"Invalid number of operands!");
531 void addRegVSFRCOperands(MCInst &Inst,
unsigned N)
const {
532 assert(
N == 1 &&
"Invalid number of operands!");
536 void addRegVSSRCOperands(MCInst &Inst,
unsigned N)
const {
537 assert(
N == 1 &&
"Invalid number of operands!");
541 void addRegSPE4RCOperands(MCInst &Inst,
unsigned N)
const {
542 assert(
N == 1 &&
"Invalid number of operands!");
546 void addRegSPERCOperands(MCInst &Inst,
unsigned N)
const {
547 assert(
N == 1 &&
"Invalid number of operands!");
551 void addRegACCRCOperands(MCInst &Inst,
unsigned N)
const {
552 assert(
N == 1 &&
"Invalid number of operands!");
556 void addRegDMRROWRCOperands(MCInst &Inst,
unsigned N)
const {
557 assert(
N == 1 &&
"Invalid number of operands!");
561 void addRegDMRROWpRCOperands(MCInst &Inst,
unsigned N)
const {
562 assert(
N == 1 &&
"Invalid number of operands!");
566 void addRegDMRRCOperands(MCInst &Inst,
unsigned N)
const {
567 assert(
N == 1 &&
"Invalid number of operands!");
571 void addRegDMRpRCOperands(MCInst &Inst,
unsigned N)
const {
572 assert(
N == 1 &&
"Invalid number of operands!");
576 void addRegWACCRCOperands(MCInst &Inst,
unsigned N)
const {
577 assert(
N == 1 &&
"Invalid number of operands!");
581 void addRegWACC_HIRCOperands(MCInst &Inst,
unsigned N)
const {
582 assert(
N == 1 &&
"Invalid number of operands!");
586 void addRegVSRpRCOperands(MCInst &Inst,
unsigned N)
const {
587 assert(
N == 1 &&
"Invalid number of operands!");
591 void addRegVSRpEvenRCOperands(MCInst &Inst,
unsigned N)
const {
592 assert(
N == 1 &&
"Invalid number of operands!");
596 void addRegCRBITRCOperands(MCInst &Inst,
unsigned N)
const {
597 assert(
N == 1 &&
"Invalid number of operands!");
601 void addRegCRRCOperands(MCInst &Inst,
unsigned N)
const {
602 assert(
N == 1 &&
"Invalid number of operands!");
606 void addCRBitMaskOperands(MCInst &Inst,
unsigned N)
const {
607 assert(
N == 1 &&
"Invalid number of operands!");
611 void addImmOperands(MCInst &Inst,
unsigned N)
const {
612 assert(
N == 1 &&
"Invalid number of operands!");
613 if (Kind == Immediate)
619 void addS16ImmOperands(MCInst &Inst,
unsigned N)
const {
620 assert(
N == 1 &&
"Invalid number of operands!");
625 case ContextImmediate:
634 void addU16ImmOperands(MCInst &Inst,
unsigned N)
const {
635 assert(
N == 1 &&
"Invalid number of operands!");
640 case ContextImmediate:
649 void addNegImmOperands(MCInst &Inst,
unsigned N)
const {
650 assert(
N == 1 &&
"Invalid number of operands!");
652 if (Kind == Immediate) {
662 void addBranchTargetOperands(MCInst &Inst,
unsigned N)
const {
663 assert(
N == 1 &&
"Invalid number of operands!");
664 if (Kind == Immediate)
670 void addTLSRegOperands(MCInst &Inst,
unsigned N)
const {
671 assert(
N == 1 &&
"Invalid number of operands!");
676 assert(Kind == Token &&
"Invalid access!");
677 return StringRef(Tok.Data, Tok.Length);
680 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override;
682 static std::unique_ptr<PPCOperand>
683 CreateToken(StringRef Str, SMLoc S,
bool IsPPC64, MCContext &Ctx) {
684 auto Op = std::make_unique<PPCOperand>(Token, Ctx);
685 Op->Tok.Data = Str.data();
686 Op->Tok.Length = Str.size();
689 Op->IsPPC64 = IsPPC64;
693 static std::unique_ptr<PPCOperand>
694 CreateTokenWithStringCopy(StringRef Str, SMLoc S,
bool IsPPC64,
701 void *Mem = ::operator
new(
sizeof(PPCOperand) + Str.size());
702 std::unique_ptr<PPCOperand>
Op(
new (Mem) PPCOperand(Token, Ctx));
703 Op->Tok.Data =
reinterpret_cast<const char *
>(
Op.get() + 1);
704 Op->Tok.Length = Str.size();
705 std::memcpy(
const_cast<char *
>(
Op->Tok.Data), Str.data(), Str.size());
708 Op->IsPPC64 = IsPPC64;
712 static std::unique_ptr<PPCOperand> CreateImm(int64_t Val, SMLoc S, SMLoc
E,
713 bool IsPPC64, MCContext &Ctx,
714 bool IsMemOpBase =
false) {
715 auto Op = std::make_unique<PPCOperand>(Immediate, Ctx);
717 Op->Imm.IsMemOpBase = IsMemOpBase;
720 Op->IsPPC64 = IsPPC64;
724 static std::unique_ptr<PPCOperand> CreateExpr(
const MCExpr *Val, SMLoc S,
725 SMLoc
E,
bool IsPPC64,
727 auto Op = std::make_unique<PPCOperand>(Expression, Ctx);
732 Op->IsPPC64 = IsPPC64;
736 static std::unique_ptr<PPCOperand> CreateTLSReg(
const MCSymbolRefExpr *Sym,
740 auto Op = std::make_unique<PPCOperand>(TLSRegister, Ctx);
741 Op->TLSReg.Sym = Sym;
744 Op->IsPPC64 = IsPPC64;
748 static std::unique_ptr<PPCOperand>
749 CreateContextImm(int64_t Val, SMLoc S, SMLoc
E,
bool IsPPC64,
751 auto Op = std::make_unique<PPCOperand>(ContextImmediate, Ctx);
755 Op->IsPPC64 = IsPPC64;
759 static std::unique_ptr<PPCOperand>
760 CreateFromMCExpr(
const MCExpr *Val, SMLoc S, SMLoc
E,
bool IsPPC64,
763 return CreateImm(
CE->getValue(), S,
E, IsPPC64, Ctx);
768 return CreateTLSReg(SRE, S,
E, IsPPC64, Ctx);
773 return CreateContextImm(Res, S,
E, IsPPC64, Ctx);
776 return CreateExpr(Val, S,
E, IsPPC64, Ctx);
780 template <
unsigned W
idth>
781 bool isExtImm(
bool Signed,
unsigned Multiple)
const {
788 case ContextImmediate:
791 (getImmS16Context() & (Multiple - 1)) == 0;
794 (getImmU16Context() & (Multiple - 1)) == 0;
807 case ContextImmediate:
838 BinExpr->getLHS(), Ctx);
846void PPCAsmParser::processInstruction(MCInst &Inst,
855 TmpInst.
setOpcode((Opcode == PPC::DCBTx || Opcode == PPC::DCBTT) ?
856 PPC::DCBT : PPC::DCBTST);
858 (Opcode == PPC::DCBTx || Opcode == PPC::DCBTSTx) ? 0 : 16));
875 case PPC::DCBTSTDS: {
890 if (Opcode == PPC::DCBFL)
892 else if (Opcode == PPC::DCBFLP)
894 else if (Opcode == PPC::DCBFPS)
896 else if (Opcode == PPC::DCBSTPS)
919 TmpInst.
setOpcode(Opcode == PPC::PLA ? PPC::PADDI : PPC::PADDI8);
929 TmpInst.
setOpcode(Opcode == PPC::PLApc ? PPC::PADDIpc : PPC::PADDI8pc);
972 case PPC::SUBIC_rec: {
982 case PPC::EXTLWI_rec: {
986 TmpInst.
setOpcode(Opcode == PPC::EXTLWI ? PPC::RLWINM : PPC::RLWINM_rec);
996 case PPC::EXTRWI_rec: {
1000 TmpInst.
setOpcode(Opcode == PPC::EXTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1010 case PPC::INSLWI_rec: {
1014 TmpInst.
setOpcode(Opcode == PPC::INSLWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1025 case PPC::INSRWI_rec: {
1029 TmpInst.
setOpcode(Opcode == PPC::INSRWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1040 case PPC::ROTRWI_rec: {
1043 TmpInst.
setOpcode(Opcode == PPC::ROTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1053 case PPC::SLWI_rec: {
1056 TmpInst.
setOpcode(Opcode == PPC::SLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1066 case PPC::SRWI_rec: {
1069 TmpInst.
setOpcode(Opcode == PPC::SRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1079 case PPC::CLRRWI_rec: {
1082 TmpInst.
setOpcode(Opcode == PPC::CLRRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1092 case PPC::CLRLSLWI_rec: {
1096 TmpInst.
setOpcode(Opcode == PPC::CLRLSLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1106 case PPC::EXTLDI_rec: {
1110 TmpInst.
setOpcode(Opcode == PPC::EXTLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1119 case PPC::EXTRDI_rec: {
1123 TmpInst.
setOpcode(Opcode == PPC::EXTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1132 case PPC::INSRDI_rec: {
1136 TmpInst.
setOpcode(Opcode == PPC::INSRDI ? PPC::RLDIMI : PPC::RLDIMI_rec);
1146 case PPC::ROTRDI_rec: {
1149 TmpInst.
setOpcode(Opcode == PPC::ROTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1158 case PPC::SLDI_rec: {
1161 TmpInst.
setOpcode(Opcode == PPC::SLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1169 case PPC::SUBPCIS: {
1179 case PPC::SRDI_rec: {
1182 TmpInst.
setOpcode(Opcode == PPC::SRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1191 case PPC::CLRRDI_rec: {
1194 TmpInst.
setOpcode(Opcode == PPC::CLRRDI ? PPC::RLDICR : PPC::RLDICR_rec);
1203 case PPC::CLRLSLDI_rec: {
1207 TmpInst.
setOpcode(Opcode == PPC::CLRLSLDI ? PPC::RLDIC : PPC::RLDIC_rec);
1216 case PPC::RLWINMbm_rec: {
1223 TmpInst.
setOpcode(Opcode == PPC::RLWINMbm ? PPC::RLWINM : PPC::RLWINM_rec);
1233 case PPC::RLWIMIbm_rec: {
1240 TmpInst.
setOpcode(Opcode == PPC::RLWIMIbm ? PPC::RLWIMI : PPC::RLWIMI_rec);
1251 case PPC::RLWNMbm_rec: {
1258 TmpInst.
setOpcode(Opcode == PPC::RLWNMbm ? PPC::RLWNM : PPC::RLWNM_rec);
1268 if (getSTI().hasFeature(PPC::FeatureMFTB)) {
1278 unsigned VariantID = 0);
1284 for (
size_t idx = 0; idx < Operands.
size(); ++idx) {
1285 const PPCOperand &
Op =
static_cast<const PPCOperand &
>(*Operands[idx]);
1286 if (
Op.isMemOpBase() != (idx == 3 && isMemriOp))
1292bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1294 MCStreamer &Out, uint64_t &ErrorInfo,
1295 bool MatchingInlineAsm) {
1297 const PPCInstrInfo *
TII =
static_cast<const PPCInstrInfo *
>(&MII);
1299 switch (MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
1302 return Error(IDLoc,
"invalid operand for instruction");
1304 processInstruction(Inst, Operands);
1308 case Match_MissingFeature:
1309 return Error(IDLoc,
"instruction use requires an option to be enabled");
1310 case Match_MnemonicFail: {
1311 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1313 ((PPCOperand &)*Operands[0]).
getToken(), FBS);
1314 return Error(IDLoc,
"invalid instruction" + Suggestion,
1315 ((PPCOperand &)*Operands[0]).getLocRange());
1317 case Match_InvalidOperand: {
1318 SMLoc ErrorLoc = IDLoc;
1319 if (ErrorInfo != ~0ULL) {
1320 if (ErrorInfo >= Operands.size())
1321 return Error(IDLoc,
"too few operands for instruction");
1323 ErrorLoc = ((PPCOperand &)*Operands[ErrorInfo]).getStartLoc();
1324 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1327 return Error(ErrorLoc,
"invalid operand for instruction");
1334#define GET_REGISTER_MATCHER
1335#include "PPCGenAsmMatcher.inc"
1337MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
1346 std::string NameBuf = getParser().getTok().getString().lower();
1352 Name.substr(Name.find_first_of(
"1234567890")).getAsInteger(10, IntVal);
1357 RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
1359 }
else if (Name ==
"ctr") {
1360 RegNo = isPPC64() ? PPC::CTR8 : PPC::CTR;
1362 }
else if (Name ==
"vrsave")
1364 else if (Name.starts_with(
"r"))
1365 RegNo = isPPC64() ? XRegs[IntVal] : RRegs[IntVal];
1371bool PPCAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1373 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
1374 return TokError(
"invalid register name");
1378ParseStatus PPCAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1380 const AsmToken &Tok = getParser().getTok();
1384 if (!(
Reg = matchRegisterName(IntVal)))
1392const MCExpr *PPCAsmParser::extractSpecifier(
const MCExpr *
E,
1394 MCContext &
Context = getParser().getContext();
1395 switch (
E->getKind()) {
1401 Spec =
TE->getSpecifier();
1402 (void)extractSpecifier(
TE->getSubExpr(), Spec);
1424 Error(
E->getLoc(),
"cannot contain more than one relocation specifier");
1432 const MCExpr *
Sub = extractSpecifier(UE->
getSubExpr(), Spec);
1440 const MCExpr *
LHS = extractSpecifier(BE->
getLHS(), Spec);
1441 const MCExpr *
RHS = extractSpecifier(BE->
getRHS(), Spec);
1455bool PPCAsmParser::parseExpression(
const MCExpr *&EVal) {
1458 if (getParser().parseExpression(EVal))
1462 const MCExpr *
E = extractSpecifier(EVal, Spec);
1472 MCAsmParser &Parser = getParser();
1478 switch (getLexer().getKind()) {
1483 if (!matchRegisterName(IntVal))
1484 return Error(S,
"invalid register name");
1487 PPCOperand::CreateImm(IntVal, S,
E, isPPC64(),
getContext()));
1499 if (!parseExpression(EVal))
1504 return Error(S,
"unknown operand");
1509 PPCOperand::CreateFromMCExpr(EVal, S,
E, isPPC64(),
getContext()));
1512 const char TlsGetAddr[] =
"__tls_get_addr";
1513 bool TlsCall =
false;
1514 const MCExpr *TlsCallAddend =
nullptr;
1516 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1520 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1521 TlsCallAddend =
Bin->getRHS();
1526 const MCExpr *TLSSym;
1528 if (parseExpression(TLSSym))
1529 return Error(S2,
"invalid TLS call expression");
1535 AsmToken Tok = getTok();
1542 const MCExpr *Addend =
nullptr;
1544 if (parsePrimaryExpr(Addend, EndLoc))
1550 TlsCallAddend = Addend;
1555 Operands.
back() = PPCOperand::CreateFromMCExpr(
1560 PPCOperand::CreateFromMCExpr(TLSSym, S,
E, isPPC64(),
getContext()));
1568 switch (getLexer().getKind()) {
1570 if (!matchRegisterName(IntVal))
1571 return Error(S,
"invalid register name");
1575 if (getParser().parseAbsoluteExpression(IntVal) || IntVal < 0 ||
1577 return Error(S,
"invalid register number");
1581 return Error(S,
"invalid memory operand");
1587 Operands.
push_back(PPCOperand::CreateImm(
1595bool PPCAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
1600 std::string NewOpcode;
1602 NewOpcode = std::string(Name);
1607 NewOpcode = std::string(Name);
1613 size_t Dot =
Name.find(
'.');
1614 StringRef Mnemonic =
Name.slice(0, Dot);
1615 if (!NewOpcode.empty())
1616 Operands.
push_back(PPCOperand::CreateTokenWithStringCopy(
1617 Mnemonic, NameLoc, isPPC64(),
getContext()));
1620 PPCOperand::CreateToken(Mnemonic, NameLoc, isPPC64(),
getContext()));
1623 StringRef DotStr =
Name.substr(Dot);
1624 if (!NewOpcode.empty())
1625 Operands.
push_back(PPCOperand::CreateTokenWithStringCopy(
1629 PPCOperand::CreateToken(DotStr, DotLoc, isPPC64(),
getContext()));
1637 if (parseOperand(Operands))
1653 if (getSTI().hasFeature(PPC::FeatureBookE) &&
1654 Operands.
size() == 4 &&
1655 (Name ==
"dcbt" || Name ==
"dcbtst")) {
1661 if (Name ==
"lqarx" || Name ==
"ldarx" || Name ==
"lwarx" ||
1662 Name ==
"lharx" || Name ==
"lbarx") {
1663 if (Operands.
size() != 5)
1665 PPCOperand &EHOp = (PPCOperand &)*Operands[4];
1666 if (EHOp.isUImm<1>() && EHOp.getImm() == 0)
1674bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
1676 if (IDVal ==
".word")
1677 parseDirectiveWord(2, DirectiveID);
1678 else if (IDVal ==
".llong")
1679 parseDirectiveWord(8, DirectiveID);
1680 else if (IDVal ==
".tc")
1681 parseDirectiveTC(isPPC64() ? 8 : 4, DirectiveID);
1682 else if (IDVal ==
".machine")
1683 parseDirectiveMachine(DirectiveID.
getLoc());
1684 else if (IDVal ==
".abiversion")
1685 parseDirectiveAbiVersion(DirectiveID.
getLoc());
1686 else if (IDVal ==
".localentry")
1687 parseDirectiveLocalEntry(DirectiveID.
getLoc());
1689 parseGNUAttribute(DirectiveID.
getLoc());
1696bool PPCAsmParser::parseDirectiveWord(
unsigned Size, AsmToken
ID) {
1697 auto parseOp = [&]() ->
bool {
1698 const MCExpr *
Value;
1699 SMLoc ExprLoc = getParser().getTok().getLoc();
1700 if (getParser().parseExpression(
Value))
1704 uint64_t IntValue = MCE->getValue();
1706 return Error(ExprLoc,
"literal value out of range for '" +
1707 ID.getIdentifier() +
"' directive");
1708 getStreamer().emitIntValue(IntValue,
Size);
1710 getStreamer().emitValue(
Value,
Size, ExprLoc);
1714 if (parseMany(parseOp))
1715 return addErrorSuffix(
" in '" +
ID.getIdentifier() +
"' directive");
1720bool PPCAsmParser::parseDirectiveTC(
unsigned Size, AsmToken
ID) {
1721 MCAsmParser &Parser = getParser();
1727 return addErrorSuffix(
" in '.tc' directive");
1730 getParser().getStreamer().emitValueToAlignment(
Align(
Size));
1733 return parseDirectiveWord(
Size,
ID);
1738bool PPCAsmParser::parseDirectiveMachine(SMLoc L) {
1739 MCAsmParser &Parser = getParser();
1742 return Error(L,
"unexpected token in '.machine' directive");
1753 return addErrorSuffix(
" in '.machine' directive");
1755 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1756 getParser().getStreamer().getTargetStreamer());
1757 if (TStreamer !=
nullptr)
1764bool PPCAsmParser::parseDirectiveAbiVersion(SMLoc L) {
1766 if (check(getParser().parseAbsoluteExpression(AbiVersion), L,
1767 "expected constant expression") ||
1769 return addErrorSuffix(
" in '.abiversion' directive");
1771 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1772 getParser().getStreamer().getTargetStreamer());
1773 if (TStreamer !=
nullptr)
1780bool PPCAsmParser::parseDirectiveLocalEntry(SMLoc L) {
1782 if (getParser().parseIdentifier(Name))
1783 return Error(L,
"expected identifier in '.localentry' directive");
1785 auto *Sym =
static_cast<MCSymbolELF *
>(
getContext().getOrCreateSymbol(Name));
1789 check(getParser().parseExpression(Expr), L,
"expected expression") ||
1791 return addErrorSuffix(
" in '.localentry' directive");
1793 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1794 getParser().getStreamer().getTargetStreamer());
1795 if (TStreamer !=
nullptr)
1801bool PPCAsmParser::parseGNUAttribute(SMLoc L) {
1803 int64_t IntegerValue;
1804 if (!getParser().parseGNUAttribute(L,
Tag, IntegerValue))
1807 getParser().getStreamer().emitGNUAttribute(
Tag, IntegerValue);
1821#define GET_MATCHER_IMPLEMENTATION
1822#define GET_MNEMONIC_SPELL_CHECKER
1823#include "PPCGenAsmMatcher.inc"
1834 case MCK_0: ImmVal = 0;
break;
1835 case MCK_1: ImmVal = 1;
break;
1836 case MCK_2: ImmVal = 2;
break;
1837 case MCK_3: ImmVal = 3;
break;
1838 case MCK_4: ImmVal = 4;
break;
1839 case MCK_5: ImmVal = 5;
break;
1840 case MCK_6: ImmVal = 6;
break;
1841 case MCK_7: ImmVal = 7;
break;
1842 default:
return Match_InvalidOperand;
1845 PPCOperand &
Op =
static_cast<PPCOperand &
>(AsmOp);
1846 if (
Op.isUImm<3>() &&
Op.getImm() == ImmVal)
1847 return Match_Success;
1849 return Match_InvalidOperand;
1852const MCExpr *PPCAsmParser::applySpecifier(
const MCExpr *
E, uint32_t Spec,
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool getRegNum(StringRef Str, unsigned &Num)
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static AMDGPUMCExpr::Specifier getSpecifier(unsigned MOFlags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
const HexagonInstrInfo * TII
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
static bool validateMemOp(const OperandVector &Operands, bool isMemriOp)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCAsmParser()
Force static initialization.
static DEFINE_PPC_REGCLASSES int64_t EvaluateCRExpr(const MCExpr *E)
static void addNegOperand(MCInst &Inst, MCOperand &Op, MCContext &Ctx)
static std::string PPCMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
#define DEFINE_PPC_REGCLASSES
LLVM_ABI SMLoc getLoc() const
bool isNot(TokenKind K) 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.
Container class for subtarget features.
This class is intended to be used as a base class for asm properties and features specific to the tar...
void printExpr(raw_ostream &, const MCExpr &) const
bool Warning(SMLoc L, const Twine &Msg)
Generic assembler parser interface, for use by target specific assembly parsers.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
Interface to description of machine instruction set.
Instances of this class represent operands of the MCInst class.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
Wrapper class representing physical registers. Should be passed by value.
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
StringRef getName() const
getName - Get the symbol name.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Unary assembler expressions.
Opcode getOpcode() const
Get the kind of this unary expression.
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getSubExpr() const
Get the child of this unary expression.
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
virtual void emitAbiVersion(int AbiVersion)
virtual void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset)
virtual void emitMachine(StringRef CPU)
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
MCExpr const & getExpr(MCExpr const &Expr)
bool evaluateAsConstant(const MCSpecifierExpr &Expr, int64_t &Res)
@ CE
Windows NT (Windows on ARM)
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Target & getThePPC64LETarget()
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.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Target & getThePPC32Target()
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
constexpr bool has_single_bit(T Value) noexcept
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.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Ref
The access may reference the value stored in memory.
Target & getThePPC64Target()
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
Target & getThePPC32LETarget()
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
static uint16_t getSpecifier(const MCSymbolRefExpr *SRE)
static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME)
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...