LLVM 24.0.0git
HexagonAsmParser.cpp
Go to the documentation of this file.
1//===-- HexagonAsmParser.cpp - Parse Hexagon asm to MCInst instructions----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
17#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/ADT/Twine.h"
23#include "llvm/MC/MCAssembler.h"
24#include "llvm/MC/MCContext.h"
27#include "llvm/MC/MCExpr.h"
28#include "llvm/MC/MCInst.h"
36#include "llvm/MC/MCStreamer.h"
38#include "llvm/MC/MCSymbol.h"
39#include "llvm/MC/MCValue.h"
44#include "llvm/Support/Debug.h"
46#include "llvm/Support/Format.h"
49#include "llvm/Support/SMLoc.h"
52#include <cassert>
53#include <cstddef>
54#include <cstdint>
55#include <memory>
56#include <string>
57#include <utility>
58
59#define DEBUG_TYPE "mcasmparser"
60
61using namespace llvm;
62
64 "mwarn-missing-parenthesis",
65 cl::desc("Warn for missing parenthesis around predicate registers"),
66 cl::init(true));
68 "merror-missing-parenthesis",
69 cl::desc("Error for missing parenthesis around predicate registers"),
70 cl::init(false));
72 "mwarn-sign-mismatch",
73 cl::desc("Warn for mismatching a signed and unsigned value"),
74 cl::init(false));
76 "mwarn-noncontigious-register",
77 cl::desc("Warn for register names that aren't contigious"), cl::init(true));
79 "merror-noncontigious-register",
80 cl::desc("Error for register names that aren't contigious"),
81 cl::init(false));
82static cl::opt<bool> AddBuildAttributes("hexagon-add-build-attributes");
83namespace {
84
85struct HexagonOperand;
86
87class HexagonAsmParser : public MCTargetAsmParser {
88
89 HexagonTargetStreamer &getTargetStreamer() {
91 return static_cast<HexagonTargetStreamer &>(TS);
92 }
93
94 MCAsmParser &Parser;
95 MCInst MCB;
96 bool InBrackets;
97
98 MCAsmParser &getParser() const { return Parser; }
99 MCAssembler *getAssembler() const {
100 MCAssembler *Assembler = nullptr;
101 // FIXME: need better way to detect AsmStreamer (upstream removed getKind())
102 if (!Parser.getStreamer().hasRawTextSupport()) {
103 MCELFStreamer *MES = static_cast<MCELFStreamer *>(&Parser.getStreamer());
104 Assembler = &MES->getAssembler();
105 }
106 return Assembler;
107 }
108
109 AsmLexer &getLexer() const { return Parser.getLexer(); }
110
111 bool equalIsAsmAssignment() override { return false; }
112 bool isLabel(AsmToken &Token) override;
113 bool tokenIsStartOfStatement(AsmToken::TokenKind Token) override;
114
115 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
116 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
117 bool ParseDirectiveFalign(unsigned Size, SMLoc L);
118
119 bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) override;
120 ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
121 SMLoc &EndLoc) override;
122 bool ParseDirectiveSubsection(SMLoc L);
123 bool ParseDirectiveComm(bool IsLocal, SMLoc L);
124
125 bool parseDirectiveAttribute(SMLoc L);
126
127 bool RegisterMatchesArch(MCRegister MatchNum) const;
128
129 bool matchBundleOptions();
130 bool handleNoncontigiousRegister(bool Contigious, SMLoc &Loc);
131 bool finishBundle(SMLoc IDLoc, MCStreamer &Out);
132 void canonicalizeImmediates(MCInst &MCI);
133 bool matchOneInstruction(MCInst &MCB, SMLoc IDLoc,
134 OperandVector &InstOperands, uint64_t &ErrorInfo,
135 bool MatchingInlineAsm);
136 void eatToEndOfPacket();
137 bool matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
138 OperandVector &Operands, MCStreamer &Out,
139 uint64_t &ErrorInfo,
140 bool MatchingInlineAsm) override;
141
142 unsigned validateTargetOperandClass(const MCParsedAsmOperand &Op,
143 unsigned Kind) override;
144 bool OutOfRange(SMLoc IDLoc, long long Val, long long Max);
145 int processInstruction(MCInst &Inst, OperandVector const &Operands,
146 SMLoc IDLoc);
147
148 MCRegister matchRegister(StringRef Name);
149
150 /// @name Auto-generated Match Functions
151 /// {
152
153#define GET_ASSEMBLER_HEADER
154#include "HexagonGenAsmMatcher.inc"
155
156 /// }
157
158public:
159 HexagonAsmParser(const MCSubtargetInfo &_STI, MCAsmParser &_Parser,
160 const MCInstrInfo &MII)
161 : MCTargetAsmParser(_STI, MII), Parser(_Parser), InBrackets(false) {
162 MCB.setOpcode(Hexagon::BUNDLE);
163 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
164
165 Parser.addAliasForDirective(".half", ".2byte");
166 Parser.addAliasForDirective(".hword", ".2byte");
167 Parser.addAliasForDirective(".word", ".4byte");
168
170
172 getTargetStreamer().emitTargetAttributes(*STI);
173 }
174
175 bool splitIdentifier(OperandVector &Operands);
176 bool parseOperand(OperandVector &Operands);
177 bool parseInstruction(OperandVector &Operands);
178 bool implicitExpressionLocation(OperandVector &Operands);
179 bool parseExpressionOrOperand(OperandVector &Operands);
180 bool parseExpression(MCExpr const *&Expr);
181
182 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
183 SMLoc NameLoc, OperandVector &Operands) override {
184 llvm_unreachable("Unimplemented");
185 }
186
187 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name, AsmToken ID,
188 OperandVector &Operands) override;
189
190 bool ParseDirective(AsmToken DirectiveID) override;
191};
192
193/// HexagonOperand - Instances of this class represent a parsed Hexagon machine
194/// instruction.
195struct HexagonOperand : public MCParsedAsmOperand {
196 enum KindTy { Token, Immediate, Register } Kind;
197 MCContext &Context;
198
199 SMLoc StartLoc, EndLoc;
200
201 struct TokTy {
202 const char *Data;
203 unsigned Length;
204 };
205
206 struct RegTy {
207 MCRegister RegNum;
208 };
209
210 struct ImmTy {
211 const MCExpr *Val;
212 };
213
214 union {
215 struct TokTy Tok;
216 struct RegTy Reg;
217 struct ImmTy Imm;
218 };
219
220 HexagonOperand(KindTy K, MCContext &Context) : Kind(K), Context(Context) {}
221
222public:
223 HexagonOperand(const HexagonOperand &o)
224 : MCParsedAsmOperand(), Context(o.Context) {
225 Kind = o.Kind;
226 StartLoc = o.StartLoc;
227 EndLoc = o.EndLoc;
228 switch (Kind) {
229 case Register:
230 Reg = o.Reg;
231 break;
232 case Immediate:
233 Imm = o.Imm;
234 break;
235 case Token:
236 Tok = o.Tok;
237 break;
238 }
239 }
240
241 /// getStartLoc - Get the location of the first token of this operand.
242 SMLoc getStartLoc() const override { return StartLoc; }
243
244 /// getEndLoc - Get the location of the last token of this operand.
245 SMLoc getEndLoc() const override { return EndLoc; }
246
247 MCRegister getReg() const override {
248 assert(Kind == Register && "Invalid access!");
249 return Reg.RegNum;
250 }
251
252 const MCExpr *getImm() const {
253 assert(Kind == Immediate && "Invalid access!");
254 return Imm.Val;
255 }
256
257 bool isToken() const override { return Kind == Token; }
258 bool isImm() const override { return Kind == Immediate; }
259 bool isMem() const override { llvm_unreachable("No isMem"); }
260 bool isReg() const override { return Kind == Register; }
261
262 bool CheckImmRange(int immBits, int zeroBits, bool isSigned,
263 bool isRelocatable, bool Extendable) const {
264 if (Kind == Immediate) {
265 const MCExpr *myMCExpr = &HexagonMCInstrInfo::getExpr(*getImm());
266 if (HexagonMCInstrInfo::mustExtend(*Imm.Val) && !Extendable)
267 return false;
268 int64_t Res;
269 if (myMCExpr->evaluateAsAbsolute(Res)) {
270 int bits = immBits + zeroBits;
271 // Field bit range is zerobits + bits
272 // zeroBits must be 0
273 if (Res & ((1 << zeroBits) - 1))
274 return false;
275 if (isSigned) {
276 if (Res < (1LL << (bits - 1)) && Res >= -(1LL << (bits - 1)))
277 return true;
278 } else {
279 if (bits == 64)
280 return true;
281 if (Res >= 0)
282 return ((uint64_t)Res < (uint64_t)(1ULL << bits));
283 else {
284 const int64_t high_bit_set = 1ULL << 63;
285 const uint64_t mask = (high_bit_set >> (63 - bits));
286 return (((uint64_t)Res & mask) == mask);
287 }
288 }
289 } else if (myMCExpr->getKind() == MCExpr::SymbolRef && isRelocatable)
290 return true;
291 else if (myMCExpr->getKind() == MCExpr::Binary ||
292 myMCExpr->getKind() == MCExpr::Unary)
293 return true;
294 }
295 return false;
296 }
297
298 bool isa30_2Imm() const { return CheckImmRange(30, 2, true, true, true); }
299 bool isb30_2Imm() const { return CheckImmRange(30, 2, true, true, true); }
300 bool isb15_2Imm() const { return CheckImmRange(15, 2, true, true, false); }
301 bool isb13_2Imm() const { return CheckImmRange(13, 2, true, true, false); }
302
303 bool ism32_0Imm() const { return true; }
304
305 bool isf32Imm() const { return false; }
306 bool isf64Imm() const { return false; }
307 bool iss32_0Imm() const { return true; }
308 bool iss31_1Imm() const { return true; }
309 bool iss30_2Imm() const { return true; }
310 bool iss29_3Imm() const { return true; }
311 bool iss27_2Imm() const { return CheckImmRange(27, 2, true, true, false); }
312 bool iss10_0Imm() const { return CheckImmRange(10, 0, true, false, false); }
313 bool iss10_6Imm() const { return CheckImmRange(10, 6, true, false, false); }
314 bool iss9_0Imm() const { return CheckImmRange(9, 0, true, false, false); }
315 bool iss8_0Imm() const { return CheckImmRange(8, 0, true, false, false); }
316 bool iss8_0Imm64() const { return CheckImmRange(8, 0, true, true, false); }
317 bool iss7_0Imm() const { return CheckImmRange(7, 0, true, false, false); }
318 bool iss6_0Imm() const { return CheckImmRange(6, 0, true, false, false); }
319 bool iss6_3Imm() const { return CheckImmRange(6, 3, true, false, false); }
320 bool iss5_0Imm() const { return CheckImmRange(5, 0, 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); }
326
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); }
355
356 bool isn1Const() const {
357 if (!isImm())
358 return false;
359 int64_t Value;
360 if (!getImm()->evaluateAsAbsolute(Value))
361 return false;
362 return Value == -1;
363 }
364 bool issgp10Const() const {
365 if (!isReg())
366 return false;
367 return getReg() == Hexagon::SGP1_0;
368 }
369 bool iss11_0Imm() const {
370 return CheckImmRange(11 + 26, 0, true, true, true);
371 }
372 bool iss11_1Imm() const {
373 return CheckImmRange(11 + 26, 1, true, true, true);
374 }
375 bool iss11_2Imm() const {
376 return CheckImmRange(11 + 26, 2, true, true, true);
377 }
378 bool iss11_3Imm() const {
379 return CheckImmRange(11 + 26, 3, true, true, true);
380 }
381 bool isu32_0MustExt() const { return isImm(); }
382
383 void addRegOperands(MCInst &Inst, unsigned N) const {
384 assert(N == 1 && "Invalid number of operands!");
386 }
387
388 void addImmOperands(MCInst &Inst, unsigned N) const {
389 assert(N == 1 && "Invalid number of operands!");
391 }
392
393 void addSignedImmOperands(MCInst &Inst, unsigned N) const {
394 assert(N == 1 && "Invalid number of operands!");
395 HexagonMCExpr *Expr =
396 const_cast<HexagonMCExpr *>(cast<HexagonMCExpr>(getImm()));
397 int64_t Value;
398 if (!Expr->evaluateAsAbsolute(Value)) {
400 return;
401 }
402 int64_t Extended = SignExtend64(Value, 32);
403 HexagonMCExpr *NewExpr = HexagonMCExpr::create(
404 MCConstantExpr::create(Extended, Context), Context);
405 if ((Extended < 0) != (Value < 0))
406 NewExpr->setSignMismatch();
407 NewExpr->setMustExtend(Expr->mustExtend());
408 NewExpr->setMustNotExtend(Expr->mustNotExtend());
409 Inst.addOperand(MCOperand::createExpr(NewExpr));
410 }
411
412 void addn1ConstOperands(MCInst &Inst, unsigned N) const {
413 addImmOperands(Inst, N);
414 }
415 void addsgp10ConstOperands(MCInst &Inst, unsigned N) const {
416 addRegOperands(Inst, N);
417 }
418
419 StringRef getToken() const {
420 assert(Kind == Token && "Invalid access!");
421 return StringRef(Tok.Data, Tok.Length);
422 }
423
424 void print(raw_ostream &OS, const MCAsmInfo &MAI) const override;
425
426 static std::unique_ptr<HexagonOperand> CreateToken(MCContext &Context,
427 StringRef Str, SMLoc S) {
428 HexagonOperand *Op = new HexagonOperand(Token, Context);
429 Op->Tok.Data = Str.data();
430 Op->Tok.Length = Str.size();
431 Op->StartLoc = S;
432 Op->EndLoc = S;
433 return std::unique_ptr<HexagonOperand>(Op);
434 }
435
436 static std::unique_ptr<HexagonOperand>
437 CreateReg(MCContext &Context, MCRegister Reg, SMLoc S, SMLoc E) {
438 HexagonOperand *Op = new HexagonOperand(Register, Context);
439 Op->Reg.RegNum = Reg;
440 Op->StartLoc = S;
441 Op->EndLoc = E;
442 return std::unique_ptr<HexagonOperand>(Op);
443 }
444
445 static std::unique_ptr<HexagonOperand>
446 CreateImm(MCContext &Context, const MCExpr *Val, SMLoc S, SMLoc E) {
447 HexagonOperand *Op = new HexagonOperand(Immediate, Context);
448 Op->Imm.Val = Val;
449 Op->StartLoc = S;
450 Op->EndLoc = E;
451 return std::unique_ptr<HexagonOperand>(Op);
452 }
453};
454
455} // end anonymous namespace
456
457void HexagonOperand::print(raw_ostream &OS, const MCAsmInfo &MAI) const {
458 switch (Kind) {
459 case Immediate:
460 MAI.printExpr(OS, *getImm());
461 break;
462 case Register:
463 OS << "<register R";
464 OS << getReg().id() << ">";
465 break;
466 case Token:
467 OS << "'" << getToken() << "'";
468 break;
469 }
470}
471
472bool HexagonAsmParser::finishBundle(SMLoc IDLoc, MCStreamer &Out) {
473 LLVM_DEBUG(dbgs() << "Bundle:");
475 LLVM_DEBUG(dbgs() << "--\n");
476
477 MCB.setLoc(IDLoc);
478
479 // Check the bundle for errors.
480 const MCRegisterInfo *RI = getContext().getRegisterInfo();
481 MCSubtargetInfo const &STI = getSTI();
482
483 HexagonMCChecker Check(getContext(), MII, STI, MCB, *RI, true);
484
486 MII, STI, getContext(), MCB, &Check, true);
487
488 if (CheckOk) {
489 if (HexagonMCInstrInfo::bundleSize(MCB) == 0) {
492 // Empty packets are valid yet aren't emitted
493 return false;
494 }
495
497
498 Out.emitInstruction(MCB, STI);
499 } else
500 return true; // Error
501
502 return false; // No error
503}
504
505bool HexagonAsmParser::matchBundleOptions() {
506 MCAsmParser &Parser = getParser();
507 while (true) {
508 if (!Parser.getTok().is(AsmToken::Colon))
509 return false;
510 Lex();
511 char const *MemNoShuffMsg =
512 "invalid instruction packet: mem_noshuf specifier not "
513 "supported with this architecture";
514 StringRef Option = Parser.getTok().getString();
515 auto IDLoc = Parser.getTok().getLoc();
516 if (Option.compare_insensitive("endloop01") == 0) {
519 } else if (Option.compare_insensitive("endloop0") == 0) {
521 } else if (Option.compare_insensitive("endloop1") == 0) {
523 } else if (Option.compare_insensitive("mem_noshuf") == 0) {
524 if (getSTI().hasFeature(Hexagon::FeatureMemNoShuf))
526 else
527 return getParser().Error(IDLoc, MemNoShuffMsg);
528 } else if (Option.compare_insensitive("mem_no_order") == 0) {
529 // Nothing.
530 } else
531 return getParser().Error(IDLoc, llvm::Twine("'") + Option +
532 "' is not a valid bundle option");
533 Lex();
534 }
535}
536
537// For instruction aliases, immediates are generated rather than
538// MCConstantExpr. Convert them for uniform MCExpr.
539// Also check for signed/unsigned mismatches and warn
540void HexagonAsmParser::canonicalizeImmediates(MCInst &MCI) {
541 MCInst NewInst;
542 NewInst.setOpcode(MCI.getOpcode());
543 for (MCOperand &I : MCI)
544 if (I.isImm()) {
545 int64_t Value(I.getImm());
548 } else {
549 if (I.isExpr() && cast<HexagonMCExpr>(I.getExpr())->signMismatch() &&
551 Warning(MCI.getLoc(), "Signed/Unsigned mismatch");
552 NewInst.addOperand(I);
553 }
554 MCI = NewInst;
555}
556
557bool HexagonAsmParser::matchOneInstruction(MCInst &MCI, SMLoc IDLoc,
558 OperandVector &InstOperands,
559 uint64_t &ErrorInfo,
560 bool MatchingInlineAsm) {
561 // Perform matching with tablegen asmmatcher generated function
562 int result =
563 MatchInstructionImpl(InstOperands, MCI, ErrorInfo, MatchingInlineAsm);
564 if (result == Match_Success) {
565 MCI.setLoc(IDLoc);
566 canonicalizeImmediates(MCI);
567 result = processInstruction(MCI, InstOperands, IDLoc);
568
569 LLVM_DEBUG(dbgs() << "Insn:");
571 LLVM_DEBUG(dbgs() << "\n\n");
572
573 MCI.setLoc(IDLoc);
574 }
575
576 // Create instruction operand for bundle instruction
577 // Break this into a separate function Code here is less readable
578 // Think about how to get an instruction error to report correctly.
579 // SMLoc will return the "{"
580 switch (result) {
581 default:
582 break;
583 case Match_Success:
584 return false;
585 case Match_MissingFeature:
586 return Error(IDLoc, "invalid instruction");
587 case Match_MnemonicFail:
588 return Error(IDLoc, "unrecognized instruction");
589 case Match_InvalidOperand:
590 [[fallthrough]];
591 case Match_InvalidTiedOperand:
592 SMLoc ErrorLoc = IDLoc;
593 if (ErrorInfo != ~0U) {
594 if (ErrorInfo >= InstOperands.size())
595 return Error(IDLoc, "too few operands for instruction");
596
597 ErrorLoc = (static_cast<HexagonOperand *>(InstOperands[ErrorInfo].get()))
598 ->getStartLoc();
599 if (ErrorLoc == SMLoc())
600 ErrorLoc = IDLoc;
601 }
602 return Error(ErrorLoc, "invalid operand for instruction");
603 }
604 llvm_unreachable("Implement any new match types added!");
605}
606
607void HexagonAsmParser::eatToEndOfPacket() {
608 assert(InBrackets);
609 AsmLexer &Lexer = getLexer();
610 while (Lexer.isNot(AsmToken::RCurly) && Lexer.isNot(AsmToken::Eof))
611 Lexer.Lex();
612 if (Lexer.is(AsmToken::RCurly)) {
613 Lexer.Lex();
614 InBrackets = false;
615 }
616}
617
618bool HexagonAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
620 MCStreamer &Out,
621 uint64_t &ErrorInfo,
622 bool MatchingInlineAsm) {
623 if (!InBrackets) {
624 MCB.clear();
626 }
627 HexagonOperand &FirstOperand = static_cast<HexagonOperand &>(*Operands[0]);
628 if (FirstOperand.isToken() && FirstOperand.getToken() == "{") {
629 assert(Operands.size() == 1 && "Brackets should be by themselves");
630 if (InBrackets) {
631 getParser().Error(IDLoc, "Already in a packet");
632 InBrackets = false;
633 return true;
634 }
635 InBrackets = true;
636 return false;
637 }
638 if (FirstOperand.isToken() && FirstOperand.getToken() == "}") {
639 assert(Operands.size() == 1 && "Brackets should be by themselves");
640 if (!InBrackets) {
641 getParser().Error(IDLoc, "Not in a packet");
642 return true;
643 }
644 InBrackets = false;
645 if (matchBundleOptions())
646 return true;
647 return finishBundle(IDLoc, Out);
648 }
649 MCInst *SubInst = getParser().getContext().createMCInst();
650 if (matchOneInstruction(*SubInst, IDLoc, Operands, ErrorInfo,
651 MatchingInlineAsm)) {
652 if (InBrackets)
653 eatToEndOfPacket();
654 return true;
655 }
657 getParser().getContext(), MII, MCB, *SubInst);
658 MCB.addOperand(MCOperand::createInst(SubInst));
659 if (!InBrackets)
660 return finishBundle(IDLoc, Out);
661 return false;
662}
663/// parseDirectiveAttribute
664/// ::= .attribute int, int
665/// ::= .attribute Tag_name, int
666bool HexagonAsmParser::parseDirectiveAttribute(SMLoc L) {
667 MCAsmParser &Parser = getParser();
668 int64_t Tag;
669 SMLoc TagLoc = Parser.getTok().getLoc();
670 if (Parser.getTok().is(AsmToken::Identifier)) {
671 StringRef Name = Parser.getTok().getIdentifier();
672 std::optional<unsigned> Ret = ELFAttrs::attrTypeFromString(
674 if (!Ret)
675 return Error(TagLoc, "attribute name not recognized: " + Name);
676 Tag = *Ret;
677 Parser.Lex();
678 } else {
679 const MCExpr *AttrExpr;
680
681 TagLoc = Parser.getTok().getLoc();
682 if (Parser.parseExpression(AttrExpr))
683 return true;
684
685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
686 if (check(!CE, TagLoc, "expected numeric constant"))
687 return true;
688
689 Tag = CE->getValue();
690 }
691
692 if (Parser.parseComma())
693 return true;
694
695 // We currently only have integer values.
696 int64_t IntegerValue = 0;
697 SMLoc ValueExprLoc = Parser.getTok().getLoc();
698 const MCExpr *ValueExpr;
699 if (Parser.parseExpression(ValueExpr))
700 return true;
701
702 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
703 if (!CE)
704 return Error(ValueExprLoc, "expected numeric constant");
705 IntegerValue = CE->getValue();
706
707 if (Parser.parseEOL())
708 return true;
709
710 getTargetStreamer().emitAttribute(Tag, IntegerValue);
711 return false;
712}
713
714/// ParseDirective parses the Hexagon specific directives
715bool HexagonAsmParser::ParseDirective(AsmToken DirectiveID) {
716 StringRef IDVal = DirectiveID.getIdentifier();
717 if (IDVal.lower() == ".falign")
718 return ParseDirectiveFalign(256, DirectiveID.getLoc());
719 if ((IDVal.lower() == ".lcomm") || (IDVal.lower() == ".lcommon"))
720 return ParseDirectiveComm(true, DirectiveID.getLoc());
721 if ((IDVal.lower() == ".comm") || (IDVal.lower() == ".common"))
722 return ParseDirectiveComm(false, DirectiveID.getLoc());
723 if (IDVal.lower() == ".subsection")
724 return ParseDirectiveSubsection(DirectiveID.getLoc());
725 if (IDVal == ".attribute")
726 return parseDirectiveAttribute(DirectiveID.getLoc());
727
728 return true;
729}
730bool HexagonAsmParser::ParseDirectiveSubsection(SMLoc L) {
731 const MCExpr *Subsection = nullptr;
732 int64_t Res;
733
734 assert((getLexer().isNot(AsmToken::EndOfStatement)) &&
735 "Invalid subsection directive");
736 getParser().parseExpression(Subsection);
737
738 if (!Subsection->evaluateAsAbsolute(Res))
739 return Error(L, "Cannot evaluate subsection number");
740
741 if (getLexer().isNot(AsmToken::EndOfStatement))
742 return TokError("unexpected token in directive");
743
744 // 0-8192 is the hard-coded range in MCObjectStreamper.cpp, this keeps the
745 // negative subsections together and in the same order but at the opposite
746 // end of the section. Only legacy hexagon-gcc created assembly code
747 // used negative subsections.
748 if ((Res < 0) && (Res > -8193))
749 Res += 8192;
750 getStreamer().switchSection(getStreamer().getCurrentSectionOnly(), Res);
751 return false;
752}
753
754/// ::= .falign [expression]
755bool HexagonAsmParser::ParseDirectiveFalign(unsigned Size, SMLoc L) {
756
757 int64_t MaxBytesToFill = 15;
758
759 // if there is an argument
760 if (getLexer().isNot(AsmToken::EndOfStatement)) {
761 const MCExpr *Value;
762 SMLoc ExprLoc = L;
763
764 // Make sure we have a number (false is returned if expression is a number)
765 if (!getParser().parseExpression(Value)) {
766 // Make sure this is a number that is in range
767 auto *MCE = cast<MCConstantExpr>(Value);
768 uint64_t IntValue = MCE->getValue();
769 if (!isUIntN(Size, IntValue) && !isIntN(Size, IntValue))
770 return Error(ExprLoc, "literal value out of range (256) for falign");
771 MaxBytesToFill = IntValue;
772 Lex();
773 } else {
774 return Error(ExprLoc, "not a valid expression for falign directive");
775 }
776 }
777
778 getTargetStreamer().emitFAlign(16, MaxBytesToFill);
779 Lex();
780
781 return false;
782}
783
784// This is largely a copy of AsmParser's ParseDirectiveComm extended to
785// accept a 3rd argument, AccessAlignment which indicates the smallest
786// memory access made to the symbol, expressed in bytes. If no
787// AccessAlignment is specified it defaults to the Alignment Value.
788// Hexagon's .lcomm:
789// .lcomm Symbol, Length, Alignment, AccessAlignment
790bool HexagonAsmParser::ParseDirectiveComm(bool IsLocal, SMLoc Loc) {
791 // FIXME: need better way to detect if AsmStreamer (upstream removed
792 // getKind())
793 if (getStreamer().hasRawTextSupport())
794 return true; // Only object file output requires special treatment.
795
796 StringRef Name;
797 if (getParser().parseIdentifier(Name))
798 return TokError("expected identifier in directive");
799 // Handle the identifier as the key symbol.
800 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
801
802 if (getLexer().isNot(AsmToken::Comma))
803 return TokError("unexpected token in directive");
804 Lex();
805
806 int64_t Size;
807 SMLoc SizeLoc = getLexer().getLoc();
808 if (getParser().parseAbsoluteExpression(Size))
809 return true;
810
811 int64_t ByteAlignment = 1;
812 SMLoc ByteAlignmentLoc;
813 if (getLexer().is(AsmToken::Comma)) {
814 Lex();
815 ByteAlignmentLoc = getLexer().getLoc();
816 if (getParser().parseAbsoluteExpression(ByteAlignment))
817 return true;
818 if (!isPowerOf2_64(ByteAlignment))
819 return Error(ByteAlignmentLoc, "alignment must be a power of 2");
820 }
821
822 int64_t AccessAlignment = 0;
823 if (getLexer().is(AsmToken::Comma)) {
824 // The optional access argument specifies the size of the smallest memory
825 // access to be made to the symbol, expressed in bytes.
826 SMLoc AccessAlignmentLoc;
827 Lex();
828 AccessAlignmentLoc = getLexer().getLoc();
829 if (getParser().parseAbsoluteExpression(AccessAlignment))
830 return true;
831
832 if (!isPowerOf2_64(AccessAlignment))
833 return Error(AccessAlignmentLoc, "access alignment must be a power of 2");
834 }
835
836 if (getLexer().isNot(AsmToken::EndOfStatement))
837 return TokError("unexpected token in '.comm' or '.lcomm' directive");
838
839 Lex();
840
841 // NOTE: a size of zero for a .comm should create a undefined symbol
842 // but a size of .lcomm creates a bss symbol of size zero.
843 if (Size < 0)
844 return Error(SizeLoc, "invalid '.comm' or '.lcomm' directive size, can't "
845 "be less than zero");
846
847 // NOTE: The alignment in the directive is a power of 2 value, the assembler
848 // may internally end up wanting an alignment in bytes.
849 // FIXME: Diagnose overflow.
850 if (ByteAlignment < 0)
851 return Error(ByteAlignmentLoc, "invalid '.comm' or '.lcomm' directive "
852 "alignment, can't be less than zero");
853
854 if (!Sym->isUndefined())
855 return Error(Loc, "invalid symbol redefinition");
856
857 HexagonMCELFStreamer &HexagonELFStreamer =
858 static_cast<HexagonMCELFStreamer &>(getStreamer());
859 if (IsLocal) {
860 HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol(
861 Sym, Size, Align(ByteAlignment), AccessAlignment);
862 return false;
863 }
864
865 HexagonELFStreamer.HexagonMCEmitCommonSymbol(Sym, Size, Align(ByteAlignment),
866 AccessAlignment);
867 return false;
868}
869
870// validate register against architecture
871bool HexagonAsmParser::RegisterMatchesArch(MCRegister MatchNum) const {
872 if (getHexagonMCRegisterClass(Hexagon::V62RegsRegClassID).contains(MatchNum))
873 if (!getSTI().hasFeature(Hexagon::ArchV62))
874 return false;
875 return true;
876}
877
878// extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonAsmLexer();
879
880/// Force static initialization.
885
886#define GET_MATCHER_IMPLEMENTATION
887#define GET_REGISTER_MATCHER
888#include "HexagonGenAsmMatcher.inc"
889
890static bool previousEqual(OperandVector &Operands, size_t Index,
892 if (Index >= Operands.size())
893 return false;
894 MCParsedAsmOperand &Operand = *Operands[Operands.size() - Index - 1];
895 if (!Operand.isToken())
896 return false;
897 return static_cast<HexagonOperand &>(Operand).getToken().equals_insensitive(
898 String);
899}
900
901static bool previousIsLoop(OperandVector &Operands, size_t Index) {
902 return previousEqual(Operands, Index, "loop0") ||
903 previousEqual(Operands, Index, "loop1") ||
904 previousEqual(Operands, Index, "sp1loop0") ||
905 previousEqual(Operands, Index, "sp2loop0") ||
906 previousEqual(Operands, Index, "sp3loop0");
907}
908
909bool HexagonAsmParser::splitIdentifier(OperandVector &Operands) {
910 AsmToken const &Token = getParser().getTok();
911 StringRef String = Token.getString();
912 SMLoc Loc = Token.getLoc();
913 Lex();
914 do {
915 std::pair<StringRef, StringRef> HeadTail = String.split('.');
916 if (!HeadTail.first.empty())
917 Operands.push_back(
918 HexagonOperand::CreateToken(getContext(), HeadTail.first, Loc));
919 if (!HeadTail.second.empty())
920 Operands.push_back(HexagonOperand::CreateToken(
921 getContext(), String.substr(HeadTail.first.size(), 1), Loc));
922 String = HeadTail.second;
923 } while (!String.empty());
924 return false;
925}
926
927bool HexagonAsmParser::parseOperand(OperandVector &Operands) {
928 MCRegister Register;
929 SMLoc Begin;
930 SMLoc End;
931 AsmLexer &Lexer = getLexer();
932 if (!parseRegister(Register, Begin, End)) {
934 switch (Register.id()) {
935 default:
936 break;
937 case Hexagon::P0:
938 case Hexagon::P1:
939 case Hexagon::P2:
940 case Hexagon::P3:
941 if (previousEqual(Operands, 0, "if")) {
943 Warning(Begin, "Missing parenthesis around predicate register");
944 static char const *LParen = "(";
945 static char const *RParen = ")";
946 Operands.push_back(
947 HexagonOperand::CreateToken(getContext(), LParen, Begin));
948 Operands.push_back(
949 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
950 const AsmToken &MaybeDotNew = Lexer.getTok();
951 if (MaybeDotNew.is(AsmToken::TokenKind::Identifier) &&
952 MaybeDotNew.getString().equals_insensitive(".new"))
953 splitIdentifier(Operands);
954 Operands.push_back(
955 HexagonOperand::CreateToken(getContext(), RParen, Begin));
956 return false;
957 }
958 if (previousEqual(Operands, 0, "!") &&
959 previousEqual(Operands, 1, "if")) {
961 Warning(Begin, "Missing parenthesis around predicate register");
962 static char const *LParen = "(";
963 static char const *RParen = ")";
964 Operands.insert(Operands.end() - 1, HexagonOperand::CreateToken(
965 getContext(), LParen, Begin));
966 Operands.push_back(
967 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
968 const AsmToken &MaybeDotNew = Lexer.getTok();
969 if (MaybeDotNew.is(AsmToken::TokenKind::Identifier) &&
970 MaybeDotNew.getString().equals_insensitive(".new"))
971 splitIdentifier(Operands);
972 Operands.push_back(
973 HexagonOperand::CreateToken(getContext(), RParen, Begin));
974 return false;
975 }
976 break;
977 }
978 Operands.push_back(
979 HexagonOperand::CreateReg(getContext(), Register, Begin, End));
980 return false;
981 }
982 return splitIdentifier(Operands);
983}
984
985bool HexagonAsmParser::isLabel(AsmToken &Token) {
986 AsmLexer &Lexer = getLexer();
987 AsmToken const &Second = Lexer.getTok();
988 AsmToken Third = Lexer.peekTok();
989 StringRef String = Token.getString();
990 if (Token.is(AsmToken::TokenKind::LCurly) ||
991 Token.is(AsmToken::TokenKind::RCurly))
992 return false;
993 // special case for parsing vwhist256:sat
994 if (String.lower() == "vwhist256" && Second.is(AsmToken::Colon) &&
995 Third.getString().lower() == "sat")
996 return false;
997 if (!Token.is(AsmToken::TokenKind::Identifier))
998 return true;
999 if (!matchRegister(String.lower()))
1000 return true;
1001 assert(Second.is(AsmToken::Colon));
1002 StringRef Raw(String.data(), Third.getString().data() - String.data() +
1003 Third.getString().size());
1004 std::string Collapsed = std::string(Raw);
1005 llvm::erase_if(Collapsed, isSpace);
1006 StringRef Whole = Collapsed;
1007 std::pair<StringRef, StringRef> DotSplit = Whole.split('.');
1008 if (!matchRegister(DotSplit.first.lower()))
1009 return true;
1010 return false;
1011}
1012
1013bool HexagonAsmParser::tokenIsStartOfStatement(AsmToken::TokenKind Token) {
1014 return Token == AsmToken::LCurly || Token == AsmToken::RCurly;
1015}
1016
1017bool HexagonAsmParser::handleNoncontigiousRegister(bool Contigious,
1018 SMLoc &Loc) {
1019 if (!Contigious && ErrorNoncontigiousRegister) {
1020 Error(Loc, "Register name is not contigious");
1021 return true;
1022 }
1023 if (!Contigious && WarnNoncontigiousRegister)
1024 Warning(Loc, "Register name is not contigious");
1025 return false;
1026}
1027
1028bool HexagonAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
1029 SMLoc &EndLoc) {
1030 return !tryParseRegister(Reg, StartLoc, EndLoc).isSuccess();
1031}
1032
1033ParseStatus HexagonAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
1034 SMLoc &EndLoc) {
1035 AsmLexer &Lexer = getLexer();
1036 StartLoc = getLexer().getLoc();
1037 SmallVector<AsmToken, 5> Lookahead;
1038 StringRef RawString(Lexer.getTok().getString().data(), 0);
1039 bool Again = Lexer.is(AsmToken::Identifier);
1040 bool NeededWorkaround = false;
1041 while (Again) {
1042 AsmToken const &Token = Lexer.getTok();
1043 RawString = StringRef(RawString.data(), Token.getString().data() -
1044 RawString.data() +
1045 Token.getString().size());
1046 Lookahead.push_back(Token);
1047 Lexer.Lex();
1048 bool Contigious = Lexer.getTok().getString().data() ==
1049 Lookahead.back().getString().data() +
1050 Lookahead.back().getString().size();
1051 bool Type = Lexer.is(AsmToken::Identifier) || Lexer.is(AsmToken::Dot) ||
1052 Lexer.is(AsmToken::Integer) || Lexer.is(AsmToken::Real) ||
1053 Lexer.is(AsmToken::Colon);
1054 bool Workaround =
1055 Lexer.is(AsmToken::Colon) || Lookahead.back().is(AsmToken::Colon);
1056 Again = (Contigious && Type) || (Workaround && Type);
1057 NeededWorkaround = NeededWorkaround || (Again && !(Contigious && Type));
1058 }
1059 std::string Collapsed = std::string(RawString);
1060 llvm::erase_if(Collapsed, isSpace);
1061 StringRef FullString = Collapsed;
1062 std::pair<StringRef, StringRef> DotSplit = FullString.split('.');
1063 MCRegister DotReg = matchRegister(DotSplit.first.lower());
1064 if (DotReg && RegisterMatchesArch(DotReg)) {
1065 if (DotSplit.second.empty()) {
1066 Reg = DotReg;
1067 EndLoc = Lexer.getLoc();
1068 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1069 return ParseStatus::NoMatch;
1070 return ParseStatus::Success;
1071 } else {
1072 Reg = DotReg;
1073 size_t First = RawString.find('.');
1074 StringRef DotString (RawString.data() + First, RawString.size() - First);
1075 Lexer.UnLex(AsmToken(AsmToken::Identifier, DotString));
1076 EndLoc = Lexer.getLoc();
1077 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1078 return ParseStatus::NoMatch;
1079 return ParseStatus::Success;
1080 }
1081 }
1082 std::pair<StringRef, StringRef> ColonSplit = StringRef(FullString).split(':');
1083 MCRegister ColonReg = matchRegister(ColonSplit.first.lower());
1084 if (ColonReg && RegisterMatchesArch(DotReg)) {
1085 do {
1086 Lexer.UnLex(Lookahead.pop_back_val());
1087 } while (!Lookahead.empty() && !Lexer.is(AsmToken::Colon));
1088 Reg = ColonReg;
1089 EndLoc = Lexer.getLoc();
1090 if (handleNoncontigiousRegister(!NeededWorkaround, StartLoc))
1091 return ParseStatus::NoMatch;
1092 return ParseStatus::Success;
1093 }
1094 while (!Lookahead.empty()) {
1095 Lexer.UnLex(Lookahead.pop_back_val());
1096 }
1097 return ParseStatus::NoMatch;
1098}
1099
1100bool HexagonAsmParser::implicitExpressionLocation(OperandVector &Operands) {
1101 if (previousEqual(Operands, 0, "call"))
1102 return true;
1103 if (previousEqual(Operands, 0, "jump"))
1104 if (!getLexer().getTok().is(AsmToken::Colon))
1105 return true;
1106 if (previousEqual(Operands, 0, "(") && previousIsLoop(Operands, 1))
1107 return true;
1108 if (previousEqual(Operands, 1, ":") && previousEqual(Operands, 2, "jump") &&
1109 (previousEqual(Operands, 0, "nt") || previousEqual(Operands, 0, "t")))
1110 return true;
1111 return false;
1112}
1113
1114bool HexagonAsmParser::parseExpression(MCExpr const *&Expr) {
1116 AsmLexer &Lexer = getLexer();
1117 bool Done = false;
1118 static char const *Comma = ",";
1119 do {
1120 Tokens.emplace_back(Lexer.getTok());
1121 Lex();
1122 switch (Tokens.back().getKind()) {
1123 case AsmToken::TokenKind::Hash:
1124 if (Tokens.size() > 1)
1125 if ((Tokens.end() - 2)->getKind() == AsmToken::TokenKind::Plus) {
1126 Tokens.insert(Tokens.end() - 2,
1127 AsmToken(AsmToken::TokenKind::Comma, Comma));
1128 Done = true;
1129 }
1130 break;
1131 case AsmToken::TokenKind::RCurly:
1132 case AsmToken::TokenKind::EndOfStatement:
1133 case AsmToken::TokenKind::Eof:
1134 Done = true;
1135 break;
1136 default:
1137 break;
1138 }
1139 } while (!Done);
1140 while (!Tokens.empty()) {
1141 Lexer.UnLex(Tokens.back());
1142 Tokens.pop_back();
1143 }
1144 SMLoc Loc = Lexer.getLoc();
1145 return getParser().parseExpression(Expr, Loc);
1146}
1147
1148bool HexagonAsmParser::parseExpressionOrOperand(OperandVector &Operands) {
1149 if (implicitExpressionLocation(Operands)) {
1150 MCAsmParser &Parser = getParser();
1151 SMLoc Loc = Parser.getLexer().getLoc();
1152 MCExpr const *Expr = nullptr;
1153 bool Error = parseExpression(Expr);
1154 Expr = HexagonMCExpr::create(Expr, getContext());
1155 if (!Error)
1156 Operands.push_back(
1157 HexagonOperand::CreateImm(getContext(), Expr, Loc, Loc));
1158 return Error;
1159 }
1160 return parseOperand(Operands);
1161}
1162
1163/// Parse an instruction.
1164bool HexagonAsmParser::parseInstruction(OperandVector &Operands) {
1165 MCAsmParser &Parser = getParser();
1166 AsmLexer &Lexer = getLexer();
1167 while (true) {
1168 AsmToken const &Token = Parser.getTok();
1169 switch (Token.getKind()) {
1170 case AsmToken::Eof:
1172 Lex();
1173 return false;
1174 }
1175 case AsmToken::LCurly: {
1176 if (!Operands.empty())
1177 return true;
1178 Operands.push_back(HexagonOperand::CreateToken(
1179 getContext(), Token.getString(), Token.getLoc()));
1180 Lex();
1181 return false;
1182 }
1183 case AsmToken::RCurly: {
1184 if (Operands.empty()) {
1185 Operands.push_back(HexagonOperand::CreateToken(
1186 getContext(), Token.getString(), Token.getLoc()));
1187 Lex();
1188 }
1189 return false;
1190 }
1191 case AsmToken::Comma: {
1192 Lex();
1193 continue;
1194 }
1200 case AsmToken::LessLess: {
1201 Operands.push_back(HexagonOperand::CreateToken(
1202 getContext(), Token.getString().substr(0, 1), Token.getLoc()));
1203 Operands.push_back(HexagonOperand::CreateToken(
1204 getContext(), Token.getString().substr(1, 1), Token.getLoc()));
1205 Lex();
1206 continue;
1207 }
1208 case AsmToken::Hash: {
1209 bool MustNotExtend = false;
1210 bool ImplicitExpression = implicitExpressionLocation(Operands);
1211 SMLoc ExprLoc = Lexer.getLoc();
1212 if (!ImplicitExpression)
1213 Operands.push_back(HexagonOperand::CreateToken(
1214 getContext(), Token.getString(), Token.getLoc()));
1215 Lex();
1216 bool MustExtend = false;
1217 bool HiOnly = false;
1218 bool LoOnly = false;
1219 if (Lexer.is(AsmToken::Hash)) {
1220 Lex();
1221 MustExtend = true;
1222 } else if (ImplicitExpression)
1223 MustNotExtend = true;
1224 AsmToken const &Token = Parser.getTok();
1225 if (Token.is(AsmToken::Identifier)) {
1226 StringRef String = Token.getString();
1227 if (String.lower() == "hi") {
1228 HiOnly = true;
1229 } else if (String.lower() == "lo") {
1230 LoOnly = true;
1231 }
1232 if (HiOnly || LoOnly) {
1233 AsmToken LParen = Lexer.peekTok();
1234 if (!LParen.is(AsmToken::LParen)) {
1235 HiOnly = false;
1236 LoOnly = false;
1237 } else {
1238 Lex();
1239 }
1240 }
1241 }
1242 MCExpr const *Expr = nullptr;
1243 if (parseExpression(Expr))
1244 return true;
1245 int64_t Value;
1246 MCContext &Context = Parser.getContext();
1247 assert(Expr != nullptr);
1248 if (Expr->evaluateAsAbsolute(Value)) {
1249 if (HiOnly)
1252 if (HiOnly || LoOnly)
1254 Expr, MCConstantExpr::create(0xffff, Context), Context);
1255 } else {
1256 MCValue Value;
1257 if (Expr->evaluateAsRelocatable(Value, nullptr)) {
1258 if (!Value.isAbsolute()) {
1259 switch (HexagonMCExpr::VariantKind(Value.getSpecifier())) {
1262 // Don't lazy extend these expression variants
1263 MustNotExtend = !MustExtend;
1264 break;
1265 default:
1266 break;
1267 }
1268 }
1269 }
1270 }
1271 Expr = HexagonMCExpr::create(Expr, Context);
1272 HexagonMCInstrInfo::setMustNotExtend(*Expr, MustNotExtend);
1273 HexagonMCInstrInfo::setMustExtend(*Expr, MustExtend);
1274 std::unique_ptr<HexagonOperand> Operand =
1275 HexagonOperand::CreateImm(getContext(), Expr, ExprLoc, ExprLoc);
1276 Operands.push_back(std::move(Operand));
1277 continue;
1278 }
1279 default:
1280 break;
1281 }
1282 if (parseExpressionOrOperand(Operands))
1283 return true;
1284 }
1285}
1286
1287bool HexagonAsmParser::parseInstruction(ParseInstructionInfo &Info,
1288 StringRef Name, AsmToken ID,
1290 getLexer().UnLex(ID);
1291 return parseInstruction(Operands);
1292}
1293
1294static MCInst makeCombineInst(int opCode, MCOperand &Rdd, MCOperand &MO1,
1295 MCOperand &MO2) {
1296 MCInst TmpInst;
1297 TmpInst.setOpcode(opCode);
1298 TmpInst.addOperand(Rdd);
1299 TmpInst.addOperand(MO1);
1300 TmpInst.addOperand(MO2);
1301
1302 return TmpInst;
1303}
1304
1305// Define this matcher function after the auto-generated include so we
1306// have the match class enum definitions.
1307unsigned
1308HexagonAsmParser::validateTargetOperandClass(const MCParsedAsmOperand &AsmOp,
1309 unsigned Kind) {
1310 const HexagonOperand *Op = static_cast<const HexagonOperand *>(&AsmOp);
1311
1312 switch (Kind) {
1313 case MCK_0: {
1314 int64_t Value;
1315 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 0
1316 ? Match_Success
1317 : Match_InvalidOperand;
1318 }
1319 case MCK_1: {
1320 int64_t Value;
1321 return Op->isImm() && Op->Imm.Val->evaluateAsAbsolute(Value) && Value == 1
1322 ? Match_Success
1323 : Match_InvalidOperand;
1324 }
1325 }
1326 if (Op->Kind == HexagonOperand::Token && Kind != InvalidMatchClass) {
1327 StringRef myStringRef = StringRef(Op->Tok.Data, Op->Tok.Length);
1328 if (matchTokenString(myStringRef.lower()) == (MatchClassKind)Kind)
1329 return Match_Success;
1330 if (matchTokenString(myStringRef.upper()) == (MatchClassKind)Kind)
1331 return Match_Success;
1332 }
1333
1334 LLVM_DEBUG(dbgs() << "Unmatched Operand:");
1335 LLVM_DEBUG(Op->dump());
1336 LLVM_DEBUG(dbgs() << "\n");
1337
1338 return Match_InvalidOperand;
1339}
1340
1341// FIXME: Calls to OutOfRange should propagate failure up to parseStatement.
1342bool HexagonAsmParser::OutOfRange(SMLoc IDLoc, long long Val, long long Max) {
1343 std::string errStr;
1344 raw_string_ostream ES(errStr);
1345 ES << "value " << Val << "(" << format_hex(Val, 0) << ") out of range: ";
1346 if (Max >= 0)
1347 ES << "0-" << Max;
1348 else
1349 ES << Max << "-" << (-Max - 1);
1350 return Parser.printError(IDLoc, ES.str());
1351}
1352
1353int HexagonAsmParser::processInstruction(MCInst &Inst,
1354 OperandVector const &Operands,
1355 SMLoc IDLoc) {
1356 MCContext &Context = getParser().getContext();
1357 const MCRegisterInfo *RI = getContext().getRegisterInfo();
1358 const std::string r = "r";
1359 const std::string Colon = ":";
1360 using RegPairVals = std::pair<unsigned, unsigned>;
1361 auto GetRegPair = [this, r](RegPairVals RegPair) {
1362 const std::string R1 = r + utostr(RegPair.first);
1363 const std::string R2 = r + utostr(RegPair.second);
1364
1365 return std::make_pair(matchRegister(R1), matchRegister(R2));
1366 };
1367 auto GetScalarRegs = [RI, GetRegPair](MCRegister RegPair) {
1368 const unsigned Lower = RI->getEncodingValue(RegPair);
1369 const RegPairVals RegPair_ = std::make_pair(Lower + 1, Lower);
1370
1371 return GetRegPair(RegPair_);
1372 };
1373 auto GetVecRegs = [GetRegPair](MCRegister VecRegPair) {
1374 const RegPairVals RegPair =
1376
1377 return GetRegPair(RegPair);
1378 };
1379
1380 bool is32bit = false; // used to distinguish between CONST32 and CONST64
1381 switch (Inst.getOpcode()) {
1382 default:
1383 if (HexagonMCInstrInfo::getDesc(MII, Inst).isPseudo()) {
1384 SMDiagnostic Diag = getSourceManager().GetMessage(
1385 IDLoc, SourceMgr::DK_Error,
1386 "Found pseudo instruction with no expansion");
1387 Diag.print("", errs());
1388 report_fatal_error("Invalid pseudo instruction");
1389 }
1390 break;
1391
1392 case Hexagon::J2_trap1:
1393 if (!getSTI().hasFeature(Hexagon::ArchV65)) {
1394 MCOperand &Rx = Inst.getOperand(0);
1395 MCOperand &Ry = Inst.getOperand(1);
1396 if (Rx.getReg() != Hexagon::R0 || Ry.getReg() != Hexagon::R0) {
1397 Error(IDLoc, "trap1 can only have register r0 as operand");
1398 return Match_InvalidOperand;
1399 }
1400 }
1401 break;
1402
1403 case Hexagon::A2_iconst: {
1404 Inst.setOpcode(Hexagon::A2_addi);
1405 MCOperand Reg = Inst.getOperand(0);
1406 MCOperand S27 = Inst.getOperand(1);
1409 Inst.clear();
1410 Inst.addOperand(Reg);
1411 Inst.addOperand(MCOperand::createReg(Hexagon::R0));
1412 Inst.addOperand(S27);
1413 break;
1414 }
1415 case Hexagon::M4_mpyrr_addr:
1416 case Hexagon::S4_addi_asl_ri:
1417 case Hexagon::S4_addi_lsr_ri:
1418 case Hexagon::S4_andi_asl_ri:
1419 case Hexagon::S4_andi_lsr_ri:
1420 case Hexagon::S4_ori_asl_ri:
1421 case Hexagon::S4_ori_lsr_ri:
1422 case Hexagon::S4_or_andix:
1423 case Hexagon::S4_subi_asl_ri:
1424 case Hexagon::S4_subi_lsr_ri: {
1425 MCOperand &Ry = Inst.getOperand(0);
1426 MCOperand &src = Inst.getOperand(2);
1427 if (RI->getEncodingValue(Ry.getReg()) != RI->getEncodingValue(src.getReg()))
1428 return Match_InvalidOperand;
1429 break;
1430 }
1431
1432 case Hexagon::C2_cmpgei: {
1433 MCOperand &MO = Inst.getOperand(2);
1437 Context));
1438 Inst.setOpcode(Hexagon::C2_cmpgti);
1439 break;
1440 }
1441
1442 case Hexagon::C2_cmpgeui: {
1443 MCOperand &MO = Inst.getOperand(2);
1444 int64_t Value;
1445 bool Success = MO.getExpr()->evaluateAsAbsolute(Value);
1446 (void)Success;
1447 assert(Success && "Assured by matcher");
1448 if (Value == 0) {
1449 MCInst TmpInst;
1450 MCOperand &Pd = Inst.getOperand(0);
1451 MCOperand &Rt = Inst.getOperand(1);
1452 TmpInst.setOpcode(Hexagon::C2_cmpeq);
1453 TmpInst.addOperand(Pd);
1454 TmpInst.addOperand(Rt);
1455 TmpInst.addOperand(Rt);
1456 Inst = TmpInst;
1457 } else {
1461 Context));
1462 Inst.setOpcode(Hexagon::C2_cmpgtui);
1463 }
1464 break;
1465 }
1466
1467 // Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)"
1468 case Hexagon::A2_tfrp: {
1469 MCOperand &MO = Inst.getOperand(1);
1470 const std::pair<MCRegister, MCRegister> RegPair =
1471 GetScalarRegs(MO.getReg());
1472 MO.setReg(RegPair.first);
1473 Inst.addOperand(MCOperand::createReg(RegPair.second));
1474 Inst.setOpcode(Hexagon::A2_combinew);
1475 break;
1476 }
1477
1478 case Hexagon::A2_tfrpt:
1479 case Hexagon::A2_tfrpf: {
1480 MCOperand &MO = Inst.getOperand(2);
1481 const std::pair<MCRegister, MCRegister> RegPair =
1482 GetScalarRegs(MO.getReg());
1483 MO.setReg(RegPair.first);
1484 Inst.addOperand(MCOperand::createReg(RegPair.second));
1485 Inst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrpt)
1486 ? Hexagon::C2_ccombinewt
1487 : Hexagon::C2_ccombinewf);
1488 break;
1489 }
1490 case Hexagon::A2_tfrptnew:
1491 case Hexagon::A2_tfrpfnew: {
1492 MCOperand &MO = Inst.getOperand(2);
1493 const std::pair<MCRegister, MCRegister> RegPair =
1494 GetScalarRegs(MO.getReg());
1495 MO.setReg(RegPair.first);
1496 Inst.addOperand(MCOperand::createReg(RegPair.second));
1497 Inst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrptnew)
1498 ? Hexagon::C2_ccombinewnewt
1499 : Hexagon::C2_ccombinewnewf);
1500 break;
1501 }
1502
1503 // Translate a "$Vdd = $Vss" to "$Vdd = vcombine($Vs, $Vt)"
1504 case Hexagon::V6_vassignp: {
1505 MCOperand &MO = Inst.getOperand(1);
1506 const std::pair<MCRegister, MCRegister> RegPair = GetVecRegs(MO.getReg());
1507 MO.setReg(RegPair.first);
1508 Inst.addOperand(MCOperand::createReg(RegPair.second));
1509 Inst.setOpcode(Hexagon::V6_vcombine);
1510 break;
1511 }
1512
1513 // Translate a "$Rx = CONST32(#imm)" to "$Rx = memw(gp+#LABEL) "
1514 case Hexagon::CONST32:
1515 is32bit = true;
1516 [[fallthrough]];
1517 // Translate a "$Rx:y = CONST64(#imm)" to "$Rx:y = memd(gp+#LABEL) "
1518 case Hexagon::CONST64:
1519 // FIXME: need better way to detect AsmStreamer (upstream removed getKind())
1520 if (!Parser.getStreamer().hasRawTextSupport()) {
1521 MCELFStreamer *MES = static_cast<MCELFStreamer *>(&Parser.getStreamer());
1522 MCOperand &MO_1 = Inst.getOperand(1);
1523 MCOperand &MO_0 = Inst.getOperand(0);
1524
1525 // push section onto section stack
1526 MES->pushSection();
1527
1528 std::string myCharStr;
1529 MCSectionELF *mySection;
1530
1531 // check if this as an immediate or a symbol
1532 int64_t Value;
1533 bool Absolute = MO_1.getExpr()->evaluateAsAbsolute(Value);
1534 if (Absolute) {
1535 // Create a new section - one for each constant
1536 // Some or all of the zeros are replaced with the given immediate.
1537 if (is32bit) {
1538 std::string myImmStr = utohexstr(static_cast<uint32_t>(Value));
1539 myCharStr = StringRef(".gnu.linkonce.l4.CONST_00000000")
1540 .drop_back(myImmStr.size())
1541 .str() +
1542 myImmStr;
1543 } else {
1544 std::string myImmStr = utohexstr(Value);
1545 myCharStr = StringRef(".gnu.linkonce.l8.CONST_0000000000000000")
1546 .drop_back(myImmStr.size())
1547 .str() +
1548 myImmStr;
1549 }
1550
1551 mySection = getContext().getELFSection(myCharStr, ELF::SHT_PROGBITS,
1553 } else if (MO_1.isExpr()) {
1554 // .lita - for expressions
1555 myCharStr = ".lita";
1556 mySection = getContext().getELFSection(myCharStr, ELF::SHT_PROGBITS,
1558 } else
1559 llvm_unreachable("unexpected type of machine operand!");
1560
1561 MES->switchSection(mySection);
1562 unsigned byteSize = is32bit ? 4 : 8;
1563 getStreamer().emitCodeAlignment(Align(byteSize), getSTI(), byteSize);
1564
1565 MCSymbol *Sym;
1566
1567 // for symbols, get rid of prepended ".gnu.linkonce.lx."
1568
1569 // emit symbol if needed
1570 if (Absolute) {
1571 Sym = getContext().getOrCreateSymbol(StringRef(myCharStr.c_str() + 16));
1572 if (Sym->isUndefined()) {
1573 getStreamer().emitLabel(Sym);
1574 getStreamer().emitSymbolAttribute(Sym, MCSA_Global);
1575 getStreamer().emitIntValue(Value, byteSize);
1576 }
1577 } else if (MO_1.isExpr()) {
1578 const char *StringStart = nullptr;
1579 const char *StringEnd = nullptr;
1580 if (*Operands[4]->getStartLoc().getPointer() == '#') {
1581 StringStart = Operands[5]->getStartLoc().getPointer();
1582 StringEnd = Operands[6]->getStartLoc().getPointer();
1583 } else { // no pound
1584 StringStart = Operands[4]->getStartLoc().getPointer();
1585 StringEnd = Operands[5]->getStartLoc().getPointer();
1586 }
1587
1588 unsigned size = StringEnd - StringStart;
1589 std::string DotConst = ".CONST_";
1590 Sym = getContext().getOrCreateSymbol(DotConst +
1591 StringRef(StringStart, size));
1592
1593 if (Sym->isUndefined()) {
1594 // case where symbol is not yet defined: emit symbol
1595 getStreamer().emitLabel(Sym);
1596 getStreamer().emitSymbolAttribute(Sym, MCSA_Local);
1597 getStreamer().emitValue(MO_1.getExpr(), 4);
1598 }
1599 } else
1600 llvm_unreachable("unexpected type of machine operand!");
1601
1602 MES->popSection();
1603
1604 if (Sym) {
1605 MCInst TmpInst;
1606 if (is32bit) // 32 bit
1607 TmpInst.setOpcode(Hexagon::L2_loadrigp);
1608 else // 64 bit
1609 TmpInst.setOpcode(Hexagon::L2_loadrdgp);
1610
1611 TmpInst.addOperand(MO_0);
1614 Inst = TmpInst;
1615 }
1616 }
1617 break;
1618
1619 // Translate a "$Rdd = #-imm" to "$Rdd = combine(#[-1,0], #-imm)"
1620 case Hexagon::A2_tfrpi: {
1621 MCOperand &Rdd = Inst.getOperand(0);
1622 MCOperand &MO = Inst.getOperand(1);
1623 int64_t Value;
1624 int sVal = (MO.getExpr()->evaluateAsAbsolute(Value) && Value < 0) ? -1 : 0;
1625 MCOperand imm(MCOperand::createExpr(
1627 Inst = makeCombineInst(Hexagon::A2_combineii, Rdd, imm, MO);
1628 break;
1629 }
1630
1631 // Translate a "$Rdd = [#]#imm" to "$Rdd = combine(#, [#]#imm)"
1632 case Hexagon::TFRI64_V4: {
1633 MCOperand &Rdd = Inst.getOperand(0);
1634 MCOperand &MO = Inst.getOperand(1);
1635 int64_t Value;
1636 if (MO.getExpr()->evaluateAsAbsolute(Value)) {
1637 int s8 = Hi_32(Value);
1638 if (!isInt<8>(s8))
1639 OutOfRange(IDLoc, s8, -128);
1641 MCConstantExpr::create(s8, Context), Context))); // upper 32
1642 auto Expr = HexagonMCExpr::create(
1646 MCOperand imm2(MCOperand::createExpr(Expr)); // lower 32
1647 Inst = makeCombineInst(Hexagon::A4_combineii, Rdd, imm, imm2);
1648 } else {
1650 MCConstantExpr::create(0, Context), Context))); // upper 32
1651 Inst = makeCombineInst(Hexagon::A4_combineii, Rdd, imm, MO);
1652 }
1653 break;
1654 }
1655
1656 // Handle $Rdd = combine(##imm, #imm)"
1657 case Hexagon::TFRI64_V2_ext: {
1658 MCOperand &Rdd = Inst.getOperand(0);
1659 MCOperand &MO1 = Inst.getOperand(1);
1660 MCOperand &MO2 = Inst.getOperand(2);
1661 int64_t Value;
1662 if (MO2.getExpr()->evaluateAsAbsolute(Value)) {
1663 int s8 = Value;
1664 if (s8 < -128 || s8 > 127)
1665 OutOfRange(IDLoc, s8, -128);
1666 }
1667 Inst = makeCombineInst(Hexagon::A2_combineii, Rdd, MO1, MO2);
1668 break;
1669 }
1670
1671 // Handle $Rdd = combine(#imm, ##imm)"
1672 case Hexagon::A4_combineii: {
1673 MCOperand &Rdd = Inst.getOperand(0);
1674 MCOperand &MO1 = Inst.getOperand(1);
1675 int64_t Value;
1676 if (MO1.getExpr()->evaluateAsAbsolute(Value)) {
1677 int s8 = Value;
1678 if (s8 < -128 || s8 > 127)
1679 OutOfRange(IDLoc, s8, -128);
1680 }
1681 MCOperand &MO2 = Inst.getOperand(2);
1682 Inst = makeCombineInst(Hexagon::A4_combineii, Rdd, MO1, MO2);
1683 break;
1684 }
1685
1686 case Hexagon::S2_tableidxb_goodsyntax:
1687 Inst.setOpcode(Hexagon::S2_tableidxb);
1688 break;
1689
1690 case Hexagon::S2_tableidxh_goodsyntax: {
1691 MCInst TmpInst;
1692 MCOperand &Rx = Inst.getOperand(0);
1693 MCOperand &Rs = Inst.getOperand(2);
1694 MCOperand &Imm4 = Inst.getOperand(3);
1695 MCOperand &Imm6 = Inst.getOperand(4);
1699 Context));
1700 TmpInst.setOpcode(Hexagon::S2_tableidxh);
1701 TmpInst.addOperand(Rx);
1702 TmpInst.addOperand(Rx);
1703 TmpInst.addOperand(Rs);
1704 TmpInst.addOperand(Imm4);
1705 TmpInst.addOperand(Imm6);
1706 Inst = TmpInst;
1707 break;
1708 }
1709
1710 case Hexagon::S2_tableidxw_goodsyntax: {
1711 MCInst TmpInst;
1712 MCOperand &Rx = Inst.getOperand(0);
1713 MCOperand &Rs = Inst.getOperand(2);
1714 MCOperand &Imm4 = Inst.getOperand(3);
1715 MCOperand &Imm6 = Inst.getOperand(4);
1719 Context));
1720 TmpInst.setOpcode(Hexagon::S2_tableidxw);
1721 TmpInst.addOperand(Rx);
1722 TmpInst.addOperand(Rx);
1723 TmpInst.addOperand(Rs);
1724 TmpInst.addOperand(Imm4);
1725 TmpInst.addOperand(Imm6);
1726 Inst = TmpInst;
1727 break;
1728 }
1729
1730 case Hexagon::S2_tableidxd_goodsyntax: {
1731 MCInst TmpInst;
1732 MCOperand &Rx = Inst.getOperand(0);
1733 MCOperand &Rs = Inst.getOperand(2);
1734 MCOperand &Imm4 = Inst.getOperand(3);
1735 MCOperand &Imm6 = Inst.getOperand(4);
1739 Context));
1740 TmpInst.setOpcode(Hexagon::S2_tableidxd);
1741 TmpInst.addOperand(Rx);
1742 TmpInst.addOperand(Rx);
1743 TmpInst.addOperand(Rs);
1744 TmpInst.addOperand(Imm4);
1745 TmpInst.addOperand(Imm6);
1746 Inst = TmpInst;
1747 break;
1748 }
1749
1750 case Hexagon::M2_mpyui:
1751 Inst.setOpcode(Hexagon::M2_mpyi);
1752 break;
1753 case Hexagon::M2_mpysmi: {
1754 MCInst TmpInst;
1755 MCOperand &Rd = Inst.getOperand(0);
1756 MCOperand &Rs = Inst.getOperand(1);
1757 MCOperand &Imm = Inst.getOperand(2);
1758 int64_t Value;
1759 MCExpr const &Expr = *Imm.getExpr();
1760 bool Absolute = Expr.evaluateAsAbsolute(Value);
1761 if (!Absolute)
1762 return Match_InvalidOperand;
1763 if (!HexagonMCInstrInfo::mustExtend(Expr) &&
1764 ((Value <= -256) || Value >= 256))
1765 return Match_InvalidOperand;
1766 if (Value < 0 && Value > -256) {
1767 Imm.setExpr(HexagonMCExpr::create(
1769 TmpInst.setOpcode(Hexagon::M2_mpysin);
1770 } else
1771 TmpInst.setOpcode(Hexagon::M2_mpysip);
1772 TmpInst.addOperand(Rd);
1773 TmpInst.addOperand(Rs);
1774 TmpInst.addOperand(Imm);
1775 Inst = TmpInst;
1776 break;
1777 }
1778
1779 case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
1780 MCOperand &Imm = Inst.getOperand(2);
1781 MCInst TmpInst;
1782 int64_t Value;
1783 bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
1784 if (!Absolute)
1785 return Match_InvalidOperand;
1786 if (Value == 0) { // convert to $Rd = $Rs
1787 TmpInst.setOpcode(Hexagon::A2_tfr);
1788 MCOperand &Rd = Inst.getOperand(0);
1789 MCOperand &Rs = Inst.getOperand(1);
1790 TmpInst.addOperand(Rd);
1791 TmpInst.addOperand(Rs);
1792 } else {
1793 Imm.setExpr(HexagonMCExpr::create(
1794 MCBinaryExpr::createSub(Imm.getExpr(),
1796 Context));
1797 TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd);
1798 MCOperand &Rd = Inst.getOperand(0);
1799 MCOperand &Rs = Inst.getOperand(1);
1800 TmpInst.addOperand(Rd);
1801 TmpInst.addOperand(Rs);
1802 TmpInst.addOperand(Imm);
1803 }
1804 Inst = TmpInst;
1805 break;
1806 }
1807
1808 case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
1809 MCOperand &Rdd = Inst.getOperand(0);
1810 MCOperand &Rss = Inst.getOperand(1);
1811 MCOperand &Imm = Inst.getOperand(2);
1812 int64_t Value;
1813 bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
1814 if (!Absolute)
1815 return Match_InvalidOperand;
1816 if (Value == 0) { // convert to $Rdd = combine ($Rs[0], $Rs[1])
1817 MCInst TmpInst;
1818 unsigned int RegPairNum = RI->getEncodingValue(Rss.getReg());
1819 std::string R1 = r + utostr(RegPairNum + 1);
1820 StringRef Reg1(R1);
1821 Rss.setReg(matchRegister(Reg1));
1822 // Add a new operand for the second register in the pair.
1823 std::string R2 = r + utostr(RegPairNum);
1824 StringRef Reg2(R2);
1825 TmpInst.setOpcode(Hexagon::A2_combinew);
1826 TmpInst.addOperand(Rdd);
1827 TmpInst.addOperand(Rss);
1828 TmpInst.addOperand(MCOperand::createReg(matchRegister(Reg2)));
1829 Inst = TmpInst;
1830 } else {
1831 Imm.setExpr(HexagonMCExpr::create(
1832 MCBinaryExpr::createSub(Imm.getExpr(),
1834 Context));
1835 Inst.setOpcode(Hexagon::S2_asr_i_p_rnd);
1836 }
1837 break;
1838 }
1839
1840 case Hexagon::A4_boundscheck: {
1841 MCOperand &Rs = Inst.getOperand(1);
1842 unsigned int RegNum = RI->getEncodingValue(Rs.getReg());
1843 if (RegNum & 1) { // Odd mapped to raw:hi, regpair is rodd:odd-1, like r3:2
1844 Inst.setOpcode(Hexagon::A4_boundscheck_hi);
1845 std::string Name = r + utostr(RegNum) + Colon + utostr(RegNum - 1);
1846 StringRef RegPair = Name;
1847 Rs.setReg(matchRegister(RegPair));
1848 } else { // raw:lo
1849 Inst.setOpcode(Hexagon::A4_boundscheck_lo);
1850 std::string Name = r + utostr(RegNum + 1) + Colon + utostr(RegNum);
1851 StringRef RegPair = Name;
1852 Rs.setReg(matchRegister(RegPair));
1853 }
1854 break;
1855 }
1856
1857 case Hexagon::A2_addsp: {
1858 MCOperand &Rs = Inst.getOperand(1);
1859 unsigned int RegNum = RI->getEncodingValue(Rs.getReg());
1860 if (RegNum & 1) { // Odd mapped to raw:hi
1861 Inst.setOpcode(Hexagon::A2_addsph);
1862 std::string Name = r + utostr(RegNum) + Colon + utostr(RegNum - 1);
1863 StringRef RegPair = Name;
1864 Rs.setReg(matchRegister(RegPair));
1865 } else { // Even mapped raw:lo
1866 Inst.setOpcode(Hexagon::A2_addspl);
1867 std::string Name = r + utostr(RegNum + 1) + Colon + utostr(RegNum);
1868 StringRef RegPair = Name;
1869 Rs.setReg(matchRegister(RegPair));
1870 }
1871 break;
1872 }
1873
1874 case Hexagon::M2_vrcmpys_s1: {
1875 MCOperand &Rt = Inst.getOperand(2);
1876 unsigned int RegNum = RI->getEncodingValue(Rt.getReg());
1877 if (RegNum & 1) { // Odd mapped to sat:raw:hi
1878 Inst.setOpcode(Hexagon::M2_vrcmpys_s1_h);
1879 std::string Name = r + utostr(RegNum) + Colon + utostr(RegNum - 1);
1880 StringRef RegPair = Name;
1881 Rt.setReg(matchRegister(RegPair));
1882 } else { // Even mapped sat:raw:lo
1883 Inst.setOpcode(Hexagon::M2_vrcmpys_s1_l);
1884 std::string Name = r + utostr(RegNum + 1) + Colon + utostr(RegNum);
1885 StringRef RegPair = Name;
1886 Rt.setReg(matchRegister(RegPair));
1887 }
1888 break;
1889 }
1890
1891 case Hexagon::M2_vrcmpys_acc_s1: {
1892 MCInst TmpInst;
1893 MCOperand &Rxx = Inst.getOperand(0);
1894 MCOperand &Rss = Inst.getOperand(2);
1895 MCOperand &Rt = Inst.getOperand(3);
1896 unsigned int RegNum = RI->getEncodingValue(Rt.getReg());
1897 if (RegNum & 1) { // Odd mapped to sat:raw:hi
1898 TmpInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
1899 std::string Name = r + utostr(RegNum) + Colon + utostr(RegNum - 1);
1900 StringRef RegPair = Name;
1901 Rt.setReg(matchRegister(RegPair));
1902 } else { // Even mapped sat:raw:lo
1903 TmpInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
1904 std::string Name = r + utostr(RegNum + 1) + Colon + utostr(RegNum);
1905 StringRef RegPair = Name;
1906 Rt.setReg(matchRegister(RegPair));
1907 }
1908 // Registers are in different positions
1909 TmpInst.addOperand(Rxx);
1910 TmpInst.addOperand(Rxx);
1911 TmpInst.addOperand(Rss);
1912 TmpInst.addOperand(Rt);
1913 Inst = TmpInst;
1914 break;
1915 }
1916
1917 case Hexagon::M2_vrcmpys_s1rp: {
1918 MCOperand &Rt = Inst.getOperand(2);
1919 unsigned int RegNum = RI->getEncodingValue(Rt.getReg());
1920 if (RegNum & 1) { // Odd mapped to rnd:sat:raw:hi
1921 Inst.setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
1922 std::string Name = r + utostr(RegNum) + Colon + utostr(RegNum - 1);
1923 StringRef RegPair = Name;
1924 Rt.setReg(matchRegister(RegPair));
1925 } else { // Even mapped rnd:sat:raw:lo
1926 Inst.setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
1927 std::string Name = r + utostr(RegNum + 1) + Colon + utostr(RegNum);
1928 StringRef RegPair = Name;
1929 Rt.setReg(matchRegister(RegPair));
1930 }
1931 break;
1932 }
1933
1934 case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
1935 MCOperand &Imm = Inst.getOperand(2);
1936 int64_t Value;
1937 bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
1938 if (!Absolute)
1939 return Match_InvalidOperand;
1940 if (Value == 0)
1941 Inst.setOpcode(Hexagon::S2_vsathub);
1942 else {
1943 Imm.setExpr(HexagonMCExpr::create(
1944 MCBinaryExpr::createSub(Imm.getExpr(),
1946 Context));
1947 Inst.setOpcode(Hexagon::S5_asrhub_rnd_sat);
1948 }
1949 break;
1950 }
1951
1952 case Hexagon::S5_vasrhrnd_goodsyntax: {
1953 MCOperand &Rdd = Inst.getOperand(0);
1954 MCOperand &Rss = Inst.getOperand(1);
1955 MCOperand &Imm = Inst.getOperand(2);
1956 int64_t Value;
1957 bool Absolute = Imm.getExpr()->evaluateAsAbsolute(Value);
1958 if (!Absolute)
1959 return Match_InvalidOperand;
1960 if (Value == 0) {
1961 MCInst TmpInst;
1962 unsigned int RegPairNum = RI->getEncodingValue(Rss.getReg());
1963 std::string R1 = r + utostr(RegPairNum + 1);
1964 StringRef Reg1(R1);
1965 Rss.setReg(matchRegister(Reg1));
1966 // Add a new operand for the second register in the pair.
1967 std::string R2 = r + utostr(RegPairNum);
1968 StringRef Reg2(R2);
1969 TmpInst.setOpcode(Hexagon::A2_combinew);
1970 TmpInst.addOperand(Rdd);
1971 TmpInst.addOperand(Rss);
1972 TmpInst.addOperand(MCOperand::createReg(matchRegister(Reg2)));
1973 Inst = TmpInst;
1974 } else {
1975 Imm.setExpr(HexagonMCExpr::create(
1976 MCBinaryExpr::createSub(Imm.getExpr(),
1978 Context));
1979 Inst.setOpcode(Hexagon::S5_vasrhrnd);
1980 }
1981 break;
1982 }
1983
1984 case Hexagon::A2_not: {
1985 MCInst TmpInst;
1986 MCOperand &Rd = Inst.getOperand(0);
1987 MCOperand &Rs = Inst.getOperand(1);
1988 TmpInst.setOpcode(Hexagon::A2_subri);
1989 TmpInst.addOperand(Rd);
1992 TmpInst.addOperand(Rs);
1993 Inst = TmpInst;
1994 break;
1995 }
1996 case Hexagon::PS_loadrubabs:
1998 Inst.setOpcode(Hexagon::L2_loadrubgp);
1999 break;
2000 case Hexagon::PS_loadrbabs:
2002 Inst.setOpcode(Hexagon::L2_loadrbgp);
2003 break;
2004 case Hexagon::PS_loadruhabs:
2006 Inst.setOpcode(Hexagon::L2_loadruhgp);
2007 break;
2008 case Hexagon::PS_loadrhabs:
2010 Inst.setOpcode(Hexagon::L2_loadrhgp);
2011 break;
2012 case Hexagon::PS_loadriabs:
2014 Inst.setOpcode(Hexagon::L2_loadrigp);
2015 break;
2016 case Hexagon::PS_loadrdabs:
2018 Inst.setOpcode(Hexagon::L2_loadrdgp);
2019 break;
2020 case Hexagon::PS_storerbabs:
2022 Inst.setOpcode(Hexagon::S2_storerbgp);
2023 break;
2024 case Hexagon::PS_storerhabs:
2026 Inst.setOpcode(Hexagon::S2_storerhgp);
2027 break;
2028 case Hexagon::PS_storerfabs:
2030 Inst.setOpcode(Hexagon::S2_storerfgp);
2031 break;
2032 case Hexagon::PS_storeriabs:
2034 Inst.setOpcode(Hexagon::S2_storerigp);
2035 break;
2036 case Hexagon::PS_storerdabs:
2038 Inst.setOpcode(Hexagon::S2_storerdgp);
2039 break;
2040 case Hexagon::PS_storerbnewabs:
2042 Inst.setOpcode(Hexagon::S2_storerbnewgp);
2043 break;
2044 case Hexagon::PS_storerhnewabs:
2046 Inst.setOpcode(Hexagon::S2_storerhnewgp);
2047 break;
2048 case Hexagon::PS_storerinewabs:
2050 Inst.setOpcode(Hexagon::S2_storerinewgp);
2051 break;
2052 case Hexagon::A2_zxtb: {
2053 Inst.setOpcode(Hexagon::A2_andir);
2054 Inst.addOperand(
2056 break;
2057 }
2058 } // switch
2059
2060 return Match_Success;
2061}
2062
2063MCRegister HexagonAsmParser::matchRegister(StringRef Name) {
2064 if (MCRegister Reg = MatchRegisterName(Name))
2065 return Reg;
2066 return MatchRegisterAltName(Name);
2067}
static MCRegister MatchRegisterName(StringRef Name)
#define Success
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
uint64_t Imm
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static MCRegister MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
bpf unwind BPF Unwind Lower
static size_t byteSize(BTF::CommonType *Type)
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
static bool isSigned(unsigned Opcode)
#define Check(C,...)
static cl::opt< bool > WarnSignedMismatch("mwarn-sign-mismatch", cl::desc("Warn for mismatching a signed and unsigned value"), cl::init(false))
static cl::opt< bool > ErrorMissingParenthesis("merror-missing-parenthesis", cl::desc("Error for missing parenthesis around predicate registers"), cl::init(false))
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonAsmParser()
Force static initialization.
static cl::opt< bool > WarnNoncontigiousRegister("mwarn-noncontigious-register", cl::desc("Warn for register names that aren't contigious"), cl::init(true))
static cl::opt< bool > ErrorNoncontigiousRegister("merror-noncontigious-register", cl::desc("Error for register names that aren't contigious"), cl::init(false))
static bool previousEqual(OperandVector &Operands, size_t Index, StringRef String)
static MCInst makeCombineInst(int opCode, MCOperand &Rdd, MCOperand &MO1, MCOperand &MO2)
static bool previousIsLoop(OperandVector &Operands, size_t Index)
static cl::opt< bool > WarnMissingParenthesis("mwarn-missing-parenthesis", cl::desc("Warn for missing parenthesis around predicate registers"), cl::init(true))
static cl::opt< bool > AddBuildAttributes("hexagon-add-build-attributes")
Value * getPointer(Value *Ptr)
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
#define R2(n)
Promote Memory to Register
Definition Mem2Reg.cpp:110
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
SI Fold Operands
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
const char * Msg
This file contains some templates that are useful if you are working with the STL at all.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
SMLoc getLoc() const
Get the current source location.
Definition AsmLexer.h:116
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
Definition AsmLexer.h:122
void UnLex(AsmToken const &Token)
Definition AsmLexer.h:107
const AsmToken & getTok() const
Get the current (last) lexed token.
Definition AsmLexer.h:119
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
Definition AsmLexer.h:148
const AsmToken & Lex()
Consume the next token from the input stream and return it.
Definition AsmLexer.h:93
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
Definition AsmLexer.h:151
LLVM_ABI SMLoc getLoc() const
Definition AsmLexer.cpp:31
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Definition MCAsmMacro.h:103
bool is(TokenKind K) const
Definition MCAsmMacro.h:75
TokenKind getKind() const
Definition MCAsmMacro.h:74
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Definition MCAsmMacro.h:92
void HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment, unsigned AccessSize)
void HexagonMCEmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment, unsigned AccessSize)
void setMustNotExtend(bool Val=true)
bool mustNotExtend() const
bool mustExtend() const
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
void setMustExtend(bool Val=true)
void setSignMismatch(bool Val=true)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:69
void printExpr(raw_ostream &, const MCExpr &) const
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
Generic assembler parser interface, for use by target specific assembly parsers.
MCContext & getContext()
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
AsmLexer & getLexer()
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
virtual bool printError(SMLoc L, const Twine &Msg, SMRange Range={})=0
Emit an error at the location L, with the message Msg.
MCStreamer & getStreamer()
static const MCBinaryExpr * createLShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:419
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:344
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:424
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Definition MCExpr.cpp:450
@ Unary
Unary expressions.
Definition MCExpr.h:41
@ SymbolRef
References to labels and assigned expressions.
Definition MCExpr.h:40
@ Binary
Binary expressions.
Definition MCExpr.h:38
LLVM_ABI bool evaluateAsAbsolute(int64_t &Res) const
Try to evaluate the expression to an absolute value.
Definition MCExpr.cpp:238
ExprKind getKind() const
Definition MCExpr.h:82
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:187
void setLoc(SMLoc loc)
Definition MCInst.h:206
unsigned getOpcode() const
Definition MCInst.h:201
LLVM_ABI void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ", const MCContext *Ctx=nullptr) const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
Definition MCInst.cpp:90
void addOperand(const MCOperand Op)
Definition MCInst.h:214
void setOpcode(unsigned Op)
Definition MCInst.h:200
void clear()
Definition MCInst.h:222
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:209
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
MCAssembler & getAssembler()
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:39
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:165
void setExpr(const MCExpr *Val)
Definition MCInst.h:122
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:137
static MCOperand createImm(int64_t Val)
Definition MCInst.h:144
void setReg(MCRegister Reg)
Set the register number.
Definition MCInst.h:78
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:72
const MCExpr * getExpr() const
Definition MCInst.h:117
bool isExpr() const
Definition MCInst.h:68
static MCOperand createInst(const MCInst *Val)
Definition MCInst.h:172
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
virtual bool isToken() const =0
isToken - Is this a token operand?
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
constexpr unsigned id() const
Definition MCRegister.h:85
virtual bool popSection()
Restore the current and previous section from the section stack.
virtual bool hasRawTextSupport() const
Return true if this asm streamer supports emitting unformatted text to the .s file with EmitRawText.
Definition MCStreamer.h:388
MCTargetStreamer * getTargetStreamer()
Definition MCStreamer.h:339
void pushSection()
Save the current and previous section on the section stack.
Definition MCStreamer.h:463
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
Generic base class for all target subtargets.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:210
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition MCSymbol.h:243
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Target specific streamer interface.
Definition MCStreamer.h:94
MCStreamer & getStreamer()
Definition MCStreamer.h:102
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
LLVM_ABI void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
reference emplace_back(ArgTypes &&... Args)
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:728
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:589
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
LLVM_ABI std::string lower() const
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Definition StringRef.h:170
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
Definition StringRef.cpp:32
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
LLVM_ABI std::optional< unsigned > attrTypeFromString(StringRef tag, TagNameMap tagNameMap)
@ SHF_ALLOC
Definition ELF.h:1098
@ SHF_WRITE
Definition ELF.h:1095
@ SHT_PROGBITS
Definition ELF.h:996
LLVM_ABI const TagNameMap & getHexagonAttributeTags()
std::pair< unsigned, unsigned > GetVecRegPairIndices(MCRegister VecRegPair)
Returns an ordered pair of the constituent register ordinals for each of the elements of VecRegPair.
bool isOuterLoop(MCInst const &MCI)
size_t bundleSize(MCInst const &MCI)
void setS27_2_reloc(MCExpr const &Expr, bool Val=true)
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
void setMemReorderDisabled(MCInst &MCI)
bool isBundle(MCInst const &MCI)
MCExpr const & getExpr(MCExpr const &Expr)
bool isInnerLoop(MCInst const &MCI)
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCB, HexagonMCChecker *Checker, bool AttemptCompatibility=false)
void setMustNotExtend(MCExpr const &Expr, bool Val=true)
void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
bool mustExtend(MCExpr const &Expr)
void setMustExtend(MCExpr const &Expr, bool Val=true)
@ CE
Windows NT (Windows on ARM)
Definition MCAsmInfo.h:51
bool isPseudo(uint64_t TSFlags)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Done
Definition Threading.h:60
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition MathExtras.h:244
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
std::string utostr(uint64_t X, bool isNeg=false)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:285
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
Target & getTheHexagonTarget()
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
Definition MathExtras.h:151
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Definition MathExtras.h:156
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition Format.h:164
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition STLExtras.h:2210
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition MathExtras.h:249
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition MathExtras.h:572
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
@ MCSA_Local
.local (ELF)
@ MCSA_Global
.type _foo, @gnu_unique_object
#define N
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...