9 #define DEBUG_TYPE "mcasmparser" 64 "mwarn-missing-parenthesis",
65 cl::desc(
"Warn for missing parenthesis around predicate registers"),
68 "merror-missing-parenthesis",
69 cl::desc(
"Error for missing parenthesis around predicate registers"),
72 "mwarn-sign-mismatch",
73 cl::desc(
"Warn for mismatching a signed and unsigned value"),
76 "mwarn-noncontigious-register",
79 "merror-noncontigious-register",
80 cl::desc(
"Error for register names that aren't contigious"),
85 struct HexagonOperand;
111 bool equalIsAsmAssignment()
override {
return false; }
112 bool isLabel(
AsmToken &Token)
override;
116 bool ParseDirectiveFalign(
unsigned Size,
SMLoc L);
118 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
119 bool ParseDirectiveSubsection(
SMLoc L);
120 bool ParseDirectiveComm(
bool IsLocal,
SMLoc L);
121 bool RegisterMatchesArch(
unsigned MatchNum)
const;
123 bool matchBundleOptions();
124 bool handleNoncontigiousRegister(
bool Contigious,
SMLoc &Loc);
126 void canonicalizeImmediates(
MCInst &MCI);
129 bool MatchingInlineAsm);
130 void eatToEndOfPacket();
131 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
134 bool MatchingInlineAsm)
override;
137 unsigned Kind)
override;
138 bool OutOfRange(
SMLoc IDLoc,
long long Val,
long long Max);
143 void chksetELFHeaderEFlags(
unsigned flags) {
145 getAssembler()->setELFHeaderEFlags(flags);
153 #define GET_ASSEMBLER_HEADER 154 #include "HexagonGenAsmMatcher.inc" 164 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
178 bool parseExpression(
MCExpr const *&Expr);
188 bool ParseDirective(
AsmToken DirectiveID)
override;
197 SMLoc StartLoc, EndLoc;
222 HexagonOperand(KindTy K,
MCContext &Context)
226 HexagonOperand(
const HexagonOperand &o)
229 StartLoc = o.StartLoc;
245 SMLoc getStartLoc()
const override {
return StartLoc; }
248 SMLoc getEndLoc()
const override {
return EndLoc; }
250 unsigned getReg()
const override {
255 const MCExpr *getImm()
const {
256 assert(Kind == Immediate &&
"Invalid access!");
260 bool isToken()
const override {
return Kind == Token; }
261 bool isImm()
const override {
return Kind == Immediate; }
265 bool CheckImmRange(
int immBits,
int zeroBits,
bool isSigned,
266 bool isRelocatable,
bool Extendable)
const {
267 if (Kind == Immediate) {
272 if (myMCExpr->evaluateAsAbsolute(Res)) {
273 int bits = immBits + zeroBits;
276 if (Res & ((1 << zeroBits) - 1))
279 if (Res < (1LL << (bits - 1)) && Res >= -(1LL << (bits - 1)))
285 return ((uint64_t)Res < (uint64_t)(1ULL << bits));
287 const int64_t high_bit_set = 1ULL << 63;
288 const uint64_t mask = (high_bit_set >> (63 -
bits));
289 return (((uint64_t)Res & mask) == mask);
301 bool isa30_2Imm()
const {
return CheckImmRange(30, 2,
true,
true,
true); }
302 bool isb30_2Imm()
const {
return CheckImmRange(30, 2,
true,
true,
true); }
303 bool isb15_2Imm()
const {
return CheckImmRange(15, 2,
true,
true,
false); }
304 bool isb13_2Imm()
const {
return CheckImmRange(13, 2,
true,
true,
false); }
306 bool ism32_0Imm()
const {
return true; }
308 bool isf32Imm()
const {
return false; }
309 bool isf64Imm()
const {
return false; }
310 bool iss32_0Imm()
const {
return true; }
311 bool iss31_1Imm()
const {
return true; }
312 bool iss30_2Imm()
const {
return true; }
313 bool iss29_3Imm()
const {
return true; }
314 bool iss27_2Imm()
const {
return CheckImmRange(27, 2,
true,
true,
false); }
315 bool iss9_0Imm()
const {
return CheckImmRange(9, 0,
true,
false,
false); }
316 bool iss8_0Imm()
const {
return CheckImmRange(8, 0,
true,
false,
false); }
317 bool iss8_0Imm64()
const {
return CheckImmRange(8, 0,
true,
true,
false); }
318 bool iss7_0Imm()
const {
return CheckImmRange(7, 0,
true,
false,
false); }
319 bool iss6_0Imm()
const {
return CheckImmRange(6, 0,
true,
false,
false); }
320 bool iss6_3Imm()
const {
return CheckImmRange(6, 3,
true,
false,
false); }
321 bool iss4_0Imm()
const {
return CheckImmRange(4, 0,
true,
false,
false); }
322 bool iss4_1Imm()
const {
return CheckImmRange(4, 1,
true,
false,
false); }
323 bool iss4_2Imm()
const {
return CheckImmRange(4, 2,
true,
false,
false); }
324 bool iss4_3Imm()
const {
return CheckImmRange(4, 3,
true,
false,
false); }
325 bool iss3_0Imm()
const {
return CheckImmRange(3, 0,
true,
false,
false); }
327 bool isu64_0Imm()
const {
return CheckImmRange(64, 0,
false,
true,
true); }
328 bool isu32_0Imm()
const {
return true; }
329 bool isu31_1Imm()
const {
return true; }
330 bool isu30_2Imm()
const {
return true; }
331 bool isu29_3Imm()
const {
return true; }
332 bool isu26_6Imm()
const {
return CheckImmRange(26, 6,
false,
true,
false); }
333 bool isu16_0Imm()
const {
return CheckImmRange(16, 0,
false,
true,
false); }
334 bool isu16_1Imm()
const {
return CheckImmRange(16, 1,
false,
true,
false); }
335 bool isu16_2Imm()
const {
return CheckImmRange(16, 2,
false,
true,
false); }
336 bool isu16_3Imm()
const {
return CheckImmRange(16, 3,
false,
true,
false); }
337 bool isu11_3Imm()
const {
return CheckImmRange(11, 3,
false,
false,
false); }
338 bool isu10_0Imm()
const {
return CheckImmRange(10, 0,
false,
false,
false); }
339 bool isu9_0Imm()
const {
return CheckImmRange(9, 0,
false,
false,
false); }
340 bool isu8_0Imm()
const {
return CheckImmRange(8, 0,
false,
false,
false); }
341 bool isu7_0Imm()
const {
return CheckImmRange(7, 0,
false,
false,
false); }
342 bool isu6_0Imm()
const {
return CheckImmRange(6, 0,
false,
false,
false); }
343 bool isu6_1Imm()
const {
return CheckImmRange(6, 1,
false,
false,
false); }
344 bool isu6_2Imm()
const {
return CheckImmRange(6, 2,
false,
false,
false); }
345 bool isu6_3Imm()
const {
return CheckImmRange(6, 3,
false,
false,
false); }
346 bool isu5_0Imm()
const {
return CheckImmRange(5, 0,
false,
false,
false); }
347 bool isu5_2Imm()
const {
return CheckImmRange(5, 2,
false,
false,
false); }
348 bool isu5_3Imm()
const {
return CheckImmRange(5, 3,
false,
false,
false); }
349 bool isu4_0Imm()
const {
return CheckImmRange(4, 0,
false,
false,
false); }
350 bool isu4_2Imm()
const {
return CheckImmRange(4, 2,
false,
false,
false); }
351 bool isu3_0Imm()
const {
return CheckImmRange(3, 0,
false,
false,
false); }
352 bool isu3_1Imm()
const {
return CheckImmRange(3, 1,
false,
false,
false); }
353 bool isu2_0Imm()
const {
return CheckImmRange(2, 0,
false,
false,
false); }
354 bool isu1_0Imm()
const {
return CheckImmRange(1, 0,
false,
false,
false); }
356 bool isn1Const()
const {
360 if (!getImm()->evaluateAsAbsolute(Value))
364 bool iss11_0Imm()
const {
365 return CheckImmRange(11 + 26, 0,
true,
true,
true);
367 bool iss11_1Imm()
const {
368 return CheckImmRange(11 + 26, 1,
true,
true,
true);
370 bool iss11_2Imm()
const {
371 return CheckImmRange(11 + 26, 2,
true,
true,
true);
373 bool iss11_3Imm()
const {
374 return CheckImmRange(11 + 26, 3,
true,
true,
true);
376 bool isu32_0MustExt()
const {
return isImm(); }
378 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
379 assert(N == 1 &&
"Invalid number of operands!");
383 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
384 assert(N == 1 &&
"Invalid number of operands!");
388 void addSignedImmOperands(
MCInst &Inst,
unsigned N)
const {
389 assert(N == 1 &&
"Invalid number of operands!");
400 if ((Extended < 0) != (Value < 0))
407 void addn1ConstOperands(
MCInst &Inst,
unsigned N)
const {
408 addImmOperands(Inst, N);
412 assert(Kind == Token &&
"Invalid access!");
418 static std::unique_ptr<HexagonOperand> CreateToken(
MCContext &Context,
420 HexagonOperand *
Op =
new HexagonOperand(Token, Context);
421 Op->Tok.Data = Str.
data();
422 Op->Tok.Length = Str.
size();
425 return std::unique_ptr<HexagonOperand>(
Op);
428 static std::unique_ptr<HexagonOperand>
430 HexagonOperand *
Op =
new HexagonOperand(
Register, Context);
431 Op->Reg.RegNum = RegNum;
434 return std::unique_ptr<HexagonOperand>(
Op);
437 static std::unique_ptr<HexagonOperand>
439 HexagonOperand *
Op =
new HexagonOperand(Immediate, Context);
443 return std::unique_ptr<HexagonOperand>(
Op);
452 getImm()->print(OS,
nullptr);
490 Error(IDLoc,
"invalid instruction packet: out of slots");
498 bool HexagonAsmParser::matchBundleOptions() {
504 char const *MemNoShuffMsg =
505 "invalid instruction packet: mem_noshuf specifier not " 506 "supported with this architecture";
517 if (getSTI().getFeatureBits()[Hexagon::FeatureMemNoShuf])
520 return getParser().Error(IDLoc, MemNoShuffMsg);
522 return getParser().Error(IDLoc,
llvm::Twine(
"'") + Option +
523 "' is not a valid bundle option");
531 void HexagonAsmParser::canonicalizeImmediates(
MCInst &MCI) {
536 int64_t
Value(
I.getImm());
540 if (
I.isExpr() && cast<HexagonMCExpr>(
I.getExpr())->signMismatch() &&
542 Warning(MCI.getLoc(),
"Signed/Unsigned mismatch");
548 bool HexagonAsmParser::matchOneInstruction(
MCInst &MCI,
SMLoc IDLoc,
551 bool MatchingInlineAsm) {
554 MatchInstructionImpl(InstOperands, MCI, ErrorInfo, MatchingInlineAsm);
555 if (result == Match_Success) {
557 canonicalizeImmediates(MCI);
558 result = processInstruction(MCI, InstOperands, IDLoc);
576 case Match_MissingFeature:
577 return Error(IDLoc,
"invalid instruction");
578 case Match_MnemonicFail:
579 return Error(IDLoc,
"unrecognized instruction");
580 case Match_InvalidOperand:
581 case Match_InvalidTiedOperand:
582 SMLoc ErrorLoc = IDLoc;
583 if (ErrorInfo != ~0U) {
584 if (ErrorInfo >= InstOperands.
size())
585 return Error(IDLoc,
"too few operands for instruction");
587 ErrorLoc = (
static_cast<HexagonOperand *
>(InstOperands[ErrorInfo].get()))
589 if (ErrorLoc ==
SMLoc())
592 return Error(ErrorLoc,
"invalid operand for instruction");
597 void HexagonAsmParser::eatToEndOfPacket() {
606 bool HexagonAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
610 bool MatchingInlineAsm) {
615 HexagonOperand &FirstOperand =
static_cast<HexagonOperand &
>(*Operands[0]);
616 if (FirstOperand.isToken() && FirstOperand.getToken() ==
"{") {
617 assert(Operands.
size() == 1 &&
"Brackets should be by themselves");
619 getParser().Error(IDLoc,
"Already in a packet");
626 if (FirstOperand.isToken() && FirstOperand.getToken() ==
"}") {
627 assert(Operands.
size() == 1 &&
"Brackets should be by themselves");
629 getParser().Error(IDLoc,
"Not in a packet");
633 if (matchBundleOptions())
635 return finishBundle(IDLoc, Out);
637 MCInst *SubInst =
new (getParser().getContext())
MCInst;
638 if (matchOneInstruction(*SubInst, IDLoc, Operands, ErrorInfo,
639 MatchingInlineAsm)) {
645 getParser().getContext(), MII, MCB, *SubInst);
648 return finishBundle(IDLoc, Out);
653 bool HexagonAsmParser::ParseDirective(
AsmToken DirectiveID) {
655 if (IDVal.
lower() ==
".falign")
656 return ParseDirectiveFalign(256, DirectiveID.
getLoc());
657 if ((IDVal.
lower() ==
".lcomm") || (IDVal.
lower() ==
".lcommon"))
658 return ParseDirectiveComm(
true, DirectiveID.
getLoc());
659 if ((IDVal.
lower() ==
".comm") || (IDVal.
lower() ==
".common"))
660 return ParseDirectiveComm(
false, DirectiveID.
getLoc());
661 if (IDVal.
lower() ==
".subsection")
662 return ParseDirectiveSubsection(DirectiveID.
getLoc());
666 bool HexagonAsmParser::ParseDirectiveSubsection(
SMLoc L) {
667 const MCExpr *Subsection =
nullptr;
671 "Invalid subsection directive");
672 getParser().parseExpression(Subsection);
674 if (!Subsection->evaluateAsAbsolute(Res))
675 return Error(L,
"Cannot evaluate subsection number");
678 return TokError(
"unexpected token in directive");
684 if ((Res < 0) && (Res > -8193))
688 getStreamer().SubSection(Subsection);
693 bool HexagonAsmParser::ParseDirectiveFalign(
unsigned Size,
SMLoc L) {
695 int64_t MaxBytesToFill = 15;
703 if (!getParser().parseExpression(Value)) {
705 auto *MCE = cast<MCConstantExpr>(
Value);
706 uint64_t IntValue = MCE->getValue();
708 return Error(ExprLoc,
"literal value out of range (256) for falign");
709 MaxBytesToFill = IntValue;
712 return Error(ExprLoc,
"not a valid expression for falign directive");
716 getTargetStreamer().emitFAlign(16, MaxBytesToFill);
728 bool HexagonAsmParser::ParseDirectiveComm(
bool IsLocal,
SMLoc Loc) {
731 if (getStreamer().hasRawTextSupport())
735 if (getParser().parseIdentifier(Name))
736 return TokError(
"expected identifier in directive");
738 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
741 return TokError(
"unexpected token in directive");
745 SMLoc SizeLoc = getLexer().getLoc();
746 if (getParser().parseAbsoluteExpression(Size))
750 SMLoc ByteAlignmentLoc;
753 ByteAlignmentLoc = getLexer().getLoc();
754 if (getParser().parseAbsoluteExpression(ByteAlignment))
757 return Error(ByteAlignmentLoc,
"alignment must be a power of 2");
760 int64_t AccessAlignment = 0;
764 SMLoc AccessAlignmentLoc;
766 AccessAlignmentLoc = getLexer().getLoc();
767 if (getParser().parseAbsoluteExpression(AccessAlignment))
771 return Error(AccessAlignmentLoc,
"access alignment must be a power of 2");
775 return TokError(
"unexpected token in '.comm' or '.lcomm' directive");
782 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't " 783 "be less than zero");
788 if (ByteAlignment < 0)
789 return Error(ByteAlignmentLoc,
"invalid '.comm' or '.lcomm' directive " 790 "alignment, can't be less than zero");
793 return Error(Loc,
"invalid symbol redefinition");
809 bool HexagonAsmParser::RegisterMatchesArch(
unsigned MatchNum)
const {
810 if (HexagonMCRegisterClasses[Hexagon::V62RegsRegClassID].
contains(MatchNum))
811 if (!getSTI().getFeatureBits()[Hexagon::ArchV62])
823 #define GET_MATCHER_IMPLEMENTATION 824 #define GET_REGISTER_MATCHER 825 #include "HexagonGenAsmMatcher.inc" 829 if (Index >= Operands.
size())
834 return static_cast<HexagonOperand &
>(Operand).
getToken().equals_lower(String);
845 bool HexagonAsmParser::splitIdentifier(
OperandVector &Operands) {
846 AsmToken const &Token = getParser().getTok();
851 std::pair<StringRef, StringRef> HeadTail = String.
split(
'.');
852 if (!HeadTail.first.empty())
854 HexagonOperand::CreateToken(getContext(), HeadTail.first, Loc));
855 if (!HeadTail.second.empty())
856 Operands.
push_back(HexagonOperand::CreateToken(
857 getContext(), String.
substr(HeadTail.first.size(), 1), Loc));
858 String = HeadTail.second;
859 }
while (!String.
empty());
863 bool HexagonAsmParser::parseOperand(
OperandVector &Operands) {
868 if (!ParseRegister(Register, Begin, End)) {
879 Warning(Begin,
"Missing parenthesis around predicate register");
880 static char const *LParen =
"(";
881 static char const *RParen =
")";
883 HexagonOperand::CreateToken(getContext(), LParen, Begin));
885 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
889 splitIdentifier(Operands);
891 HexagonOperand::CreateToken(getContext(), RParen, Begin));
897 Warning(Begin,
"Missing parenthesis around predicate register");
898 static char const *LParen =
"(";
899 static char const *RParen =
")";
900 Operands.
insert(Operands.
end() - 1, HexagonOperand::CreateToken(
901 getContext(), LParen, Begin));
903 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
907 splitIdentifier(Operands);
909 HexagonOperand::CreateToken(getContext(), RParen, Begin));
915 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
918 return splitIdentifier(Operands);
921 bool HexagonAsmParser::isLabel(
AsmToken &Token) {
926 if (Token.
is(AsmToken::TokenKind::LCurly) ||
927 Token.
is(AsmToken::TokenKind::RCurly))
935 if (!matchRegister(String.
lower()))
940 std::string Collapsed = Raw;
943 std::pair<StringRef, StringRef> DotSplit = Whole.
split(
'.');
944 if (!matchRegister(DotSplit.first.lower()))
949 bool HexagonAsmParser::handleNoncontigiousRegister(
bool Contigious,
952 Error(Loc,
"Register name is not contigious");
956 Warning(Loc,
"Register name is not contigious");
960 bool HexagonAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
963 StartLoc = getLexer().getLoc();
967 bool NeededWorkaround =
false;
976 Lookahead.
back().getString().data() +
977 Lookahead.
back().getString().size();
983 Again = (Contigious &&
Type) || (Workaround && Type);
984 NeededWorkaround = NeededWorkaround || (Again && !(Contigious &&
Type));
986 std::string Collapsed = RawString;
989 std::pair<StringRef, StringRef> DotSplit = FullString.
split(
'.');
990 unsigned DotReg = matchRegister(DotSplit.first.lower());
991 if (DotReg != Hexagon::NoRegister && RegisterMatchesArch(DotReg)) {
992 if (DotSplit.second.empty()) {
995 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1000 size_t First = RawString.find(
'.');
1001 StringRef DotString (RawString.data() + First, RawString.size() - First);
1004 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1009 std::pair<StringRef, StringRef> ColonSplit =
StringRef(FullString).
split(
':');
1010 unsigned ColonReg = matchRegister(ColonSplit.first.lower());
1011 if (ColonReg != Hexagon::NoRegister && RegisterMatchesArch(DotReg)) {
1018 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1022 while (!Lookahead.
empty()) {
1029 bool HexagonAsmParser::implicitExpressionLocation(
OperandVector &Operands) {
1043 bool HexagonAsmParser::parseExpression(
MCExpr const *&Expr) {
1047 static char const *
Comma =
",";
1051 switch (Tokens.
back().getKind()) {
1052 case AsmToken::TokenKind::Hash:
1053 if (Tokens.
size() > 1)
1054 if ((Tokens.
end() - 2)->getKind() == AsmToken::TokenKind::Plus) {
1060 case AsmToken::TokenKind::RCurly:
1061 case AsmToken::TokenKind::EndOfStatement:
1069 while (!Tokens.
empty()) {
1074 return getParser().parseExpression(Expr, Loc);
1077 bool HexagonAsmParser::parseExpressionOrOperand(
OperandVector &Operands) {
1078 if (implicitExpressionLocation(Operands)) {
1081 MCExpr const *Expr =
nullptr;
1082 bool Error = parseExpression(Expr);
1086 HexagonOperand::CreateImm(getContext(), Expr, Loc, Loc));
1089 return parseOperand(Operands);
1093 bool HexagonAsmParser::parseInstruction(
OperandVector &Operands) {
1105 if (!Operands.
empty())
1107 Operands.
push_back(HexagonOperand::CreateToken(
1113 if (Operands.
empty()) {
1114 Operands.
push_back(HexagonOperand::CreateToken(
1130 Operands.
push_back(HexagonOperand::CreateToken(
1132 Operands.
push_back(HexagonOperand::CreateToken(
1138 bool MustNotExtend =
false;
1139 bool ImplicitExpression = implicitExpressionLocation(Operands);
1141 if (!ImplicitExpression)
1142 Operands.
push_back(HexagonOperand::CreateToken(
1145 bool MustExtend =
false;
1146 bool HiOnly =
false;
1147 bool LoOnly =
false;
1151 }
else if (ImplicitExpression)
1152 MustNotExtend =
true;
1156 if (String.
lower() ==
"hi") {
1158 }
else if (String.
lower() ==
"lo") {
1161 if (HiOnly || LoOnly) {
1171 MCExpr const *Expr =
nullptr;
1172 if (parseExpression(Expr))
1177 if (Expr->evaluateAsAbsolute(Value)) {
1181 if (HiOnly || LoOnly)
1189 case MCSymbolRefExpr::VariantKind::VK_TPREL:
1190 case MCSymbolRefExpr::VariantKind::VK_DTPREL:
1192 MustNotExtend = !MustExtend;
1203 std::unique_ptr<HexagonOperand> Operand =
1204 HexagonOperand::CreateImm(getContext(), Expr, ExprLoc, ExprLoc);
1211 if (parseExpressionOrOperand(Operands))
1219 getLexer().UnLex(ID);
1220 return parseInstruction(Operands);
1238 HexagonOperand *
Op =
static_cast<HexagonOperand *
>(&AsmOp);
1243 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 0
1245 : Match_InvalidOperand;
1249 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 1
1251 : Match_InvalidOperand;
1254 if (Op->Kind == HexagonOperand::Token && Kind != InvalidMatchClass) {
1256 if (matchTokenString(myStringRef.
lower()) == (MatchClassKind)
Kind)
1257 return Match_Success;
1258 if (matchTokenString(myStringRef.
upper()) == (MatchClassKind)
Kind)
1259 return Match_Success;
1266 return Match_InvalidOperand;
1270 bool HexagonAsmParser::OutOfRange(
SMLoc IDLoc,
long long Val,
long long Max) {
1273 ES <<
"value " << Val <<
"(" <<
format_hex(Val, 0) <<
") out of range: ";
1277 ES << Max <<
"-" << (-Max - 1);
1281 int HexagonAsmParser::processInstruction(
MCInst &Inst,
1286 std::string r =
"r";
1287 std::string v =
"v";
1288 std::string Colon =
":";
1296 "Found pseudo instruction with no expansion");
1302 case Hexagon::J2_trap1:
1303 if (!getSTI().getFeatureBits()[Hexagon::ArchV65]) {
1306 if (Rx.
getReg() != Hexagon::R0 || Ry.
getReg() != Hexagon::R0) {
1307 Error(IDLoc,
"trap1 can only have register r0 as operand");
1308 return Match_InvalidOperand;
1313 case Hexagon::A2_iconst: {
1325 case Hexagon::M4_mpyrr_addr:
1326 case Hexagon::S4_addi_asl_ri:
1327 case Hexagon::S4_addi_lsr_ri:
1328 case Hexagon::S4_andi_asl_ri:
1329 case Hexagon::S4_andi_lsr_ri:
1330 case Hexagon::S4_ori_asl_ri:
1331 case Hexagon::S4_ori_lsr_ri:
1332 case Hexagon::S4_or_andix:
1333 case Hexagon::S4_subi_asl_ri:
1334 case Hexagon::S4_subi_lsr_ri: {
1338 return Match_InvalidOperand;
1342 case Hexagon::C2_cmpgei: {
1352 case Hexagon::C2_cmpgeui: {
1357 assert(Success &&
"Assured by matcher");
1378 case Hexagon::A2_tfrp: {
1381 std::string R1 = r +
utostr(RegPairNum + 1);
1383 MO.
setReg(matchRegister(Reg1));
1385 std::string
R2 = r +
utostr(RegPairNum);
1392 case Hexagon::A2_tfrpt:
1393 case Hexagon::A2_tfrpf: {
1396 std::string R1 = r +
utostr(RegPairNum + 1);
1398 MO.
setReg(matchRegister(Reg1));
1400 std::string
R2 = r +
utostr(RegPairNum);
1404 ? Hexagon::C2_ccombinewt
1405 : Hexagon::C2_ccombinewf);
1408 case Hexagon::A2_tfrptnew:
1409 case Hexagon::A2_tfrpfnew: {
1412 std::string R1 = r +
utostr(RegPairNum + 1);
1414 MO.
setReg(matchRegister(Reg1));
1416 std::string
R2 = r +
utostr(RegPairNum);
1420 ? Hexagon::C2_ccombinewnewt
1421 : Hexagon::C2_ccombinewnewf);
1426 case Hexagon::V6_vassignp: {
1429 std::string R1 = v +
utostr(RegPairNum + 1);
1432 std::string
R2 = v +
utostr(RegPairNum);
1443 case Hexagon::CONST64:
1453 std::string myCharStr;
1463 std::string myImmStr =
utohexstr(static_cast<uint32_t>(Value));
1464 myCharStr =
StringRef(
".gnu.linkonce.l4.CONST_00000000")
1469 std::string myImmStr =
utohexstr(Value);
1470 myCharStr =
StringRef(
".gnu.linkonce.l8.CONST_0000000000000000")
1478 }
else if (MO_1.
isExpr()) {
1480 myCharStr =
".lita";
1487 unsigned byteSize = is32bit ? 4 : 8;
1488 getStreamer().EmitCodeAlignment(byteSize, byteSize);
1496 Sym = getContext().getOrCreateSymbol(
StringRef(myCharStr.c_str() + 16));
1498 getStreamer().EmitLabel(Sym);
1499 getStreamer().EmitSymbolAttribute(Sym,
MCSA_Global);
1500 getStreamer().EmitIntValue(Value, byteSize);
1502 }
else if (MO_1.
isExpr()) {
1503 const char *StringStart =
nullptr;
1504 const char *StringEnd =
nullptr;
1505 if (*Operands[4]->getStartLoc().getPointer() ==
'#') {
1506 StringStart = Operands[5]->getStartLoc().getPointer();
1507 StringEnd = Operands[6]->getStartLoc().getPointer();
1509 StringStart = Operands[4]->getStartLoc().getPointer();
1510 StringEnd = Operands[5]->getStartLoc().getPointer();
1513 unsigned size = StringEnd - StringStart;
1514 std::string DotConst =
".CONST_";
1515 Sym = getContext().getOrCreateSymbol(DotConst +
1520 getStreamer().EmitLabel(Sym);
1521 getStreamer().EmitSymbolAttribute(Sym,
MCSA_Local);
1522 getStreamer().EmitValue(MO_1.
getExpr(), 4);
1532 TmpInst.
setOpcode(Hexagon::L2_loadrigp);
1534 TmpInst.
setOpcode(Hexagon::L2_loadrdgp);
1545 case Hexagon::A2_tfrpi: {
1549 int sVal = (MO.
getExpr()->evaluateAsAbsolute(Value) && Value < 0) ? -1 : 0;
1557 case Hexagon::TFRI64_V4: {
1561 if (MO.
getExpr()->evaluateAsAbsolute(Value)) {
1562 int s8 =
Hi_32(Value);
1564 OutOfRange(IDLoc, s8, -128);
1582 case Hexagon::TFRI64_V2_ext: {
1587 if (MO2.
getExpr()->evaluateAsAbsolute(Value)) {
1589 if (s8 < -128 || s8 > 127)
1590 OutOfRange(IDLoc, s8, -128);
1597 case Hexagon::A4_combineii: {
1601 if (MO1.
getExpr()->evaluateAsAbsolute(Value)) {
1603 if (s8 < -128 || s8 > 127)
1604 OutOfRange(IDLoc, s8, -128);
1611 case Hexagon::S2_tableidxb_goodsyntax:
1615 case Hexagon::S2_tableidxh_goodsyntax: {
1625 TmpInst.
setOpcode(Hexagon::S2_tableidxh);
1635 case Hexagon::S2_tableidxw_goodsyntax: {
1645 TmpInst.
setOpcode(Hexagon::S2_tableidxw);
1655 case Hexagon::S2_tableidxd_goodsyntax: {
1665 TmpInst.
setOpcode(Hexagon::S2_tableidxd);
1675 case Hexagon::M2_mpyui:
1678 case Hexagon::M2_mpysmi: {
1685 bool Absolute = Expr.evaluateAsAbsolute(Value);
1687 return Match_InvalidOperand;
1689 ((Value <= -256) || Value >= 256))
1690 return Match_InvalidOperand;
1704 case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
1710 return Match_InvalidOperand;
1722 TmpInst.
setOpcode(Hexagon::S2_asr_i_r_rnd);
1733 case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
1740 return Match_InvalidOperand;
1744 std::string R1 = r +
utostr(RegPairNum + 1);
1746 Rss.
setReg(matchRegister(Reg1));
1748 std::string
R2 = r +
utostr(RegPairNum);
1750 TmpInst.
setOpcode(Hexagon::A2_combinew);
1760 Inst.
setOpcode(Hexagon::S2_asr_i_p_rnd);
1765 case Hexagon::A4_boundscheck: {
1769 Inst.
setOpcode(Hexagon::A4_boundscheck_hi);
1770 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1772 Rs.
setReg(matchRegister(RegPair));
1774 Inst.
setOpcode(Hexagon::A4_boundscheck_lo);
1775 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1777 Rs.
setReg(matchRegister(RegPair));
1782 case Hexagon::A2_addsp: {
1787 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1789 Rs.
setReg(matchRegister(RegPair));
1792 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1794 Rs.
setReg(matchRegister(RegPair));
1799 case Hexagon::M2_vrcmpys_s1: {
1803 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1_h);
1804 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1806 Rt.
setReg(matchRegister(RegPair));
1808 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1_l);
1809 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1811 Rt.
setReg(matchRegister(RegPair));
1816 case Hexagon::M2_vrcmpys_acc_s1: {
1823 TmpInst.
setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
1824 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1826 Rt.
setReg(matchRegister(RegPair));
1828 TmpInst.
setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
1829 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1831 Rt.
setReg(matchRegister(RegPair));
1842 case Hexagon::M2_vrcmpys_s1rp: {
1846 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
1847 std::string Name = r +
utostr(RegNum) + Colon +
utostr(RegNum - 1);
1849 Rt.
setReg(matchRegister(RegPair));
1851 Inst.
setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
1852 std::string Name = r +
utostr(RegNum + 1) + Colon +
utostr(RegNum);
1854 Rt.
setReg(matchRegister(RegPair));
1859 case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
1864 return Match_InvalidOperand;
1872 Inst.
setOpcode(Hexagon::S5_asrhub_rnd_sat);
1877 case Hexagon::S5_vasrhrnd_goodsyntax: {
1884 return Match_InvalidOperand;
1888 std::string R1 = r +
utostr(RegPairNum + 1);
1890 Rss.
setReg(matchRegister(Reg1));
1892 std::string
R2 = r +
utostr(RegPairNum);
1894 TmpInst.
setOpcode(Hexagon::A2_combinew);
1909 case Hexagon::A2_not: {
1921 case Hexagon::PS_loadrubabs:
1925 case Hexagon::PS_loadrbabs:
1929 case Hexagon::PS_loadruhabs:
1933 case Hexagon::PS_loadrhabs:
1937 case Hexagon::PS_loadriabs:
1941 case Hexagon::PS_loadrdabs:
1945 case Hexagon::PS_storerbabs:
1949 case Hexagon::PS_storerhabs:
1953 case Hexagon::PS_storerfabs:
1957 case Hexagon::PS_storeriabs:
1961 case Hexagon::PS_storerdabs:
1965 case Hexagon::PS_storerbnewabs:
1967 Inst.
setOpcode(Hexagon::S2_storerbnewgp);
1969 case Hexagon::PS_storerhnewabs:
1971 Inst.
setOpcode(Hexagon::S2_storerhnewgp);
1973 case Hexagon::PS_storerinewabs:
1975 Inst.
setOpcode(Hexagon::S2_storerinewgp);
1977 case Hexagon::A2_zxtb: {
1985 return Match_Success;
1988 unsigned HexagonAsmParser::matchRegister(
StringRef Name) {
static bool isReg(const MCInst &MI, unsigned OpNo)
static bool Check(DecodeStatus &Out, DecodeStatus In)
reference emplace_back(ArgTypes &&... Args)
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.
This class represents lattice values for constants.
static unsigned MatchRegisterName(StringRef Name)
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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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)
void push_back(const T &Elt)
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...
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
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
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 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.
mir Rename Register Operands
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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_EXTERNAL_VISIBILITY void LLVMInitializeHexagonAsmParser()
Force static initialization.
LLVM_NODISCARD size_t size() const
size - Get the string size.
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 std::string upper() const
Convert the given ASCII string to uppercase.
Analysis containing CSE Info
Instances of this class represent a single low-level machine instruction.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
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...
uint16_t getEncodingValue(MCRegister RegNo) const
Returns the encoding for RegNo.
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)
static unsigned MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
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)
#define LLVM_EXTERNAL_VISIBILITY
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)
MCExpr const & getExpr(MCExpr const &Expr)
LLVM_NODISCARD bool empty() const
static MCInst makeCombineInst(int opCode, MCOperand &Rdd, MCOperand &MO1, MCOperand &MO2)
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
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
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
#define HEXAGON_PACKET_SIZE
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM Value Representation.
LLVM_NODISCARD StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Lightweight error class with error context and mandatory checking.
Check for a valid bundle.
This class implements an extremely fast bulk output stream that can only output to a stream...
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)
Target & getTheHexagonTarget()
Wrapper class representing virtual and physical registers.
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)