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;
352 bool isU1Imm()
const {
return Kind == Immediate &&
isUInt<1>(
getImm()); }
353 bool isU2Imm()
const {
return Kind == Immediate &&
isUInt<2>(
getImm()); }
354 bool isU3Imm()
const {
return Kind == Immediate &&
isUInt<3>(
getImm()); }
355 bool isU4Imm()
const {
return Kind == Immediate &&
isUInt<4>(
getImm()); }
356 bool isU5Imm()
const {
return Kind == Immediate &&
isUInt<5>(
getImm()); }
357 bool isS5Imm()
const {
return Kind == Immediate &&
isInt<5>(
getImm()); }
358 bool isU6Imm()
const {
return Kind == Immediate &&
isUInt<6>(
getImm()); }
359 bool isU6ImmX2()
const {
return Kind == Immediate &&
362 bool isU7Imm()
const {
return Kind == Immediate &&
isUInt<7>(
getImm()); }
363 bool isU7ImmX4()
const {
return Kind == Immediate &&
366 bool isU8Imm()
const {
return Kind == Immediate &&
isUInt<8>(
getImm()); }
367 bool isU8ImmX8()
const {
return Kind == Immediate &&
373 bool isU16Imm()
const {
return isExtImm<16>(
false, 1); }
374 bool isS16Imm()
const {
return isExtImm<16>(
true, 1); }
375 bool isS16ImmX4()
const {
return isExtImm<16>(
true, 4); }
376 bool isS16ImmX16()
const {
return isExtImm<16>(
true, 16); }
377 bool isS17Imm()
const {
return isExtImm<17>(
true, 1); }
379 bool isHashImmX8()
const {
383 return (Kind == Immediate &&
getImm() <= -8 &&
getImm() >= -512 &&
387 bool isS34ImmX16()
const {
388 return Kind == Expression ||
391 bool isS34Imm()
const {
394 return Kind == Expression || (Kind == Immediate &&
isInt<34>(
getImm()));
397 bool isTLSReg()
const {
return Kind == TLSRegister; }
398 bool isDirectBr()
const {
399 if (Kind == Expression)
401 if (Kind != Immediate)
415 bool isCondBr()
const {
return Kind == Expression ||
418 bool isImmZero()
const {
return Kind == Immediate &&
getImm() == 0; }
419 bool isRegNumber()
const {
return Kind == Immediate &&
isUInt<5>(
getImm()); }
420 bool isACCRegNumber()
const {
423 bool isDMRROWRegNumber()
const {
426 bool isDMRROWpRegNumber()
const {
429 bool isDMRRegNumber()
const {
432 bool isDMRpRegNumber()
const {
435 bool isVSRpEvenRegNumber()
const {
438 bool isVSRegNumber()
const {
441 bool isCCRegNumber()
const {
return (Kind == Expression
445 bool isCRBitNumber()
const {
return (Kind == Expression
450 bool isEvenRegNumber()
const {
return isRegNumber() && (
getImm() & 1) == 0; }
452 bool isCRBitMask()
const {
456 bool isATBitsAsHint()
const {
return false; }
457 bool isMem()
const override {
return false; }
458 bool isReg()
const override {
return false; }
460 void addRegOperands(MCInst &Inst,
unsigned N)
const {
464 void addRegGPRCOperands(MCInst &Inst,
unsigned N)
const {
465 assert(
N == 1 &&
"Invalid number of operands!");
469 void addRegGPRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
470 assert(
N == 1 &&
"Invalid number of operands!");
474 void addRegG8RCOperands(MCInst &Inst,
unsigned N)
const {
475 assert(
N == 1 &&
"Invalid number of operands!");
479 void addRegG8RCNoX0Operands(MCInst &Inst,
unsigned N)
const {
480 assert(
N == 1 &&
"Invalid number of operands!");
484 void addRegG8pRCOperands(MCInst &Inst,
unsigned N)
const {
485 assert(
N == 1 &&
"Invalid number of operands!");
489 void addRegGxRCOperands(MCInst &Inst,
unsigned N)
const {
491 addRegG8RCOperands(Inst,
N);
493 addRegGPRCOperands(Inst,
N);
496 void addRegGxRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
498 addRegG8RCNoX0Operands(Inst,
N);
500 addRegGPRCNoR0Operands(Inst,
N);
503 void addRegF4RCOperands(MCInst &Inst,
unsigned N)
const {
504 assert(
N == 1 &&
"Invalid number of operands!");
508 void addRegF8RCOperands(MCInst &Inst,
unsigned N)
const {
509 assert(
N == 1 &&
"Invalid number of operands!");
513 void addRegFpRCOperands(MCInst &Inst,
unsigned N)
const {
514 assert(
N == 1 &&
"Invalid number of operands!");
518 void addRegVFRCOperands(MCInst &Inst,
unsigned N)
const {
519 assert(
N == 1 &&
"Invalid number of operands!");
523 void addRegVRRCOperands(MCInst &Inst,
unsigned N)
const {
524 assert(
N == 1 &&
"Invalid number of operands!");
528 void addRegVSRCOperands(MCInst &Inst,
unsigned N)
const {
529 assert(
N == 1 &&
"Invalid number of operands!");
533 void addRegVSFRCOperands(MCInst &Inst,
unsigned N)
const {
534 assert(
N == 1 &&
"Invalid number of operands!");
538 void addRegVSSRCOperands(MCInst &Inst,
unsigned N)
const {
539 assert(
N == 1 &&
"Invalid number of operands!");
543 void addRegSPE4RCOperands(MCInst &Inst,
unsigned N)
const {
544 assert(
N == 1 &&
"Invalid number of operands!");
548 void addRegSPERCOperands(MCInst &Inst,
unsigned N)
const {
549 assert(
N == 1 &&
"Invalid number of operands!");
553 void addRegACCRCOperands(MCInst &Inst,
unsigned N)
const {
554 assert(
N == 1 &&
"Invalid number of operands!");
558 void addRegDMRROWRCOperands(MCInst &Inst,
unsigned N)
const {
559 assert(
N == 1 &&
"Invalid number of operands!");
563 void addRegDMRROWpRCOperands(MCInst &Inst,
unsigned N)
const {
564 assert(
N == 1 &&
"Invalid number of operands!");
568 void addRegDMRRCOperands(MCInst &Inst,
unsigned N)
const {
569 assert(
N == 1 &&
"Invalid number of operands!");
573 void addRegDMRpRCOperands(MCInst &Inst,
unsigned N)
const {
574 assert(
N == 1 &&
"Invalid number of operands!");
578 void addRegWACCRCOperands(MCInst &Inst,
unsigned N)
const {
579 assert(
N == 1 &&
"Invalid number of operands!");
583 void addRegWACC_HIRCOperands(MCInst &Inst,
unsigned N)
const {
584 assert(
N == 1 &&
"Invalid number of operands!");
588 void addRegVSRpRCOperands(MCInst &Inst,
unsigned N)
const {
589 assert(
N == 1 &&
"Invalid number of operands!");
593 void addRegVSRpEvenRCOperands(MCInst &Inst,
unsigned N)
const {
594 assert(
N == 1 &&
"Invalid number of operands!");
598 void addRegCRBITRCOperands(MCInst &Inst,
unsigned N)
const {
599 assert(
N == 1 &&
"Invalid number of operands!");
603 void addRegCRRCOperands(MCInst &Inst,
unsigned N)
const {
604 assert(
N == 1 &&
"Invalid number of operands!");
608 void addCRBitMaskOperands(MCInst &Inst,
unsigned N)
const {
609 assert(
N == 1 &&
"Invalid number of operands!");
613 void addImmOperands(MCInst &Inst,
unsigned N)
const {
614 assert(
N == 1 &&
"Invalid number of operands!");
615 if (Kind == Immediate)
621 void addS16ImmOperands(MCInst &Inst,
unsigned N)
const {
622 assert(
N == 1 &&
"Invalid number of operands!");
627 case ContextImmediate:
636 void addU16ImmOperands(MCInst &Inst,
unsigned N)
const {
637 assert(
N == 1 &&
"Invalid number of operands!");
642 case ContextImmediate:
651 void addBranchTargetOperands(MCInst &Inst,
unsigned N)
const {
652 assert(
N == 1 &&
"Invalid number of operands!");
653 if (Kind == Immediate)
659 void addTLSRegOperands(MCInst &Inst,
unsigned N)
const {
660 assert(
N == 1 &&
"Invalid number of operands!");
665 assert(Kind == Token &&
"Invalid access!");
666 return StringRef(Tok.Data, Tok.Length);
669 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override;
671 static std::unique_ptr<PPCOperand> CreateToken(StringRef Str, SMLoc S,
673 auto Op = std::make_unique<PPCOperand>(Token);
674 Op->Tok.Data = Str.data();
675 Op->Tok.Length = Str.size();
678 Op->IsPPC64 = IsPPC64;
682 static std::unique_ptr<PPCOperand>
683 CreateTokenWithStringCopy(StringRef Str, SMLoc S,
bool IsPPC64) {
689 void *Mem = ::operator
new(
sizeof(PPCOperand) + Str.size());
690 std::unique_ptr<PPCOperand>
Op(
new (Mem) PPCOperand(Token));
691 Op->Tok.Data =
reinterpret_cast<const char *
>(
Op.get() + 1);
692 Op->Tok.Length = Str.size();
693 std::memcpy(
const_cast<char *
>(
Op->Tok.Data), Str.data(), Str.size());
696 Op->IsPPC64 = IsPPC64;
700 static std::unique_ptr<PPCOperand> CreateImm(int64_t Val, SMLoc S, SMLoc
E,
702 bool IsMemOpBase =
false) {
703 auto Op = std::make_unique<PPCOperand>(Immediate);
705 Op->Imm.IsMemOpBase = IsMemOpBase;
708 Op->IsPPC64 = IsPPC64;
712 static std::unique_ptr<PPCOperand> CreateExpr(
const MCExpr *Val, SMLoc S,
713 SMLoc
E,
bool IsPPC64) {
714 auto Op = std::make_unique<PPCOperand>(Expression);
719 Op->IsPPC64 = IsPPC64;
723 static std::unique_ptr<PPCOperand>
724 CreateTLSReg(
const MCSymbolRefExpr *Sym, SMLoc S, SMLoc
E,
bool IsPPC64) {
725 auto Op = std::make_unique<PPCOperand>(TLSRegister);
726 Op->TLSReg.Sym = Sym;
729 Op->IsPPC64 = IsPPC64;
733 static std::unique_ptr<PPCOperand>
734 CreateContextImm(int64_t Val, SMLoc S, SMLoc
E,
bool IsPPC64) {
735 auto Op = std::make_unique<PPCOperand>(ContextImmediate);
739 Op->IsPPC64 = IsPPC64;
743 static std::unique_ptr<PPCOperand>
744 CreateFromMCExpr(
const MCExpr *Val, SMLoc S, SMLoc
E,
bool IsPPC64) {
746 return CreateImm(
CE->getValue(), S,
E, IsPPC64);
751 return CreateTLSReg(SRE, S,
E, IsPPC64);
756 return CreateContextImm(Res, S,
E, IsPPC64);
759 return CreateExpr(Val, S,
E, IsPPC64);
763 template <
unsigned W
idth>
764 bool isExtImm(
bool Signed,
unsigned Multiple)
const {
771 case ContextImmediate:
774 (getImmS16Context() & (Multiple - 1)) == 0;
777 (getImmU16Context() & (Multiple - 1)) == 0;
790 case ContextImmediate:
817 BinExpr->getLHS(), Ctx);
825void PPCAsmParser::processInstruction(MCInst &Inst,
834 TmpInst.
setOpcode((Opcode == PPC::DCBTx || Opcode == PPC::DCBTT) ?
835 PPC::DCBT : PPC::DCBTST);
837 (Opcode == PPC::DCBTx || Opcode == PPC::DCBTSTx) ? 0 : 16));
854 case PPC::DCBTSTDS: {
869 if (Opcode == PPC::DCBFL)
871 else if (Opcode == PPC::DCBFLP)
873 else if (Opcode == PPC::DCBFPS)
875 else if (Opcode == PPC::DCBSTPS)
898 TmpInst.
setOpcode(Opcode == PPC::PLA ? PPC::PADDI : PPC::PADDI8);
908 TmpInst.
setOpcode(Opcode == PPC::PLApc ? PPC::PADDIpc : PPC::PADDI8pc);
951 case PPC::SUBIC_rec: {
961 case PPC::EXTLWI_rec: {
965 TmpInst.
setOpcode(Opcode == PPC::EXTLWI ? PPC::RLWINM : PPC::RLWINM_rec);
975 case PPC::EXTRWI_rec: {
979 TmpInst.
setOpcode(Opcode == PPC::EXTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
989 case PPC::INSLWI_rec: {
993 TmpInst.
setOpcode(Opcode == PPC::INSLWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1004 case PPC::INSRWI_rec: {
1008 TmpInst.
setOpcode(Opcode == PPC::INSRWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1019 case PPC::ROTRWI_rec: {
1022 TmpInst.
setOpcode(Opcode == PPC::ROTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1032 case PPC::SLWI_rec: {
1035 TmpInst.
setOpcode(Opcode == PPC::SLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1045 case PPC::SRWI_rec: {
1048 TmpInst.
setOpcode(Opcode == PPC::SRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1058 case PPC::CLRRWI_rec: {
1061 TmpInst.
setOpcode(Opcode == PPC::CLRRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1071 case PPC::CLRLSLWI_rec: {
1075 TmpInst.
setOpcode(Opcode == PPC::CLRLSLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1085 case PPC::EXTLDI_rec: {
1089 TmpInst.
setOpcode(Opcode == PPC::EXTLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1098 case PPC::EXTRDI_rec: {
1102 TmpInst.
setOpcode(Opcode == PPC::EXTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1111 case PPC::INSRDI_rec: {
1115 TmpInst.
setOpcode(Opcode == PPC::INSRDI ? PPC::RLDIMI : PPC::RLDIMI_rec);
1125 case PPC::ROTRDI_rec: {
1128 TmpInst.
setOpcode(Opcode == PPC::ROTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1137 case PPC::SLDI_rec: {
1140 TmpInst.
setOpcode(Opcode == PPC::SLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1148 case PPC::SUBPCIS: {
1158 case PPC::SRDI_rec: {
1161 TmpInst.
setOpcode(Opcode == PPC::SRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1170 case PPC::CLRRDI_rec: {
1173 TmpInst.
setOpcode(Opcode == PPC::CLRRDI ? PPC::RLDICR : PPC::RLDICR_rec);
1182 case PPC::CLRLSLDI_rec: {
1186 TmpInst.
setOpcode(Opcode == PPC::CLRLSLDI ? PPC::RLDIC : PPC::RLDIC_rec);
1195 case PPC::RLWINMbm_rec: {
1202 TmpInst.
setOpcode(Opcode == PPC::RLWINMbm ? PPC::RLWINM : PPC::RLWINM_rec);
1212 case PPC::RLWIMIbm_rec: {
1219 TmpInst.
setOpcode(Opcode == PPC::RLWIMIbm ? PPC::RLWIMI : PPC::RLWIMI_rec);
1230 case PPC::RLWNMbm_rec: {
1237 TmpInst.
setOpcode(Opcode == PPC::RLWNMbm ? PPC::RLWNM : PPC::RLWNM_rec);
1247 if (getSTI().hasFeature(PPC::FeatureMFTB)) {
1257 unsigned VariantID = 0);
1263 for (
size_t idx = 0; idx <
Operands.size(); ++idx) {
1264 const PPCOperand &
Op =
static_cast<const PPCOperand &
>(*
Operands[idx]);
1265 if (
Op.isMemOpBase() != (idx == 3 && isMemriOp))
1271bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1273 MCStreamer &Out, uint64_t &ErrorInfo,
1274 bool MatchingInlineAsm) {
1276 const PPCInstrInfo *
TII =
static_cast<const PPCInstrInfo *
>(&MII);
1278 switch (MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
1281 return Error(IDLoc,
"invalid operand for instruction");
1283 processInstruction(Inst,
Operands);
1287 case Match_MissingFeature:
1288 return Error(IDLoc,
"instruction use requires an option to be enabled");
1289 case Match_MnemonicFail: {
1290 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1293 return Error(IDLoc,
"invalid instruction" + Suggestion,
1294 ((PPCOperand &)*
Operands[0]).getLocRange());
1296 case Match_InvalidOperand: {
1297 SMLoc ErrorLoc = IDLoc;
1298 if (ErrorInfo != ~0ULL) {
1300 return Error(IDLoc,
"too few operands for instruction");
1302 ErrorLoc = ((PPCOperand &)*
Operands[ErrorInfo]).getStartLoc();
1303 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1306 return Error(ErrorLoc,
"invalid operand for instruction");
1313#define GET_REGISTER_MATCHER
1314#include "PPCGenAsmMatcher.inc"
1316MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
1325 std::string NameBuf = getParser().getTok().getString().lower();
1331 Name.substr(Name.find_first_of(
"1234567890")).getAsInteger(10, IntVal);
1336 RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
1338 }
else if (Name ==
"ctr") {
1339 RegNo = isPPC64() ? PPC::CTR8 : PPC::CTR;
1341 }
else if (Name ==
"vrsave")
1343 else if (Name.starts_with(
"r"))
1344 RegNo = isPPC64() ? XRegs[IntVal] : RRegs[IntVal];
1350bool PPCAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1352 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
1353 return TokError(
"invalid register name");
1357ParseStatus PPCAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1359 const AsmToken &Tok = getParser().getTok();
1363 if (!(
Reg = matchRegisterName(IntVal)))
1371const MCExpr *PPCAsmParser::extractSpecifier(
const MCExpr *
E,
1373 MCContext &
Context = getParser().getContext();
1374 switch (
E->getKind()) {
1380 Spec =
TE->getSpecifier();
1381 (void)extractSpecifier(
TE->getSubExpr(), Spec);
1403 Error(
E->getLoc(),
"cannot contain more than one relocation specifier");
1411 const MCExpr *
Sub = extractSpecifier(UE->
getSubExpr(), Spec);
1419 const MCExpr *
LHS = extractSpecifier(BE->
getLHS(), Spec);
1420 const MCExpr *
RHS = extractSpecifier(BE->
getRHS(), Spec);
1434bool PPCAsmParser::parseExpression(
const MCExpr *&EVal) {
1437 if (getParser().parseExpression(EVal))
1441 const MCExpr *
E = extractSpecifier(EVal, Spec);
1451 MCAsmParser &Parser = getParser();
1457 switch (getLexer().getKind()) {
1462 if (!matchRegisterName(IntVal))
1463 return Error(S,
"invalid register name");
1465 Operands.push_back(PPCOperand::CreateImm(IntVal, S,
E, isPPC64()));
1477 if (!parseExpression(EVal))
1482 return Error(S,
"unknown operand");
1486 Operands.push_back(PPCOperand::CreateFromMCExpr(EVal, S,
E, isPPC64()));
1489 const char TlsGetAddr[] =
"__tls_get_addr";
1490 bool TlsCall =
false;
1491 const MCExpr *TlsCallAddend =
nullptr;
1493 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1497 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1498 TlsCallAddend =
Bin->getRHS();
1503 const MCExpr *TLSSym;
1505 if (parseExpression(TLSSym))
1506 return Error(S2,
"invalid TLS call expression");
1512 AsmToken Tok = getTok();
1519 const MCExpr *Addend =
nullptr;
1521 if (parsePrimaryExpr(Addend, EndLoc))
1527 TlsCallAddend = Addend;
1532 Operands.back() = PPCOperand::CreateFromMCExpr(
1536 Operands.push_back(PPCOperand::CreateFromMCExpr(TLSSym, S,
E, isPPC64()));
1544 switch (getLexer().getKind()) {
1546 if (!matchRegisterName(IntVal))
1547 return Error(S,
"invalid register name");
1551 if (getParser().parseAbsoluteExpression(IntVal) || IntVal < 0 ||
1553 return Error(S,
"invalid register number");
1557 return Error(S,
"invalid memory operand");
1564 PPCOperand::CreateImm(IntVal, S,
E, isPPC64(),
true));
1571bool PPCAsmParser::parseInstruction(ParseInstructionInfo &
Info, StringRef Name,
1576 std::string NewOpcode;
1578 NewOpcode = std::string(Name);
1583 NewOpcode = std::string(Name);
1589 size_t Dot =
Name.find(
'.');
1590 StringRef Mnemonic =
Name.slice(0, Dot);
1591 if (!NewOpcode.empty())
1593 PPCOperand::CreateTokenWithStringCopy(Mnemonic, NameLoc, isPPC64()));
1595 Operands.push_back(PPCOperand::CreateToken(Mnemonic, NameLoc, isPPC64()));
1598 StringRef DotStr =
Name.substr(Dot);
1599 if (!NewOpcode.empty())
1601 PPCOperand::CreateTokenWithStringCopy(DotStr, DotLoc, isPPC64()));
1603 Operands.push_back(PPCOperand::CreateToken(DotStr, DotLoc, isPPC64()));
1627 if (getSTI().hasFeature(PPC::FeatureBookE) &&
1629 (Name ==
"dcbt" || Name ==
"dcbtst")) {
1635 if (Name ==
"lqarx" || Name ==
"ldarx" || Name ==
"lwarx" ||
1636 Name ==
"lharx" || Name ==
"lbarx") {
1639 PPCOperand &EHOp = (PPCOperand &)*
Operands[4];
1640 if (EHOp.isU1Imm() && EHOp.getImm() == 0)
1648bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
1650 if (IDVal ==
".word")
1651 parseDirectiveWord(2, DirectiveID);
1652 else if (IDVal ==
".llong")
1653 parseDirectiveWord(8, DirectiveID);
1654 else if (IDVal ==
".tc")
1655 parseDirectiveTC(isPPC64() ? 8 : 4, DirectiveID);
1656 else if (IDVal ==
".machine")
1657 parseDirectiveMachine(DirectiveID.
getLoc());
1658 else if (IDVal ==
".abiversion")
1659 parseDirectiveAbiVersion(DirectiveID.
getLoc());
1660 else if (IDVal ==
".localentry")
1661 parseDirectiveLocalEntry(DirectiveID.
getLoc());
1663 parseGNUAttribute(DirectiveID.
getLoc());
1670bool PPCAsmParser::parseDirectiveWord(
unsigned Size, AsmToken
ID) {
1671 auto parseOp = [&]() ->
bool {
1672 const MCExpr *
Value;
1673 SMLoc ExprLoc = getParser().getTok().getLoc();
1674 if (getParser().parseExpression(
Value))
1678 uint64_t IntValue = MCE->getValue();
1680 return Error(ExprLoc,
"literal value out of range for '" +
1681 ID.getIdentifier() +
"' directive");
1682 getStreamer().emitIntValue(IntValue,
Size);
1684 getStreamer().emitValue(
Value,
Size, ExprLoc);
1688 if (parseMany(parseOp))
1689 return addErrorSuffix(
" in '" +
ID.getIdentifier() +
"' directive");
1694bool PPCAsmParser::parseDirectiveTC(
unsigned Size, AsmToken
ID) {
1695 MCAsmParser &Parser = getParser();
1701 return addErrorSuffix(
" in '.tc' directive");
1704 getParser().getStreamer().emitValueToAlignment(
Align(
Size));
1707 return parseDirectiveWord(
Size,
ID);
1712bool PPCAsmParser::parseDirectiveMachine(SMLoc L) {
1713 MCAsmParser &Parser = getParser();
1716 return Error(L,
"unexpected token in '.machine' directive");
1727 return addErrorSuffix(
" in '.machine' directive");
1729 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1730 getParser().getStreamer().getTargetStreamer());
1731 if (TStreamer !=
nullptr)
1738bool PPCAsmParser::parseDirectiveAbiVersion(SMLoc L) {
1740 if (check(getParser().parseAbsoluteExpression(AbiVersion), L,
1741 "expected constant expression") ||
1743 return addErrorSuffix(
" in '.abiversion' directive");
1745 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1746 getParser().getStreamer().getTargetStreamer());
1747 if (TStreamer !=
nullptr)
1754bool PPCAsmParser::parseDirectiveLocalEntry(SMLoc L) {
1756 if (getParser().parseIdentifier(Name))
1757 return Error(L,
"expected identifier in '.localentry' directive");
1759 auto *Sym =
static_cast<MCSymbolELF *
>(
getContext().getOrCreateSymbol(Name));
1763 check(getParser().parseExpression(Expr), L,
"expected expression") ||
1765 return addErrorSuffix(
" in '.localentry' directive");
1767 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1768 getParser().getStreamer().getTargetStreamer());
1769 if (TStreamer !=
nullptr)
1775bool PPCAsmParser::parseGNUAttribute(SMLoc L) {
1777 int64_t IntegerValue;
1778 if (!getParser().parseGNUAttribute(L,
Tag, IntegerValue))
1781 getParser().getStreamer().emitGNUAttribute(
Tag, IntegerValue);
1795#define GET_MATCHER_IMPLEMENTATION
1796#define GET_MNEMONIC_SPELL_CHECKER
1797#include "PPCGenAsmMatcher.inc"
1808 case MCK_0: ImmVal = 0;
break;
1809 case MCK_1: ImmVal = 1;
break;
1810 case MCK_2: ImmVal = 2;
break;
1811 case MCK_3: ImmVal = 3;
break;
1812 case MCK_4: ImmVal = 4;
break;
1813 case MCK_5: ImmVal = 5;
break;
1814 case MCK_6: ImmVal = 6;
break;
1815 case MCK_7: ImmVal = 7;
break;
1816 default:
return Match_InvalidOperand;
1819 PPCOperand &
Op =
static_cast<PPCOperand &
>(AsmOp);
1820 if (
Op.isU3Imm() &&
Op.getImm() == ImmVal)
1821 return Match_Success;
1823 return Match_InvalidOperand;
1826const 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[]
mir Rename Register Operands
static unsigned 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
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
static constexpr size_t npos
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,...