blob: 12e4e8679908da8851fe0e32dfd9ff73572a9a04 [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,
33 OpMla,
Bob Wilson05843162010-12-07 23:53:37 +000034 OpMlal,
Nate Begeman73cef3e2010-06-04 01:26:15 +000035 OpMls,
Bob Wilson05843162010-12-07 23:53:37 +000036 OpMlsl,
Nate Begeman4b425a82010-06-10 00:16:56 +000037 OpMulN,
38 OpMlaN,
39 OpMlsN,
Bob Wilson05843162010-12-07 23:53:37 +000040 OpMlalN,
41 OpMlslN,
Bob Wilsonb0d98692010-12-03 00:34:12 +000042 OpMulLane,
Bob Wilson3467cd02010-12-07 22:02:48 +000043 OpMullLane,
Bob Wilsonb0d98692010-12-03 00:34:12 +000044 OpMlaLane,
45 OpMlsLane,
Bob Wilson05843162010-12-07 23:53:37 +000046 OpMlalLane,
47 OpMlslLane,
Bob Wilson74410892010-12-08 22:36:08 +000048 OpQDMullLane,
49 OpQDMlalLane,
50 OpQDMlslLane,
51 OpQDMulhLane,
52 OpQRDMulhLane,
Nate Begeman73cef3e2010-06-04 01:26:15 +000053 OpEq,
54 OpGe,
55 OpLe,
56 OpGt,
57 OpLt,
58 OpNeg,
59 OpNot,
60 OpAnd,
61 OpOr,
62 OpXor,
63 OpAndNot,
64 OpOrNot,
Nate Begeman900f4672010-06-08 00:14:42 +000065 OpCast,
66 OpConcat,
Nate Begeman6c060db2010-06-09 01:09:00 +000067 OpDup,
Bob Wilson2196caa2010-12-07 22:39:24 +000068 OpDupLane,
Nate Begeman6c060db2010-06-09 01:09:00 +000069 OpHi,
Nate Begemancc3c41a2010-06-12 03:09:49 +000070 OpLo,
71 OpSelect,
72 OpRev16,
73 OpRev32,
Bob Wilson3890e392010-12-07 01:12:23 +000074 OpRev64,
Bob Wilsonf4f39d32010-12-08 20:09:10 +000075 OpReinterpret,
Bob Wilsonb4504302010-12-08 21:39:04 +000076 OpAbdl,
77 OpAba,
78 OpAbal
Nate Begeman73cef3e2010-06-04 01:26:15 +000079};
80
81enum ClassKind {
82 ClassNone,
Bob Wilson95148ad2010-12-01 19:49:56 +000083 ClassI, // generic integer instruction, e.g., "i8" suffix
84 ClassS, // signed/unsigned/poly, e.g., "s8", "u8" or "p8" suffix
85 ClassW, // width-specific instruction, e.g., "8" suffix
86 ClassB // bitcast arguments with enum argument to specify type
Nate Begeman73cef3e2010-06-04 01:26:15 +000087};
Nate Begeman5ddb0872010-05-28 01:08:32 +000088
89namespace llvm {
Bob Wilson7f762182010-12-04 04:40:15 +000090
Nate Begeman5ddb0872010-05-28 01:08:32 +000091 class NeonEmitter : public TableGenBackend {
92 RecordKeeper &Records;
Nate Begeman73cef3e2010-06-04 01:26:15 +000093 StringMap<OpKind> OpMap;
94 DenseMap<Record*, ClassKind> ClassMap;
Bob Wilson7f762182010-12-04 04:40:15 +000095
Nate Begeman5ddb0872010-05-28 01:08:32 +000096 public:
Nate Begeman73cef3e2010-06-04 01:26:15 +000097 NeonEmitter(RecordKeeper &R) : Records(R) {
Nate Begeman4b425a82010-06-10 00:16:56 +000098 OpMap["OP_NONE"] = OpNone;
99 OpMap["OP_ADD"] = OpAdd;
Bob Wilsone113ae52010-12-08 00:14:04 +0000100 OpMap["OP_ADDL"] = OpAddl;
101 OpMap["OP_ADDW"] = OpAddw;
Nate Begeman4b425a82010-06-10 00:16:56 +0000102 OpMap["OP_SUB"] = OpSub;
Bob Wilsone113ae52010-12-08 00:14:04 +0000103 OpMap["OP_SUBL"] = OpSubl;
104 OpMap["OP_SUBW"] = OpSubw;
Nate Begeman4b425a82010-06-10 00:16:56 +0000105 OpMap["OP_MUL"] = OpMul;
106 OpMap["OP_MLA"] = OpMla;
Bob Wilson05843162010-12-07 23:53:37 +0000107 OpMap["OP_MLAL"] = OpMlal;
Nate Begeman4b425a82010-06-10 00:16:56 +0000108 OpMap["OP_MLS"] = OpMls;
Bob Wilson05843162010-12-07 23:53:37 +0000109 OpMap["OP_MLSL"] = OpMlsl;
Nate Begeman4b425a82010-06-10 00:16:56 +0000110 OpMap["OP_MUL_N"] = OpMulN;
111 OpMap["OP_MLA_N"] = OpMlaN;
112 OpMap["OP_MLS_N"] = OpMlsN;
Bob Wilson05843162010-12-07 23:53:37 +0000113 OpMap["OP_MLAL_N"] = OpMlalN;
114 OpMap["OP_MLSL_N"] = OpMlslN;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000115 OpMap["OP_MUL_LN"]= OpMulLane;
Bob Wilson3467cd02010-12-07 22:02:48 +0000116 OpMap["OP_MULL_LN"] = OpMullLane;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000117 OpMap["OP_MLA_LN"]= OpMlaLane;
118 OpMap["OP_MLS_LN"]= OpMlsLane;
Bob Wilson05843162010-12-07 23:53:37 +0000119 OpMap["OP_MLAL_LN"] = OpMlalLane;
120 OpMap["OP_MLSL_LN"] = OpMlslLane;
Bob Wilson74410892010-12-08 22:36:08 +0000121 OpMap["OP_QDMULL_LN"] = OpQDMullLane;
122 OpMap["OP_QDMLAL_LN"] = OpQDMlalLane;
123 OpMap["OP_QDMLSL_LN"] = OpQDMlslLane;
124 OpMap["OP_QDMULH_LN"] = OpQDMulhLane;
125 OpMap["OP_QRDMULH_LN"] = OpQRDMulhLane;
Nate Begeman4b425a82010-06-10 00:16:56 +0000126 OpMap["OP_EQ"] = OpEq;
127 OpMap["OP_GE"] = OpGe;
128 OpMap["OP_LE"] = OpLe;
129 OpMap["OP_GT"] = OpGt;
130 OpMap["OP_LT"] = OpLt;
131 OpMap["OP_NEG"] = OpNeg;
132 OpMap["OP_NOT"] = OpNot;
133 OpMap["OP_AND"] = OpAnd;
134 OpMap["OP_OR"] = OpOr;
135 OpMap["OP_XOR"] = OpXor;
136 OpMap["OP_ANDN"] = OpAndNot;
137 OpMap["OP_ORN"] = OpOrNot;
138 OpMap["OP_CAST"] = OpCast;
139 OpMap["OP_CONC"] = OpConcat;
140 OpMap["OP_HI"] = OpHi;
141 OpMap["OP_LO"] = OpLo;
142 OpMap["OP_DUP"] = OpDup;
Bob Wilson2196caa2010-12-07 22:39:24 +0000143 OpMap["OP_DUP_LN"] = OpDupLane;
Nate Begemancc3c41a2010-06-12 03:09:49 +0000144 OpMap["OP_SEL"] = OpSelect;
145 OpMap["OP_REV16"] = OpRev16;
146 OpMap["OP_REV32"] = OpRev32;
147 OpMap["OP_REV64"] = OpRev64;
Bob Wilson3890e392010-12-07 01:12:23 +0000148 OpMap["OP_REINT"] = OpReinterpret;
Bob Wilsonb4504302010-12-08 21:39:04 +0000149 OpMap["OP_ABDL"] = OpAbdl;
Bob Wilsonf4f39d32010-12-08 20:09:10 +0000150 OpMap["OP_ABA"] = OpAba;
Bob Wilsonb4504302010-12-08 21:39:04 +0000151 OpMap["OP_ABAL"] = OpAbal;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000152
153 Record *SI = R.getClass("SInst");
154 Record *II = R.getClass("IInst");
155 Record *WI = R.getClass("WInst");
Nate Begeman73cef3e2010-06-04 01:26:15 +0000156 ClassMap[SI] = ClassS;
157 ClassMap[II] = ClassI;
158 ClassMap[WI] = ClassW;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000159 }
Bob Wilson7f762182010-12-04 04:40:15 +0000160
Nate Begemana8979a02010-06-04 00:21:41 +0000161 // run - Emit arm_neon.h.inc
Nate Begeman5ddb0872010-05-28 01:08:32 +0000162 void run(raw_ostream &o);
Nate Begemana8979a02010-06-04 00:21:41 +0000163
164 // runHeader - Emit all the __builtin prototypes used in arm_neon.h
165 void runHeader(raw_ostream &o);
Bob Wilsonda1d3dc2010-12-07 23:53:32 +0000166
Bob Wilson333f5192010-12-15 16:58:45 +0000167 // runTests - Emit tests for all the Neon intrinsics.
168 void runTests(raw_ostream &o);
169
Bob Wilsonda1d3dc2010-12-07 23:53:32 +0000170 private:
171 void emitIntrinsic(raw_ostream &OS, Record *R);
Nate Begeman5ddb0872010-05-28 01:08:32 +0000172 };
Bob Wilson7f762182010-12-04 04:40:15 +0000173
Nate Begeman5ddb0872010-05-28 01:08:32 +0000174} // End llvm namespace
175
176#endif