2006-10-14 15:06:20 +08:00
|
|
|
//===--- TargetInfo.cpp - Information about Target machine ----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-10-14 15:06:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the TargetInfo and TargetInfoImpl interfaces.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2009-11-06 04:14:16 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2007-09-23 02:29:59 +08:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
2007-11-25 08:25:21 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2008-04-06 12:02:29 +08:00
|
|
|
#include <cstdlib>
|
2006-10-14 15:06:20 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2008-03-08 16:59:43 +08:00
|
|
|
// TargetInfo Constructor.
|
|
|
|
TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
|
2008-05-20 22:21:01 +08:00
|
|
|
// Set defaults. Defaults are set for a 32-bit RISC platform,
|
|
|
|
// like PPC or SPARC.
|
|
|
|
// These should be overridden by concrete targets as needed.
|
2009-04-20 05:38:35 +08:00
|
|
|
TLSSupported = true;
|
2008-05-09 14:08:39 +08:00
|
|
|
PointerWidth = PointerAlign = 32;
|
2008-03-08 16:59:43 +08:00
|
|
|
WCharWidth = WCharAlign = 32;
|
2009-07-14 14:30:34 +08:00
|
|
|
Char16Width = Char16Align = 16;
|
|
|
|
Char32Width = Char32Align = 32;
|
2008-05-08 13:58:21 +08:00
|
|
|
IntWidth = IntAlign = 32;
|
2008-05-09 13:50:02 +08:00
|
|
|
LongWidth = LongAlign = 32;
|
|
|
|
LongLongWidth = LongLongAlign = 64;
|
2008-05-20 22:21:01 +08:00
|
|
|
FloatWidth = 32;
|
|
|
|
FloatAlign = 32;
|
2008-04-19 01:17:24 +08:00
|
|
|
DoubleWidth = 64;
|
2008-05-20 22:21:01 +08:00
|
|
|
DoubleAlign = 64;
|
|
|
|
LongDoubleWidth = 64;
|
|
|
|
LongDoubleAlign = 64;
|
2009-01-18 07:56:13 +08:00
|
|
|
IntMaxTWidth = 64;
|
2008-11-01 00:05:19 +08:00
|
|
|
SizeType = UnsignedLong;
|
2008-11-02 10:43:55 +08:00
|
|
|
PtrDiffType = SignedLong;
|
2008-10-31 17:52:39 +08:00
|
|
|
IntMaxType = SignedLongLong;
|
|
|
|
UIntMaxType = UnsignedLongLong;
|
2009-02-14 06:28:55 +08:00
|
|
|
IntPtrType = SignedLong;
|
2008-11-02 10:43:55 +08:00
|
|
|
WCharType = SignedInt;
|
2009-10-21 12:59:34 +08:00
|
|
|
WIntType = SignedInt;
|
2009-07-14 14:30:34 +08:00
|
|
|
Char16Type = UnsignedShort;
|
|
|
|
Char32Type = UnsignedInt;
|
2009-07-01 11:36:11 +08:00
|
|
|
Int64Type = SignedLongLong;
|
2008-03-08 16:59:43 +08:00
|
|
|
FloatFormat = &llvm::APFloat::IEEEsingle;
|
|
|
|
DoubleFormat = &llvm::APFloat::IEEEdouble;
|
|
|
|
LongDoubleFormat = &llvm::APFloat::IEEEdouble;
|
2008-08-21 08:13:15 +08:00
|
|
|
DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
|
|
|
|
"i64:64:64-f32:32:32-f64:64:64";
|
2008-10-06 03:22:37 +08:00
|
|
|
UserLabelPrefix = "_";
|
2007-09-23 02:29:59 +08:00
|
|
|
}
|
|
|
|
|
2008-03-08 16:59:43 +08:00
|
|
|
// Out of line virtual dtor for TargetInfo.
|
|
|
|
TargetInfo::~TargetInfo() {}
|
2007-09-23 02:29:59 +08:00
|
|
|
|
2009-02-06 13:04:11 +08:00
|
|
|
/// getTypeName - Return the user string for the specified integer type enum.
|
|
|
|
/// For example, SignedShort -> "short".
|
|
|
|
const char *TargetInfo::getTypeName(IntType T) {
|
|
|
|
switch (T) {
|
|
|
|
default: assert(0 && "not an integer!");
|
|
|
|
case SignedShort: return "short";
|
|
|
|
case UnsignedShort: return "unsigned short";
|
|
|
|
case SignedInt: return "int";
|
|
|
|
case UnsignedInt: return "unsigned int";
|
|
|
|
case SignedLong: return "long int";
|
|
|
|
case UnsignedLong: return "long unsigned int";
|
|
|
|
case SignedLongLong: return "long long int";
|
|
|
|
case UnsignedLongLong: return "long long unsigned int";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 14:24:21 +08:00
|
|
|
/// getTypeConstantSuffix - Return the constant suffix for the specified
|
|
|
|
/// integer type enum. For example, SignedLong -> "L".
|
|
|
|
const char *TargetInfo::getTypeConstantSuffix(IntType T) {
|
|
|
|
switch (T) {
|
|
|
|
default: assert(0 && "not an integer!");
|
|
|
|
case SignedShort:
|
|
|
|
case SignedInt: return "";
|
|
|
|
case SignedLong: return "L";
|
|
|
|
case SignedLongLong: return "LL";
|
|
|
|
case UnsignedShort:
|
|
|
|
case UnsignedInt: return "U";
|
|
|
|
case UnsignedLong: return "UL";
|
|
|
|
case UnsignedLongLong: return "ULL";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getTypeWidth - Return the width (in bits) of the specified integer type
|
|
|
|
/// enum. For example, SignedInt -> getIntWidth().
|
|
|
|
unsigned TargetInfo::getTypeWidth(IntType T) const {
|
|
|
|
switch (T) {
|
|
|
|
default: assert(0 && "not an integer!");
|
|
|
|
case SignedShort: return getShortWidth();
|
|
|
|
case UnsignedShort: return getShortWidth();
|
|
|
|
case SignedInt: return getIntWidth();
|
|
|
|
case UnsignedInt: return getIntWidth();
|
|
|
|
case SignedLong: return getLongWidth();
|
|
|
|
case UnsignedLong: return getLongWidth();
|
|
|
|
case SignedLongLong: return getLongLongWidth();
|
|
|
|
case UnsignedLongLong: return getLongLongWidth();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-10-26 06:49:18 +08:00
|
|
|
/// isTypeSigned - Return whether an integer types is signed. Returns true if
|
2009-10-21 14:24:21 +08:00
|
|
|
/// the type is signed; false otherwise.
|
2009-10-26 06:49:18 +08:00
|
|
|
bool TargetInfo::isTypeSigned(IntType T) const {
|
2009-10-21 14:24:21 +08:00
|
|
|
switch (T) {
|
|
|
|
default: assert(0 && "not an integer!");
|
|
|
|
case SignedShort:
|
|
|
|
case SignedInt:
|
|
|
|
case SignedLong:
|
|
|
|
case SignedLongLong:
|
|
|
|
return true;
|
|
|
|
case UnsignedShort:
|
|
|
|
case UnsignedInt:
|
|
|
|
case UnsignedLong:
|
|
|
|
case UnsignedLongLong:
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-11-06 04:14:16 +08:00
|
|
|
/// setForcedLangOptions - Set forced language options.
|
|
|
|
/// Apply changes to the target information with respect to certain
|
|
|
|
/// language options which change the target configuration.
|
|
|
|
void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
|
|
|
|
if (Opts.ShortWChar) {
|
|
|
|
WCharType = UnsignedShort;
|
|
|
|
WCharWidth = WCharAlign = 16;
|
|
|
|
}
|
|
|
|
}
|
2009-10-21 14:24:21 +08:00
|
|
|
|
2007-09-23 02:29:59 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-01-29 13:24:35 +08:00
|
|
|
|
2008-03-05 09:18:20 +08:00
|
|
|
static void removeGCCRegisterPrefix(const char *&Name) {
|
2008-02-06 08:11:32 +08:00
|
|
|
if (Name[0] == '%' || Name[0] == '#')
|
|
|
|
Name++;
|
|
|
|
}
|
|
|
|
|
2007-11-25 07:38:12 +08:00
|
|
|
/// 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 TargetInfo::isValidGCCRegisterName(const char *Name) const {
|
2007-11-25 08:25:21 +08:00
|
|
|
const char * const *Names;
|
|
|
|
unsigned NumNames;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-25 08:25:21 +08:00
|
|
|
// Get rid of any register prefix.
|
2008-02-06 08:11:32 +08:00
|
|
|
removeGCCRegisterPrefix(Name);
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-25 08:25:21 +08:00
|
|
|
if (strcmp(Name, "memory") == 0 ||
|
|
|
|
strcmp(Name, "cc") == 0)
|
|
|
|
return true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 16:24:01 +08:00
|
|
|
getGCCRegNames(Names, NumNames);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-25 08:25:21 +08:00
|
|
|
// If we have a number it maps to an entry in the register name array.
|
|
|
|
if (isdigit(Name[0])) {
|
|
|
|
char *End;
|
|
|
|
int n = (int)strtol(Name, &End, 0);
|
|
|
|
if (*End == 0)
|
|
|
|
return n >= 0 && (unsigned)n < NumNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check register names.
|
|
|
|
for (unsigned i = 0; i < NumNames; i++) {
|
|
|
|
if (strcmp(Name, Names[i]) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-25 08:25:21 +08:00
|
|
|
// Now check aliases.
|
2008-03-08 16:24:01 +08:00
|
|
|
const GCCRegAlias *Aliases;
|
2007-11-25 08:25:21 +08:00
|
|
|
unsigned NumAliases;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 16:24:01 +08:00
|
|
|
getGCCRegAliases(Aliases, NumAliases);
|
2007-11-25 08:25:21 +08:00
|
|
|
for (unsigned i = 0; i < NumAliases; i++) {
|
|
|
|
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
|
|
|
|
if (!Aliases[i].Aliases[j])
|
|
|
|
break;
|
|
|
|
if (strcmp(Aliases[i].Aliases[j], Name) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-25 07:38:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
2007-11-27 12:11:28 +08:00
|
|
|
|
2008-03-08 16:24:01 +08:00
|
|
|
const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const {
|
2007-11-27 12:11:28 +08:00
|
|
|
assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-06 08:11:32 +08:00
|
|
|
removeGCCRegisterPrefix(Name);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
const char * const *Names;
|
|
|
|
unsigned NumNames;
|
|
|
|
|
2008-03-08 16:24:01 +08:00
|
|
|
getGCCRegNames(Names, NumNames);
|
2007-11-27 12:11:28 +08:00
|
|
|
|
|
|
|
// First, check if we have a number.
|
|
|
|
if (isdigit(Name[0])) {
|
|
|
|
char *End;
|
|
|
|
int n = (int)strtol(Name, &End, 0);
|
|
|
|
if (*End == 0) {
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(n >= 0 && (unsigned)n < NumNames &&
|
2007-11-27 12:11:28 +08:00
|
|
|
"Out of bounds register number!");
|
|
|
|
return Names[n];
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
// Now check aliases.
|
2008-03-08 16:24:01 +08:00
|
|
|
const GCCRegAlias *Aliases;
|
2007-11-27 12:11:28 +08:00
|
|
|
unsigned NumAliases;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 16:24:01 +08:00
|
|
|
getGCCRegAliases(Aliases, NumAliases);
|
2007-11-27 12:11:28 +08:00
|
|
|
for (unsigned i = 0; i < NumAliases; i++) {
|
|
|
|
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
|
|
|
|
if (!Aliases[i].Aliases[j])
|
|
|
|
break;
|
|
|
|
if (strcmp(Aliases[i].Aliases[j], Name) == 0)
|
|
|
|
return Aliases[i].Register;
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
2009-04-27 01:19:08 +08:00
|
|
|
bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
|
|
|
|
const char *Name = Info.getConstraintStr().c_str();
|
2007-11-27 12:11:28 +08:00
|
|
|
// An output constraint must start with '=' or '+'
|
|
|
|
if (*Name != '=' && *Name != '+')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (*Name == '+')
|
2009-04-26 15:16:29 +08:00
|
|
|
Info.setIsReadWrite();
|
2007-11-27 12:11:28 +08:00
|
|
|
|
|
|
|
Name++;
|
|
|
|
while (*Name) {
|
|
|
|
switch (*Name) {
|
|
|
|
default:
|
2009-04-26 15:16:29 +08:00
|
|
|
if (!validateAsmConstraint(Name, Info)) {
|
2008-04-25 00:36:38 +08:00
|
|
|
// FIXME: We temporarily return false
|
2007-11-27 12:11:28 +08:00
|
|
|
// so we can add more constraints as we hit it.
|
|
|
|
// Eventually, an unknown constraint should just be treated as 'g'.
|
2008-04-25 00:36:38 +08:00
|
|
|
return false;
|
2007-11-27 12:11:28 +08:00
|
|
|
}
|
|
|
|
case '&': // early clobber.
|
|
|
|
break;
|
2009-10-13 12:32:07 +08:00
|
|
|
case '%': // commutative.
|
|
|
|
// FIXME: Check that there is a another register after this one.
|
|
|
|
break;
|
2007-11-27 12:11:28 +08:00
|
|
|
case 'r': // general register.
|
2009-04-26 15:16:29 +08:00
|
|
|
Info.setAllowsRegister();
|
2007-11-27 12:11:28 +08:00
|
|
|
break;
|
|
|
|
case 'm': // memory operand.
|
2009-04-26 15:16:29 +08:00
|
|
|
Info.setAllowsMemory();
|
2007-11-27 12:11:28 +08:00
|
|
|
break;
|
|
|
|
case 'g': // general register, memory operand or immediate integer.
|
2009-01-18 10:12:04 +08:00
|
|
|
case 'X': // any operand.
|
2009-04-26 15:16:29 +08:00
|
|
|
Info.setAllowsRegister();
|
|
|
|
Info.setAllowsMemory();
|
2007-11-27 12:11:28 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
Name++;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-18 09:56:57 +08:00
|
|
|
bool TargetInfo::resolveSymbolicName(const char *&Name,
|
2009-04-27 01:57:12 +08:00
|
|
|
ConstraintInfo *OutputConstraints,
|
|
|
|
unsigned NumOutputs,
|
2009-04-26 15:16:29 +08:00
|
|
|
unsigned &Index) const {
|
2009-01-18 09:56:57 +08:00
|
|
|
assert(*Name == '[' && "Symbolic name did not start with '['");
|
|
|
|
Name++;
|
|
|
|
const char *Start = Name;
|
|
|
|
while (*Name && *Name != ']')
|
|
|
|
Name++;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-18 09:56:57 +08:00
|
|
|
if (!*Name) {
|
|
|
|
// Missing ']'
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-18 09:56:57 +08:00
|
|
|
std::string SymbolicName(Start, Name - Start);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 01:57:12 +08:00
|
|
|
for (Index = 0; Index != NumOutputs; ++Index)
|
|
|
|
if (SymbolicName == OutputConstraints[Index].getName())
|
2009-01-18 09:56:57 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-04-27 01:57:12 +08:00
|
|
|
bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
|
|
|
|
unsigned NumOutputs,
|
2009-04-26 15:16:29 +08:00
|
|
|
ConstraintInfo &Info) const {
|
2009-04-27 01:19:08 +08:00
|
|
|
const char *Name = Info.ConstraintStr.c_str();
|
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
while (*Name) {
|
|
|
|
switch (*Name) {
|
|
|
|
default:
|
|
|
|
// Check if we have a matching constraint
|
|
|
|
if (*Name >= '0' && *Name <= '9') {
|
|
|
|
unsigned i = *Name - '0';
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
// Check if matching constraint is out of bounds.
|
|
|
|
if (i >= NumOutputs)
|
|
|
|
return false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
// The constraint should have the same info as the respective
|
2009-01-28 04:38:24 +08:00
|
|
|
// output constraint.
|
2009-04-27 02:05:25 +08:00
|
|
|
Info.setTiedOperand(i, OutputConstraints[i]);
|
2009-04-26 15:16:29 +08:00
|
|
|
} else if (!validateAsmConstraint(Name, Info)) {
|
2008-08-25 17:46:27 +08:00
|
|
|
// FIXME: This error return is in place temporarily so we can
|
|
|
|
// add more constraints as we hit it. Eventually, an unknown
|
|
|
|
// constraint should just be treated as 'g'.
|
|
|
|
return false;
|
2009-01-18 09:56:57 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '[': {
|
|
|
|
unsigned Index = 0;
|
2009-04-27 01:57:12 +08:00
|
|
|
if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index))
|
2009-01-18 09:56:57 +08:00
|
|
|
return false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-18 09:56:57 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2007-12-09 03:32:57 +08:00
|
|
|
case '%': // commutative
|
|
|
|
// FIXME: Fail if % is used with the last operand.
|
|
|
|
break;
|
2007-11-27 12:11:28 +08:00
|
|
|
case 'i': // immediate integer.
|
2008-03-09 14:02:02 +08:00
|
|
|
case 'n': // immediate integer with a known value.
|
2007-11-27 12:11:28 +08:00
|
|
|
break;
|
2009-05-06 12:33:31 +08:00
|
|
|
case 'I': // Various constant constraints with target-specific meanings.
|
|
|
|
case 'J':
|
|
|
|
case 'K':
|
|
|
|
case 'L':
|
|
|
|
case 'M':
|
|
|
|
case 'N':
|
|
|
|
case 'O':
|
|
|
|
case 'P':
|
|
|
|
break;
|
2007-11-27 12:11:28 +08:00
|
|
|
case 'r': // general register.
|
2009-04-26 15:16:29 +08:00
|
|
|
Info.setAllowsRegister();
|
2007-11-27 12:11:28 +08:00
|
|
|
break;
|
|
|
|
case 'm': // memory operand.
|
2009-04-26 15:16:29 +08:00
|
|
|
Info.setAllowsMemory();
|
2007-11-27 12:11:28 +08:00
|
|
|
break;
|
|
|
|
case 'g': // general register, memory operand or immediate integer.
|
2009-01-18 10:12:04 +08:00
|
|
|
case 'X': // any operand.
|
2009-04-26 15:16:29 +08:00
|
|
|
Info.setAllowsRegister();
|
|
|
|
Info.setAllowsMemory();
|
2007-11-27 12:11:28 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
Name++;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-27 12:11:28 +08:00
|
|
|
return true;
|
|
|
|
}
|