blob: 69b39e9e4f7e29f1841857353e260d3f501722e2 [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,
Bob Wilsonf4f39d32010-12-08 20:09:10 +000072 OpReinterpret,
Bob Wilsonb4504302010-12-08 21:39:04 +000073 OpAbdl,
74 OpAba,
75 OpAbal
Nate Begeman73cef3e2010-06-04 01:26:15 +000076};
77
78enum ClassKind {
79 ClassNone,
Bob Wilson95148ad2010-12-01 19:49:56 +000080 ClassI, // generic integer instruction, e.g., "i8" suffix
81 ClassS, // signed/unsigned/poly, e.g., "s8", "u8" or "p8" suffix
82 ClassW, // width-specific instruction, e.g., "8" suffix
83 ClassB // bitcast arguments with enum argument to specify type
Nate Begeman73cef3e2010-06-04 01:26:15 +000084};
Nate Begeman5ddb0872010-05-28 01:08:32 +000085
86namespace llvm {
Bob Wilson7f762182010-12-04 04:40:15 +000087
Nate Begeman5ddb0872010-05-28 01:08:32 +000088 class NeonEmitter : public TableGenBackend {
89 RecordKeeper &Records;
Nate Begeman73cef3e2010-06-04 01:26:15 +000090 StringMap<OpKind> OpMap;
91 DenseMap<Record*, ClassKind> ClassMap;
Bob Wilson7f762182010-12-04 04:40:15 +000092
Nate Begeman5ddb0872010-05-28 01:08:32 +000093 public:
Nate Begeman73cef3e2010-06-04 01:26:15 +000094 NeonEmitter(RecordKeeper &R) : Records(R) {
Nate Begeman4b425a82010-06-10 00:16:56 +000095 OpMap["OP_NONE"] = OpNone;
96 OpMap["OP_ADD"] = OpAdd;
Bob Wilsone113ae52010-12-08 00:14:04 +000097 OpMap["OP_ADDL"] = OpAddl;
98 OpMap["OP_ADDW"] = OpAddw;
Nate Begeman4b425a82010-06-10 00:16:56 +000099 OpMap["OP_SUB"] = OpSub;
Bob Wilsone113ae52010-12-08 00:14:04 +0000100 OpMap["OP_SUBL"] = OpSubl;
101 OpMap["OP_SUBW"] = OpSubw;
Nate Begeman4b425a82010-06-10 00:16:56 +0000102 OpMap["OP_MUL"] = OpMul;
Bob Wilsonc4ba09d2010-12-07 20:02:45 +0000103 OpMap["OP_MULL"] = OpMull;
Nate Begeman4b425a82010-06-10 00:16:56 +0000104 OpMap["OP_MLA"] = OpMla;
Bob Wilson05843162010-12-07 23:53:37 +0000105 OpMap["OP_MLAL"] = OpMlal;
Nate Begeman4b425a82010-06-10 00:16:56 +0000106 OpMap["OP_MLS"] = OpMls;
Bob Wilson05843162010-12-07 23:53:37 +0000107 OpMap["OP_MLSL"] = OpMlsl;
Nate Begeman4b425a82010-06-10 00:16:56 +0000108 OpMap["OP_MUL_N"] = OpMulN;
Bob Wilsonc4ba09d2010-12-07 20:02:45 +0000109 OpMap["OP_MULL_N"]= OpMullN;
Nate Begeman4b425a82010-06-10 00:16:56 +0000110 OpMap["OP_MLA_N"] = OpMlaN;
111 OpMap["OP_MLS_N"] = OpMlsN;
Bob Wilson05843162010-12-07 23:53:37 +0000112 OpMap["OP_MLAL_N"] = OpMlalN;
113 OpMap["OP_MLSL_N"] = OpMlslN;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000114 OpMap["OP_MUL_LN"]= OpMulLane;
Bob Wilson3467cd02010-12-07 22:02:48 +0000115 OpMap["OP_MULL_LN"] = OpMullLane;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000116 OpMap["OP_MLA_LN"]= OpMlaLane;
117 OpMap["OP_MLS_LN"]= OpMlsLane;
Bob Wilson05843162010-12-07 23:53:37 +0000118 OpMap["OP_MLAL_LN"] = OpMlalLane;
119 OpMap["OP_MLSL_LN"] = OpMlslLane;
Nate Begeman4b425a82010-06-10 00:16:56 +0000120 OpMap["OP_EQ"] = OpEq;
121 OpMap["OP_GE"] = OpGe;
122 OpMap["OP_LE"] = OpLe;
123 OpMap["OP_GT"] = OpGt;
124 OpMap["OP_LT"] = OpLt;
125 OpMap["OP_NEG"] = OpNeg;
126 OpMap["OP_NOT"] = OpNot;
127 OpMap["OP_AND"] = OpAnd;
128 OpMap["OP_OR"] = OpOr;
129 OpMap["OP_XOR"] = OpXor;
130 OpMap["OP_ANDN"] = OpAndNot;
131 OpMap["OP_ORN"] = OpOrNot;
132 OpMap["OP_CAST"] = OpCast;
133 OpMap["OP_CONC"] = OpConcat;
134 OpMap["OP_HI"] = OpHi;
135 OpMap["OP_LO"] = OpLo;
136 OpMap["OP_DUP"] = OpDup;
Bob Wilson2196caa2010-12-07 22:39:24 +0000137 OpMap["OP_DUP_LN"] = OpDupLane;
Nate Begemancc3c41a2010-06-12 03:09:49 +0000138 OpMap["OP_SEL"] = OpSelect;
139 OpMap["OP_REV16"] = OpRev16;
140 OpMap["OP_REV32"] = OpRev32;
141 OpMap["OP_REV64"] = OpRev64;
Bob Wilson3890e392010-12-07 01:12:23 +0000142 OpMap["OP_REINT"] = OpReinterpret;
Bob Wilsonb4504302010-12-08 21:39:04 +0000143 OpMap["OP_ABDL"] = OpAbdl;
Bob Wilsonf4f39d32010-12-08 20:09:10 +0000144 OpMap["OP_ABA"] = OpAba;
Bob Wilsonb4504302010-12-08 21:39:04 +0000145 OpMap["OP_ABAL"] = OpAbal;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000146
147 Record *SI = R.getClass("SInst");
148 Record *II = R.getClass("IInst");
149 Record *WI = R.getClass("WInst");
Nate Begeman73cef3e2010-06-04 01:26:15 +0000150 ClassMap[SI] = ClassS;
151 ClassMap[II] = ClassI;
152 ClassMap[WI] = ClassW;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000153 }
Bob Wilson7f762182010-12-04 04:40:15 +0000154
Nate Begemana8979a02010-06-04 00:21:41 +0000155 // run - Emit arm_neon.h.inc
Nate Begeman5ddb0872010-05-28 01:08:32 +0000156 void run(raw_ostream &o);
Nate Begemana8979a02010-06-04 00:21:41 +0000157
158 // runHeader - Emit all the __builtin prototypes used in arm_neon.h
159 void runHeader(raw_ostream &o);
Bob Wilsonda1d3dc2010-12-07 23:53:32 +0000160
161 private:
162 void emitIntrinsic(raw_ostream &OS, Record *R);
Nate Begeman5ddb0872010-05-28 01:08:32 +0000163 };
Bob Wilson7f762182010-12-04 04:40:15 +0000164
Nate Begeman5ddb0872010-05-28 01:08:32 +0000165} // End llvm namespace
166
167#endif