1//===--- TCE.h - Declare TCE target feature support -------------*- 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 file declares TCE TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_TCE_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_TCE_H
15
16#include "clang/Basic/TargetInfo.h"
17#include "clang/Basic/TargetOptions.h"
18#include "llvm/Support/Compiler.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22namespace targets {
23
24// llvm and clang cannot be used directly to output native binaries for
25// target, but is used to compile C code to llvm bitcode with correct
26// type and alignment information.
27//
28// TCE uses the llvm bitcode as input and uses it for generating customized
29// target processor and program binary. TCE co-design environment is
30// publicly available in http://tce.cs.tut.fi
31
32static const unsigned TCEOpenCLAddrSpaceMap[] = {
33 0, // Default
34 1, // opencl_global
35 3, // opencl_local
36 2, // opencl_constant
37 0, // opencl_private
38 1, // opencl_global_device
39 1, // opencl_global_host
40 // FIXME: generic has to be added to the target
41 0, // opencl_generic
42 0, // cuda_device
43 0, // cuda_constant
44 0, // cuda_shared
45 0, // sycl_global
46 0, // sycl_global_device
47 0, // sycl_global_host
48 0, // sycl_local
49 0, // sycl_private
50 0, // ptr32_sptr
51 0, // ptr32_uptr
52 0, // ptr64
53 0, // hlsl_groupshared
54 0, // hlsl_constant
55 0, // hlsl_private
56 0, // hlsl_device
57 0, // hlsl_input
58 0, // hlsl_output
59 0, // hlsl_push_constant
60 // Wasm address space values for this target are dummy values,
61 // as it is only enabled for Wasm targets.
62 20, // wasm_funcref
63};
64
65class LLVM_LIBRARY_VISIBILITY TCETargetInfo : public TargetInfo {
66public:
67 TCETargetInfo(const llvm::Triple &Triple, const TargetOptions &)
68 : TargetInfo(Triple) {
69 TLSSupported = false;
70 IntWidth = 32;
71 LongWidth = LongLongWidth = 32;
72 PointerWidth = 32;
73 IntAlign = 32;
74 LongAlign = LongLongAlign = 32;
75 PointerAlign = 32;
76 SuitableAlign = 32;
77 SizeType = UnsignedInt;
78 IntMaxType = SignedLong;
79 IntPtrType = SignedInt;
80 PtrDiffType = SignedInt;
81 FloatWidth = 32;
82 FloatAlign = 32;
83 DoubleWidth = 32;
84 DoubleAlign = 32;
85 LongDoubleWidth = 32;
86 LongDoubleAlign = 32;
87 FloatFormat = &llvm::APFloat::IEEEsingle();
88 DoubleFormat = &llvm::APFloat::IEEEsingle();
89 LongDoubleFormat = &llvm::APFloat::IEEEsingle();
90 resetDataLayout(DL: "E-p:32:32:32-i1:8:8-i8:8:32-"
91 "i16:16:32-i32:32:32-i64:32:32-"
92 "f16:16:16-f32:32:32-f64:32:32-v64:64:64-"
93 "i128:128-"
94 "v128:128:128-v256:256:256-v512:512:512-"
95 "v1024:1024:1024-v2048:2048:2048-"
96 "v4096:4096:4096-a0:0:32-n32");
97 AddrSpaceMap = &TCEOpenCLAddrSpaceMap;
98 UseAddrSpaceMapMangling = true;
99 }
100
101 void getTargetDefines(const LangOptions &Opts,
102 MacroBuilder &Builder) const override;
103
104 bool hasFeature(StringRef Feature) const override { return Feature == "tce"; }
105
106 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override {
107 return {};
108 }
109
110 std::string_view getClobbers() const override { return ""; }
111
112 BuiltinVaListKind getBuiltinVaListKind() const override {
113 return TargetInfo::VoidPtrBuiltinVaList;
114 }
115
116 ArrayRef<const char *> getGCCRegNames() const override { return {}; }
117
118 bool validateAsmConstraint(const char *&Name,
119 TargetInfo::ConstraintInfo &info) const override {
120 return true;
121 }
122
123 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
124 return {};
125 }
126
127 // TCE does not have fixed, but user specified register names.
128 bool isValidGCCRegisterName(StringRef Name) const override { return true; }
129};
130
131class LLVM_LIBRARY_VISIBILITY TCELETargetInfo : public TCETargetInfo {
132public:
133 TCELETargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
134 : TCETargetInfo(Triple, Opts) {
135 BigEndian = false;
136
137 resetDataLayout(DL: "e-p:32:32:32-i1:8:8-i8:8:32-"
138 "i16:16:32-i32:32:32-i64:32:32-"
139 "f16:16:16-f32:32:32-f64:32:32-v64:64:64-"
140 "i128:128-"
141 "v128:128:128-v256:256:256-v512:512:512-"
142 "v1024:1024:1024-v2048:2048:2048-"
143 "v4096:4096:4096-a0:0:32-n32");
144 }
145
146 void getTargetDefines(const LangOptions &Opts,
147 MacroBuilder &Builder) const override;
148};
149
150class LLVM_LIBRARY_VISIBILITY TCELE64TargetInfo : public TCETargetInfo {
151public:
152 TCELE64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
153 : TCETargetInfo(Triple, Opts) {
154 BigEndian = false;
155
156 resetDataLayout(DL: "e-p:64:64:64-i1:8:64-i8:8:64-"
157 "i16:16:64-i32:32:64-i64:64:64-"
158 "f16:16:64-f32:32:64-f64:64:64-v64:64:64-"
159 "i128:128-"
160 "v128:128:128-v256:256:256-v512:512:512-"
161 "v1024:1024:1024-v2048:2048:2048-"
162 "v4096:4096:4096-a0:0:64-n64");
163
164 LongWidth = LongLongWidth = 64;
165 PointerWidth = 64;
166 PointerAlign = 64;
167 LongAlign = LongLongAlign = 64;
168 IntPtrType = SignedLong;
169 SizeType = UnsignedLong;
170 PtrDiffType = SignedLong;
171 DoubleWidth = 64;
172 DoubleAlign = 64;
173 LongDoubleWidth = 64;
174 LongDoubleAlign = 64;
175 DoubleFormat = &llvm::APFloat::IEEEdouble();
176 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
177 }
178
179 void getTargetDefines(const LangOptions &Opts,
180 MacroBuilder &Builder) const override;
181};
182
183} // namespace targets
184} // namespace clang
185#endif // LLVM_CLANG_LIB_BASIC_TARGETS_TCE_H
186