2014-05-24 20:50:23 +08:00
|
|
|
//==- AArch64AsmParser.cpp - Parse AArch64 assembly to MCInst instructions -==//
|
2014-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "MCTargetDesc/AArch64AddressingModes.h"
|
|
|
|
#include "MCTargetDesc/AArch64MCExpr.h"
|
2015-05-24 00:15:10 +08:00
|
|
|
#include "MCTargetDesc/AArch64TargetStreamer.h"
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "Utils/AArch64BaseInfo.h"
|
2014-07-25 19:42:14 +08:00
|
|
|
#include "llvm/ADT/APInt.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2016-09-09 01:27:03 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2014-07-25 19:42:14 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
2014-10-23 04:35:57 +08:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2014-07-25 19:42:14 +08:00
|
|
|
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
|
|
|
#include "llvm/MC/MCParser/MCAsmParser.h"
|
|
|
|
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
|
2016-01-27 18:01:28 +08:00
|
|
|
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2016-09-09 01:27:03 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2014-07-25 19:42:14 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2016-06-09 10:56:40 +08:00
|
|
|
#include "llvm/Support/TargetParser.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
class AArch64Operand;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
class AArch64AsmParser : public MCTargetAsmParser {
|
2014-03-29 18:18:08 +08:00
|
|
|
private:
|
2014-03-30 03:40:32 +08:00
|
|
|
StringRef Mnemonic; ///< Instruction mnemonic.
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-07-02 12:50:23 +08:00
|
|
|
// Map of register aliases registers via the .req directive.
|
|
|
|
StringMap<std::pair<bool, unsigned> > RegisterReqs;
|
|
|
|
|
2014-06-25 00:21:38 +08:00
|
|
|
AArch64TargetStreamer &getTargetStreamer() {
|
|
|
|
MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
|
|
|
|
return static_cast<AArch64TargetStreamer &>(TS);
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:18:41 +08:00
|
|
|
SMLoc getLoc() const { return getParser().getTok().getLoc(); }
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
bool parseSysAlias(StringRef Name, SMLoc NameLoc, OperandVector &Operands);
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64CC::CondCode parseCondCodeString(StringRef Cond);
|
2014-03-29 18:18:08 +08:00
|
|
|
bool parseCondCode(OperandVector &Operands, bool invertCondCode);
|
2014-07-02 12:50:23 +08:00
|
|
|
unsigned matchRegisterNameAlias(StringRef Name, bool isVector);
|
2014-03-29 18:18:08 +08:00
|
|
|
int tryParseRegister();
|
2014-04-09 22:41:58 +08:00
|
|
|
int tryMatchVectorRegister(StringRef &Kind, bool expected);
|
2014-03-29 18:18:08 +08:00
|
|
|
bool parseRegister(OperandVector &Operands);
|
|
|
|
bool parseSymbolicImmVal(const MCExpr *&ImmVal);
|
|
|
|
bool parseVectorList(OperandVector &Operands);
|
|
|
|
bool parseOperand(OperandVector &Operands, bool isCondCode,
|
|
|
|
bool invertCondCode);
|
|
|
|
|
2014-11-11 13:18:41 +08:00
|
|
|
void Warning(SMLoc L, const Twine &Msg) { getParser().Warning(L, Msg); }
|
|
|
|
bool Error(SMLoc L, const Twine &Msg) { return getParser().Error(L, Msg); }
|
2014-03-29 18:18:08 +08:00
|
|
|
bool showMatchError(SMLoc Loc, unsigned ErrCode);
|
|
|
|
|
2016-06-09 10:56:40 +08:00
|
|
|
bool parseDirectiveArch(SMLoc L);
|
2016-04-03 03:29:52 +08:00
|
|
|
bool parseDirectiveCPU(SMLoc L);
|
2014-03-29 18:18:08 +08:00
|
|
|
bool parseDirectiveWord(unsigned Size, SMLoc L);
|
2014-10-23 04:35:57 +08:00
|
|
|
bool parseDirectiveInst(SMLoc L);
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool parseDirectiveTLSDescCall(SMLoc L);
|
|
|
|
|
|
|
|
bool parseDirectiveLOH(StringRef LOH, SMLoc L);
|
2014-06-25 00:21:38 +08:00
|
|
|
bool parseDirectiveLtorg(SMLoc L);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-07-02 12:50:23 +08:00
|
|
|
bool parseDirectiveReq(StringRef Name, SMLoc L);
|
|
|
|
bool parseDirectiveUnreq(SMLoc L);
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool validateInstruction(MCInst &Inst, SmallVectorImpl<SMLoc> &Loc);
|
|
|
|
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
|
|
|
OperandVector &Operands, MCStreamer &Out,
|
2014-08-18 19:49:42 +08:00
|
|
|
uint64_t &ErrorInfo,
|
2014-04-29 15:58:25 +08:00
|
|
|
bool MatchingInlineAsm) override;
|
2014-03-29 18:18:08 +08:00
|
|
|
/// @name Auto-generated Match Functions
|
|
|
|
/// {
|
|
|
|
|
|
|
|
#define GET_ASSEMBLER_HEADER
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64GenAsmMatcher.inc"
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
/// }
|
|
|
|
|
2014-05-12 22:13:17 +08:00
|
|
|
OperandMatchResultTy tryParseOptionalShiftExtend(OperandVector &Operands);
|
2014-03-29 18:18:08 +08:00
|
|
|
OperandMatchResultTy tryParseBarrierOperand(OperandVector &Operands);
|
2014-04-09 22:42:36 +08:00
|
|
|
OperandMatchResultTy tryParseMRSSystemRegister(OperandVector &Operands);
|
2014-04-09 22:43:06 +08:00
|
|
|
OperandMatchResultTy tryParseSysReg(OperandVector &Operands);
|
2014-03-29 18:18:08 +08:00
|
|
|
OperandMatchResultTy tryParseSysCROperand(OperandVector &Operands);
|
|
|
|
OperandMatchResultTy tryParsePrefetch(OperandVector &Operands);
|
2015-12-01 18:48:51 +08:00
|
|
|
OperandMatchResultTy tryParsePSBHint(OperandVector &Operands);
|
2014-03-29 18:18:08 +08:00
|
|
|
OperandMatchResultTy tryParseAdrpLabel(OperandVector &Operands);
|
|
|
|
OperandMatchResultTy tryParseAdrLabel(OperandVector &Operands);
|
|
|
|
OperandMatchResultTy tryParseFPImm(OperandVector &Operands);
|
2014-05-08 23:39:58 +08:00
|
|
|
OperandMatchResultTy tryParseAddSubImm(OperandVector &Operands);
|
2014-05-22 19:56:09 +08:00
|
|
|
OperandMatchResultTy tryParseGPR64sp0Operand(OperandVector &Operands);
|
2014-03-29 18:18:08 +08:00
|
|
|
bool tryParseVectorRegister(OperandVector &Operands);
|
2015-06-02 18:58:41 +08:00
|
|
|
OperandMatchResultTy tryParseGPRSeqPair(OperandVector &Operands);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
public:
|
2014-05-24 20:50:23 +08:00
|
|
|
enum AArch64MatchResultTy {
|
2014-03-29 18:18:08 +08:00
|
|
|
Match_InvalidSuffix = FIRST_TARGET_MATCH_RESULT_TY,
|
|
|
|
#define GET_OPERAND_DIAGNOSTIC_TYPES
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64GenAsmMatcher.inc"
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
2015-11-14 14:35:56 +08:00
|
|
|
AArch64AsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser,
|
2015-03-17 02:06:57 +08:00
|
|
|
const MCInstrInfo &MII, const MCTargetOptions &Options)
|
2015-11-14 13:20:05 +08:00
|
|
|
: MCTargetAsmParser(Options, STI) {
|
2015-03-17 02:06:57 +08:00
|
|
|
MCAsmParserExtension::Initialize(Parser);
|
2014-11-11 13:18:41 +08:00
|
|
|
MCStreamer &S = getParser().getStreamer();
|
|
|
|
if (S.getTargetStreamer() == nullptr)
|
|
|
|
new AArch64TargetStreamer(S);
|
2014-04-23 14:22:48 +08:00
|
|
|
|
|
|
|
// Initialize the set of available features.
|
2015-11-14 13:20:05 +08:00
|
|
|
setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:25 +08:00
|
|
|
bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
|
|
|
|
SMLoc NameLoc, OperandVector &Operands) override;
|
|
|
|
bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
|
|
|
|
bool ParseDirective(AsmToken DirectiveID) override;
|
2014-06-09 00:18:35 +08:00
|
|
|
unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
|
2014-04-29 15:58:25 +08:00
|
|
|
unsigned Kind) override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
static bool classifySymbolRef(const MCExpr *Expr,
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VariantKind &ELFRefKind,
|
2014-03-29 18:18:08 +08:00
|
|
|
MCSymbolRefExpr::VariantKind &DarwinRefKind,
|
2014-04-24 20:56:38 +08:00
|
|
|
int64_t &Addend);
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// AArch64Operand - Instances of this class represent a parsed AArch64 machine
|
2014-03-29 18:18:08 +08:00
|
|
|
/// instruction.
|
2014-05-24 20:50:23 +08:00
|
|
|
class AArch64Operand : public MCParsedAsmOperand {
|
2014-03-29 18:18:08 +08:00
|
|
|
private:
|
|
|
|
enum KindTy {
|
|
|
|
k_Immediate,
|
2014-05-08 23:39:58 +08:00
|
|
|
k_ShiftedImm,
|
2014-05-15 19:06:51 +08:00
|
|
|
k_CondCode,
|
2014-03-29 18:18:08 +08:00
|
|
|
k_Register,
|
|
|
|
k_VectorList,
|
|
|
|
k_VectorIndex,
|
|
|
|
k_Token,
|
2014-04-09 22:43:06 +08:00
|
|
|
k_SysReg,
|
2014-03-29 18:18:08 +08:00
|
|
|
k_SysCR,
|
|
|
|
k_Prefetch,
|
2014-05-12 22:13:17 +08:00
|
|
|
k_ShiftExtend,
|
2014-03-29 18:18:08 +08:00
|
|
|
k_FPImm,
|
2015-12-01 18:48:51 +08:00
|
|
|
k_Barrier,
|
|
|
|
k_PSBHint,
|
2014-03-29 18:18:08 +08:00
|
|
|
} Kind;
|
|
|
|
|
2014-05-22 19:56:09 +08:00
|
|
|
SMLoc StartLoc, EndLoc;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
struct TokOp {
|
|
|
|
const char *Data;
|
|
|
|
unsigned Length;
|
|
|
|
bool IsSuffix; // Is the operand actually a suffix on the mnemonic.
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RegOp {
|
|
|
|
unsigned RegNum;
|
|
|
|
bool isVector;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VectorListOp {
|
|
|
|
unsigned RegNum;
|
|
|
|
unsigned Count;
|
|
|
|
unsigned NumElements;
|
|
|
|
unsigned ElementKind;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VectorIndexOp {
|
|
|
|
unsigned Val;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ImmOp {
|
|
|
|
const MCExpr *Val;
|
|
|
|
};
|
|
|
|
|
2014-05-08 23:39:58 +08:00
|
|
|
struct ShiftedImmOp {
|
|
|
|
const MCExpr *Val;
|
|
|
|
unsigned ShiftAmount;
|
|
|
|
};
|
|
|
|
|
2014-05-15 19:06:51 +08:00
|
|
|
struct CondCodeOp {
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64CC::CondCode Code;
|
2014-05-15 19:06:51 +08:00
|
|
|
};
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
struct FPImmOp {
|
|
|
|
unsigned Val; // Encoded 8-bit representation.
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BarrierOp {
|
2015-03-27 01:29:53 +08:00
|
|
|
const char *Data;
|
|
|
|
unsigned Length;
|
2016-08-19 06:35:06 +08:00
|
|
|
unsigned Val; // Not the enum since not all values have names.
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
2014-04-09 22:43:06 +08:00
|
|
|
struct SysRegOp {
|
|
|
|
const char *Data;
|
|
|
|
unsigned Length;
|
2015-01-23 01:23:04 +08:00
|
|
|
uint32_t MRSReg;
|
|
|
|
uint32_t MSRReg;
|
|
|
|
uint32_t PStateField;
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SysCRImmOp {
|
|
|
|
unsigned Val;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PrefetchOp {
|
2015-03-27 01:29:53 +08:00
|
|
|
const char *Data;
|
|
|
|
unsigned Length;
|
2016-08-19 06:35:06 +08:00
|
|
|
unsigned Val;
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
2015-12-01 18:48:51 +08:00
|
|
|
struct PSBHintOp {
|
|
|
|
const char *Data;
|
|
|
|
unsigned Length;
|
2016-08-19 06:35:06 +08:00
|
|
|
unsigned Val;
|
2015-12-01 18:48:51 +08:00
|
|
|
};
|
|
|
|
|
2014-05-12 22:13:17 +08:00
|
|
|
struct ShiftExtendOp {
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType Type;
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned Amount;
|
2014-05-22 19:56:09 +08:00
|
|
|
bool HasExplicitAmount;
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ExtendOp {
|
|
|
|
unsigned Val;
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct TokOp Tok;
|
|
|
|
struct RegOp Reg;
|
|
|
|
struct VectorListOp VectorList;
|
|
|
|
struct VectorIndexOp VectorIndex;
|
|
|
|
struct ImmOp Imm;
|
2014-05-08 23:39:58 +08:00
|
|
|
struct ShiftedImmOp ShiftedImm;
|
2014-05-15 19:06:51 +08:00
|
|
|
struct CondCodeOp CondCode;
|
2014-03-29 18:18:08 +08:00
|
|
|
struct FPImmOp FPImm;
|
|
|
|
struct BarrierOp Barrier;
|
2014-04-09 22:43:06 +08:00
|
|
|
struct SysRegOp SysReg;
|
2014-03-29 18:18:08 +08:00
|
|
|
struct SysCRImmOp SysCRImm;
|
|
|
|
struct PrefetchOp Prefetch;
|
2015-12-01 18:48:51 +08:00
|
|
|
struct PSBHintOp PSBHint;
|
2014-05-12 22:13:17 +08:00
|
|
|
struct ShiftExtendOp ShiftExtend;
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Keep the MCContext around as the MCExprs may need manipulated during
|
|
|
|
// the add<>Operands() calls.
|
|
|
|
MCContext &Ctx;
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
public:
|
2015-03-17 02:06:57 +08:00
|
|
|
AArch64Operand(KindTy K, MCContext &Ctx) : Kind(K), Ctx(Ctx) {}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand(const AArch64Operand &o) : MCParsedAsmOperand(), Ctx(o.Ctx) {
|
2014-03-29 18:18:08 +08:00
|
|
|
Kind = o.Kind;
|
|
|
|
StartLoc = o.StartLoc;
|
|
|
|
EndLoc = o.EndLoc;
|
|
|
|
switch (Kind) {
|
|
|
|
case k_Token:
|
|
|
|
Tok = o.Tok;
|
|
|
|
break;
|
|
|
|
case k_Immediate:
|
|
|
|
Imm = o.Imm;
|
|
|
|
break;
|
2014-05-08 23:39:58 +08:00
|
|
|
case k_ShiftedImm:
|
|
|
|
ShiftedImm = o.ShiftedImm;
|
|
|
|
break;
|
2014-05-15 19:06:51 +08:00
|
|
|
case k_CondCode:
|
|
|
|
CondCode = o.CondCode;
|
|
|
|
break;
|
2014-03-29 18:18:08 +08:00
|
|
|
case k_FPImm:
|
|
|
|
FPImm = o.FPImm;
|
|
|
|
break;
|
|
|
|
case k_Barrier:
|
|
|
|
Barrier = o.Barrier;
|
|
|
|
break;
|
|
|
|
case k_Register:
|
|
|
|
Reg = o.Reg;
|
|
|
|
break;
|
|
|
|
case k_VectorList:
|
|
|
|
VectorList = o.VectorList;
|
|
|
|
break;
|
|
|
|
case k_VectorIndex:
|
|
|
|
VectorIndex = o.VectorIndex;
|
|
|
|
break;
|
2014-04-09 22:43:06 +08:00
|
|
|
case k_SysReg:
|
|
|
|
SysReg = o.SysReg;
|
|
|
|
break;
|
2014-03-29 18:18:08 +08:00
|
|
|
case k_SysCR:
|
|
|
|
SysCRImm = o.SysCRImm;
|
|
|
|
break;
|
|
|
|
case k_Prefetch:
|
|
|
|
Prefetch = o.Prefetch;
|
|
|
|
break;
|
2015-12-01 18:48:51 +08:00
|
|
|
case k_PSBHint:
|
|
|
|
PSBHint = o.PSBHint;
|
|
|
|
break;
|
2014-05-12 22:13:17 +08:00
|
|
|
case k_ShiftExtend:
|
|
|
|
ShiftExtend = o.ShiftExtend;
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getStartLoc - Get the location of the first token of this operand.
|
2014-04-29 15:58:25 +08:00
|
|
|
SMLoc getStartLoc() const override { return StartLoc; }
|
2014-03-29 18:18:08 +08:00
|
|
|
/// getEndLoc - Get the location of the last token of this operand.
|
2014-04-29 15:58:25 +08:00
|
|
|
SMLoc getEndLoc() const override { return EndLoc; }
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
StringRef getToken() const {
|
|
|
|
assert(Kind == k_Token && "Invalid access!");
|
|
|
|
return StringRef(Tok.Data, Tok.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isTokenSuffix() const {
|
|
|
|
assert(Kind == k_Token && "Invalid access!");
|
|
|
|
return Tok.IsSuffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCExpr *getImm() const {
|
|
|
|
assert(Kind == k_Immediate && "Invalid access!");
|
|
|
|
return Imm.Val;
|
|
|
|
}
|
|
|
|
|
2014-05-08 23:39:58 +08:00
|
|
|
const MCExpr *getShiftedImmVal() const {
|
|
|
|
assert(Kind == k_ShiftedImm && "Invalid access!");
|
|
|
|
return ShiftedImm.Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getShiftedImmShift() const {
|
|
|
|
assert(Kind == k_ShiftedImm && "Invalid access!");
|
|
|
|
return ShiftedImm.ShiftAmount;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64CC::CondCode getCondCode() const {
|
2014-05-15 19:06:51 +08:00
|
|
|
assert(Kind == k_CondCode && "Invalid access!");
|
|
|
|
return CondCode.Code;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned getFPImm() const {
|
|
|
|
assert(Kind == k_FPImm && "Invalid access!");
|
|
|
|
return FPImm.Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getBarrier() const {
|
|
|
|
assert(Kind == k_Barrier && "Invalid access!");
|
|
|
|
return Barrier.Val;
|
|
|
|
}
|
|
|
|
|
2015-03-27 01:29:53 +08:00
|
|
|
StringRef getBarrierName() const {
|
|
|
|
assert(Kind == k_Barrier && "Invalid access!");
|
|
|
|
return StringRef(Barrier.Data, Barrier.Length);
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:25 +08:00
|
|
|
unsigned getReg() const override {
|
2014-03-29 18:18:08 +08:00
|
|
|
assert(Kind == k_Register && "Invalid access!");
|
|
|
|
return Reg.RegNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getVectorListStart() const {
|
|
|
|
assert(Kind == k_VectorList && "Invalid access!");
|
|
|
|
return VectorList.RegNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getVectorListCount() const {
|
|
|
|
assert(Kind == k_VectorList && "Invalid access!");
|
|
|
|
return VectorList.Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getVectorIndex() const {
|
|
|
|
assert(Kind == k_VectorIndex && "Invalid access!");
|
|
|
|
return VectorIndex.Val;
|
|
|
|
}
|
|
|
|
|
2014-04-09 22:43:06 +08:00
|
|
|
StringRef getSysReg() const {
|
|
|
|
assert(Kind == k_SysReg && "Invalid access!");
|
|
|
|
return StringRef(SysReg.Data, SysReg.Length);
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned getSysCR() const {
|
|
|
|
assert(Kind == k_SysCR && "Invalid access!");
|
|
|
|
return SysCRImm.Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getPrefetch() const {
|
|
|
|
assert(Kind == k_Prefetch && "Invalid access!");
|
|
|
|
return Prefetch.Val;
|
|
|
|
}
|
|
|
|
|
2015-12-01 18:48:51 +08:00
|
|
|
unsigned getPSBHint() const {
|
|
|
|
assert(Kind == k_PSBHint && "Invalid access!");
|
|
|
|
return PSBHint.Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef getPSBHintName() const {
|
|
|
|
assert(Kind == k_PSBHint && "Invalid access!");
|
|
|
|
return StringRef(PSBHint.Data, PSBHint.Length);
|
|
|
|
}
|
|
|
|
|
2015-03-27 01:29:53 +08:00
|
|
|
StringRef getPrefetchName() const {
|
|
|
|
assert(Kind == k_Prefetch && "Invalid access!");
|
|
|
|
return StringRef(Prefetch.Data, Prefetch.Length);
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType getShiftExtendType() const {
|
2014-05-12 22:13:17 +08:00
|
|
|
assert(Kind == k_ShiftExtend && "Invalid access!");
|
|
|
|
return ShiftExtend.Type;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned getShiftExtendAmount() const {
|
|
|
|
assert(Kind == k_ShiftExtend && "Invalid access!");
|
|
|
|
return ShiftExtend.Amount;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-22 19:56:09 +08:00
|
|
|
bool hasShiftExtendAmount() const {
|
|
|
|
assert(Kind == k_ShiftExtend && "Invalid access!");
|
|
|
|
return ShiftExtend.HasExplicitAmount;
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:25 +08:00
|
|
|
bool isImm() const override { return Kind == k_Immediate; }
|
2014-05-22 19:56:09 +08:00
|
|
|
bool isMem() const override { return false; }
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isSImm9() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= -256 && Val < 256);
|
|
|
|
}
|
|
|
|
bool isSImm7s4() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= -256 && Val <= 252 && (Val & 3) == 0);
|
|
|
|
}
|
|
|
|
bool isSImm7s8() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= -512 && Val <= 504 && (Val & 7) == 0);
|
|
|
|
}
|
|
|
|
bool isSImm7s16() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= -1024 && Val <= 1008 && (Val & 15) == 0);
|
|
|
|
}
|
2014-05-22 19:56:09 +08:00
|
|
|
|
|
|
|
bool isSymbolicUImm12Offset(const MCExpr *Expr, unsigned Scale) const {
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VariantKind ELFRefKind;
|
2014-05-22 19:56:09 +08:00
|
|
|
MCSymbolRefExpr::VariantKind DarwinRefKind;
|
|
|
|
int64_t Addend;
|
2014-05-24 20:50:23 +08:00
|
|
|
if (!AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
|
2014-05-22 19:56:09 +08:00
|
|
|
Addend)) {
|
|
|
|
// If we don't understand the expression, assume the best and
|
|
|
|
// let the fixup and relocation code deal with it.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
|
2014-05-24 20:50:23 +08:00
|
|
|
ELFRefKind == AArch64MCExpr::VK_LO12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_GOT_LO12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_TPREL_LO12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_GOTTPREL_LO12_NC ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12) {
|
2014-05-22 19:56:09 +08:00
|
|
|
// Note that we don't range-check the addend. It's adjusted modulo page
|
|
|
|
// size when converted, so there is no "out of range" condition when using
|
|
|
|
// @pageoff.
|
|
|
|
return Addend >= 0 && (Addend % Scale) == 0;
|
|
|
|
} else if (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF ||
|
|
|
|
DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF) {
|
|
|
|
// @gotpageoff/@tlvppageoff can only be used directly, not with an addend.
|
|
|
|
return Addend == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <int Scale> bool isUImm12Offset() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return isSymbolicUImm12Offset(getImm(), Scale);
|
|
|
|
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val % Scale) == 0 && Val >= 0 && (Val / Scale) < 0x1000;
|
|
|
|
}
|
|
|
|
|
2015-10-05 21:42:31 +08:00
|
|
|
bool isImm0_1() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 2);
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isImm0_7() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 8);
|
|
|
|
}
|
|
|
|
bool isImm1_8() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val > 0 && Val < 9);
|
|
|
|
}
|
|
|
|
bool isImm0_15() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 16);
|
|
|
|
}
|
|
|
|
bool isImm1_16() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val > 0 && Val < 17);
|
|
|
|
}
|
|
|
|
bool isImm0_31() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 32);
|
|
|
|
}
|
|
|
|
bool isImm1_31() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 1 && Val < 32);
|
|
|
|
}
|
|
|
|
bool isImm1_32() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 1 && Val < 33);
|
|
|
|
}
|
|
|
|
bool isImm0_63() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 64);
|
|
|
|
}
|
|
|
|
bool isImm1_63() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 1 && Val < 64);
|
|
|
|
}
|
|
|
|
bool isImm1_64() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 1 && Val < 65);
|
|
|
|
}
|
|
|
|
bool isImm0_127() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 128);
|
|
|
|
}
|
|
|
|
bool isImm0_255() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 256);
|
|
|
|
}
|
|
|
|
bool isImm0_65535() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 0 && Val < 65536);
|
|
|
|
}
|
2014-05-19 23:58:15 +08:00
|
|
|
bool isImm32_63() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
return (Val >= 32 && Val < 64);
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isLogicalImm32() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
2014-07-08 17:53:04 +08:00
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
if (Val >> 32 != 0 && Val >> 32 != ~0LL)
|
|
|
|
return false;
|
|
|
|
Val &= 0xFFFFFFFF;
|
|
|
|
return AArch64_AM::isLogicalImmediate(Val, 32);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
bool isLogicalImm64() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64_AM::isLogicalImmediate(MCE->getValue(), 64);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
[AArch64] Add logical alias instructions to MC AsmParser
This patch teaches the AsmParser to accept some logical+immediate
instructions and convert them as shown:
bic Rd, Rn, #imm -> and Rd, Rn, #~imm
bics Rd, Rn, #imm -> ands Rd, Rn, #~imm
orn Rd, Rn, #imm -> orr Rd, Rn, #~imm
eon Rd, Rn, #imm -> eor Rd, Rn, #~imm
Those instructions are an alternate syntax available to assembly coders,
and are needed in order to support code already compiling with some other
assemblers. For example, the bic construct is used by the linux kernel.
llvm-svn: 212722
2014-07-10 23:12:26 +08:00
|
|
|
bool isLogicalImm32Not() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
int64_t Val = ~MCE->getValue() & 0xFFFFFFFF;
|
|
|
|
return AArch64_AM::isLogicalImmediate(Val, 32);
|
|
|
|
}
|
|
|
|
bool isLogicalImm64Not() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
|
|
|
return AArch64_AM::isLogicalImmediate(~MCE->getValue(), 64);
|
|
|
|
}
|
2014-05-08 23:39:58 +08:00
|
|
|
bool isShiftedImm() const { return Kind == k_ShiftedImm; }
|
|
|
|
bool isAddSubImm() const {
|
|
|
|
if (!isShiftedImm() && !isImm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const MCExpr *Expr;
|
|
|
|
|
|
|
|
// An ADD/SUB shifter is either 'lsl #0' or 'lsl #12'.
|
|
|
|
if (isShiftedImm()) {
|
|
|
|
unsigned Shift = ShiftedImm.ShiftAmount;
|
|
|
|
Expr = ShiftedImm.Val;
|
|
|
|
if (Shift != 0 && Shift != 12)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
Expr = getImm();
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VariantKind ELFRefKind;
|
2014-05-08 23:39:58 +08:00
|
|
|
MCSymbolRefExpr::VariantKind DarwinRefKind;
|
|
|
|
int64_t Addend;
|
2014-05-24 20:50:23 +08:00
|
|
|
if (AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind,
|
2014-05-08 23:39:58 +08:00
|
|
|
DarwinRefKind, Addend)) {
|
|
|
|
return DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF
|
|
|
|
|| DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF
|
|
|
|
|| (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF && Addend == 0)
|
2014-05-24 20:50:23 +08:00
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_LO12
|
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_DTPREL_HI12
|
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12
|
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC
|
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_TPREL_HI12
|
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_TPREL_LO12
|
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC
|
|
|
|
|| ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12;
|
2014-05-08 23:39:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise it should be a real immediate in range:
|
|
|
|
const MCConstantExpr *CE = cast<MCConstantExpr>(Expr);
|
|
|
|
return CE->getValue() >= 0 && CE->getValue() <= 0xfff;
|
|
|
|
}
|
[AArch64] Implement add/adds/sub/subs/cmp/cmn with negative immediate aliases
This patch teaches the AsmParser to accept add/adds/sub/subs/cmp/cmn
with a negative immediate operand and convert them as shown:
add Rd, Rn, -imm -> sub Rd, Rn, imm
sub Rd, Rn, -imm -> add Rd, Rn, imm
adds Rd, Rn, -imm -> subs Rd, Rn, imm
subs Rd, Rn, -imm -> adds Rd, Rn, imm
cmp Rn, -imm -> cmn Rn, imm
cmn Rn, -imm -> cmp Rn, imm
Those instructions are an alternate syntax available to assembly coders,
and are needed in order to support code already compiling with some other
assemblers (gas). They are documented in the "ARMv8 Instruction Set
Overview", in the "Arithmetic (immediate)" section. This makes llvm-mc
a programmer-friendly assembler !
This also fixes PR20978: "Assembly handling of adding negative numbers
not as smart as gas".
llvm-svn: 241166
2015-07-01 23:05:58 +08:00
|
|
|
bool isAddSubImmNeg() const {
|
|
|
|
if (!isShiftedImm() && !isImm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const MCExpr *Expr;
|
|
|
|
|
|
|
|
// An ADD/SUB shifter is either 'lsl #0' or 'lsl #12'.
|
|
|
|
if (isShiftedImm()) {
|
|
|
|
unsigned Shift = ShiftedImm.ShiftAmount;
|
|
|
|
Expr = ShiftedImm.Val;
|
|
|
|
if (Shift != 0 && Shift != 12)
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
Expr = getImm();
|
|
|
|
|
|
|
|
// Otherwise it should be a real negative immediate in range:
|
|
|
|
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
|
|
|
|
return CE != nullptr && CE->getValue() < 0 && -CE->getValue() <= 0xfff;
|
|
|
|
}
|
2014-05-15 19:06:51 +08:00
|
|
|
bool isCondCode() const { return Kind == k_CondCode; }
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isSIMDImmType10() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return false;
|
2014-05-24 20:50:23 +08:00
|
|
|
return AArch64_AM::isAdvSIMDModImmType10(MCE->getValue());
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
bool isBranchTarget26() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return true;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
if (Val & 0x3)
|
|
|
|
return false;
|
|
|
|
return (Val >= -(0x2000000 << 2) && Val <= (0x1ffffff << 2));
|
|
|
|
}
|
2014-04-24 20:12:10 +08:00
|
|
|
bool isPCRelLabel19() const {
|
2014-03-29 18:18:08 +08:00
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return true;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
if (Val & 0x3)
|
|
|
|
return false;
|
|
|
|
return (Val >= -(0x40000 << 2) && Val <= (0x3ffff << 2));
|
|
|
|
}
|
|
|
|
bool isBranchTarget14() const {
|
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
return true;
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
if (Val & 0x3)
|
|
|
|
return false;
|
|
|
|
return (Val >= -(0x2000 << 2) && Val <= (0x1fff << 2));
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool
|
|
|
|
isMovWSymbol(ArrayRef<AArch64MCExpr::VariantKind> AllowedModifiers) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VariantKind ELFRefKind;
|
2014-03-29 18:18:08 +08:00
|
|
|
MCSymbolRefExpr::VariantKind DarwinRefKind;
|
2014-04-24 20:56:38 +08:00
|
|
|
int64_t Addend;
|
2014-05-24 20:50:23 +08:00
|
|
|
if (!AArch64AsmParser::classifySymbolRef(getImm(), ELFRefKind,
|
|
|
|
DarwinRefKind, Addend)) {
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (DarwinRefKind != MCSymbolRefExpr::VK_None)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i != AllowedModifiers.size(); ++i) {
|
|
|
|
if (ELFRefKind == AllowedModifiers[i])
|
|
|
|
return Addend == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isMovZSymbolG3() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol(AArch64MCExpr::VK_ABS_G3);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMovZSymbolG2() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol({AArch64MCExpr::VK_ABS_G2, AArch64MCExpr::VK_ABS_G2_S,
|
|
|
|
AArch64MCExpr::VK_TPREL_G2,
|
|
|
|
AArch64MCExpr::VK_DTPREL_G2});
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMovZSymbolG1() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol({
|
|
|
|
AArch64MCExpr::VK_ABS_G1, AArch64MCExpr::VK_ABS_G1_S,
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VK_GOTTPREL_G1, AArch64MCExpr::VK_TPREL_G1,
|
|
|
|
AArch64MCExpr::VK_DTPREL_G1,
|
2015-03-09 00:07:39 +08:00
|
|
|
});
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMovZSymbolG0() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol({AArch64MCExpr::VK_ABS_G0, AArch64MCExpr::VK_ABS_G0_S,
|
|
|
|
AArch64MCExpr::VK_TPREL_G0,
|
|
|
|
AArch64MCExpr::VK_DTPREL_G0});
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-24 20:56:27 +08:00
|
|
|
bool isMovKSymbolG3() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol(AArch64MCExpr::VK_ABS_G3);
|
2014-04-24 20:56:27 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isMovKSymbolG2() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol(AArch64MCExpr::VK_ABS_G2_NC);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMovKSymbolG1() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol({AArch64MCExpr::VK_ABS_G1_NC,
|
|
|
|
AArch64MCExpr::VK_TPREL_G1_NC,
|
|
|
|
AArch64MCExpr::VK_DTPREL_G1_NC});
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMovKSymbolG0() const {
|
2015-03-09 00:07:39 +08:00
|
|
|
return isMovWSymbol(
|
|
|
|
{AArch64MCExpr::VK_ABS_G0_NC, AArch64MCExpr::VK_GOTTPREL_G0_NC,
|
|
|
|
AArch64MCExpr::VK_TPREL_G0_NC, AArch64MCExpr::VK_DTPREL_G0_NC});
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-13 02:03:36 +08:00
|
|
|
template<int RegWidth, int Shift>
|
|
|
|
bool isMOVZMovAlias() const {
|
|
|
|
if (!isImm()) return false;
|
|
|
|
|
|
|
|
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!CE) return false;
|
|
|
|
uint64_t Value = CE->getValue();
|
|
|
|
|
2016-06-16 09:42:25 +08:00
|
|
|
return AArch64_AM::isMOVZMovAlias(Value, Shift, RegWidth);
|
2014-05-13 02:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int RegWidth, int Shift>
|
|
|
|
bool isMOVNMovAlias() const {
|
|
|
|
if (!isImm()) return false;
|
|
|
|
|
|
|
|
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!CE) return false;
|
|
|
|
uint64_t Value = CE->getValue();
|
|
|
|
|
2016-06-16 09:42:25 +08:00
|
|
|
return AArch64_AM::isMOVNMovAlias(Value, Shift, RegWidth);
|
2014-05-13 02:03:36 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isFPImm() const { return Kind == k_FPImm; }
|
|
|
|
bool isBarrier() const { return Kind == k_Barrier; }
|
2014-04-09 22:43:06 +08:00
|
|
|
bool isSysReg() const { return Kind == k_SysReg; }
|
|
|
|
bool isMRSSystemRegister() const {
|
|
|
|
if (!isSysReg()) return false;
|
|
|
|
|
2015-01-23 01:23:04 +08:00
|
|
|
return SysReg.MRSReg != -1U;
|
2014-04-09 22:43:06 +08:00
|
|
|
}
|
|
|
|
bool isMSRSystemRegister() const {
|
|
|
|
if (!isSysReg()) return false;
|
2015-01-23 01:23:04 +08:00
|
|
|
return SysReg.MSRReg != -1U;
|
2014-04-09 22:43:06 +08:00
|
|
|
}
|
2015-10-05 21:42:31 +08:00
|
|
|
bool isSystemPStateFieldWithImm0_1() const {
|
2014-04-09 22:43:06 +08:00
|
|
|
if (!isSysReg()) return false;
|
2015-11-26 23:32:30 +08:00
|
|
|
return (SysReg.PStateField == AArch64PState::PAN ||
|
|
|
|
SysReg.PStateField == AArch64PState::UAO);
|
2015-10-05 21:42:31 +08:00
|
|
|
}
|
|
|
|
bool isSystemPStateFieldWithImm0_15() const {
|
|
|
|
if (!isSysReg() || isSystemPStateFieldWithImm0_1()) return false;
|
2015-01-23 01:23:04 +08:00
|
|
|
return SysReg.PStateField != -1U;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
2014-04-29 15:58:25 +08:00
|
|
|
bool isReg() const override { return Kind == k_Register && !Reg.isVector; }
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isVectorReg() const { return Kind == k_Register && Reg.isVector; }
|
2014-04-28 19:27:43 +08:00
|
|
|
bool isVectorRegLo() const {
|
|
|
|
return Kind == k_Register && Reg.isVector &&
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCRegisterClasses[AArch64::FPR128_loRegClassID].contains(
|
|
|
|
Reg.RegNum);
|
2014-04-28 19:27:43 +08:00
|
|
|
}
|
2014-05-19 23:58:15 +08:00
|
|
|
bool isGPR32as64() const {
|
|
|
|
return Kind == k_Register && !Reg.isVector &&
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCRegisterClasses[AArch64::GPR64RegClassID].contains(Reg.RegNum);
|
2014-05-19 23:58:15 +08:00
|
|
|
}
|
2015-06-02 18:58:41 +08:00
|
|
|
bool isWSeqPair() const {
|
|
|
|
return Kind == k_Register && !Reg.isVector &&
|
|
|
|
AArch64MCRegisterClasses[AArch64::WSeqPairsClassRegClassID].contains(
|
|
|
|
Reg.RegNum);
|
|
|
|
}
|
|
|
|
bool isXSeqPair() const {
|
|
|
|
return Kind == k_Register && !Reg.isVector &&
|
|
|
|
AArch64MCRegisterClasses[AArch64::XSeqPairsClassRegClassID].contains(
|
|
|
|
Reg.RegNum);
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-22 19:56:09 +08:00
|
|
|
bool isGPR64sp0() const {
|
|
|
|
return Kind == k_Register && !Reg.isVector &&
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCRegisterClasses[AArch64::GPR64spRegClassID].contains(Reg.RegNum);
|
2014-05-22 19:56:09 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// Is this a vector list with the type implicit (presumably attached to the
|
|
|
|
/// instruction itself)?
|
|
|
|
template <unsigned NumRegs> bool isImplicitlyTypedVectorList() const {
|
|
|
|
return Kind == k_VectorList && VectorList.Count == NumRegs &&
|
|
|
|
!VectorList.ElementKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <unsigned NumRegs, unsigned NumElements, char ElementKind>
|
|
|
|
bool isTypedVectorList() const {
|
|
|
|
if (Kind != k_VectorList)
|
|
|
|
return false;
|
|
|
|
if (VectorList.Count != NumRegs)
|
|
|
|
return false;
|
|
|
|
if (VectorList.ElementKind != ElementKind)
|
|
|
|
return false;
|
|
|
|
return VectorList.NumElements == NumElements;
|
|
|
|
}
|
|
|
|
|
2014-05-15 19:07:57 +08:00
|
|
|
bool isVectorIndex1() const {
|
|
|
|
return Kind == k_VectorIndex && VectorIndex.Val == 1;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isVectorIndexB() const {
|
|
|
|
return Kind == k_VectorIndex && VectorIndex.Val < 16;
|
|
|
|
}
|
|
|
|
bool isVectorIndexH() const {
|
|
|
|
return Kind == k_VectorIndex && VectorIndex.Val < 8;
|
|
|
|
}
|
|
|
|
bool isVectorIndexS() const {
|
|
|
|
return Kind == k_VectorIndex && VectorIndex.Val < 4;
|
|
|
|
}
|
|
|
|
bool isVectorIndexD() const {
|
|
|
|
return Kind == k_VectorIndex && VectorIndex.Val < 2;
|
|
|
|
}
|
2014-04-29 15:58:25 +08:00
|
|
|
bool isToken() const override { return Kind == k_Token; }
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isTokenEqual(StringRef Str) const {
|
|
|
|
return Kind == k_Token && getToken() == Str;
|
|
|
|
}
|
|
|
|
bool isSysCR() const { return Kind == k_SysCR; }
|
|
|
|
bool isPrefetch() const { return Kind == k_Prefetch; }
|
2015-12-01 18:48:51 +08:00
|
|
|
bool isPSBHint() const { return Kind == k_PSBHint; }
|
2014-05-12 22:13:17 +08:00
|
|
|
bool isShiftExtend() const { return Kind == k_ShiftExtend; }
|
|
|
|
bool isShifter() const {
|
|
|
|
if (!isShiftExtend())
|
|
|
|
return false;
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ST = getShiftExtendType();
|
|
|
|
return (ST == AArch64_AM::LSL || ST == AArch64_AM::LSR ||
|
|
|
|
ST == AArch64_AM::ASR || ST == AArch64_AM::ROR ||
|
|
|
|
ST == AArch64_AM::MSL);
|
2014-05-12 22:13:17 +08:00
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isExtend() const {
|
2014-05-12 22:13:17 +08:00
|
|
|
if (!isShiftExtend())
|
|
|
|
return false;
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
return (ET == AArch64_AM::UXTB || ET == AArch64_AM::SXTB ||
|
|
|
|
ET == AArch64_AM::UXTH || ET == AArch64_AM::SXTH ||
|
|
|
|
ET == AArch64_AM::UXTW || ET == AArch64_AM::SXTW ||
|
|
|
|
ET == AArch64_AM::UXTX || ET == AArch64_AM::SXTX ||
|
|
|
|
ET == AArch64_AM::LSL) &&
|
2014-05-12 22:13:17 +08:00
|
|
|
getShiftExtendAmount() <= 4;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
2014-05-12 22:13:17 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isExtend64() const {
|
2014-05-12 22:13:17 +08:00
|
|
|
if (!isExtend())
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
// UXTX and SXTX require a 64-bit source register (the ExtendLSL64 class).
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
return ET != AArch64_AM::UXTX && ET != AArch64_AM::SXTX;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
bool isExtendLSL64() const {
|
2014-05-12 22:13:17 +08:00
|
|
|
if (!isExtend())
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
return (ET == AArch64_AM::UXTX || ET == AArch64_AM::SXTX ||
|
|
|
|
ET == AArch64_AM::LSL) &&
|
|
|
|
getShiftExtendAmount() <= 4;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-22 19:56:09 +08:00
|
|
|
template<int Width> bool isMemXExtend() const {
|
|
|
|
if (!isExtend())
|
|
|
|
return false;
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
return (ET == AArch64_AM::LSL || ET == AArch64_AM::SXTX) &&
|
2014-05-22 19:56:09 +08:00
|
|
|
(getShiftExtendAmount() == Log2_32(Width / 8) ||
|
|
|
|
getShiftExtendAmount() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<int Width> bool isMemWExtend() const {
|
|
|
|
if (!isExtend())
|
|
|
|
return false;
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
return (ET == AArch64_AM::UXTW || ET == AArch64_AM::SXTW) &&
|
2014-05-22 19:56:09 +08:00
|
|
|
(getShiftExtendAmount() == Log2_32(Width / 8) ||
|
|
|
|
getShiftExtendAmount() == 0);
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:41:43 +08:00
|
|
|
template <unsigned width>
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isArithmeticShifter() const {
|
|
|
|
if (!isShifter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// An arithmetic shifter is LSL, LSR, or ASR.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ST = getShiftExtendType();
|
|
|
|
return (ST == AArch64_AM::LSL || ST == AArch64_AM::LSR ||
|
|
|
|
ST == AArch64_AM::ASR) && getShiftExtendAmount() < width;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:49:16 +08:00
|
|
|
template <unsigned width>
|
|
|
|
bool isLogicalShifter() const {
|
|
|
|
if (!isShifter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// A logical shifter is LSL, LSR, ASR or ROR.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ST = getShiftExtendType();
|
|
|
|
return (ST == AArch64_AM::LSL || ST == AArch64_AM::LSR ||
|
|
|
|
ST == AArch64_AM::ASR || ST == AArch64_AM::ROR) &&
|
2014-05-12 22:13:17 +08:00
|
|
|
getShiftExtendAmount() < width;
|
2014-05-12 19:49:16 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool isMovImm32Shifter() const {
|
|
|
|
if (!isShifter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// A MOVi shifter is LSL of 0, 16, 32, or 48.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ST = getShiftExtendType();
|
|
|
|
if (ST != AArch64_AM::LSL)
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
2014-05-12 22:13:17 +08:00
|
|
|
uint64_t Val = getShiftExtendAmount();
|
2014-03-29 18:18:08 +08:00
|
|
|
return (Val == 0 || Val == 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isMovImm64Shifter() const {
|
|
|
|
if (!isShifter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// A MOVi shifter is LSL of 0 or 16.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ST = getShiftExtendType();
|
|
|
|
if (ST != AArch64_AM::LSL)
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
2014-05-12 22:13:17 +08:00
|
|
|
uint64_t Val = getShiftExtendAmount();
|
2014-03-29 18:18:08 +08:00
|
|
|
return (Val == 0 || Val == 16 || Val == 32 || Val == 48);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isLogicalVecShifter() const {
|
|
|
|
if (!isShifter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// A logical vector shifter is a left shift by 0, 8, 16, or 24.
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned Shift = getShiftExtendAmount();
|
2014-05-24 20:50:23 +08:00
|
|
|
return getShiftExtendType() == AArch64_AM::LSL &&
|
2014-03-29 18:18:08 +08:00
|
|
|
(Shift == 0 || Shift == 8 || Shift == 16 || Shift == 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isLogicalVecHalfWordShifter() const {
|
|
|
|
if (!isLogicalVecShifter())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// A logical vector shifter is a left shift by 0 or 8.
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned Shift = getShiftExtendAmount();
|
2014-05-24 20:50:23 +08:00
|
|
|
return getShiftExtendType() == AArch64_AM::LSL &&
|
|
|
|
(Shift == 0 || Shift == 8);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMoveVecShifter() const {
|
2014-05-12 22:13:17 +08:00
|
|
|
if (!isShiftExtend())
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// A logical vector shifter is a left shift by 8 or 16.
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned Shift = getShiftExtendAmount();
|
2014-05-24 20:50:23 +08:00
|
|
|
return getShiftExtendType() == AArch64_AM::MSL &&
|
|
|
|
(Shift == 8 || Shift == 16);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback unscaled operands are for aliases of LDR/STR that fall back
|
|
|
|
// to LDUR/STUR when the offset is not legal for the former but is for
|
|
|
|
// the latter. As such, in addition to checking for being a legal unscaled
|
|
|
|
// address, also check that it is not a legal scaled address. This avoids
|
|
|
|
// ambiguity in the matcher.
|
2014-05-22 19:56:09 +08:00
|
|
|
template<int Width>
|
|
|
|
bool isSImm9OffsetFB() const {
|
|
|
|
return isSImm9() && !isUImm12Offset<Width / 8>();
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isAdrpLabel() const {
|
|
|
|
// Validation was handled during parsing, so we just sanity check that
|
|
|
|
// something didn't go haywire.
|
2014-04-09 22:44:12 +08:00
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
|
|
|
|
int64_t Val = CE->getValue();
|
|
|
|
int64_t Min = - (4096 * (1LL << (21 - 1)));
|
|
|
|
int64_t Max = 4096 * ((1LL << (21 - 1)) - 1);
|
|
|
|
return (Val % 4096) == 0 && Val >= Min && Val <= Max;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isAdrLabel() const {
|
|
|
|
// Validation was handled during parsing, so we just sanity check that
|
|
|
|
// something didn't go haywire.
|
2014-04-09 22:44:12 +08:00
|
|
|
if (!isImm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
|
|
|
|
int64_t Val = CE->getValue();
|
|
|
|
int64_t Min = - (1LL << (21 - 1));
|
|
|
|
int64_t Max = ((1LL << (21 - 1)) - 1);
|
|
|
|
return Val >= Min && Val <= Max;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addExpr(MCInst &Inst, const MCExpr *Expr) const {
|
|
|
|
// Add as immediates when possible. Null MCExpr = 0.
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!Expr)
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(0));
|
2014-03-29 18:18:08 +08:00
|
|
|
else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(CE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
else
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createExpr(Expr));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addRegOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(getReg()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-19 23:58:15 +08:00
|
|
|
void addGPR32as64Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-05-24 20:50:23 +08:00
|
|
|
assert(
|
|
|
|
AArch64MCRegisterClasses[AArch64::GPR64RegClassID].contains(getReg()));
|
2014-05-19 23:58:15 +08:00
|
|
|
|
|
|
|
const MCRegisterInfo *RI = Ctx.getRegisterInfo();
|
2014-05-24 20:50:23 +08:00
|
|
|
uint32_t Reg = RI->getRegClass(AArch64::GPR32RegClassID).getRegister(
|
2014-05-19 23:58:15 +08:00
|
|
|
RI->getEncodingValue(getReg()));
|
|
|
|
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(Reg));
|
2014-05-19 23:58:15 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 19:16:19 +08:00
|
|
|
void addVectorReg64Operands(MCInst &Inst, unsigned N) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-05-24 20:50:23 +08:00
|
|
|
assert(
|
|
|
|
AArch64MCRegisterClasses[AArch64::FPR128RegClassID].contains(getReg()));
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(AArch64::D0 + getReg() - AArch64::Q0));
|
2014-05-15 19:16:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addVectorReg128Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-05-24 20:50:23 +08:00
|
|
|
assert(
|
|
|
|
AArch64MCRegisterClasses[AArch64::FPR128RegClassID].contains(getReg()));
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(getReg()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-28 19:27:43 +08:00
|
|
|
void addVectorRegLoOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(getReg()));
|
2014-04-28 19:27:43 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
template <unsigned NumRegs>
|
|
|
|
void addVectorList64Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-10-18 13:15:34 +08:00
|
|
|
static const unsigned FirstRegs[] = { AArch64::D0,
|
|
|
|
AArch64::D0_D1,
|
|
|
|
AArch64::D0_D1_D2,
|
|
|
|
AArch64::D0_D1_D2_D3 };
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned FirstReg = FirstRegs[NumRegs - 1];
|
|
|
|
|
|
|
|
Inst.addOperand(
|
2015-05-14 02:37:00 +08:00
|
|
|
MCOperand::createReg(FirstReg + getVectorListStart() - AArch64::Q0));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <unsigned NumRegs>
|
|
|
|
void addVectorList128Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-10-18 13:15:34 +08:00
|
|
|
static const unsigned FirstRegs[] = { AArch64::Q0,
|
|
|
|
AArch64::Q0_Q1,
|
|
|
|
AArch64::Q0_Q1_Q2,
|
|
|
|
AArch64::Q0_Q1_Q2_Q3 };
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned FirstReg = FirstRegs[NumRegs - 1];
|
|
|
|
|
|
|
|
Inst.addOperand(
|
2015-05-14 02:37:00 +08:00
|
|
|
MCOperand::createReg(FirstReg + getVectorListStart() - AArch64::Q0));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 19:07:57 +08:00
|
|
|
void addVectorIndex1Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getVectorIndex()));
|
2014-05-15 19:07:57 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
void addVectorIndexBOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getVectorIndex()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addVectorIndexHOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getVectorIndex()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addVectorIndexSOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getVectorIndex()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addVectorIndexDOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getVectorIndex()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImmOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
// If this is a pageoff symrefexpr with an addend, adjust the addend
|
|
|
|
// to be only the page-offset portion. Otherwise, just add the expr
|
|
|
|
// as-is.
|
|
|
|
addExpr(Inst, getImm());
|
|
|
|
}
|
|
|
|
|
2014-05-08 23:39:58 +08:00
|
|
|
void addAddSubImmOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 2 && "Invalid number of operands!");
|
|
|
|
if (isShiftedImm()) {
|
|
|
|
addExpr(Inst, getShiftedImmVal());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getShiftedImmShift()));
|
2014-05-08 23:39:58 +08:00
|
|
|
} else {
|
|
|
|
addExpr(Inst, getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(0));
|
2014-05-08 23:39:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[AArch64] Implement add/adds/sub/subs/cmp/cmn with negative immediate aliases
This patch teaches the AsmParser to accept add/adds/sub/subs/cmp/cmn
with a negative immediate operand and convert them as shown:
add Rd, Rn, -imm -> sub Rd, Rn, imm
sub Rd, Rn, -imm -> add Rd, Rn, imm
adds Rd, Rn, -imm -> subs Rd, Rn, imm
subs Rd, Rn, -imm -> adds Rd, Rn, imm
cmp Rn, -imm -> cmn Rn, imm
cmn Rn, -imm -> cmp Rn, imm
Those instructions are an alternate syntax available to assembly coders,
and are needed in order to support code already compiling with some other
assemblers (gas). They are documented in the "ARMv8 Instruction Set
Overview", in the "Arithmetic (immediate)" section. This makes llvm-mc
a programmer-friendly assembler !
This also fixes PR20978: "Assembly handling of adding negative numbers
not as smart as gas".
llvm-svn: 241166
2015-07-01 23:05:58 +08:00
|
|
|
void addAddSubImmNegOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 2 && "Invalid number of operands!");
|
|
|
|
|
|
|
|
const MCExpr *MCE = isShiftedImm() ? getShiftedImmVal() : getImm();
|
|
|
|
const MCConstantExpr *CE = cast<MCConstantExpr>(MCE);
|
|
|
|
int64_t Val = -CE->getValue();
|
|
|
|
unsigned ShiftAmt = isShiftedImm() ? ShiftedImm.ShiftAmount : 0;
|
|
|
|
|
|
|
|
Inst.addOperand(MCOperand::createImm(Val));
|
|
|
|
Inst.addOperand(MCOperand::createImm(ShiftAmt));
|
|
|
|
}
|
|
|
|
|
2014-05-15 19:06:51 +08:00
|
|
|
void addCondCodeOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getCondCode()));
|
2014-05-15 19:06:51 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
void addAdrpLabelOperands(MCInst &Inst, unsigned N) const {
|
2014-04-09 22:44:12 +08:00
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE)
|
|
|
|
addExpr(Inst, getImm());
|
|
|
|
else
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() >> 12));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
addImmOperands(Inst, N);
|
|
|
|
}
|
|
|
|
|
2014-05-22 19:56:09 +08:00
|
|
|
template<int Scale>
|
|
|
|
void addUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
|
|
|
|
if (!MCE) {
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createExpr(getImm()));
|
2014-05-22 19:56:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() / Scale));
|
2014-05-22 19:56:09 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
void addSImm9Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addSImm7s4Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() / 4));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addSImm7s8Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() / 8));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addSImm7s16Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() / 16));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2015-10-05 21:42:31 +08:00
|
|
|
void addImm0_1Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
void addImm0_7Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm1_8Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm0_15Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm1_16Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2014-03-29 18:18:08 +08:00
|
|
|
assert(MCE && "Invalid constant immediate operand!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm0_31Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm1_31Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm1_32Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm0_63Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm1_63Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm1_64Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm0_127Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm0_255Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addImm0_65535Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-19 23:58:15 +08:00
|
|
|
void addImm32_63Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue()));
|
2014-05-19 23:58:15 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
void addLogicalImm32Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2014-07-08 17:53:04 +08:00
|
|
|
uint64_t encoding =
|
|
|
|
AArch64_AM::encodeLogicalImmediate(MCE->getValue() & 0xFFFFFFFF, 32);
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(encoding));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addLogicalImm64Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2014-05-24 20:50:23 +08:00
|
|
|
uint64_t encoding = AArch64_AM::encodeLogicalImmediate(MCE->getValue(), 64);
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(encoding));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
[AArch64] Add logical alias instructions to MC AsmParser
This patch teaches the AsmParser to accept some logical+immediate
instructions and convert them as shown:
bic Rd, Rn, #imm -> and Rd, Rn, #~imm
bics Rd, Rn, #imm -> ands Rd, Rn, #~imm
orn Rd, Rn, #imm -> orr Rd, Rn, #~imm
eon Rd, Rn, #imm -> eor Rd, Rn, #~imm
Those instructions are an alternate syntax available to assembly coders,
and are needed in order to support code already compiling with some other
assemblers. For example, the bic construct is used by the linux kernel.
llvm-svn: 212722
2014-07-10 23:12:26 +08:00
|
|
|
void addLogicalImm32NotOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
|
|
|
int64_t Val = ~MCE->getValue() & 0xFFFFFFFF;
|
|
|
|
uint64_t encoding = AArch64_AM::encodeLogicalImmediate(Val, 32);
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(encoding));
|
[AArch64] Add logical alias instructions to MC AsmParser
This patch teaches the AsmParser to accept some logical+immediate
instructions and convert them as shown:
bic Rd, Rn, #imm -> and Rd, Rn, #~imm
bics Rd, Rn, #imm -> ands Rd, Rn, #~imm
orn Rd, Rn, #imm -> orr Rd, Rn, #~imm
eon Rd, Rn, #imm -> eor Rd, Rn, #~imm
Those instructions are an alternate syntax available to assembly coders,
and are needed in order to support code already compiling with some other
assemblers. For example, the bic construct is used by the linux kernel.
llvm-svn: 212722
2014-07-10 23:12:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addLogicalImm64NotOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
|
|
|
uint64_t encoding =
|
|
|
|
AArch64_AM::encodeLogicalImmediate(~MCE->getValue(), 64);
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(encoding));
|
[AArch64] Add logical alias instructions to MC AsmParser
This patch teaches the AsmParser to accept some logical+immediate
instructions and convert them as shown:
bic Rd, Rn, #imm -> and Rd, Rn, #~imm
bics Rd, Rn, #imm -> ands Rd, Rn, #~imm
orn Rd, Rn, #imm -> orr Rd, Rn, #~imm
eon Rd, Rn, #imm -> eor Rd, Rn, #~imm
Those instructions are an alternate syntax available to assembly coders,
and are needed in order to support code already compiling with some other
assemblers. For example, the bic construct is used by the linux kernel.
llvm-svn: 212722
2014-07-10 23:12:26 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
void addSIMDImmType10Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-07-18 03:08:14 +08:00
|
|
|
const MCConstantExpr *MCE = cast<MCConstantExpr>(getImm());
|
2014-05-24 20:50:23 +08:00
|
|
|
uint64_t encoding = AArch64_AM::encodeAdvSIMDModImmType10(MCE->getValue());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(encoding));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addBranchTarget26Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
// Branch operands don't encode the low bits, so shift them off
|
|
|
|
// here. If it's a label, however, just put it on directly as there's
|
|
|
|
// not enough information now to do anything.
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE) {
|
|
|
|
addExpr(Inst, getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(MCE && "Invalid constant immediate operand!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() >> 2));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-24 20:12:10 +08:00
|
|
|
void addPCRelLabel19Operands(MCInst &Inst, unsigned N) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Branch operands don't encode the low bits, so shift them off
|
|
|
|
// here. If it's a label, however, just put it on directly as there's
|
|
|
|
// not enough information now to do anything.
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE) {
|
|
|
|
addExpr(Inst, getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(MCE && "Invalid constant immediate operand!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() >> 2));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addBranchTarget14Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
// Branch operands don't encode the low bits, so shift them off
|
|
|
|
// here. If it's a label, however, just put it on directly as there's
|
|
|
|
// not enough information now to do anything.
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
|
|
|
|
if (!MCE) {
|
|
|
|
addExpr(Inst, getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(MCE && "Invalid constant immediate operand!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(MCE->getValue() >> 2));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addFPImmOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getFPImm()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addBarrierOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getBarrier()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-09 22:43:06 +08:00
|
|
|
void addMRSSystemRegisterOperands(MCInst &Inst, unsigned N) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-04-09 22:43:06 +08:00
|
|
|
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(SysReg.MRSReg));
|
2014-04-09 22:43:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addMSRSystemRegisterOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(SysReg.MSRReg));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2015-10-05 21:42:31 +08:00
|
|
|
void addSystemPStateFieldWithImm0_1Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
|
|
|
|
Inst.addOperand(MCOperand::createImm(SysReg.PStateField));
|
|
|
|
}
|
|
|
|
|
|
|
|
void addSystemPStateFieldWithImm0_15Operands(MCInst &Inst, unsigned N) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-04-09 22:43:06 +08:00
|
|
|
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(SysReg.PStateField));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addSysCROperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getSysCR()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addPrefetchOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(getPrefetch()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2015-12-01 18:48:51 +08:00
|
|
|
void addPSBHintOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
Inst.addOperand(MCOperand::createImm(getPSBHint()));
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
void addShifterOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-05-12 22:13:17 +08:00
|
|
|
unsigned Imm =
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::getShifterImm(getShiftExtendType(), getShiftExtendAmount());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(Imm));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addExtendOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
if (ET == AArch64_AM::LSL) ET = AArch64_AM::UXTW;
|
|
|
|
unsigned Imm = AArch64_AM::getArithExtendImm(ET, getShiftExtendAmount());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(Imm));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addExtend64Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
if (ET == AArch64_AM::LSL) ET = AArch64_AM::UXTX;
|
|
|
|
unsigned Imm = AArch64_AM::getArithExtendImm(ET, getShiftExtendAmount());
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(Imm));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-22 19:56:09 +08:00
|
|
|
void addMemExtendOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 2 && "Invalid number of operands!");
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
bool IsSigned = ET == AArch64_AM::SXTW || ET == AArch64_AM::SXTX;
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(IsSigned));
|
|
|
|
Inst.addOperand(MCOperand::createImm(getShiftExtendAmount() != 0));
|
2014-05-22 19:56:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// For 8-bit load/store instructions with a register offset, both the
|
|
|
|
// "DoShift" and "NoShift" variants have a shift of 0. Because of this,
|
|
|
|
// they're disambiguated by whether the shift was explicit or implicit rather
|
|
|
|
// than its size.
|
|
|
|
void addMemExtend8Operands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 2 && "Invalid number of operands!");
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ET = getShiftExtendType();
|
|
|
|
bool IsSigned = ET == AArch64_AM::SXTW || ET == AArch64_AM::SXTX;
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(IsSigned));
|
|
|
|
Inst.addOperand(MCOperand::createImm(hasShiftExtendAmount()));
|
2014-05-22 19:56:09 +08:00
|
|
|
}
|
|
|
|
|
2014-05-13 02:03:36 +08:00
|
|
|
template<int Shift>
|
|
|
|
void addMOVZMovAliasOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
|
|
|
|
const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
|
|
|
|
uint64_t Value = CE->getValue();
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm((Value >> Shift) & 0xffff));
|
2014-05-13 02:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int Shift>
|
|
|
|
void addMOVNMovAliasOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands!");
|
|
|
|
|
|
|
|
const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
|
|
|
|
uint64_t Value = CE->getValue();
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm((~Value >> Shift) & 0xffff));
|
2014-05-13 02:03:36 +08:00
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:25 +08:00
|
|
|
void print(raw_ostream &OS) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand>
|
|
|
|
CreateToken(StringRef Str, bool IsSuffix, SMLoc S, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_Token, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->Tok.Data = Str.data();
|
|
|
|
Op->Tok.Length = Str.size();
|
|
|
|
Op->Tok.IsSuffix = IsSuffix;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = S;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand>
|
|
|
|
CreateReg(unsigned RegNum, bool isVector, SMLoc S, SMLoc E, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_Register, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->Reg.RegNum = RegNum;
|
|
|
|
Op->Reg.isVector = isVector;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand>
|
|
|
|
CreateVectorList(unsigned RegNum, unsigned Count, unsigned NumElements,
|
|
|
|
char ElementKind, SMLoc S, SMLoc E, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_VectorList, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->VectorList.RegNum = RegNum;
|
|
|
|
Op->VectorList.Count = Count;
|
|
|
|
Op->VectorList.NumElements = NumElements;
|
|
|
|
Op->VectorList.ElementKind = ElementKind;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand>
|
|
|
|
CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_VectorIndex, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->VectorIndex.Val = Idx;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreateImm(const MCExpr *Val, SMLoc S,
|
|
|
|
SMLoc E, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_Immediate, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->Imm.Val = Val;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreateShiftedImm(const MCExpr *Val,
|
|
|
|
unsigned ShiftAmount,
|
|
|
|
SMLoc S, SMLoc E,
|
|
|
|
MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_ShiftedImm, Ctx);
|
2014-05-08 23:39:58 +08:00
|
|
|
Op->ShiftedImm .Val = Val;
|
|
|
|
Op->ShiftedImm.ShiftAmount = ShiftAmount;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand>
|
|
|
|
CreateCondCode(AArch64CC::CondCode Code, SMLoc S, SMLoc E, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_CondCode, Ctx);
|
2014-05-15 19:06:51 +08:00
|
|
|
Op->CondCode.Code = Code;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreateFPImm(unsigned Val, SMLoc S,
|
|
|
|
MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_FPImm, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->FPImm.Val = Val;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = S;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2015-03-27 01:29:53 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreateBarrier(unsigned Val,
|
|
|
|
StringRef Str,
|
|
|
|
SMLoc S,
|
2014-06-09 00:18:35 +08:00
|
|
|
MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_Barrier, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->Barrier.Val = Val;
|
2015-03-27 01:29:53 +08:00
|
|
|
Op->Barrier.Data = Str.data();
|
|
|
|
Op->Barrier.Length = Str.size();
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = S;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2015-01-23 01:23:04 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreateSysReg(StringRef Str, SMLoc S,
|
|
|
|
uint32_t MRSReg,
|
|
|
|
uint32_t MSRReg,
|
|
|
|
uint32_t PStateField,
|
|
|
|
MCContext &Ctx) {
|
2014-06-09 00:18:35 +08:00
|
|
|
auto Op = make_unique<AArch64Operand>(k_SysReg, Ctx);
|
2014-04-09 22:43:06 +08:00
|
|
|
Op->SysReg.Data = Str.data();
|
|
|
|
Op->SysReg.Length = Str.size();
|
2015-01-23 01:23:04 +08:00
|
|
|
Op->SysReg.MRSReg = MRSReg;
|
|
|
|
Op->SysReg.MSRReg = MSRReg;
|
|
|
|
Op->SysReg.PStateField = PStateField;
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = S;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreateSysCR(unsigned Val, SMLoc S,
|
|
|
|
SMLoc E, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_SysCR, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->SysCRImm.Val = Val;
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2015-03-27 01:29:53 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreatePrefetch(unsigned Val,
|
|
|
|
StringRef Str,
|
|
|
|
SMLoc S,
|
2014-06-09 00:18:35 +08:00
|
|
|
MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_Prefetch, Ctx);
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->Prefetch.Val = Val;
|
2015-03-27 01:29:53 +08:00
|
|
|
Op->Barrier.Data = Str.data();
|
|
|
|
Op->Barrier.Length = Str.size();
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = S;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2015-12-01 18:48:51 +08:00
|
|
|
static std::unique_ptr<AArch64Operand> CreatePSBHint(unsigned Val,
|
|
|
|
StringRef Str,
|
|
|
|
SMLoc S,
|
|
|
|
MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_PSBHint, Ctx);
|
|
|
|
Op->PSBHint.Val = Val;
|
|
|
|
Op->PSBHint.Data = Str.data();
|
|
|
|
Op->PSBHint.Length = Str.size();
|
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = S;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<AArch64Operand>
|
|
|
|
CreateShiftExtend(AArch64_AM::ShiftExtendType ShOp, unsigned Val,
|
|
|
|
bool HasExplicitAmount, SMLoc S, SMLoc E, MCContext &Ctx) {
|
|
|
|
auto Op = make_unique<AArch64Operand>(k_ShiftExtend, Ctx);
|
2014-05-12 22:13:17 +08:00
|
|
|
Op->ShiftExtend.Type = ShOp;
|
|
|
|
Op->ShiftExtend.Amount = Val;
|
2014-05-22 19:56:09 +08:00
|
|
|
Op->ShiftExtend.HasExplicitAmount = HasExplicitAmount;
|
2014-03-29 18:18:08 +08:00
|
|
|
Op->StartLoc = S;
|
|
|
|
Op->EndLoc = E;
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace.
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
void AArch64Operand::print(raw_ostream &OS) const {
|
2014-03-29 18:18:08 +08:00
|
|
|
switch (Kind) {
|
|
|
|
case k_FPImm:
|
2014-05-24 20:50:23 +08:00
|
|
|
OS << "<fpimm " << getFPImm() << "("
|
|
|
|
<< AArch64_AM::getFPImmFloat(getFPImm()) << ") >";
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
case k_Barrier: {
|
2015-03-27 01:29:53 +08:00
|
|
|
StringRef Name = getBarrierName();
|
|
|
|
if (!Name.empty())
|
2014-04-09 22:42:42 +08:00
|
|
|
OS << "<barrier " << Name << ">";
|
2014-03-29 18:18:08 +08:00
|
|
|
else
|
2014-04-09 22:43:06 +08:00
|
|
|
OS << "<barrier invalid #" << getBarrier() << ">";
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case k_Immediate:
|
2015-05-27 21:05:42 +08:00
|
|
|
OS << *getImm();
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
2014-05-08 23:39:58 +08:00
|
|
|
case k_ShiftedImm: {
|
|
|
|
unsigned Shift = getShiftedImmShift();
|
|
|
|
OS << "<shiftedimm ";
|
2015-05-27 21:05:42 +08:00
|
|
|
OS << *getShiftedImmVal();
|
2014-05-24 20:50:23 +08:00
|
|
|
OS << ", lsl #" << AArch64_AM::getShiftValue(Shift) << ">";
|
2014-05-08 23:39:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-05-15 19:06:51 +08:00
|
|
|
case k_CondCode:
|
|
|
|
OS << "<condcode " << getCondCode() << ">";
|
|
|
|
break;
|
2014-03-29 18:18:08 +08:00
|
|
|
case k_Register:
|
|
|
|
OS << "<register " << getReg() << ">";
|
|
|
|
break;
|
|
|
|
case k_VectorList: {
|
|
|
|
OS << "<vectorlist ";
|
|
|
|
unsigned Reg = getVectorListStart();
|
|
|
|
for (unsigned i = 0, e = getVectorListCount(); i != e; ++i)
|
|
|
|
OS << Reg + i << " ";
|
|
|
|
OS << ">";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case k_VectorIndex:
|
|
|
|
OS << "<vectorindex " << getVectorIndex() << ">";
|
|
|
|
break;
|
2014-04-09 22:43:06 +08:00
|
|
|
case k_SysReg:
|
|
|
|
OS << "<sysreg: " << getSysReg() << '>';
|
|
|
|
break;
|
2014-03-29 18:18:08 +08:00
|
|
|
case k_Token:
|
|
|
|
OS << "'" << getToken() << "'";
|
|
|
|
break;
|
|
|
|
case k_SysCR:
|
|
|
|
OS << "c" << getSysCR();
|
|
|
|
break;
|
2014-04-09 22:42:53 +08:00
|
|
|
case k_Prefetch: {
|
2015-03-27 01:29:53 +08:00
|
|
|
StringRef Name = getPrefetchName();
|
|
|
|
if (!Name.empty())
|
2014-04-09 22:42:53 +08:00
|
|
|
OS << "<prfop " << Name << ">";
|
2014-03-29 18:18:08 +08:00
|
|
|
else
|
2014-04-09 22:42:53 +08:00
|
|
|
OS << "<prfop invalid #" << getPrefetch() << ">";
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
2014-04-09 22:42:53 +08:00
|
|
|
}
|
2015-12-01 18:48:51 +08:00
|
|
|
case k_PSBHint: {
|
|
|
|
OS << getPSBHintName();
|
|
|
|
break;
|
|
|
|
}
|
2014-05-12 22:13:17 +08:00
|
|
|
case k_ShiftExtend: {
|
2014-05-24 20:50:23 +08:00
|
|
|
OS << "<" << AArch64_AM::getShiftExtendName(getShiftExtendType()) << " #"
|
2014-05-22 19:56:09 +08:00
|
|
|
<< getShiftExtendAmount();
|
|
|
|
if (!hasShiftExtendAmount())
|
|
|
|
OS << "<imp>";
|
|
|
|
OS << '>';
|
2014-03-29 18:18:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @name Auto-generated Match Functions
|
|
|
|
/// {
|
|
|
|
|
|
|
|
static unsigned MatchRegisterName(StringRef Name);
|
|
|
|
|
|
|
|
/// }
|
|
|
|
|
|
|
|
static unsigned matchVectorRegName(StringRef Name) {
|
2015-06-09 05:32:16 +08:00
|
|
|
return StringSwitch<unsigned>(Name.lower())
|
2014-05-24 20:50:23 +08:00
|
|
|
.Case("v0", AArch64::Q0)
|
|
|
|
.Case("v1", AArch64::Q1)
|
|
|
|
.Case("v2", AArch64::Q2)
|
|
|
|
.Case("v3", AArch64::Q3)
|
|
|
|
.Case("v4", AArch64::Q4)
|
|
|
|
.Case("v5", AArch64::Q5)
|
|
|
|
.Case("v6", AArch64::Q6)
|
|
|
|
.Case("v7", AArch64::Q7)
|
|
|
|
.Case("v8", AArch64::Q8)
|
|
|
|
.Case("v9", AArch64::Q9)
|
|
|
|
.Case("v10", AArch64::Q10)
|
|
|
|
.Case("v11", AArch64::Q11)
|
|
|
|
.Case("v12", AArch64::Q12)
|
|
|
|
.Case("v13", AArch64::Q13)
|
|
|
|
.Case("v14", AArch64::Q14)
|
|
|
|
.Case("v15", AArch64::Q15)
|
|
|
|
.Case("v16", AArch64::Q16)
|
|
|
|
.Case("v17", AArch64::Q17)
|
|
|
|
.Case("v18", AArch64::Q18)
|
|
|
|
.Case("v19", AArch64::Q19)
|
|
|
|
.Case("v20", AArch64::Q20)
|
|
|
|
.Case("v21", AArch64::Q21)
|
|
|
|
.Case("v22", AArch64::Q22)
|
|
|
|
.Case("v23", AArch64::Q23)
|
|
|
|
.Case("v24", AArch64::Q24)
|
|
|
|
.Case("v25", AArch64::Q25)
|
|
|
|
.Case("v26", AArch64::Q26)
|
|
|
|
.Case("v27", AArch64::Q27)
|
|
|
|
.Case("v28", AArch64::Q28)
|
|
|
|
.Case("v29", AArch64::Q29)
|
|
|
|
.Case("v30", AArch64::Q30)
|
|
|
|
.Case("v31", AArch64::Q31)
|
2014-03-29 18:18:08 +08:00
|
|
|
.Default(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isValidVectorKind(StringRef Name) {
|
|
|
|
return StringSwitch<bool>(Name.lower())
|
|
|
|
.Case(".8b", true)
|
|
|
|
.Case(".16b", true)
|
|
|
|
.Case(".4h", true)
|
|
|
|
.Case(".8h", true)
|
|
|
|
.Case(".2s", true)
|
|
|
|
.Case(".4s", true)
|
|
|
|
.Case(".1d", true)
|
|
|
|
.Case(".2d", true)
|
|
|
|
.Case(".1q", true)
|
|
|
|
// Accept the width neutral ones, too, for verbose syntax. If those
|
|
|
|
// aren't used in the right places, the token operand won't match so
|
|
|
|
// all will work out.
|
|
|
|
.Case(".b", true)
|
|
|
|
.Case(".h", true)
|
|
|
|
.Case(".s", true)
|
|
|
|
.Case(".d", true)
|
2015-12-08 20:16:10 +08:00
|
|
|
// Needed for fp16 scalar pairwise reductions
|
|
|
|
.Case(".2h", true)
|
2014-03-29 18:18:08 +08:00
|
|
|
.Default(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parseValidVectorKind(StringRef Name, unsigned &NumElements,
|
|
|
|
char &ElementKind) {
|
|
|
|
assert(isValidVectorKind(Name));
|
|
|
|
|
|
|
|
ElementKind = Name.lower()[Name.size() - 1];
|
|
|
|
NumElements = 0;
|
|
|
|
|
|
|
|
if (Name.size() == 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Parse the lane count
|
|
|
|
Name = Name.drop_front();
|
|
|
|
while (isdigit(Name.front())) {
|
|
|
|
NumElements = 10 * NumElements + (Name.front() - '0');
|
|
|
|
Name = Name.drop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
|
|
|
|
SMLoc &EndLoc) {
|
2014-03-29 18:18:08 +08:00
|
|
|
StartLoc = getLoc();
|
|
|
|
RegNo = tryParseRegister();
|
|
|
|
EndLoc = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
|
|
|
return (RegNo == (unsigned)-1);
|
|
|
|
}
|
|
|
|
|
2014-07-02 12:50:23 +08:00
|
|
|
// Matches a register name or register alias previously defined by '.req'
|
|
|
|
unsigned AArch64AsmParser::matchRegisterNameAlias(StringRef Name,
|
|
|
|
bool isVector) {
|
|
|
|
unsigned RegNum = isVector ? matchVectorRegName(Name)
|
|
|
|
: MatchRegisterName(Name);
|
|
|
|
|
|
|
|
if (RegNum == 0) {
|
|
|
|
// Check for aliases registered via .req. Canonicalize to lower case.
|
|
|
|
// That's more consistent since register names are case insensitive, and
|
|
|
|
// it's how the original entry was passed in from MC/MCParser/AsmParser.
|
|
|
|
auto Entry = RegisterReqs.find(Name.lower());
|
|
|
|
if (Entry == RegisterReqs.end())
|
|
|
|
return 0;
|
|
|
|
// set RegNum if the match is the right kind of register
|
|
|
|
if (isVector == Entry->getValue().first)
|
|
|
|
RegNum = Entry->getValue().second;
|
|
|
|
}
|
|
|
|
return RegNum;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// tryParseRegister - Try to parse a register name. The token must be an
|
|
|
|
/// Identifier when called, and if it is a register name the token is eaten and
|
|
|
|
/// the register is added to the operand list.
|
2014-05-24 20:50:23 +08:00
|
|
|
int AArch64AsmParser::tryParseRegister() {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
|
|
|
|
|
|
|
|
std::string lowerCase = Tok.getString().lower();
|
2014-07-02 12:50:23 +08:00
|
|
|
unsigned RegNum = matchRegisterNameAlias(lowerCase, false);
|
2014-03-29 18:18:08 +08:00
|
|
|
// Also handle a few aliases of registers.
|
|
|
|
if (RegNum == 0)
|
|
|
|
RegNum = StringSwitch<unsigned>(lowerCase)
|
2014-05-24 20:50:23 +08:00
|
|
|
.Case("fp", AArch64::FP)
|
|
|
|
.Case("lr", AArch64::LR)
|
|
|
|
.Case("x31", AArch64::XZR)
|
|
|
|
.Case("w31", AArch64::WZR)
|
2014-03-29 18:18:08 +08:00
|
|
|
.Default(0);
|
|
|
|
|
|
|
|
if (RegNum == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat identifier token.
|
|
|
|
return RegNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tryMatchVectorRegister - Try to parse a vector register name with optional
|
|
|
|
/// kind specifier. If it is a register specifier, eat the token and return it.
|
2014-05-24 20:50:23 +08:00
|
|
|
int AArch64AsmParser::tryMatchVectorRegister(StringRef &Kind, bool expected) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
TokError("vector register expected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef Name = Parser.getTok().getString();
|
|
|
|
// If there is a kind specifier, it's separated from the register name by
|
|
|
|
// a '.'.
|
|
|
|
size_t Start = 0, Next = Name.find('.');
|
|
|
|
StringRef Head = Name.slice(Start, Next);
|
2014-07-02 12:50:23 +08:00
|
|
|
unsigned RegNum = matchRegisterNameAlias(Head, true);
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
if (RegNum) {
|
|
|
|
if (Next != StringRef::npos) {
|
|
|
|
Kind = Name.slice(Next, StringRef::npos);
|
|
|
|
if (!isValidVectorKind(Kind)) {
|
|
|
|
TokError("invalid vector kind qualifier");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Parser.Lex(); // Eat the register token.
|
|
|
|
return RegNum;
|
|
|
|
}
|
2014-04-09 22:41:58 +08:00
|
|
|
|
|
|
|
if (expected)
|
|
|
|
TokError("vector register expected");
|
2014-03-29 18:18:08 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tryParseSysCROperand - Try to parse a system instruction CR operand name.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseSysCROperand(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
|
2014-05-16 00:28:32 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
Error(S, "Expected cN operand where 0 <= N <= 15");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef Tok = Parser.getTok().getIdentifier();
|
|
|
|
if (Tok[0] != 'c' && Tok[0] != 'C') {
|
|
|
|
Error(S, "Expected cN operand where 0 <= N <= 15");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CRNum;
|
|
|
|
bool BadNum = Tok.drop_front().getAsInteger(10, CRNum);
|
|
|
|
if (BadNum || CRNum > 15) {
|
|
|
|
Error(S, "Expected cN operand where 0 <= N <= 15");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
Parser.Lex(); // Eat identifier token.
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(
|
|
|
|
AArch64Operand::CreateSysCR(CRNum, S, getLoc(), getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tryParsePrefetch - Try to parse a prefetch operand.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParsePrefetch(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
// Either an identifier for named values or a 5-bit immediate.
|
2014-04-15 19:43:09 +08:00
|
|
|
bool Hash = Tok.is(AsmToken::Hash);
|
|
|
|
if (Hash || Tok.is(AsmToken::Integer)) {
|
|
|
|
if (Hash)
|
|
|
|
Parser.Lex(); // Eat hash token.
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCExpr *ImmVal;
|
|
|
|
if (getParser().parseExpression(ImmVal))
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
|
|
|
|
if (!MCE) {
|
|
|
|
TokError("immediate value expected for prefetch operand");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
unsigned prfop = MCE->getValue();
|
|
|
|
if (prfop > 31) {
|
|
|
|
TokError("prefetch operand out of range, [0,31] expected");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2016-07-06 05:23:04 +08:00
|
|
|
auto PRFM = AArch64PRFM::lookupPRFMByEncoding(MCE->getValue());
|
|
|
|
Operands.push_back(AArch64Operand::CreatePrefetch(
|
|
|
|
prfop, PRFM ? PRFM->Name : "", S, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.isNot(AsmToken::Identifier)) {
|
|
|
|
TokError("pre-fetch hint expected");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2016-07-06 05:23:04 +08:00
|
|
|
auto PRFM = AArch64PRFM::lookupPRFMByName(Tok.getString());
|
|
|
|
if (!PRFM) {
|
2014-03-29 18:18:08 +08:00
|
|
|
TokError("pre-fetch hint expected");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat identifier token.
|
2016-07-06 05:23:04 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreatePrefetch(
|
|
|
|
PRFM->Encoding, Tok.getString(), S, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
2015-12-01 18:48:51 +08:00
|
|
|
/// tryParsePSBHint - Try to parse a PSB operand, mapped to Hint command
|
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParsePSBHint(OperandVector &Operands) {
|
|
|
|
MCAsmParser &Parser = getParser();
|
|
|
|
SMLoc S = getLoc();
|
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
if (Tok.isNot(AsmToken::Identifier)) {
|
|
|
|
TokError("invalid operand for instruction");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2016-07-06 05:23:04 +08:00
|
|
|
auto PSB = AArch64PSBHint::lookupPSBByName(Tok.getString());
|
|
|
|
if (!PSB) {
|
2015-12-01 18:48:51 +08:00
|
|
|
TokError("invalid operand for instruction");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat identifier token.
|
2016-07-06 05:23:04 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreatePSBHint(
|
|
|
|
PSB->Encoding, Tok.getString(), S, getContext()));
|
2015-12-01 18:48:51 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// tryParseAdrpLabel - Parse and validate a source label for the ADRP
|
|
|
|
/// instruction.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseAdrpLabel(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
const MCExpr *Expr;
|
2014-04-09 22:44:12 +08:00
|
|
|
|
|
|
|
if (Parser.getTok().is(AsmToken::Hash)) {
|
|
|
|
Parser.Lex(); // Eat hash token.
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
if (parseSymbolicImmVal(Expr))
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VariantKind ELFRefKind;
|
2014-03-29 18:18:08 +08:00
|
|
|
MCSymbolRefExpr::VariantKind DarwinRefKind;
|
2014-04-24 20:56:38 +08:00
|
|
|
int64_t Addend;
|
2014-04-09 22:44:12 +08:00
|
|
|
if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
|
|
|
|
if (DarwinRefKind == MCSymbolRefExpr::VK_None &&
|
2014-05-24 20:50:23 +08:00
|
|
|
ELFRefKind == AArch64MCExpr::VK_INVALID) {
|
2014-04-09 22:44:12 +08:00
|
|
|
// No modifier was specified at all; this is the syntax for an ELF basic
|
|
|
|
// ADRP relocation (unfortunately).
|
2014-05-24 20:50:23 +08:00
|
|
|
Expr =
|
2015-05-30 09:25:56 +08:00
|
|
|
AArch64MCExpr::create(Expr, AArch64MCExpr::VK_ABS_PAGE, getContext());
|
2014-04-09 22:44:12 +08:00
|
|
|
} else if ((DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGE ||
|
|
|
|
DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGE) &&
|
|
|
|
Addend != 0) {
|
|
|
|
Error(S, "gotpage label reference not allowed an addend");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
} else if (DarwinRefKind != MCSymbolRefExpr::VK_PAGE &&
|
|
|
|
DarwinRefKind != MCSymbolRefExpr::VK_GOTPAGE &&
|
|
|
|
DarwinRefKind != MCSymbolRefExpr::VK_TLVPPAGE &&
|
2014-05-24 20:50:23 +08:00
|
|
|
ELFRefKind != AArch64MCExpr::VK_GOT_PAGE &&
|
|
|
|
ELFRefKind != AArch64MCExpr::VK_GOTTPREL_PAGE &&
|
|
|
|
ELFRefKind != AArch64MCExpr::VK_TLSDESC_PAGE) {
|
2014-04-09 22:44:12 +08:00
|
|
|
// The operand must be an @page or @gotpage qualified symbolref.
|
|
|
|
Error(S, "page or gotpage label reference expected");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-09 22:44:12 +08:00
|
|
|
// We have either a label reference possibly with addend or an immediate. The
|
|
|
|
// addend is a raw value here. The linker will adjust it to only reference the
|
|
|
|
// page.
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tryParseAdrLabel - Parse and validate a source label for the ADR
|
|
|
|
/// instruction.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseAdrLabel(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
const MCExpr *Expr;
|
|
|
|
|
2014-04-09 22:44:12 +08:00
|
|
|
if (Parser.getTok().is(AsmToken::Hash)) {
|
|
|
|
Parser.Lex(); // Eat hash token.
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-09 22:44:12 +08:00
|
|
|
if (getParser().parseExpression(Expr))
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tryParseFPImm - A floating point immediate expression operand.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseFPImm(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
|
2014-04-15 19:43:09 +08:00
|
|
|
bool Hash = false;
|
|
|
|
if (Parser.getTok().is(AsmToken::Hash)) {
|
|
|
|
Parser.Lex(); // Eat '#'
|
|
|
|
Hash = true;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Handle negation, as that still comes through as a separate token.
|
|
|
|
bool isNegative = false;
|
|
|
|
if (Parser.getTok().is(AsmToken::Minus)) {
|
|
|
|
isNegative = true;
|
|
|
|
Parser.Lex();
|
|
|
|
}
|
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
if (Tok.is(AsmToken::Real)) {
|
|
|
|
APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
|
2015-04-08 06:49:47 +08:00
|
|
|
if (isNegative)
|
|
|
|
RealVal.changeSign();
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
|
2014-05-24 20:50:23 +08:00
|
|
|
int Val = AArch64_AM::getFP64Imm(APInt(64, IntVal));
|
2014-03-29 18:18:08 +08:00
|
|
|
Parser.Lex(); // Eat the token.
|
|
|
|
// Check for out of range values. As an exception, we let Zero through,
|
|
|
|
// as we handle that special case in post-processing before matching in
|
|
|
|
// order to use the zero register for it.
|
2015-04-08 06:49:47 +08:00
|
|
|
if (Val == -1 && !RealVal.isPosZero()) {
|
2014-05-15 19:07:28 +08:00
|
|
|
TokError("expected compatible register or floating-point constant");
|
2014-03-29 18:18:08 +08:00
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateFPImm(Val, S, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
if (Tok.is(AsmToken::Integer)) {
|
|
|
|
int64_t Val;
|
|
|
|
if (!isNegative && Tok.getString().startswith("0x")) {
|
|
|
|
Val = Tok.getIntVal();
|
|
|
|
if (Val > 255 || Val < 0) {
|
|
|
|
TokError("encoded floating point value out of range");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
|
|
|
|
uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
|
|
|
|
// If we had a '-' in front, toggle the sign bit.
|
|
|
|
IntVal ^= (uint64_t)isNegative << 63;
|
2014-05-24 20:50:23 +08:00
|
|
|
Val = AArch64_AM::getFP64Imm(APInt(64, IntVal));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
Parser.Lex(); // Eat the token.
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateFPImm(Val, S, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
2014-04-15 19:43:09 +08:00
|
|
|
if (!Hash)
|
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
TokError("invalid floating point immediate");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2014-05-08 23:39:58 +08:00
|
|
|
/// tryParseAddSubImm - Parse ADD/SUB shifted immediate operand
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseAddSubImm(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-05-08 23:39:58 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
|
|
|
|
if (Parser.getTok().is(AsmToken::Hash))
|
|
|
|
Parser.Lex(); // Eat '#'
|
|
|
|
else if (Parser.getTok().isNot(AsmToken::Integer))
|
|
|
|
// Operand should start from # or should be integer, emit error otherwise.
|
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
|
|
|
const MCExpr *Imm;
|
|
|
|
if (parseSymbolicImmVal(Imm))
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
else if (Parser.getTok().isNot(AsmToken::Comma)) {
|
|
|
|
uint64_t ShiftAmount = 0;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Imm);
|
|
|
|
if (MCE) {
|
|
|
|
int64_t Val = MCE->getValue();
|
|
|
|
if (Val > 0xfff && (Val & 0xfff) == 0) {
|
2015-05-30 09:25:56 +08:00
|
|
|
Imm = MCConstantExpr::create(Val >> 12, getContext());
|
2014-05-08 23:39:58 +08:00
|
|
|
ShiftAmount = 12;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SMLoc E = Parser.getTok().getLoc();
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateShiftedImm(Imm, ShiftAmount, S, E,
|
|
|
|
getContext()));
|
2014-05-08 23:39:58 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eat ','
|
|
|
|
Parser.Lex();
|
|
|
|
|
|
|
|
// The optional operand must be "lsl #N" where N is non-negative.
|
|
|
|
if (!Parser.getTok().is(AsmToken::Identifier) ||
|
|
|
|
!Parser.getTok().getIdentifier().equals_lower("lsl")) {
|
|
|
|
Error(Parser.getTok().getLoc(), "only 'lsl #+N' valid after immediate");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eat 'lsl'
|
|
|
|
Parser.Lex();
|
|
|
|
|
|
|
|
if (Parser.getTok().is(AsmToken::Hash)) {
|
|
|
|
Parser.Lex();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Integer)) {
|
|
|
|
Error(Parser.getTok().getLoc(), "only 'lsl #+N' valid after immediate");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t ShiftAmount = Parser.getTok().getIntVal();
|
|
|
|
|
|
|
|
if (ShiftAmount < 0) {
|
|
|
|
Error(Parser.getTok().getLoc(), "positive shift amount required");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
Parser.Lex(); // Eat the number
|
|
|
|
|
|
|
|
SMLoc E = Parser.getTok().getLoc();
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateShiftedImm(Imm, ShiftAmount,
|
|
|
|
S, E, getContext()));
|
2014-05-08 23:39:58 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// parseCondCodeString - Parse a Condition Code string.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64CC::CondCode AArch64AsmParser::parseCondCodeString(StringRef Cond) {
|
|
|
|
AArch64CC::CondCode CC = StringSwitch<AArch64CC::CondCode>(Cond.lower())
|
|
|
|
.Case("eq", AArch64CC::EQ)
|
|
|
|
.Case("ne", AArch64CC::NE)
|
|
|
|
.Case("cs", AArch64CC::HS)
|
|
|
|
.Case("hs", AArch64CC::HS)
|
|
|
|
.Case("cc", AArch64CC::LO)
|
|
|
|
.Case("lo", AArch64CC::LO)
|
|
|
|
.Case("mi", AArch64CC::MI)
|
|
|
|
.Case("pl", AArch64CC::PL)
|
|
|
|
.Case("vs", AArch64CC::VS)
|
|
|
|
.Case("vc", AArch64CC::VC)
|
|
|
|
.Case("hi", AArch64CC::HI)
|
|
|
|
.Case("ls", AArch64CC::LS)
|
|
|
|
.Case("ge", AArch64CC::GE)
|
|
|
|
.Case("lt", AArch64CC::LT)
|
|
|
|
.Case("gt", AArch64CC::GT)
|
|
|
|
.Case("le", AArch64CC::LE)
|
|
|
|
.Case("al", AArch64CC::AL)
|
|
|
|
.Case("nv", AArch64CC::NV)
|
|
|
|
.Default(AArch64CC::Invalid);
|
2014-03-29 18:18:08 +08:00
|
|
|
return CC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// parseCondCode - Parse a Condition Code operand.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseCondCode(OperandVector &Operands,
|
|
|
|
bool invertCondCode) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
|
|
|
|
|
|
|
|
StringRef Cond = Tok.getString();
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64CC::CondCode CC = parseCondCodeString(Cond);
|
|
|
|
if (CC == AArch64CC::Invalid)
|
2014-03-29 18:18:08 +08:00
|
|
|
return TokError("invalid condition code");
|
|
|
|
Parser.Lex(); // Eat identifier token.
|
|
|
|
|
2014-06-10 21:11:35 +08:00
|
|
|
if (invertCondCode) {
|
|
|
|
if (CC == AArch64CC::AL || CC == AArch64CC::NV)
|
|
|
|
return TokError("condition codes AL and NV are invalid for this instruction");
|
2014-05-24 20:50:23 +08:00
|
|
|
CC = AArch64CC::getInvertedCondCode(AArch64CC::CondCode(CC));
|
2014-06-10 21:11:35 +08:00
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateCondCode(CC, S, getLoc(), getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-08 22:11:16 +08:00
|
|
|
/// tryParseOptionalShift - Some operands take an optional shift argument. Parse
|
2014-03-29 18:18:08 +08:00
|
|
|
/// them if present.
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseOptionalShiftExtend(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
const AsmToken &Tok = Parser.getTok();
|
2014-05-08 22:11:16 +08:00
|
|
|
std::string LowerID = Tok.getString().lower();
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64_AM::ShiftExtendType ShOp =
|
|
|
|
StringSwitch<AArch64_AM::ShiftExtendType>(LowerID)
|
|
|
|
.Case("lsl", AArch64_AM::LSL)
|
|
|
|
.Case("lsr", AArch64_AM::LSR)
|
|
|
|
.Case("asr", AArch64_AM::ASR)
|
|
|
|
.Case("ror", AArch64_AM::ROR)
|
|
|
|
.Case("msl", AArch64_AM::MSL)
|
|
|
|
.Case("uxtb", AArch64_AM::UXTB)
|
|
|
|
.Case("uxth", AArch64_AM::UXTH)
|
|
|
|
.Case("uxtw", AArch64_AM::UXTW)
|
|
|
|
.Case("uxtx", AArch64_AM::UXTX)
|
|
|
|
.Case("sxtb", AArch64_AM::SXTB)
|
|
|
|
.Case("sxth", AArch64_AM::SXTH)
|
|
|
|
.Case("sxtw", AArch64_AM::SXTW)
|
|
|
|
.Case("sxtx", AArch64_AM::SXTX)
|
|
|
|
.Default(AArch64_AM::InvalidShiftExtend);
|
|
|
|
|
|
|
|
if (ShOp == AArch64_AM::InvalidShiftExtend)
|
2014-05-08 22:11:16 +08:00
|
|
|
return MatchOperand_NoMatch;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
SMLoc S = Tok.getLoc();
|
|
|
|
Parser.Lex();
|
|
|
|
|
2014-04-15 19:43:09 +08:00
|
|
|
bool Hash = getLexer().is(AsmToken::Hash);
|
|
|
|
if (!Hash && getLexer().isNot(AsmToken::Integer)) {
|
2014-05-24 20:50:23 +08:00
|
|
|
if (ShOp == AArch64_AM::LSL || ShOp == AArch64_AM::LSR ||
|
|
|
|
ShOp == AArch64_AM::ASR || ShOp == AArch64_AM::ROR ||
|
|
|
|
ShOp == AArch64_AM::MSL) {
|
2014-05-12 22:13:17 +08:00
|
|
|
// We expect a number here.
|
|
|
|
TokError("expected #imm after shift specifier");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "extend" type operatoins don't need an immediate, #0 is implicit.
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateShiftExtend(ShOp, 0, false, S, E, getContext()));
|
2014-05-08 22:11:16 +08:00
|
|
|
return MatchOperand_Success;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 19:43:09 +08:00
|
|
|
if (Hash)
|
|
|
|
Parser.Lex(); // Eat the '#'.
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-09-24 06:16:02 +08:00
|
|
|
// Make sure we do actually have a number or a parenthesized expression.
|
|
|
|
SMLoc E = Parser.getTok().getLoc();
|
|
|
|
if (!Parser.getTok().is(AsmToken::Integer) &&
|
|
|
|
!Parser.getTok().is(AsmToken::LParen)) {
|
|
|
|
Error(E, "expected integer shift amount");
|
2014-05-08 22:11:16 +08:00
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCExpr *ImmVal;
|
|
|
|
if (getParser().parseExpression(ImmVal))
|
2014-05-08 22:11:16 +08:00
|
|
|
return MatchOperand_ParseFail;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
|
2014-05-08 22:11:16 +08:00
|
|
|
if (!MCE) {
|
2014-09-24 06:16:02 +08:00
|
|
|
Error(E, "expected constant '#imm' after shift specifier");
|
2014-05-08 22:11:16 +08:00
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-09-24 06:16:02 +08:00
|
|
|
E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateShiftExtend(
|
|
|
|
ShOp, MCE->getValue(), true, S, E, getContext()));
|
2014-05-08 22:11:16 +08:00
|
|
|
return MatchOperand_Success;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// parseSysAlias - The IC, DC, AT, and TLBI instructions are simple aliases for
|
|
|
|
/// the SYS instruction. Parse them specially so that we create a SYS MCInst.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseSysAlias(StringRef Name, SMLoc NameLoc,
|
2014-03-29 18:18:08 +08:00
|
|
|
OperandVector &Operands) {
|
|
|
|
if (Name.find('.') != StringRef::npos)
|
|
|
|
return TokError("invalid operand");
|
|
|
|
|
|
|
|
Mnemonic = Name;
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken("sys", false, NameLoc, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
StringRef Op = Tok.getString();
|
|
|
|
SMLoc S = Tok.getLoc();
|
|
|
|
|
2014-04-25 13:30:21 +08:00
|
|
|
const MCExpr *Expr = nullptr;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
#define SYS_ALIAS(op1, Cn, Cm, op2) \
|
|
|
|
do { \
|
2015-05-30 09:25:56 +08:00
|
|
|
Expr = MCConstantExpr::create(op1, getContext()); \
|
2014-03-29 18:18:08 +08:00
|
|
|
Operands.push_back( \
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
|
2014-03-29 18:18:08 +08:00
|
|
|
Operands.push_back( \
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateSysCR(Cn, S, getLoc(), getContext())); \
|
2014-03-29 18:18:08 +08:00
|
|
|
Operands.push_back( \
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateSysCR(Cm, S, getLoc(), getContext())); \
|
2015-05-30 09:25:56 +08:00
|
|
|
Expr = MCConstantExpr::create(op2, getContext()); \
|
2014-03-29 18:18:08 +08:00
|
|
|
Operands.push_back( \
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateImm(Expr, S, getLoc(), getContext())); \
|
2014-03-29 18:18:08 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
if (Mnemonic == "ic") {
|
|
|
|
if (!Op.compare_lower("ialluis")) {
|
|
|
|
// SYS #0, C7, C1, #0
|
|
|
|
SYS_ALIAS(0, 7, 1, 0);
|
|
|
|
} else if (!Op.compare_lower("iallu")) {
|
|
|
|
// SYS #0, C7, C5, #0
|
|
|
|
SYS_ALIAS(0, 7, 5, 0);
|
|
|
|
} else if (!Op.compare_lower("ivau")) {
|
|
|
|
// SYS #3, C7, C5, #1
|
|
|
|
SYS_ALIAS(3, 7, 5, 1);
|
|
|
|
} else {
|
|
|
|
return TokError("invalid operand for IC instruction");
|
|
|
|
}
|
|
|
|
} else if (Mnemonic == "dc") {
|
|
|
|
if (!Op.compare_lower("zva")) {
|
|
|
|
// SYS #3, C7, C4, #1
|
|
|
|
SYS_ALIAS(3, 7, 4, 1);
|
|
|
|
} else if (!Op.compare_lower("ivac")) {
|
|
|
|
// SYS #3, C7, C6, #1
|
|
|
|
SYS_ALIAS(0, 7, 6, 1);
|
|
|
|
} else if (!Op.compare_lower("isw")) {
|
|
|
|
// SYS #0, C7, C6, #2
|
|
|
|
SYS_ALIAS(0, 7, 6, 2);
|
|
|
|
} else if (!Op.compare_lower("cvac")) {
|
|
|
|
// SYS #3, C7, C10, #1
|
|
|
|
SYS_ALIAS(3, 7, 10, 1);
|
|
|
|
} else if (!Op.compare_lower("csw")) {
|
|
|
|
// SYS #0, C7, C10, #2
|
|
|
|
SYS_ALIAS(0, 7, 10, 2);
|
|
|
|
} else if (!Op.compare_lower("cvau")) {
|
|
|
|
// SYS #3, C7, C11, #1
|
|
|
|
SYS_ALIAS(3, 7, 11, 1);
|
|
|
|
} else if (!Op.compare_lower("civac")) {
|
|
|
|
// SYS #3, C7, C14, #1
|
|
|
|
SYS_ALIAS(3, 7, 14, 1);
|
|
|
|
} else if (!Op.compare_lower("cisw")) {
|
|
|
|
// SYS #0, C7, C14, #2
|
|
|
|
SYS_ALIAS(0, 7, 14, 2);
|
2015-11-26 23:28:47 +08:00
|
|
|
} else if (!Op.compare_lower("cvap")) {
|
|
|
|
if (getSTI().getFeatureBits()[AArch64::HasV8_2aOps]) {
|
|
|
|
// SYS #3, C7, C12, #1
|
|
|
|
SYS_ALIAS(3, 7, 12, 1);
|
|
|
|
} else {
|
|
|
|
return TokError("DC CVAP requires ARMv8.2a");
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
} else {
|
|
|
|
return TokError("invalid operand for DC instruction");
|
|
|
|
}
|
|
|
|
} else if (Mnemonic == "at") {
|
|
|
|
if (!Op.compare_lower("s1e1r")) {
|
|
|
|
// SYS #0, C7, C8, #0
|
|
|
|
SYS_ALIAS(0, 7, 8, 0);
|
|
|
|
} else if (!Op.compare_lower("s1e2r")) {
|
|
|
|
// SYS #4, C7, C8, #0
|
|
|
|
SYS_ALIAS(4, 7, 8, 0);
|
|
|
|
} else if (!Op.compare_lower("s1e3r")) {
|
|
|
|
// SYS #6, C7, C8, #0
|
|
|
|
SYS_ALIAS(6, 7, 8, 0);
|
|
|
|
} else if (!Op.compare_lower("s1e1w")) {
|
|
|
|
// SYS #0, C7, C8, #1
|
|
|
|
SYS_ALIAS(0, 7, 8, 1);
|
|
|
|
} else if (!Op.compare_lower("s1e2w")) {
|
|
|
|
// SYS #4, C7, C8, #1
|
|
|
|
SYS_ALIAS(4, 7, 8, 1);
|
|
|
|
} else if (!Op.compare_lower("s1e3w")) {
|
|
|
|
// SYS #6, C7, C8, #1
|
|
|
|
SYS_ALIAS(6, 7, 8, 1);
|
|
|
|
} else if (!Op.compare_lower("s1e0r")) {
|
|
|
|
// SYS #0, C7, C8, #3
|
|
|
|
SYS_ALIAS(0, 7, 8, 2);
|
|
|
|
} else if (!Op.compare_lower("s1e0w")) {
|
|
|
|
// SYS #0, C7, C8, #3
|
|
|
|
SYS_ALIAS(0, 7, 8, 3);
|
|
|
|
} else if (!Op.compare_lower("s12e1r")) {
|
|
|
|
// SYS #4, C7, C8, #4
|
|
|
|
SYS_ALIAS(4, 7, 8, 4);
|
|
|
|
} else if (!Op.compare_lower("s12e1w")) {
|
|
|
|
// SYS #4, C7, C8, #5
|
|
|
|
SYS_ALIAS(4, 7, 8, 5);
|
|
|
|
} else if (!Op.compare_lower("s12e0r")) {
|
|
|
|
// SYS #4, C7, C8, #6
|
|
|
|
SYS_ALIAS(4, 7, 8, 6);
|
|
|
|
} else if (!Op.compare_lower("s12e0w")) {
|
|
|
|
// SYS #4, C7, C8, #7
|
|
|
|
SYS_ALIAS(4, 7, 8, 7);
|
2015-11-26 23:34:44 +08:00
|
|
|
} else if (!Op.compare_lower("s1e1rp")) {
|
|
|
|
if (getSTI().getFeatureBits()[AArch64::HasV8_2aOps]) {
|
|
|
|
// SYS #0, C7, C9, #0
|
|
|
|
SYS_ALIAS(0, 7, 9, 0);
|
|
|
|
} else {
|
|
|
|
return TokError("AT S1E1RP requires ARMv8.2a");
|
|
|
|
}
|
|
|
|
} else if (!Op.compare_lower("s1e1wp")) {
|
|
|
|
if (getSTI().getFeatureBits()[AArch64::HasV8_2aOps]) {
|
|
|
|
// SYS #0, C7, C9, #1
|
|
|
|
SYS_ALIAS(0, 7, 9, 1);
|
|
|
|
} else {
|
|
|
|
return TokError("AT S1E1WP requires ARMv8.2a");
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
} else {
|
|
|
|
return TokError("invalid operand for AT instruction");
|
|
|
|
}
|
|
|
|
} else if (Mnemonic == "tlbi") {
|
|
|
|
if (!Op.compare_lower("vmalle1is")) {
|
|
|
|
// SYS #0, C8, C3, #0
|
|
|
|
SYS_ALIAS(0, 8, 3, 0);
|
|
|
|
} else if (!Op.compare_lower("alle2is")) {
|
|
|
|
// SYS #4, C8, C3, #0
|
|
|
|
SYS_ALIAS(4, 8, 3, 0);
|
|
|
|
} else if (!Op.compare_lower("alle3is")) {
|
|
|
|
// SYS #6, C8, C3, #0
|
|
|
|
SYS_ALIAS(6, 8, 3, 0);
|
|
|
|
} else if (!Op.compare_lower("vae1is")) {
|
|
|
|
// SYS #0, C8, C3, #1
|
|
|
|
SYS_ALIAS(0, 8, 3, 1);
|
|
|
|
} else if (!Op.compare_lower("vae2is")) {
|
|
|
|
// SYS #4, C8, C3, #1
|
|
|
|
SYS_ALIAS(4, 8, 3, 1);
|
|
|
|
} else if (!Op.compare_lower("vae3is")) {
|
|
|
|
// SYS #6, C8, C3, #1
|
|
|
|
SYS_ALIAS(6, 8, 3, 1);
|
|
|
|
} else if (!Op.compare_lower("aside1is")) {
|
|
|
|
// SYS #0, C8, C3, #2
|
|
|
|
SYS_ALIAS(0, 8, 3, 2);
|
|
|
|
} else if (!Op.compare_lower("vaae1is")) {
|
|
|
|
// SYS #0, C8, C3, #3
|
|
|
|
SYS_ALIAS(0, 8, 3, 3);
|
|
|
|
} else if (!Op.compare_lower("alle1is")) {
|
|
|
|
// SYS #4, C8, C3, #4
|
|
|
|
SYS_ALIAS(4, 8, 3, 4);
|
|
|
|
} else if (!Op.compare_lower("vale1is")) {
|
|
|
|
// SYS #0, C8, C3, #5
|
|
|
|
SYS_ALIAS(0, 8, 3, 5);
|
|
|
|
} else if (!Op.compare_lower("vaale1is")) {
|
|
|
|
// SYS #0, C8, C3, #7
|
|
|
|
SYS_ALIAS(0, 8, 3, 7);
|
|
|
|
} else if (!Op.compare_lower("vmalle1")) {
|
|
|
|
// SYS #0, C8, C7, #0
|
|
|
|
SYS_ALIAS(0, 8, 7, 0);
|
|
|
|
} else if (!Op.compare_lower("alle2")) {
|
|
|
|
// SYS #4, C8, C7, #0
|
|
|
|
SYS_ALIAS(4, 8, 7, 0);
|
|
|
|
} else if (!Op.compare_lower("vale2is")) {
|
|
|
|
// SYS #4, C8, C3, #5
|
|
|
|
SYS_ALIAS(4, 8, 3, 5);
|
|
|
|
} else if (!Op.compare_lower("vale3is")) {
|
|
|
|
// SYS #6, C8, C3, #5
|
|
|
|
SYS_ALIAS(6, 8, 3, 5);
|
|
|
|
} else if (!Op.compare_lower("alle3")) {
|
|
|
|
// SYS #6, C8, C7, #0
|
|
|
|
SYS_ALIAS(6, 8, 7, 0);
|
|
|
|
} else if (!Op.compare_lower("vae1")) {
|
|
|
|
// SYS #0, C8, C7, #1
|
|
|
|
SYS_ALIAS(0, 8, 7, 1);
|
|
|
|
} else if (!Op.compare_lower("vae2")) {
|
|
|
|
// SYS #4, C8, C7, #1
|
|
|
|
SYS_ALIAS(4, 8, 7, 1);
|
|
|
|
} else if (!Op.compare_lower("vae3")) {
|
|
|
|
// SYS #6, C8, C7, #1
|
|
|
|
SYS_ALIAS(6, 8, 7, 1);
|
|
|
|
} else if (!Op.compare_lower("aside1")) {
|
|
|
|
// SYS #0, C8, C7, #2
|
|
|
|
SYS_ALIAS(0, 8, 7, 2);
|
|
|
|
} else if (!Op.compare_lower("vaae1")) {
|
|
|
|
// SYS #0, C8, C7, #3
|
|
|
|
SYS_ALIAS(0, 8, 7, 3);
|
|
|
|
} else if (!Op.compare_lower("alle1")) {
|
|
|
|
// SYS #4, C8, C7, #4
|
|
|
|
SYS_ALIAS(4, 8, 7, 4);
|
|
|
|
} else if (!Op.compare_lower("vale1")) {
|
|
|
|
// SYS #0, C8, C7, #5
|
|
|
|
SYS_ALIAS(0, 8, 7, 5);
|
|
|
|
} else if (!Op.compare_lower("vale2")) {
|
|
|
|
// SYS #4, C8, C7, #5
|
|
|
|
SYS_ALIAS(4, 8, 7, 5);
|
|
|
|
} else if (!Op.compare_lower("vale3")) {
|
|
|
|
// SYS #6, C8, C7, #5
|
|
|
|
SYS_ALIAS(6, 8, 7, 5);
|
|
|
|
} else if (!Op.compare_lower("vaale1")) {
|
|
|
|
// SYS #0, C8, C7, #7
|
|
|
|
SYS_ALIAS(0, 8, 7, 7);
|
|
|
|
} else if (!Op.compare_lower("ipas2e1")) {
|
|
|
|
// SYS #4, C8, C4, #1
|
|
|
|
SYS_ALIAS(4, 8, 4, 1);
|
|
|
|
} else if (!Op.compare_lower("ipas2le1")) {
|
|
|
|
// SYS #4, C8, C4, #5
|
|
|
|
SYS_ALIAS(4, 8, 4, 5);
|
2014-04-09 22:43:11 +08:00
|
|
|
} else if (!Op.compare_lower("ipas2e1is")) {
|
|
|
|
// SYS #4, C8, C4, #1
|
|
|
|
SYS_ALIAS(4, 8, 0, 1);
|
|
|
|
} else if (!Op.compare_lower("ipas2le1is")) {
|
|
|
|
// SYS #4, C8, C4, #5
|
|
|
|
SYS_ALIAS(4, 8, 0, 5);
|
2014-03-29 18:18:08 +08:00
|
|
|
} else if (!Op.compare_lower("vmalls12e1")) {
|
|
|
|
// SYS #4, C8, C7, #6
|
|
|
|
SYS_ALIAS(4, 8, 7, 6);
|
|
|
|
} else if (!Op.compare_lower("vmalls12e1is")) {
|
|
|
|
// SYS #4, C8, C3, #6
|
|
|
|
SYS_ALIAS(4, 8, 3, 6);
|
|
|
|
} else {
|
|
|
|
return TokError("invalid operand for TLBI instruction");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef SYS_ALIAS
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat operand.
|
|
|
|
|
2014-04-09 22:43:11 +08:00
|
|
|
bool ExpectRegister = (Op.lower().find("all") == StringRef::npos);
|
|
|
|
bool HasRegister = false;
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// Check for the optional register operand.
|
|
|
|
if (getLexer().is(AsmToken::Comma)) {
|
|
|
|
Parser.Lex(); // Eat comma.
|
|
|
|
|
|
|
|
if (Tok.isNot(AsmToken::Identifier) || parseRegister(Operands))
|
|
|
|
return TokError("expected register operand");
|
2014-04-09 22:43:11 +08:00
|
|
|
|
|
|
|
HasRegister = true;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
2016-09-14 02:17:00 +08:00
|
|
|
Parser.eatToEndOfStatement();
|
2014-03-29 18:18:08 +08:00
|
|
|
return TokError("unexpected token in argument list");
|
|
|
|
}
|
|
|
|
|
2014-04-09 22:43:11 +08:00
|
|
|
if (ExpectRegister && !HasRegister) {
|
|
|
|
return TokError("specified " + Mnemonic + " op requires a register");
|
|
|
|
}
|
|
|
|
else if (!ExpectRegister && HasRegister) {
|
|
|
|
return TokError("specified " + Mnemonic + " op does not use a register");
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
Parser.Lex(); // Consume the EndOfStatement
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
|
|
|
|
// Can be either a #imm style literal or an option name
|
2014-04-15 19:43:09 +08:00
|
|
|
bool Hash = Tok.is(AsmToken::Hash);
|
|
|
|
if (Hash || Tok.is(AsmToken::Integer)) {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Immediate operand.
|
2014-04-15 19:43:09 +08:00
|
|
|
if (Hash)
|
|
|
|
Parser.Lex(); // Eat the '#'
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCExpr *ImmVal;
|
|
|
|
SMLoc ExprLoc = getLoc();
|
|
|
|
if (getParser().parseExpression(ImmVal))
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
|
|
|
|
if (!MCE) {
|
|
|
|
Error(ExprLoc, "immediate value expected for barrier operand");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
if (MCE->getValue() < 0 || MCE->getValue() > 15) {
|
|
|
|
Error(ExprLoc, "barrier operand out of range");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2016-07-06 05:23:04 +08:00
|
|
|
auto DB = AArch64DB::lookupDBByEncoding(MCE->getValue());
|
|
|
|
Operands.push_back(AArch64Operand::CreateBarrier(
|
|
|
|
MCE->getValue(), DB ? DB->Name : "", ExprLoc, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.isNot(AsmToken::Identifier)) {
|
|
|
|
TokError("invalid operand for instruction");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2016-07-06 05:23:04 +08:00
|
|
|
auto DB = AArch64DB::lookupDBByName(Tok.getString());
|
|
|
|
if (!DB) {
|
2014-03-29 18:18:08 +08:00
|
|
|
TokError("invalid barrier option name");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The only valid named option for ISB is 'sy'
|
2016-07-06 05:23:04 +08:00
|
|
|
if (Mnemonic == "isb" && DB->Encoding != AArch64DB::sy) {
|
2014-03-29 18:18:08 +08:00
|
|
|
TokError("'sy' or #imm operand expected");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2016-07-06 05:23:04 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateBarrier(
|
|
|
|
DB->Encoding, Tok.getString(), getLoc(), getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
Parser.Lex(); // Consume the option
|
|
|
|
|
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseSysReg(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
|
|
|
|
if (Tok.isNot(AsmToken::Identifier))
|
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
2016-07-06 05:23:04 +08:00
|
|
|
int MRSReg, MSRReg;
|
|
|
|
auto SysReg = AArch64SysReg::lookupSysRegByName(Tok.getString());
|
|
|
|
if (SysReg && SysReg->haveFeatures(getSTI().getFeatureBits())) {
|
|
|
|
MRSReg = SysReg->Readable ? SysReg->Encoding : -1;
|
|
|
|
MSRReg = SysReg->Writeable ? SysReg->Encoding : -1;
|
|
|
|
} else
|
|
|
|
MRSReg = MSRReg = AArch64SysReg::parseGenericRegister(Tok.getString());
|
|
|
|
|
|
|
|
auto PState = AArch64PState::lookupPStateByName(Tok.getString());
|
|
|
|
unsigned PStateImm = -1;
|
|
|
|
if (PState && PState->haveFeatures(getSTI().getFeatureBits()))
|
|
|
|
PStateImm = PState->Encoding;
|
|
|
|
|
|
|
|
Operands.push_back(
|
|
|
|
AArch64Operand::CreateSysReg(Tok.getString(), getLoc(), MRSReg, MSRReg,
|
|
|
|
PStateImm, getContext()));
|
2014-04-09 22:43:06 +08:00
|
|
|
Parser.Lex(); // Eat identifier
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tryParseVectorRegister - Parse a vector register operand.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::tryParseVectorRegister(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SMLoc S = getLoc();
|
|
|
|
// Check for a vector register specifier first.
|
|
|
|
StringRef Kind;
|
2014-04-09 22:41:58 +08:00
|
|
|
int64_t Reg = tryMatchVectorRegister(Kind, false);
|
2014-03-29 18:18:08 +08:00
|
|
|
if (Reg == -1)
|
|
|
|
return true;
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateReg(Reg, true, S, getLoc(), getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
// If there was an explicit qualifier, that goes on as a literal text
|
|
|
|
// operand.
|
|
|
|
if (!Kind.empty())
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(
|
|
|
|
AArch64Operand::CreateToken(Kind, false, S, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// If there is an index specifier following the register, parse that too.
|
|
|
|
if (Parser.getTok().is(AsmToken::LBrac)) {
|
|
|
|
SMLoc SIdx = getLoc();
|
|
|
|
Parser.Lex(); // Eat left bracket token.
|
|
|
|
|
|
|
|
const MCExpr *ImmVal;
|
|
|
|
if (getParser().parseExpression(ImmVal))
|
2014-04-01 20:22:20 +08:00
|
|
|
return false;
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
|
|
|
|
if (!MCE) {
|
|
|
|
TokError("immediate value expected for vector index");
|
2014-04-01 20:22:20 +08:00
|
|
|
return false;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SMLoc E = getLoc();
|
|
|
|
if (Parser.getTok().isNot(AsmToken::RBrac)) {
|
|
|
|
Error(E, "']' expected");
|
2014-04-01 20:22:20 +08:00
|
|
|
return false;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat right bracket token.
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateVectorIndex(MCE->getValue(), SIdx,
|
|
|
|
E, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// parseRegister - Parse a non-vector register operand.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseRegister(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
SMLoc S = getLoc();
|
|
|
|
// Try for a vector register.
|
|
|
|
if (!tryParseVectorRegister(Operands))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Try for a scalar register.
|
|
|
|
int64_t Reg = tryParseRegister();
|
|
|
|
if (Reg == -1)
|
|
|
|
return true;
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateReg(Reg, false, S, getLoc(), getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// A small number of instructions (FMOVXDhighr, for example) have "[1]"
|
|
|
|
// as a string token in the instruction itself.
|
|
|
|
if (getLexer().getKind() == AsmToken::LBrac) {
|
|
|
|
SMLoc LBracS = getLoc();
|
|
|
|
Parser.Lex();
|
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
if (Tok.is(AsmToken::Integer)) {
|
|
|
|
SMLoc IntS = getLoc();
|
|
|
|
int64_t Val = Tok.getIntVal();
|
|
|
|
if (Val == 1) {
|
|
|
|
Parser.Lex();
|
|
|
|
if (getLexer().getKind() == AsmToken::RBrac) {
|
|
|
|
SMLoc RBracS = getLoc();
|
|
|
|
Parser.Lex();
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken("[", false, LBracS, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken("1", false, IntS, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken("]", false, RBracS, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
bool HasELFModifier = false;
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VariantKind RefKind;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
if (Parser.getTok().is(AsmToken::Colon)) {
|
|
|
|
Parser.Lex(); // Eat ':"
|
|
|
|
HasELFModifier = true;
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
Error(Parser.getTok().getLoc(),
|
|
|
|
"expect relocation specifier in operand after ':'");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LowerCase = Parser.getTok().getIdentifier().lower();
|
2014-05-24 20:50:23 +08:00
|
|
|
RefKind = StringSwitch<AArch64MCExpr::VariantKind>(LowerCase)
|
|
|
|
.Case("lo12", AArch64MCExpr::VK_LO12)
|
|
|
|
.Case("abs_g3", AArch64MCExpr::VK_ABS_G3)
|
|
|
|
.Case("abs_g2", AArch64MCExpr::VK_ABS_G2)
|
|
|
|
.Case("abs_g2_s", AArch64MCExpr::VK_ABS_G2_S)
|
|
|
|
.Case("abs_g2_nc", AArch64MCExpr::VK_ABS_G2_NC)
|
|
|
|
.Case("abs_g1", AArch64MCExpr::VK_ABS_G1)
|
|
|
|
.Case("abs_g1_s", AArch64MCExpr::VK_ABS_G1_S)
|
|
|
|
.Case("abs_g1_nc", AArch64MCExpr::VK_ABS_G1_NC)
|
|
|
|
.Case("abs_g0", AArch64MCExpr::VK_ABS_G0)
|
|
|
|
.Case("abs_g0_s", AArch64MCExpr::VK_ABS_G0_S)
|
|
|
|
.Case("abs_g0_nc", AArch64MCExpr::VK_ABS_G0_NC)
|
|
|
|
.Case("dtprel_g2", AArch64MCExpr::VK_DTPREL_G2)
|
|
|
|
.Case("dtprel_g1", AArch64MCExpr::VK_DTPREL_G1)
|
|
|
|
.Case("dtprel_g1_nc", AArch64MCExpr::VK_DTPREL_G1_NC)
|
|
|
|
.Case("dtprel_g0", AArch64MCExpr::VK_DTPREL_G0)
|
|
|
|
.Case("dtprel_g0_nc", AArch64MCExpr::VK_DTPREL_G0_NC)
|
|
|
|
.Case("dtprel_hi12", AArch64MCExpr::VK_DTPREL_HI12)
|
|
|
|
.Case("dtprel_lo12", AArch64MCExpr::VK_DTPREL_LO12)
|
|
|
|
.Case("dtprel_lo12_nc", AArch64MCExpr::VK_DTPREL_LO12_NC)
|
|
|
|
.Case("tprel_g2", AArch64MCExpr::VK_TPREL_G2)
|
|
|
|
.Case("tprel_g1", AArch64MCExpr::VK_TPREL_G1)
|
|
|
|
.Case("tprel_g1_nc", AArch64MCExpr::VK_TPREL_G1_NC)
|
|
|
|
.Case("tprel_g0", AArch64MCExpr::VK_TPREL_G0)
|
|
|
|
.Case("tprel_g0_nc", AArch64MCExpr::VK_TPREL_G0_NC)
|
|
|
|
.Case("tprel_hi12", AArch64MCExpr::VK_TPREL_HI12)
|
|
|
|
.Case("tprel_lo12", AArch64MCExpr::VK_TPREL_LO12)
|
|
|
|
.Case("tprel_lo12_nc", AArch64MCExpr::VK_TPREL_LO12_NC)
|
|
|
|
.Case("tlsdesc_lo12", AArch64MCExpr::VK_TLSDESC_LO12)
|
|
|
|
.Case("got", AArch64MCExpr::VK_GOT_PAGE)
|
|
|
|
.Case("got_lo12", AArch64MCExpr::VK_GOT_LO12)
|
|
|
|
.Case("gottprel", AArch64MCExpr::VK_GOTTPREL_PAGE)
|
|
|
|
.Case("gottprel_lo12", AArch64MCExpr::VK_GOTTPREL_LO12_NC)
|
|
|
|
.Case("gottprel_g1", AArch64MCExpr::VK_GOTTPREL_G1)
|
|
|
|
.Case("gottprel_g0_nc", AArch64MCExpr::VK_GOTTPREL_G0_NC)
|
|
|
|
.Case("tlsdesc", AArch64MCExpr::VK_TLSDESC_PAGE)
|
|
|
|
.Default(AArch64MCExpr::VK_INVALID);
|
|
|
|
|
|
|
|
if (RefKind == AArch64MCExpr::VK_INVALID) {
|
2014-03-29 18:18:08 +08:00
|
|
|
Error(Parser.getTok().getLoc(),
|
|
|
|
"expect relocation specifier in operand after ':'");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat identifier
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Colon)) {
|
|
|
|
Error(Parser.getTok().getLoc(), "expect ':' after relocation specifier");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Parser.Lex(); // Eat ':'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getParser().parseExpression(ImmVal))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (HasELFModifier)
|
2015-05-30 09:25:56 +08:00
|
|
|
ImmVal = AArch64MCExpr::create(ImmVal, RefKind, getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// parseVectorList - Parse a vector list operand for AdvSIMD instructions.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseVectorList(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
assert(Parser.getTok().is(AsmToken::LCurly) && "Token is not a Left Bracket");
|
|
|
|
SMLoc S = getLoc();
|
|
|
|
Parser.Lex(); // Eat left bracket token.
|
|
|
|
StringRef Kind;
|
2014-04-09 22:41:58 +08:00
|
|
|
int64_t FirstReg = tryMatchVectorRegister(Kind, true);
|
2014-03-29 18:18:08 +08:00
|
|
|
if (FirstReg == -1)
|
2014-04-09 22:41:58 +08:00
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
int64_t PrevReg = FirstReg;
|
|
|
|
unsigned Count = 1;
|
|
|
|
|
2014-04-09 22:41:58 +08:00
|
|
|
if (Parser.getTok().is(AsmToken::Minus)) {
|
|
|
|
Parser.Lex(); // Eat the minus.
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
SMLoc Loc = getLoc();
|
|
|
|
StringRef NextKind;
|
2014-04-09 22:41:58 +08:00
|
|
|
int64_t Reg = tryMatchVectorRegister(NextKind, true);
|
2014-03-29 18:18:08 +08:00
|
|
|
if (Reg == -1)
|
2014-04-09 22:41:58 +08:00
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
// Any Kind suffices must match on all regs in the list.
|
|
|
|
if (Kind != NextKind)
|
|
|
|
return Error(Loc, "mismatched register size suffix");
|
|
|
|
|
2014-04-09 22:41:58 +08:00
|
|
|
unsigned Space = (PrevReg < Reg) ? (Reg - PrevReg) : (Reg + 32 - PrevReg);
|
|
|
|
|
|
|
|
if (Space == 0 || Space > 3) {
|
|
|
|
return Error(Loc, "invalid number of vectors");
|
|
|
|
}
|
|
|
|
|
|
|
|
Count += Space;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (Parser.getTok().is(AsmToken::Comma)) {
|
|
|
|
Parser.Lex(); // Eat the comma token.
|
|
|
|
|
|
|
|
SMLoc Loc = getLoc();
|
|
|
|
StringRef NextKind;
|
|
|
|
int64_t Reg = tryMatchVectorRegister(NextKind, true);
|
|
|
|
if (Reg == -1)
|
|
|
|
return true;
|
|
|
|
// Any Kind suffices must match on all regs in the list.
|
|
|
|
if (Kind != NextKind)
|
|
|
|
return Error(Loc, "mismatched register size suffix");
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-04-09 22:41:58 +08:00
|
|
|
// Registers must be incremental (with wraparound at 31)
|
|
|
|
if (getContext().getRegisterInfo()->getEncodingValue(Reg) !=
|
|
|
|
(getContext().getRegisterInfo()->getEncodingValue(PrevReg) + 1) % 32)
|
|
|
|
return Error(Loc, "registers must be sequential");
|
|
|
|
|
|
|
|
PrevReg = Reg;
|
|
|
|
++Count;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
2014-04-09 22:41:58 +08:00
|
|
|
|
2014-05-06 20:50:51 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::RCurly))
|
|
|
|
return Error(getLoc(), "'}' expected");
|
2014-03-29 18:18:08 +08:00
|
|
|
Parser.Lex(); // Eat the '}' token.
|
|
|
|
|
2014-05-06 20:50:51 +08:00
|
|
|
if (Count > 4)
|
|
|
|
return Error(S, "invalid number of vectors");
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned NumElements = 0;
|
|
|
|
char ElementKind = 0;
|
|
|
|
if (!Kind.empty())
|
|
|
|
parseValidVectorKind(Kind, NumElements, ElementKind);
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateVectorList(
|
2014-03-29 18:18:08 +08:00
|
|
|
FirstReg, Count, NumElements, ElementKind, S, getLoc(), getContext()));
|
|
|
|
|
|
|
|
// If there is an index specifier following the list, parse that too.
|
|
|
|
if (Parser.getTok().is(AsmToken::LBrac)) {
|
|
|
|
SMLoc SIdx = getLoc();
|
|
|
|
Parser.Lex(); // Eat left bracket token.
|
|
|
|
|
|
|
|
const MCExpr *ImmVal;
|
|
|
|
if (getParser().parseExpression(ImmVal))
|
2014-04-01 20:22:20 +08:00
|
|
|
return false;
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
|
|
|
|
if (!MCE) {
|
|
|
|
TokError("immediate value expected for vector index");
|
2014-04-01 20:22:20 +08:00
|
|
|
return false;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SMLoc E = getLoc();
|
|
|
|
if (Parser.getTok().isNot(AsmToken::RBrac)) {
|
|
|
|
Error(E, "']' expected");
|
2014-04-01 20:22:20 +08:00
|
|
|
return false;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat right bracket token.
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateVectorIndex(MCE->getValue(), SIdx,
|
|
|
|
E, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseGPR64sp0Operand(OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-05-22 19:56:09 +08:00
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
if (!Tok.is(AsmToken::Identifier))
|
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
2014-07-02 12:50:23 +08:00
|
|
|
unsigned RegNum = matchRegisterNameAlias(Tok.getString().lower(), false);
|
2014-05-22 19:56:09 +08:00
|
|
|
|
|
|
|
MCContext &Ctx = getContext();
|
|
|
|
const MCRegisterInfo *RI = Ctx.getRegisterInfo();
|
2014-05-24 20:50:23 +08:00
|
|
|
if (!RI->getRegClass(AArch64::GPR64spRegClassID).contains(RegNum))
|
2014-05-22 19:56:09 +08:00
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
|
|
|
SMLoc S = getLoc();
|
|
|
|
Parser.Lex(); // Eat register
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Comma)) {
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(
|
|
|
|
AArch64Operand::CreateReg(RegNum, false, S, getLoc(), Ctx));
|
2014-05-22 19:56:09 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
Parser.Lex(); // Eat comma.
|
|
|
|
|
|
|
|
if (Parser.getTok().is(AsmToken::Hash))
|
|
|
|
Parser.Lex(); // Eat hash
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Integer)) {
|
|
|
|
Error(getLoc(), "index must be absent or #0");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCExpr *ImmVal;
|
|
|
|
if (Parser.parseExpression(ImmVal) || !isa<MCConstantExpr>(ImmVal) ||
|
|
|
|
cast<MCConstantExpr>(ImmVal)->getValue() != 0) {
|
|
|
|
Error(getLoc(), "index must be absent or #0");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(
|
|
|
|
AArch64Operand::CreateReg(RegNum, false, S, getLoc(), Ctx));
|
2014-05-22 19:56:09 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// parseOperand - Parse a arm instruction operand. For now this parses the
|
|
|
|
/// operand regardless of the mnemonic.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,
|
2014-03-29 18:18:08 +08:00
|
|
|
bool invertCondCode) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
// Check if the current operand has a custom associated parser, if so, try to
|
|
|
|
// custom parse the operand, or fallback to the general approach.
|
|
|
|
OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
|
|
|
|
if (ResTy == MatchOperand_Success)
|
|
|
|
return false;
|
|
|
|
// If there wasn't a custom match, try the generic matcher below. Otherwise,
|
|
|
|
// there was a match, but an error occurred, in which case, just return that
|
|
|
|
// the operand parsing failed.
|
|
|
|
if (ResTy == MatchOperand_ParseFail)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Nothing custom, so do general case parsing.
|
|
|
|
SMLoc S, E;
|
|
|
|
switch (getLexer().getKind()) {
|
|
|
|
default: {
|
|
|
|
SMLoc S = getLoc();
|
|
|
|
const MCExpr *Expr;
|
|
|
|
if (parseSymbolicImmVal(Expr))
|
|
|
|
return Error(S, "invalid operand");
|
|
|
|
|
|
|
|
SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-22 19:56:09 +08:00
|
|
|
case AsmToken::LBrac: {
|
|
|
|
SMLoc Loc = Parser.getTok().getLoc();
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateToken("[", false, Loc,
|
|
|
|
getContext()));
|
2014-05-22 19:56:09 +08:00
|
|
|
Parser.Lex(); // Eat '['
|
|
|
|
|
|
|
|
// There's no comma after a '[', so we can parse the next operand
|
|
|
|
// immediately.
|
|
|
|
return parseOperand(Operands, false, false);
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
case AsmToken::LCurly:
|
|
|
|
return parseVectorList(Operands);
|
|
|
|
case AsmToken::Identifier: {
|
|
|
|
// If we're expecting a Condition Code operand, then just parse that.
|
|
|
|
if (isCondCode)
|
|
|
|
return parseCondCode(Operands, invertCondCode);
|
|
|
|
|
|
|
|
// If it's a register name, parse it.
|
|
|
|
if (!parseRegister(Operands))
|
|
|
|
return false;
|
|
|
|
|
2014-05-12 22:13:17 +08:00
|
|
|
// This could be an optional "shift" or "extend" operand.
|
|
|
|
OperandMatchResultTy GotShift = tryParseOptionalShiftExtend(Operands);
|
2014-05-08 22:11:16 +08:00
|
|
|
// We can only continue if no tokens were eaten.
|
|
|
|
if (GotShift != MatchOperand_NoMatch)
|
|
|
|
return GotShift;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// This was not a register so parse other operands that start with an
|
|
|
|
// identifier (like labels) as expressions and create them as immediates.
|
|
|
|
const MCExpr *IdVal;
|
|
|
|
S = getLoc();
|
|
|
|
if (getParser().parseExpression(IdVal))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateImm(IdVal, S, E, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-15 19:43:09 +08:00
|
|
|
case AsmToken::Integer:
|
|
|
|
case AsmToken::Real:
|
2014-03-29 18:18:08 +08:00
|
|
|
case AsmToken::Hash: {
|
|
|
|
// #42 -> immediate.
|
|
|
|
S = getLoc();
|
2014-04-15 19:43:09 +08:00
|
|
|
if (getLexer().is(AsmToken::Hash))
|
|
|
|
Parser.Lex();
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-15 19:07:28 +08:00
|
|
|
// Parse a negative sign
|
|
|
|
bool isNegative = false;
|
|
|
|
if (Parser.getTok().is(AsmToken::Minus)) {
|
|
|
|
isNegative = true;
|
|
|
|
// We need to consume this token only when we have a Real, otherwise
|
|
|
|
// we let parseSymbolicImmVal take care of it
|
|
|
|
if (Parser.getLexer().peekTok().is(AsmToken::Real))
|
|
|
|
Parser.Lex();
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// The only Real that should come through here is a literal #0.0 for
|
|
|
|
// the fcmp[e] r, #0.0 instructions. They expect raw token operands,
|
|
|
|
// so convert the value.
|
|
|
|
const AsmToken &Tok = Parser.getTok();
|
|
|
|
if (Tok.is(AsmToken::Real)) {
|
|
|
|
APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
|
|
|
|
uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
|
2014-05-06 20:50:47 +08:00
|
|
|
if (Mnemonic != "fcmp" && Mnemonic != "fcmpe" && Mnemonic != "fcmeq" &&
|
|
|
|
Mnemonic != "fcmge" && Mnemonic != "fcmgt" && Mnemonic != "fcmle" &&
|
|
|
|
Mnemonic != "fcmlt")
|
2014-03-29 18:18:08 +08:00
|
|
|
return TokError("unexpected floating point literal");
|
2014-05-15 19:07:28 +08:00
|
|
|
else if (IntVal != 0 || isNegative)
|
|
|
|
return TokError("expected floating-point constant #0.0");
|
2014-03-29 18:18:08 +08:00
|
|
|
Parser.Lex(); // Eat the token.
|
|
|
|
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken("#0", false, S, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken(".0", false, S, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCExpr *ImmVal;
|
|
|
|
if (parseSymbolicImmVal(ImmVal))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateImm(ImmVal, S, E, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-06-25 00:21:38 +08:00
|
|
|
case AsmToken::Equal: {
|
|
|
|
SMLoc Loc = Parser.getTok().getLoc();
|
|
|
|
if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
|
|
|
|
return Error(Loc, "unexpected token in operand");
|
|
|
|
Parser.Lex(); // Eat '='
|
|
|
|
const MCExpr *SubExprVal;
|
|
|
|
if (getParser().parseExpression(SubExprVal))
|
|
|
|
return true;
|
|
|
|
|
2014-07-19 00:05:14 +08:00
|
|
|
if (Operands.size() < 2 ||
|
|
|
|
!static_cast<AArch64Operand &>(*Operands[1]).isReg())
|
2015-11-16 18:25:19 +08:00
|
|
|
return Error(Loc, "Only valid when first operand is register");
|
2014-07-19 00:05:14 +08:00
|
|
|
|
|
|
|
bool IsXReg =
|
|
|
|
AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
|
|
|
|
Operands[1]->getReg());
|
|
|
|
|
2014-06-25 00:21:38 +08:00
|
|
|
MCContext& Ctx = getContext();
|
|
|
|
E = SMLoc::getFromPointer(Loc.getPointer() - 1);
|
|
|
|
// If the op is an imm and can be fit into a mov, then replace ldr with mov.
|
2014-07-19 00:05:14 +08:00
|
|
|
if (isa<MCConstantExpr>(SubExprVal)) {
|
2014-06-25 00:21:38 +08:00
|
|
|
uint64_t Imm = (cast<MCConstantExpr>(SubExprVal))->getValue();
|
|
|
|
uint32_t ShiftAmt = 0, MaxShiftAmt = IsXReg ? 48 : 16;
|
|
|
|
while(Imm > 0xFFFF && countTrailingZeros(Imm) >= 16) {
|
|
|
|
ShiftAmt += 16;
|
|
|
|
Imm >>= 16;
|
|
|
|
}
|
|
|
|
if (ShiftAmt <= MaxShiftAmt && Imm <= 0xFFFF) {
|
|
|
|
Operands[0] = AArch64Operand::CreateToken("movz", false, Loc, Ctx);
|
|
|
|
Operands.push_back(AArch64Operand::CreateImm(
|
2015-05-30 09:25:56 +08:00
|
|
|
MCConstantExpr::create(Imm, Ctx), S, E, Ctx));
|
2014-06-25 00:21:38 +08:00
|
|
|
if (ShiftAmt)
|
|
|
|
Operands.push_back(AArch64Operand::CreateShiftExtend(AArch64_AM::LSL,
|
|
|
|
ShiftAmt, true, S, E, Ctx));
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-19 00:05:14 +08:00
|
|
|
APInt Simm = APInt(64, Imm << ShiftAmt);
|
|
|
|
// check if the immediate is an unsigned or signed 32-bit int for W regs
|
|
|
|
if (!IsXReg && !(Simm.isIntN(32) || Simm.isSignedIntN(32)))
|
|
|
|
return Error(Loc, "Immediate too large for register");
|
2014-06-25 00:21:38 +08:00
|
|
|
}
|
|
|
|
// If it is a label or an imm that cannot fit in a movz, put it into CP.
|
2014-07-19 00:05:14 +08:00
|
|
|
const MCExpr *CPLoc =
|
2015-11-17 00:25:47 +08:00
|
|
|
getTargetStreamer().addConstantPoolEntry(SubExprVal, IsXReg ? 8 : 4, Loc);
|
2014-06-25 00:21:38 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateImm(CPLoc, S, E, Ctx));
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// ParseInstruction - Parse an AArch64 instruction mnemonic followed by its
|
2014-03-29 18:18:08 +08:00
|
|
|
/// operands.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::ParseInstruction(ParseInstructionInfo &Info,
|
|
|
|
StringRef Name, SMLoc NameLoc,
|
|
|
|
OperandVector &Operands) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-04-30 21:36:56 +08:00
|
|
|
Name = StringSwitch<StringRef>(Name.lower())
|
|
|
|
.Case("beq", "b.eq")
|
|
|
|
.Case("bne", "b.ne")
|
|
|
|
.Case("bhs", "b.hs")
|
|
|
|
.Case("bcs", "b.cs")
|
|
|
|
.Case("blo", "b.lo")
|
|
|
|
.Case("bcc", "b.cc")
|
|
|
|
.Case("bmi", "b.mi")
|
|
|
|
.Case("bpl", "b.pl")
|
|
|
|
.Case("bvs", "b.vs")
|
|
|
|
.Case("bvc", "b.vc")
|
|
|
|
.Case("bhi", "b.hi")
|
|
|
|
.Case("bls", "b.ls")
|
|
|
|
.Case("bge", "b.ge")
|
|
|
|
.Case("blt", "b.lt")
|
|
|
|
.Case("bgt", "b.gt")
|
|
|
|
.Case("ble", "b.le")
|
|
|
|
.Case("bal", "b.al")
|
|
|
|
.Case("bnv", "b.nv")
|
|
|
|
.Default(Name);
|
|
|
|
|
2014-07-02 12:50:23 +08:00
|
|
|
// First check for the AArch64-specific .req directive.
|
|
|
|
if (Parser.getTok().is(AsmToken::Identifier) &&
|
|
|
|
Parser.getTok().getIdentifier() == ".req") {
|
|
|
|
parseDirectiveReq(Name, NameLoc);
|
|
|
|
// We always return 'error' for this, as we're done with this
|
|
|
|
// statement and don't need to match the 'instruction."
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// Create the leading tokens for the mnemonic, split by '.' characters.
|
|
|
|
size_t Start = 0, Next = Name.find('.');
|
|
|
|
StringRef Head = Name.slice(Start, Next);
|
|
|
|
|
|
|
|
// IC, DC, AT, and TLBI instructions are aliases for the SYS instruction.
|
2014-05-16 00:28:32 +08:00
|
|
|
if (Head == "ic" || Head == "dc" || Head == "at" || Head == "tlbi") {
|
|
|
|
bool IsError = parseSysAlias(Head, NameLoc, Operands);
|
2016-09-14 02:17:00 +08:00
|
|
|
if (IsError && getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
Parser.eatToEndOfStatement();
|
2014-05-16 00:28:32 +08:00
|
|
|
return IsError;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken(Head, false, NameLoc, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
Mnemonic = Head;
|
|
|
|
|
|
|
|
// Handle condition codes for a branch mnemonic
|
|
|
|
if (Head == "b" && Next != StringRef::npos) {
|
|
|
|
Start = Next;
|
|
|
|
Next = Name.find('.', Start + 1);
|
|
|
|
Head = Name.slice(Start + 1, Next);
|
|
|
|
|
|
|
|
SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
|
|
|
|
(Head.data() - Name.data()));
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64CC::CondCode CC = parseCondCodeString(Head);
|
|
|
|
if (CC == AArch64CC::Invalid)
|
2014-03-29 18:18:08 +08:00
|
|
|
return Error(SuffixLoc, "invalid condition code");
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken(".", true, SuffixLoc, getContext()));
|
2014-05-15 19:06:51 +08:00
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateCondCode(CC, NameLoc, NameLoc, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the remaining tokens in the mnemonic.
|
|
|
|
while (Next != StringRef::npos) {
|
|
|
|
Start = Next;
|
|
|
|
Next = Name.find('.', Start + 1);
|
|
|
|
Head = Name.slice(Start, Next);
|
|
|
|
SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
|
|
|
|
(Head.data() - Name.data()) + 1);
|
|
|
|
Operands.push_back(
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64Operand::CreateToken(Head, true, SuffixLoc, getContext()));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional compare instructions have a Condition Code operand, which needs
|
|
|
|
// to be parsed and an immediate operand created.
|
|
|
|
bool condCodeFourthOperand =
|
|
|
|
(Head == "ccmp" || Head == "ccmn" || Head == "fccmp" ||
|
|
|
|
Head == "fccmpe" || Head == "fcsel" || Head == "csel" ||
|
|
|
|
Head == "csinc" || Head == "csinv" || Head == "csneg");
|
|
|
|
|
|
|
|
// These instructions are aliases to some of the conditional select
|
|
|
|
// instructions. However, the condition code is inverted in the aliased
|
|
|
|
// instruction.
|
|
|
|
//
|
|
|
|
// FIXME: Is this the correct way to handle these? Or should the parser
|
|
|
|
// generate the aliased instructions directly?
|
|
|
|
bool condCodeSecondOperand = (Head == "cset" || Head == "csetm");
|
|
|
|
bool condCodeThirdOperand =
|
|
|
|
(Head == "cinc" || Head == "cinv" || Head == "cneg");
|
|
|
|
|
|
|
|
// Read the remaining operands.
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
|
|
|
// Read the first operand.
|
|
|
|
if (parseOperand(Operands, false, false)) {
|
2016-09-14 02:17:00 +08:00
|
|
|
Parser.eatToEndOfStatement();
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned N = 2;
|
|
|
|
while (getLexer().is(AsmToken::Comma)) {
|
|
|
|
Parser.Lex(); // Eat the comma.
|
|
|
|
|
|
|
|
// Parse and remember the operand.
|
|
|
|
if (parseOperand(Operands, (N == 4 && condCodeFourthOperand) ||
|
|
|
|
(N == 3 && condCodeThirdOperand) ||
|
|
|
|
(N == 2 && condCodeSecondOperand),
|
|
|
|
condCodeSecondOperand || condCodeThirdOperand)) {
|
2016-09-14 02:17:00 +08:00
|
|
|
Parser.eatToEndOfStatement();
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-22 19:56:09 +08:00
|
|
|
// After successfully parsing some operands there are two special cases to
|
|
|
|
// consider (i.e. notional operands not separated by commas). Both are due
|
|
|
|
// to memory specifiers:
|
|
|
|
// + An RBrac will end an address for load/store/prefetch
|
|
|
|
// + An '!' will indicate a pre-indexed operation.
|
|
|
|
//
|
|
|
|
// It's someone else's responsibility to make sure these tokens are sane
|
|
|
|
// in the given context!
|
|
|
|
if (Parser.getTok().is(AsmToken::RBrac)) {
|
|
|
|
SMLoc Loc = Parser.getTok().getLoc();
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateToken("]", false, Loc,
|
|
|
|
getContext()));
|
2014-05-22 19:56:09 +08:00
|
|
|
Parser.Lex();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Parser.getTok().is(AsmToken::Exclaim)) {
|
|
|
|
SMLoc Loc = Parser.getTok().getLoc();
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateToken("!", false, Loc,
|
|
|
|
getContext()));
|
2014-05-22 19:56:09 +08:00
|
|
|
Parser.Lex();
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
++N;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
|
|
|
SMLoc Loc = Parser.getTok().getLoc();
|
2016-09-14 02:17:00 +08:00
|
|
|
Parser.eatToEndOfStatement();
|
2014-03-29 18:18:08 +08:00
|
|
|
return Error(Loc, "unexpected token in argument list");
|
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex(); // Consume the EndOfStatement
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This entire function is a giant hack to provide us with decent
|
|
|
|
// operand range validation/diagnostics until TableGen/MC can be extended
|
|
|
|
// to support autogeneration of this kind of validation.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::validateInstruction(MCInst &Inst,
|
2014-03-29 18:18:08 +08:00
|
|
|
SmallVectorImpl<SMLoc> &Loc) {
|
|
|
|
const MCRegisterInfo *RI = getContext().getRegisterInfo();
|
|
|
|
// Check for indexed addressing modes w/ the base register being the
|
|
|
|
// same as a destination/source register or pair load where
|
|
|
|
// the Rt == Rt2. All of those are undefined behaviour.
|
|
|
|
switch (Inst.getOpcode()) {
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::LDPSWpre:
|
|
|
|
case AArch64::LDPWpost:
|
|
|
|
case AArch64::LDPWpre:
|
|
|
|
case AArch64::LDPXpost:
|
|
|
|
case AArch64::LDPXpre: {
|
2014-05-22 19:56:20 +08:00
|
|
|
unsigned Rt = Inst.getOperand(1).getReg();
|
|
|
|
unsigned Rt2 = Inst.getOperand(2).getReg();
|
|
|
|
unsigned Rn = Inst.getOperand(3).getReg();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (RI->isSubRegisterEq(Rn, Rt))
|
|
|
|
return Error(Loc[0], "unpredictable LDP instruction, writeback base "
|
|
|
|
"is also a destination");
|
|
|
|
if (RI->isSubRegisterEq(Rn, Rt2))
|
|
|
|
return Error(Loc[1], "unpredictable LDP instruction, writeback base "
|
|
|
|
"is also a destination");
|
2016-08-17 13:10:15 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::LDPDi:
|
|
|
|
case AArch64::LDPQi:
|
|
|
|
case AArch64::LDPSi:
|
|
|
|
case AArch64::LDPSWi:
|
|
|
|
case AArch64::LDPWi:
|
|
|
|
case AArch64::LDPXi: {
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned Rt = Inst.getOperand(0).getReg();
|
|
|
|
unsigned Rt2 = Inst.getOperand(1).getReg();
|
|
|
|
if (Rt == Rt2)
|
|
|
|
return Error(Loc[1], "unpredictable LDP instruction, Rt2==Rt");
|
|
|
|
break;
|
|
|
|
}
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::LDPDpost:
|
|
|
|
case AArch64::LDPDpre:
|
|
|
|
case AArch64::LDPQpost:
|
|
|
|
case AArch64::LDPQpre:
|
|
|
|
case AArch64::LDPSpost:
|
|
|
|
case AArch64::LDPSpre:
|
|
|
|
case AArch64::LDPSWpost: {
|
2014-05-22 19:56:20 +08:00
|
|
|
unsigned Rt = Inst.getOperand(1).getReg();
|
|
|
|
unsigned Rt2 = Inst.getOperand(2).getReg();
|
|
|
|
if (Rt == Rt2)
|
|
|
|
return Error(Loc[1], "unpredictable LDP instruction, Rt2==Rt");
|
|
|
|
break;
|
|
|
|
}
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::STPDpost:
|
|
|
|
case AArch64::STPDpre:
|
|
|
|
case AArch64::STPQpost:
|
|
|
|
case AArch64::STPQpre:
|
|
|
|
case AArch64::STPSpost:
|
|
|
|
case AArch64::STPSpre:
|
|
|
|
case AArch64::STPWpost:
|
|
|
|
case AArch64::STPWpre:
|
|
|
|
case AArch64::STPXpost:
|
|
|
|
case AArch64::STPXpre: {
|
2014-05-22 19:56:20 +08:00
|
|
|
unsigned Rt = Inst.getOperand(1).getReg();
|
|
|
|
unsigned Rt2 = Inst.getOperand(2).getReg();
|
|
|
|
unsigned Rn = Inst.getOperand(3).getReg();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (RI->isSubRegisterEq(Rn, Rt))
|
|
|
|
return Error(Loc[0], "unpredictable STP instruction, writeback base "
|
|
|
|
"is also a source");
|
|
|
|
if (RI->isSubRegisterEq(Rn, Rt2))
|
|
|
|
return Error(Loc[1], "unpredictable STP instruction, writeback base "
|
|
|
|
"is also a source");
|
|
|
|
break;
|
|
|
|
}
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::LDRBBpre:
|
|
|
|
case AArch64::LDRBpre:
|
|
|
|
case AArch64::LDRHHpre:
|
|
|
|
case AArch64::LDRHpre:
|
|
|
|
case AArch64::LDRSBWpre:
|
|
|
|
case AArch64::LDRSBXpre:
|
|
|
|
case AArch64::LDRSHWpre:
|
|
|
|
case AArch64::LDRSHXpre:
|
|
|
|
case AArch64::LDRSWpre:
|
|
|
|
case AArch64::LDRWpre:
|
|
|
|
case AArch64::LDRXpre:
|
|
|
|
case AArch64::LDRBBpost:
|
|
|
|
case AArch64::LDRBpost:
|
|
|
|
case AArch64::LDRHHpost:
|
|
|
|
case AArch64::LDRHpost:
|
|
|
|
case AArch64::LDRSBWpost:
|
|
|
|
case AArch64::LDRSBXpost:
|
|
|
|
case AArch64::LDRSHWpost:
|
|
|
|
case AArch64::LDRSHXpost:
|
|
|
|
case AArch64::LDRSWpost:
|
|
|
|
case AArch64::LDRWpost:
|
|
|
|
case AArch64::LDRXpost: {
|
2014-05-22 19:56:20 +08:00
|
|
|
unsigned Rt = Inst.getOperand(1).getReg();
|
|
|
|
unsigned Rn = Inst.getOperand(2).getReg();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (RI->isSubRegisterEq(Rn, Rt))
|
|
|
|
return Error(Loc[0], "unpredictable LDR instruction, writeback base "
|
|
|
|
"is also a source");
|
|
|
|
break;
|
|
|
|
}
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::STRBBpost:
|
|
|
|
case AArch64::STRBpost:
|
|
|
|
case AArch64::STRHHpost:
|
|
|
|
case AArch64::STRHpost:
|
|
|
|
case AArch64::STRWpost:
|
|
|
|
case AArch64::STRXpost:
|
|
|
|
case AArch64::STRBBpre:
|
|
|
|
case AArch64::STRBpre:
|
|
|
|
case AArch64::STRHHpre:
|
|
|
|
case AArch64::STRHpre:
|
|
|
|
case AArch64::STRWpre:
|
|
|
|
case AArch64::STRXpre: {
|
2014-05-22 19:56:20 +08:00
|
|
|
unsigned Rt = Inst.getOperand(1).getReg();
|
|
|
|
unsigned Rn = Inst.getOperand(2).getReg();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (RI->isSubRegisterEq(Rn, Rt))
|
|
|
|
return Error(Loc[0], "unpredictable STR instruction, writeback base "
|
|
|
|
"is also a source");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check immediate ranges. Separate from the above as there is overlap
|
|
|
|
// in the instructions being checked and this keeps the nested conditionals
|
|
|
|
// to a minimum.
|
|
|
|
switch (Inst.getOpcode()) {
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::ADDSWri:
|
|
|
|
case AArch64::ADDSXri:
|
|
|
|
case AArch64::ADDWri:
|
|
|
|
case AArch64::ADDXri:
|
|
|
|
case AArch64::SUBSWri:
|
|
|
|
case AArch64::SUBSXri:
|
|
|
|
case AArch64::SUBWri:
|
|
|
|
case AArch64::SUBXri: {
|
2014-05-08 23:39:58 +08:00
|
|
|
// Annoyingly we can't do this in the isAddSubImm predicate, so there is
|
|
|
|
// some slight duplication here.
|
|
|
|
if (Inst.getOperand(2).isExpr()) {
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCExpr *Expr = Inst.getOperand(2).getExpr();
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCExpr::VariantKind ELFRefKind;
|
2014-03-29 18:18:08 +08:00
|
|
|
MCSymbolRefExpr::VariantKind DarwinRefKind;
|
2014-04-24 20:56:38 +08:00
|
|
|
int64_t Addend;
|
2014-03-29 18:18:08 +08:00
|
|
|
if (!classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
|
|
|
|
return Error(Loc[2], "invalid immediate expression");
|
|
|
|
}
|
|
|
|
|
2014-05-08 23:39:58 +08:00
|
|
|
// Only allow these with ADDXri.
|
2014-05-01 00:13:26 +08:00
|
|
|
if ((DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
|
2014-05-08 23:39:58 +08:00
|
|
|
DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF) &&
|
2014-05-24 20:50:23 +08:00
|
|
|
Inst.getOpcode() == AArch64::ADDXri)
|
2014-05-01 00:13:26 +08:00
|
|
|
return false;
|
2014-05-08 23:39:58 +08:00
|
|
|
|
|
|
|
// Only allow these with ADDXri/ADDWri
|
2014-05-24 20:50:23 +08:00
|
|
|
if ((ELFRefKind == AArch64MCExpr::VK_LO12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_DTPREL_HI12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_TPREL_HI12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_TPREL_LO12 ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC ||
|
|
|
|
ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12) &&
|
|
|
|
(Inst.getOpcode() == AArch64::ADDXri ||
|
|
|
|
Inst.getOpcode() == AArch64::ADDWri))
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
|
2014-05-08 23:39:58 +08:00
|
|
|
// Don't allow expressions in the immediate field otherwise
|
2014-03-29 18:18:08 +08:00
|
|
|
return Error(Loc[2], "invalid immediate expression");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::showMatchError(SMLoc Loc, unsigned ErrCode) {
|
2014-03-29 18:18:08 +08:00
|
|
|
switch (ErrCode) {
|
|
|
|
case Match_MissingFeature:
|
|
|
|
return Error(Loc,
|
|
|
|
"instruction requires a CPU feature not currently enabled");
|
|
|
|
case Match_InvalidOperand:
|
|
|
|
return Error(Loc, "invalid operand for instruction");
|
|
|
|
case Match_InvalidSuffix:
|
|
|
|
return Error(Loc, "invalid type suffix for instruction");
|
2014-05-15 19:06:51 +08:00
|
|
|
case Match_InvalidCondCode:
|
|
|
|
return Error(Loc, "expected AArch64 condition code");
|
2014-05-08 22:12:12 +08:00
|
|
|
case Match_AddSubRegExtendSmall:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected '[su]xt[bhw]' or 'lsl' with optional integer in range [0, 4]");
|
|
|
|
case Match_AddSubRegExtendLarge:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'sxtx' 'uxtx' or 'lsl' with optional integer in range [0, 4]");
|
2014-05-08 23:39:58 +08:00
|
|
|
case Match_AddSubSecondSource:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected compatible register, symbol or integer in range [0, 4095]");
|
2014-05-12 17:38:16 +08:00
|
|
|
case Match_LogicalSecondSource:
|
|
|
|
return Error(Loc, "expected compatible register or logical immediate");
|
2014-05-15 19:06:16 +08:00
|
|
|
case Match_InvalidMovImm32Shift:
|
|
|
|
return Error(Loc, "expected 'lsl' with optional integer 0 or 16");
|
|
|
|
case Match_InvalidMovImm64Shift:
|
|
|
|
return Error(Loc, "expected 'lsl' with optional integer 0, 16, 32 or 48");
|
2014-05-08 23:40:39 +08:00
|
|
|
case Match_AddSubRegShift32:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'lsl', 'lsr' or 'asr' with optional integer in range [0, 31]");
|
|
|
|
case Match_AddSubRegShift64:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'lsl', 'lsr' or 'asr' with optional integer in range [0, 63]");
|
2014-05-15 19:07:28 +08:00
|
|
|
case Match_InvalidFPImm:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected compatible register or floating-point constant");
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_InvalidMemoryIndexedSImm9:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be an integer in range [-256, 255].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed4SImm7:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be a multiple of 4 in range [-256, 252].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed8SImm7:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be a multiple of 8 in range [-512, 504].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed16SImm7:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be a multiple of 16 in range [-1024, 1008].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryWExtend8:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'uxtw' or 'sxtw' with optional shift of #0");
|
|
|
|
case Match_InvalidMemoryWExtend16:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'uxtw' or 'sxtw' with optional shift of #0 or #1");
|
|
|
|
case Match_InvalidMemoryWExtend32:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'uxtw' or 'sxtw' with optional shift of #0 or #2");
|
|
|
|
case Match_InvalidMemoryWExtend64:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'uxtw' or 'sxtw' with optional shift of #0 or #3");
|
|
|
|
case Match_InvalidMemoryWExtend128:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'uxtw' or 'sxtw' with optional shift of #0 or #4");
|
|
|
|
case Match_InvalidMemoryXExtend8:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'lsl' or 'sxtx' with optional shift of #0");
|
|
|
|
case Match_InvalidMemoryXExtend16:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'lsl' or 'sxtx' with optional shift of #0 or #1");
|
|
|
|
case Match_InvalidMemoryXExtend32:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'lsl' or 'sxtx' with optional shift of #0 or #2");
|
|
|
|
case Match_InvalidMemoryXExtend64:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'lsl' or 'sxtx' with optional shift of #0 or #3");
|
|
|
|
case Match_InvalidMemoryXExtend128:
|
|
|
|
return Error(Loc,
|
|
|
|
"expected 'lsl' or 'sxtx' with optional shift of #0 or #4");
|
|
|
|
case Match_InvalidMemoryIndexed1:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be an integer in range [0, 4095].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed2:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be a multiple of 2 in range [0, 8190].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed4:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be a multiple of 4 in range [0, 16380].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed8:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be a multiple of 8 in range [0, 32760].");
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed16:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "index must be a multiple of 16 in range [0, 65520].");
|
2015-10-05 21:42:31 +08:00
|
|
|
case Match_InvalidImm0_1:
|
|
|
|
return Error(Loc, "immediate must be an integer in range [0, 1].");
|
2014-05-06 19:18:53 +08:00
|
|
|
case Match_InvalidImm0_7:
|
|
|
|
return Error(Loc, "immediate must be an integer in range [0, 7].");
|
|
|
|
case Match_InvalidImm0_15:
|
|
|
|
return Error(Loc, "immediate must be an integer in range [0, 15].");
|
|
|
|
case Match_InvalidImm0_31:
|
|
|
|
return Error(Loc, "immediate must be an integer in range [0, 31].");
|
|
|
|
case Match_InvalidImm0_63:
|
|
|
|
return Error(Loc, "immediate must be an integer in range [0, 63].");
|
2014-05-15 19:06:16 +08:00
|
|
|
case Match_InvalidImm0_127:
|
|
|
|
return Error(Loc, "immediate must be an integer in range [0, 127].");
|
|
|
|
case Match_InvalidImm0_65535:
|
|
|
|
return Error(Loc, "immediate must be an integer in range [0, 65535].");
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_InvalidImm1_8:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "immediate must be an integer in range [1, 8].");
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_InvalidImm1_16:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "immediate must be an integer in range [1, 16].");
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_InvalidImm1_32:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "immediate must be an integer in range [1, 32].");
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_InvalidImm1_64:
|
2014-05-06 19:18:53 +08:00
|
|
|
return Error(Loc, "immediate must be an integer in range [1, 64].");
|
2014-05-15 19:07:57 +08:00
|
|
|
case Match_InvalidIndex1:
|
|
|
|
return Error(Loc, "expected lane specifier '[1]'");
|
2014-05-06 20:50:44 +08:00
|
|
|
case Match_InvalidIndexB:
|
|
|
|
return Error(Loc, "vector lane must be an integer in range [0, 15].");
|
|
|
|
case Match_InvalidIndexH:
|
|
|
|
return Error(Loc, "vector lane must be an integer in range [0, 7].");
|
|
|
|
case Match_InvalidIndexS:
|
|
|
|
return Error(Loc, "vector lane must be an integer in range [0, 3].");
|
|
|
|
case Match_InvalidIndexD:
|
|
|
|
return Error(Loc, "vector lane must be an integer in range [0, 1].");
|
2014-04-09 22:44:12 +08:00
|
|
|
case Match_InvalidLabel:
|
|
|
|
return Error(Loc, "expected label or encodable integer pc offset");
|
2014-05-01 00:13:20 +08:00
|
|
|
case Match_MRS:
|
|
|
|
return Error(Loc, "expected readable system register");
|
|
|
|
case Match_MSR:
|
|
|
|
return Error(Loc, "expected writable system register or pstate");
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_MnemonicFail:
|
|
|
|
return Error(Loc, "unrecognized instruction mnemonic");
|
|
|
|
default:
|
2014-06-19 14:10:58 +08:00
|
|
|
llvm_unreachable("unexpected error code!");
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 20:32:53 +08:00
|
|
|
static const char *getSubtargetFeatureName(uint64_t Val);
|
2014-04-23 14:22:48 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
|
|
|
OperandVector &Operands,
|
|
|
|
MCStreamer &Out,
|
2014-08-18 19:49:42 +08:00
|
|
|
uint64_t &ErrorInfo,
|
2014-05-24 20:50:23 +08:00
|
|
|
bool MatchingInlineAsm) {
|
2014-03-29 18:18:08 +08:00
|
|
|
assert(!Operands.empty() && "Unexpect empty operand list!");
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op = static_cast<AArch64Operand &>(*Operands[0]);
|
|
|
|
assert(Op.isToken() && "Leading operand should always be a mnemonic!");
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
StringRef Tok = Op.getToken();
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned NumOperands = Operands.size();
|
|
|
|
|
2014-05-13 02:03:36 +08:00
|
|
|
if (NumOperands == 4 && Tok == "lsl") {
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op2 = static_cast<AArch64Operand &>(*Operands[2]);
|
|
|
|
AArch64Operand &Op3 = static_cast<AArch64Operand &>(*Operands[3]);
|
|
|
|
if (Op2.isReg() && Op3.isImm()) {
|
|
|
|
const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3.getImm());
|
2014-05-13 02:03:42 +08:00
|
|
|
if (Op3CE) {
|
|
|
|
uint64_t Op3Val = Op3CE->getValue();
|
|
|
|
uint64_t NewOp3Val = 0;
|
|
|
|
uint64_t NewOp4Val = 0;
|
2014-05-24 20:50:23 +08:00
|
|
|
if (AArch64MCRegisterClasses[AArch64::GPR32allRegClassID].contains(
|
2014-06-09 00:18:35 +08:00
|
|
|
Op2.getReg())) {
|
2014-05-13 02:03:42 +08:00
|
|
|
NewOp3Val = (32 - Op3Val) & 0x1f;
|
|
|
|
NewOp4Val = 31 - Op3Val;
|
|
|
|
} else {
|
|
|
|
NewOp3Val = (64 - Op3Val) & 0x3f;
|
|
|
|
NewOp4Val = 63 - Op3Val;
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
2014-05-13 02:03:42 +08:00
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *NewOp3 = MCConstantExpr::create(NewOp3Val, getContext());
|
|
|
|
const MCExpr *NewOp4 = MCConstantExpr::create(NewOp4Val, getContext());
|
2014-05-13 02:03:42 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
2014-06-09 00:18:35 +08:00
|
|
|
"ubfm", false, Op.getStartLoc(), getContext());
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands.push_back(AArch64Operand::CreateImm(
|
2014-06-09 00:18:35 +08:00
|
|
|
NewOp4, Op3.getStartLoc(), Op3.getEndLoc(), getContext()));
|
|
|
|
Operands[3] = AArch64Operand::CreateImm(NewOp3, Op3.getStartLoc(),
|
|
|
|
Op3.getEndLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-01 02:28:58 +08:00
|
|
|
} else if (NumOperands == 4 && Tok == "bfc") {
|
|
|
|
// FIXME: Horrible hack to handle BFC->BFM alias.
|
|
|
|
AArch64Operand &Op1 = static_cast<AArch64Operand &>(*Operands[1]);
|
|
|
|
AArch64Operand LSBOp = static_cast<AArch64Operand &>(*Operands[2]);
|
|
|
|
AArch64Operand WidthOp = static_cast<AArch64Operand &>(*Operands[3]);
|
|
|
|
|
|
|
|
if (Op1.isReg() && LSBOp.isImm() && WidthOp.isImm()) {
|
|
|
|
const MCConstantExpr *LSBCE = dyn_cast<MCConstantExpr>(LSBOp.getImm());
|
|
|
|
const MCConstantExpr *WidthCE = dyn_cast<MCConstantExpr>(WidthOp.getImm());
|
|
|
|
|
|
|
|
if (LSBCE && WidthCE) {
|
|
|
|
uint64_t LSB = LSBCE->getValue();
|
|
|
|
uint64_t Width = WidthCE->getValue();
|
|
|
|
|
|
|
|
uint64_t RegWidth = 0;
|
|
|
|
if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
|
|
|
|
Op1.getReg()))
|
|
|
|
RegWidth = 64;
|
|
|
|
else
|
|
|
|
RegWidth = 32;
|
|
|
|
|
|
|
|
if (LSB >= RegWidth)
|
|
|
|
return Error(LSBOp.getStartLoc(),
|
|
|
|
"expected integer in range [0, 31]");
|
|
|
|
if (Width < 1 || Width > RegWidth)
|
|
|
|
return Error(WidthOp.getStartLoc(),
|
|
|
|
"expected integer in range [1, 32]");
|
|
|
|
|
|
|
|
uint64_t ImmR = 0;
|
|
|
|
if (RegWidth == 32)
|
|
|
|
ImmR = (32 - LSB) & 0x1f;
|
|
|
|
else
|
|
|
|
ImmR = (64 - LSB) & 0x3f;
|
|
|
|
|
|
|
|
uint64_t ImmS = Width - 1;
|
|
|
|
|
|
|
|
if (ImmR != 0 && ImmS >= ImmR)
|
|
|
|
return Error(WidthOp.getStartLoc(),
|
|
|
|
"requested insert overflows register");
|
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *ImmRExpr = MCConstantExpr::create(ImmR, getContext());
|
|
|
|
const MCExpr *ImmSExpr = MCConstantExpr::create(ImmS, getContext());
|
2015-05-01 02:28:58 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
|
|
|
"bfm", false, Op.getStartLoc(), getContext());
|
|
|
|
Operands[2] = AArch64Operand::CreateReg(
|
|
|
|
RegWidth == 32 ? AArch64::WZR : AArch64::XZR, false, SMLoc(),
|
|
|
|
SMLoc(), getContext());
|
|
|
|
Operands[3] = AArch64Operand::CreateImm(
|
|
|
|
ImmRExpr, LSBOp.getStartLoc(), LSBOp.getEndLoc(), getContext());
|
|
|
|
Operands.emplace_back(
|
|
|
|
AArch64Operand::CreateImm(ImmSExpr, WidthOp.getStartLoc(),
|
|
|
|
WidthOp.getEndLoc(), getContext()));
|
|
|
|
}
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
} else if (NumOperands == 5) {
|
|
|
|
// FIXME: Horrible hack to handle the BFI -> BFM, SBFIZ->SBFM, and
|
|
|
|
// UBFIZ -> UBFM aliases.
|
|
|
|
if (Tok == "bfi" || Tok == "sbfiz" || Tok == "ubfiz") {
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op1 = static_cast<AArch64Operand &>(*Operands[1]);
|
|
|
|
AArch64Operand &Op3 = static_cast<AArch64Operand &>(*Operands[3]);
|
|
|
|
AArch64Operand &Op4 = static_cast<AArch64Operand &>(*Operands[4]);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
if (Op1.isReg() && Op3.isImm() && Op4.isImm()) {
|
|
|
|
const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3.getImm());
|
|
|
|
const MCConstantExpr *Op4CE = dyn_cast<MCConstantExpr>(Op4.getImm());
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
if (Op3CE && Op4CE) {
|
|
|
|
uint64_t Op3Val = Op3CE->getValue();
|
|
|
|
uint64_t Op4Val = Op4CE->getValue();
|
|
|
|
|
2014-05-12 17:44:57 +08:00
|
|
|
uint64_t RegWidth = 0;
|
2014-05-24 20:50:23 +08:00
|
|
|
if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
|
2014-06-09 00:18:35 +08:00
|
|
|
Op1.getReg()))
|
2014-05-12 17:44:57 +08:00
|
|
|
RegWidth = 64;
|
|
|
|
else
|
|
|
|
RegWidth = 32;
|
|
|
|
|
|
|
|
if (Op3Val >= RegWidth)
|
2014-06-09 00:18:35 +08:00
|
|
|
return Error(Op3.getStartLoc(),
|
2014-05-12 17:44:57 +08:00
|
|
|
"expected integer in range [0, 31]");
|
|
|
|
if (Op4Val < 1 || Op4Val > RegWidth)
|
2014-06-09 00:18:35 +08:00
|
|
|
return Error(Op4.getStartLoc(),
|
2014-05-12 17:44:57 +08:00
|
|
|
"expected integer in range [1, 32]");
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
uint64_t NewOp3Val = 0;
|
2015-05-01 02:28:58 +08:00
|
|
|
if (RegWidth == 32)
|
2014-03-29 18:18:08 +08:00
|
|
|
NewOp3Val = (32 - Op3Val) & 0x1f;
|
|
|
|
else
|
|
|
|
NewOp3Val = (64 - Op3Val) & 0x3f;
|
|
|
|
|
|
|
|
uint64_t NewOp4Val = Op4Val - 1;
|
|
|
|
|
2014-05-12 17:44:57 +08:00
|
|
|
if (NewOp3Val != 0 && NewOp4Val >= NewOp3Val)
|
2014-06-09 00:18:35 +08:00
|
|
|
return Error(Op4.getStartLoc(),
|
2014-05-12 17:44:57 +08:00
|
|
|
"requested insert overflows register");
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCExpr *NewOp3 =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCConstantExpr::create(NewOp3Val, getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
const MCExpr *NewOp4 =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCConstantExpr::create(NewOp4Val, getContext());
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[3] = AArch64Operand::CreateImm(
|
2014-06-09 00:18:35 +08:00
|
|
|
NewOp3, Op3.getStartLoc(), Op3.getEndLoc(), getContext());
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[4] = AArch64Operand::CreateImm(
|
2014-06-09 00:18:35 +08:00
|
|
|
NewOp4, Op4.getStartLoc(), Op4.getEndLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
if (Tok == "bfi")
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
2014-06-09 00:18:35 +08:00
|
|
|
"bfm", false, Op.getStartLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
else if (Tok == "sbfiz")
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
2014-06-09 00:18:35 +08:00
|
|
|
"sbfm", false, Op.getStartLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
else if (Tok == "ubfiz")
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
2014-06-09 00:18:35 +08:00
|
|
|
"ubfm", false, Op.getStartLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("No valid mnemonic for alias?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Horrible hack to handle the BFXIL->BFM, SBFX->SBFM, and
|
|
|
|
// UBFX -> UBFM aliases.
|
|
|
|
} else if (NumOperands == 5 &&
|
|
|
|
(Tok == "bfxil" || Tok == "sbfx" || Tok == "ubfx")) {
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op1 = static_cast<AArch64Operand &>(*Operands[1]);
|
|
|
|
AArch64Operand &Op3 = static_cast<AArch64Operand &>(*Operands[3]);
|
|
|
|
AArch64Operand &Op4 = static_cast<AArch64Operand &>(*Operands[4]);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
if (Op1.isReg() && Op3.isImm() && Op4.isImm()) {
|
|
|
|
const MCConstantExpr *Op3CE = dyn_cast<MCConstantExpr>(Op3.getImm());
|
|
|
|
const MCConstantExpr *Op4CE = dyn_cast<MCConstantExpr>(Op4.getImm());
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
if (Op3CE && Op4CE) {
|
|
|
|
uint64_t Op3Val = Op3CE->getValue();
|
|
|
|
uint64_t Op4Val = Op4CE->getValue();
|
2014-05-12 17:44:57 +08:00
|
|
|
|
|
|
|
uint64_t RegWidth = 0;
|
2014-05-24 20:50:23 +08:00
|
|
|
if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
|
2014-06-09 00:18:35 +08:00
|
|
|
Op1.getReg()))
|
2014-05-12 17:44:57 +08:00
|
|
|
RegWidth = 64;
|
|
|
|
else
|
|
|
|
RegWidth = 32;
|
|
|
|
|
|
|
|
if (Op3Val >= RegWidth)
|
2014-06-09 00:18:35 +08:00
|
|
|
return Error(Op3.getStartLoc(),
|
2014-05-12 17:44:57 +08:00
|
|
|
"expected integer in range [0, 31]");
|
|
|
|
if (Op4Val < 1 || Op4Val > RegWidth)
|
2014-06-09 00:18:35 +08:00
|
|
|
return Error(Op4.getStartLoc(),
|
2014-05-12 17:44:57 +08:00
|
|
|
"expected integer in range [1, 32]");
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
uint64_t NewOp4Val = Op3Val + Op4Val - 1;
|
|
|
|
|
2014-05-12 17:44:57 +08:00
|
|
|
if (NewOp4Val >= RegWidth || NewOp4Val < Op3Val)
|
2014-06-09 00:18:35 +08:00
|
|
|
return Error(Op4.getStartLoc(),
|
2014-05-12 17:44:57 +08:00
|
|
|
"requested extract overflows register");
|
|
|
|
|
|
|
|
const MCExpr *NewOp4 =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCConstantExpr::create(NewOp4Val, getContext());
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[4] = AArch64Operand::CreateImm(
|
2014-06-09 00:18:35 +08:00
|
|
|
NewOp4, Op4.getStartLoc(), Op4.getEndLoc(), getContext());
|
2014-05-12 17:44:57 +08:00
|
|
|
if (Tok == "bfxil")
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
2014-06-09 00:18:35 +08:00
|
|
|
"bfm", false, Op.getStartLoc(), getContext());
|
2014-05-12 17:44:57 +08:00
|
|
|
else if (Tok == "sbfx")
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
2014-06-09 00:18:35 +08:00
|
|
|
"sbfm", false, Op.getStartLoc(), getContext());
|
2014-05-12 17:44:57 +08:00
|
|
|
else if (Tok == "ubfx")
|
2014-05-24 20:50:23 +08:00
|
|
|
Operands[0] = AArch64Operand::CreateToken(
|
2014-06-09 00:18:35 +08:00
|
|
|
"ubfm", false, Op.getStartLoc(), getContext());
|
2014-05-12 17:44:57 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("No valid mnemonic for alias?");
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FIXME: Horrible hack for sxtw and uxtw with Wn src and Xd dst operands.
|
|
|
|
// InstAlias can't quite handle this since the reg classes aren't
|
|
|
|
// subclasses.
|
|
|
|
if (NumOperands == 3 && (Tok == "sxtw" || Tok == "uxtw")) {
|
|
|
|
// The source register can be Wn here, but the matcher expects a
|
|
|
|
// GPR64. Twiddle it here if necessary.
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op = static_cast<AArch64Operand &>(*Operands[2]);
|
|
|
|
if (Op.isReg()) {
|
|
|
|
unsigned Reg = getXRegFromWReg(Op.getReg());
|
|
|
|
Operands[2] = AArch64Operand::CreateReg(Reg, false, Op.getStartLoc(),
|
|
|
|
Op.getEndLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
2014-04-30 21:37:02 +08:00
|
|
|
// FIXME: Likewise for sxt[bh] with a Xd dst operand
|
|
|
|
else if (NumOperands == 3 && (Tok == "sxtb" || Tok == "sxth")) {
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op = static_cast<AArch64Operand &>(*Operands[1]);
|
|
|
|
if (Op.isReg() &&
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
|
2014-06-09 00:18:35 +08:00
|
|
|
Op.getReg())) {
|
2014-03-29 18:18:08 +08:00
|
|
|
// The source register can be Wn here, but the matcher expects a
|
|
|
|
// GPR64. Twiddle it here if necessary.
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op = static_cast<AArch64Operand &>(*Operands[2]);
|
|
|
|
if (Op.isReg()) {
|
|
|
|
unsigned Reg = getXRegFromWReg(Op.getReg());
|
|
|
|
Operands[2] = AArch64Operand::CreateReg(Reg, false, Op.getStartLoc(),
|
|
|
|
Op.getEndLoc(), getContext());
|
2014-04-30 21:37:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FIXME: Likewise for uxt[bh] with a Xd dst operand
|
|
|
|
else if (NumOperands == 3 && (Tok == "uxtb" || Tok == "uxth")) {
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op = static_cast<AArch64Operand &>(*Operands[1]);
|
|
|
|
if (Op.isReg() &&
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
|
2014-06-09 00:18:35 +08:00
|
|
|
Op.getReg())) {
|
2014-04-30 21:37:02 +08:00
|
|
|
// The source register can be Wn here, but the matcher expects a
|
|
|
|
// GPR32. Twiddle it here if necessary.
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op = static_cast<AArch64Operand &>(*Operands[1]);
|
|
|
|
if (Op.isReg()) {
|
|
|
|
unsigned Reg = getWRegFromXReg(Op.getReg());
|
|
|
|
Operands[1] = AArch64Operand::CreateReg(Reg, false, Op.getStartLoc(),
|
|
|
|
Op.getEndLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yet another horrible hack to handle FMOV Rd, #0.0 using [WX]ZR.
|
|
|
|
if (NumOperands == 3 && Tok == "fmov") {
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &RegOp = static_cast<AArch64Operand &>(*Operands[1]);
|
|
|
|
AArch64Operand &ImmOp = static_cast<AArch64Operand &>(*Operands[2]);
|
|
|
|
if (RegOp.isReg() && ImmOp.isFPImm() && ImmOp.getFPImm() == (unsigned)-1) {
|
2014-05-24 20:50:23 +08:00
|
|
|
unsigned zreg =
|
2015-11-27 21:04:48 +08:00
|
|
|
!AArch64MCRegisterClasses[AArch64::FPR64RegClassID].contains(
|
2014-06-09 00:18:35 +08:00
|
|
|
RegOp.getReg())
|
2014-05-24 20:50:23 +08:00
|
|
|
? AArch64::WZR
|
|
|
|
: AArch64::XZR;
|
2014-06-09 00:18:35 +08:00
|
|
|
Operands[2] = AArch64Operand::CreateReg(zreg, false, Op.getStartLoc(),
|
|
|
|
Op.getEndLoc(), getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MCInst Inst;
|
|
|
|
// First try to match against the secondary set of tables containing the
|
|
|
|
// short-form NEON instructions (e.g. "fadd.2s v0, v1, v2").
|
|
|
|
unsigned MatchResult =
|
2015-06-30 20:32:53 +08:00
|
|
|
MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 1);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// If that fails, try against the alternate table containing long-form NEON:
|
|
|
|
// "fadd v0.2s, v1.2s, v2.2s"
|
2015-08-20 01:40:19 +08:00
|
|
|
if (MatchResult != Match_Success) {
|
|
|
|
// But first, save the short-form match result: we can use it in case the
|
|
|
|
// long-form match also fails.
|
|
|
|
auto ShortFormNEONErrorInfo = ErrorInfo;
|
|
|
|
auto ShortFormNEONMatchResult = MatchResult;
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
MatchResult =
|
2015-06-30 20:32:53 +08:00
|
|
|
MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 0);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-08-20 01:40:19 +08:00
|
|
|
// Now, both matches failed, and the long-form match failed on the mnemonic
|
|
|
|
// suffix token operand. The short-form match failure is probably more
|
|
|
|
// relevant: use it instead.
|
|
|
|
if (MatchResult == Match_InvalidOperand && ErrorInfo == 1 &&
|
2015-10-14 02:55:34 +08:00
|
|
|
Operands.size() > 1 && ((AArch64Operand &)*Operands[1]).isToken() &&
|
2015-08-20 01:40:19 +08:00
|
|
|
((AArch64Operand &)*Operands[1]).isTokenSuffix()) {
|
|
|
|
MatchResult = ShortFormNEONMatchResult;
|
|
|
|
ErrorInfo = ShortFormNEONErrorInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
switch (MatchResult) {
|
|
|
|
case Match_Success: {
|
|
|
|
// Perform range checking and other semantic validations
|
|
|
|
SmallVector<SMLoc, 8> OperandLocs;
|
|
|
|
NumOperands = Operands.size();
|
|
|
|
for (unsigned i = 1; i < NumOperands; ++i)
|
|
|
|
OperandLocs.push_back(Operands[i]->getStartLoc());
|
|
|
|
if (validateInstruction(Inst, OperandLocs))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Inst.setLoc(IDLoc);
|
2015-11-14 13:20:05 +08:00
|
|
|
Out.EmitInstruction(Inst, getSTI());
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-23 14:22:48 +08:00
|
|
|
case Match_MissingFeature: {
|
2015-06-30 20:32:53 +08:00
|
|
|
assert(ErrorInfo && "Unknown missing feature!");
|
2014-04-23 14:22:48 +08:00
|
|
|
// Special case the error message for the very common case where only
|
|
|
|
// a single subtarget feature is missing (neon, e.g.).
|
|
|
|
std::string Msg = "instruction requires:";
|
2015-06-30 20:32:53 +08:00
|
|
|
uint64_t Mask = 1;
|
|
|
|
for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
|
|
|
|
if (ErrorInfo & Mask) {
|
2014-04-23 14:22:48 +08:00
|
|
|
Msg += " ";
|
2015-06-30 20:32:53 +08:00
|
|
|
Msg += getSubtargetFeatureName(ErrorInfo & Mask);
|
2014-04-23 14:22:48 +08:00
|
|
|
}
|
2015-06-30 20:32:53 +08:00
|
|
|
Mask <<= 1;
|
2014-04-23 14:22:48 +08:00
|
|
|
}
|
|
|
|
return Error(IDLoc, Msg);
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_MnemonicFail:
|
|
|
|
return showMatchError(IDLoc, MatchResult);
|
|
|
|
case Match_InvalidOperand: {
|
|
|
|
SMLoc ErrorLoc = IDLoc;
|
2015-08-14 05:09:13 +08:00
|
|
|
|
2014-08-18 19:49:42 +08:00
|
|
|
if (ErrorInfo != ~0ULL) {
|
2014-03-29 18:18:08 +08:00
|
|
|
if (ErrorInfo >= Operands.size())
|
|
|
|
return Error(IDLoc, "too few operands for instruction");
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
ErrorLoc = ((AArch64Operand &)*Operands[ErrorInfo]).getStartLoc();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (ErrorLoc == SMLoc())
|
|
|
|
ErrorLoc = IDLoc;
|
|
|
|
}
|
|
|
|
// If the match failed on a suffix token operand, tweak the diagnostic
|
|
|
|
// accordingly.
|
2014-06-09 00:18:35 +08:00
|
|
|
if (((AArch64Operand &)*Operands[ErrorInfo]).isToken() &&
|
|
|
|
((AArch64Operand &)*Operands[ErrorInfo]).isTokenSuffix())
|
2014-03-29 18:18:08 +08:00
|
|
|
MatchResult = Match_InvalidSuffix;
|
|
|
|
|
|
|
|
return showMatchError(ErrorLoc, MatchResult);
|
|
|
|
}
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryIndexed1:
|
|
|
|
case Match_InvalidMemoryIndexed2:
|
|
|
|
case Match_InvalidMemoryIndexed4:
|
|
|
|
case Match_InvalidMemoryIndexed8:
|
|
|
|
case Match_InvalidMemoryIndexed16:
|
2014-05-15 19:06:51 +08:00
|
|
|
case Match_InvalidCondCode:
|
2014-05-08 22:12:12 +08:00
|
|
|
case Match_AddSubRegExtendSmall:
|
|
|
|
case Match_AddSubRegExtendLarge:
|
2014-05-08 23:39:58 +08:00
|
|
|
case Match_AddSubSecondSource:
|
2014-05-12 17:38:16 +08:00
|
|
|
case Match_LogicalSecondSource:
|
2014-05-08 23:40:39 +08:00
|
|
|
case Match_AddSubRegShift32:
|
|
|
|
case Match_AddSubRegShift64:
|
2014-05-15 19:06:16 +08:00
|
|
|
case Match_InvalidMovImm32Shift:
|
|
|
|
case Match_InvalidMovImm64Shift:
|
2014-05-15 19:07:28 +08:00
|
|
|
case Match_InvalidFPImm:
|
2014-05-22 19:56:09 +08:00
|
|
|
case Match_InvalidMemoryWExtend8:
|
|
|
|
case Match_InvalidMemoryWExtend16:
|
|
|
|
case Match_InvalidMemoryWExtend32:
|
|
|
|
case Match_InvalidMemoryWExtend64:
|
|
|
|
case Match_InvalidMemoryWExtend128:
|
|
|
|
case Match_InvalidMemoryXExtend8:
|
|
|
|
case Match_InvalidMemoryXExtend16:
|
|
|
|
case Match_InvalidMemoryXExtend32:
|
|
|
|
case Match_InvalidMemoryXExtend64:
|
|
|
|
case Match_InvalidMemoryXExtend128:
|
|
|
|
case Match_InvalidMemoryIndexed4SImm7:
|
|
|
|
case Match_InvalidMemoryIndexed8SImm7:
|
|
|
|
case Match_InvalidMemoryIndexed16SImm7:
|
|
|
|
case Match_InvalidMemoryIndexedSImm9:
|
2015-10-05 21:42:31 +08:00
|
|
|
case Match_InvalidImm0_1:
|
2014-05-06 19:18:53 +08:00
|
|
|
case Match_InvalidImm0_7:
|
|
|
|
case Match_InvalidImm0_15:
|
|
|
|
case Match_InvalidImm0_31:
|
|
|
|
case Match_InvalidImm0_63:
|
2014-05-15 19:06:16 +08:00
|
|
|
case Match_InvalidImm0_127:
|
|
|
|
case Match_InvalidImm0_65535:
|
2014-03-29 18:18:08 +08:00
|
|
|
case Match_InvalidImm1_8:
|
|
|
|
case Match_InvalidImm1_16:
|
|
|
|
case Match_InvalidImm1_32:
|
2014-04-09 22:44:12 +08:00
|
|
|
case Match_InvalidImm1_64:
|
2014-05-15 19:07:57 +08:00
|
|
|
case Match_InvalidIndex1:
|
2014-05-06 20:50:44 +08:00
|
|
|
case Match_InvalidIndexB:
|
|
|
|
case Match_InvalidIndexH:
|
|
|
|
case Match_InvalidIndexS:
|
|
|
|
case Match_InvalidIndexD:
|
2014-05-01 00:13:20 +08:00
|
|
|
case Match_InvalidLabel:
|
|
|
|
case Match_MSR:
|
|
|
|
case Match_MRS: {
|
2014-05-29 19:26:15 +08:00
|
|
|
if (ErrorInfo >= Operands.size())
|
|
|
|
return Error(IDLoc, "too few operands for instruction");
|
2014-03-29 18:18:08 +08:00
|
|
|
// Any time we get here, there's nothing fancy to do. Just get the
|
|
|
|
// operand SMLoc and display the diagnostic.
|
2014-06-09 00:18:35 +08:00
|
|
|
SMLoc ErrorLoc = ((AArch64Operand &)*Operands[ErrorInfo]).getStartLoc();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (ErrorLoc == SMLoc())
|
|
|
|
ErrorLoc = IDLoc;
|
|
|
|
return showMatchError(ErrorLoc, MatchResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Implement any new match types added!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseDirective parses the arm specific directives
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) {
|
2015-08-14 23:48:41 +08:00
|
|
|
const MCObjectFileInfo::Environment Format =
|
|
|
|
getContext().getObjectFileInfo()->getObjectFileType();
|
|
|
|
bool IsMachO = Format == MCObjectFileInfo::IsMachO;
|
|
|
|
bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
|
2014-10-23 04:35:57 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
StringRef IDVal = DirectiveID.getIdentifier();
|
|
|
|
SMLoc Loc = DirectiveID.getLoc();
|
2016-06-09 10:56:40 +08:00
|
|
|
if (IDVal == ".arch")
|
|
|
|
return parseDirectiveArch(Loc);
|
2016-04-03 03:29:52 +08:00
|
|
|
if (IDVal == ".cpu")
|
|
|
|
return parseDirectiveCPU(Loc);
|
2014-03-29 18:18:08 +08:00
|
|
|
if (IDVal == ".hword")
|
|
|
|
return parseDirectiveWord(2, Loc);
|
|
|
|
if (IDVal == ".word")
|
|
|
|
return parseDirectiveWord(4, Loc);
|
|
|
|
if (IDVal == ".xword")
|
|
|
|
return parseDirectiveWord(8, Loc);
|
|
|
|
if (IDVal == ".tlsdesccall")
|
|
|
|
return parseDirectiveTLSDescCall(Loc);
|
2014-06-25 00:21:38 +08:00
|
|
|
if (IDVal == ".ltorg" || IDVal == ".pool")
|
|
|
|
return parseDirectiveLtorg(Loc);
|
2014-07-02 12:50:23 +08:00
|
|
|
if (IDVal == ".unreq")
|
2015-05-29 02:18:21 +08:00
|
|
|
return parseDirectiveUnreq(Loc);
|
2014-07-02 12:50:23 +08:00
|
|
|
|
2014-10-23 04:35:57 +08:00
|
|
|
if (!IsMachO && !IsCOFF) {
|
|
|
|
if (IDVal == ".inst")
|
|
|
|
return parseDirectiveInst(Loc);
|
|
|
|
}
|
|
|
|
|
2016-09-14 02:17:00 +08:00
|
|
|
return parseDirectiveLOH(IDVal, Loc);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2016-04-03 03:29:52 +08:00
|
|
|
static const struct {
|
|
|
|
const char *Name;
|
|
|
|
const FeatureBitset Features;
|
|
|
|
} ExtensionMap[] = {
|
|
|
|
{ "crc", {AArch64::FeatureCRC} },
|
|
|
|
{ "crypto", {AArch64::FeatureCrypto} },
|
|
|
|
{ "fp", {AArch64::FeatureFPARMv8} },
|
|
|
|
{ "simd", {AArch64::FeatureNEON} },
|
2016-09-09 01:27:03 +08:00
|
|
|
{ "ras", {AArch64::FeatureRAS} },
|
2016-04-03 03:29:52 +08:00
|
|
|
|
|
|
|
// FIXME: Unsupported extensions
|
|
|
|
{ "lse", {} },
|
|
|
|
{ "pan", {} },
|
|
|
|
{ "lor", {} },
|
|
|
|
{ "rdma", {} },
|
|
|
|
{ "profile", {} },
|
|
|
|
};
|
|
|
|
|
2016-06-09 10:56:40 +08:00
|
|
|
/// parseDirectiveArch
|
|
|
|
/// ::= .arch token
|
|
|
|
bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
|
|
|
|
SMLoc ArchLoc = getLoc();
|
|
|
|
|
|
|
|
StringRef Arch, ExtensionString;
|
|
|
|
std::tie(Arch, ExtensionString) =
|
|
|
|
getParser().parseStringToEndOfStatement().trim().split('+');
|
|
|
|
|
|
|
|
unsigned ID = AArch64::parseArch(Arch);
|
2016-07-28 14:11:18 +08:00
|
|
|
if (ID == static_cast<unsigned>(AArch64::ArchKind::AK_INVALID)) {
|
2016-06-09 10:56:40 +08:00
|
|
|
Error(ArchLoc, "unknown arch name");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-09 01:27:03 +08:00
|
|
|
// Get the architecture and extension features.
|
|
|
|
std::vector<const char *> AArch64Features;
|
|
|
|
AArch64::getArchFeatures(ID, AArch64Features);
|
|
|
|
AArch64::getExtensionFeatures(AArch64::getDefaultExtensions("generic", ID),
|
|
|
|
AArch64Features);
|
|
|
|
|
2016-06-09 10:56:40 +08:00
|
|
|
MCSubtargetInfo &STI = copySTI();
|
2016-09-09 01:27:03 +08:00
|
|
|
std::vector<std::string> ArchFeatures(AArch64Features.begin(), AArch64Features.end());
|
|
|
|
STI.setDefaultFeatures("generic", join(ArchFeatures.begin(), ArchFeatures.end(), ","));
|
|
|
|
|
|
|
|
SmallVector<StringRef, 4> RequestedExtensions;
|
2016-06-09 10:56:40 +08:00
|
|
|
if (!ExtensionString.empty())
|
2016-09-09 01:27:03 +08:00
|
|
|
ExtensionString.split(RequestedExtensions, '+');
|
|
|
|
|
|
|
|
FeatureBitset Features = STI.getFeatureBits();
|
|
|
|
for (auto Name : RequestedExtensions) {
|
|
|
|
bool EnableFeature = true;
|
2016-06-09 10:56:40 +08:00
|
|
|
|
2016-09-09 01:27:03 +08:00
|
|
|
if (Name.startswith_lower("no")) {
|
|
|
|
EnableFeature = false;
|
|
|
|
Name = Name.substr(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &Extension : ExtensionMap) {
|
|
|
|
if (Extension.Name != Name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Extension.Features.none())
|
|
|
|
report_fatal_error("unsupported architectural extension: " + Name);
|
|
|
|
|
|
|
|
FeatureBitset ToggleFeatures = EnableFeature
|
|
|
|
? (~Features & Extension.Features)
|
|
|
|
: ( Features & Extension.Features);
|
|
|
|
uint64_t Features =
|
|
|
|
ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
|
|
|
|
setAvailableFeatures(Features);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-06-09 10:56:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-03 03:29:52 +08:00
|
|
|
/// parseDirectiveCPU
|
|
|
|
/// ::= .cpu id
|
|
|
|
bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
|
|
|
|
SMLoc CPULoc = getLoc();
|
|
|
|
|
|
|
|
StringRef CPU, ExtensionString;
|
|
|
|
std::tie(CPU, ExtensionString) =
|
|
|
|
getParser().parseStringToEndOfStatement().trim().split('+');
|
|
|
|
|
|
|
|
SmallVector<StringRef, 4> RequestedExtensions;
|
|
|
|
if (!ExtensionString.empty())
|
|
|
|
ExtensionString.split(RequestedExtensions, '+');
|
|
|
|
|
|
|
|
// FIXME This is using tablegen data, but should be moved to ARMTargetParser
|
|
|
|
// once that is tablegen'ed
|
|
|
|
if (!getSTI().isCPUStringValid(CPU)) {
|
|
|
|
Error(CPULoc, "unknown CPU name");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCSubtargetInfo &STI = copySTI();
|
|
|
|
STI.setDefaultFeatures(CPU, "");
|
|
|
|
|
|
|
|
FeatureBitset Features = STI.getFeatureBits();
|
|
|
|
for (auto Name : RequestedExtensions) {
|
|
|
|
bool EnableFeature = true;
|
|
|
|
|
|
|
|
if (Name.startswith_lower("no")) {
|
|
|
|
EnableFeature = false;
|
|
|
|
Name = Name.substr(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &Extension : ExtensionMap) {
|
|
|
|
if (Extension.Name != Name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Extension.Features.none())
|
|
|
|
report_fatal_error("unsupported architectural extension: " + Name);
|
|
|
|
|
|
|
|
FeatureBitset ToggleFeatures = EnableFeature
|
|
|
|
? (~Features & Extension.Features)
|
|
|
|
: ( Features & Extension.Features);
|
|
|
|
uint64_t Features =
|
|
|
|
ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
|
|
|
|
setAvailableFeatures(Features);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// parseDirectiveWord
|
|
|
|
/// ::= .word [ expression (, expression)* ]
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-03-29 18:18:08 +08:00
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
|
|
|
for (;;) {
|
|
|
|
const MCExpr *Value;
|
|
|
|
if (getParser().parseExpression(Value))
|
|
|
|
return true;
|
|
|
|
|
2015-11-17 00:22:47 +08:00
|
|
|
getParser().getStreamer().EmitValue(Value, Size, L);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
if (getLexer().is(AsmToken::EndOfStatement))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// FIXME: Improve diagnostic.
|
|
|
|
if (getLexer().isNot(AsmToken::Comma))
|
|
|
|
return Error(L, "unexpected token in directive");
|
|
|
|
Parser.Lex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:35:57 +08:00
|
|
|
/// parseDirectiveInst
|
|
|
|
/// ::= .inst opcode [, ...]
|
|
|
|
bool AArch64AsmParser::parseDirectiveInst(SMLoc Loc) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-10-23 04:35:57 +08:00
|
|
|
if (getLexer().is(AsmToken::EndOfStatement)) {
|
2016-09-14 02:17:00 +08:00
|
|
|
Parser.eatToEndOfStatement();
|
2014-10-23 04:35:57 +08:00
|
|
|
Error(Loc, "expected expression following directive");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
const MCExpr *Expr;
|
|
|
|
|
|
|
|
if (getParser().parseExpression(Expr)) {
|
|
|
|
Error(Loc, "expected expression");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
|
|
|
|
if (!Value) {
|
|
|
|
Error(Loc, "expected constant expression");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTargetStreamer().emitInst(Value->getValue());
|
|
|
|
|
|
|
|
if (getLexer().is(AsmToken::EndOfStatement))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::Comma)) {
|
|
|
|
Error(Loc, "unexpected token in directive");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex(); // Eat comma.
|
|
|
|
}
|
|
|
|
|
|
|
|
Parser.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// parseDirectiveTLSDescCall:
|
|
|
|
// ::= .tlsdesccall symbol
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseDirectiveTLSDescCall(SMLoc L) {
|
2014-03-29 18:18:08 +08:00
|
|
|
StringRef Name;
|
|
|
|
if (getParser().parseIdentifier(Name))
|
|
|
|
return Error(L, "expected symbol after directive");
|
|
|
|
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *Expr = MCSymbolRefExpr::create(Sym, getContext());
|
|
|
|
Expr = AArch64MCExpr::create(Expr, AArch64MCExpr::VK_TLSDESC, getContext());
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
MCInst Inst;
|
2014-05-24 20:50:23 +08:00
|
|
|
Inst.setOpcode(AArch64::TLSDESCCALL);
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createExpr(Expr));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-11-14 13:20:05 +08:00
|
|
|
getParser().getStreamer().EmitInstruction(Inst, getSTI());
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ::= .loh <lohName | lohId> label1, ..., labelN
|
|
|
|
/// The number of arguments depends on the loh identifier.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64AsmParser::parseDirectiveLOH(StringRef IDVal, SMLoc Loc) {
|
2016-09-14 02:17:00 +08:00
|
|
|
if (IDVal != MCLOHDirectiveName())
|
|
|
|
return true;
|
2014-03-29 18:18:08 +08:00
|
|
|
MCLOHType Kind;
|
|
|
|
if (getParser().getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
if (getParser().getTok().isNot(AsmToken::Integer))
|
|
|
|
return TokError("expected an identifier or a number in directive");
|
|
|
|
// We successfully get a numeric value for the identifier.
|
|
|
|
// Check if it is valid.
|
|
|
|
int64_t Id = getParser().getTok().getIntVal();
|
2016-09-14 02:17:00 +08:00
|
|
|
if (Id <= -1U && !isValidMCLOHType(Id))
|
|
|
|
return TokError("invalid numeric identifier in directive");
|
2014-08-30 06:34:28 +08:00
|
|
|
Kind = (MCLOHType)Id;
|
2014-03-29 18:18:08 +08:00
|
|
|
} else {
|
|
|
|
StringRef Name = getTok().getIdentifier();
|
|
|
|
// We successfully parse an identifier.
|
|
|
|
// Check if it is a recognized one.
|
|
|
|
int Id = MCLOHNameToId(Name);
|
|
|
|
|
|
|
|
if (Id == -1)
|
|
|
|
return TokError("invalid identifier in directive");
|
|
|
|
Kind = (MCLOHType)Id;
|
|
|
|
}
|
|
|
|
// Consume the identifier.
|
|
|
|
Lex();
|
|
|
|
// Get the number of arguments of this LOH.
|
|
|
|
int NbArgs = MCLOHIdToNbArgs(Kind);
|
|
|
|
|
|
|
|
assert(NbArgs != -1 && "Invalid number of arguments");
|
|
|
|
|
|
|
|
SmallVector<MCSymbol *, 3> Args;
|
|
|
|
for (int Idx = 0; Idx < NbArgs; ++Idx) {
|
|
|
|
StringRef Name;
|
|
|
|
if (getParser().parseIdentifier(Name))
|
|
|
|
return TokError("expected identifier in directive");
|
2015-05-19 02:43:14 +08:00
|
|
|
Args.push_back(getContext().getOrCreateSymbol(Name));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
if (Idx + 1 == NbArgs)
|
|
|
|
break;
|
|
|
|
if (getLexer().isNot(AsmToken::Comma))
|
|
|
|
return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
|
|
|
|
Lex();
|
|
|
|
}
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
|
|
|
|
|
|
|
|
getStreamer().EmitLOHDirective((MCLOHType)Kind, Args);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-25 00:21:38 +08:00
|
|
|
/// parseDirectiveLtorg
|
|
|
|
/// ::= .ltorg | .pool
|
|
|
|
bool AArch64AsmParser::parseDirectiveLtorg(SMLoc L) {
|
|
|
|
getTargetStreamer().emitCurrentConstantPool();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-02 12:50:23 +08:00
|
|
|
/// parseDirectiveReq
|
|
|
|
/// ::= name .req registername
|
|
|
|
bool AArch64AsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-07-02 12:50:23 +08:00
|
|
|
Parser.Lex(); // Eat the '.req' token.
|
|
|
|
SMLoc SRegLoc = getLoc();
|
|
|
|
unsigned RegNum = tryParseRegister();
|
|
|
|
bool IsVector = false;
|
|
|
|
|
|
|
|
if (RegNum == static_cast<unsigned>(-1)) {
|
|
|
|
StringRef Kind;
|
|
|
|
RegNum = tryMatchVectorRegister(Kind, false);
|
2016-09-14 02:17:00 +08:00
|
|
|
if (!Kind.empty()) {
|
|
|
|
Error(SRegLoc, "vector register without type specifier expected");
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-02 12:50:23 +08:00
|
|
|
IsVector = true;
|
|
|
|
}
|
|
|
|
|
2016-09-14 02:17:00 +08:00
|
|
|
if (RegNum == static_cast<unsigned>(-1)) {
|
|
|
|
Parser.eatToEndOfStatement();
|
|
|
|
Error(SRegLoc, "register name or alias expected");
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-02 12:50:23 +08:00
|
|
|
|
|
|
|
// Shouldn't be anything else.
|
2016-09-14 02:17:00 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
|
|
|
|
Error(Parser.getTok().getLoc(), "unexpected input in .req directive");
|
|
|
|
Parser.eatToEndOfStatement();
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-02 12:50:23 +08:00
|
|
|
|
|
|
|
Parser.Lex(); // Consume the EndOfStatement
|
|
|
|
|
|
|
|
auto pair = std::make_pair(IsVector, RegNum);
|
2015-02-04 11:10:03 +08:00
|
|
|
if (RegisterReqs.insert(std::make_pair(Name, pair)).first->second != pair)
|
2014-07-02 12:50:23 +08:00
|
|
|
Warning(L, "ignoring redefinition of register alias '" + Name + "'");
|
|
|
|
|
2016-09-14 02:17:00 +08:00
|
|
|
return true;
|
2014-07-02 12:50:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// parseDirectiveUneq
|
|
|
|
/// ::= .unreq registername
|
|
|
|
bool AArch64AsmParser::parseDirectiveUnreq(SMLoc L) {
|
2014-11-11 13:18:41 +08:00
|
|
|
MCAsmParser &Parser = getParser();
|
2014-07-02 12:50:23 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
Error(Parser.getTok().getLoc(), "unexpected input in .unreq directive.");
|
2016-09-14 02:17:00 +08:00
|
|
|
Parser.eatToEndOfStatement();
|
2014-07-02 12:50:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
|
|
|
|
Parser.Lex(); // Eat the identifier.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
bool
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64AsmParser::classifySymbolRef(const MCExpr *Expr,
|
|
|
|
AArch64MCExpr::VariantKind &ELFRefKind,
|
|
|
|
MCSymbolRefExpr::VariantKind &DarwinRefKind,
|
|
|
|
int64_t &Addend) {
|
|
|
|
ELFRefKind = AArch64MCExpr::VK_INVALID;
|
2014-03-29 18:18:08 +08:00
|
|
|
DarwinRefKind = MCSymbolRefExpr::VK_None;
|
2014-04-24 20:56:38 +08:00
|
|
|
Addend = 0;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
if (const AArch64MCExpr *AE = dyn_cast<AArch64MCExpr>(Expr)) {
|
2014-03-29 18:18:08 +08:00
|
|
|
ELFRefKind = AE->getKind();
|
|
|
|
Expr = AE->getSubExpr();
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCSymbolRefExpr *SE = dyn_cast<MCSymbolRefExpr>(Expr);
|
|
|
|
if (SE) {
|
|
|
|
// It's a simple symbol reference with no addend.
|
|
|
|
DarwinRefKind = SE->getKind();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr);
|
|
|
|
if (!BE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
|
|
|
|
if (!SE)
|
|
|
|
return false;
|
|
|
|
DarwinRefKind = SE->getKind();
|
|
|
|
|
2014-04-24 20:56:38 +08:00
|
|
|
if (BE->getOpcode() != MCBinaryExpr::Add &&
|
|
|
|
BE->getOpcode() != MCBinaryExpr::Sub)
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// See if the addend is is a constant, otherwise there's more going
|
|
|
|
// on here than we can deal with.
|
2014-04-24 20:56:38 +08:00
|
|
|
auto AddendExpr = dyn_cast<MCConstantExpr>(BE->getRHS());
|
|
|
|
if (!AddendExpr)
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
|
2014-04-24 20:56:38 +08:00
|
|
|
Addend = AddendExpr->getValue();
|
|
|
|
if (BE->getOpcode() == MCBinaryExpr::Sub)
|
|
|
|
Addend = -Addend;
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// It's some symbol reference + a constant addend, but really
|
|
|
|
// shouldn't use both Darwin and ELF syntax.
|
2014-05-24 20:50:23 +08:00
|
|
|
return ELFRefKind == AArch64MCExpr::VK_INVALID ||
|
2014-03-29 18:18:08 +08:00
|
|
|
DarwinRefKind == MCSymbolRefExpr::VK_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Force static initialization.
|
2014-05-24 20:50:23 +08:00
|
|
|
extern "C" void LLVMInitializeAArch64AsmParser() {
|
|
|
|
RegisterMCAsmParser<AArch64AsmParser> X(TheAArch64leTarget);
|
|
|
|
RegisterMCAsmParser<AArch64AsmParser> Y(TheAArch64beTarget);
|
2014-07-23 20:58:11 +08:00
|
|
|
RegisterMCAsmParser<AArch64AsmParser> Z(TheARM64Target);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_REGISTER_MATCHER
|
2014-04-23 14:22:48 +08:00
|
|
|
#define GET_SUBTARGET_FEATURE_NAME
|
2014-03-29 18:18:08 +08:00
|
|
|
#define GET_MATCHER_IMPLEMENTATION
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64GenAsmMatcher.inc"
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// Define this matcher function after the auto-generated include so we
|
|
|
|
// have the match class enum definitions.
|
2014-06-09 00:18:35 +08:00
|
|
|
unsigned AArch64AsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
|
2014-05-24 20:50:23 +08:00
|
|
|
unsigned Kind) {
|
2014-06-09 00:18:35 +08:00
|
|
|
AArch64Operand &Op = static_cast<AArch64Operand &>(AsmOp);
|
2014-03-29 18:18:08 +08:00
|
|
|
// If the kind is a token for a literal immediate, check if our asm
|
|
|
|
// operand matches. This is for InstAliases which have a fixed-value
|
|
|
|
// immediate in the syntax.
|
|
|
|
int64_t ExpectedVal;
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
|
|
|
return Match_InvalidOperand;
|
|
|
|
case MCK__35_0:
|
|
|
|
ExpectedVal = 0;
|
|
|
|
break;
|
|
|
|
case MCK__35_1:
|
|
|
|
ExpectedVal = 1;
|
|
|
|
break;
|
|
|
|
case MCK__35_12:
|
|
|
|
ExpectedVal = 12;
|
|
|
|
break;
|
|
|
|
case MCK__35_16:
|
|
|
|
ExpectedVal = 16;
|
|
|
|
break;
|
|
|
|
case MCK__35_2:
|
|
|
|
ExpectedVal = 2;
|
|
|
|
break;
|
|
|
|
case MCK__35_24:
|
|
|
|
ExpectedVal = 24;
|
|
|
|
break;
|
|
|
|
case MCK__35_3:
|
|
|
|
ExpectedVal = 3;
|
|
|
|
break;
|
|
|
|
case MCK__35_32:
|
|
|
|
ExpectedVal = 32;
|
|
|
|
break;
|
|
|
|
case MCK__35_4:
|
|
|
|
ExpectedVal = 4;
|
|
|
|
break;
|
|
|
|
case MCK__35_48:
|
|
|
|
ExpectedVal = 48;
|
|
|
|
break;
|
|
|
|
case MCK__35_6:
|
|
|
|
ExpectedVal = 6;
|
|
|
|
break;
|
|
|
|
case MCK__35_64:
|
|
|
|
ExpectedVal = 64;
|
|
|
|
break;
|
|
|
|
case MCK__35_8:
|
|
|
|
ExpectedVal = 8;
|
|
|
|
break;
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
if (!Op.isImm())
|
2014-03-29 18:18:08 +08:00
|
|
|
return Match_InvalidOperand;
|
2014-06-09 00:18:35 +08:00
|
|
|
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
|
2014-03-29 18:18:08 +08:00
|
|
|
if (!CE)
|
|
|
|
return Match_InvalidOperand;
|
|
|
|
if (CE->getValue() == ExpectedVal)
|
|
|
|
return Match_Success;
|
|
|
|
return Match_InvalidOperand;
|
|
|
|
}
|
2015-06-02 18:58:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
AArch64AsmParser::OperandMatchResultTy
|
|
|
|
AArch64AsmParser::tryParseGPRSeqPair(OperandVector &Operands) {
|
|
|
|
|
|
|
|
SMLoc S = getLoc();
|
|
|
|
|
|
|
|
if (getParser().getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
Error(S, "expected register");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FirstReg = tryParseRegister();
|
|
|
|
if (FirstReg == -1) {
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
const MCRegisterClass &WRegClass =
|
|
|
|
AArch64MCRegisterClasses[AArch64::GPR32RegClassID];
|
|
|
|
const MCRegisterClass &XRegClass =
|
|
|
|
AArch64MCRegisterClasses[AArch64::GPR64RegClassID];
|
|
|
|
|
|
|
|
bool isXReg = XRegClass.contains(FirstReg),
|
|
|
|
isWReg = WRegClass.contains(FirstReg);
|
|
|
|
if (!isXReg && !isWReg) {
|
|
|
|
Error(S, "expected first even register of a "
|
|
|
|
"consecutive same-size even/odd register pair");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCRegisterInfo *RI = getContext().getRegisterInfo();
|
|
|
|
unsigned FirstEncoding = RI->getEncodingValue(FirstReg);
|
|
|
|
|
|
|
|
if (FirstEncoding & 0x1) {
|
|
|
|
Error(S, "expected first even register of a "
|
|
|
|
"consecutive same-size even/odd register pair");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
SMLoc M = getLoc();
|
|
|
|
if (getParser().getTok().isNot(AsmToken::Comma)) {
|
|
|
|
Error(M, "expected comma");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
// Eat the comma
|
|
|
|
getParser().Lex();
|
|
|
|
|
|
|
|
SMLoc E = getLoc();
|
|
|
|
int SecondReg = tryParseRegister();
|
|
|
|
if (SecondReg ==-1) {
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RI->getEncodingValue(SecondReg) != FirstEncoding + 1 ||
|
|
|
|
(isXReg && !XRegClass.contains(SecondReg)) ||
|
|
|
|
(isWReg && !WRegClass.contains(SecondReg))) {
|
|
|
|
Error(E,"expected second odd register of a "
|
|
|
|
"consecutive same-size even/odd register pair");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Pair = 0;
|
|
|
|
if(isXReg) {
|
|
|
|
Pair = RI->getMatchingSuperReg(FirstReg, AArch64::sube64,
|
|
|
|
&AArch64MCRegisterClasses[AArch64::XSeqPairsClassRegClassID]);
|
|
|
|
} else {
|
|
|
|
Pair = RI->getMatchingSuperReg(FirstReg, AArch64::sube32,
|
|
|
|
&AArch64MCRegisterClasses[AArch64::WSeqPairsClassRegClassID]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Operands.push_back(AArch64Operand::CreateReg(Pair, false, S, getLoc(),
|
|
|
|
getContext()));
|
|
|
|
|
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|