10 #define DEBUG_TYPE "mcasmparser" 65 "mwarn-missing-parenthesis",
66 cl::desc(
"Warn for missing parenthesis around predicate registers"),
69 "merror-missing-parenthesis",
70 cl::desc(
"Error for missing parenthesis around predicate registers"),
73 "mwarn-sign-mismatch",
74 cl::desc(
"Warn for mismatching a signed and unsigned value"),
77 "mwarn-noncontigious-register",
80 "merror-noncontigious-register",
81 cl::desc(
"Error for register names that aren't contigious"),
86 struct HexagonOperand;
112 bool equalIsAsmAssignment()
override {
return false; }
113 bool isLabel(
AsmToken &Token)
override;
117 bool ParseDirectiveFalign(
unsigned Size,
SMLoc L);
119 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
120 bool ParseDirectiveSubsection(
SMLoc L);
121 bool ParseDirectiveComm(
bool IsLocal,
SMLoc L);
122 bool RegisterMatchesArch(
unsigned MatchNum)
const;
124 bool matchBundleOptions();
125 bool handleNoncontigiousRegister(
bool Contigious,
SMLoc &Loc);
127 void canonicalizeImmediates(
MCInst &MCI);
130 bool MatchingInlineAsm);
131 void eatToEndOfPacket();
132 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
135 bool MatchingInlineAsm)
override;
138 unsigned Kind)
override;
139 bool OutOfRange(
SMLoc IDLoc,
long long Val,
long long Max);
144 void chksetELFHeaderEFlags(
unsigned flags) {
146 getAssembler()->setELFHeaderEFlags(flags);
154 #define GET_ASSEMBLER_HEADER 155 #include "HexagonGenAsmMatcher.inc" 165 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
179 bool parseExpression(
MCExpr const *&Expr);
189 bool ParseDirective(
AsmToken DirectiveID)
override;
198 SMLoc StartLoc, EndLoc;
223 HexagonOperand(KindTy K,
MCContext &Context)
227 HexagonOperand(
const HexagonOperand &o)
230 StartLoc = o.StartLoc;
246 SMLoc getStartLoc()
const override {
return StartLoc; }
249 SMLoc getEndLoc()
const override {
return EndLoc; }
251 unsigned getReg()
const override {
256 const MCExpr *getImm()
const {
257 assert(Kind == Immediate &&
"Invalid access!");
261 bool isToken()
const override {
return Kind == Token; }
262 bool isImm()
const override {
return Kind == Immediate; }
266 bool CheckImmRange(
int immBits,
int zeroBits,
bool isSigned,
267 bool isRelocatable,
bool Extendable)
const {
268 if (Kind == Immediate) {
273 if (myMCExpr->evaluateAsAbsolute(Res)) {
274 int bits = immBits + zeroBits;
277 if (Res & ((1 << zeroBits) - 1))
280 if (Res < (1LL << (bits - 1)) && Res >= -(1LL << (bits - 1)))
286 return ((uint64_t)Res < (uint64_t)(1ULL << bits));
288 const int64_t high_bit_set = 1ULL << 63;
289 const uint64_t mask = (high_bit_set >> (63 -
bits));
290 return (((uint64_t)Res & mask) == mask);
302 bool isa30_2Imm()
const {
return CheckImmRange(30, 2,
true,
true,
true); }
303 bool isb30_2Imm()
const {
return CheckImmRange(30, 2,
true,
true,
true); }
304 bool isb15_2Imm()
const {
return CheckImmRange(15, 2,
true,
true,
false); }
305 bool isb13_2Imm()
const {
return CheckImmRange(13, 2,
true,
true,
false); }
307 bool ism32_0Imm()
const {
return true; }
309 bool isf32Imm()
const {
return false; }
310 bool isf64Imm()
const {
return false; }
311 bool iss32_0Imm()
const {
return true; }
312 bool iss31_1Imm()
const {
return true; }
313 bool iss30_2Imm()
const {
return true; }
314 bool iss29_3Imm()
const {
return true; }
315 bool iss27_2Imm()
const {
return CheckImmRange(27, 2,
true,
true,
false); }
316 bool iss10_0Imm()
const {
return CheckImmRange(10, 0,
true,
false,
false); }
317 bool iss10_6Imm()
const {
return CheckImmRange(10, 6,
true,
false,
false); }
318 bool iss9_0Imm()
const {
return CheckImmRange(9, 0,
true,
false,
false); }
319 bool iss8_0Imm()
const {
return CheckImmRange(8, 0,
true,
false,
false); }
320 bool iss8_0Imm64()
const {
return CheckImmRange(8, 0,
true,
true,
false); }
321 bool iss7_0Imm()
const {
return CheckImmRange(7, 0,
true,
false,
false); }
322 bool iss6_0Imm()
const {
return CheckImmRange(6, 0,
true,
false,
false); }
323 bool iss6_3Imm()
const {
return CheckImmRange(6, 3,
true,
false,
false); }
324 bool iss4_0Imm()
const {
return CheckImmRange(4, 0,
true,
false,
false); }
325 bool iss4_1Imm()
const {
return CheckImmRange(4, 1,
true,
false,
false); }
326 bool iss4_2Imm()
const {
return CheckImmRange(4, 2,
true,
false,
false); }
327 bool iss4_3Imm()
const {
return CheckImmRange(4, 3,
true,
false,
false); }
328 bool iss3_0Imm()
const {
return CheckImmRange(3, 0,
true,
false,
false); }
330 bool isu64_0Imm()
const {
return CheckImmRange(64, 0,
false,
true,
true); }
331 bool isu32_0Imm()
const {
return true; }
332 bool isu31_1Imm()
const {
return true; }
333 bool isu30_2Imm()
const {
return true; }
334 bool isu29_3Imm()
const {
return true; }
335 bool isu26_6Imm()
const {
return CheckImmRange(26, 6,
false,
true,
false); }
336 bool isu16_0Imm()
const {
return CheckImmRange(16, 0,
false,
true,
false); }
337 bool isu16_1Imm()
const {
return CheckImmRange(16, 1,
false,
true,
false); }
338 bool isu16_2Imm()
const {
return CheckImmRange(16, 2,
false,
true,
false); }
339 bool isu16_3Imm()
const {
return CheckImmRange(16, 3,
false,
true,
false); }
340 bool isu11_3Imm()
const {
return CheckImmRange(11, 3,
false,
false,
false); }
341 bool isu10_0Imm()
const {
return CheckImmRange(10, 0,
false,
false,
false); }
342 bool isu9_0Imm()
const {
return CheckImmRange(9, 0,
false,
false,
false); }
343 bool isu8_0Imm()
const {
return CheckImmRange(8, 0,
false,
false,
false); }
344 bool isu7_0Imm()
const {
return CheckImmRange(7, 0,
false,
false,
false); }
345 bool isu6_0Imm()
const {
return CheckImmRange(6, 0,
false,
false,
false); }
346 bool isu6_1Imm()
const {
return CheckImmRange(6, 1,
false,
false,
false); }
347 bool isu6_2Imm()
const {
return CheckImmRange(6, 2,
false,
false,
false); }
348 bool isu6_3Imm()
const {
return CheckImmRange(6, 3,
false,
false,
false); }
349 bool isu5_0Imm()
const {
return CheckImmRange(5, 0,
false,
false,
false); }
350 bool isu5_2Imm()
const {
return CheckImmRange(5, 2,
false,
false,
false); }
351 bool isu5_3Imm()
const {
return CheckImmRange(5, 3,
false,
false,
false); }
352 bool isu4_0Imm()
const {
return CheckImmRange(4, 0,
false,
false,
false); }
353 bool isu4_2Imm()
const {
return CheckImmRange(4, 2,
false,
false,
false); }
354 bool isu3_0Imm()
const {
return CheckImmRange(3, 0,
false,
false,
false); }
355 bool isu3_1Imm()
const {
return CheckImmRange(3, 1,
false,
false,
false); }
356 bool isu2_0Imm()
const {
return CheckImmRange(2, 0,
false,
false,
false); }
357 bool isu1_0Imm()
const {
return CheckImmRange(1, 0,
false,
false,
false); }
359 bool isn1Const()
const {
363 if (!getImm()->evaluateAsAbsolute(Value))
367 bool iss11_0Imm()
const {
368 return CheckImmRange(11 + 26, 0,
true,
true,
true);
370 bool iss11_1Imm()
const {
371 return CheckImmRange(11 + 26, 1,
true,
true,
true);
373 bool iss11_2Imm()
const {
374 return CheckImmRange(11 + 26, 2,
true,
true,
true);
376 bool iss11_3Imm()
const {
377 return CheckImmRange(11 + 26, 3,
true,
true,
true);
379 bool isu32_0MustExt()
const {
return isImm(); }
381 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
382 assert(N == 1 &&
"Invalid number of operands!");
386 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
387 assert(N == 1 &&
"Invalid number of operands!");
391 void addSignedImmOperands(
MCInst &Inst,
unsigned N)
const {
392 assert(N == 1 &&
"Invalid number of operands!");
403 if ((Extended < 0) != (Value < 0))
410 void addn1ConstOperands(
MCInst &Inst,
unsigned N)
const {
411 addImmOperands(Inst, N);
415 assert(Kind == Token &&
"Invalid access!");
421 static std::unique_ptr<HexagonOperand> CreateToken(
MCContext &Context,
423 HexagonOperand *
Op =
new HexagonOperand(Token, Context);
424 Op->Tok.Data = Str.
data();
425 Op->Tok.Length = Str.
size();
428 return std::unique_ptr<HexagonOperand>(
Op);
431 static std::unique_ptr<HexagonOperand>
433 HexagonOperand *
Op =
new HexagonOperand(
Register, Context);
434 Op->Reg.RegNum = RegNum;
437 return std::unique_ptr<HexagonOperand>(
Op);
440 static std::unique_ptr<HexagonOperand>
442 HexagonOperand *
Op =
new HexagonOperand(Immediate, Context);
446 return std::unique_ptr<HexagonOperand>(
Op);
455 getImm()->print(OS,
nullptr);
493 Error(IDLoc,
"invalid instruction packet: out of slots");
501 bool HexagonAsmParser::matchBundleOptions() {
507 char const *MemNoShuffMsg =
508 "invalid instruction packet: mem_noshuf specifier not " 509 "supported with this architecture";
520 if (getSTI().getFeatureBits()[Hexagon::FeatureMemNoShuf])
523 return getParser().Error(IDLoc, MemNoShuffMsg);
525 return getParser().Error(IDLoc,
llvm::Twine(
"'") + Option +
526 "' is not a valid bundle option");
534 void HexagonAsmParser::canonicalizeImmediates(
MCInst &MCI) {
539 int64_t
Value(
I.getImm());
543 if (
I.isExpr() && cast<HexagonMCExpr>(
I.getExpr())->signMismatch() &&
545 Warning(MCI.getLoc(),
"Signed/Unsigned mismatch");
551 bool HexagonAsmParser::matchOneInstruction(
MCInst &MCI,
SMLoc IDLoc,
554 bool MatchingInlineAsm) {
557 MatchInstructionImpl(InstOperands, MCI, ErrorInfo, MatchingInlineAsm);
558 if (result == Match_Success) {
560 canonicalizeImmediates(MCI);
561 result = processInstruction(MCI, InstOperands, IDLoc);
579 case Match_MissingFeature:
580 return Error(IDLoc,
"invalid instruction");
581 case Match_MnemonicFail:
582 return Error(IDLoc,
"unrecognized instruction");
583 case Match_InvalidOperand:
584 SMLoc ErrorLoc = IDLoc;
585 if (ErrorInfo != ~0U) {
586 if (ErrorInfo >= InstOperands.
size())
587 return Error(IDLoc,
"too few operands for instruction");
589 ErrorLoc = (
static_cast<HexagonOperand *
>(InstOperands[ErrorInfo].get()))
591 if (ErrorLoc ==
SMLoc())
594 return Error(ErrorLoc,
"invalid operand for instruction");
599 void HexagonAsmParser::eatToEndOfPacket() {
608 bool HexagonAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
612 bool MatchingInlineAsm) {
617 HexagonOperand &FirstOperand =
static_cast<HexagonOperand &
>(*Operands[0]);
618 if (FirstOperand.isToken() && FirstOperand.getToken() ==
"{") {
619 assert(Operands.
size() == 1 &&
"Brackets should be by themselves");
621 getParser().Error(IDLoc,
"Already in a packet");
628 if (FirstOperand.isToken() && FirstOperand.getToken() ==
"}") {
629 assert(Operands.
size() == 1 &&
"Brackets should be by themselves");
631 getParser().Error(IDLoc,
"Not in a packet");
635 if (matchBundleOptions())
637 return finishBundle(IDLoc, Out);
639 MCInst *SubInst =
new (getParser().getContext())
MCInst;
640 if (matchOneInstruction(*SubInst, IDLoc, Operands, ErrorInfo,
641 MatchingInlineAsm)) {
647 getParser().getContext(), MII, MCB, *SubInst);
650 return finishBundle(IDLoc, Out);
655 bool HexagonAsmParser::ParseDirective(
AsmToken DirectiveID) {
657 if (IDVal.
lower() ==
".falign")
658 return ParseDirectiveFalign(256, DirectiveID.
getLoc());
659 if ((IDVal.
lower() ==
".lcomm") || (IDVal.
lower() ==
".lcommon"))
660 return ParseDirectiveComm(
true, DirectiveID.
getLoc());
661 if ((IDVal.
lower() ==
".comm") || (IDVal.
lower() ==
".common"))
662 return ParseDirectiveComm(
false, DirectiveID.
getLoc());
663 if (IDVal.
lower() ==
".subsection")
664 return ParseDirectiveSubsection(DirectiveID.
getLoc());
668 bool HexagonAsmParser::ParseDirectiveSubsection(
SMLoc L) {
669 const MCExpr *Subsection =
nullptr;
673 "Invalid subsection directive");
674 getParser().parseExpression(Subsection);
676 if (!Subsection->evaluateAsAbsolute(Res))
677 return Error(L,
"Cannot evaluate subsection number");
680 return TokError(
"unexpected token in directive");
686 if ((Res < 0) && (Res > -8193))
690 getStreamer().SubSection(Subsection);
695 bool HexagonAsmParser::ParseDirectiveFalign(
unsigned Size,
SMLoc L) {
697 int64_t MaxBytesToFill = 15;
705 if (!getParser().parseExpression(Value)) {
708 uint64_t IntValue = MCE->
getValue();
710 return Error(ExprLoc,
"literal value out of range (256) for falign");
711 MaxBytesToFill = IntValue;
714 return Error(ExprLoc,
"not a valid expression for falign directive");
718 getTargetStreamer().emitFAlign(16, MaxBytesToFill);
730 bool HexagonAsmParser::ParseDirectiveComm(
bool IsLocal,
SMLoc Loc) {
733 if (getStreamer().hasRawTextSupport())
737 if (getParser().parseIdentifier(Name))
738 return TokError(
"expected identifier in directive");
740 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
743 return TokError(
"unexpected token in directive");
747 SMLoc SizeLoc = getLexer().getLoc();
748 if (getParser().parseAbsoluteExpression(Size))
752 SMLoc ByteAlignmentLoc;
755 ByteAlignmentLoc = getLexer().getLoc();
756 if (getParser().parseAbsoluteExpression(ByteAlignment))
759 return Error(ByteAlignmentLoc,
"alignment must be a power of 2");
762 int64_t AccessAlignment = 0;
766 SMLoc AccessAlignmentLoc;
768 AccessAlignmentLoc = getLexer().getLoc();
769 if (getParser().parseAbsoluteExpression(AccessAlignment))
773 return Error(AccessAlignmentLoc,
"access alignment must be a power of 2");
777 return TokError(
"unexpected token in '.comm' or '.lcomm' directive");
784 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't " 785 "be less than zero");
790 if (ByteAlignment < 0)
791 return Error(ByteAlignmentLoc,
"invalid '.comm' or '.lcomm' directive " 792 "alignment, can't be less than zero");
795 return Error(Loc,
"invalid symbol redefinition");
811 bool HexagonAsmParser::RegisterMatchesArch(
unsigned MatchNum)
const {
812 if (HexagonMCRegisterClasses[Hexagon::V62RegsRegClassID].
contains(MatchNum))
813 if (!getSTI().getFeatureBits()[Hexagon::ArchV62])
825 #define GET_MATCHER_IMPLEMENTATION 826 #define GET_REGISTER_MATCHER 827 #include "HexagonGenAsmMatcher.inc" 831 if (Index >= Operands.
size())
836 return static_cast<HexagonOperand &
>(Operand).
getToken().equals_lower(String);
847 bool HexagonAsmParser::splitIdentifier(
OperandVector &Operands) {
848 AsmToken const &Token = getParser().getTok();
853 std::pair<StringRef, StringRef> HeadTail = String.
split(
'.');
854 if (!HeadTail.first.empty())
856 HexagonOperand::CreateToken(getContext(), HeadTail.first, Loc));
857 if (!HeadTail.second.empty())
858 Operands.
push_back(HexagonOperand::CreateToken(
859 getContext(), String.
substr(HeadTail.first.size(), 1), Loc));
860 String = HeadTail.second;
861 }
while (!String.
empty());
865 bool HexagonAsmParser::parseOperand(
OperandVector &Operands) {
870 if (!ParseRegister(Register, Begin, End)) {
881 Warning(Begin,
"Missing parenthesis around predicate register");
882 static char const *LParen =
"(";
883 static char const *RParen =
")";
885 HexagonOperand::CreateToken(getContext(), LParen, Begin));
887 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
891 splitIdentifier(Operands);
893 HexagonOperand::CreateToken(getContext(), RParen, Begin));
899 Warning(Begin,
"Missing parenthesis around predicate register");
900 static char const *LParen =
"(";
901 static char const *RParen =
")";
902 Operands.
insert(Operands.
end() - 1, HexagonOperand::CreateToken(
903 getContext(), LParen, Begin));
905 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
909 splitIdentifier(Operands);
911 HexagonOperand::CreateToken(getContext(), RParen, Begin));
917 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
920 return splitIdentifier(Operands);
923 bool HexagonAsmParser::isLabel(
AsmToken &Token) {
928 if (Token.
is(AsmToken::TokenKind::LCurly) ||
929 Token.
is(AsmToken::TokenKind::RCurly))
937 if (!matchRegister(String.
lower()))
942 std::string Collapsed = Raw;
945 std::pair<StringRef, StringRef> DotSplit = Whole.
split(
'.');
946 if (!matchRegister(DotSplit.first.lower()))
951 bool HexagonAsmParser::handleNoncontigiousRegister(
bool Contigious,
954 Error(Loc,
"Register name is not contigious");
958 Warning(Loc,
"Register name is not contigious");
962 bool HexagonAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
965 StartLoc = getLexer().getLoc();
969 bool NeededWorkaround =
false;
985 Again = (Contigious &&
Type) || (Workaround && Type);
986 NeededWorkaround = NeededWorkaround || (Again && !(Contigious &&
Type));
988 std::string Collapsed = RawString;
991 std::pair<StringRef, StringRef> DotSplit = FullString.
split(
'.');
992 unsigned DotReg = matchRegister(DotSplit.first.lower());
993 if (DotReg != Hexagon::NoRegister && RegisterMatchesArch(DotReg)) {
994 if (DotSplit.second.empty()) {
997 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1002 size_t First = RawString.find(
'.');
1003 StringRef DotString (RawString.data() + First, RawString.size() - First);
1006 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1011 std::pair<StringRef, StringRef> ColonSplit =
StringRef(FullString).
split(
':');
1012 unsigned ColonReg = matchRegister(ColonSplit.first.lower());
1013 if (ColonReg != Hexagon::NoRegister && RegisterMatchesArch(DotReg)) {
1020 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1024 while (!Lookahead.
empty()) {
1031 bool HexagonAsmParser::implicitExpressionLocation(
OperandVector &Operands) {
1045 bool HexagonAsmParser::parseExpression(
MCExpr const *&Expr) {
1049 static char const *
Comma =
",";
1054 case AsmToken::TokenKind::Hash:
1055 if (Tokens.
size() > 1)
1056 if ((Tokens.
end() - 2)->getKind() == AsmToken::TokenKind::Plus) {
1062 case AsmToken::TokenKind::RCurly:
1063 case AsmToken::TokenKind::EndOfStatement:
1071 while (!Tokens.
empty()) {
1076 return getParser().parseExpression(Expr, Loc);
1079 bool HexagonAsmParser::parseExpressionOrOperand(
OperandVector &Operands) {
1080 if (implicitExpressionLocation(Operands)) {
1083 MCExpr const *Expr =
nullptr;
1084 bool Error = parseExpression(Expr);
1088 HexagonOperand::CreateImm(getContext(), Expr, Loc, Loc));
1091 return parseOperand(Operands);
1095 bool HexagonAsmParser::parseInstruction(
OperandVector &Operands) {
1107 if (!Operands.
empty())
1109 Operands.
push_back(HexagonOperand::CreateToken(
1115 if (Operands.
empty()) {
1116 Operands.
push_back(HexagonOperand::CreateToken(
1132 Operands.
push_back(HexagonOperand::CreateToken(
1134 Operands.
push_back(HexagonOperand::CreateToken(
1140 bool MustNotExtend =
false;
1141 bool ImplicitExpression = implicitExpressionLocation(Operands);
1143 if (!ImplicitExpression)
1144 Operands.
push_back(HexagonOperand::CreateToken(
1147 bool MustExtend =
false;
1148 bool HiOnly =
false;
1149 bool LoOnly =
false;
1153 }
else if (ImplicitExpression)
1154 MustNotExtend =
true;
1158 if (String.
lower() ==
"hi") {
1160 }
else if (String.
lower() ==
"lo") {
1163 if (HiOnly || LoOnly) {
1173 MCExpr const *Expr =
nullptr;
1174 if (parseExpression(Expr))
1179 if (Expr->evaluateAsAbsolute(Value)) {
1183 if (HiOnly || LoOnly)
1191 case MCSymbolRefExpr::VariantKind::VK_TPREL:
1192 case MCSymbolRefExpr::VariantKind::VK_DTPREL:
1194 MustNotExtend = !MustExtend;
1205 std::unique_ptr<HexagonOperand> Operand =
1206 HexagonOperand::CreateImm(getContext(), Expr, ExprLoc, ExprLoc);
1213 if (parseExpressionOrOperand(Operands))
1221 getLexer().UnLex(ID);
1222 return parseInstruction(Operands);
1240 HexagonOperand *
Op =
static_cast<HexagonOperand *
>(&AsmOp);
1245 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 0
1247 : Match_InvalidOperand;
1251 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 1
1253 : Match_InvalidOperand;
1256 if (Op->Kind == HexagonOperand::Token && Kind != InvalidMatchClass) {
1258 if (matchTokenString(myStringRef.
lower()) == (MatchClassKind)
Kind)
1259 return Match_Success;
1260 if (matchTokenString(myStringRef.
upper()) == (MatchClassKind)
Kind)
1261 return Match_Success;
1268 return Match_InvalidOperand;
1272 bool HexagonAsmParser::OutOfRange(
SMLoc IDLoc,
long long Val,
long long Max) {
1275 ES <<
"value " << Val <<
"(" <<
format_hex(Val, 0) <<
") out of range: ";
1279 ES << Max <<
"-" << (-Max - 1);
1283 int HexagonAsmParser::processInstruction(
MCInst &Inst,
1288 std::string r =
"r";
1289 std::string v =
"v";
1290 std::string Colon =
":";
1298 "Found pseudo instruction with no expansion");
1304 case Hexagon::J2_trap1:
1305 if (!getSTI().getFeatureBits()[Hexagon::ArchV65]) {
1308 if (Rx.
getReg() != Hexagon::R0 || Ry.
getReg() != Hexagon::R0) {
1309 Error(IDLoc,
"trap1 can only have register r0 as operand");
1310 return Match_InvalidOperand;
1315 case Hexagon::A2_iconst: {
1327 case Hexagon::M4_mpyrr_addr:
1328 case Hexagon::S4_addi_asl_ri:
1329 case Hexagon::S4_addi_lsr_ri:
1330 case Hexagon::S4_andi_asl_ri:
1331 case Hexagon::S4_andi_lsr_ri:
1332 case Hexagon::S4_ori_asl_ri:
1333 case Hexagon::S4_ori_lsr_ri:
1334 case Hexagon::S4_or_andix:
1335 case Hexagon::S4_subi_asl_ri:
1336 case Hexagon::S4_subi_lsr_ri: {
1340 return Match_InvalidOperand;
1344 case Hexagon::C2_cmpgei: {
1354 case Hexagon::C2_cmpgeui: {
1359 assert(Success &&
"Assured by matcher");
1380 case Hexagon::A2_tfrp: {
1383 std::string R1 = r +
utostr(RegPairNum + 1);
1385 MO.
setReg(matchRegister(Reg1));
1387 std::string
R2 = r +
utostr(RegPairNum);
1394 case Hexagon::A2_tfrpt:
1395 case Hexagon::A2_tfrpf: {
1398 std::string R1 = r +
utostr(RegPairNum + 1);
1400 MO.
setReg(matchRegister(Reg1));
1402 std::string
R2 = r +
utostr(RegPairNum);
1406 ? Hexagon::C2_ccombinewt
1407 : Hexagon::C2_ccombinewf);
1410 case Hexagon::A2_tfrptnew:
1411 case Hexagon::A2_tfrpfnew: {
1414 std::string R1 = r +
utostr(RegPairNum + 1);
1416 MO.
setReg(matchRegister(Reg1));
1418 std::string
R2 = r +
utostr(RegPairNum);
1422 ? Hexagon::C2_ccombinewnewt
1423 : Hexagon::C2_ccombinewnewf);
1428 case Hexagon::V6_vassignp: {
1431 std::string R1 = v +
utostr(RegPairNum + 1);
1434 std::string
R2 = v +
utostr(RegPairNum);
1445 case Hexagon::CONST64:
1455 std::string myCharStr;
1465 std::string myImmStr =
utohexstr(static_cast<uint32_t>(Value));
1466 myCharStr =
StringRef(
".gnu.linkonce.l4.CONST_00000000")
1471 std::string myImmStr =
utohexstr(Value);
1472 myCharStr =
StringRef(
".gnu.linkonce.l8.CONST_0000000000000000")
1480 }
else if (MO_1.
isExpr()) {
1482 myCharStr =
".lita";
1489 unsigned byteSize = is32bit ? 4 : 8;
1490 getStreamer().EmitCodeAlignment(byteSize, byteSize);
1498 Sym = getContext().getOrCreateSymbol(
StringRef(myCharStr.c_str() + 16));
1500 getStreamer().EmitLabel(Sym);
1501 getStreamer().EmitSymbolAttribute(Sym,
MCSA_Global);
1502 getStreamer().EmitIntValue(Value, byteSize);
1504 }
else if (MO_1.
isExpr()) {
1505 const char *StringStart =
nullptr;
1506 const char *StringEnd =
nullptr;
1507 if (*Operands[4]->getStartLoc().getPointer() ==
'#') {
1508 StringStart = Operands[5]->getStartLoc().getPointer();
1509 StringEnd = Operands[6]->getStartLoc().getPointer();
1511 StringStart = Operands[4]->getStartLoc().getPointer();
1512 StringEnd = Operands[5]->getStartLoc().getPointer();
1515 unsigned size = StringEnd - StringStart;
1516 std::string DotConst =
".CONST_";
1517 Sym = getContext().getOrCreateSymbol(DotConst +
1522 getStreamer().EmitLabel(Sym);
1523 getStreamer().EmitSymbolAttribute(Sym,
MCSA_Local);
1524 getStreamer().EmitValue(MO_1.
getExpr(), 4);
1534 TmpInst.
setOpcode(Hexagon::L2_loadrigp);
1536 TmpInst.
setOpcode(Hexagon::L2_loadrdgp);
1547 case Hexagon::A2_tfrpi: {
1551 int sVal = (MO.
getExpr()->evaluateAsAbsolute(Value) && Value < 0) ? -1 : 0;
1559 case Hexagon::TFRI64_V4: {
1563 if (MO.
getExpr()->evaluateAsAbsolute(Value)) {
1564 int s8 =
Hi_32(Value);
1566 OutOfRange(IDLoc, s8, -128);
1584 case Hexagon::TFRI64_V2_ext: {
1589 if (MO2.
getExpr()->evaluateAsAbsolute(Value)) {
1591 if (s8 < -128 || s8 > 127)
1592 OutOfRange(IDLoc, s8, -128);
1599 case Hexagon::A4_combineii: {
1603 if (MO1.
getExpr()->evaluateAsAbsolute(Value)) {
1605 if (s8 < -128 || s8 > 127)
1606 OutOfRange(IDLoc, s8, -128);
1613 case Hexagon::S2_tableidxb_goodsyntax:
1617 case Hexagon::S2_tableidxh_goodsyntax: {
1627 TmpInst.
setOpcode(Hexagon::S2_tableidxh);
1637 case Hexagon::S2_tableidxw_goodsyntax: {
1647 TmpInst.
setOpcode(Hexagon::S2_tableidxw);
1657 case Hexagon::S2_tableidxd_goodsyntax: {
1667 TmpInst.
setOpcode(Hexagon::S2_tableidxd);
1677 case Hexagon::M2_mpyui:
1680 case Hexagon::M2_mpysmi: {
1687 bool Absolute = Expr.evaluateAsAbsolute(Value);
1691 ((Value <= -256) || Value >= 256))
1692 return Match_InvalidOperand;
1706 case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
1724 TmpInst.
setOpcode(Hexagon::S2_asr_i_r_rnd);
1735 case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
1746 std::string R1 = r +
utostr(RegPairNum + 1);
1748 Rss.
setReg(matchRegister(Reg1));
1750 std::string
R2 = r +
utostr(RegPairNum);
1752 TmpInst.
setOpcode(Hexagon::A2_combinew);
1762 Inst.
setOpcode(Hexagon::S2_asr_i_p_rnd);
1767 case Hexagon::A4_boundscheck: {
1771 Inst.
setOpcode(Hexagon::A4_boundscheck_hi);
1772 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1774 Rs.
setReg(matchRegister(RegPair));
1776 Inst.
setOpcode(Hexagon::A4_boundscheck_lo);
1777 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1779 Rs.
setReg(matchRegister(RegPair));
1784 case Hexagon::A2_addsp: {
1789 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1791 Rs.
setReg(matchRegister(RegPair));
1794 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1796 Rs.
setReg(matchRegister(RegPair));
1801 case Hexagon::M2_vrcmpys_s1: {
1805 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1_h);
1806 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1808 Rt.
setReg(matchRegister(RegPair));
1810 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1_l);
1811 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1813 Rt.
setReg(matchRegister(RegPair));
1818 case Hexagon::M2_vrcmpys_acc_s1: {
1825 TmpInst.
setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
1826 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1828 Rt.
setReg(matchRegister(RegPair));
1830 TmpInst.
setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
1831 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1833 Rt.
setReg(matchRegister(RegPair));
1844 case Hexagon::M2_vrcmpys_s1rp: {
1848 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
1849 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1851 Rt.
setReg(matchRegister(RegPair));
1853 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
1854 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1856 Rt.
setReg(matchRegister(RegPair));
1861 case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
1874 Inst.
setOpcode(Hexagon::S5_asrhub_rnd_sat);
1879 case Hexagon::S5_vasrhrnd_goodsyntax: {
1890 std::string R1 = r +
utostr(RegPairNum + 1);
1892 Rss.
setReg(matchRegister(Reg1));
1894 std::string
R2 = r +
utostr(RegPairNum);
1896 TmpInst.
setOpcode(Hexagon::A2_combinew);
1911 case Hexagon::A2_not: {
1923 case Hexagon::PS_loadrubabs:
1927 case Hexagon::PS_loadrbabs:
1931 case Hexagon::PS_loadruhabs:
1935 case Hexagon::PS_loadrhabs:
1939 case Hexagon::PS_loadriabs:
1943 case Hexagon::PS_loadrdabs:
1947 case Hexagon::PS_storerbabs:
1951 case Hexagon::PS_storerhabs:
1955 case Hexagon::PS_storerfabs:
1959 case Hexagon::PS_storeriabs:
1963 case Hexagon::PS_storerdabs:
1967 case Hexagon::PS_storerbnewabs:
1969 Inst.
setOpcode(Hexagon::S2_storerbnewgp);
1971 case Hexagon::PS_storerhnewabs:
1973 Inst.
setOpcode(Hexagon::S2_storerhnewgp);
1975 case Hexagon::PS_storerinewabs:
1977 Inst.
setOpcode(Hexagon::S2_storerinewgp);
1979 case Hexagon::A2_zxtb: {
1987 return Match_Success;
1990 unsigned HexagonAsmParser::matchRegister(
StringRef Name) {
static bool isReg(const MCInst &MI, unsigned OpNo)
static bool Check(DecodeStatus &Out, DecodeStatus In)
void push_back(const T &Elt)
const AsmToken & getTok() const
Get the current (last) lexed token.
void setMustExtend(bool Val=true)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
This represents an "assembler immediate".
virtual bool Warning(SMLoc L, const Twine &Msg, SMRange Range=None)=0
Emit a warning at the location L, with the message Msg.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
static MCOperand createExpr(const MCExpr *Val)
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
void setMustNotExtend(bool Val=true)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
virtual bool isToken() const =0
isToken - Is this a token operand?
void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ") const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
Target specific streamer interface.
constexpr bool isInt< 8 >(int64_t x)
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
void PushSection()
Save the current and previous section on the section stack.
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
bool isPseudo() const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction...
void LLVMInitializeHexagonAsmParser()
Force static initialization.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
static cl::opt< bool > WarnSignedMismatch("mwarn-sign-mismatch", cl::desc("Warn for mismatching a signed and unsigned value"), cl::init(true))
bool isOuterLoop(MCInst const &MCI)
static bool is32bit(MachineTypes Machine)
MCSymbolRefExpr::VariantKind getAccessVariant() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
return AArch64::GPR64RegClass contains(Reg)
void setInnerLoop(MCInst &MCI)
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
SMLoc getLoc() const
Get the current source location.
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Generic assembler lexer interface, for use by target specific assembly lexers.
static unsigned MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
#define HEXAGON_PACKET_SIZE
static cl::opt< bool > WarnNoncontigiousRegister("mwarn-noncontigious-register", cl::desc("Warn for register names that arent contigious"), cl::init(true))
static cl::opt< bool > ErrorMissingParenthesis("merror-missing-parenthesis", cl::desc("Error for missing parenthesis around predicate registers"), cl::init(false))
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
virtual bool printError(SMLoc L, const Twine &Msg, SMRange Range=None)=0
Emit an error at the location L, with the message Msg.
Base class for the full range of assembler expressions which are needed for parsing.
Target independent representation for an assembler token.
static bool isMem(const MachineInstr &MI, unsigned Op)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
unsigned getReg() const
Returns the register number.
void setMemReorderDisabled(MCInst &MCI)
Context object for machine code objects.
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCB, HexagonMCChecker *Checker)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
void setMustExtend(MCExpr const &Expr, bool Val=true)
const MCExpr * getExpr() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD std::string upper() const
Convert the given ASCII string to uppercase.
Instances of this class represent a single low-level machine instruction.
virtual bool hasRawTextSupport() const
Return true if this asm streamer supports emitting unformatted text to the .s file with EmitRawText...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
virtual MCContext & getContext()=0
initializer< Ty > init(const Ty &Val)
Streaming machine code generation interface.
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
MCTargetStreamer * getTargetStreamer()
The instances of the Type class are immutable: once they are created, they are never changed...
bool mustExtend(MCExpr const &Expr)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
void setSignMismatch(bool Val=true)
MCAssembler & getAssembler()
Interface to description of machine instruction set.
virtual MCAsmLexer & getLexer()=0
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
static cl::opt< bool > ErrorNoncontigiousRegister("merror-noncontigious-register", cl::desc("Error for register names that aren't contigious"), cl::init(false))
void setOuterLoop(MCInst &MCI)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool Error(SMLoc L, const Twine &Msg, SMRange Range=None)
Return an error at the location L, with the message Msg.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
bool mustNotExtend() const
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const MCBinaryExpr * createLShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
LLVM_NODISCARD int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
void HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, unsigned AccessSize)
MCStreamer & getStreamer()
void setOpcode(unsigned Op)
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
void UnLex(AsmToken const &Token)
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
const MCOperand & getOperand(unsigned i) const
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Promote Memory to Register
static bool previousIsLoop(OperandVector &Operands, size_t Index)
static bool previousEqual(OperandVector &Operands, size_t Index, StringRef String)
std::string utostr(uint64_t X, bool isNeg=false)
const AsmToken & Lex()
Consume the next token from the input stream and return it.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool is(TokenKind K) const
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
bool evaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout, const SectionAddrMap &Addrs) const
Try to evaluate the expression to an absolute value.
Base class for user error types.
iterator insert(iterator I, T &&Elt)
static MCOperand createInst(const MCInst *Val)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
void emplace_back(ArgTypes &&... Args)
MCExpr const & getExpr(MCExpr const &Expr)
LLVM_NODISCARD bool empty() const
static MCInst makeCombineInst(int opCode, MCOperand &Rdd, MCOperand &MO1, MCOperand &MO2)
static bool isSigned(Value *V)
Can the given value generate sign bits.
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
References to labels and assigned expressions.
void setMustNotExtend(MCExpr const &Expr, bool Val=true)
size_t bundleSize(MCInst const &MCI)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
void setReg(unsigned Reg)
Set the register number.
LLVM_NODISCARD std::string lower() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInnerLoop(MCInst const &MCI)
A raw_ostream that writes to an std::string.
bool PopSection()
Restore the current and previous section from the section stack.
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM Value Representation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
static unsigned MatchRegisterName(StringRef Name)
Maps from the set of all register names to a register number.
Check for a valid bundle.
This class implements an extremely fast bulk output stream that can only output to a stream...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
static cl::opt< bool > WarnMissingParenthesis("mwarn-missing-parenthesis", cl::desc("Warn for missing parenthesis around predicate registers"), cl::init(true))
Represents a location in source code.
void setS27_2_reloc(MCExpr const &Expr, bool Val=true)
unsigned getOpcode() const
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Instances of this class represent operands of the MCInst class.
static MCOperand createImm(int64_t Val)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Target & getTheHexagonTarget()
void HexagonMCEmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, unsigned AccessSize)
std::string utohexstr(uint64_t X, bool LowerCase=false)
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
TokenKind getKind() const
void setExpr(const MCExpr *Val)