1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
//===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the TargetInfo and TargetInfoImpl interfaces.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_TARGETINFO_H
#define LLVM_CLANG_BASIC_TARGETINFO_H
#include "clang/Basic/SourceLocation.h"
#include "llvm/Support/DataTypes.h"
#include <vector>
#include <string>
namespace llvm { struct fltSemantics; }
namespace clang {
class TargetInfoImpl;
class Diagnostic;
class SourceManager;
namespace Builtin { struct Info; }
/// TargetInfo - This class exposes information about the current target set.
/// A target set consists of a primary target and zero or more secondary targets
/// which are each represented by a TargetInfoImpl object. TargetInfo responds
/// to various queries as though it were the primary target, but keeps track of,
/// and warns about, the first query made of it that are contradictary among the
/// targets it tracks. For example, if it contains a "PPC32" and "PPC64"
/// target, it will warn the first time the size of the 'long' datatype is
/// queried.
///
/// Note that TargetInfo does not take ownership of the various targets or the
/// diagnostic info, but does expect them to be alive for as long as it is.
///
class TargetInfo {
/// Primary - This tracks the primary target in the target set.
///
const TargetInfoImpl *PrimaryTarget;
/// SecondaryTargets - This tracks the set of secondary targets.
///
std::vector<const TargetInfoImpl*> SecondaryTargets;
/// Diag - If non-null, this object is used to report the first use of
/// non-portable functionality in the translation unit.
///
Diagnostic *Diag;
/// NonPortable - This instance variable keeps track of whether or not the
/// current translation unit is portable across the set of targets tracked.
bool NonPortable;
/// These are all caches for target values.
unsigned WCharWidth, WCharAlign;
//==----------------------------------------------------------------==/
// TargetInfo Construction.
//==----------------------------------------------------------------==/
TargetInfo(const TargetInfoImpl *Primary, Diagnostic *D = 0) {
PrimaryTarget = Primary;
Diag = D;
NonPortable = false;
// Initialize Cache values to uncomputed.
WCharWidth = 0;
}
public:
/// CreateTargetInfo - Create a TargetInfo object from a group of
/// target triples. The first target triple is considered the primary
/// target.
static TargetInfo* CreateTargetInfo(const std::string* TriplesBeg,
const std::string* TripledEnd,
Diagnostic* Diags = NULL);
//==----------------------------------------------------------------==/
// Accessors.
//==----------------------------------------------------------------==/
/// isNonPortable - Return true if the current translation unit has used a
/// target property that is non-portable across the secondary targets.
bool isNonPortable() const {
return NonPortable;
}
/// isPortable - Return true if this translation unit is portable across the
/// secondary targets so far.
bool isPortable() const {
return !NonPortable;
}
/// AddSecondaryTarget - Add a secondary target to the target set.
void AddSecondaryTarget(const TargetInfoImpl *Secondary) {
SecondaryTargets.push_back(Secondary);
}
///===---- Target property query methods --------------------------------===//
/// DiagnoseNonPortability - Emit a diagnostic indicating that the current
/// translation unit is non-portable due to a construct at the specified
/// location. DiagKind indicates what went wrong.
void DiagnoseNonPortability(FullSourceLoc Loc, unsigned DiagKind);
/// getTargetDefines - Appends the target-specific #define values for this
/// target set to the specified buffer.
void getTargetDefines(std::vector<char> &DefineBuffer);
/// isCharSigned - Return true if 'char' is 'signed char' or false if it is
/// treated as 'unsigned char'. This is implementation defined according to
/// C99 6.2.5p15. In our implementation, this is target-specific.
bool isCharSigned(FullSourceLoc Loc) {
// FIXME: implement correctly.
return true;
}
/// getPointerWidth - Return the width of pointers on this target, we
/// currently assume one pointer type.
void getPointerInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = 32; // FIXME: implement correctly.
Align = 32;
}
/// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target,
/// in bits.
void getBoolInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 8; // FIXME: implement correctly: wrong for ppc32.
}
/// getCharInfo - Return the size of 'char', 'signed char' and
/// 'unsigned char' for this target, in bits.
void getCharInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 8; // FIXME: implement correctly.
}
/// getShortInfo - Return the size of 'signed short' and 'unsigned short' for
/// this target, in bits.
void getShortInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 16; // FIXME: implement correctly.
}
/// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this
/// target, in bits.
void getIntInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 32; // FIXME: implement correctly.
}
/// getLongInfo - Return the size of 'signed long' and 'unsigned long' for
/// this target, in bits.
void getLongInfo(uint64_t &Size, unsigned &Align, FullSourceLoc Loc) {
Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64
}
/// getLongLongInfo - Return the size of 'signed long long' and
/// 'unsigned long long' for this target, in bits.
void getLongLongInfo(uint64_t &Size, unsigned &Align,
FullSourceLoc Loc) {
Size = Align = 64; // FIXME: implement correctly.
}
/// getFloatInfo - Characterize 'float' for this target.
void getFloatInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, FullSourceLoc Loc);
/// getDoubleInfo - Characterize 'double' for this target.
void getDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, FullSourceLoc Loc);
/// getLongDoubleInfo - Characterize 'long double' for this target.
void getLongDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format, FullSourceLoc Loc);
/// getWCharInfo - Return the size of wchar_t in bits.
///
void getWCharInfo(uint64_t &Size, unsigned &Align,
FullSourceLoc Loc) {
if (!WCharWidth) ComputeWCharInfo(Loc);
Size = WCharWidth;
Align = WCharAlign;
}
/// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
/// target, in bits.
unsigned getIntMaxTWidth(FullSourceLoc Loc) {
// FIXME: implement correctly.
return 64;
}
/// getTargetBuiltins - Return information about target-specific builtins for
/// the current primary target, and info about which builtins are non-portable
/// across the current set of primary and secondary targets.
void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords,
std::vector<const char *> &NonPortableBuiltins) const;
/// getVAListDeclaration - Return the declaration to use for
/// __builtin_va_list, which is target-specific.
const char *getVAListDeclaration() const;
/// isValidGCCRegisterName - Returns whether the passed in string
/// is a valid register name according to GCC. This is used by Sema for
/// inline asm statements.
bool isValidGCCRegisterName(const char *Name) const;
// getNormalizedGCCRegisterName - Returns the "normalized" GCC register name.
// For example, on x86 it will return "ax" when "eax" is passed in.
const char *getNormalizedGCCRegisterName(const char *Name) const;
enum ConstraintInfo {
CI_None = 0x00,
CI_AllowsMemory = 0x01,
CI_AllowsRegister = 0x02,
CI_ReadWrite = 0x03
};
// validateOutputConstraint, validateInputConstraint - Checks that
// a constraint is valid and provides information about it.
// FIXME: These should return a real error instead of just true/false.
bool validateOutputConstraint(const char *Name, ConstraintInfo &Info) const;
bool validateInputConstraint (const char *Name, unsigned NumOutputs,
ConstraintInfo &info) const;
// Returns a string of target-specific clobbers, in LLVM format.
const char *getClobbers() const;
///===---- Some helper methods ------------------------------------------===//
unsigned getBoolWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getBoolInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
unsigned getCharWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getCharInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
unsigned getWCharWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getWCharInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
unsigned getIntWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getIntInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
unsigned getLongWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getLongInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
unsigned getLongLongWidth(FullSourceLoc Loc) {
uint64_t Size; unsigned Align;
getLongLongInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
/// getTargetPrefix - Return the target prefix used for identifying
/// llvm intrinsics.
const char *getTargetPrefix() const;
/// getTargetTriple - Return the target triple of the primary target.
const char *getTargetTriple() const;
const char *getTargetDescription() const {
// FIXME !
// Hard code darwin-x86 for now.
return "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:\
32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128";
}
private:
void ComputeWCharInfo(FullSourceLoc Loc);
};
/// TargetInfoImpl - This class is implemented for specific targets and is used
/// by the TargetInfo class. Target implementations should initialize instance
/// variables and implement various virtual methods if the default values are
/// not appropriate for the target.
class TargetInfoImpl {
protected:
|