63 const MCRegisterInfo &MRI;
65 enum class TailRelocKind { Load_GOT, Add_TLS, Load_TLS, Call_TLS };
70#define GET_ASSEMBLER_HEADER
71#include "SparcGenAsmMatcher.inc"
76 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
79 bool MatchingInlineAsm)
override;
82 SMLoc &EndLoc)
override;
86 bool parseDirectiveRegister();
87 bool parseExprWithSpecifier(
const MCExpr *&Res,
SMLoc &
E);
88 bool parseDataExpr(
const MCExpr *&Res)
override;
99 template <TailRelocKind Kind>
108 ParseStatus parseSparcAsmOperand(std::unique_ptr<SparcOperand> &Operand);
119 bool isPossibleExpression(
const AsmToken &Token);
122 MatchResultTy mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
123 bool mnemonicTakesBranchModifiers(
StringRef Mnemonic);
130 bool is64Bit()
const {
return getSTI().getTargetTriple().isSPARC64(); }
131 bool isV9()
const {
return getSTI().hasFeature(Sparc::FeatureV9); }
133 bool expandSET(MCInst &Inst, SMLoc IDLoc,
134 SmallVectorImpl<MCInst> &Instructions);
136 bool expandSETSW(MCInst &Inst, SMLoc IDLoc,
137 SmallVectorImpl<MCInst> &Instructions);
139 bool expandSETX(MCInst &Inst, SMLoc IDLoc,
140 SmallVectorImpl<MCInst> &Instructions);
142 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
145 SparcAsmParser(
const MCSubtargetInfo &sti, MCAsmParser &parser,
146 const MCInstrInfo &MII)
147 : MCTargetAsmParser(sti, MII), Parser(parser),
149 Parser.addAliasForDirective(
".half",
".2byte");
150 Parser.addAliasForDirective(
".uahalf",
".2byte");
151 Parser.addAliasForDirective(
".word",
".4byte");
152 Parser.addAliasForDirective(
".uaword",
".4byte");
153 Parser.addAliasForDirective(
".nword",
is64Bit() ?
".8byte" :
".4byte");
155 Parser.addAliasForDirective(
".xword",
".8byte");
158 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
165 Sparc::G0, Sparc::G1, Sparc::G2, Sparc::G3,
166 Sparc::G4, Sparc::G5, Sparc::G6, Sparc::G7,
167 Sparc::O0, Sparc::O1, Sparc::O2, Sparc::O3,
168 Sparc::O4, Sparc::O5, Sparc::O6, Sparc::O7,
169 Sparc::L0, Sparc::L1, Sparc::L2, Sparc::L3,
170 Sparc::L4, Sparc::L5, Sparc::L6, Sparc::L7,
171 Sparc::I0, Sparc::I1, Sparc::I2, Sparc::I3,
172 Sparc::I4, Sparc::I5, Sparc::I6, Sparc::I7 };
198 SMLoc StartLoc, EndLoc;
216 MCRegister OffsetReg;
230 SparcOperand(KindTy K) : Kind(
K) {}
232 bool isToken()
const override {
return Kind == k_Token; }
233 bool isReg()
const override {
return Kind == k_Register; }
234 bool isImm()
const override {
return Kind == k_Immediate; }
235 bool isMem()
const override {
return isMEMrr() || isMEMri(); }
236 bool isMEMrr()
const {
return Kind == k_MemoryReg; }
237 bool isMEMri()
const {
return Kind == k_MemoryImm; }
238 bool isMembarTag()
const {
return Kind == k_Immediate; }
239 bool isASITag()
const {
return Kind == k_ASITag; }
240 bool isPrefetchTag()
const {
return Kind == k_PrefetchTag; }
241 bool isTailRelocSym()
const {
return Kind == k_TailRelocSym; }
243 bool isCallTarget()
const {
248 return CE->getValue() % 4 == 0;
253 bool isShiftAmtImm5()
const {
263 bool isShiftAmtImm6()
const {
274 return (Kind == k_Register &&
Reg.Kind == rk_IntReg);
278 assert(Kind == k_Token &&
"Invalid access!");
279 return StringRef(Tok.Data, Tok.Length);
282 MCRegister
getReg()
const override {
283 assert((Kind == k_Register) &&
"Invalid access!");
287 const MCExpr *
getImm()
const {
288 assert((Kind == k_Immediate) &&
"Invalid access!");
292 MCRegister getMemBase()
const {
293 assert((Kind == k_MemoryReg || Kind == k_MemoryImm) &&
"Invalid access!");
297 MCRegister getMemOffsetReg()
const {
298 assert((Kind == k_MemoryReg) &&
"Invalid access!");
299 return Mem.OffsetReg;
302 const MCExpr *getMemOff()
const {
303 assert((Kind == k_MemoryImm) &&
"Invalid access!");
307 unsigned getASITag()
const {
308 assert((Kind == k_ASITag) &&
"Invalid access!");
312 unsigned getPrefetchTag()
const {
313 assert((Kind == k_PrefetchTag) &&
"Invalid access!");
317 const MCExpr *getTailRelocSym()
const {
318 assert((Kind == k_TailRelocSym) &&
"Invalid access!");
323 SMLoc getStartLoc()
const override {
327 SMLoc getEndLoc()
const override {
331 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
333 case k_Token: OS <<
"Token: " <<
getToken() <<
"\n";
break;
335 OS <<
"Reg: #" <<
getReg().
id() <<
"\n";
337 case k_Immediate: OS <<
"Imm: " <<
getImm() <<
"\n";
break;
339 OS <<
"Mem: " << getMemBase().id() <<
"+" << getMemOffsetReg().id()
342 case k_MemoryImm:
assert(getMemOff() !=
nullptr);
343 OS <<
"Mem: " << getMemBase().id() <<
"+";
348 OS <<
"ASI tag: " << getASITag() <<
"\n";
351 OS <<
"Prefetch tag: " << getPrefetchTag() <<
"\n";
354 OS <<
"TailReloc: " << getTailRelocSym() <<
"\n";
359 void addRegOperands(MCInst &Inst,
unsigned N)
const {
360 assert(
N == 1 &&
"Invalid number of operands!");
364 void addImmOperands(MCInst &Inst,
unsigned N)
const {
365 assert(
N == 1 &&
"Invalid number of operands!");
366 const MCExpr *Expr =
getImm();
370 void addShiftAmtImm5Operands(MCInst &Inst,
unsigned N)
const {
371 assert(
N == 1 &&
"Invalid number of operands!");
374 void addShiftAmtImm6Operands(MCInst &Inst,
unsigned N)
const {
375 assert(
N == 1 &&
"Invalid number of operands!");
379 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const{
389 void addMEMrrOperands(MCInst &Inst,
unsigned N)
const {
390 assert(
N == 2 &&
"Invalid number of operands!");
398 void addMEMriOperands(MCInst &Inst,
unsigned N)
const {
399 assert(
N == 2 &&
"Invalid number of operands!");
403 const MCExpr *Expr = getMemOff();
407 void addASITagOperands(MCInst &Inst,
unsigned N)
const {
408 assert(
N == 1 &&
"Invalid number of operands!");
412 void addPrefetchTagOperands(MCInst &Inst,
unsigned N)
const {
413 assert(
N == 1 &&
"Invalid number of operands!");
417 void addMembarTagOperands(MCInst &Inst,
unsigned N)
const {
418 assert(
N == 1 &&
"Invalid number of operands!");
419 const MCExpr *Expr =
getImm();
424 assert(
N == 1 &&
"Invalid number of operands!");
428 void addTailRelocSymOperands(MCInst &Inst,
unsigned N)
const {
429 assert(
N == 1 &&
"Invalid number of operands!");
430 addExpr(Inst, getTailRelocSym());
433 static std::unique_ptr<SparcOperand> CreateToken(StringRef Str, SMLoc S) {
434 auto Op = std::make_unique<SparcOperand>(k_Token);
435 Op->Tok.Data = Str.data();
436 Op->Tok.Length = Str.size();
442 static std::unique_ptr<SparcOperand> CreateReg(MCRegister
Reg,
unsigned Kind,
444 auto Op = std::make_unique<SparcOperand>(k_Register);
446 Op->Reg.Kind = (SparcOperand::RegisterKind)Kind;
452 static std::unique_ptr<SparcOperand> CreateImm(
const MCExpr *Val, SMLoc S,
454 auto Op = std::make_unique<SparcOperand>(k_Immediate);
461 static std::unique_ptr<SparcOperand> CreateASITag(
unsigned Val, SMLoc S,
463 auto Op = std::make_unique<SparcOperand>(k_ASITag);
470 static std::unique_ptr<SparcOperand> CreatePrefetchTag(
unsigned Val, SMLoc S,
472 auto Op = std::make_unique<SparcOperand>(k_PrefetchTag);
479 static std::unique_ptr<SparcOperand> CreateTailRelocSym(
const MCExpr *Val,
481 auto Op = std::make_unique<SparcOperand>(k_TailRelocSym);
488 static std::unique_ptr<SparcOperand>
489 MorphToMEMrr(MCRegister
Base, std::unique_ptr<SparcOperand>
Op) {
490 MCRegister offsetReg =
Op->getReg();
491 Op->Kind = k_MemoryReg;
493 Op->Mem.OffsetReg = offsetReg;
494 Op->Mem.Off =
nullptr;
498 static std::unique_ptr<SparcOperand> CreateMEMr(MCRegister
Base, SMLoc S,
500 auto Op = std::make_unique<SparcOperand>(k_MemoryReg);
502 Op->Mem.OffsetReg = Sparc::G0;
503 Op->Mem.Off =
nullptr;
509 static std::unique_ptr<SparcOperand>
510 MorphToMEMri(MCRegister
Base, std::unique_ptr<SparcOperand>
Op) {
511 const MCExpr *
Imm =
Op->getImm();
512 Op->Kind = k_MemoryImm;
514 Op->Mem.OffsetReg = MCRegister();
522#define GET_MATCHER_IMPLEMENTATION
523#define GET_REGISTER_MATCHER
524#define GET_MNEMONIC_SPELL_CHECKER
525#include "SparcGenAsmMatcher.inc"
529SparcAsmParser::MatchResultTy
530SparcAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
535 const MatchEntry *Start, *
End;
540 Start = std::begin(MatchTable0);
541 End = std::end(MatchTable0);
546 auto MnemonicRange = std::equal_range(Start,
End, Mnemonic, LessOpcode());
548 if (MnemonicRange.first == MnemonicRange.second)
549 return Match_MnemonicFail;
551 for (
const MatchEntry *it = MnemonicRange.first, *ie = MnemonicRange.second;
554 FeatureBitsets[it->RequiredFeaturesIdx];
555 if ((getAvailableFeatures() & RequiredFeatures) == RequiredFeatures)
556 return Match_Success;
558 return Match_MissingFeature;
563bool SparcAsmParser::mnemonicTakesBranchModifiers(StringRef Mnemonic) {
564 auto MnemonicRange = std::equal_range(
565 std::begin(MatchTable0), std::end(MatchTable0), Mnemonic, LessOpcode());
567 return E.Classes[0] == MCK_a ||
E.Classes[0] == MCK_pn ||
568 E.Classes[0] == MCK_pt;
572bool SparcAsmParser::expandSET(MCInst &Inst, SMLoc IDLoc,
573 SmallVectorImpl<MCInst> &Instructions) {
581 int64_t RawImmValue = IsImm ? MCValOp.
getImm() : 0;
584 if (RawImmValue < -2147483648LL || RawImmValue > 4294967295LL) {
586 "set: argument must be between -2147483648 and 4294967295");
591 int32_t ImmValue = RawImmValue;
595 bool IsEffectivelyImm13 =
596 IsImm && ((
is64Bit() ? 0 : -4096) <= ImmValue && ImmValue < 4096);
597 const MCExpr *ValExpr;
608 if (!IsEffectivelyImm13) {
610 const MCExpr *Expr = adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr);
629 if (!IsImm || IsEffectivelyImm13 || (ImmValue & 0x3ff)) {
632 if (IsEffectivelyImm13)
635 Expr = adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr);
646bool SparcAsmParser::expandSETSW(MCInst &Inst, SMLoc IDLoc,
647 SmallVectorImpl<MCInst> &Instructions) {
655 int64_t ImmValue = IsImm ? MCValOp.
getImm() : 0;
659 bool IsSmallImm = IsImm &&
isInt<13>(ImmValue);
660 bool NoLowBitsImm = IsImm && ((ImmValue & 0x3FF) == 0);
666 "set: argument must be between -2147483648 and 2147483647");
673 MCInstBuilder(SP::SETHIi)
675 .addExpr(adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr)));
681 if (!NoLowBitsImm || IsSmallImm) {
683 IsSmallImm ? ValExpr : adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr);
688 .addReg(PrevReg.getReg())
697 if (!IsImm || ImmValue < 0) {
708bool SparcAsmParser::expandSETX(MCInst &Inst, SMLoc IDLoc,
709 SmallVectorImpl<MCInst> &Instructions) {
717 bool IsImm = MCValOp.
isImm();
718 int64_t ImmValue = IsImm ? MCValOp.
getImm() : 0;
737 MCInstBuilder(SP::SETHIi)
739 .addExpr(adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr)));
742 MCInstBuilder(SP::ORri)
745 .addExpr(adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr)));
775 .addReg(MCRegOp.
getReg()));
780bool SparcAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
784 bool MatchingInlineAsm) {
787 unsigned MatchResult = MatchInstructionImpl(
Operands, Inst, ErrorInfo,
789 switch (MatchResult) {
790 case Match_Success: {
800 if (!isV9() &&
Operands.size() == 4)
802 "instruction requires a CPU feature not currently "
813 if (expandSET(Inst, IDLoc, Instructions))
817 if (expandSETSW(Inst, IDLoc, Instructions))
821 if (expandSETX(Inst, IDLoc, Instructions))
826 for (
const MCInst &
I : Instructions) {
827 Out.emitInstruction(
I, getSTI());
832 case Match_MissingFeature:
834 "instruction requires a CPU feature not currently enabled");
836 case Match_InvalidOperand: {
837 SMLoc ErrorLoc = IDLoc;
838 if (ErrorInfo != ~0ULL) {
840 return Error(IDLoc,
"too few operands for instruction");
842 ErrorLoc = ((SparcOperand &)*
Operands[ErrorInfo]).getStartLoc();
843 if (ErrorLoc == SMLoc())
847 return Error(ErrorLoc,
"invalid operand for instruction");
849 case Match_MnemonicFail:
850 return Error(IDLoc,
"invalid instruction mnemonic");
855bool SparcAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
857 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
858 return Error(StartLoc,
"invalid register name");
862ParseStatus SparcAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
864 const AsmToken &Tok = Parser.
getTok();
867 Reg = Sparc::NoRegister;
871 unsigned RegKind = SparcOperand::rk_None;
878 getLexer().UnLex(Tok);
882bool SparcAsmParser::parseInstruction(ParseInstructionInfo &Info,
883 StringRef Name, SMLoc NameLoc,
894 MatchResultTy MS = mnemonicIsValid(Name, 0);
898 case Match_MissingFeature:
899 return Error(NameLoc,
900 "instruction requires a CPU feature not currently enabled");
901 case Match_MnemonicFail:
902 return Error(NameLoc,
903 "invalid instruction mnemonic" +
904 SparcMnemonicSpellCheck(Name, getAvailableFeatures(), 0));
910 Operands.push_back(SparcOperand::CreateToken(Name, NameLoc));
917 auto OperandFailed = [&](ParseStatus Res) {
920 return Error(getLexer().getLoc(),
"unexpected token");
925 if (getLexer().is(
AsmToken::Comma) && mnemonicTakesBranchModifiers(Name)) {
926 ParseStatus Res = parseBranchModifiers(
Operands);
928 return OperandFailed(Res);
930 ParseStatus Res = parseOperand(
Operands, Name);
932 return OperandFailed(Res);
943 return OperandFailed(Res);
947 SMLoc Loc = getLexer().getLoc();
948 return Error(Loc,
"unexpected token");
956bool SparcAsmParser::parseDirectiveRegister() {
958 "register syntax is .register %g[2367],{#scratch|symbolname|#ignore}";
960 SMLoc RegLoc = getLoc();
963 if (!tryParseRegister(
Reg, S,
E).isSuccess() ||
964 (
Reg != SP::G2 &&
Reg != SP::G3 &&
Reg != SP::G6 &&
Reg != SP::G7))
965 return Error(RegLoc, Syntax);
969 SMLoc NameLoc = getLoc();
974 if (Parser.
parseIdentifier(Kind) || (Kind !=
"scratch" && Kind !=
"ignore"))
975 return Error(NameLoc, Syntax);
978 return Error(NameLoc, Syntax);
983 auto &TS =
static_cast<SparcTargetStreamer &
>(
984 *getParser().getStreamer().getTargetStreamer());
990 unsigned RegNo =
MRI.getEncodingValue(
Reg);
991 switch (TS.getRegisterDeclKind(RegNo,
Ignore, Name)) {
992 case SparcTargetStreamer::RegisterDeclKind::Conflict:
993 return Error(RegLoc,
"redefinition of global register");
994 case SparcTargetStreamer::RegisterDeclKind::New:
996 return Error(NameLoc,
"register symbol '" + Name +
"' already defined");
997 TS.declareRegister(RegNo,
Ignore, Name);
999 case SparcTargetStreamer::RegisterDeclKind::Same:
1005 TS.emitSparcRegisterIgnore(
Reg);
1006 else if (
Name.empty())
1007 TS.emitSparcRegisterScratch(
Reg);
1009 TS.emitSparcRegisterName(
Reg, Name);
1013ParseStatus SparcAsmParser::parseDirective(AsmToken DirectiveID) {
1014 StringRef IDVal = DirectiveID.
getString();
1016 if (IDVal ==
".register")
1017 return parseDirectiveRegister();
1018 if (IDVal ==
".proc") {
1024 if (IDVal ==
".seg") {
1030 uint32_t Subsection = 0;
1031 const MCObjectFileInfo *MCOFI =
getContext().getObjectFileInfo();
1032 if (Name ==
"text") {
1034 }
else if (Name ==
"data" || Name ==
"data1") {
1036 Subsection =
Name ==
"data1" ? 1 : 0;
1037 }
else if (Name ==
"bss") {
1040 return Error(DirectiveID.
getLoc(),
"unknown segment type");
1042 getStreamer().switchSection(Section, Subsection);
1053 std::unique_ptr<SparcOperand>
LHS;
1054 ParseStatus Res = parseSparcAsmOperand(
LHS);
1060 Operands.push_back(SparcOperand::MorphToMEMri(Sparc::G0, std::move(
LHS)));
1064 if (!
LHS->isIntReg())
1065 return Error(
LHS->getStartLoc(),
"invalid register kind for this operand");
1067 AsmToken Tok = getLexer().getTok();
1073 std::unique_ptr<SparcOperand>
RHS;
1074 Res = parseSparcAsmOperand(
RHS);
1076 return Error(getLoc(),
"expected register or immediate");
1080 if (
RHS->isReg() && !
RHS->isIntReg())
1082 "invalid register kind for this operand");
1086 ? SparcOperand::MorphToMEMri(
LHS->getReg(), std::move(
RHS))
1087 : SparcOperand::MorphToMEMrr(
LHS->getReg(), std::move(
RHS)));
1092 Operands.push_back(SparcOperand::CreateMEMr(
LHS->getReg(), S,
E));
1096template <
unsigned N>
1106 if (getParser().parseExpression(Expr))
1111 return Error(S,
"constant expression expected");
1114 return Error(S,
"immediate shift value out of range");
1116 Operands.push_back(SparcOperand::CreateImm(Expr, S,
E));
1120template <SparcAsmParser::TailRelocKind Kind>
1125 auto MatchesKind = [](uint16_t RelType) ->
bool {
1127 case TailRelocKind::Load_GOT:
1130 return RelType == ELF::R_SPARC_GOTDATA_OP;
1131 case TailRelocKind::Add_TLS:
1135 case ELF::R_SPARC_TLS_GD_ADD:
1136 case ELF::R_SPARC_TLS_IE_ADD:
1137 case ELF::R_SPARC_TLS_LDM_ADD:
1138 case ELF::R_SPARC_TLS_LDO_ADD:
1143 case TailRelocKind::Load_TLS:
1147 case ELF::R_SPARC_TLS_IE_LD:
1148 case ELF::R_SPARC_TLS_IE_LDX:
1153 case TailRelocKind::Call_TLS:
1157 case ELF::R_SPARC_TLS_GD_CALL:
1158 case ELF::R_SPARC_TLS_LDM_CALL:
1170 const AsmToken Tok = Parser.
getTok();
1174 return Error(getLoc(),
"expected valid identifier for operand modifier");
1176 StringRef
Name = getParser().getTok().getIdentifier();
1179 return Error(getLoc(),
"invalid relocation specifier");
1181 if (!MatchesKind(RelType)) {
1183 getLexer().UnLex(Tok);
1189 return Error(getLoc(),
"expected '('");
1192 const MCExpr *SubExpr;
1193 if (getParser().parseParenExpression(SubExpr,
E))
1196 const MCExpr *Val = adjustPICRelocation(RelType, SubExpr);
1197 Operands.push_back(SparcOperand::CreateTailRelocSym(Val, S,
E));
1206 std::unique_ptr<SparcOperand>
Mask;
1207 ParseStatus Res = parseSparcAsmOperand(Mask);
1211 if (!
Mask->isImm() || !
Mask->getImm()->evaluateAsAbsolute(ImmVal) ||
1212 ImmVal < 0 || ImmVal > 127)
1213 return Error(S,
"invalid membar mask number");
1217 SMLoc TagStart = getLexer().getLoc();
1219 unsigned MaskVal = StringSwitch<unsigned>(Parser.
getTok().
getString())
1220 .Case(
"LoadLoad", 0x1)
1221 .Case(
"StoreLoad", 0x2)
1222 .Case(
"LoadStore", 0x4)
1223 .Case(
"StoreStore", 0x8)
1224 .Case(
"Lookaside", 0x10)
1225 .Case(
"MemIssue", 0x20)
1232 return Error(TagStart,
"unknown membar tag");
1242 Operands.push_back(SparcOperand::CreateImm(EVal, S,
E));
1254 ParseStatus ParseExprStatus = parseExpression(ASIVal);
1256 return ParseExprStatus;
1259 return Error(S,
"invalid ASI number, must be between 0 and 255");
1261 Operands.push_back(SparcOperand::CreateASITag(ASIVal, S,
E));
1267 SMLoc TagStart = getLexer().peekTok(
false).getLoc();
1270 const SparcASITag::ASITag *ASITag = SparcASITag::lookupASITagByName(ASIName);
1272 ASITag = SparcASITag::lookupASITagByAltName(ASIName);
1276 return Error(TagStart,
"unknown ASI tag");
1280 Operands.push_back(SparcOperand::CreateASITag(ASIVal, S,
E));
1287 int64_t PrefetchVal = 0;
1292 ParseStatus ParseExprStatus = parseExpression(PrefetchVal);
1294 return ParseExprStatus;
1297 return Error(S,
"invalid prefetch number, must be between 0 and 31");
1299 Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S,
E));
1303 SMLoc TagStart = getLexer().peekTok(
false).getLoc();
1306 const SparcPrefetchTag::PrefetchTag *PrefetchTag =
1307 SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
1311 return Error(TagStart,
"unknown prefetch tag");
1313 PrefetchVal = PrefetchTag->
Encoding;
1315 Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S,
E));
1323 switch (getLexer().getKind()) {
1333 const MCExpr *DestValue;
1334 if (getParser().parseExpression(DestValue))
1337 Operands.push_back(SparcOperand::CreateImm(DestValue, S,
E));
1342 StringRef Mnemonic) {
1344 ParseStatus Res = MatchOperandParserImpl(
Operands, Mnemonic);
1354 Operands.push_back(SparcOperand::CreateToken(
"[",
1358 if (Mnemonic ==
"cas" || Mnemonic ==
"casl" || Mnemonic ==
"casa" ||
1359 Mnemonic ==
"casx" || Mnemonic ==
"casxl" || Mnemonic ==
"casxa") {
1362 return Error(getLoc(),
"expected register name");
1368 return Error(getLoc(),
"expected register name");
1372 Operands.push_back(SparcOperand::CreateReg(
Reg, RegKind, S,
E));
1377 return Error(getLoc(),
"expected register or immediate");
1384 return Error(getLoc(),
"expected ']'");
1386 Operands.push_back(SparcOperand::CreateToken(
"]",
1393 StringRef MalformedASITag =
1394 is64Bit() ?
"malformed ASI tag, must be %asi, a constant integer "
1395 "expression, or a named tag"
1396 :
"malformed ASI tag, must be a constant integer expression";
1400 return Error(S, MalformedASITag);
1403 const AsmToken Tok = Parser.
getTok();
1411 if (OldMemOp.isMEMrr()) {
1412 if (OldMemOp.getMemOffsetReg() != Sparc::G0) {
1413 return Error(S,
"invalid operand for instruction");
1416 OldMemOp.getMemBase(),
1418 OldMemOp.getStartLoc(),
1419 OldMemOp.getEndLoc()));
1426 Operands.push_back(SparcOperand::CreateToken(
"%asi", S));
1430 return Error(S, MalformedASITag);
1439 return Error(getLoc(), MalformedASITag);
1445 std::unique_ptr<SparcOperand>
Op;
1447 Res = parseSparcAsmOperand(
Op);
1458SparcAsmParser::parseSparcAsmOperand(std::unique_ptr<SparcOperand> &
Op) {
1464 switch (getLexer().getKind()) {
1479 if (
Reg == Sparc::ICC && Name ==
"xcc")
1480 Op = SparcOperand::CreateToken(
"%xcc", S);
1482 Op = SparcOperand::CreateReg(
Reg, RegKind, S,
E);
1485 ParseStatus Res = matchSparcAsmModifiers(EVal,
E);
1488 return Error(getLoc(),
"invalid register name");
1492 Op = SparcOperand::CreateImm(EVal, S,
E);
1503 if (getParser().parseExpression(EVal,
E))
1506 Op = SparcOperand::CreateImm(EVal, S,
E);
1518 return Error(getLoc(),
"expected branch modifier");
1520 if (modName ==
"a" || modName ==
"pn" || modName ==
"pt") {
1521 Operands.push_back(SparcOperand::CreateToken(modName,
1529ParseStatus SparcAsmParser::parseExpression(int64_t &Val) {
1530 AsmToken Tok = getLexer().getTok();
1532 if (!isPossibleExpression(Tok))
1535 return getParser().parseAbsoluteExpression(Val);
1538MCRegister SparcAsmParser::matchRegisterName(
const AsmToken &Tok,
1539 unsigned &RegKind) {
1540 RegKind = SparcOperand::rk_None;
1542 return SP::NoRegister;
1552 return SP::NoRegister;
1556 if (
Reg == SP::TICK && !isV9())
1557 return SP::NoRegister;
1565 if (
Reg == SP::ASR4 && Name ==
"tick") {
1566 RegKind = SparcOperand::rk_Special;
1571 RegKind = SparcOperand::rk_IntReg;
1580 RegKind = SparcOperand::rk_Special;
1589 RegKind = SparcOperand::rk_IntReg;
1593 RegKind = SparcOperand::rk_IntReg;
1599 if (
Name.starts_with(
"r") && !
Name.drop_front().getAsInteger(10, RegNo) &&
1601 RegKind = SparcOperand::rk_IntReg;
1605 if (Name ==
"xcc" || Name ==
"ncc") {
1607 RegKind = SparcOperand::rk_Special;
1613 return SP::NoRegister;
1617 if (Name ==
"pcr") {
1618 RegKind = SparcOperand::rk_Special;
1621 if (Name ==
"pic") {
1622 RegKind = SparcOperand::rk_Special;
1625 if (Name ==
"dcr") {
1626 RegKind = SparcOperand::rk_Special;
1629 if (Name ==
"gsr") {
1630 RegKind = SparcOperand::rk_Special;
1633 if (Name ==
"set_softint") {
1634 RegKind = SparcOperand::rk_Special;
1637 if (Name ==
"clear_softint") {
1638 RegKind = SparcOperand::rk_Special;
1641 if (Name ==
"softint") {
1642 RegKind = SparcOperand::rk_Special;
1645 if (Name ==
"tick_cmpr") {
1646 RegKind = SparcOperand::rk_Special;
1649 if (Name ==
"stick" || Name ==
"sys_tick") {
1650 RegKind = SparcOperand::rk_Special;
1653 if (Name ==
"stick_cmpr" || Name ==
"sys_tick_cmpr") {
1654 RegKind = SparcOperand::rk_Special;
1658 return SP::NoRegister;
1692const MCSpecifierExpr *
1693SparcAsmParser::adjustPICRelocation(uint16_t RelType,
const MCExpr *subExpr) {
1699 if (
getContext().getObjectFileInfo()->isPositionIndependent()) {
1702 case ELF::R_SPARC_LO10:
1706 case ELF::R_SPARC_HI22:
1716ParseStatus SparcAsmParser::matchSparcAsmModifiers(
const MCExpr *&EVal,
1719 AsmToken Tok = Parser.
getTok();
1729 return Error(getLoc(),
"invalid relocation specifier");
1731 case ELF::R_SPARC_GOTDATA_OP:
1732 case ELF::R_SPARC_TLS_GD_ADD:
1733 case ELF::R_SPARC_TLS_GD_CALL:
1734 case ELF::R_SPARC_TLS_IE_ADD:
1735 case ELF::R_SPARC_TLS_IE_LD:
1736 case ELF::R_SPARC_TLS_IE_LDX:
1737 case ELF::R_SPARC_TLS_LDM_ADD:
1738 case ELF::R_SPARC_TLS_LDM_CALL:
1739 case ELF::R_SPARC_TLS_LDO_ADD:
1742 return Error(getLoc(),
"unexpected relocation specifier");
1750 const MCExpr *subExpr;
1754 EVal = adjustPICRelocation(VK, subExpr);
1758bool SparcAsmParser::parseExprWithSpecifier(
const MCExpr *&Res, SMLoc &
E) {
1759 SMLoc Loc = getLoc();
1761 return TokError(
"expected '%' relocation specifier");
1764 return TokError(
"invalid relocation specifier");
1770 const MCExpr *SubExpr;
1777bool SparcAsmParser::parseDataExpr(
const MCExpr *&Res) {
1780 return parseExprWithSpecifier(Res, EndLoc);
1784bool SparcAsmParser::isPossibleExpression(
const AsmToken &Token) {
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID)
static bool addCallTargetOperands(MachineInstrBuilder &CallInst, MachineIRBuilder &MIRBuilder, AMDGPUCallLowering::CallLoweringInfo &Info, bool IsDynamicVGPRChainCall=false)
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
ReachingDefInfo InstSet InstSet & Ignore
static MCRegister MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
loop data Loop Data Prefetch
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
MachineRegisterInfo & MRI
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the SmallVector class.
static bool hasGOTReference(const MCExpr *Expr)
static const MCPhysReg IntRegs[32]
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcAsmParser()
static bool is64Bit(const char *name)
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
bool is(TokenKind K) const
TokenKind getKind() const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Base class for user error types.
Container class for subtarget features.
void printExpr(raw_ostream &, const MCExpr &) const
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
virtual bool parseEscapedString(std::string &Data)=0
Parse the current token as a string which may include escaped characters and return the string conten...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool parseIdentifier(StringRef &Res)=0
Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents.
virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression, assuming that an initial '(' has already been consumed.
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
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.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
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.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
MCSection * getBSSSection() const
MCSection * getTextSection() const
MCSection * getDataSection() const
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
Wrapper class representing physical registers and target specific virtual registers.
constexpr unsigned id() const
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Streaming machine code generation interface.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
StringRef getName() const
getName - Get the symbol name.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
constexpr bool isNoMatch() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isIntReg(MCRegister Reg)
MCExpr const & getExpr(MCExpr const &Expr)
MCRegister matchRegisterName(StringRef Name, const MCRegisterInfo &MRI, unsigned RegClassID, unsigned AltIdx)
Match a symbolic name in RegClassID, or return an invalid register.
uint16_t parseSpecifier(StringRef name)
uint16_t parseDataSpecifier(StringRef name)
@ CE
Windows NT (Windows on ARM)
This is an optimization pass for GlobalISel generic memory operations.
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.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Target & getTheSparcTarget()
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Target & getTheSparcV9Target()
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Target & getTheSparcelTarget()
@ End
Run the machine verifier once, at the end of the pipeline.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...