151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//===- NeonEmitter.h - Generate arm_neon.h for use with clang ---*- C++ -*-===//
251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//
351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//                     The LLVM Compiler Infrastructure
451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//
551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne// This file is distributed under the University of Illinois Open Source
651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne// License. See LICENSE.TXT for details.
751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//
851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//===----------------------------------------------------------------------===//
951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//
1051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne// This tablegen backend is responsible for emitting arm_neon.h, which includes
1151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne// a declaration and definition of each function specified by the ARM NEON
1251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne// compiler interface.  See ARM document DUI0348B.
1351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//
1451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne//===----------------------------------------------------------------------===//
1551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
1651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne#ifndef NEON_EMITTER_H
1751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne#define NEON_EMITTER_H
1851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
1951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne#include "llvm/TableGen/Record.h"
2051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne#include "llvm/TableGen/TableGenBackend.h"
2151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne#include "llvm/ADT/DenseMap.h"
2251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne#include "llvm/ADT/StringMap.h"
2351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
2451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourneenum OpKind {
2551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpNone,
2651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAdd,
2751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAddl,
2851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAddw,
2951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpSub,
3051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpSubl,
3151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpSubw,
3251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMul,
3351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMla,
3451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlal,
3551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMls,
3651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlsl,
3751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMulN,
3851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlaN,
3951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlsN,
4051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlalN,
4151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlslN,
4251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMulLane,
4351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMullLane,
4451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlaLane,
4551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlsLane,
4651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlalLane,
4751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpMlslLane,
4851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpQDMullLane,
4951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpQDMlalLane,
5051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpQDMlslLane,
5151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpQDMulhLane,
5251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpQRDMulhLane,
5351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpEq,
5451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpGe,
5551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpLe,
5651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpGt,
5751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpLt,
5851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpNeg,
5951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpNot,
6051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAnd,
6151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpOr,
6251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpXor,
6351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAndNot,
6451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpOrNot,
6551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpCast,
6651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpConcat,
6751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpDup,
6851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpDupLane,
6951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpHi,
7051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpLo,
7151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpSelect,
7251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpRev16,
7351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpRev32,
7451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpRev64,
7551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpReinterpret,
7651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAbdl,
7751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAba,
7851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  OpAbal
7951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne};
8051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
8151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourneenum ClassKind {
8251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  ClassNone,
8351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  ClassI,           // generic integer instruction, e.g., "i8" suffix
8451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  ClassS,           // signed/unsigned/poly, e.g., "s8", "u8" or "p8" suffix
8551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  ClassW,           // width-specific instruction, e.g., "8" suffix
8651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  ClassB            // bitcast arguments with enum argument to specify type
8751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne};
8851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
8951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbournenamespace llvm {
9051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
9151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  class NeonEmitter : public TableGenBackend {
9251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    RecordKeeper &Records;
9351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    StringMap<OpKind> OpMap;
9451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    DenseMap<Record*, ClassKind> ClassMap;
9551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
9651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  public:
9751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    NeonEmitter(RecordKeeper &R) : Records(R) {
9851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_NONE"]  = OpNone;
9951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ADD"]   = OpAdd;
10051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ADDL"]  = OpAddl;
10151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ADDW"]  = OpAddw;
10251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_SUB"]   = OpSub;
10351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_SUBL"]  = OpSubl;
10451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_SUBW"]  = OpSubw;
10551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MUL"]   = OpMul;
10651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLA"]   = OpMla;
10751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLAL"]  = OpMlal;
10851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLS"]   = OpMls;
10951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLSL"]  = OpMlsl;
11051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MUL_N"] = OpMulN;
11151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLA_N"] = OpMlaN;
11251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLS_N"] = OpMlsN;
11351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLAL_N"] = OpMlalN;
11451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLSL_N"] = OpMlslN;
11551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MUL_LN"]= OpMulLane;
11651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MULL_LN"] = OpMullLane;
11751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLA_LN"]= OpMlaLane;
11851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLS_LN"]= OpMlsLane;
11951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLAL_LN"] = OpMlalLane;
12051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_MLSL_LN"] = OpMlslLane;
12151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_QDMULL_LN"] = OpQDMullLane;
12251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_QDMLAL_LN"] = OpQDMlalLane;
12351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_QDMLSL_LN"] = OpQDMlslLane;
12451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_QDMULH_LN"] = OpQDMulhLane;
12551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_QRDMULH_LN"] = OpQRDMulhLane;
12651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_EQ"]    = OpEq;
12751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_GE"]    = OpGe;
12851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_LE"]    = OpLe;
12951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_GT"]    = OpGt;
13051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_LT"]    = OpLt;
13151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_NEG"]   = OpNeg;
13251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_NOT"]   = OpNot;
13351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_AND"]   = OpAnd;
13451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_OR"]    = OpOr;
13551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_XOR"]   = OpXor;
13651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ANDN"]  = OpAndNot;
13751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ORN"]   = OpOrNot;
13851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_CAST"]  = OpCast;
13951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_CONC"]  = OpConcat;
14051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_HI"]    = OpHi;
14151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_LO"]    = OpLo;
14251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_DUP"]   = OpDup;
14351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_DUP_LN"] = OpDupLane;
14451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_SEL"]   = OpSelect;
14551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_REV16"] = OpRev16;
14651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_REV32"] = OpRev32;
14751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_REV64"] = OpRev64;
14851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_REINT"] = OpReinterpret;
14951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ABDL"]  = OpAbdl;
15051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ABA"]   = OpAba;
15151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      OpMap["OP_ABAL"]  = OpAbal;
15251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
15351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      Record *SI = R.getClass("SInst");
15451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      Record *II = R.getClass("IInst");
15551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      Record *WI = R.getClass("WInst");
15651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      ClassMap[SI] = ClassS;
15751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      ClassMap[II] = ClassI;
15851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne      ClassMap[WI] = ClassW;
15951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    }
16051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
16151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    // run - Emit arm_neon.h.inc
16251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    void run(raw_ostream &o);
16351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
16451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    // runHeader - Emit all the __builtin prototypes used in arm_neon.h
16551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    void runHeader(raw_ostream &o);
16651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
16751d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    // runTests - Emit tests for all the Neon intrinsics.
16851d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    void runTests(raw_ostream &o);
16951d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
17051d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  private:
17151d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne    void emitIntrinsic(raw_ostream &OS, Record *R);
17251d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne  };
17351d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
17451d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne} // End llvm namespace
17551d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne
17651d7777a21b9706d503496c650af06f80d278c1aPeter Collingbourne#endif
177