10 #define DEBUG_TYPE "mcasmparser"
64 cl::desc(
"Enable future registers"));
67 "mwarn-missing-parenthesis",
68 cl::desc(
"Warn for missing parenthesis around predicate registers"),
71 "merror-missing-parenthesis",
72 cl::desc(
"Error for missing parenthesis around predicate registers"),
75 "mwarn-sign-mismatch",
76 cl::desc(
"Warn for mismatching a signed and unsigned value"),
79 "mwarn-noncontigious-register",
82 "merror-noncontigious-register",
83 cl::desc(
"Error for register names that aren't contigious"),
88 struct HexagonOperand;
104 MCAssembler *getAssembler()
const {
return Assembler; }
105 MCAsmLexer &getLexer()
const {
return Parser.getLexer(); }
107 bool equalIsAsmAssignment()
override {
return false; }
108 bool isLabel(
AsmToken &Token)
override;
110 void Warning(
SMLoc L,
const Twine &Msg) { Parser.Warning(L, Msg); }
112 bool ParseDirectiveFalign(
unsigned Size,
SMLoc L);
114 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
115 bool ParseDirectiveSubsection(
SMLoc L);
116 bool ParseDirectiveValue(
unsigned Size,
SMLoc L);
117 bool ParseDirectiveComm(
bool IsLocal,
SMLoc L);
118 bool RegisterMatchesArch(
unsigned MatchNum)
const;
120 bool matchBundleOptions();
121 bool handleNoncontigiousRegister(
bool Contigious,
SMLoc &Loc);
123 void canonicalizeImmediates(
MCInst &MCI);
126 bool MatchingInlineAsm);
128 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
131 bool MatchingInlineAsm)
override;
134 unsigned Kind)
override;
135 bool OutOfRange(
SMLoc IDLoc,
long long Val,
long long Max);
140 void chksetELFHeaderEFlags(
unsigned flags) {
142 getAssembler()->setELFHeaderEFlags(flags);
150 #define GET_ASSEMBLER_HEADER
151 #include "HexagonGenAsmMatcher.inc"
160 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
166 if (!Parser.getStreamer().hasRawTextSupport()) {
177 bool parseExpression(
MCExpr const *&Expr);
187 bool ParseDirective(
AsmToken DirectiveID)
override;
195 SMLoc StartLoc, EndLoc;
225 StartLoc = o.StartLoc;
241 SMLoc getStartLoc()
const override {
return StartLoc; }
244 SMLoc getEndLoc()
const override {
return EndLoc; }
246 unsigned getReg()
const override {
251 const MCExpr *getImm()
const {
252 assert(
Kind == Immediate &&
"Invalid access!");
256 bool isToken()
const override {
return Kind == Token; }
257 bool isImm()
const override {
return Kind == Immediate; }
261 bool CheckImmRange(
int immBits,
int zeroBits,
bool isSigned,
262 bool isRelocatable,
bool Extendable)
const {
263 if (
Kind == Immediate) {
268 if (myMCExpr->evaluateAsAbsolute(Res)) {
269 int bits = immBits + zeroBits;
272 if (Res & ((1 << zeroBits) - 1))
275 if (Res < (1LL << (bits - 1)) && Res >= -(1LL << (bits - 1)))
281 return ((uint64_t)Res < (uint64_t)(1ULL << bits));
283 const int64_t high_bit_set = 1ULL << 63;
284 const uint64_t mask = (high_bit_set >> (63 -
bits));
285 return (((uint64_t)Res & mask) == mask);
297 bool isa30_2Imm()
const {
return CheckImmRange(30, 2,
true,
true,
true); }
298 bool isb30_2Imm()
const {
return CheckImmRange(30, 2,
true,
true,
true); }
299 bool isb15_2Imm()
const {
return CheckImmRange(15, 2,
true,
true,
false); }
300 bool isb13_2Imm()
const {
return CheckImmRange(13, 2,
true,
true,
false); }
302 bool ism32_0Imm()
const {
return true; }
304 bool isf32Imm()
const {
return false; }
305 bool isf64Imm()
const {
return false; }
306 bool iss32_0Imm()
const {
return true; }
307 bool iss31_1Imm()
const {
return true; }
308 bool iss30_2Imm()
const {
return true; }
309 bool iss29_3Imm()
const {
return true; }
310 bool iss27_2Imm()
const {
return CheckImmRange(27, 2,
true,
true,
false); }
311 bool iss10_0Imm()
const {
return CheckImmRange(10, 0,
true,
false,
false); }
312 bool iss10_6Imm()
const {
return CheckImmRange(10, 6,
true,
false,
false); }
313 bool iss9_0Imm()
const {
return CheckImmRange(9, 0,
true,
false,
false); }
314 bool iss8_0Imm()
const {
return CheckImmRange(8, 0,
true,
false,
false); }
315 bool iss8_0Imm64()
const {
return CheckImmRange(8, 0,
true,
true,
false); }
316 bool iss7_0Imm()
const {
return CheckImmRange(7, 0,
true,
false,
false); }
317 bool iss6_0Imm()
const {
return CheckImmRange(6, 0,
true,
false,
false); }
318 bool iss6_3Imm()
const {
return CheckImmRange(6, 3,
true,
false,
false); }
319 bool iss4_0Imm()
const {
return CheckImmRange(4, 0,
true,
false,
false); }
320 bool iss4_1Imm()
const {
return CheckImmRange(4, 1,
true,
false,
false); }
321 bool iss4_2Imm()
const {
return CheckImmRange(4, 2,
true,
false,
false); }
322 bool iss4_3Imm()
const {
return CheckImmRange(4, 3,
true,
false,
false); }
323 bool iss3_0Imm()
const {
return CheckImmRange(3, 0,
true,
false,
false); }
325 bool isu64_0Imm()
const {
return CheckImmRange(64, 0,
false,
true,
true); }
326 bool isu32_0Imm()
const {
return true; }
327 bool isu31_1Imm()
const {
return true; }
328 bool isu30_2Imm()
const {
return true; }
329 bool isu29_3Imm()
const {
return true; }
330 bool isu26_6Imm()
const {
return CheckImmRange(26, 6,
false,
true,
false); }
331 bool isu16_0Imm()
const {
return CheckImmRange(16, 0,
false,
true,
false); }
332 bool isu16_1Imm()
const {
return CheckImmRange(16, 1,
false,
true,
false); }
333 bool isu16_2Imm()
const {
return CheckImmRange(16, 2,
false,
true,
false); }
334 bool isu16_3Imm()
const {
return CheckImmRange(16, 3,
false,
true,
false); }
335 bool isu11_3Imm()
const {
return CheckImmRange(11, 3,
false,
false,
false); }
336 bool isu10_0Imm()
const {
return CheckImmRange(10, 0,
false,
false,
false); }
337 bool isu9_0Imm()
const {
return CheckImmRange(9, 0,
false,
false,
false); }
338 bool isu8_0Imm()
const {
return CheckImmRange(8, 0,
false,
false,
false); }
339 bool isu7_0Imm()
const {
return CheckImmRange(7, 0,
false,
false,
false); }
340 bool isu6_0Imm()
const {
return CheckImmRange(6, 0,
false,
false,
false); }
341 bool isu6_1Imm()
const {
return CheckImmRange(6, 1,
false,
false,
false); }
342 bool isu6_2Imm()
const {
return CheckImmRange(6, 2,
false,
false,
false); }
343 bool isu6_3Imm()
const {
return CheckImmRange(6, 3,
false,
false,
false); }
344 bool isu5_0Imm()
const {
return CheckImmRange(5, 0,
false,
false,
false); }
345 bool isu5_2Imm()
const {
return CheckImmRange(5, 2,
false,
false,
false); }
346 bool isu5_3Imm()
const {
return CheckImmRange(5, 3,
false,
false,
false); }
347 bool isu4_0Imm()
const {
return CheckImmRange(4, 0,
false,
false,
false); }
348 bool isu4_2Imm()
const {
return CheckImmRange(4, 2,
false,
false,
false); }
349 bool isu3_0Imm()
const {
return CheckImmRange(3, 0,
false,
false,
false); }
350 bool isu3_1Imm()
const {
return CheckImmRange(3, 1,
false,
false,
false); }
351 bool isu2_0Imm()
const {
return CheckImmRange(2, 0,
false,
false,
false); }
352 bool isu1_0Imm()
const {
return CheckImmRange(1, 0,
false,
false,
false); }
354 bool isn1Const()
const {
358 if (!getImm()->evaluateAsAbsolute(Value))
362 bool iss11_0Imm()
const {
363 return CheckImmRange(11 + 26, 0,
true,
true,
true);
365 bool iss11_1Imm()
const {
366 return CheckImmRange(11 + 26, 1,
true,
true,
true);
368 bool iss11_2Imm()
const {
369 return CheckImmRange(11 + 26, 2,
true,
true,
true);
371 bool iss11_3Imm()
const {
372 return CheckImmRange(11 + 26, 3,
true,
true,
true);
374 bool isu32_0MustExt()
const {
return isImm(); }
376 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
377 assert(N == 1 &&
"Invalid number of operands!");
381 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
382 assert(N == 1 &&
"Invalid number of operands!");
386 void addSignedImmOperands(
MCInst &Inst,
unsigned N)
const {
387 assert(N == 1 &&
"Invalid number of operands!");
396 if ((Extended < 0) != (Value < 0))
401 void addn1ConstOperands(
MCInst &Inst,
unsigned N)
const {
402 addImmOperands(Inst, N);
412 static std::unique_ptr<HexagonOperand> CreateToken(
StringRef Str,
SMLoc S) {
413 HexagonOperand *
Op =
new HexagonOperand(Token);
414 Op->Tok.Data = Str.
data();
415 Op->Tok.Length = Str.
size();
418 return std::unique_ptr<HexagonOperand>(
Op);
421 static std::unique_ptr<HexagonOperand> CreateReg(
unsigned RegNum,
SMLoc S,
423 HexagonOperand *Op =
new HexagonOperand(
Register);
424 Op->Reg.RegNum = RegNum;
427 return std::unique_ptr<HexagonOperand>(
Op);
430 static std::unique_ptr<HexagonOperand> CreateImm(
const MCExpr *Val,
SMLoc S,
432 HexagonOperand *Op =
new HexagonOperand(Immediate);
436 return std::unique_ptr<HexagonOperand>(
Op);
442 void HexagonOperand::print(
raw_ostream &OS)
const {
445 getImm()->print(OS,
nullptr);
483 Error(IDLoc,
"invalid instruction packet: out of slots");
491 bool HexagonAsmParser::matchBundleOptions() {
511 void HexagonAsmParser::canonicalizeImmediates(
MCInst &MCI) {
516 int64_t Value (
I.getImm());
520 if (
I.isExpr() && cast<HexagonMCExpr>(
I.getExpr())->signMismatch() &&
522 Warning (MCI.getLoc(),
"Signed/Unsigned mismatch");
528 bool HexagonAsmParser::matchOneInstruction(
MCInst &MCI,
SMLoc IDLoc,
531 bool MatchingInlineAsm) {
534 MatchInstructionImpl(InstOperands, MCI, ErrorInfo, MatchingInlineAsm);
535 if (result == Match_Success) {
537 canonicalizeImmediates(MCI);
538 result = processInstruction(MCI, InstOperands, IDLoc);
556 case Match_MissingFeature:
557 return Error(IDLoc,
"invalid instruction");
558 case Match_MnemonicFail:
559 return Error(IDLoc,
"unrecognized instruction");
560 case Match_InvalidOperand:
561 SMLoc ErrorLoc = IDLoc;
562 if (ErrorInfo != ~0U) {
563 if (ErrorInfo >= InstOperands.
size())
564 return Error(IDLoc,
"too few operands for instruction");
566 ErrorLoc = (
static_cast<HexagonOperand *
>(InstOperands[ErrorInfo].get()))
568 if (ErrorLoc ==
SMLoc())
571 return Error(ErrorLoc,
"invalid operand for instruction");
576 bool HexagonAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
580 bool MatchingInlineAsm) {
585 HexagonOperand &FirstOperand =
static_cast<HexagonOperand &
>(*Operands[0]);
586 if (FirstOperand.isToken() && FirstOperand.getToken() ==
"{") {
587 assert(Operands.
size() == 1 &&
"Brackets should be by themselves");
589 getParser().Error(IDLoc,
"Already in a packet");
595 if (FirstOperand.isToken() && FirstOperand.getToken() ==
"}") {
596 assert(Operands.
size() == 1 &&
"Brackets should be by themselves");
598 getParser().Error(IDLoc,
"Not in a packet");
602 if (matchBundleOptions())
604 return finishBundle(IDLoc, Out);
606 MCInst *SubInst =
new (getParser().getContext())
MCInst;
607 if (matchOneInstruction(*SubInst, IDLoc, Operands, ErrorInfo,
611 getParser().getContext(), MCII, MCB, *SubInst);
614 return finishBundle(IDLoc, Out);
619 bool HexagonAsmParser::ParseDirective(
AsmToken DirectiveID) {
621 if ((IDVal.
lower() ==
".word") || (IDVal.
lower() ==
".4byte"))
622 return ParseDirectiveValue(4, DirectiveID.
getLoc());
623 if (IDVal.
lower() ==
".short" || IDVal.
lower() ==
".hword" ||
624 IDVal.
lower() ==
".half")
625 return ParseDirectiveValue(2, DirectiveID.
getLoc());
626 if (IDVal.
lower() ==
".falign")
627 return ParseDirectiveFalign(256, DirectiveID.
getLoc());
628 if ((IDVal.
lower() ==
".lcomm") || (IDVal.
lower() ==
".lcommon"))
629 return ParseDirectiveComm(
true, DirectiveID.
getLoc());
630 if ((IDVal.
lower() ==
".comm") || (IDVal.
lower() ==
".common"))
631 return ParseDirectiveComm(
false, DirectiveID.
getLoc());
632 if (IDVal.
lower() ==
".subsection")
633 return ParseDirectiveSubsection(DirectiveID.
getLoc());
637 bool HexagonAsmParser::ParseDirectiveSubsection(
SMLoc L) {
638 const MCExpr *Subsection =
nullptr;
642 "Invalid subsection directive");
643 getParser().parseExpression(Subsection);
645 if (!Subsection->evaluateAsAbsolute(Res))
646 return Error(L,
"Cannot evaluate subsection number");
649 return TokError(
"unexpected token in directive");
655 if ((Res < 0) && (Res > -8193))
659 getStreamer().SubSection(Subsection);
664 bool HexagonAsmParser::ParseDirectiveFalign(
unsigned Size,
SMLoc L) {
666 int64_t MaxBytesToFill = 15;
674 if (!getParser().parseExpression(Value)) {
677 uint64_t IntValue = MCE->
getValue();
679 return Error(ExprLoc,
"literal value out of range (256) for falign");
680 MaxBytesToFill = IntValue;
683 return Error(ExprLoc,
"not a valid expression for falign directive");
687 getTargetStreamer().emitFAlign(16, MaxBytesToFill);
694 bool HexagonAsmParser::ParseDirectiveValue(
unsigned Size,
SMLoc L) {
699 if (getParser().parseExpression(Value))
703 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
704 assert(Size <= 8 &&
"Invalid size");
705 uint64_t IntValue = MCE->
getValue();
706 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
707 return Error(ExprLoc,
"literal value out of range for directive");
708 getStreamer().EmitIntValue(IntValue, Size);
710 getStreamer().EmitValue(Value, Size);
717 return TokError(
"unexpected token in directive");
732 bool HexagonAsmParser::ParseDirectiveComm(
bool IsLocal,
SMLoc Loc) {
735 if (getStreamer().hasRawTextSupport())
739 if (getParser().parseIdentifier(Name))
740 return TokError(
"expected identifier in directive");
742 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
745 return TokError(
"unexpected token in directive");
749 SMLoc SizeLoc = getLexer().getLoc();
750 if (getParser().parseAbsoluteExpression(Size))
754 SMLoc ByteAlignmentLoc;
757 ByteAlignmentLoc = getLexer().getLoc();
758 if (getParser().parseAbsoluteExpression(ByteAlignment))
761 return Error(ByteAlignmentLoc,
"alignment must be a power of 2");
764 int64_t AccessAlignment = 0;
768 SMLoc AccessAlignmentLoc;
770 AccessAlignmentLoc = getLexer().getLoc();
771 if (getParser().parseAbsoluteExpression(AccessAlignment))
775 return Error(AccessAlignmentLoc,
"access alignment must be a power of 2");
779 return TokError(
"unexpected token in '.comm' or '.lcomm' directive");
786 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't "
787 "be less than zero");
792 if (ByteAlignment < 0)
793 return Error(ByteAlignmentLoc,
"invalid '.comm' or '.lcomm' directive "
794 "alignment, can't be less than zero");
797 return Error(Loc,
"invalid symbol redefinition");
813 bool HexagonAsmParser::RegisterMatchesArch(
unsigned MatchNum)
const {
814 if (HexagonMCRegisterClasses[Hexagon::V62RegsRegClassID].
contains(MatchNum))
815 if (!getSTI().getFeatureBits()[Hexagon::ArchV62])
827 #define GET_MATCHER_IMPLEMENTATION
828 #define GET_REGISTER_MATCHER
829 #include "HexagonGenAsmMatcher.inc"
833 if (Index >= Operands.
size())
838 return static_cast<HexagonOperand &
>(Operand).
getToken().equals_lower(String);
849 bool HexagonAsmParser::splitIdentifier(
OperandVector &Operands) {
850 AsmToken const &Token = getParser().getTok();
855 std::pair<StringRef, StringRef> HeadTail = String.
split(
'.');
856 if (!HeadTail.first.empty())
857 Operands.
push_back(HexagonOperand::CreateToken(HeadTail.first, Loc));
858 if (!HeadTail.second.empty())
859 Operands.
push_back(HexagonOperand::CreateToken(
860 String.
substr(HeadTail.first.size(), 1), Loc));
861 String = HeadTail.second;
862 }
while (!String.
empty());
866 bool HexagonAsmParser::parseOperand(
OperandVector &Operands) {
871 if (!ParseRegister(Register, Begin, End)) {
882 Warning (Begin,
"Missing parenthesis around predicate register");
883 static char const *LParen =
"(";
884 static char const *RParen =
")";
885 Operands.
push_back(HexagonOperand::CreateToken(LParen, Begin));
886 Operands.
push_back(HexagonOperand::CreateReg(Register, Begin, End));
890 splitIdentifier(Operands);
891 Operands.
push_back(HexagonOperand::CreateToken(RParen, Begin));
897 Warning (Begin,
"Missing parenthesis around predicate register");
898 static char const *LParen =
"(";
899 static char const *RParen =
")";
901 HexagonOperand::CreateToken(LParen, Begin));
902 Operands.
push_back(HexagonOperand::CreateReg(Register, Begin, End));
906 splitIdentifier(Operands);
907 Operands.
push_back(HexagonOperand::CreateToken(RParen, Begin));
912 Operands.
push_back(HexagonOperand::CreateReg(
913 Register, Begin, End));
916 return splitIdentifier(Operands);
919 bool HexagonAsmParser::isLabel(
AsmToken &Token) {
924 if (Token.
is(AsmToken::TokenKind::LCurly) ||
925 Token.
is(AsmToken::TokenKind::RCurly))
933 if (!matchRegister(String.
lower()))
939 std::string Collapsed = Raw;
942 std::pair<StringRef, StringRef> DotSplit = Whole.
split(
'.');
943 if (!matchRegister(DotSplit.first.lower()))
948 bool HexagonAsmParser::handleNoncontigiousRegister(
bool Contigious,
SMLoc &Loc) {
950 Error(Loc,
"Register name is not contigious");
954 Warning(Loc,
"Register name is not contigious");
958 bool HexagonAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc) {
960 StartLoc = getLexer().getLoc();
964 bool NeededWorkaround =
false;
980 Again = (Contigious &&
Type) || (Workaround && Type);
981 NeededWorkaround = NeededWorkaround || (Again && !(Contigious &&
Type));
983 std::string Collapsed = RawString;
986 std::pair<StringRef, StringRef> DotSplit = FullString.
split(
'.');
987 unsigned DotReg = matchRegister(DotSplit.first.lower());
988 if (DotReg != Hexagon::NoRegister && RegisterMatchesArch(DotReg)) {
989 if (DotSplit.second.empty()) {
992 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
997 size_t First = RawString.find(
'.');
998 StringRef DotString (RawString.data() + First, RawString.size() - First);
1001 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1006 std::pair<StringRef, StringRef> ColonSplit =
StringRef(FullString).
split(
':');
1007 unsigned ColonReg = matchRegister(ColonSplit.first.lower());
1008 if (ColonReg != Hexagon::NoRegister && RegisterMatchesArch(DotReg)) {
1015 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1019 while (!Lookahead.
empty()) {
1026 bool HexagonAsmParser::implicitExpressionLocation(
OperandVector &Operands) {
1040 bool HexagonAsmParser::parseExpression(
MCExpr const *& Expr) {
1044 static char const *
Comma =
",";
1051 if (Tokens.
size () > 1)
1052 if ((Tokens.
end () - 2)->getKind() == AsmToken::TokenKind::Plus) {
1058 case AsmToken::TokenKind::RCurly:
1059 case AsmToken::TokenKind::EndOfStatement:
1067 while (!Tokens.
empty()) {
1071 return getParser().parseExpression(Expr);
1074 bool HexagonAsmParser::parseExpressionOrOperand(
OperandVector &Operands) {
1075 if (implicitExpressionLocation(Operands)) {
1078 MCExpr const *Expr =
nullptr;
1079 bool Error = parseExpression(Expr);
1082 Operands.
push_back(HexagonOperand::CreateImm(Expr, Loc, Loc));
1085 return parseOperand(Operands);
1089 bool HexagonAsmParser::parseInstruction(
OperandVector &Operands) {
1100 if (!Operands.
empty())
1108 if (Operands.
empty()) {
1125 Operands.
push_back(HexagonOperand::CreateToken(
1127 Operands.
push_back(HexagonOperand::CreateToken(
1133 bool MustNotExtend =
false;
1134 bool ImplicitExpression = implicitExpressionLocation(Operands);
1136 if (!ImplicitExpression)
1140 bool MustExtend =
false;
1141 bool HiOnly =
false;
1142 bool LoOnly =
false;
1146 }
else if (ImplicitExpression)
1147 MustNotExtend =
true;
1151 if (String.
lower() ==
"hi") {
1153 }
else if (String.
lower() ==
"lo") {
1156 if (HiOnly || LoOnly) {
1166 MCExpr const *Expr =
nullptr;
1167 if (parseExpression(Expr))
1172 if (Expr->evaluateAsAbsolute(Value)) {
1176 if (HiOnly || LoOnly)
1185 case MCSymbolRefExpr::VariantKind::VK_TPREL:
1186 case MCSymbolRefExpr::VariantKind::VK_DTPREL:
1188 MustNotExtend = !MustExtend;
1199 std::unique_ptr<HexagonOperand> Operand =
1200 HexagonOperand::CreateImm(Expr, ExprLoc, ExprLoc);
1207 if (parseExpressionOrOperand(Operands))
1216 getLexer().UnLex(ID);
1217 return parseInstruction(Operands);
1235 HexagonOperand *
Op =
static_cast<HexagonOperand *
>(&AsmOp);
1240 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 0
1242 : Match_InvalidOperand;
1246 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 1
1248 : Match_InvalidOperand;
1251 if (Op->Kind == HexagonOperand::Token && Kind != InvalidMatchClass) {
1253 if (matchTokenString(myStringRef.
lower()) == (MatchClassKind)
Kind)
1254 return Match_Success;
1255 if (matchTokenString(myStringRef.
upper()) == (MatchClassKind)
Kind)
1256 return Match_Success;
1263 return Match_InvalidOperand;
1267 bool HexagonAsmParser::OutOfRange(
SMLoc IDLoc,
long long Val,
long long Max) {
1270 ES <<
"value " << Val <<
"(" <<
format_hex(Val, 0) <<
") out of range: ";
1274 ES << Max <<
"-" << (-Max - 1);
1278 int HexagonAsmParser::processInstruction(
MCInst &Inst,
1281 MCContext &Context = getParser().getContext();
1283 std::string r =
"r";
1284 std::string v =
"v";
1285 std::string Colon =
":";
1292 case Hexagon::A2_iconst: {
1304 case Hexagon::M4_mpyrr_addr:
1305 case Hexagon::S4_addi_asl_ri:
1306 case Hexagon::S4_addi_lsr_ri:
1307 case Hexagon::S4_andi_asl_ri:
1308 case Hexagon::S4_andi_lsr_ri:
1309 case Hexagon::S4_ori_asl_ri:
1310 case Hexagon::S4_ori_lsr_ri:
1311 case Hexagon::S4_or_andix:
1312 case Hexagon::S4_subi_asl_ri:
1313 case Hexagon::S4_subi_lsr_ri: {
1317 return Match_InvalidOperand;
1321 case Hexagon::C2_cmpgei: {
1329 case Hexagon::C2_cmpgeui: {
1334 assert(Success &&
"Assured by matcher");
1353 case Hexagon::A2_tfrp: {
1356 std::string R1 = r +
utostr(RegPairNum + 1);
1358 MO.
setReg(matchRegister(Reg1));
1360 std::string
R2 = r +
utostr(RegPairNum);
1367 case Hexagon::A2_tfrpt:
1368 case Hexagon::A2_tfrpf: {
1371 std::string R1 = r +
utostr(RegPairNum + 1);
1373 MO.
setReg(matchRegister(Reg1));
1375 std::string R2 = r +
utostr(RegPairNum);
1379 ? Hexagon::C2_ccombinewt
1380 : Hexagon::C2_ccombinewf);
1383 case Hexagon::A2_tfrptnew:
1384 case Hexagon::A2_tfrpfnew: {
1387 std::string R1 = r +
utostr(RegPairNum + 1);
1389 MO.
setReg(matchRegister(Reg1));
1391 std::string R2 = r +
utostr(RegPairNum);
1395 ? Hexagon::C2_ccombinewnewt
1396 : Hexagon::C2_ccombinewnewf);
1401 case Hexagon::V6_vassignp: {
1404 std::string R1 = v +
utostr(RegPairNum + 1);
1407 std::string R2 = v +
utostr(RegPairNum);
1418 case Hexagon::CONST64:
1428 std::string myCharStr;
1438 std::string myImmStr =
utohexstr(static_cast<uint32_t>(Value));
1439 myCharStr =
StringRef(
".gnu.linkonce.l4.CONST_00000000")
1444 std::string myImmStr =
utohexstr(Value);
1445 myCharStr =
StringRef(
".gnu.linkonce.l8.CONST_0000000000000000")
1453 }
else if (MO_1.
isExpr()) {
1455 myCharStr =
".lita";
1462 unsigned byteSize = is32bit ? 4 : 8;
1463 getStreamer().EmitCodeAlignment(byteSize, byteSize);
1471 Sym = getContext().getOrCreateSymbol(
StringRef(myCharStr.c_str() + 16));
1473 getStreamer().EmitLabel(Sym);
1474 getStreamer().EmitSymbolAttribute(Sym,
MCSA_Global);
1475 getStreamer().EmitIntValue(Value, byteSize);
1477 }
else if (MO_1.
isExpr()) {
1478 const char *StringStart =
nullptr;
1479 const char *StringEnd =
nullptr;
1480 if (*Operands[4]->getStartLoc().getPointer() ==
'#') {
1481 StringStart = Operands[5]->getStartLoc().getPointer();
1482 StringEnd = Operands[6]->getStartLoc().getPointer();
1484 StringStart = Operands[4]->getStartLoc().getPointer();
1485 StringEnd = Operands[5]->getStartLoc().getPointer();
1488 unsigned size = StringEnd - StringStart;
1489 std::string DotConst =
".CONST_";
1490 Sym = getContext().getOrCreateSymbol(DotConst +
1495 getStreamer().EmitLabel(Sym);
1496 getStreamer().EmitSymbolAttribute(Sym,
MCSA_Local);
1497 getStreamer().EmitValue(MO_1.
getExpr(), 4);
1507 TmpInst.
setOpcode(Hexagon::L2_loadrigp);
1509 TmpInst.
setOpcode(Hexagon::L2_loadrdgp);
1520 case Hexagon::A2_tfrpi: {
1524 int sVal = (MO.
getExpr()->evaluateAsAbsolute(Value) && Value < 0) ? -1 : 0;
1532 case Hexagon::TFRI64_V4: {
1536 if (MO.
getExpr()->evaluateAsAbsolute(Value)) {
1537 int s8 =
Hi_32(Value);
1539 OutOfRange(IDLoc, s8, -128);
1556 case Hexagon::TFRI64_V2_ext: {
1561 if (MO2.
getExpr()->evaluateAsAbsolute(Value)) {
1563 if (s8 < -128 || s8 > 127)
1564 OutOfRange(IDLoc, s8, -128);
1571 case Hexagon::A4_combineii: {
1575 if (MO1.
getExpr()->evaluateAsAbsolute(Value)) {
1577 if (s8 < -128 || s8 > 127)
1578 OutOfRange(IDLoc, s8, -128);
1585 case Hexagon::S2_tableidxb_goodsyntax:
1589 case Hexagon::S2_tableidxh_goodsyntax: {
1598 TmpInst.
setOpcode(Hexagon::S2_tableidxh);
1608 case Hexagon::S2_tableidxw_goodsyntax: {
1617 TmpInst.
setOpcode(Hexagon::S2_tableidxw);
1627 case Hexagon::S2_tableidxd_goodsyntax: {
1636 TmpInst.
setOpcode(Hexagon::S2_tableidxd);
1646 case Hexagon::M2_mpyui:
1649 case Hexagon::M2_mpysmi: {
1656 bool Absolute = Expr.evaluateAsAbsolute(Value);
1667 return Match_InvalidOperand;
1672 return Match_InvalidOperand;
1681 case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
1685 bool Absolute = Imm.
getExpr()->evaluateAsAbsolute(Value);
1699 TmpInst.
setOpcode(Hexagon::S2_asr_i_r_rnd);
1710 case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
1715 bool Absolute = Imm.
getExpr()->evaluateAsAbsolute(Value);
1721 std::string R1 = r +
utostr(RegPairNum + 1);
1723 Rss.
setReg(matchRegister(Reg1));
1725 std::string R2 = r +
utostr(RegPairNum);
1727 TmpInst.
setOpcode(Hexagon::A2_combinew);
1737 Inst.
setOpcode(Hexagon::S2_asr_i_p_rnd);
1742 case Hexagon::A4_boundscheck: {
1746 Inst.
setOpcode(Hexagon::A4_boundscheck_hi);
1747 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1749 Rs.
setReg(matchRegister(RegPair));
1751 Inst.
setOpcode(Hexagon::A4_boundscheck_lo);
1752 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1754 Rs.
setReg(matchRegister(RegPair));
1759 case Hexagon::A2_addsp: {
1764 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1766 Rs.
setReg(matchRegister(RegPair));
1769 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1771 Rs.
setReg(matchRegister(RegPair));
1776 case Hexagon::M2_vrcmpys_s1: {
1780 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1_h);
1781 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1783 Rt.
setReg(matchRegister(RegPair));
1785 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1_l);
1786 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1788 Rt.
setReg(matchRegister(RegPair));
1793 case Hexagon::M2_vrcmpys_acc_s1: {
1800 TmpInst.
setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
1801 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1803 Rt.
setReg(matchRegister(RegPair));
1805 TmpInst.
setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
1806 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1808 Rt.
setReg(matchRegister(RegPair));
1819 case Hexagon::M2_vrcmpys_s1rp: {
1823 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
1824 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1826 Rt.
setReg(matchRegister(RegPair));
1828 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
1829 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1831 Rt.
setReg(matchRegister(RegPair));
1836 case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
1839 bool Absolute = Imm.
getExpr()->evaluateAsAbsolute(Value);
1849 Inst.
setOpcode(Hexagon::S5_asrhub_rnd_sat);
1854 case Hexagon::S5_vasrhrnd_goodsyntax: {
1859 bool Absolute = Imm.
getExpr()->evaluateAsAbsolute(Value);
1865 std::string R1 = r +
utostr(RegPairNum + 1);
1867 Rss.
setReg(matchRegister(Reg1));
1869 std::string R2 = r +
utostr(RegPairNum);
1871 TmpInst.
setOpcode(Hexagon::A2_combinew);
1886 case Hexagon::A2_not: {
1898 case Hexagon::PS_loadrubabs:
1902 case Hexagon::PS_loadrbabs:
1906 case Hexagon::PS_loadruhabs:
1910 case Hexagon::PS_loadrhabs:
1914 case Hexagon::PS_loadriabs:
1918 case Hexagon::PS_loadrdabs:
1922 case Hexagon::PS_storerbabs:
1926 case Hexagon::PS_storerhabs:
1930 case Hexagon::PS_storerfabs:
1934 case Hexagon::PS_storeriabs:
1938 case Hexagon::PS_storerdabs:
1942 case Hexagon::PS_storerbnewabs:
1944 Inst.
setOpcode(Hexagon::S2_storerbnewgp);
1946 case Hexagon::PS_storerhnewabs:
1948 Inst.
setOpcode(Hexagon::S2_storerhnewgp);
1950 case Hexagon::PS_storerinewabs:
1952 Inst.
setOpcode(Hexagon::S2_storerinewgp);
1954 case Hexagon::A2_zxtb: {
1961 return Match_Success;
1964 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)
LLVM_NODISCARD int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
TokenKind getKind() const
This represents an "assembler immediate".
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Generic assembler parser interface, for use by target specific assembly parsers.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
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.
virtual bool isToken() const =0
isToken - Is this a token operand?
Target specific streamer interface.
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
constexpr bool isInt< 8 >(int64_t x)
virtual bool hasRawTextSupport() const
Return true if this asm streamer supports emitting unformatted text to the .s file with EmitRawText...
void PushSection()
Save the current and previous section on the section stack.
SMLoc getLoc() const
Get the current source location.
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
void LLVMInitializeHexagonAsmParser()
Force static initialization.
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)
const AsmToken & getTok() const
Get the current (last) lexed token.
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.
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)
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.
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 ...
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.
Reg
All possible values of the reg field in the ModR/M byte.
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...
LLVM_NODISCARD bool empty() const
Context object for machine code objects.
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
unsigned getReg() const
Returns the register number.
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCB, HexagonMCChecker *Checker)
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
static std::string utostr(uint64_t X, bool isNeg=false)
void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
void setMustExtend(MCExpr const &Expr, bool Val=true)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
Instances of this class represent a single low-level machine instruction.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const MCExpr * getExpr() const
Function Alias Analysis false
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)
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()
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).
Interface to description of machine instruction set.
virtual MCAsmLexer & getLexer()=0
MCSymbolRefExpr::VariantKind getAccessVariant() const
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
static cl::opt< bool > ErrorNoncontigiousRegister("merror-noncontigious-register", cl::desc("Error for register names that aren't contigious"), cl::init(false))
static cl::opt< bool > EnableFutureRegs("mfuture-regs", cl::desc("Enable future registers"))
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
void setOuterLoop(MCInst &MCI)
static const unsigned End
MCExpr const & getExpr(MCExpr const &Expr)
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
static const MCBinaryExpr * createLShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
void HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, unsigned AccessSize)
MCStreamer & getStreamer()
void setOpcode(unsigned Op)
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
void UnLex(AsmToken const &Token)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::string upper() const
Convert the given ASCII string to uppercase.
Promote Memory to Register
static bool previousIsLoop(OperandVector &Operands, size_t Index)
bool is(TokenKind K) const
static bool previousEqual(OperandVector &Operands, size_t Index, StringRef String)
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 evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
unsigned getOpcode() const
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
Base class for user error types.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
iterator insert(iterator I, T &&Elt)
static MCOperand createInst(const MCInst *Val)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
void emplace_back(ArgTypes &&...Args)
static MCInst makeCombineInst(int opCode, MCOperand &Rdd, MCOperand &MO1, MCOperand &MO2)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
MCSubtargetInfo - 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)
bool evaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout, const SectionAddrMap &Addrs) const
Try to evaluate the expression to an absolute value.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
static std::string utohexstr(uint64_t X, bool LowerCase=false)
void setReg(unsigned Reg)
Set the register number.
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.
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM Value Representation.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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...
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).
std::string Hash(const Unit &U)
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
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.
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)
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)
LLVM_NODISCARD std::string lower() const
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
const MCOperand & getOperand(unsigned i) const
Target & getTheHexagonTarget()
void HexagonMCEmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, unsigned AccessSize)
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
void setExpr(const MCExpr *Val)