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"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2007-01-29 13:24:35 +08:00
|
|
|
#include "clang/AST/Builtins.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) {
|
|
|
|
// Set defaults. These should be overridden by concrete targets as needed.
|
|
|
|
CharIsSigned = true;
|
|
|
|
WCharWidth = WCharAlign = 32;
|
2008-05-09 13:47:41 +08:00
|
|
|
LongWidth = LongAlign = 32;
|
2008-05-08 13:58:21 +08:00
|
|
|
IntWidth = IntAlign = 32;
|
2008-04-19 01:17:24 +08:00
|
|
|
DoubleWidth = 64;
|
|
|
|
DoubleAlign = 32;
|
2008-03-08 16:59:43 +08:00
|
|
|
FloatFormat = &llvm::APFloat::IEEEsingle;
|
|
|
|
DoubleFormat = &llvm::APFloat::IEEEdouble;
|
|
|
|
LongDoubleFormat = &llvm::APFloat::IEEEdouble;
|
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
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Get rid of any register prefix.
|
2008-02-06 08:11:32 +08:00
|
|
|
removeGCCRegisterPrefix(Name);
|
|
|
|
|
2007-11-25 08:25:21 +08:00
|
|
|
|
|
|
|
if (strcmp(Name, "memory") == 0 ||
|
|
|
|
strcmp(Name, "cc") == 0)
|
|
|
|
return true;
|
|
|
|
|
2008-03-08 16:24:01 +08:00
|
|
|
getGCCRegNames(Names, NumNames);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check aliases.
|
2008-03-08 16:24:01 +08:00
|
|
|
const GCCRegAlias *Aliases;
|
2007-11-25 08:25:21 +08:00
|
|
|
unsigned NumAliases;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
2008-02-06 08:11:32 +08:00
|
|
|
removeGCCRegisterPrefix(Name);
|
2008-02-06 07:30:20 +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) {
|
|
|
|
assert(n >= 0 && (unsigned)n < NumNames &&
|
|
|
|
"Out of bounds register number!");
|
|
|
|
return Names[n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check aliases.
|
2008-03-08 16:24:01 +08:00
|
|
|
const GCCRegAlias *Aliases;
|
2007-11-27 12:11:28 +08:00
|
|
|
unsigned NumAliases;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetInfo::validateOutputConstraint(const char *Name,
|
|
|
|
ConstraintInfo &info) const
|
|
|
|
{
|
|
|
|
// An output constraint must start with '=' or '+'
|
|
|
|
if (*Name != '=' && *Name != '+')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (*Name == '+')
|
|
|
|
info = CI_ReadWrite;
|
|
|
|
else
|
|
|
|
info = CI_None;
|
|
|
|
|
|
|
|
Name++;
|
|
|
|
while (*Name) {
|
|
|
|
switch (*Name) {
|
|
|
|
default:
|
2008-03-08 16:24:01 +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;
|
|
|
|
case 'r': // general register.
|
|
|
|
info = (ConstraintInfo)(info|CI_AllowsRegister);
|
|
|
|
break;
|
|
|
|
case 'm': // memory operand.
|
|
|
|
info = (ConstraintInfo)(info|CI_AllowsMemory);
|
|
|
|
break;
|
|
|
|
case 'g': // general register, memory operand or immediate integer.
|
|
|
|
info = (ConstraintInfo)(info|CI_AllowsMemory|CI_AllowsRegister);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Name++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetInfo::validateInputConstraint(const char *Name,
|
|
|
|
unsigned NumOutputs,
|
2008-03-08 16:24:01 +08:00
|
|
|
ConstraintInfo &info) const {
|
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';
|
|
|
|
|
|
|
|
// Check if matching constraint is out of bounds.
|
|
|
|
if (i >= NumOutputs)
|
|
|
|
return false;
|
2008-03-08 16:24:01 +08:00
|
|
|
} else if (!validateAsmConstraint(*Name, info)) {
|
2007-11-27 12:11:28 +08:00
|
|
|
// FIXME: This assert is in place temporarily
|
|
|
|
// so we can add more constraints as we hit it.
|
|
|
|
// Eventually, an unknown constraint should just be treated as 'g'.
|
|
|
|
assert(0 && "Unknown input constraint type!");
|
|
|
|
}
|
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-02-19 01:00:25 +08:00
|
|
|
case 'I':
|
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;
|
|
|
|
case 'r': // general register.
|
|
|
|
info = (ConstraintInfo)(info|CI_AllowsRegister);
|
|
|
|
break;
|
|
|
|
case 'm': // memory operand.
|
|
|
|
info = (ConstraintInfo)(info|CI_AllowsMemory);
|
|
|
|
break;
|
|
|
|
case 'g': // general register, memory operand or immediate integer.
|
|
|
|
info = (ConstraintInfo)(info|CI_AllowsMemory|CI_AllowsRegister);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Name++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|