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 isS34Imm()
const {
371 return Kind == Expression || isSImm<34>();
373 bool isS34ImmX16()
const {
374 return Kind == Expression || (isSImm<34>() && (
getImm() & 15) == 0);
377 bool isHashImmX8()
const {
381 return (Kind == Immediate &&
getImm() <= -8 &&
getImm() >= -512 &&
385 bool isTLSReg()
const {
return Kind == TLSRegister; }
386 bool isDirectBr()
const {
387 if (Kind == Expression)
389 if (Kind != Immediate)
403 bool isCondBr()
const {
return Kind == Expression ||
406 bool isImmZero()
const {
return Kind == Immediate &&
getImm() == 0; }
407 bool isRegNumber()
const {
return Kind == Immediate &&
isUInt<5>(
getImm()); }
408 bool isACCRegNumber()
const {
411 bool isDMRROWRegNumber()
const {
414 bool isDMRROWpRegNumber()
const {
417 bool isDMRRegNumber()
const {
420 bool isDMRpRegNumber()
const {
423 bool isVSRpEvenRegNumber()
const {
426 bool isVSRegNumber()
const {
429 bool isCCRegNumber()
const {
return (Kind == Expression
433 bool isCRBitNumber()
const {
return (Kind == Expression
438 bool isEvenRegNumber()
const {
return isRegNumber() && (
getImm() & 1) == 0; }
440 bool isCRBitMask()
const {
444 bool isATBitsAsHint()
const {
return false; }
445 bool isMem()
const override {
return false; }
446 bool isReg()
const override {
return false; }
448 void addRegOperands(MCInst &Inst,
unsigned N)
const {
452 void addRegGPRCOperands(MCInst &Inst,
unsigned N)
const {
453 assert(
N == 1 &&
"Invalid number of operands!");
457 void addRegGPRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
458 assert(
N == 1 &&
"Invalid number of operands!");
462 void addRegG8RCOperands(MCInst &Inst,
unsigned N)
const {
463 assert(
N == 1 &&
"Invalid number of operands!");
467 void addRegG8RCNoX0Operands(MCInst &Inst,
unsigned N)
const {
468 assert(
N == 1 &&
"Invalid number of operands!");
472 void addRegG8pRCOperands(MCInst &Inst,
unsigned N)
const {
473 assert(
N == 1 &&
"Invalid number of operands!");
477 void addRegGxRCOperands(MCInst &Inst,
unsigned N)
const {
479 addRegG8RCOperands(Inst,
N);
481 addRegGPRCOperands(Inst,
N);
484 void addRegGxRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
486 addRegG8RCNoX0Operands(Inst,
N);
488 addRegGPRCNoR0Operands(Inst,
N);
491 void addRegF4RCOperands(MCInst &Inst,
unsigned N)
const {
492 assert(
N == 1 &&
"Invalid number of operands!");
496 void addRegF8RCOperands(MCInst &Inst,
unsigned N)
const {
497 assert(
N == 1 &&
"Invalid number of operands!");
501 void addRegFpRCOperands(MCInst &Inst,
unsigned N)
const {
502 assert(
N == 1 &&
"Invalid number of operands!");
506 void addRegVFRCOperands(MCInst &Inst,
unsigned N)
const {
507 assert(
N == 1 &&
"Invalid number of operands!");
511 void addRegVRRCOperands(MCInst &Inst,
unsigned N)
const {
512 assert(
N == 1 &&
"Invalid number of operands!");
516 void addRegVSRCOperands(MCInst &Inst,
unsigned N)
const {
517 assert(
N == 1 &&
"Invalid number of operands!");
521 void addRegVSFRCOperands(MCInst &Inst,
unsigned N)
const {
522 assert(
N == 1 &&
"Invalid number of operands!");
526 void addRegVSSRCOperands(MCInst &Inst,
unsigned N)
const {
527 assert(
N == 1 &&
"Invalid number of operands!");
531 void addRegSPE4RCOperands(MCInst &Inst,
unsigned N)
const {
532 assert(
N == 1 &&
"Invalid number of operands!");
536 void addRegSPERCOperands(MCInst &Inst,
unsigned N)
const {
537 assert(
N == 1 &&
"Invalid number of operands!");
541 void addRegACCRCOperands(MCInst &Inst,
unsigned N)
const {
542 assert(
N == 1 &&
"Invalid number of operands!");
546 void addRegDMRROWRCOperands(MCInst &Inst,
unsigned N)
const {
547 assert(
N == 1 &&
"Invalid number of operands!");
551 void addRegDMRROWpRCOperands(MCInst &Inst,
unsigned N)
const {
552 assert(
N == 1 &&
"Invalid number of operands!");
556 void addRegDMRRCOperands(MCInst &Inst,
unsigned N)
const {
557 assert(
N == 1 &&
"Invalid number of operands!");
561 void addRegDMRpRCOperands(MCInst &Inst,
unsigned N)
const {
562 assert(
N == 1 &&
"Invalid number of operands!");
566 void addRegWACCRCOperands(MCInst &Inst,
unsigned N)
const {
567 assert(
N == 1 &&
"Invalid number of operands!");
571 void addRegWACC_HIRCOperands(MCInst &Inst,
unsigned N)
const {
572 assert(
N == 1 &&
"Invalid number of operands!");
576 void addRegVSRpRCOperands(MCInst &Inst,
unsigned N)
const {
577 assert(
N == 1 &&
"Invalid number of operands!");
581 void addRegVSRpEvenRCOperands(MCInst &Inst,
unsigned N)
const {
582 assert(
N == 1 &&
"Invalid number of operands!");
586 void addRegCRBITRCOperands(MCInst &Inst,
unsigned N)
const {
587 assert(
N == 1 &&
"Invalid number of operands!");
591 void addRegCRRCOperands(MCInst &Inst,
unsigned N)
const {
592 assert(
N == 1 &&
"Invalid number of operands!");
596 void addCRBitMaskOperands(MCInst &Inst,
unsigned N)
const {
597 assert(
N == 1 &&
"Invalid number of operands!");
601 void addImmOperands(MCInst &Inst,
unsigned N)
const {
602 assert(
N == 1 &&
"Invalid number of operands!");
603 if (Kind == Immediate)
609 void addS16ImmOperands(MCInst &Inst,
unsigned N)
const {
610 assert(
N == 1 &&
"Invalid number of operands!");
615 case ContextImmediate:
624 void addU16ImmOperands(MCInst &Inst,
unsigned N)
const {
625 assert(
N == 1 &&
"Invalid number of operands!");
630 case ContextImmediate:
639 void addBranchTargetOperands(MCInst &Inst,
unsigned N)
const {
640 assert(
N == 1 &&
"Invalid number of operands!");
641 if (Kind == Immediate)
647 void addTLSRegOperands(MCInst &Inst,
unsigned N)
const {
648 assert(
N == 1 &&
"Invalid number of operands!");
653 assert(Kind == Token &&
"Invalid access!");
654 return StringRef(Tok.Data, Tok.Length);
657 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override;
659 static std::unique_ptr<PPCOperand> CreateToken(StringRef Str, SMLoc S,
661 auto Op = std::make_unique<PPCOperand>(Token);
662 Op->Tok.Data = Str.data();
663 Op->Tok.Length = Str.size();
666 Op->IsPPC64 = IsPPC64;
670 static std::unique_ptr<PPCOperand>
671 CreateTokenWithStringCopy(StringRef Str, SMLoc S,
bool IsPPC64) {
677 void *Mem = ::operator
new(
sizeof(PPCOperand) + Str.size());
678 std::unique_ptr<PPCOperand>
Op(
new (Mem) PPCOperand(Token));
679 Op->Tok.Data =
reinterpret_cast<const char *
>(
Op.get() + 1);
680 Op->Tok.Length = Str.size();
681 std::memcpy(
const_cast<char *
>(
Op->Tok.Data), Str.data(), Str.size());
684 Op->IsPPC64 = IsPPC64;
688 static std::unique_ptr<PPCOperand> CreateImm(int64_t Val, SMLoc S, SMLoc
E,
690 bool IsMemOpBase =
false) {
691 auto Op = std::make_unique<PPCOperand>(Immediate);
693 Op->Imm.IsMemOpBase = IsMemOpBase;
696 Op->IsPPC64 = IsPPC64;
700 static std::unique_ptr<PPCOperand> CreateExpr(
const MCExpr *Val, SMLoc S,
701 SMLoc
E,
bool IsPPC64) {
702 auto Op = std::make_unique<PPCOperand>(Expression);
707 Op->IsPPC64 = IsPPC64;
711 static std::unique_ptr<PPCOperand>
712 CreateTLSReg(
const MCSymbolRefExpr *Sym, SMLoc S, SMLoc
E,
bool IsPPC64) {
713 auto Op = std::make_unique<PPCOperand>(TLSRegister);
714 Op->TLSReg.Sym = Sym;
717 Op->IsPPC64 = IsPPC64;
721 static std::unique_ptr<PPCOperand>
722 CreateContextImm(int64_t Val, SMLoc S, SMLoc
E,
bool IsPPC64) {
723 auto Op = std::make_unique<PPCOperand>(ContextImmediate);
727 Op->IsPPC64 = IsPPC64;
731 static std::unique_ptr<PPCOperand>
732 CreateFromMCExpr(
const MCExpr *Val, SMLoc S, SMLoc
E,
bool IsPPC64) {
734 return CreateImm(
CE->getValue(), S,
E, IsPPC64);
739 return CreateTLSReg(SRE, S,
E, IsPPC64);
744 return CreateContextImm(Res, S,
E, IsPPC64);
747 return CreateExpr(Val, S,
E, IsPPC64);
751 template <
unsigned W
idth>
752 bool isExtImm(
bool Signed,
unsigned Multiple)
const {
759 case ContextImmediate:
762 (getImmS16Context() & (Multiple - 1)) == 0;
765 (getImmU16Context() & (Multiple - 1)) == 0;
778 case ContextImmediate:
805 BinExpr->getLHS(), Ctx);
813void PPCAsmParser::processInstruction(MCInst &Inst,
822 TmpInst.
setOpcode((Opcode == PPC::DCBTx || Opcode == PPC::DCBTT) ?
823 PPC::DCBT : PPC::DCBTST);
825 (Opcode == PPC::DCBTx || Opcode == PPC::DCBTSTx) ? 0 : 16));
842 case PPC::DCBTSTDS: {
857 if (Opcode == PPC::DCBFL)
859 else if (Opcode == PPC::DCBFLP)
861 else if (Opcode == PPC::DCBFPS)
863 else if (Opcode == PPC::DCBSTPS)
886 TmpInst.
setOpcode(Opcode == PPC::PLA ? PPC::PADDI : PPC::PADDI8);
896 TmpInst.
setOpcode(Opcode == PPC::PLApc ? PPC::PADDIpc : PPC::PADDI8pc);
939 case PPC::SUBIC_rec: {
949 case PPC::EXTLWI_rec: {
953 TmpInst.
setOpcode(Opcode == PPC::EXTLWI ? PPC::RLWINM : PPC::RLWINM_rec);
963 case PPC::EXTRWI_rec: {
967 TmpInst.
setOpcode(Opcode == PPC::EXTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
977 case PPC::INSLWI_rec: {
981 TmpInst.
setOpcode(Opcode == PPC::INSLWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
992 case PPC::INSRWI_rec: {
996 TmpInst.
setOpcode(Opcode == PPC::INSRWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1007 case PPC::ROTRWI_rec: {
1010 TmpInst.
setOpcode(Opcode == PPC::ROTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1020 case PPC::SLWI_rec: {
1023 TmpInst.
setOpcode(Opcode == PPC::SLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1033 case PPC::SRWI_rec: {
1036 TmpInst.
setOpcode(Opcode == PPC::SRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1046 case PPC::CLRRWI_rec: {
1049 TmpInst.
setOpcode(Opcode == PPC::CLRRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1059 case PPC::CLRLSLWI_rec: {
1063 TmpInst.
setOpcode(Opcode == PPC::CLRLSLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1073 case PPC::EXTLDI_rec: {
1077 TmpInst.
setOpcode(Opcode == PPC::EXTLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1086 case PPC::EXTRDI_rec: {
1090 TmpInst.
setOpcode(Opcode == PPC::EXTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1099 case PPC::INSRDI_rec: {
1103 TmpInst.
setOpcode(Opcode == PPC::INSRDI ? PPC::RLDIMI : PPC::RLDIMI_rec);
1113 case PPC::ROTRDI_rec: {
1116 TmpInst.
setOpcode(Opcode == PPC::ROTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1125 case PPC::SLDI_rec: {
1128 TmpInst.
setOpcode(Opcode == PPC::SLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1136 case PPC::SUBPCIS: {
1146 case PPC::SRDI_rec: {
1149 TmpInst.
setOpcode(Opcode == PPC::SRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1158 case PPC::CLRRDI_rec: {
1161 TmpInst.
setOpcode(Opcode == PPC::CLRRDI ? PPC::RLDICR : PPC::RLDICR_rec);
1170 case PPC::CLRLSLDI_rec: {
1174 TmpInst.
setOpcode(Opcode == PPC::CLRLSLDI ? PPC::RLDIC : PPC::RLDIC_rec);
1183 case PPC::RLWINMbm_rec: {
1190 TmpInst.
setOpcode(Opcode == PPC::RLWINMbm ? PPC::RLWINM : PPC::RLWINM_rec);
1200 case PPC::RLWIMIbm_rec: {
1207 TmpInst.
setOpcode(Opcode == PPC::RLWIMIbm ? PPC::RLWIMI : PPC::RLWIMI_rec);
1218 case PPC::RLWNMbm_rec: {
1225 TmpInst.
setOpcode(Opcode == PPC::RLWNMbm ? PPC::RLWNM : PPC::RLWNM_rec);
1235 if (getSTI().hasFeature(PPC::FeatureMFTB)) {
1245 unsigned VariantID = 0);
1251 for (
size_t idx = 0; idx <
Operands.size(); ++idx) {
1252 const PPCOperand &
Op =
static_cast<const PPCOperand &
>(*
Operands[idx]);
1253 if (
Op.isMemOpBase() != (idx == 3 && isMemriOp))
1259bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1261 MCStreamer &Out, uint64_t &ErrorInfo,
1262 bool MatchingInlineAsm) {
1264 const PPCInstrInfo *
TII =
static_cast<const PPCInstrInfo *
>(&MII);
1266 switch (MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
1269 return Error(IDLoc,
"invalid operand for instruction");
1271 processInstruction(Inst,
Operands);
1275 case Match_MissingFeature:
1276 return Error(IDLoc,
"instruction use requires an option to be enabled");
1277 case Match_MnemonicFail: {
1278 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1281 return Error(IDLoc,
"invalid instruction" + Suggestion,
1282 ((PPCOperand &)*
Operands[0]).getLocRange());
1284 case Match_InvalidOperand: {
1285 SMLoc ErrorLoc = IDLoc;
1286 if (ErrorInfo != ~0ULL) {
1288 return Error(IDLoc,
"too few operands for instruction");
1290 ErrorLoc = ((PPCOperand &)*
Operands[ErrorInfo]).getStartLoc();
1291 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1294 return Error(ErrorLoc,
"invalid operand for instruction");
1301#define GET_REGISTER_MATCHER
1302#include "PPCGenAsmMatcher.inc"
1304MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
1313 std::string NameBuf = getParser().getTok().getString().lower();
1319 Name.substr(Name.find_first_of(
"1234567890")).getAsInteger(10, IntVal);
1324 RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
1326 }
else if (Name ==
"ctr") {
1327 RegNo = isPPC64() ? PPC::CTR8 : PPC::CTR;
1329 }
else if (Name ==
"vrsave")
1331 else if (Name.starts_with(
"r"))
1332 RegNo = isPPC64() ? XRegs[IntVal] : RRegs[IntVal];
1338bool PPCAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1340 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
1341 return TokError(
"invalid register name");
1345ParseStatus PPCAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1347 const AsmToken &Tok = getParser().getTok();
1351 if (!(
Reg = matchRegisterName(IntVal)))
1359const MCExpr *PPCAsmParser::extractSpecifier(
const MCExpr *
E,
1361 MCContext &
Context = getParser().getContext();
1362 switch (
E->getKind()) {
1368 Spec =
TE->getSpecifier();
1369 (void)extractSpecifier(
TE->getSubExpr(), Spec);
1391 Error(
E->getLoc(),
"cannot contain more than one relocation specifier");
1399 const MCExpr *
Sub = extractSpecifier(UE->
getSubExpr(), Spec);
1407 const MCExpr *
LHS = extractSpecifier(BE->
getLHS(), Spec);
1408 const MCExpr *
RHS = extractSpecifier(BE->
getRHS(), Spec);
1422bool PPCAsmParser::parseExpression(
const MCExpr *&EVal) {
1425 if (getParser().parseExpression(EVal))
1429 const MCExpr *
E = extractSpecifier(EVal, Spec);
1439 MCAsmParser &Parser = getParser();
1445 switch (getLexer().getKind()) {
1450 if (!matchRegisterName(IntVal))
1451 return Error(S,
"invalid register name");
1453 Operands.push_back(PPCOperand::CreateImm(IntVal, S,
E, isPPC64()));
1465 if (!parseExpression(EVal))
1470 return Error(S,
"unknown operand");
1474 Operands.push_back(PPCOperand::CreateFromMCExpr(EVal, S,
E, isPPC64()));
1477 const char TlsGetAddr[] =
"__tls_get_addr";
1478 bool TlsCall =
false;
1479 const MCExpr *TlsCallAddend =
nullptr;
1481 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1485 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1486 TlsCallAddend =
Bin->getRHS();
1491 const MCExpr *TLSSym;
1493 if (parseExpression(TLSSym))
1494 return Error(S2,
"invalid TLS call expression");
1500 AsmToken Tok = getTok();
1507 const MCExpr *Addend =
nullptr;
1509 if (parsePrimaryExpr(Addend, EndLoc))
1515 TlsCallAddend = Addend;
1520 Operands.back() = PPCOperand::CreateFromMCExpr(
1524 Operands.push_back(PPCOperand::CreateFromMCExpr(TLSSym, S,
E, isPPC64()));
1532 switch (getLexer().getKind()) {
1534 if (!matchRegisterName(IntVal))
1535 return Error(S,
"invalid register name");
1539 if (getParser().parseAbsoluteExpression(IntVal) || IntVal < 0 ||
1541 return Error(S,
"invalid register number");
1545 return Error(S,
"invalid memory operand");
1552 PPCOperand::CreateImm(IntVal, S,
E, isPPC64(),
true));
1559bool PPCAsmParser::parseInstruction(ParseInstructionInfo &
Info, StringRef Name,
1564 std::string NewOpcode;
1566 NewOpcode = std::string(Name);
1571 NewOpcode = std::string(Name);
1577 size_t Dot =
Name.find(
'.');
1578 StringRef Mnemonic =
Name.slice(0, Dot);
1579 if (!NewOpcode.empty())
1581 PPCOperand::CreateTokenWithStringCopy(Mnemonic, NameLoc, isPPC64()));
1583 Operands.push_back(PPCOperand::CreateToken(Mnemonic, NameLoc, isPPC64()));
1586 StringRef DotStr =
Name.substr(Dot);
1587 if (!NewOpcode.empty())
1589 PPCOperand::CreateTokenWithStringCopy(DotStr, DotLoc, isPPC64()));
1591 Operands.push_back(PPCOperand::CreateToken(DotStr, DotLoc, isPPC64()));
1615 if (getSTI().hasFeature(PPC::FeatureBookE) &&
1617 (Name ==
"dcbt" || Name ==
"dcbtst")) {
1623 if (Name ==
"lqarx" || Name ==
"ldarx" || Name ==
"lwarx" ||
1624 Name ==
"lharx" || Name ==
"lbarx") {
1627 PPCOperand &EHOp = (PPCOperand &)*
Operands[4];
1628 if (EHOp.isUImm<1>() && EHOp.getImm() == 0)
1636bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
1638 if (IDVal ==
".word")
1639 parseDirectiveWord(2, DirectiveID);
1640 else if (IDVal ==
".llong")
1641 parseDirectiveWord(8, DirectiveID);
1642 else if (IDVal ==
".tc")
1643 parseDirectiveTC(isPPC64() ? 8 : 4, DirectiveID);
1644 else if (IDVal ==
".machine")
1645 parseDirectiveMachine(DirectiveID.
getLoc());
1646 else if (IDVal ==
".abiversion")
1647 parseDirectiveAbiVersion(DirectiveID.
getLoc());
1648 else if (IDVal ==
".localentry")
1649 parseDirectiveLocalEntry(DirectiveID.
getLoc());
1651 parseGNUAttribute(DirectiveID.
getLoc());
1658bool PPCAsmParser::parseDirectiveWord(
unsigned Size, AsmToken
ID) {
1659 auto parseOp = [&]() ->
bool {
1660 const MCExpr *
Value;
1661 SMLoc ExprLoc = getParser().getTok().getLoc();
1662 if (getParser().parseExpression(
Value))
1666 uint64_t IntValue = MCE->getValue();
1668 return Error(ExprLoc,
"literal value out of range for '" +
1669 ID.getIdentifier() +
"' directive");
1670 getStreamer().emitIntValue(IntValue,
Size);
1672 getStreamer().emitValue(
Value,
Size, ExprLoc);
1676 if (parseMany(parseOp))
1677 return addErrorSuffix(
" in '" +
ID.getIdentifier() +
"' directive");
1682bool PPCAsmParser::parseDirectiveTC(
unsigned Size, AsmToken
ID) {
1683 MCAsmParser &Parser = getParser();
1689 return addErrorSuffix(
" in '.tc' directive");
1692 getParser().getStreamer().emitValueToAlignment(
Align(
Size));
1695 return parseDirectiveWord(
Size,
ID);
1700bool PPCAsmParser::parseDirectiveMachine(SMLoc L) {
1701 MCAsmParser &Parser = getParser();
1704 return Error(L,
"unexpected token in '.machine' directive");
1715 return addErrorSuffix(
" in '.machine' directive");
1717 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1718 getParser().getStreamer().getTargetStreamer());
1719 if (TStreamer !=
nullptr)
1726bool PPCAsmParser::parseDirectiveAbiVersion(SMLoc L) {
1728 if (check(getParser().parseAbsoluteExpression(AbiVersion), L,
1729 "expected constant expression") ||
1731 return addErrorSuffix(
" in '.abiversion' directive");
1733 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1734 getParser().getStreamer().getTargetStreamer());
1735 if (TStreamer !=
nullptr)
1742bool PPCAsmParser::parseDirectiveLocalEntry(SMLoc L) {
1744 if (getParser().parseIdentifier(Name))
1745 return Error(L,
"expected identifier in '.localentry' directive");
1747 auto *Sym =
static_cast<MCSymbolELF *
>(
getContext().getOrCreateSymbol(Name));
1751 check(getParser().parseExpression(Expr), L,
"expected expression") ||
1753 return addErrorSuffix(
" in '.localentry' directive");
1755 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1756 getParser().getStreamer().getTargetStreamer());
1757 if (TStreamer !=
nullptr)
1763bool PPCAsmParser::parseGNUAttribute(SMLoc L) {
1765 int64_t IntegerValue;
1766 if (!getParser().parseGNUAttribute(L,
Tag, IntegerValue))
1769 getParser().getStreamer().emitGNUAttribute(
Tag, IntegerValue);
1783#define GET_MATCHER_IMPLEMENTATION
1784#define GET_MNEMONIC_SPELL_CHECKER
1785#include "PPCGenAsmMatcher.inc"
1796 case MCK_0: ImmVal = 0;
break;
1797 case MCK_1: ImmVal = 1;
break;
1798 case MCK_2: ImmVal = 2;
break;
1799 case MCK_3: ImmVal = 3;
break;
1800 case MCK_4: ImmVal = 4;
break;
1801 case MCK_5: ImmVal = 5;
break;
1802 case MCK_6: ImmVal = 6;
break;
1803 case MCK_7: ImmVal = 7;
break;
1804 default:
return Match_InvalidOperand;
1807 PPCOperand &
Op =
static_cast<PPCOperand &
>(AsmOp);
1808 if (
Op.isUImm<3>() &&
Op.getImm() == ImmVal)
1809 return Match_Success;
1811 return Match_InvalidOperand;
1814const 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,...