blob: 6c0937b3579d8a3c96c7f7e6c6146736971215d8 [file] [log] [blame]
Nate Begeman5ddb0872010-05-28 01:08:32 +00001//===- NeonEmitter.h - Generate arm_neon.h for use with clang ---*- C++ -*-===//
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 tablegen backend is responsible for emitting arm_neon.h, which includes
Bob Wilson7f762182010-12-04 04:40:15 +000011// a declaration and definition of each function specified by the ARM NEON
Nate Begeman5ddb0872010-05-28 01:08:32 +000012// compiler interface. See ARM document DUI0348B.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef NEON_EMITTER_H
17#define NEON_EMITTER_H
18
Nate Begeman73cef3e2010-06-04 01:26:15 +000019#include "Record.h"
Nate Begeman5ddb0872010-05-28 01:08:32 +000020#include "TableGenBackend.h"
Nate Begeman73cef3e2010-06-04 01:26:15 +000021#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/StringMap.h"
23
24enum OpKind {
25 OpNone,
26 OpAdd,
Bob Wilsone113ae52010-12-08 00:14:04 +000027 OpAddl,
28 OpAddw,
Nate Begeman73cef3e2010-06-04 01:26:15 +000029 OpSub,
Bob Wilsone113ae52010-12-08 00:14:04 +000030 OpSubl,
31 OpSubw,
Nate Begeman73cef3e2010-06-04 01:26:15 +000032 OpMul,
Bob Wilsonc4ba09d2010-12-07 20:02:45 +000033 OpMull,
Nate Begeman73cef3e2010-06-04 01:26:15 +000034 OpMla,
Bob Wilson05843162010-12-07 23:53:37 +000035 OpMlal,
Nate Begeman73cef3e2010-06-04 01:26:15 +000036 OpMls,
Bob Wilson05843162010-12-07 23:53:37 +000037 OpMlsl,
Nate Begeman4b425a82010-06-10 00:16:56 +000038 OpMulN,
Bob Wilsonc4ba09d2010-12-07 20:02:45 +000039 OpMullN,
Nate Begeman4b425a82010-06-10 00:16:56 +000040 OpMlaN,
41 OpMlsN,
Bob Wilson05843162010-12-07 23:53:37 +000042 OpMlalN,
43 OpMlslN,
Bob Wilsonb0d98692010-12-03 00:34:12 +000044 OpMulLane,
Bob Wilson3467cd02010-12-07 22:02:48 +000045 OpMullLane,
Bob Wilsonb0d98692010-12-03 00:34:12 +000046 OpMlaLane,
47 OpMlsLane,
Bob Wilson05843162010-12-07 23:53:37 +000048 OpMlalLane,
49 OpMlslLane,
Nate Begeman73cef3e2010-06-04 01:26:15 +000050 OpEq,
51 OpGe,
52 OpLe,
53 OpGt,
54 OpLt,
55 OpNeg,
56 OpNot,
57 OpAnd,
58 OpOr,
59 OpXor,
60 OpAndNot,
61 OpOrNot,
Nate Begeman900f4672010-06-08 00:14:42 +000062 OpCast,
63 OpConcat,
Nate Begeman6c060db2010-06-09 01:09:00 +000064 OpDup,
Bob Wilson2196caa2010-12-07 22:39:24 +000065 OpDupLane,
Nate Begeman6c060db2010-06-09 01:09:00 +000066 OpHi,
Nate Begemancc3c41a2010-06-12 03:09:49 +000067 OpLo,
68 OpSelect,
69 OpRev16,
70 OpRev32,
Bob Wilson3890e392010-12-07 01:12:23 +000071 OpRev64,
72 OpReinterpret
Nate Begeman73cef3e2010-06-04 01:26:15 +000073};
74
75enum ClassKind {
76 ClassNone,
Bob Wilson95148ad2010-12-01 19:49:56 +000077 ClassI, // generic integer instruction, e.g., "i8" suffix
78 ClassS, // signed/unsigned/poly, e.g., "s8", "u8" or "p8" suffix
79 ClassW, // width-specific instruction, e.g., "8" suffix
80 ClassB // bitcast arguments with enum argument to specify type
Nate Begeman73cef3e2010-06-04 01:26:15 +000081};
Nate Begeman5ddb0872010-05-28 01:08:32 +000082
83namespace llvm {
Bob Wilson7f762182010-12-04 04:40:15 +000084
Nate Begeman5ddb0872010-05-28 01:08:32 +000085 class NeonEmitter : public TableGenBackend {
86 RecordKeeper &Records;
Nate Begeman73cef3e2010-06-04 01:26:15 +000087 StringMap<OpKind> OpMap;
88 DenseMap<Record*, ClassKind> ClassMap;
Bob Wilson7f762182010-12-04 04:40:15 +000089
Nate Begeman5ddb0872010-05-28 01:08:32 +000090 public:
Nate Begeman73cef3e2010-06-04 01:26:15 +000091 NeonEmitter(RecordKeeper &R) : Records(R) {
Nate Begeman4b425a82010-06-10 00:16:56 +000092 OpMap["OP_NONE"] = OpNone;
93 OpMap["OP_ADD"] = OpAdd;
Bob Wilsone113ae52010-12-08 00:14:04 +000094 OpMap["OP_ADDL"] = OpAddl;
95 OpMap["OP_ADDW"] = OpAddw;
Nate Begeman4b425a82010-06-10 00:16:56 +000096 OpMap["OP_SUB"] = OpSub;
Bob Wilsone113ae52010-12-08 00:14:04 +000097 OpMap["OP_SUBL"] = OpSubl;
98 OpMap["OP_SUBW"] = OpSubw;
Nate Begeman4b425a82010-06-10 00:16:56 +000099 OpMap["OP_MUL"] = OpMul;
Bob Wilsonc4ba09d2010-12-07 20:02:45 +0000100 OpMap["OP_MULL"] = OpMull;
Nate Begeman4b425a82010-06-10 00:16:56 +0000101 OpMap["OP_MLA"] = OpMla;
Bob Wilson05843162010-12-07 23:53:37 +0000102 OpMap["OP_MLAL"] = OpMlal;
Nate Begeman4b425a82010-06-10 00:16:56 +0000103 OpMap["OP_MLS"] = OpMls;
Bob Wilson05843162010-12-07 23:53:37 +0000104 OpMap["OP_MLSL"] = OpMlsl;
Nate Begeman4b425a82010-06-10 00:16:56 +0000105 OpMap["OP_MUL_N"] = OpMulN;
Bob Wilsonc4ba09d2010-12-07 20:02:45 +0000106 OpMap["OP_MULL_N"]= OpMullN;
Nate Begeman4b425a82010-06-10 00:16:56 +0000107 OpMap["OP_MLA_N"] = OpMlaN;
108 OpMap["OP_MLS_N"] = OpMlsN;
Bob Wilson05843162010-12-07 23:53:37 +0000109 OpMap["OP_MLAL_N"] = OpMlalN;
110 OpMap["OP_MLSL_N"] = OpMlslN;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000111 OpMap["OP_MUL_LN"]= OpMulLane;
Bob Wilson3467cd02010-12-07 22:02:48 +0000112 OpMap["OP_MULL_LN"] = OpMullLane;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000113 OpMap["OP_MLA_LN"]= OpMlaLane;
114 OpMap["OP_MLS_LN"]= OpMlsLane;
Bob Wilson05843162010-12-07 23:53:37 +0000115 OpMap["OP_MLAL_LN"] = OpMlalLane;
116 OpMap["OP_MLSL_LN"] = OpMlslLane;
Nate Begeman4b425a82010-06-10 00:16:56 +0000117 OpMap["OP_EQ"] = OpEq;
118 OpMap["OP_GE"] = OpGe;
119 OpMap["OP_LE"] = OpLe;
120 OpMap["OP_GT"] = OpGt;
121 OpMap["OP_LT"] = OpLt;
122 OpMap["OP_NEG"] = OpNeg;
123 OpMap["OP_NOT"] = OpNot;
124 OpMap["OP_AND"] = OpAnd;
125 OpMap["OP_OR"] = OpOr;
126 OpMap["OP_XOR"] = OpXor;
127 OpMap["OP_ANDN"] = OpAndNot;
128 OpMap["OP_ORN"] = OpOrNot;
129 OpMap["OP_CAST"] = OpCast;
130 OpMap["OP_CONC"] = OpConcat;
131 OpMap["OP_HI"] = OpHi;
132 OpMap["OP_LO"] = OpLo;
133 OpMap["OP_DUP"] = OpDup;
Bob Wilson2196caa2010-12-07 22:39:24 +0000134 OpMap["OP_DUP_LN"] = OpDupLane;
Nate Begemancc3c41a2010-06-12 03:09:49 +0000135 OpMap["OP_SEL"] = OpSelect;
136 OpMap["OP_REV16"] = OpRev16;
137 OpMap["OP_REV32"] = OpRev32;
138 OpMap["OP_REV64"] = OpRev64;
Bob Wilson3890e392010-12-07 01:12:23 +0000139 OpMap["OP_REINT"] = OpReinterpret;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000140
141 Record *SI = R.getClass("SInst");
142 Record *II = R.getClass("IInst");
143 Record *WI = R.getClass("WInst");
Nate Begeman73cef3e2010-06-04 01:26:15 +0000144 ClassMap[SI] = ClassS;
145 ClassMap[II] = ClassI;
146 ClassMap[WI] = ClassW;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000147 }
Bob Wilson7f762182010-12-04 04:40:15 +0000148
Nate Begemana8979a02010-06-04 00:21:41 +0000149 // run - Emit arm_neon.h.inc
Nate Begeman5ddb0872010-05-28 01:08:32 +0000150 void run(raw_ostream &o);
Nate Begemana8979a02010-06-04 00:21:41 +0000151
152 // runHeader - Emit all the __builtin prototypes used in arm_neon.h
153 void runHeader(raw_ostream &o);
Bob Wilsonda1d3dc2010-12-07 23:53:32 +0000154
155 private:
156 void emitIntrinsic(raw_ostream &OS, Record *R);
Nate Begeman5ddb0872010-05-28 01:08:32 +0000157 };
Bob Wilson7f762182010-12-04 04:40:15 +0000158
Nate Begeman5ddb0872010-05-28 01:08:32 +0000159} // End llvm namespace
160
161#endif