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 constexpr LangASMap TCEOpenCLAddrSpaceMap = {
33 {LangAS::opencl_global, 1},
34 {LangAS::opencl_local, 3},
35 {LangAS::opencl_constant, 2},
36 // FIXME: generic has to be added to the target
37 {LangAS::opencl_generic, 0},
38 {LangAS::opencl_global_device, 1},
39 {LangAS::opencl_global_host, 1},
40};
41
42class LLVM_LIBRARY_VISIBILITY TCETargetInfo : public TargetInfo {
43public:
44 TCETargetInfo(const llvm::Triple &Triple, const TargetOptions &)
45 : TargetInfo(Triple) {
46 TLSSupported = false;
47 IntWidth = 32;
48 LongWidth = LongLongWidth = 32;
49 PointerWidth = 32;
50 IntAlign = 32;
51 LongAlign = LongLongAlign = 32;
52 PointerAlign = 32;
53 SuitableAlign = 32;
54 SizeType = UnsignedInt;
55 IntMaxType = SignedLong;
56 IntPtrType = SignedInt;
57 PtrDiffType = SignedInt;
58 FloatWidth = 32;
59 FloatAlign = 32;
60 DoubleWidth = 32;
61 DoubleAlign = 32;
62 LongDoubleWidth = 32;
63 LongDoubleAlign = 32;
64 FloatFormat = &llvm::APFloat::IEEEsingle();
65 DoubleFormat = &llvm::APFloat::IEEEsingle();
66 LongDoubleFormat = &llvm::APFloat::IEEEsingle();
67 resetDataLayout(DL: "E-p:32:32:32-i1:8:8-i8:8:32-"
68 "i16:16:32-i32:32:32-i64:32:32-"
69 "f16:16:16-f32:32:32-f64:32:32-v64:64:64-"
70 "i128:128-"
71 "v128:128:128-v256:256:256-v512:512:512-"
72 "v1024:1024:1024-v2048:2048:2048-"
73 "v4096:4096:4096-a0:0:32-n32");
74 AddrSpaceMap = &TCEOpenCLAddrSpaceMap;
75 UseAddrSpaceMapMangling = true;
76 }
77
78 void getTargetDefines(const LangOptions &Opts,
79 MacroBuilder &Builder) const override;
80
81 bool hasFeature(StringRef Feature) const override { return Feature == "tce"; }
82
83 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override {
84 return {};
85 }
86
87 std::string_view getClobbers() const override { return ""; }
88
89 BuiltinVaListKind getBuiltinVaListKind() const override {
90 return TargetInfo::VoidPtrBuiltinVaList;
91 }
92
93 ArrayRef<const char *> getGCCRegNames() const override { return {}; }
94
95 bool validateAsmConstraint(const char *&Name,
96 TargetInfo::ConstraintInfo &info) const override {
97 return true;
98 }
99
100 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
101 return {};
102 }
103
104 // TCE does not have fixed, but user specified register names.
105 bool isValidGCCRegisterName(StringRef Name) const override { return true; }
106};
107
108class LLVM_LIBRARY_VISIBILITY TCELETargetInfo : public TCETargetInfo {
109public:
110 TCELETargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
111 : TCETargetInfo(Triple, Opts) {
112 BigEndian = false;
113
114 resetDataLayout(DL: "e-p:32:32:32-i1:8:8-i8:8:32-"
115 "i16:16:32-i32:32:32-i64:32:32-"
116 "f16:16:16-f32:32:32-f64:32:32-v64:64:64-"
117 "i128:128-"
118 "v128:128:128-v256:256:256-v512:512:512-"
119 "v1024:1024:1024-v2048:2048:2048-"
120 "v4096:4096:4096-a0:0:32-n32");
121 }
122
123 void getTargetDefines(const LangOptions &Opts,
124 MacroBuilder &Builder) const override;
125};
126
127class LLVM_LIBRARY_VISIBILITY TCELE64TargetInfo : public TCETargetInfo {
128public:
129 TCELE64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
130 : TCETargetInfo(Triple, Opts) {
131 BigEndian = false;
132
133 resetDataLayout(DL: "e-p:64:64:64-i1:8:64-i8:8:64-"
134 "i16:16:64-i32:32:64-i64:64:64-"
135 "f16:16:64-f32:32:64-f64:64:64-v64:64:64-"
136 "i128:128-"
137 "v128:128:128-v256:256:256-v512:512:512-"
138 "v1024:1024:1024-v2048:2048:2048-"
139 "v4096:4096:4096-a0:0:64-n64");
140
141 LongWidth = LongLongWidth = 64;
142 PointerWidth = 64;
143 PointerAlign = 64;
144 LongAlign = LongLongAlign = 64;
145 IntPtrType = SignedLong;
146 SizeType = UnsignedLong;
147 PtrDiffType = SignedLong;
148 DoubleWidth = 64;
149 DoubleAlign = 64;
150 LongDoubleWidth = 64;
151 LongDoubleAlign = 64;
152 DoubleFormat = &llvm::APFloat::IEEEdouble();
153 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
154 }
155
156 void getTargetDefines(const LangOptions &Opts,
157 MacroBuilder &Builder) const override;
158};
159
160} // namespace targets
161} // namespace clang
162#endif // LLVM_CLANG_LIB_BASIC_TARGETS_TCE_H
163