blob: 4c5889388ba673836c2fa0ec1590ddcaf2726fa0 [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,
27 OpSub,
28 OpMul,
Bob Wilsonc4ba09d2010-12-07 20:02:45 +000029 OpMull,
Nate Begeman73cef3e2010-06-04 01:26:15 +000030 OpMla,
Bob Wilson05843162010-12-07 23:53:37 +000031 OpMlal,
Nate Begeman73cef3e2010-06-04 01:26:15 +000032 OpMls,
Bob Wilson05843162010-12-07 23:53:37 +000033 OpMlsl,
Nate Begeman4b425a82010-06-10 00:16:56 +000034 OpMulN,
Bob Wilsonc4ba09d2010-12-07 20:02:45 +000035 OpMullN,
Nate Begeman4b425a82010-06-10 00:16:56 +000036 OpMlaN,
37 OpMlsN,
Bob Wilson05843162010-12-07 23:53:37 +000038 OpMlalN,
39 OpMlslN,
Bob Wilsonb0d98692010-12-03 00:34:12 +000040 OpMulLane,
Bob Wilson3467cd02010-12-07 22:02:48 +000041 OpMullLane,
Bob Wilsonb0d98692010-12-03 00:34:12 +000042 OpMlaLane,
43 OpMlsLane,
Bob Wilson05843162010-12-07 23:53:37 +000044 OpMlalLane,
45 OpMlslLane,
Nate Begeman73cef3e2010-06-04 01:26:15 +000046 OpEq,
47 OpGe,
48 OpLe,
49 OpGt,
50 OpLt,
51 OpNeg,
52 OpNot,
53 OpAnd,
54 OpOr,
55 OpXor,
56 OpAndNot,
57 OpOrNot,
Nate Begeman900f4672010-06-08 00:14:42 +000058 OpCast,
59 OpConcat,
Nate Begeman6c060db2010-06-09 01:09:00 +000060 OpDup,
Bob Wilson2196caa2010-12-07 22:39:24 +000061 OpDupLane,
Nate Begeman6c060db2010-06-09 01:09:00 +000062 OpHi,
Nate Begemancc3c41a2010-06-12 03:09:49 +000063 OpLo,
64 OpSelect,
65 OpRev16,
66 OpRev32,
Bob Wilson3890e392010-12-07 01:12:23 +000067 OpRev64,
68 OpReinterpret
Nate Begeman73cef3e2010-06-04 01:26:15 +000069};
70
71enum ClassKind {
72 ClassNone,
Bob Wilson95148ad2010-12-01 19:49:56 +000073 ClassI, // generic integer instruction, e.g., "i8" suffix
74 ClassS, // signed/unsigned/poly, e.g., "s8", "u8" or "p8" suffix
75 ClassW, // width-specific instruction, e.g., "8" suffix
76 ClassB // bitcast arguments with enum argument to specify type
Nate Begeman73cef3e2010-06-04 01:26:15 +000077};
Nate Begeman5ddb0872010-05-28 01:08:32 +000078
79namespace llvm {
Bob Wilson7f762182010-12-04 04:40:15 +000080
Nate Begeman5ddb0872010-05-28 01:08:32 +000081 class NeonEmitter : public TableGenBackend {
82 RecordKeeper &Records;
Nate Begeman73cef3e2010-06-04 01:26:15 +000083 StringMap<OpKind> OpMap;
84 DenseMap<Record*, ClassKind> ClassMap;
Bob Wilson7f762182010-12-04 04:40:15 +000085
Nate Begeman5ddb0872010-05-28 01:08:32 +000086 public:
Nate Begeman73cef3e2010-06-04 01:26:15 +000087 NeonEmitter(RecordKeeper &R) : Records(R) {
Nate Begeman4b425a82010-06-10 00:16:56 +000088 OpMap["OP_NONE"] = OpNone;
89 OpMap["OP_ADD"] = OpAdd;
90 OpMap["OP_SUB"] = OpSub;
91 OpMap["OP_MUL"] = OpMul;
Bob Wilsonc4ba09d2010-12-07 20:02:45 +000092 OpMap["OP_MULL"] = OpMull;
Nate Begeman4b425a82010-06-10 00:16:56 +000093 OpMap["OP_MLA"] = OpMla;
Bob Wilson05843162010-12-07 23:53:37 +000094 OpMap["OP_MLAL"] = OpMlal;
Nate Begeman4b425a82010-06-10 00:16:56 +000095 OpMap["OP_MLS"] = OpMls;
Bob Wilson05843162010-12-07 23:53:37 +000096 OpMap["OP_MLSL"] = OpMlsl;
Nate Begeman4b425a82010-06-10 00:16:56 +000097 OpMap["OP_MUL_N"] = OpMulN;
Bob Wilsonc4ba09d2010-12-07 20:02:45 +000098 OpMap["OP_MULL_N"]= OpMullN;
Nate Begeman4b425a82010-06-10 00:16:56 +000099 OpMap["OP_MLA_N"] = OpMlaN;
100 OpMap["OP_MLS_N"] = OpMlsN;
Bob Wilson05843162010-12-07 23:53:37 +0000101 OpMap["OP_MLAL_N"] = OpMlalN;
102 OpMap["OP_MLSL_N"] = OpMlslN;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000103 OpMap["OP_MUL_LN"]= OpMulLane;
Bob Wilson3467cd02010-12-07 22:02:48 +0000104 OpMap["OP_MULL_LN"] = OpMullLane;
Bob Wilsonb0d98692010-12-03 00:34:12 +0000105 OpMap["OP_MLA_LN"]= OpMlaLane;
106 OpMap["OP_MLS_LN"]= OpMlsLane;
Bob Wilson05843162010-12-07 23:53:37 +0000107 OpMap["OP_MLAL_LN"] = OpMlalLane;
108 OpMap["OP_MLSL_LN"] = OpMlslLane;
Nate Begeman4b425a82010-06-10 00:16:56 +0000109 OpMap["OP_EQ"] = OpEq;
110 OpMap["OP_GE"] = OpGe;
111 OpMap["OP_LE"] = OpLe;
112 OpMap["OP_GT"] = OpGt;
113 OpMap["OP_LT"] = OpLt;
114 OpMap["OP_NEG"] = OpNeg;
115 OpMap["OP_NOT"] = OpNot;
116 OpMap["OP_AND"] = OpAnd;
117 OpMap["OP_OR"] = OpOr;
118 OpMap["OP_XOR"] = OpXor;
119 OpMap["OP_ANDN"] = OpAndNot;
120 OpMap["OP_ORN"] = OpOrNot;
121 OpMap["OP_CAST"] = OpCast;
122 OpMap["OP_CONC"] = OpConcat;
123 OpMap["OP_HI"] = OpHi;
124 OpMap["OP_LO"] = OpLo;
125 OpMap["OP_DUP"] = OpDup;
Bob Wilson2196caa2010-12-07 22:39:24 +0000126 OpMap["OP_DUP_LN"] = OpDupLane;
Nate Begemancc3c41a2010-06-12 03:09:49 +0000127 OpMap["OP_SEL"] = OpSelect;
128 OpMap["OP_REV16"] = OpRev16;
129 OpMap["OP_REV32"] = OpRev32;
130 OpMap["OP_REV64"] = OpRev64;
Bob Wilson3890e392010-12-07 01:12:23 +0000131 OpMap["OP_REINT"] = OpReinterpret;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000132
133 Record *SI = R.getClass("SInst");
134 Record *II = R.getClass("IInst");
135 Record *WI = R.getClass("WInst");
Nate Begeman73cef3e2010-06-04 01:26:15 +0000136 ClassMap[SI] = ClassS;
137 ClassMap[II] = ClassI;
138 ClassMap[WI] = ClassW;
Nate Begeman73cef3e2010-06-04 01:26:15 +0000139 }
Bob Wilson7f762182010-12-04 04:40:15 +0000140
Nate Begemana8979a02010-06-04 00:21:41 +0000141 // run - Emit arm_neon.h.inc
Nate Begeman5ddb0872010-05-28 01:08:32 +0000142 void run(raw_ostream &o);
Nate Begemana8979a02010-06-04 00:21:41 +0000143
144 // runHeader - Emit all the __builtin prototypes used in arm_neon.h
145 void runHeader(raw_ostream &o);
Bob Wilsonda1d3dc2010-12-07 23:53:32 +0000146
147 private:
148 void emitIntrinsic(raw_ostream &OS, Record *R);
Nate Begeman5ddb0872010-05-28 01:08:32 +0000149 };
Bob Wilson7f762182010-12-04 04:40:15 +0000150
Nate Begeman5ddb0872010-05-28 01:08:32 +0000151} // End llvm namespace
152
153#endif