LLVM 24.0.0git
SparcAsmParser.cpp
Go to the documentation of this file.
1//===-- SparcAsmParser.cpp - Parse Sparc assembly 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
13#include "llvm/ADT/StringRef.h"
15#include "llvm/MC/MCAsmMacro.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCInst.h"
20#include "llvm/MC/MCInstrInfo.h"
27#include "llvm/MC/MCStreamer.h"
29#include "llvm/MC/MCSymbol.h"
35#include "llvm/Support/SMLoc.h"
38#include <algorithm>
39#include <cassert>
40#include <cstdint>
41#include <memory>
42#include <string>
43
44using namespace llvm;
45
46// The generated AsmMatcher SparcGenAsmMatcher uses "Sparc" as the target
47// namespace. But SPARC backend uses "SP" as its namespace.
48namespace llvm {
49namespace Sparc {
50
51 using namespace SP;
52
53} // end namespace Sparc
54} // end namespace llvm
55
56namespace {
57
58class SparcOperand;
59
60class SparcAsmParser : public MCTargetAsmParser {
61 MCAsmParser &Parser;
62 const MCRegisterInfo &MRI;
63
64 enum class TailRelocKind { Load_GOT, Add_TLS, Load_TLS, Call_TLS };
65
66 /// @name Auto-generated Match Functions
67 /// {
68
69#define GET_ASSEMBLER_HEADER
70#include "SparcGenAsmMatcher.inc"
71
72 /// }
73
74 // public interface of the MCTargetAsmParser.
75 bool matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
78 bool MatchingInlineAsm) override;
79 bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) override;
80 ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
81 SMLoc &EndLoc) override;
82 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
83 SMLoc NameLoc, OperandVector &Operands) override;
84 ParseStatus parseDirective(AsmToken DirectiveID) override;
85 bool parseExprWithSpecifier(const MCExpr *&Res, SMLoc &E);
86 bool parseDataExpr(const MCExpr *&Res) override;
87
88 // Custom parse functions for Sparc specific operands.
89 ParseStatus parseMEMOperand(OperandVector &Operands);
90
91 ParseStatus parseMembarTag(OperandVector &Operands);
92
94
95 ParseStatus parsePrefetchTag(OperandVector &Operands);
96
97 template <TailRelocKind Kind>
98 ParseStatus parseTailRelocSym(OperandVector &Operands);
99
100 template <unsigned N> ParseStatus parseShiftAmtImm(OperandVector &Operands);
101
102 ParseStatus parseCallTarget(OperandVector &Operands);
103
104 ParseStatus parseOperand(OperandVector &Operands, StringRef Name);
105
106 ParseStatus parseSparcAsmOperand(std::unique_ptr<SparcOperand> &Operand);
107
108 ParseStatus parseBranchModifiers(OperandVector &Operands);
109
110 ParseStatus parseExpression(int64_t &Val);
111
112 // Helper function for dealing with %lo / %hi in PIC mode.
113 const MCSpecifierExpr *adjustPICRelocation(uint16_t VK,
114 const MCExpr *subExpr);
115
116 // Helper function to see if current token can start an expression.
117 bool isPossibleExpression(const AsmToken &Token);
118
119 // Check if mnemonic is valid.
120 MatchResultTy mnemonicIsValid(StringRef Mnemonic, unsigned VariantID);
121
122 // returns true if Tok is matched to a register and returns register in RegNo.
123 MCRegister matchRegisterName(const AsmToken &Tok, unsigned &RegKind);
124
125 ParseStatus matchSparcAsmModifiers(const MCExpr *&EVal, SMLoc &EndLoc);
126
127 bool is64Bit() const { return getSTI().getTargetTriple().isSPARC64(); }
128
129 bool expandSET(MCInst &Inst, SMLoc IDLoc,
130 SmallVectorImpl<MCInst> &Instructions);
131
132 bool expandSETSW(MCInst &Inst, SMLoc IDLoc,
133 SmallVectorImpl<MCInst> &Instructions);
134
135 bool expandSETX(MCInst &Inst, SMLoc IDLoc,
136 SmallVectorImpl<MCInst> &Instructions);
137
138 SMLoc getLoc() const { return getParser().getTok().getLoc(); }
139
140public:
141 SparcAsmParser(const MCSubtargetInfo &sti, MCAsmParser &parser,
142 const MCInstrInfo &MII)
143 : MCTargetAsmParser(sti, MII), Parser(parser),
144 MRI(*Parser.getContext().getRegisterInfo()) {
145 Parser.addAliasForDirective(".half", ".2byte");
146 Parser.addAliasForDirective(".uahalf", ".2byte");
147 Parser.addAliasForDirective(".word", ".4byte");
148 Parser.addAliasForDirective(".uaword", ".4byte");
149 Parser.addAliasForDirective(".nword", is64Bit() ? ".8byte" : ".4byte");
150 if (is64Bit())
151 Parser.addAliasForDirective(".xword", ".8byte");
152
153 // Initialize the set of available features.
154 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
155 }
156};
157
158} // end anonymous namespace
159
160 static const MCPhysReg IntRegs[32] = {
161 Sparc::G0, Sparc::G1, Sparc::G2, Sparc::G3,
162 Sparc::G4, Sparc::G5, Sparc::G6, Sparc::G7,
163 Sparc::O0, Sparc::O1, Sparc::O2, Sparc::O3,
164 Sparc::O4, Sparc::O5, Sparc::O6, Sparc::O7,
165 Sparc::L0, Sparc::L1, Sparc::L2, Sparc::L3,
166 Sparc::L4, Sparc::L5, Sparc::L6, Sparc::L7,
167 Sparc::I0, Sparc::I1, Sparc::I2, Sparc::I3,
168 Sparc::I4, Sparc::I5, Sparc::I6, Sparc::I7 };
169
170namespace {
171
172/// SparcOperand - Instances of this class represent a parsed Sparc machine
173/// instruction.
174class SparcOperand : public MCParsedAsmOperand {
175public:
176 enum RegisterKind {
177 rk_None,
178 rk_IntReg,
179 rk_Special,
180 };
181
182private:
183 enum KindTy {
184 k_Token,
185 k_Register,
186 k_Immediate,
187 k_MemoryReg,
188 k_MemoryImm,
189 k_ASITag,
190 k_PrefetchTag,
191 k_TailRelocSym, // Special kind of immediate for TLS relocation purposes.
192 } Kind;
193
194 SMLoc StartLoc, EndLoc;
195
196 struct Token {
197 const char *Data;
198 unsigned Length;
199 };
200
201 struct RegOp {
202 MCRegister Reg;
203 RegisterKind Kind;
204 };
205
206 struct ImmOp {
207 const MCExpr *Val;
208 };
209
210 struct MemOp {
211 MCRegister Base;
212 MCRegister OffsetReg;
213 const MCExpr *Off;
214 };
215
216 union {
217 struct Token Tok;
218 struct RegOp Reg;
219 struct ImmOp Imm;
220 struct MemOp Mem;
221 unsigned ASI;
222 unsigned Prefetch;
223 };
224
225public:
226 SparcOperand(KindTy K) : Kind(K) {}
227
228 bool isToken() const override { return Kind == k_Token; }
229 bool isReg() const override { return Kind == k_Register; }
230 bool isImm() const override { return Kind == k_Immediate; }
231 bool isMem() const override { return isMEMrr() || isMEMri(); }
232 bool isMEMrr() const { return Kind == k_MemoryReg; }
233 bool isMEMri() const { return Kind == k_MemoryImm; }
234 bool isMembarTag() const { return Kind == k_Immediate; }
235 bool isASITag() const { return Kind == k_ASITag; }
236 bool isPrefetchTag() const { return Kind == k_PrefetchTag; }
237 bool isTailRelocSym() const { return Kind == k_TailRelocSym; }
238
239 bool isCallTarget() const {
240 if (!isImm())
241 return false;
242
243 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val))
244 return CE->getValue() % 4 == 0;
245
246 return true;
247 }
248
249 bool isShiftAmtImm5() const {
250 if (!isImm())
251 return false;
252
253 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val))
254 return isUInt<5>(CE->getValue());
255
256 return false;
257 }
258
259 bool isShiftAmtImm6() const {
260 if (!isImm())
261 return false;
262
263 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val))
264 return isUInt<6>(CE->getValue());
265
266 return false;
267 }
268
269 bool isIntReg() const {
270 return (Kind == k_Register && Reg.Kind == rk_IntReg);
271 }
272
273 StringRef getToken() const {
274 assert(Kind == k_Token && "Invalid access!");
275 return StringRef(Tok.Data, Tok.Length);
276 }
277
278 MCRegister getReg() const override {
279 assert((Kind == k_Register) && "Invalid access!");
280 return Reg.Reg;
281 }
282
283 const MCExpr *getImm() const {
284 assert((Kind == k_Immediate) && "Invalid access!");
285 return Imm.Val;
286 }
287
288 MCRegister getMemBase() const {
289 assert((Kind == k_MemoryReg || Kind == k_MemoryImm) && "Invalid access!");
290 return Mem.Base;
291 }
292
293 MCRegister getMemOffsetReg() const {
294 assert((Kind == k_MemoryReg) && "Invalid access!");
295 return Mem.OffsetReg;
296 }
297
298 const MCExpr *getMemOff() const {
299 assert((Kind == k_MemoryImm) && "Invalid access!");
300 return Mem.Off;
301 }
302
303 unsigned getASITag() const {
304 assert((Kind == k_ASITag) && "Invalid access!");
305 return ASI;
306 }
307
308 unsigned getPrefetchTag() const {
309 assert((Kind == k_PrefetchTag) && "Invalid access!");
310 return Prefetch;
311 }
312
313 const MCExpr *getTailRelocSym() const {
314 assert((Kind == k_TailRelocSym) && "Invalid access!");
315 return Imm.Val;
316 }
317
318 /// getStartLoc - Get the location of the first token of this operand.
319 SMLoc getStartLoc() const override {
320 return StartLoc;
321 }
322 /// getEndLoc - Get the location of the last token of this operand.
323 SMLoc getEndLoc() const override {
324 return EndLoc;
325 }
326
327 void print(raw_ostream &OS, const MCAsmInfo &MAI) const override {
328 switch (Kind) {
329 case k_Token: OS << "Token: " << getToken() << "\n"; break;
330 case k_Register:
331 OS << "Reg: #" << getReg().id() << "\n";
332 break;
333 case k_Immediate: OS << "Imm: " << getImm() << "\n"; break;
334 case k_MemoryReg:
335 OS << "Mem: " << getMemBase().id() << "+" << getMemOffsetReg().id()
336 << "\n";
337 break;
338 case k_MemoryImm: assert(getMemOff() != nullptr);
339 OS << "Mem: " << getMemBase().id() << "+";
340 MAI.printExpr(OS, *getMemOff());
341 OS << "\n";
342 break;
343 case k_ASITag:
344 OS << "ASI tag: " << getASITag() << "\n";
345 break;
346 case k_PrefetchTag:
347 OS << "Prefetch tag: " << getPrefetchTag() << "\n";
348 break;
349 case k_TailRelocSym:
350 OS << "TailReloc: " << getTailRelocSym() << "\n";
351 break;
352 }
353 }
354
355 void addRegOperands(MCInst &Inst, unsigned N) const {
356 assert(N == 1 && "Invalid number of operands!");
358 }
359
360 void addImmOperands(MCInst &Inst, unsigned N) const {
361 assert(N == 1 && "Invalid number of operands!");
362 const MCExpr *Expr = getImm();
363 addExpr(Inst, Expr);
364 }
365
366 void addShiftAmtImm5Operands(MCInst &Inst, unsigned N) const {
367 assert(N == 1 && "Invalid number of operands!");
368 addExpr(Inst, getImm());
369 }
370 void addShiftAmtImm6Operands(MCInst &Inst, unsigned N) const {
371 assert(N == 1 && "Invalid number of operands!");
372 addExpr(Inst, getImm());
373 }
374
375 void addExpr(MCInst &Inst, const MCExpr *Expr) const{
376 // Add as immediate when possible. Null MCExpr = 0.
377 if (!Expr)
379 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
380 Inst.addOperand(MCOperand::createImm(CE->getValue()));
381 else
383 }
384
385 void addMEMrrOperands(MCInst &Inst, unsigned N) const {
386 assert(N == 2 && "Invalid number of operands!");
387
388 Inst.addOperand(MCOperand::createReg(getMemBase()));
389
390 assert(getMemOffsetReg().isValid() && "Invalid offset");
391 Inst.addOperand(MCOperand::createReg(getMemOffsetReg()));
392 }
393
394 void addMEMriOperands(MCInst &Inst, unsigned N) const {
395 assert(N == 2 && "Invalid number of operands!");
396
397 Inst.addOperand(MCOperand::createReg(getMemBase()));
398
399 const MCExpr *Expr = getMemOff();
400 addExpr(Inst, Expr);
401 }
402
403 void addASITagOperands(MCInst &Inst, unsigned N) const {
404 assert(N == 1 && "Invalid number of operands!");
405 Inst.addOperand(MCOperand::createImm(getASITag()));
406 }
407
408 void addPrefetchTagOperands(MCInst &Inst, unsigned N) const {
409 assert(N == 1 && "Invalid number of operands!");
410 Inst.addOperand(MCOperand::createImm(getPrefetchTag()));
411 }
412
413 void addMembarTagOperands(MCInst &Inst, unsigned N) const {
414 assert(N == 1 && "Invalid number of operands!");
415 const MCExpr *Expr = getImm();
416 addExpr(Inst, Expr);
417 }
418
419 void addCallTargetOperands(MCInst &Inst, unsigned N) const {
420 assert(N == 1 && "Invalid number of operands!");
421 addExpr(Inst, getImm());
422 }
423
424 void addTailRelocSymOperands(MCInst &Inst, unsigned N) const {
425 assert(N == 1 && "Invalid number of operands!");
426 addExpr(Inst, getTailRelocSym());
427 }
428
429 static std::unique_ptr<SparcOperand> CreateToken(StringRef Str, SMLoc S) {
430 auto Op = std::make_unique<SparcOperand>(k_Token);
431 Op->Tok.Data = Str.data();
432 Op->Tok.Length = Str.size();
433 Op->StartLoc = S;
434 Op->EndLoc = S;
435 return Op;
436 }
437
438 static std::unique_ptr<SparcOperand> CreateReg(MCRegister Reg, unsigned Kind,
439 SMLoc S, SMLoc E) {
440 auto Op = std::make_unique<SparcOperand>(k_Register);
441 Op->Reg.Reg = Reg;
442 Op->Reg.Kind = (SparcOperand::RegisterKind)Kind;
443 Op->StartLoc = S;
444 Op->EndLoc = E;
445 return Op;
446 }
447
448 static std::unique_ptr<SparcOperand> CreateImm(const MCExpr *Val, SMLoc S,
449 SMLoc E) {
450 auto Op = std::make_unique<SparcOperand>(k_Immediate);
451 Op->Imm.Val = Val;
452 Op->StartLoc = S;
453 Op->EndLoc = E;
454 return Op;
455 }
456
457 static std::unique_ptr<SparcOperand> CreateASITag(unsigned Val, SMLoc S,
458 SMLoc E) {
459 auto Op = std::make_unique<SparcOperand>(k_ASITag);
460 Op->ASI = Val;
461 Op->StartLoc = S;
462 Op->EndLoc = E;
463 return Op;
464 }
465
466 static std::unique_ptr<SparcOperand> CreatePrefetchTag(unsigned Val, SMLoc S,
467 SMLoc E) {
468 auto Op = std::make_unique<SparcOperand>(k_PrefetchTag);
469 Op->Prefetch = Val;
470 Op->StartLoc = S;
471 Op->EndLoc = E;
472 return Op;
473 }
474
475 static std::unique_ptr<SparcOperand> CreateTailRelocSym(const MCExpr *Val,
476 SMLoc S, SMLoc E) {
477 auto Op = std::make_unique<SparcOperand>(k_TailRelocSym);
478 Op->Imm.Val = Val;
479 Op->StartLoc = S;
480 Op->EndLoc = E;
481 return Op;
482 }
483
484 static std::unique_ptr<SparcOperand>
485 MorphToMEMrr(MCRegister Base, std::unique_ptr<SparcOperand> Op) {
486 MCRegister offsetReg = Op->getReg();
487 Op->Kind = k_MemoryReg;
488 Op->Mem.Base = Base;
489 Op->Mem.OffsetReg = offsetReg;
490 Op->Mem.Off = nullptr;
491 return Op;
492 }
493
494 static std::unique_ptr<SparcOperand> CreateMEMr(MCRegister Base, SMLoc S,
495 SMLoc E) {
496 auto Op = std::make_unique<SparcOperand>(k_MemoryReg);
497 Op->Mem.Base = Base;
498 Op->Mem.OffsetReg = Sparc::G0; // always 0
499 Op->Mem.Off = nullptr;
500 Op->StartLoc = S;
501 Op->EndLoc = E;
502 return Op;
503 }
504
505 static std::unique_ptr<SparcOperand>
506 MorphToMEMri(MCRegister Base, std::unique_ptr<SparcOperand> Op) {
507 const MCExpr *Imm = Op->getImm();
508 Op->Kind = k_MemoryImm;
509 Op->Mem.Base = Base;
510 Op->Mem.OffsetReg = MCRegister();
511 Op->Mem.Off = Imm;
512 return Op;
513 }
514};
515
516} // end anonymous namespace
517
518#define GET_MATCHER_IMPLEMENTATION
519#define GET_REGISTER_MATCHER
520#define GET_MNEMONIC_SPELL_CHECKER
521#include "SparcGenAsmMatcher.inc"
522
523// Use a custom function instead of the one from SparcGenAsmMatcher
524// so we can differentiate between unavailable and unknown instructions.
525SparcAsmParser::MatchResultTy
526SparcAsmParser::mnemonicIsValid(StringRef Mnemonic, unsigned VariantID) {
527 // Process all MnemonicAliases to remap the mnemonic.
528 applyMnemonicAliases(Mnemonic, getAvailableFeatures(), VariantID);
529
530 // Find the appropriate table for this asm variant.
531 const MatchEntry *Start, *End;
532 switch (VariantID) {
533 default:
534 llvm_unreachable("invalid variant!");
535 case 0:
536 Start = std::begin(MatchTable0);
537 End = std::end(MatchTable0);
538 break;
539 }
540
541 // Search the table.
542 auto MnemonicRange = std::equal_range(Start, End, Mnemonic, LessOpcode());
543
544 if (MnemonicRange.first == MnemonicRange.second)
545 return Match_MnemonicFail;
546
547 for (const MatchEntry *it = MnemonicRange.first, *ie = MnemonicRange.second;
548 it != ie; ++it) {
549 const FeatureBitset &RequiredFeatures =
550 FeatureBitsets[it->RequiredFeaturesIdx];
551 if ((getAvailableFeatures() & RequiredFeatures) == RequiredFeatures)
552 return Match_Success;
553 }
554 return Match_MissingFeature;
555}
556
557bool SparcAsmParser::expandSET(MCInst &Inst, SMLoc IDLoc,
558 SmallVectorImpl<MCInst> &Instructions) {
559 MCOperand MCRegOp = Inst.getOperand(0);
560 MCOperand MCValOp = Inst.getOperand(1);
561 assert(MCRegOp.isReg());
562 assert(MCValOp.isImm() || MCValOp.isExpr());
563
564 // the imm operand can be either an expression or an immediate.
565 bool IsImm = Inst.getOperand(1).isImm();
566 int64_t RawImmValue = IsImm ? MCValOp.getImm() : 0;
567
568 // Allow either a signed or unsigned 32-bit immediate.
569 if (RawImmValue < -2147483648LL || RawImmValue > 4294967295LL) {
570 return Error(IDLoc,
571 "set: argument must be between -2147483648 and 4294967295");
572 }
573
574 // If the value was expressed as a large unsigned number, that's ok.
575 // We want to see if it "looks like" a small signed number.
576 int32_t ImmValue = RawImmValue;
577 // For 'set' you can't use 'or' with a negative operand on V9 because
578 // that would splat the sign bit across the upper half of the destination
579 // register, whereas 'set' is defined to zero the high 32 bits.
580 bool IsEffectivelyImm13 =
581 IsImm && ((is64Bit() ? 0 : -4096) <= ImmValue && ImmValue < 4096);
582 const MCExpr *ValExpr;
583 if (IsImm)
584 ValExpr = MCConstantExpr::create(ImmValue, getContext());
585 else
586 ValExpr = MCValOp.getExpr();
587
588 MCOperand PrevReg = MCOperand::createReg(Sparc::G0);
589
590 // If not just a signed imm13 value, then either we use a 'sethi' with a
591 // following 'or', or a 'sethi' by itself if there are no more 1 bits.
592 // In either case, start with the 'sethi'.
593 if (!IsEffectivelyImm13) {
594 MCInst TmpInst;
595 const MCExpr *Expr = adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr);
596 TmpInst.setLoc(IDLoc);
597 TmpInst.setOpcode(SP::SETHIi);
598 TmpInst.addOperand(MCRegOp);
599 TmpInst.addOperand(MCOperand::createExpr(Expr));
600 Instructions.push_back(TmpInst);
601 PrevReg = MCRegOp;
602 }
603
604 // The low bits require touching in 3 cases:
605 // * A non-immediate value will always require both instructions.
606 // * An effectively imm13 value needs only an 'or' instruction.
607 // * Otherwise, an immediate that is not effectively imm13 requires the
608 // 'or' only if bits remain after clearing the 22 bits that 'sethi' set.
609 // If the low bits are known zeros, there's nothing to do.
610 // In the second case, and only in that case, must we NOT clear
611 // bits of the immediate value via the %lo() assembler function.
612 // Note also, the 'or' instruction doesn't mind a large value in the case
613 // where the operand to 'set' was 0xFFFFFzzz - it does exactly what you mean.
614 if (!IsImm || IsEffectivelyImm13 || (ImmValue & 0x3ff)) {
615 MCInst TmpInst;
616 const MCExpr *Expr;
617 if (IsEffectivelyImm13)
618 Expr = ValExpr;
619 else
620 Expr = adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr);
621 TmpInst.setLoc(IDLoc);
622 TmpInst.setOpcode(SP::ORri);
623 TmpInst.addOperand(MCRegOp);
624 TmpInst.addOperand(PrevReg);
625 TmpInst.addOperand(MCOperand::createExpr(Expr));
626 Instructions.push_back(TmpInst);
627 }
628 return false;
629}
630
631bool SparcAsmParser::expandSETSW(MCInst &Inst, SMLoc IDLoc,
632 SmallVectorImpl<MCInst> &Instructions) {
633 MCOperand MCRegOp = Inst.getOperand(0);
634 MCOperand MCValOp = Inst.getOperand(1);
635 assert(MCRegOp.isReg());
636 assert(MCValOp.isImm() || MCValOp.isExpr());
637
638 // The imm operand can be either an expression or an immediate.
639 bool IsImm = Inst.getOperand(1).isImm();
640 int64_t ImmValue = IsImm ? MCValOp.getImm() : 0;
641 const MCExpr *ValExpr = IsImm ? MCConstantExpr::create(ImmValue, getContext())
642 : MCValOp.getExpr();
643
644 bool IsSmallImm = IsImm && isInt<13>(ImmValue);
645 bool NoLowBitsImm = IsImm && ((ImmValue & 0x3FF) == 0);
646
647 MCOperand PrevReg = MCOperand::createReg(Sparc::G0);
648
649 if (!isInt<32>(ImmValue)) {
650 return Error(IDLoc,
651 "set: argument must be between -2147483648 and 2147483647");
652 }
653
654 // Very small immediates can be expressed without emitting a sethi.
655 if (!IsSmallImm) {
656 // sethi %hi(val), rd
657 Instructions.push_back(
658 MCInstBuilder(SP::SETHIi)
659 .addReg(MCRegOp.getReg())
660 .addExpr(adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr)));
661
662 PrevReg = MCRegOp;
663 }
664
665 // If the immediate has the lower bits set or is small, we need to emit an or.
666 if (!NoLowBitsImm || IsSmallImm) {
667 const MCExpr *Expr =
668 IsSmallImm ? ValExpr : adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr);
669
670 // or rd, %lo(val), rd
671 Instructions.push_back(MCInstBuilder(SP::ORri)
672 .addReg(MCRegOp.getReg())
673 .addReg(PrevReg.getReg())
674 .addExpr(Expr));
675
676 // If it's a small immediate there's nothing more to do.
677 if (IsSmallImm)
678 return false;
679 }
680
681 // Large negative or non-immediate expressions would need an sra.
682 if (!IsImm || ImmValue < 0) {
683 // sra rd, %g0, rd
684 Instructions.push_back(MCInstBuilder(SP::SRArr)
685 .addReg(MCRegOp.getReg())
686 .addReg(MCRegOp.getReg())
687 .addReg(Sparc::G0));
688 }
689
690 return false;
691}
692
693bool SparcAsmParser::expandSETX(MCInst &Inst, SMLoc IDLoc,
694 SmallVectorImpl<MCInst> &Instructions) {
695 MCOperand MCRegOp = Inst.getOperand(0);
696 MCOperand MCValOp = Inst.getOperand(1);
697 MCOperand MCTmpOp = Inst.getOperand(2);
698 assert(MCRegOp.isReg() && MCTmpOp.isReg());
699 assert(MCValOp.isImm() || MCValOp.isExpr());
700
701 // the imm operand can be either an expression or an immediate.
702 bool IsImm = MCValOp.isImm();
703 int64_t ImmValue = IsImm ? MCValOp.getImm() : 0;
704
705 const MCExpr *ValExpr = IsImm ? MCConstantExpr::create(ImmValue, getContext())
706 : MCValOp.getExpr();
707
708 // Very small immediates can be expressed directly as a single `or`.
709 if (IsImm && isInt<13>(ImmValue)) {
710 // or rd, val, rd
711 Instructions.push_back(MCInstBuilder(SP::ORri)
712 .addReg(MCRegOp.getReg())
713 .addReg(Sparc::G0)
714 .addExpr(ValExpr));
715 return false;
716 }
717
718 // Otherwise, first we set the lower half of the register.
719
720 // sethi %hi(val), rd
721 Instructions.push_back(
722 MCInstBuilder(SP::SETHIi)
723 .addReg(MCRegOp.getReg())
724 .addExpr(adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr)));
725 // or rd, %lo(val), rd
726 Instructions.push_back(
727 MCInstBuilder(SP::ORri)
728 .addReg(MCRegOp.getReg())
729 .addReg(MCRegOp.getReg())
730 .addExpr(adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr)));
731
732 // Small positive immediates can be expressed as a single `sethi`+`or`
733 // combination, so we can just return here.
734 if (IsImm && isUInt<32>(ImmValue))
735 return false;
736
737 // For bigger immediates, we need to generate the upper half, then shift and
738 // merge it with the lower half that has just been generated above.
739
740 // sethi %hh(val), tmp
741 Instructions.push_back(MCInstBuilder(SP::SETHIi)
742 .addReg(MCTmpOp.getReg())
744 ValExpr, ELF::R_SPARC_HH22, getContext())));
745 // or tmp, %hm(val), tmp
746 Instructions.push_back(MCInstBuilder(SP::ORri)
747 .addReg(MCTmpOp.getReg())
748 .addReg(MCTmpOp.getReg())
750 ValExpr, ELF::R_SPARC_HM10, getContext())));
751 // sllx tmp, 32, tmp
752 Instructions.push_back(MCInstBuilder(SP::SLLXri)
753 .addReg(MCTmpOp.getReg())
754 .addReg(MCTmpOp.getReg())
755 .addImm(32));
756 // or tmp, rd, rd
757 Instructions.push_back(MCInstBuilder(SP::ORrr)
758 .addReg(MCRegOp.getReg())
759 .addReg(MCTmpOp.getReg())
760 .addReg(MCRegOp.getReg()));
761
762 return false;
763}
764
765bool SparcAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
767 MCStreamer &Out,
768 uint64_t &ErrorInfo,
769 bool MatchingInlineAsm) {
770 MCInst Inst;
772 unsigned MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
773 MatchingInlineAsm);
774 switch (MatchResult) {
775 case Match_Success: {
776 switch (Inst.getOpcode()) {
777 default:
778 Inst.setLoc(IDLoc);
779 Instructions.push_back(Inst);
780 break;
781 case SP::SET:
782 if (expandSET(Inst, IDLoc, Instructions))
783 return true;
784 break;
785 case SP::SETSW:
786 if (expandSETSW(Inst, IDLoc, Instructions))
787 return true;
788 break;
789 case SP::SETX:
790 if (expandSETX(Inst, IDLoc, Instructions))
791 return true;
792 break;
793 }
794
795 for (const MCInst &I : Instructions) {
796 Out.emitInstruction(I, getSTI());
797 }
798 return false;
799 }
800
801 case Match_MissingFeature:
802 return Error(IDLoc,
803 "instruction requires a CPU feature not currently enabled");
804
805 case Match_InvalidOperand: {
806 SMLoc ErrorLoc = IDLoc;
807 if (ErrorInfo != ~0ULL) {
808 if (ErrorInfo >= Operands.size())
809 return Error(IDLoc, "too few operands for instruction");
810
811 ErrorLoc = ((SparcOperand &)*Operands[ErrorInfo]).getStartLoc();
812 if (ErrorLoc == SMLoc())
813 ErrorLoc = IDLoc;
814 }
815
816 return Error(ErrorLoc, "invalid operand for instruction");
817 }
818 case Match_MnemonicFail:
819 return Error(IDLoc, "invalid instruction mnemonic");
820 }
821 llvm_unreachable("Implement any new match types added!");
822}
823
824bool SparcAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
825 SMLoc &EndLoc) {
826 if (!tryParseRegister(Reg, StartLoc, EndLoc).isSuccess())
827 return Error(StartLoc, "invalid register name");
828 return false;
829}
830
831ParseStatus SparcAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
832 SMLoc &EndLoc) {
833 const AsmToken &Tok = Parser.getTok();
834 StartLoc = Tok.getLoc();
835 EndLoc = Tok.getEndLoc();
836 Reg = Sparc::NoRegister;
837 if (getLexer().getKind() != AsmToken::Percent)
839 Parser.Lex();
840 unsigned RegKind = SparcOperand::rk_None;
841 Reg = matchRegisterName(Tok, RegKind);
842 if (Reg) {
843 Parser.Lex();
845 }
846
847 getLexer().UnLex(Tok);
849}
850
851bool SparcAsmParser::parseInstruction(ParseInstructionInfo &Info,
852 StringRef Name, SMLoc NameLoc,
854 // Validate and reject unavailable mnemonics early before
855 // running any operand parsing.
856 // This is needed because some operands (mainly memory ones)
857 // differ between V8 and V9 ISA and so any operand parsing errors
858 // will cause IAS to bail out before it reaches matchAndEmitInstruction
859 // (where the instruction as a whole, including the mnemonic, is validated
860 // once again just before emission).
861 // As a nice side effect this also allows us to reject unknown
862 // instructions and suggest replacements.
863 MatchResultTy MS = mnemonicIsValid(Name, 0);
864 switch (MS) {
865 case Match_Success:
866 break;
867 case Match_MissingFeature:
868 return Error(NameLoc,
869 "instruction requires a CPU feature not currently enabled");
870 case Match_MnemonicFail:
871 return Error(NameLoc,
872 "invalid instruction mnemonic" +
873 SparcMnemonicSpellCheck(Name, getAvailableFeatures(), 0));
874 default:
875 llvm_unreachable("invalid return status!");
876 }
877
878 // First operand in MCInst is instruction mnemonic.
879 Operands.push_back(SparcOperand::CreateToken(Name, NameLoc));
880
881 // apply mnemonic aliases, if any, so that we can parse operands correctly.
882 applyMnemonicAliases(Name, getAvailableFeatures(), 0);
883
884 if (getLexer().isNot(AsmToken::EndOfStatement)) {
885 // Read the first operand.
886 if (getLexer().is(AsmToken::Comma)) {
887 if (!parseBranchModifiers(Operands).isSuccess()) {
888 SMLoc Loc = getLexer().getLoc();
889 return Error(Loc, "unexpected token");
890 }
891 }
892 if (!parseOperand(Operands, Name).isSuccess()) {
893 SMLoc Loc = getLexer().getLoc();
894 return Error(Loc, "unexpected token");
895 }
896
897 while (getLexer().is(AsmToken::Comma) || getLexer().is(AsmToken::Plus)) {
898 if (getLexer().is(AsmToken::Plus)) {
899 // Plus tokens are significant in software_traps (p83, sparcv8.pdf). We must capture them.
900 Operands.push_back(SparcOperand::CreateToken("+", Parser.getTok().getLoc()));
901 }
902 Parser.Lex(); // Eat the comma or plus.
903 // Parse and remember the operand.
904 if (!parseOperand(Operands, Name).isSuccess()) {
905 SMLoc Loc = getLexer().getLoc();
906 return Error(Loc, "unexpected token");
907 }
908 }
909 }
910 if (getLexer().isNot(AsmToken::EndOfStatement)) {
911 SMLoc Loc = getLexer().getLoc();
912 return Error(Loc, "unexpected token");
913 }
914 Parser.Lex(); // Consume the EndOfStatement.
915 return false;
916}
917
918ParseStatus SparcAsmParser::parseDirective(AsmToken DirectiveID) {
919 StringRef IDVal = DirectiveID.getString();
920
921 if (IDVal == ".register") {
922 // For now, ignore .register directive.
923 Parser.eatToEndOfStatement();
925 }
926 if (IDVal == ".proc") {
927 // For compatibility, ignore this directive.
928 // (It's supposed to be an "optimization" in the Sun assembler)
929 Parser.eatToEndOfStatement();
931 }
932 if (IDVal == ".seg") {
933 std::string Name;
934 if (Parser.parseEscapedString(Name) || Parser.parseEOL())
936
937 MCSection *Section;
938 uint32_t Subsection = 0;
939 const MCObjectFileInfo *MCOFI = getContext().getObjectFileInfo();
940 if (Name == "text") {
941 Section = MCOFI->getTextSection();
942 } else if (Name == "data" || Name == "data1") {
943 Section = MCOFI->getDataSection();
944 Subsection = Name == "data1" ? 1 : 0;
945 } else if (Name == "bss") {
946 Section = MCOFI->getBSSSection();
947 } else {
948 return Error(DirectiveID.getLoc(), "unknown segment type");
949 }
950 getStreamer().switchSection(Section, Subsection);
952 }
953
954 // Let the MC layer to handle other directives.
956}
957
958ParseStatus SparcAsmParser::parseMEMOperand(OperandVector &Operands) {
959 SMLoc S, E;
960
961 std::unique_ptr<SparcOperand> LHS;
962 if (!parseSparcAsmOperand(LHS).isSuccess())
964
965 // Single immediate operand
966 if (LHS->isImm()) {
967 Operands.push_back(SparcOperand::MorphToMEMri(Sparc::G0, std::move(LHS)));
969 }
970
971 if (!LHS->isIntReg())
972 return Error(LHS->getStartLoc(), "invalid register kind for this operand");
973
974 AsmToken Tok = getLexer().getTok();
975 // The plus token may be followed by a register or an immediate value, the
976 // minus one is always interpreted as sign for the immediate value
977 if (Tok.is(AsmToken::Plus) || Tok.is(AsmToken::Minus)) {
979
980 std::unique_ptr<SparcOperand> RHS;
981 if (!parseSparcAsmOperand(RHS).isSuccess())
983
984 if (RHS->isReg() && !RHS->isIntReg())
985 return Error(RHS->getStartLoc(),
986 "invalid register kind for this operand");
987
988 Operands.push_back(
989 RHS->isImm()
990 ? SparcOperand::MorphToMEMri(LHS->getReg(), std::move(RHS))
991 : SparcOperand::MorphToMEMrr(LHS->getReg(), std::move(RHS)));
992
994 }
995
996 Operands.push_back(SparcOperand::CreateMEMr(LHS->getReg(), S, E));
998}
999
1000template <unsigned N>
1001ParseStatus SparcAsmParser::parseShiftAmtImm(OperandVector &Operands) {
1002 SMLoc S = Parser.getTok().getLoc();
1003 SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
1004
1005 // This is a register, not an immediate
1006 if (getLexer().getKind() == AsmToken::Percent)
1007 return ParseStatus::NoMatch;
1008
1009 const MCExpr *Expr;
1010 if (getParser().parseExpression(Expr))
1011 return ParseStatus::Failure;
1012
1013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
1014 if (!CE)
1015 return Error(S, "constant expression expected");
1016
1017 if (!isUInt<N>(CE->getValue()))
1018 return Error(S, "immediate shift value out of range");
1019
1020 Operands.push_back(SparcOperand::CreateImm(Expr, S, E));
1021 return ParseStatus::Success;
1022}
1023
1024template <SparcAsmParser::TailRelocKind Kind>
1025ParseStatus SparcAsmParser::parseTailRelocSym(OperandVector &Operands) {
1026 SMLoc S = getLoc();
1027 SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
1028
1029 auto MatchesKind = [](uint16_t RelType) -> bool {
1030 switch (Kind) {
1031 case TailRelocKind::Load_GOT:
1032 // Non-TLS relocations on ld (or ldx).
1033 // ld [%rr + %rr], %rr, %rel(sym)
1034 return RelType == ELF::R_SPARC_GOTDATA_OP;
1035 case TailRelocKind::Add_TLS:
1036 // TLS relocations on add.
1037 // add %rr, %rr, %rr, %rel(sym)
1038 switch (RelType) {
1039 case ELF::R_SPARC_TLS_GD_ADD:
1040 case ELF::R_SPARC_TLS_IE_ADD:
1041 case ELF::R_SPARC_TLS_LDM_ADD:
1042 case ELF::R_SPARC_TLS_LDO_ADD:
1043 return true;
1044 default:
1045 return false;
1046 }
1047 case TailRelocKind::Load_TLS:
1048 // TLS relocations on ld (or ldx).
1049 // ld[x] %addr, %rr, %rel(sym)
1050 switch (RelType) {
1051 case ELF::R_SPARC_TLS_IE_LD:
1052 case ELF::R_SPARC_TLS_IE_LDX:
1053 return true;
1054 default:
1055 return false;
1056 }
1057 case TailRelocKind::Call_TLS:
1058 // TLS relocations on call.
1059 // call sym, %rel(sym)
1060 switch (RelType) {
1061 case ELF::R_SPARC_TLS_GD_CALL:
1062 case ELF::R_SPARC_TLS_LDM_CALL:
1063 return true;
1064 default:
1065 return false;
1066 }
1067 }
1068 llvm_unreachable("Unhandled SparcAsmParser::TailRelocKind enum");
1069 };
1070
1071 if (getLexer().getKind() != AsmToken::Percent)
1072 return ParseStatus::NoMatch;
1073
1074 const AsmToken Tok = Parser.getTok();
1075 getParser().Lex(); // Eat '%'
1076
1077 if (getLexer().getKind() != AsmToken::Identifier)
1078 return Error(getLoc(), "expected valid identifier for operand modifier");
1079
1080 StringRef Name = getParser().getTok().getIdentifier();
1081 uint16_t RelType = Sparc::parseSpecifier(Name);
1082 if (RelType == 0)
1083 return Error(getLoc(), "invalid relocation specifier");
1084
1085 if (!MatchesKind(RelType)) {
1086 // Did not match the specified set of relocation types, put '%' back.
1087 getLexer().UnLex(Tok);
1088 return ParseStatus::NoMatch;
1089 }
1090
1091 Parser.Lex(); // Eat the identifier.
1092 if (getLexer().getKind() != AsmToken::LParen)
1093 return Error(getLoc(), "expected '('");
1094
1095 getParser().Lex(); // Eat '('
1096 const MCExpr *SubExpr;
1097 if (getParser().parseParenExpression(SubExpr, E))
1098 return ParseStatus::Failure;
1099
1100 const MCExpr *Val = adjustPICRelocation(RelType, SubExpr);
1101 Operands.push_back(SparcOperand::CreateTailRelocSym(Val, S, E));
1102 return ParseStatus::Success;
1103}
1104
1105ParseStatus SparcAsmParser::parseMembarTag(OperandVector &Operands) {
1106 SMLoc S = Parser.getTok().getLoc();
1107 const MCExpr *EVal;
1108 int64_t ImmVal = 0;
1109
1110 std::unique_ptr<SparcOperand> Mask;
1111 if (parseSparcAsmOperand(Mask).isSuccess()) {
1112 if (!Mask->isImm() || !Mask->getImm()->evaluateAsAbsolute(ImmVal) ||
1113 ImmVal < 0 || ImmVal > 127)
1114 return Error(S, "invalid membar mask number");
1115 }
1116
1117 while (getLexer().getKind() == AsmToken::Hash) {
1118 SMLoc TagStart = getLexer().getLoc();
1119 Parser.Lex(); // Eat the '#'.
1120 unsigned MaskVal = StringSwitch<unsigned>(Parser.getTok().getString())
1121 .Case("LoadLoad", 0x1)
1122 .Case("StoreLoad", 0x2)
1123 .Case("LoadStore", 0x4)
1124 .Case("StoreStore", 0x8)
1125 .Case("Lookaside", 0x10)
1126 .Case("MemIssue", 0x20)
1127 .Case("Sync", 0x40)
1128 .Default(0);
1129
1130 Parser.Lex(); // Eat the identifier token.
1131
1132 if (!MaskVal)
1133 return Error(TagStart, "unknown membar tag");
1134
1135 ImmVal |= MaskVal;
1136
1137 if (getLexer().getKind() == AsmToken::Pipe)
1138 Parser.Lex(); // Eat the '|'.
1139 }
1140
1141 EVal = MCConstantExpr::create(ImmVal, getContext());
1142 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1143 Operands.push_back(SparcOperand::CreateImm(EVal, S, E));
1144 return ParseStatus::Success;
1145}
1146
1147ParseStatus SparcAsmParser::parseASITag(OperandVector &Operands) {
1148 SMLoc S = Parser.getTok().getLoc();
1149 SMLoc E = Parser.getTok().getEndLoc();
1150 int64_t ASIVal = 0;
1151
1152 if (getLexer().getKind() != AsmToken::Hash) {
1153 // If the ASI tag provided is not a named tag, then it
1154 // must be a constant expression.
1155 ParseStatus ParseExprStatus = parseExpression(ASIVal);
1156 if (!ParseExprStatus.isSuccess())
1157 return ParseExprStatus;
1158
1159 if (!isUInt<8>(ASIVal))
1160 return Error(S, "invalid ASI number, must be between 0 and 255");
1161
1162 Operands.push_back(SparcOperand::CreateASITag(ASIVal, S, E));
1163 return ParseStatus::Success;
1164 }
1165
1166 // For now we only support named tags for 64-bit/V9 systems.
1167 // TODO: add support for 32-bit/V8 systems.
1168 SMLoc TagStart = getLexer().peekTok(false).getLoc();
1169 Parser.Lex(); // Eat the '#'.
1170 const StringRef ASIName = Parser.getTok().getString();
1171 const SparcASITag::ASITag *ASITag = SparcASITag::lookupASITagByName(ASIName);
1172 if (!ASITag)
1173 ASITag = SparcASITag::lookupASITagByAltName(ASIName);
1174 Parser.Lex(); // Eat the identifier token.
1175
1176 if (!ASITag)
1177 return Error(TagStart, "unknown ASI tag");
1178
1179 ASIVal = ASITag->Encoding;
1180
1181 Operands.push_back(SparcOperand::CreateASITag(ASIVal, S, E));
1182 return ParseStatus::Success;
1183}
1184
1185ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector &Operands) {
1186 SMLoc S = Parser.getTok().getLoc();
1187 SMLoc E = Parser.getTok().getEndLoc();
1188 int64_t PrefetchVal = 0;
1189
1190 if (getLexer().getKind() != AsmToken::Hash) {
1191 // If the prefetch tag provided is not a named tag, then it
1192 // must be a constant expression.
1193 ParseStatus ParseExprStatus = parseExpression(PrefetchVal);
1194 if (!ParseExprStatus.isSuccess())
1195 return ParseExprStatus;
1196
1197 if (!isUInt<8>(PrefetchVal))
1198 return Error(S, "invalid prefetch number, must be between 0 and 31");
1199
1200 Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S, E));
1201 return ParseStatus::Success;
1202 }
1203
1204 SMLoc TagStart = getLexer().peekTok(false).getLoc();
1205 Parser.Lex(); // Eat the '#'.
1206 const StringRef PrefetchName = Parser.getTok().getString();
1207 const SparcPrefetchTag::PrefetchTag *PrefetchTag =
1208 SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
1209 Parser.Lex(); // Eat the identifier token.
1210
1211 if (!PrefetchTag)
1212 return Error(TagStart, "unknown prefetch tag");
1213
1214 PrefetchVal = PrefetchTag->Encoding;
1215
1216 Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S, E));
1217 return ParseStatus::Success;
1218}
1219
1220ParseStatus SparcAsmParser::parseCallTarget(OperandVector &Operands) {
1221 SMLoc S = Parser.getTok().getLoc();
1222 SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
1223
1224 switch (getLexer().getKind()) {
1225 default:
1226 return ParseStatus::NoMatch;
1227 case AsmToken::LParen:
1228 case AsmToken::Integer:
1230 case AsmToken::Dot:
1231 break;
1232 }
1233
1234 const MCExpr *DestValue;
1235 if (getParser().parseExpression(DestValue))
1236 return ParseStatus::NoMatch;
1237
1238 Operands.push_back(SparcOperand::CreateImm(DestValue, S, E));
1239 return ParseStatus::Success;
1240}
1241
1242ParseStatus SparcAsmParser::parseOperand(OperandVector &Operands,
1243 StringRef Mnemonic) {
1244
1245 ParseStatus Res = MatchOperandParserImpl(Operands, Mnemonic);
1246
1247 // If there wasn't a custom match, try the generic matcher below. Otherwise,
1248 // there was a match, but an error occurred, in which case, just return that
1249 // the operand parsing failed.
1250 if (Res.isSuccess() || Res.isFailure())
1251 return Res;
1252
1253 if (getLexer().is(AsmToken::LBrac)) {
1254 // Memory operand
1255 Operands.push_back(SparcOperand::CreateToken("[",
1256 Parser.getTok().getLoc()));
1257 Parser.Lex(); // Eat the [
1258
1259 if (Mnemonic == "cas" || Mnemonic == "casl" || Mnemonic == "casa" ||
1260 Mnemonic == "casx" || Mnemonic == "casxl" || Mnemonic == "casxa") {
1261 SMLoc S = Parser.getTok().getLoc();
1262 if (getLexer().getKind() != AsmToken::Percent)
1263 return ParseStatus::NoMatch;
1264 Parser.Lex(); // eat %
1265
1266 unsigned RegKind;
1267 MCRegister Reg = matchRegisterName(Parser.getTok(), RegKind);
1268 if (!Reg)
1269 return ParseStatus::NoMatch;
1270
1271 Parser.Lex(); // Eat the identifier token.
1272 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer()-1);
1273 Operands.push_back(SparcOperand::CreateReg(Reg, RegKind, S, E));
1275 } else {
1276 Res = parseMEMOperand(Operands);
1277 }
1278
1279 if (!Res.isSuccess())
1280 return Res;
1281
1282 if (!getLexer().is(AsmToken::RBrac))
1283 return ParseStatus::Failure;
1284
1285 Operands.push_back(SparcOperand::CreateToken("]",
1286 Parser.getTok().getLoc()));
1287 Parser.Lex(); // Eat the ]
1288
1289 // Parse an optional address-space identifier after the address.
1290 // This will be either an immediate constant expression, or, on 64-bit
1291 // processors, the %asi register.
1292 if (getLexer().is(AsmToken::Percent)) {
1293 SMLoc S = Parser.getTok().getLoc();
1294 if (!is64Bit())
1295 return Error(
1296 S, "malformed ASI tag, must be a constant integer expression");
1297
1298 Parser.Lex(); // Eat the %.
1299 const AsmToken Tok = Parser.getTok();
1300 if (Tok.is(AsmToken::Identifier) && Tok.getString() == "asi") {
1301 // Here we patch the MEM operand from [base + %g0] into [base + 0]
1302 // as memory operations with ASI tag stored in %asi register needs
1303 // to use immediate offset. We need to do this because Reg addressing
1304 // will be parsed as Reg+G0 initially.
1305 // This allows forms such as `ldxa [%o0] %asi, %o0` to parse correctly.
1306 SparcOperand &OldMemOp = (SparcOperand &)*Operands[Operands.size() - 2];
1307 if (OldMemOp.isMEMrr()) {
1308 if (OldMemOp.getMemOffsetReg() != Sparc::G0) {
1309 return Error(S, "invalid operand for instruction");
1310 }
1311 Operands[Operands.size() - 2] = SparcOperand::MorphToMEMri(
1312 OldMemOp.getMemBase(),
1313 SparcOperand::CreateImm(MCConstantExpr::create(0, getContext()),
1314 OldMemOp.getStartLoc(),
1315 OldMemOp.getEndLoc()));
1316 }
1317 Parser.Lex(); // Eat the identifier.
1318 // In this context, we convert the register operand into
1319 // a plain "%asi" token since the register access is already
1320 // implicit in the instruction definition and encoding.
1321 // See LoadASI/StoreASI in SparcInstrInfo.td.
1322 Operands.push_back(SparcOperand::CreateToken("%asi", S));
1323 return ParseStatus::Success;
1324 }
1325
1326 return Error(S, "malformed ASI tag, must be %asi, a constant integer "
1327 "expression, or a named tag");
1328 }
1329
1330 // If we're not at the end of statement and the next token is not a comma,
1331 // then it is an immediate ASI value.
1332 if (getLexer().isNot(AsmToken::EndOfStatement) &&
1333 getLexer().isNot(AsmToken::Comma))
1334 return parseASITag(Operands);
1335 return ParseStatus::Success;
1336 }
1337
1338 std::unique_ptr<SparcOperand> Op;
1339
1340 Res = parseSparcAsmOperand(Op);
1341 if (!Res.isSuccess() || !Op)
1342 return ParseStatus::Failure;
1343
1344 // Push the parsed operand into the list of operands
1345 Operands.push_back(std::move(Op));
1346
1347 return ParseStatus::Success;
1348}
1349
1350ParseStatus
1351SparcAsmParser::parseSparcAsmOperand(std::unique_ptr<SparcOperand> &Op) {
1352 SMLoc S = Parser.getTok().getLoc();
1353 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1354 const MCExpr *EVal;
1355
1356 Op = nullptr;
1357 switch (getLexer().getKind()) {
1358 default: break;
1359
1360 case AsmToken::Percent: {
1361 Parser.Lex(); // Eat the '%'.
1362 unsigned RegKind;
1363 if (MCRegister Reg = matchRegisterName(Parser.getTok(), RegKind)) {
1364 StringRef Name = Parser.getTok().getString();
1365 Parser.Lex(); // Eat the identifier token.
1366
1367 if (Name == "ncc")
1368 Name = is64Bit() ? "xcc" : "icc";
1369
1370 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1371 if (Reg == Sparc::ICC && Name == "xcc")
1372 Op = SparcOperand::CreateToken("%xcc", S);
1373 else
1374 Op = SparcOperand::CreateReg(Reg, RegKind, S, E);
1375 break;
1376 }
1377 ParseStatus Res = matchSparcAsmModifiers(EVal, E);
1378 if (Res.isSuccess()) {
1379 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1380 Op = SparcOperand::CreateImm(EVal, S, E);
1381 } else if (Res.isNoMatch()) {
1382 // Neither a register name nor a relocation specifier.
1383 Error(getLoc(), "invalid register name");
1384 }
1385 break;
1386 }
1387
1388 case AsmToken::Plus:
1389 case AsmToken::Minus:
1390 case AsmToken::Tilde:
1391 case AsmToken::Integer:
1392 case AsmToken::LParen:
1393 case AsmToken::Dot:
1395 if (getParser().parseExpression(EVal, E))
1396 break;
1397
1398 Op = SparcOperand::CreateImm(EVal, S, E);
1399 break;
1400 }
1402}
1403
1404ParseStatus SparcAsmParser::parseBranchModifiers(OperandVector &Operands) {
1405 // parse (,a|,pn|,pt)+
1406
1407 while (getLexer().is(AsmToken::Comma)) {
1408 Parser.Lex(); // Eat the comma
1409
1410 if (!getLexer().is(AsmToken::Identifier))
1411 return ParseStatus::Failure;
1412 StringRef modName = Parser.getTok().getString();
1413 if (modName == "a" || modName == "pn" || modName == "pt") {
1414 Operands.push_back(SparcOperand::CreateToken(modName,
1415 Parser.getTok().getLoc()));
1416 Parser.Lex(); // eat the identifier.
1417 }
1418 }
1419 return ParseStatus::Success;
1420}
1421
1422ParseStatus SparcAsmParser::parseExpression(int64_t &Val) {
1423 AsmToken Tok = getLexer().getTok();
1424
1425 if (!isPossibleExpression(Tok))
1426 return ParseStatus::NoMatch;
1427
1428 return getParser().parseAbsoluteExpression(Val);
1429}
1430
1431MCRegister SparcAsmParser::matchRegisterName(const AsmToken &Tok,
1432 unsigned &RegKind) {
1433 RegKind = SparcOperand::rk_None;
1434 if (!Tok.is(AsmToken::Identifier))
1435 return SP::NoRegister;
1436
1437 StringRef Name = Tok.getString();
1438 MCRegister Reg = MatchRegisterName(Name.lower());
1439 if (!Reg)
1440 Reg = MatchRegisterAltName(Name.lower());
1441
1442 if (Reg) {
1443 // Some registers share a spelling (e.g. "f0" for F0/D0/Q0, "sp" for
1444 // O6/O6_O7). PositionOrder in SparcRegisterInfo.td makes the generated
1445 // matcher return the canonical one.
1446
1447 // See the note in SparcRegisterInfo.td near ASRRegs register class.
1448 if (Reg == SP::ASR4 && Name == "tick") {
1449 RegKind = SparcOperand::rk_Special;
1450 return SP::TICK;
1451 }
1452
1453 if (MRI.getRegClass(SP::IntRegsRegClassID).contains(Reg)) {
1454 RegKind = SparcOperand::rk_IntReg;
1455 return Reg;
1456 }
1457
1458 // The generated matcher never returns QFP registers because of
1459 // PositionOrder.
1460 assert(!MRI.getRegClass(SP::QFPRegsRegClassID).contains(Reg));
1461
1462 // Other registers do not need special handling.
1463 RegKind = SparcOperand::rk_Special;
1464 return Reg;
1465 }
1466
1467 // If we still have no match, try custom parsing.
1468 // Not all registers and their spellings are modeled in td files.
1469
1470 // O6 and I6 have primary AsmNames "sp" and "fp", so handle "%o6"/"%i6" here.
1471 if (Name.equals_insensitive("o6")) {
1472 RegKind = SparcOperand::rk_IntReg;
1473 return SP::O6;
1474 }
1475 if (Name.equals_insensitive("i6")) {
1476 RegKind = SparcOperand::rk_IntReg;
1477 return SP::I6;
1478 }
1479
1480 // %r0 - %r31
1481 unsigned RegNo;
1482 if (Name.starts_with_insensitive("r") &&
1483 !Name.drop_front().getAsInteger(10, RegNo) && RegNo <= 31) {
1484 RegKind = SparcOperand::rk_IntReg;
1485 return IntRegs[RegNo];
1486 }
1487
1488 if (Name == "xcc" || Name == "ncc") {
1489 // FIXME:: check 64bit.
1490 RegKind = SparcOperand::rk_Special;
1491 return SP::ICC;
1492 }
1493
1494 // JPS1 extension - aliases for ASRs
1495 // Section 5.2.11 - Ancillary State Registers (ASRs)
1496 if (Name == "pcr") {
1497 RegKind = SparcOperand::rk_Special;
1498 return SP::ASR16;
1499 }
1500 if (Name == "pic") {
1501 RegKind = SparcOperand::rk_Special;
1502 return SP::ASR17;
1503 }
1504 if (Name == "dcr") {
1505 RegKind = SparcOperand::rk_Special;
1506 return SP::ASR18;
1507 }
1508 if (Name == "gsr") {
1509 RegKind = SparcOperand::rk_Special;
1510 return SP::ASR19;
1511 }
1512 if (Name == "set_softint") {
1513 RegKind = SparcOperand::rk_Special;
1514 return SP::ASR20;
1515 }
1516 if (Name == "clear_softint") {
1517 RegKind = SparcOperand::rk_Special;
1518 return SP::ASR21;
1519 }
1520 if (Name == "softint") {
1521 RegKind = SparcOperand::rk_Special;
1522 return SP::ASR22;
1523 }
1524 if (Name == "tick_cmpr") {
1525 RegKind = SparcOperand::rk_Special;
1526 return SP::ASR23;
1527 }
1528 if (Name == "stick" || Name == "sys_tick") {
1529 RegKind = SparcOperand::rk_Special;
1530 return SP::ASR24;
1531 }
1532 if (Name == "stick_cmpr" || Name == "sys_tick_cmpr") {
1533 RegKind = SparcOperand::rk_Special;
1534 return SP::ASR25;
1535 }
1536
1537 return SP::NoRegister;
1538}
1539
1540// Determine if an expression contains a reference to the symbol
1541// "_GLOBAL_OFFSET_TABLE_".
1542static bool hasGOTReference(const MCExpr *Expr) {
1543 switch (Expr->getKind()) {
1544 case MCExpr::Target:
1545 if (const MCSpecifierExpr *SE = dyn_cast<MCSpecifierExpr>(Expr))
1546 return hasGOTReference(SE->getSubExpr());
1547 break;
1548
1549 case MCExpr::Constant:
1550 break;
1551
1552 case MCExpr::Binary: {
1553 const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
1554 return hasGOTReference(BE->getLHS()) || hasGOTReference(BE->getRHS());
1555 }
1556
1557 case MCExpr::SymbolRef: {
1558 const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
1559 return (SymRef.getSymbol().getName() == "_GLOBAL_OFFSET_TABLE_");
1560 }
1561
1562 case MCExpr::Unary:
1563 return hasGOTReference(cast<MCUnaryExpr>(Expr)->getSubExpr());
1564
1565 case MCExpr::Specifier:
1566 llvm_unreachable("unused by this backend");
1567 }
1568 return false;
1569}
1570
1571const MCSpecifierExpr *
1572SparcAsmParser::adjustPICRelocation(uint16_t RelType, const MCExpr *subExpr) {
1573 // When in PIC mode, "%lo(...)" and "%hi(...)" behave differently.
1574 // If the expression refers contains _GLOBAL_OFFSET_TABLE, it is
1575 // actually a %pc10 or %pc22 relocation. Otherwise, they are interpreted
1576 // as %got10 or %got22 relocation.
1577
1578 if (getContext().getObjectFileInfo()->isPositionIndependent()) {
1579 switch (RelType) {
1580 default: break;
1581 case ELF::R_SPARC_LO10:
1582 RelType =
1583 hasGOTReference(subExpr) ? ELF::R_SPARC_PC10 : ELF::R_SPARC_GOT10;
1584 break;
1585 case ELF::R_SPARC_HI22:
1586 RelType =
1587 hasGOTReference(subExpr) ? ELF::R_SPARC_PC22 : ELF::R_SPARC_GOT22;
1588 break;
1589 }
1590 }
1591
1592 return MCSpecifierExpr::create(subExpr, RelType, getContext());
1593}
1594
1595ParseStatus SparcAsmParser::matchSparcAsmModifiers(const MCExpr *&EVal,
1596 SMLoc &EndLoc) {
1597 // A relocation specifier is an identifier followed by '('.
1598 AsmToken Tok = Parser.getTok();
1599 if (!Tok.is(AsmToken::Identifier) ||
1600 !getLexer().peekTok().is(AsmToken::LParen))
1601 return ParseStatus::NoMatch;
1602
1603 StringRef name = Tok.getString();
1604
1605 auto VK = Sparc::parseSpecifier(name);
1606 switch (VK) {
1607 case 0:
1608 return Error(getLoc(), "invalid relocation specifier");
1609
1610 case ELF::R_SPARC_GOTDATA_OP:
1611 case ELF::R_SPARC_TLS_GD_ADD:
1612 case ELF::R_SPARC_TLS_GD_CALL:
1613 case ELF::R_SPARC_TLS_IE_ADD:
1614 case ELF::R_SPARC_TLS_IE_LD:
1615 case ELF::R_SPARC_TLS_IE_LDX:
1616 case ELF::R_SPARC_TLS_LDM_ADD:
1617 case ELF::R_SPARC_TLS_LDM_CALL:
1618 case ELF::R_SPARC_TLS_LDO_ADD:
1619 // These are special-cased at tablegen level and are only valid as the
1620 // trailing relocation operand, see parseTailRelocSym.
1621 return Error(getLoc(), "unexpected relocation specifier");
1622
1623 default:
1624 break;
1625 }
1626
1627 Parser.Lex(); // Eat the identifier.
1628 Parser.Lex(); // Eat the LParen token.
1629 const MCExpr *subExpr;
1630 if (Parser.parseParenExpression(subExpr, EndLoc))
1631 return ParseStatus::Failure;
1632
1633 EVal = adjustPICRelocation(VK, subExpr);
1634 return ParseStatus::Success;
1635}
1636
1637bool SparcAsmParser::parseExprWithSpecifier(const MCExpr *&Res, SMLoc &E) {
1638 SMLoc Loc = getLoc();
1639 if (getLexer().getKind() != AsmToken::Identifier)
1640 return TokError("expected '%' relocation specifier");
1641 auto Spec = Sparc::parseDataSpecifier(Parser.getTok().getIdentifier());
1642 if (!Spec)
1643 return TokError("invalid relocation specifier");
1644
1645 Parser.Lex();
1646 if (parseToken(AsmToken::LParen, "expected '('"))
1647 return true;
1648
1649 const MCExpr *SubExpr;
1650 if (Parser.parseParenExpression(SubExpr, E))
1651 return true;
1652 Res = MCSpecifierExpr::create(SubExpr, Spec, getContext(), Loc);
1653 return false;
1654}
1655
1656bool SparcAsmParser::parseDataExpr(const MCExpr *&Res) {
1657 SMLoc EndLoc;
1658 if (parseOptionalToken(AsmToken::Percent))
1659 return parseExprWithSpecifier(Res, EndLoc);
1660 return Parser.parseExpression(Res);
1661}
1662
1663bool SparcAsmParser::isPossibleExpression(const AsmToken &Token) {
1664 switch (Token.getKind()) {
1665 case AsmToken::LParen:
1666 case AsmToken::Integer:
1668 case AsmToken::Plus:
1669 case AsmToken::Minus:
1670 case AsmToken::Tilde:
1671 return true;
1672 default:
1673 return false;
1674 }
1675}
1676
1677extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID)
static bool addCallTargetOperands(MachineInstrBuilder &CallInst, MachineIRBuilder &MIRBuilder, AMDGPUCallLowering::CallLoweringInfo &Info, bool IsDynamicVGPRChainCall=false)
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.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
loop data Loop Data Prefetch
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
MachineRegisterInfo & MRI
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
SI Fold Operands
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static const char * name
This file defines the SmallVector class.
static bool hasGOTReference(const MCExpr *Expr)
static const MCPhysReg IntRegs[32]
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcAsmParser()
static bool is64Bit(const char *name)
Value * RHS
Value * LHS
Target independent representation for an assembler token.
Definition MCAsmMacro.h:22
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
LLVM_ABI SMLoc getEndLoc() const
Definition AsmLexer.cpp:33
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Definition MCAsmMacro.h:92
Base class for user error types.
Definition Error.h:354
Container class for subtarget features.
void printExpr(raw_ostream &, const MCExpr &) const
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
virtual bool parseEscapedString(std::string &Data)=0
Parse the current token as a string which may include escaped characters and return the string conten...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression, assuming that an initial '(' has already been consumed.
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
Binary assembler expressions.
Definition MCExpr.h:298
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition MCExpr.h:445
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition MCExpr.h:448
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
@ Unary
Unary expressions.
Definition MCExpr.h:44
@ Constant
Constant expressions.
Definition MCExpr.h:42
@ SymbolRef
References to labels and assigned expressions.
Definition MCExpr.h:43
@ Target
Target specific expression.
Definition MCExpr.h:46
@ Specifier
Expression with a relocation specifier.
Definition MCExpr.h:45
@ Binary
Binary expressions.
Definition MCExpr.h:41
ExprKind getKind() const
Definition MCExpr.h:85
void setLoc(SMLoc loc)
Definition MCInst.h:207
unsigned getOpcode() const
Definition MCInst.h:202
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
MCSection * getBSSSection() const
MCSection * getTextSection() const
MCSection * getDataSection() const
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:166
int64_t getImm() const
Definition MCInst.h:84
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
bool isImm() const
Definition MCInst.h:66
bool isReg() const
Definition MCInst.h:65
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:73
const MCExpr * getExpr() const
Definition MCInst.h:118
bool isExpr() const
Definition MCInst.h:69
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr unsigned id() const
Definition MCRegister.h:82
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition MCExpr.h:494
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
Streaming machine code generation interface.
Definition MCStreamer.h:222
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:190
const MCSymbol & getSymbol() const
Definition MCExpr.h:226
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
MCTargetAsmParser - Generic interface to target specific assembly parsers.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
constexpr bool isNoMatch() const
Represents a location in source code.
Definition SMLoc.h:22
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
constexpr const char * getPointer() const
Definition SMLoc.h:33
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isIntReg(MCRegister Reg)
MCExpr const & getExpr(MCExpr const &Expr)
MCRegister matchRegisterName(StringRef Name, const MCRegisterInfo &MRI, unsigned RegClassID, unsigned AltIdx)
Match a symbolic name in RegClassID, or return an invalid register.
uint16_t parseSpecifier(StringRef name)
uint16_t parseDataSpecifier(StringRef name)
@ CE
Windows NT (Windows on ARM)
Definition MCAsmInfo.h:51
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
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
Target & getTheSparcTarget()
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Target & getTheSparcV9Target()
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Target & getTheSparcelTarget()
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
#define N
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...