blob: 3c9f917d0ffb0d61b912cc40b4cc8557a8ec06fc [file] [log] [blame]
Sander de Smalen5087ace2020-03-15 14:29:45 +00001//===- SveEmitter.cpp - Generate arm_sve.h for use with clang -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This tablegen backend is responsible for emitting arm_sve.h, which includes
10// a declaration and definition of each function specified by the ARM C/C++
11// Language Extensions (ACLE).
12//
13// For details, visit:
14// https://developer.arm.com/architectures/system-architectures/software-standards/acle
15//
16// Each SVE instruction is implemented in terms of 1 or more functions which
17// are suffixed with the element type of the input vectors. Functions may be
18// implemented in terms of generic vector operations such as +, *, -, etc. or
19// by calling a __builtin_-prefixed function which will be handled by clang's
20// CodeGen library.
21//
22// See also the documentation in include/clang/Basic/arm_sve.td.
23//
24//===----------------------------------------------------------------------===//
25
26#include "llvm/ADT/STLExtras.h"
27#include "llvm/ADT/DenseMap.h"
28#include "llvm/ADT/ArrayRef.h"
29#include "llvm/ADT/StringExtras.h"
30#include "llvm/TableGen/Record.h"
31#include "llvm/TableGen/Error.h"
32#include <string>
33#include <sstream>
34#include <set>
35#include <cctype>
36
37using namespace llvm;
38
39//===----------------------------------------------------------------------===//
40// SVEEmitter
41//===----------------------------------------------------------------------===//
42
43namespace {
44
45class SVEEmitter {
46private:
47 RecordKeeper &Records;
48
49public:
50 SVEEmitter(RecordKeeper &R) : Records(R) {}
51
52 // run - Emit arm_sve.h
53 void run(raw_ostream &o);
54};
55
56} // end anonymous namespace
57
58
59//===----------------------------------------------------------------------===//
60// SVEEmitter implementation
61//===----------------------------------------------------------------------===//
62
63void SVEEmitter::run(raw_ostream &OS) {
64 OS << "/*===---- arm_sve.h - ARM SVE intrinsics "
65 "-----------------------------------===\n"
66 " *\n"
67 " *\n"
68 " * Part of the LLVM Project, under the Apache License v2.0 with LLVM "
69 "Exceptions.\n"
70 " * See https://llvm.org/LICENSE.txt for license information.\n"
71 " * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
72 " *\n"
73 " *===-----------------------------------------------------------------"
74 "------===\n"
75 " */\n\n";
76
77 OS << "#ifndef __ARM_SVE_H\n";
78 OS << "#define __ARM_SVE_H\n\n";
79
80 OS << "#if !defined(__ARM_FEATURE_SVE)\n";
81 OS << "#error \"SVE support not enabled\"\n";
82 OS << "#else\n\n";
83
84 OS << "#include <stdint.h>\n\n";
85 OS << "#ifndef __cplusplus\n";
86 OS << "#include <stdbool.h>\n";
87 OS << "#endif\n\n";
88
89 OS << "typedef __fp16 float16_t;\n";
90 OS << "typedef float float32_t;\n";
91 OS << "typedef double float64_t;\n";
92 OS << "typedef bool bool_t;\n\n";
93
94 OS << "typedef __SVInt8_t svint8_t;\n";
95 OS << "typedef __SVInt16_t svint16_t;\n";
96 OS << "typedef __SVInt32_t svint32_t;\n";
97 OS << "typedef __SVInt64_t svint64_t;\n";
98 OS << "typedef __SVUint8_t svuint8_t;\n";
99 OS << "typedef __SVUint16_t svuint16_t;\n";
100 OS << "typedef __SVUint32_t svuint32_t;\n";
101 OS << "typedef __SVUint64_t svuint64_t;\n";
102 OS << "typedef __SVFloat16_t svfloat16_t;\n";
103 OS << "typedef __SVFloat32_t svfloat32_t;\n";
104 OS << "typedef __SVFloat64_t svfloat64_t;\n";
105 OS << "typedef __SVBool_t svbool_t;\n\n";
106
107 OS << "#define svld1_u8(...) __builtin_sve_svld1_u8(__VA_ARGS__)\n";
108 OS << "#define svld1_u16(...) __builtin_sve_svld1_u16(__VA_ARGS__)\n";
109 OS << "#define svld1_u32(...) __builtin_sve_svld1_u32(__VA_ARGS__)\n";
110 OS << "#define svld1_u64(...) __builtin_sve_svld1_u64(__VA_ARGS__)\n";
111 OS << "#define svld1_s8(...) __builtin_sve_svld1_s8(__VA_ARGS__)\n";
112 OS << "#define svld1_s16(...) __builtin_sve_svld1_s16(__VA_ARGS__)\n";
113 OS << "#define svld1_s32(...) __builtin_sve_svld1_s32(__VA_ARGS__)\n";
114 OS << "#define svld1_s64(...) __builtin_sve_svld1_s64(__VA_ARGS__)\n";
115 OS << "#define svld1_f16(...) __builtin_sve_svld1_f16(__VA_ARGS__)\n";
116 OS << "#define svld1_f32(...) __builtin_sve_svld1_f32(__VA_ARGS__)\n";
117 OS << "#define svld1_f64(...) __builtin_sve_svld1_f64(__VA_ARGS__)\n";
118
119 OS << "#endif /*__ARM_FEATURE_SVE */\n";
120 OS << "#endif /* __ARM_SVE_H */\n";
121}
122
123namespace clang {
124void EmitSveHeader(RecordKeeper &Records, raw_ostream &OS) {
125 SVEEmitter(Records).run(OS);
126}
127
128} // End namespace clang