blob: 4a7903d26daa14d3408a4b92e9387f06705fbac9 [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===-- AArch64BaseInfo.cpp - AArch64 Base encoding information------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides basic encoding and assembly information for AArch64.
11//
12//===----------------------------------------------------------------------===//
13#include "AArch64BaseInfo.h"
Tim Northovere6ae6762016-07-05 21:23:04 +000014#include "llvm/ADT/ArrayRef.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000015#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/StringExtras.h"
17#include "llvm/Support/Regex.h"
18
19using namespace llvm;
20
Tim Northovere6ae6762016-07-05 21:23:04 +000021namespace llvm {
22 namespace AArch64AT {
23#define GET_AT_IMPL
24#include "AArch64GenSystemOperands.inc"
Tim Northover3b0846e2014-05-24 12:50:23 +000025 }
Tim Northover3b0846e2014-05-24 12:50:23 +000026}
27
Tim Northovere6ae6762016-07-05 21:23:04 +000028
29namespace llvm {
30 namespace AArch64DB {
31#define GET_DB_IMPL
32#include "AArch64GenSystemOperands.inc"
Tim Northover3b0846e2014-05-24 12:50:23 +000033 }
Tim Northover3b0846e2014-05-24 12:50:23 +000034}
35
Tim Northovere6ae6762016-07-05 21:23:04 +000036namespace llvm {
37 namespace AArch64DC {
38#define GET_DC_IMPL
39#include "AArch64GenSystemOperands.inc"
Tim Northover3b0846e2014-05-24 12:50:23 +000040 }
Tim Northovere6ae6762016-07-05 21:23:04 +000041}
Tim Northover3b0846e2014-05-24 12:50:23 +000042
Tim Northovere6ae6762016-07-05 21:23:04 +000043namespace llvm {
44 namespace AArch64IC {
45#define GET_IC_IMPL
46#include "AArch64GenSystemOperands.inc"
Tim Northover3b0846e2014-05-24 12:50:23 +000047 }
Tim Northovere6ae6762016-07-05 21:23:04 +000048}
Tim Northover3b0846e2014-05-24 12:50:23 +000049
Tim Northovere6ae6762016-07-05 21:23:04 +000050namespace llvm {
51 namespace AArch64ISB {
52#define GET_ISB_IMPL
53#include "AArch64GenSystemOperands.inc"
54 }
55}
56namespace llvm {
57 namespace AArch64PRFM {
58#define GET_PRFM_IMPL
59#include "AArch64GenSystemOperands.inc"
60 }
61}
62
63namespace llvm {
64 namespace AArch64PState {
65#define GET_PSTATE_IMPL
66#include "AArch64GenSystemOperands.inc"
67 }
68}
69
70namespace llvm {
71 namespace AArch64PSBHint {
72#define GET_PSB_IMPL
73#include "AArch64GenSystemOperands.inc"
74 }
75}
76
77namespace llvm {
78 namespace AArch64SysReg {
79#define GET_SYSREG_IMPL
80#include "AArch64GenSystemOperands.inc"
81 }
82}
83
84uint32_t AArch64SysReg::parseGenericRegister(StringRef Name) {
Tom Coxone493f172014-10-01 10:13:59 +000085 // Try to parse an S<op0>_<op1>_<Cn>_<Cm>_<op2> register name
Tim Northovere6ae6762016-07-05 21:23:04 +000086 Regex GenericRegPattern("^S([0-3])_([0-7])_C([0-9]|1[0-5])_C([0-9]|1[0-5])_([0-7])$");
Tim Northover3b0846e2014-05-24 12:50:23 +000087
Tom Coxone493f172014-10-01 10:13:59 +000088 SmallVector<StringRef, 5> Ops;
Tim Northovere6ae6762016-07-05 21:23:04 +000089 if (!GenericRegPattern.match(Name.upper(), &Ops))
Tim Northover3b0846e2014-05-24 12:50:23 +000090 return -1;
Tim Northover3b0846e2014-05-24 12:50:23 +000091
Tom Coxone493f172014-10-01 10:13:59 +000092 uint32_t Op0 = 0, Op1 = 0, CRn = 0, CRm = 0, Op2 = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000093 uint32_t Bits;
Tom Coxone493f172014-10-01 10:13:59 +000094 Ops[1].getAsInteger(10, Op0);
95 Ops[2].getAsInteger(10, Op1);
96 Ops[3].getAsInteger(10, CRn);
97 Ops[4].getAsInteger(10, CRm);
98 Ops[5].getAsInteger(10, Op2);
Tim Northover3b0846e2014-05-24 12:50:23 +000099 Bits = (Op0 << 14) | (Op1 << 11) | (CRn << 7) | (CRm << 3) | Op2;
100
Tim Northover3b0846e2014-05-24 12:50:23 +0000101 return Bits;
102}
103
Tim Northovere6ae6762016-07-05 21:23:04 +0000104std::string AArch64SysReg::genericRegisterString(uint32_t Bits) {
Tom Coxone493f172014-10-01 10:13:59 +0000105 assert(Bits < 0x10000);
Tim Northover3b0846e2014-05-24 12:50:23 +0000106 uint32_t Op0 = (Bits >> 14) & 0x3;
107 uint32_t Op1 = (Bits >> 11) & 0x7;
108 uint32_t CRn = (Bits >> 7) & 0xf;
109 uint32_t CRm = (Bits >> 3) & 0xf;
110 uint32_t Op2 = Bits & 0x7;
111
Tim Northovere6ae6762016-07-05 21:23:04 +0000112 return "S" + utostr(Op0) + "_" + utostr(Op1) + "_C" + utostr(CRn) + "_C" +
113 utostr(CRm) + "_" + utostr(Op2);
Tim Northover3b0846e2014-05-24 12:50:23 +0000114}
115
Tim Northovere6ae6762016-07-05 21:23:04 +0000116namespace llvm {
117 namespace AArch64TLBI {
118#define GET_TLBI_IMPL
119#include "AArch64GenSystemOperands.inc"
120 }
121}