24 static bool inRange(
const MCExpr *Expr, int64_t MinValue, int64_t MaxValue) {
26 int64_t
Value = CE->getValue();
27 return Value >= MinValue && Value <= MaxValue;
64 SMLoc StartLoc, EndLoc;
107 SystemZOperand(OperandKind kind,
SMLoc startLoc,
SMLoc endLoc)
108 :
Kind(kind), StartLoc(startLoc), EndLoc(endLoc)
115 else if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
123 static SystemZOperand *createInvalid(
SMLoc StartLoc,
SMLoc EndLoc) {
124 return new SystemZOperand(KindInvalid, StartLoc, EndLoc);
127 SystemZOperand *Op =
new SystemZOperand(KindToken, Loc, Loc);
128 Op->Token.Data = Str.
data();
129 Op->Token.Length = Str.
size();
134 SystemZOperand *Op =
new SystemZOperand(KindReg, StartLoc, EndLoc);
139 static SystemZOperand *createAccessReg(
unsigned Num,
SMLoc StartLoc,
141 SystemZOperand *Op =
new SystemZOperand(KindAccessReg, StartLoc, EndLoc);
145 static SystemZOperand *createImm(
const MCExpr *Expr,
SMLoc StartLoc,
147 SystemZOperand *Op =
new SystemZOperand(KindImm, StartLoc, EndLoc);
151 static SystemZOperand *createMem(
RegisterKind RegKind,
unsigned Base,
152 const MCExpr *Disp,
unsigned Index,
155 SystemZOperand *Op =
new SystemZOperand(KindMem, StartLoc, EndLoc);
156 Op->Mem.RegKind = RegKind;
158 Op->Mem.Index = Index;
160 Op->Mem.Length = Length;
166 return Kind == KindToken;
169 assert(
Kind == KindToken &&
"Not a token");
170 return StringRef(Token.Data, Token.Length);
175 return Kind == KindReg;
178 return Kind == KindReg &&
Reg.Kind == RegKind;
181 assert(
Kind == KindReg &&
"Not a register");
187 bool isAccessReg()
const {
188 return Kind == KindAccessReg;
193 return Kind == KindImm;
195 bool isImm(int64_t MinValue, int64_t MaxValue)
const {
196 return Kind == KindImm &&
inRange(Imm, MinValue, MaxValue);
198 const MCExpr *getImm()
const {
199 assert(
Kind == KindImm &&
"Not an immediate");
205 return Kind == KindMem;
208 return (
Kind == KindMem &&
209 Mem.RegKind == RegKind &&
210 (MemKind == BDXMem || !Mem.Index) &&
211 (MemKind == BDLMem) == (Mem.Length != 0));
214 return isMem(RegKind, MemKind) &&
inRange(Mem.Disp, 0, 0xfff);
217 return isMem(RegKind, MemKind) &&
inRange(Mem.Disp, -524288, 524287);
220 return isMemDisp12(RegKind, BDLMem) &&
inRange(Mem.Length, 1, 0x100);
230 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
231 assert(N == 1 &&
"Invalid number of operands");
234 void addAccessRegOperands(
MCInst &Inst,
unsigned N)
const {
235 assert(N == 1 &&
"Invalid number of operands");
236 assert(
Kind == KindAccessReg &&
"Invalid operand type");
239 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
240 assert(N == 1 &&
"Invalid number of operands");
241 addExpr(Inst, getImm());
243 void addBDAddrOperands(
MCInst &Inst,
unsigned N)
const {
244 assert(N == 2 &&
"Invalid number of operands");
245 assert(
Kind == KindMem && Mem.Index == 0 &&
"Invalid operand type");
247 addExpr(Inst, Mem.Disp);
249 void addBDXAddrOperands(
MCInst &Inst,
unsigned N)
const {
250 assert(N == 3 &&
"Invalid number of operands");
251 assert(
Kind == KindMem &&
"Invalid operand type");
253 addExpr(Inst, Mem.Disp);
256 void addBDLAddrOperands(
MCInst &Inst,
unsigned N)
const {
257 assert(N == 3 &&
"Invalid number of operands");
258 assert(
Kind == KindMem &&
"Invalid operand type");
260 addExpr(Inst, Mem.Disp);
261 addExpr(Inst, Mem.Length);
265 bool isGR32()
const {
return isReg(GR32Reg); }
266 bool isGRH32()
const {
return isReg(GRH32Reg); }
267 bool isGRX32()
const {
return false; }
268 bool isGR64()
const {
return isReg(GR64Reg); }
269 bool isGR128()
const {
return isReg(GR128Reg); }
270 bool isADDR32()
const {
return isReg(ADDR32Reg); }
271 bool isADDR64()
const {
return isReg(ADDR64Reg); }
272 bool isADDR128()
const {
return false; }
273 bool isFP32()
const {
return isReg(FP32Reg); }
274 bool isFP64()
const {
return isReg(FP64Reg); }
275 bool isFP128()
const {
return isReg(FP128Reg); }
276 bool isBDAddr32Disp12()
const {
return isMemDisp12(ADDR32Reg, BDMem); }
277 bool isBDAddr32Disp20()
const {
return isMemDisp20(ADDR32Reg, BDMem); }
278 bool isBDAddr64Disp12()
const {
return isMemDisp12(ADDR64Reg, BDMem); }
279 bool isBDAddr64Disp20()
const {
return isMemDisp20(ADDR64Reg, BDMem); }
280 bool isBDXAddr64Disp12()
const {
return isMemDisp12(ADDR64Reg, BDXMem); }
281 bool isBDXAddr64Disp20()
const {
return isMemDisp20(ADDR64Reg, BDXMem); }
282 bool isBDLAddr64Disp12Len8()
const {
return isMemDisp12Len8(ADDR64Reg); }
283 bool isU4Imm()
const {
return isImm(0, 15); }
284 bool isU6Imm()
const {
return isImm(0, 63); }
285 bool isU8Imm()
const {
return isImm(0, 255); }
286 bool isS8Imm()
const {
return isImm(-128, 127); }
287 bool isU16Imm()
const {
return isImm(0, 65535); }
288 bool isS16Imm()
const {
return isImm(-32768, 32767); }
289 bool isU32Imm()
const {
return isImm(0, (1LL << 32) - 1); }
290 bool isS32Imm()
const {
return isImm(-(1LL << 31), (1LL << 31) - 1); }
294 #define GET_ASSEMBLER_HEADER
295 #include "SystemZGenAsmMatcher.inc"
308 SMLoc StartLoc, EndLoc;
313 bool parseRegister(
Register &
Reg, RegisterGroup Group,
const unsigned *Regs,
314 bool IsAddress =
false);
320 bool parseAddress(
unsigned &Base,
const MCExpr *&Disp,
321 unsigned &Index,
const MCExpr *&Length,
339 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
344 virtual bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
351 MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
421 int64_t MinVal, int64_t MaxVal);
424 return parsePCRel(Operands, -(1LL << 16), (1LL << 16) - 1);
428 return parsePCRel(Operands, -(1LL << 32), (1LL << 32) - 1);
433 #define GET_REGISTER_MATCHER
434 #define GET_SUBTARGET_FEATURE_NAME
435 #define GET_MATCHER_IMPLEMENTATION
436 #include "SystemZGenAsmMatcher.inc"
438 void SystemZOperand::print(
raw_ostream &OS)
const {
443 bool SystemZAsmParser::parseRegister(
Register &
Reg) {
444 Reg.StartLoc = Parser.getTok().getLoc();
448 return Error(Parser.getTok().getLoc(),
"register expected");
453 return Error(Reg.StartLoc,
"invalid register");
458 return Error(Reg.StartLoc,
"invalid register");
463 return Error(Reg.StartLoc,
"invalid register");
466 if (Prefix ==
'r' && Reg.Num < 16)
468 else if (Prefix ==
'f' && Reg.Num < 16)
470 else if (Prefix ==
'a' && Reg.Num < 16)
471 Reg.Group = RegAccess;
473 return Error(Reg.StartLoc,
"invalid register");
475 Reg.EndLoc = Parser.getTok().getLoc();
484 bool SystemZAsmParser::parseRegister(
Register &Reg, RegisterGroup Group,
485 const unsigned *Regs,
bool IsAddress) {
486 if (parseRegister(Reg))
488 if (Reg.Group != Group)
489 return Error(Reg.StartLoc,
"invalid operand for instruction");
490 if (Regs && Regs[Reg.Num] == 0)
491 return Error(Reg.StartLoc,
"invalid register pair");
492 if (Reg.Num == 0 && IsAddress)
493 return Error(Reg.StartLoc,
"%r0 used in an address");
495 Reg.Num = Regs[Reg.Num];
500 SystemZAsmParser::OperandMatchResultTy
502 RegisterGroup Group,
const unsigned *Regs,
505 return MatchOperand_NoMatch;
508 bool IsAddress = (Kind == ADDR32Reg || Kind == ADDR64Reg);
509 if (parseRegister(Reg, Group, Regs, IsAddress))
510 return MatchOperand_ParseFail;
512 Operands.
push_back(SystemZOperand::createReg(Kind, Reg.Num,
513 Reg.StartLoc, Reg.EndLoc));
514 return MatchOperand_Success;
520 bool SystemZAsmParser::parseAddress(
unsigned &Base,
const MCExpr *&Disp,
521 unsigned &Index,
const MCExpr *&Length,
522 const unsigned *Regs,
525 if (getParser().parseExpression(Disp))
538 if (parseRegister(Reg, RegGR, Regs, RegKind))
546 if (getParser().parseExpression(Length))
554 if (parseRegister(Reg, RegGR, Regs, RegKind))
561 return Error(Parser.getTok().getLoc(),
"unexpected token in address");
569 SystemZAsmParser::OperandMatchResultTy
573 SMLoc StartLoc = Parser.getTok().getLoc();
574 unsigned Base, Index;
577 if (parseAddress(Base, Disp, Index, Length, Regs, RegKind))
578 return MatchOperand_ParseFail;
580 if (Index && MemKind != BDXMem)
582 Error(StartLoc,
"invalid use of indexed addressing");
583 return MatchOperand_ParseFail;
586 if (Length && MemKind != BDLMem)
588 Error(StartLoc,
"invalid use of length addressing");
589 return MatchOperand_ParseFail;
592 if (!Length && MemKind == BDLMem)
594 Error(StartLoc,
"missing length in address");
595 return MatchOperand_ParseFail;
600 Operands.
push_back(SystemZOperand::createMem(RegKind, Base, Disp, Index,
601 Length, StartLoc, EndLoc));
602 return MatchOperand_Success;
605 bool SystemZAsmParser::ParseDirective(
AsmToken DirectiveID) {
609 bool SystemZAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
612 if (parseRegister(Reg))
614 if (Reg.Group == RegGR)
616 else if (Reg.Group == RegFP)
620 return Error(Reg.StartLoc,
"invalid operand for instruction");
621 StartLoc = Reg.StartLoc;
626 bool SystemZAsmParser::
629 Operands.
push_back(SystemZOperand::createToken(Name, NameLoc));
634 if (parseOperand(Operands, Name)) {
635 Parser.eatToEndOfStatement();
642 if (parseOperand(Operands, Name)) {
643 Parser.eatToEndOfStatement();
648 SMLoc Loc = getLexer().getLoc();
649 Parser.eatToEndOfStatement();
650 return Error(Loc,
"unexpected token in argument list");
659 bool SystemZAsmParser::
664 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
665 if (ResTy == MatchOperand_Success)
671 if (ResTy == MatchOperand_ParseFail)
680 if (parseRegister(Reg))
682 Operands.
push_back(SystemZOperand::createInvalid(Reg.StartLoc, Reg.EndLoc));
689 SMLoc StartLoc = Parser.getTok().getLoc();
690 unsigned Base, Index;
691 const MCExpr *Expr, *Length;
697 if (Base || Index || Length)
698 Operands.
push_back(SystemZOperand::createInvalid(StartLoc, EndLoc));
700 Operands.
push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc));
704 bool SystemZAsmParser::
705 MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
708 bool MatchingInlineAsm) {
710 unsigned MatchResult;
712 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
714 switch (MatchResult) {
721 case Match_MissingFeature: {
722 assert(ErrorInfo &&
"Unknown missing feature!");
725 std::string Msg =
"instruction requires:";
727 for (
unsigned I = 0;
I <
sizeof(ErrorInfo) * 8 - 1; ++
I) {
728 if (ErrorInfo & Mask) {
734 return Error(IDLoc, Msg);
737 case Match_InvalidOperand: {
738 SMLoc ErrorLoc = IDLoc;
739 if (ErrorInfo != ~0U) {
740 if (ErrorInfo >= Operands.
size())
741 return Error(IDLoc,
"too few operands for instruction");
743 ErrorLoc = ((SystemZOperand*)Operands[ErrorInfo])->getStartLoc();
744 if (ErrorLoc ==
SMLoc())
747 return Error(ErrorLoc,
"invalid operand for instruction");
750 case Match_MnemonicFail:
751 return Error(IDLoc,
"invalid instruction");
757 SystemZAsmParser::OperandMatchResultTy SystemZAsmParser::
760 return MatchOperand_NoMatch;
763 if (parseRegister(Reg, RegAccess, 0))
764 return MatchOperand_ParseFail;
766 Operands.
push_back(SystemZOperand::createAccessReg(Reg.Num,
769 return MatchOperand_Success;
772 SystemZAsmParser::OperandMatchResultTy SystemZAsmParser::
774 int64_t MinVal, int64_t MaxVal) {
778 SMLoc StartLoc = Parser.getTok().getLoc();
779 if (getParser().parseExpression(Expr))
780 return MatchOperand_NoMatch;
785 int64_t
Value = CE->getValue();
787 Error(StartLoc,
"offset out of range");
788 return MatchOperand_ParseFail;
799 Operands.
push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc));
800 return MatchOperand_Success;
static bool isReg(const MCInst &MI, unsigned OpNo)
void push_back(const T &Elt)
const unsigned GR32Regs[16]
size_t size() const
size - Get the string size.
static MCOperand CreateReg(unsigned Reg)
const unsigned FP128Regs[16]
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser. The extension should use the AsmParser i...
MCTargetAsmParser - Generic interface to target specific assembly parsers.
static MCOperand CreateExpr(const MCExpr *Val)
StringRef substr(size_t Start, size_t N=npos) const
virtual void EmitInstruction(const MCInst &Inst)=0
const unsigned FP32Regs[16]
MCSymbol * CreateTempSymbol()
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
#define llvm_unreachable(msg)
AsmToken - Target independent representation for an assembler token.
const unsigned GRH32Regs[16]
const char * data() const
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
static bool inRange(const MCExpr *Expr, int64_t MinValue, int64_t MaxValue)
enable_if_c< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
virtual void EmitLabel(MCSymbol *Symbol)
void LLVMInitializeSystemZAsmParser()
const unsigned FP64Regs[16]
Promote Memory to Register
const unsigned GR128Regs[16]
const unsigned GR64Regs[16]
static SMLoc getFromPointer(const char *Ptr)
static const MCBinaryExpr * CreateAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static MCOperand CreateImm(int64_t Val)
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
static bool isMem(const MachineInstr *MI, unsigned Op)
LLVM Value Representation.
void addOperand(const MCOperand &Op)
Represents a location in source code.
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
static const char * getSubtargetFeatureName(unsigned Val)