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;
104 void Warning(SMLoc L,
const Twine &Msg) { getParser().
Warning(L, Msg); }
106 bool isPPC64()
const {
return IsPPC64; }
108 MCRegister matchRegisterName(int64_t &IntVal);
110 bool parseRegister(MCRegister &
Reg, SMLoc &StartLoc, SMLoc &EndLoc)
override;
111 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
112 SMLoc &EndLoc)
override;
114 const MCExpr *extractSpecifier(
const MCExpr *
E,
116 bool parseExpression(
const MCExpr *&EVal);
120 bool parseDirectiveWord(
unsigned Size, AsmToken
ID);
121 bool parseDirectiveTC(
unsigned Size, AsmToken
ID);
122 bool parseDirectiveMachine(SMLoc L);
123 bool parseDirectiveAbiVersion(SMLoc L);
124 bool parseDirectiveLocalEntry(SMLoc L);
125 bool parseGNUAttribute(SMLoc L);
127 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
130 bool MatchingInlineAsm)
override;
137#define GET_ASSEMBLER_HEADER
138#include "PPCGenAsmMatcher.inc"
147 IsPPC64(STI.getTargetTriple().isPPC64()) {
149 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
152 bool parseInstruction(ParseInstructionInfo &
Info, StringRef Name,
155 bool ParseDirective(AsmToken DirectiveID)
override;
157 unsigned validateTargetOperandClass(MCParsedAsmOperand &
Op,
158 unsigned Kind)
override;
160 const MCExpr *applySpecifier(
const MCExpr *
E, uint32_t,
161 MCContext &Ctx)
override;
175 SMLoc StartLoc, EndLoc;
194 const MCSymbolRefExpr *Sym;
201 struct TLSRegOp TLSReg;
204 PPCOperand(KindTy K) : Kind(
K) {}
207 PPCOperand(
const PPCOperand &o) : MCParsedAsmOperand() {
209 StartLoc =
o.StartLoc;
217 case ContextImmediate:
231 void operator delete(
void *
p) { ::operator
delete(
p); }
234 SMLoc getStartLoc()
const override {
return StartLoc; }
237 SMLoc getEndLoc()
const override {
return EndLoc; }
241 SMRange getLocRange()
const {
return SMRange(StartLoc, EndLoc); }
244 bool isPPC64()
const {
return IsPPC64; }
247 bool isMemOpBase()
const {
return Kind == Immediate &&
Imm.IsMemOpBase; }
250 assert(Kind == Immediate &&
"Invalid access!");
253 int64_t getImmS16Context()
const {
254 assert((Kind == Immediate || Kind == ContextImmediate) &&
256 if (Kind == Immediate)
258 return static_cast<int16_t
>(
Imm.Val);
260 int64_t getImmU16Context()
const {
261 assert((Kind == Immediate || Kind == ContextImmediate) &&
266 const MCExpr *
getExpr()
const {
267 assert(Kind == Expression &&
"Invalid access!");
271 int64_t getExprCRVal()
const {
272 assert(Kind == Expression &&
"Invalid access!");
276 const MCExpr *getTLSReg()
const {
277 assert(Kind == TLSRegister &&
"Invalid access!");
284 assert(isRegNumber() &&
"Invalid access!");
285 return (
unsigned)
Imm.Val;
288 unsigned getFpReg()
const {
289 assert(isEvenRegNumber() &&
"Invalid access!");
290 return (
unsigned)(
Imm.Val >> 1);
293 unsigned getVSReg()
const {
294 assert(isVSRegNumber() &&
"Invalid access!");
295 return (
unsigned)
Imm.Val;
298 unsigned getACCReg()
const {
299 assert(isACCRegNumber() &&
"Invalid access!");
300 return (
unsigned)
Imm.Val;
303 unsigned getDMRROWReg()
const {
304 assert(isDMRROWRegNumber() &&
"Invalid access!");
305 return (
unsigned)
Imm.Val;
308 unsigned getDMRROWpReg()
const {
309 assert(isDMRROWpRegNumber() &&
"Invalid access!");
310 return (
unsigned)
Imm.Val;
313 unsigned getDMRReg()
const {
314 assert(isDMRRegNumber() &&
"Invalid access!");
315 return (
unsigned)
Imm.Val;
318 unsigned getDMRpReg()
const {
319 assert(isDMRpRegNumber() &&
"Invalid access!");
320 return (
unsigned)
Imm.Val;
323 unsigned getVSRpEvenReg()
const {
324 assert(isVSRpEvenRegNumber() &&
"Invalid access!");
325 return (
unsigned)
Imm.Val >> 1;
328 unsigned getG8pReg()
const {
329 assert(isEvenRegNumber() &&
"Invalid access!");
330 return (
unsigned)
Imm.Val;
333 unsigned getCCReg()
const {
334 assert(isCCRegNumber() &&
"Invalid access!");
335 return (
unsigned) (Kind == Immediate ?
Imm.Val : Expr.CRVal);
338 unsigned getCRBit()
const {
339 assert(isCRBitNumber() &&
"Invalid access!");
340 return (
unsigned) (Kind == Immediate ?
Imm.Val : Expr.CRVal);
343 unsigned getCRBitMask()
const {
344 assert(isCRBitMask() &&
"Invalid access!");
348 bool isToken()
const override {
return Kind == Token; }
349 bool isImm()
const override {
350 return Kind == Immediate || Kind == Expression;
353 template <u
int64_t N>
bool isUImm()
const {
356 template <u
int64_t N>
bool isSImm()
const {
359 bool isU6ImmX2()
const {
return isUImm<6>() && (
getImm() & 1) == 0; }
360 bool isU7ImmX4()
const {
return isUImm<7>() && (
getImm() & 3) == 0; }
361 bool isU8ImmX8()
const {
return isUImm<8>() && (
getImm() & 7) == 0; }
363 bool isU16Imm()
const {
return isExtImm<16>(
false, 1); }
364 bool isS16Imm()
const {
return isExtImm<16>(
true, 1); }
365 bool isS16ImmX4()
const {
return isExtImm<16>(
true, 4); }
366 bool isS16ImmX16()
const {
return isExtImm<16>(
true, 16); }
367 bool isS17Imm()
const {
return isExtImm<17>(
true, 1); }
368 bool isS32Imm()
const {
370 return Kind == Expression || isSImm<32>();
372 bool isS34Imm()
const {
375 return Kind == Expression || isSImm<34>();
377 bool isS34ImmX16()
const {
378 return Kind == Expression || (isSImm<34>() && (
getImm() & 15) == 0);
381 bool isHashImmX8()
const {
385 return (Kind == Immediate &&
getImm() <= -8 &&
getImm() >= -512 &&
389 bool isTLSReg()
const {
return Kind == TLSRegister; }
390 bool isDirectBr()
const {
391 if (Kind == Expression)
393 if (Kind != Immediate)
407 bool isCondBr()
const {
return Kind == Expression ||
410 bool isImmZero()
const {
return Kind == Immediate &&
getImm() == 0; }
411 bool isRegNumber()
const {
return Kind == Immediate &&
isUInt<5>(
getImm()); }
412 bool isACCRegNumber()
const {
415 bool isDMRROWRegNumber()
const {
418 bool isDMRROWpRegNumber()
const {
421 bool isDMRRegNumber()
const {
424 bool isDMRpRegNumber()
const {
427 bool isVSRpEvenRegNumber()
const {
430 bool isVSRegNumber()
const {
433 bool isCCRegNumber()
const {
return (Kind == Expression
437 bool isCRBitNumber()
const {
return (Kind == Expression
442 bool isEvenRegNumber()
const {
return isRegNumber() && (
getImm() & 1) == 0; }
444 bool isCRBitMask()
const {
448 bool isATBitsAsHint()
const {
return false; }
449 bool isMem()
const override {
return false; }
450 bool isReg()
const override {
return false; }
452 void addRegOperands(MCInst &Inst,
unsigned N)
const {
456 void addRegGPRCOperands(MCInst &Inst,
unsigned N)
const {
457 assert(
N == 1 &&
"Invalid number of operands!");
461 void addRegGPRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
462 assert(
N == 1 &&
"Invalid number of operands!");
466 void addRegG8RCOperands(MCInst &Inst,
unsigned N)
const {
467 assert(
N == 1 &&
"Invalid number of operands!");
471 void addRegG8RCNoX0Operands(MCInst &Inst,
unsigned N)
const {
472 assert(
N == 1 &&
"Invalid number of operands!");
476 void addRegG8pRCOperands(MCInst &Inst,
unsigned N)
const {
477 assert(
N == 1 &&
"Invalid number of operands!");
481 void addRegGxRCOperands(MCInst &Inst,
unsigned N)
const {
483 addRegG8RCOperands(Inst,
N);
485 addRegGPRCOperands(Inst,
N);
488 void addRegGxRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
490 addRegG8RCNoX0Operands(Inst,
N);
492 addRegGPRCNoR0Operands(Inst,
N);
495 void addRegF4RCOperands(MCInst &Inst,
unsigned N)
const {
496 assert(
N == 1 &&
"Invalid number of operands!");
500 void addRegF8RCOperands(MCInst &Inst,
unsigned N)
const {
501 assert(
N == 1 &&
"Invalid number of operands!");
505 void addRegFpRCOperands(MCInst &Inst,
unsigned N)
const {
506 assert(
N == 1 &&
"Invalid number of operands!");
510 void addRegVFRCOperands(MCInst &Inst,
unsigned N)
const {
511 assert(
N == 1 &&
"Invalid number of operands!");
515 void addRegVRRCOperands(MCInst &Inst,
unsigned N)
const {
516 assert(
N == 1 &&
"Invalid number of operands!");
520 void addRegVSRCOperands(MCInst &Inst,
unsigned N)
const {
521 assert(
N == 1 &&
"Invalid number of operands!");
525 void addRegVSFRCOperands(MCInst &Inst,
unsigned N)
const {
526 assert(
N == 1 &&
"Invalid number of operands!");
530 void addRegVSSRCOperands(MCInst &Inst,
unsigned N)
const {
531 assert(
N == 1 &&
"Invalid number of operands!");
535 void addRegSPE4RCOperands(MCInst &Inst,
unsigned N)
const {
536 assert(
N == 1 &&
"Invalid number of operands!");
540 void addRegSPERCOperands(MCInst &Inst,
unsigned N)
const {
541 assert(
N == 1 &&
"Invalid number of operands!");
545 void addRegACCRCOperands(MCInst &Inst,
unsigned N)
const {
546 assert(
N == 1 &&
"Invalid number of operands!");
550 void addRegDMRROWRCOperands(MCInst &Inst,
unsigned N)
const {
551 assert(
N == 1 &&
"Invalid number of operands!");
555 void addRegDMRROWpRCOperands(MCInst &Inst,
unsigned N)
const {
556 assert(
N == 1 &&
"Invalid number of operands!");
560 void addRegDMRRCOperands(MCInst &Inst,
unsigned N)
const {
561 assert(
N == 1 &&
"Invalid number of operands!");
565 void addRegDMRpRCOperands(MCInst &Inst,
unsigned N)
const {
566 assert(
N == 1 &&
"Invalid number of operands!");
570 void addRegWACCRCOperands(MCInst &Inst,
unsigned N)
const {
571 assert(
N == 1 &&
"Invalid number of operands!");
575 void addRegWACC_HIRCOperands(MCInst &Inst,
unsigned N)
const {
576 assert(
N == 1 &&
"Invalid number of operands!");
580 void addRegVSRpRCOperands(MCInst &Inst,
unsigned N)
const {
581 assert(
N == 1 &&
"Invalid number of operands!");
585 void addRegVSRpEvenRCOperands(MCInst &Inst,
unsigned N)
const {
586 assert(
N == 1 &&
"Invalid number of operands!");
590 void addRegCRBITRCOperands(MCInst &Inst,
unsigned N)
const {
591 assert(
N == 1 &&
"Invalid number of operands!");
595 void addRegCRRCOperands(MCInst &Inst,
unsigned N)
const {
596 assert(
N == 1 &&
"Invalid number of operands!");
600 void addCRBitMaskOperands(MCInst &Inst,
unsigned N)
const {
601 assert(
N == 1 &&
"Invalid number of operands!");
605 void addImmOperands(MCInst &Inst,
unsigned N)
const {
606 assert(
N == 1 &&
"Invalid number of operands!");
607 if (Kind == Immediate)
613 void addS16ImmOperands(MCInst &Inst,
unsigned N)
const {
614 assert(
N == 1 &&
"Invalid number of operands!");
619 case ContextImmediate:
628 void addU16ImmOperands(MCInst &Inst,
unsigned N)
const {
629 assert(
N == 1 &&
"Invalid number of operands!");
634 case ContextImmediate:
643 void addBranchTargetOperands(MCInst &Inst,
unsigned N)
const {
644 assert(
N == 1 &&
"Invalid number of operands!");
645 if (Kind == Immediate)
651 void addTLSRegOperands(MCInst &Inst,
unsigned N)
const {
652 assert(
N == 1 &&
"Invalid number of operands!");
657 assert(Kind == Token &&
"Invalid access!");
658 return StringRef(Tok.Data, Tok.Length);
661 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override;
663 static std::unique_ptr<PPCOperand> CreateToken(StringRef Str, SMLoc S,
665 auto Op = std::make_unique<PPCOperand>(Token);
666 Op->Tok.Data = Str.data();
667 Op->Tok.Length = Str.size();
670 Op->IsPPC64 = IsPPC64;
674 static std::unique_ptr<PPCOperand>
675 CreateTokenWithStringCopy(StringRef Str, SMLoc S,
bool IsPPC64) {
681 void *Mem = ::operator
new(
sizeof(PPCOperand) + Str.size());
682 std::unique_ptr<PPCOperand>
Op(
new (Mem) PPCOperand(Token));
683 Op->Tok.Data =
reinterpret_cast<const char *
>(
Op.get() + 1);
684 Op->Tok.Length = Str.size();
685 std::memcpy(
const_cast<char *
>(
Op->Tok.Data), Str.data(), Str.size());
688 Op->IsPPC64 = IsPPC64;
692 static std::unique_ptr<PPCOperand> CreateImm(int64_t Val, SMLoc S, SMLoc
E,
694 bool IsMemOpBase =
false) {
695 auto Op = std::make_unique<PPCOperand>(Immediate);
697 Op->Imm.IsMemOpBase = IsMemOpBase;
700 Op->IsPPC64 = IsPPC64;
704 static std::unique_ptr<PPCOperand> CreateExpr(
const MCExpr *Val, SMLoc S,
705 SMLoc
E,
bool IsPPC64) {
706 auto Op = std::make_unique<PPCOperand>(Expression);
711 Op->IsPPC64 = IsPPC64;
715 static std::unique_ptr<PPCOperand>
716 CreateTLSReg(
const MCSymbolRefExpr *Sym, SMLoc S, SMLoc
E,
bool IsPPC64) {
717 auto Op = std::make_unique<PPCOperand>(TLSRegister);
718 Op->TLSReg.Sym = Sym;
721 Op->IsPPC64 = IsPPC64;
725 static std::unique_ptr<PPCOperand>
726 CreateContextImm(int64_t Val, SMLoc S, SMLoc
E,
bool IsPPC64) {
727 auto Op = std::make_unique<PPCOperand>(ContextImmediate);
731 Op->IsPPC64 = IsPPC64;
735 static std::unique_ptr<PPCOperand>
736 CreateFromMCExpr(
const MCExpr *Val, SMLoc S, SMLoc
E,
bool IsPPC64) {
738 return CreateImm(
CE->getValue(), S,
E, IsPPC64);
743 return CreateTLSReg(SRE, S,
E, IsPPC64);
748 return CreateContextImm(Res, S,
E, IsPPC64);
751 return CreateExpr(Val, S,
E, IsPPC64);
755 template <
unsigned W
idth>
756 bool isExtImm(
bool Signed,
unsigned Multiple)
const {
763 case ContextImmediate:
766 (getImmS16Context() & (Multiple - 1)) == 0;
769 (getImmU16Context() & (Multiple - 1)) == 0;
782 case ContextImmediate:
809 BinExpr->getLHS(), Ctx);
817void PPCAsmParser::processInstruction(MCInst &Inst,
826 TmpInst.
setOpcode((Opcode == PPC::DCBTx || Opcode == PPC::DCBTT) ?
827 PPC::DCBT : PPC::DCBTST);
829 (Opcode == PPC::DCBTx || Opcode == PPC::DCBTSTx) ? 0 : 16));
846 case PPC::DCBTSTDS: {
861 if (Opcode == PPC::DCBFL)
863 else if (Opcode == PPC::DCBFLP)
865 else if (Opcode == PPC::DCBFPS)
867 else if (Opcode == PPC::DCBSTPS)
890 TmpInst.
setOpcode(Opcode == PPC::PLA ? PPC::PADDI : PPC::PADDI8);
900 TmpInst.
setOpcode(Opcode == PPC::PLApc ? PPC::PADDIpc : PPC::PADDI8pc);
943 case PPC::SUBIC_rec: {
953 case PPC::EXTLWI_rec: {
957 TmpInst.
setOpcode(Opcode == PPC::EXTLWI ? PPC::RLWINM : PPC::RLWINM_rec);
967 case PPC::EXTRWI_rec: {
971 TmpInst.
setOpcode(Opcode == PPC::EXTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
981 case PPC::INSLWI_rec: {
985 TmpInst.
setOpcode(Opcode == PPC::INSLWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
996 case PPC::INSRWI_rec: {
1000 TmpInst.
setOpcode(Opcode == PPC::INSRWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1011 case PPC::ROTRWI_rec: {
1014 TmpInst.
setOpcode(Opcode == PPC::ROTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1024 case PPC::SLWI_rec: {
1027 TmpInst.
setOpcode(Opcode == PPC::SLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1037 case PPC::SRWI_rec: {
1040 TmpInst.
setOpcode(Opcode == PPC::SRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1050 case PPC::CLRRWI_rec: {
1053 TmpInst.
setOpcode(Opcode == PPC::CLRRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1063 case PPC::CLRLSLWI_rec: {
1067 TmpInst.
setOpcode(Opcode == PPC::CLRLSLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1077 case PPC::EXTLDI_rec: {
1081 TmpInst.
setOpcode(Opcode == PPC::EXTLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1090 case PPC::EXTRDI_rec: {
1094 TmpInst.
setOpcode(Opcode == PPC::EXTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1103 case PPC::INSRDI_rec: {
1107 TmpInst.
setOpcode(Opcode == PPC::INSRDI ? PPC::RLDIMI : PPC::RLDIMI_rec);
1117 case PPC::ROTRDI_rec: {
1120 TmpInst.
setOpcode(Opcode == PPC::ROTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1129 case PPC::SLDI_rec: {
1132 TmpInst.
setOpcode(Opcode == PPC::SLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1140 case PPC::SUBPCIS: {
1150 case PPC::SRDI_rec: {
1153 TmpInst.
setOpcode(Opcode == PPC::SRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1162 case PPC::CLRRDI_rec: {
1165 TmpInst.
setOpcode(Opcode == PPC::CLRRDI ? PPC::RLDICR : PPC::RLDICR_rec);
1174 case PPC::CLRLSLDI_rec: {
1178 TmpInst.
setOpcode(Opcode == PPC::CLRLSLDI ? PPC::RLDIC : PPC::RLDIC_rec);
1187 case PPC::RLWINMbm_rec: {
1194 TmpInst.
setOpcode(Opcode == PPC::RLWINMbm ? PPC::RLWINM : PPC::RLWINM_rec);
1204 case PPC::RLWIMIbm_rec: {
1211 TmpInst.
setOpcode(Opcode == PPC::RLWIMIbm ? PPC::RLWIMI : PPC::RLWIMI_rec);
1222 case PPC::RLWNMbm_rec: {
1229 TmpInst.
setOpcode(Opcode == PPC::RLWNMbm ? PPC::RLWNM : PPC::RLWNM_rec);
1239 if (getSTI().hasFeature(PPC::FeatureMFTB)) {
1249 unsigned VariantID = 0);
1255 for (
size_t idx = 0; idx < Operands.
size(); ++idx) {
1256 const PPCOperand &
Op =
static_cast<const PPCOperand &
>(*Operands[idx]);
1257 if (
Op.isMemOpBase() != (idx == 3 && isMemriOp))
1263bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1265 MCStreamer &Out, uint64_t &ErrorInfo,
1266 bool MatchingInlineAsm) {
1268 const PPCInstrInfo *
TII =
static_cast<const PPCInstrInfo *
>(&MII);
1270 switch (MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
1273 return Error(IDLoc,
"invalid operand for instruction");
1275 processInstruction(Inst, Operands);
1279 case Match_MissingFeature:
1280 return Error(IDLoc,
"instruction use requires an option to be enabled");
1281 case Match_MnemonicFail: {
1282 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1284 ((PPCOperand &)*Operands[0]).
getToken(), FBS);
1285 return Error(IDLoc,
"invalid instruction" + Suggestion,
1286 ((PPCOperand &)*Operands[0]).getLocRange());
1288 case Match_InvalidOperand: {
1289 SMLoc ErrorLoc = IDLoc;
1290 if (ErrorInfo != ~0ULL) {
1291 if (ErrorInfo >= Operands.size())
1292 return Error(IDLoc,
"too few operands for instruction");
1294 ErrorLoc = ((PPCOperand &)*Operands[ErrorInfo]).getStartLoc();
1295 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1298 return Error(ErrorLoc,
"invalid operand for instruction");
1305#define GET_REGISTER_MATCHER
1306#include "PPCGenAsmMatcher.inc"
1308MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
1317 std::string NameBuf = getParser().getTok().getString().lower();
1323 Name.substr(Name.find_first_of(
"1234567890")).getAsInteger(10, IntVal);
1328 RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
1330 }
else if (Name ==
"ctr") {
1331 RegNo = isPPC64() ? PPC::CTR8 : PPC::CTR;
1333 }
else if (Name ==
"vrsave")
1335 else if (Name.starts_with(
"r"))
1336 RegNo = isPPC64() ? XRegs[IntVal] : RRegs[IntVal];
1342bool PPCAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1344 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
1345 return TokError(
"invalid register name");
1349ParseStatus PPCAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1351 const AsmToken &Tok = getParser().getTok();
1355 if (!(
Reg = matchRegisterName(IntVal)))
1363const MCExpr *PPCAsmParser::extractSpecifier(
const MCExpr *
E,
1365 MCContext &
Context = getParser().getContext();
1366 switch (
E->getKind()) {
1372 Spec =
TE->getSpecifier();
1373 (void)extractSpecifier(
TE->getSubExpr(), Spec);
1395 Error(
E->getLoc(),
"cannot contain more than one relocation specifier");
1403 const MCExpr *
Sub = extractSpecifier(UE->
getSubExpr(), Spec);
1411 const MCExpr *
LHS = extractSpecifier(BE->
getLHS(), Spec);
1412 const MCExpr *
RHS = extractSpecifier(BE->
getRHS(), Spec);
1426bool PPCAsmParser::parseExpression(
const MCExpr *&EVal) {
1429 if (getParser().parseExpression(EVal))
1433 const MCExpr *
E = extractSpecifier(EVal, Spec);
1443 MCAsmParser &Parser = getParser();
1449 switch (getLexer().getKind()) {
1454 if (!matchRegisterName(IntVal))
1455 return Error(S,
"invalid register name");
1457 Operands.
push_back(PPCOperand::CreateImm(IntVal, S,
E, isPPC64()));
1469 if (!parseExpression(EVal))
1474 return Error(S,
"unknown operand");
1478 Operands.
push_back(PPCOperand::CreateFromMCExpr(EVal, S,
E, isPPC64()));
1481 const char TlsGetAddr[] =
"__tls_get_addr";
1482 bool TlsCall =
false;
1483 const MCExpr *TlsCallAddend =
nullptr;
1485 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1489 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1490 TlsCallAddend =
Bin->getRHS();
1495 const MCExpr *TLSSym;
1497 if (parseExpression(TLSSym))
1498 return Error(S2,
"invalid TLS call expression");
1504 AsmToken Tok = getTok();
1511 const MCExpr *Addend =
nullptr;
1513 if (parsePrimaryExpr(Addend, EndLoc))
1519 TlsCallAddend = Addend;
1524 Operands.
back() = PPCOperand::CreateFromMCExpr(
1528 Operands.
push_back(PPCOperand::CreateFromMCExpr(TLSSym, S,
E, isPPC64()));
1536 switch (getLexer().getKind()) {
1538 if (!matchRegisterName(IntVal))
1539 return Error(S,
"invalid register name");
1543 if (getParser().parseAbsoluteExpression(IntVal) || IntVal < 0 ||
1545 return Error(S,
"invalid register number");
1549 return Error(S,
"invalid memory operand");
1556 PPCOperand::CreateImm(IntVal, S,
E, isPPC64(),
true));
1563bool PPCAsmParser::parseInstruction(ParseInstructionInfo &
Info, StringRef Name,
1568 std::string NewOpcode;
1570 NewOpcode = std::string(Name);
1575 NewOpcode = std::string(Name);
1581 size_t Dot =
Name.find(
'.');
1582 StringRef Mnemonic =
Name.slice(0, Dot);
1583 if (!NewOpcode.empty())
1585 PPCOperand::CreateTokenWithStringCopy(Mnemonic, NameLoc, isPPC64()));
1587 Operands.
push_back(PPCOperand::CreateToken(Mnemonic, NameLoc, isPPC64()));
1590 StringRef DotStr =
Name.substr(Dot);
1591 if (!NewOpcode.empty())
1593 PPCOperand::CreateTokenWithStringCopy(DotStr, DotLoc, isPPC64()));
1595 Operands.
push_back(PPCOperand::CreateToken(DotStr, DotLoc, isPPC64()));
1603 if (parseOperand(Operands))
1619 if (getSTI().hasFeature(PPC::FeatureBookE) &&
1620 Operands.
size() == 4 &&
1621 (Name ==
"dcbt" || Name ==
"dcbtst")) {
1627 if (Name ==
"lqarx" || Name ==
"ldarx" || Name ==
"lwarx" ||
1628 Name ==
"lharx" || Name ==
"lbarx") {
1629 if (Operands.
size() != 5)
1631 PPCOperand &EHOp = (PPCOperand &)*Operands[4];
1632 if (EHOp.isUImm<1>() && EHOp.getImm() == 0)
1640bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
1642 if (IDVal ==
".word")
1643 parseDirectiveWord(2, DirectiveID);
1644 else if (IDVal ==
".llong")
1645 parseDirectiveWord(8, DirectiveID);
1646 else if (IDVal ==
".tc")
1647 parseDirectiveTC(isPPC64() ? 8 : 4, DirectiveID);
1648 else if (IDVal ==
".machine")
1649 parseDirectiveMachine(DirectiveID.
getLoc());
1650 else if (IDVal ==
".abiversion")
1651 parseDirectiveAbiVersion(DirectiveID.
getLoc());
1652 else if (IDVal ==
".localentry")
1653 parseDirectiveLocalEntry(DirectiveID.
getLoc());
1655 parseGNUAttribute(DirectiveID.
getLoc());
1662bool PPCAsmParser::parseDirectiveWord(
unsigned Size, AsmToken
ID) {
1663 auto parseOp = [&]() ->
bool {
1664 const MCExpr *
Value;
1665 SMLoc ExprLoc = getParser().getTok().getLoc();
1666 if (getParser().parseExpression(
Value))
1670 uint64_t IntValue = MCE->getValue();
1672 return Error(ExprLoc,
"literal value out of range for '" +
1673 ID.getIdentifier() +
"' directive");
1674 getStreamer().emitIntValue(IntValue,
Size);
1676 getStreamer().emitValue(
Value,
Size, ExprLoc);
1680 if (parseMany(parseOp))
1681 return addErrorSuffix(
" in '" +
ID.getIdentifier() +
"' directive");
1686bool PPCAsmParser::parseDirectiveTC(
unsigned Size, AsmToken
ID) {
1687 MCAsmParser &Parser = getParser();
1693 return addErrorSuffix(
" in '.tc' directive");
1696 getParser().getStreamer().emitValueToAlignment(
Align(
Size));
1699 return parseDirectiveWord(
Size,
ID);
1704bool PPCAsmParser::parseDirectiveMachine(SMLoc L) {
1705 MCAsmParser &Parser = getParser();
1708 return Error(L,
"unexpected token in '.machine' directive");
1719 return addErrorSuffix(
" in '.machine' directive");
1721 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1722 getParser().getStreamer().getTargetStreamer());
1723 if (TStreamer !=
nullptr)
1730bool PPCAsmParser::parseDirectiveAbiVersion(SMLoc L) {
1732 if (check(getParser().parseAbsoluteExpression(AbiVersion), L,
1733 "expected constant expression") ||
1735 return addErrorSuffix(
" in '.abiversion' directive");
1737 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1738 getParser().getStreamer().getTargetStreamer());
1739 if (TStreamer !=
nullptr)
1746bool PPCAsmParser::parseDirectiveLocalEntry(SMLoc L) {
1748 if (getParser().parseIdentifier(Name))
1749 return Error(L,
"expected identifier in '.localentry' directive");
1751 auto *Sym =
static_cast<MCSymbolELF *
>(
getContext().getOrCreateSymbol(Name));
1755 check(getParser().parseExpression(Expr), L,
"expected expression") ||
1757 return addErrorSuffix(
" in '.localentry' directive");
1759 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1760 getParser().getStreamer().getTargetStreamer());
1761 if (TStreamer !=
nullptr)
1767bool PPCAsmParser::parseGNUAttribute(SMLoc L) {
1769 int64_t IntegerValue;
1770 if (!getParser().parseGNUAttribute(L,
Tag, IntegerValue))
1773 getParser().getStreamer().emitGNUAttribute(
Tag, IntegerValue);
1787#define GET_MATCHER_IMPLEMENTATION
1788#define GET_MNEMONIC_SPELL_CHECKER
1789#include "PPCGenAsmMatcher.inc"
1800 case MCK_0: ImmVal = 0;
break;
1801 case MCK_1: ImmVal = 1;
break;
1802 case MCK_2: ImmVal = 2;
break;
1803 case MCK_3: ImmVal = 3;
break;
1804 case MCK_4: ImmVal = 4;
break;
1805 case MCK_5: ImmVal = 5;
break;
1806 case MCK_6: ImmVal = 6;
break;
1807 case MCK_7: ImmVal = 7;
break;
1808 default:
return Match_InvalidOperand;
1811 PPCOperand &
Op =
static_cast<PPCOperand &
>(AsmOp);
1812 if (
Op.isUImm<3>() &&
Op.getImm() == ImmVal)
1813 return Match_Success;
1815 return Match_InvalidOperand;
1818const 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")
Analysis containing CSE Info
#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,...