[cfe-commits] r48049 - in /cfe/trunk: Basic/TargetInfo.cpp Basic/Targets.cpp include/clang/Basic/TargetInfo.h
Chris Lattner
sabre at nondot.org
Sat Mar 8 00:24:01 PST 2008
Author: lattner
Date: Sat Mar 8 02:24:01 2008
New Revision: 48049
URL: http://llvm.org/viewvc/llvm-project?rev=48049&view=rev
Log:
eliminate the TargetInfoImpl stuff, simplifying the target implementations.
Modified:
cfe/trunk/Basic/TargetInfo.cpp
cfe/trunk/Basic/Targets.cpp
cfe/trunk/include/clang/Basic/TargetInfo.h
Modified: cfe/trunk/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/TargetInfo.cpp?rev=48049&r1=48048&r2=48049&view=diff
==============================================================================
--- cfe/trunk/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/Basic/TargetInfo.cpp Sat Mar 8 02:24:01 2008
@@ -15,32 +15,29 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/AST/Builtins.h"
#include "llvm/ADT/APFloat.h"
-#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/STLExtras.h"
-#include <set>
using namespace clang;
-void TargetInfoImpl::ANCHOR() {} // out-of-line virtual method for class.
-
+// Out of line virtual dtor for TargetInfo.
+TargetInfo::~TargetInfo() {}
//===----------------------------------------------------------------------===//
-// FIXME: These are temporary hacks, they should revector into the
-// TargetInfoImpl.
+// FIXME: These are temporary hacks.
void TargetInfo::getFloatInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format) {
+ const llvm::fltSemantics *&Format) const {
Align = 32; // FIXME: implement correctly.
Size = 32;
Format = &llvm::APFloat::IEEEsingle;
}
void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format) {
+ const llvm::fltSemantics *&Format) const {
Size = 64; // FIXME: implement correctly.
Align = 32;
Format = &llvm::APFloat::IEEEdouble;
}
void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format) {
+ const llvm::fltSemantics *&Format) const {
Size = Align = 64; // FIXME: implement correctly.
Format = &llvm::APFloat::IEEEdouble;
//Size = 80; Align = 32; // FIXME: implement correctly.
@@ -50,47 +47,6 @@
//===----------------------------------------------------------------------===//
-TargetInfo::TargetInfo(const TargetInfoImpl *TII) {
- Target = TII;
-
- // Initialize Cache values to uncomputed.
- TII->getWCharInfo(WCharWidth, WCharAlign);
-}
-
-
-TargetInfo::~TargetInfo() {
- delete Target;
-}
-
-const char* TargetInfo::getTargetTriple() const {
- return Target->getTargetTriple();
-}
-
-const char *TargetInfo::getTargetPrefix() const {
- return Target->getTargetPrefix();
-}
-
-/// getTargetDefines - Appends the target-specific #define values for this
-/// target set to the specified buffer.
-void TargetInfo::getTargetDefines(std::vector<char> &Buffer) {
- Target->getTargetDefines(Buffer);
-}
-
-
-/// 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 TargetInfo::getTargetBuiltins(const Builtin::Info *&Records,
- unsigned &NumRecords) const {
- // Get info about what actual builtins we will expose.
- Target->getTargetBuiltins(Records, NumRecords);
-}
-
-/// getVAListDeclaration - Return the declaration to use for
-/// __builtin_va_list, which is target-specific.
-const char *TargetInfo::getVAListDeclaration() const {
- return Target->getVAListDeclaration();
-}
static void removeGCCRegisterPrefix(const char *&Name) {
if (Name[0] == '%' || Name[0] == '#')
@@ -112,7 +68,7 @@
strcmp(Name, "cc") == 0)
return true;
- Target->getGCCRegNames(Names, NumNames);
+ getGCCRegNames(Names, NumNames);
// If we have a number it maps to an entry in the register name array.
if (isdigit(Name[0])) {
@@ -129,10 +85,10 @@
}
// Now check aliases.
- const TargetInfoImpl::GCCRegAlias *Aliases;
+ const GCCRegAlias *Aliases;
unsigned NumAliases;
- Target->getGCCRegAliases(Aliases, NumAliases);
+ getGCCRegAliases(Aliases, NumAliases);
for (unsigned i = 0; i < NumAliases; i++) {
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
if (!Aliases[i].Aliases[j])
@@ -145,8 +101,7 @@
return false;
}
-const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const
-{
+const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const {
assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
removeGCCRegisterPrefix(Name);
@@ -154,7 +109,7 @@
const char * const *Names;
unsigned NumNames;
- Target->getGCCRegNames(Names, NumNames);
+ getGCCRegNames(Names, NumNames);
// First, check if we have a number.
if (isdigit(Name[0])) {
@@ -168,10 +123,10 @@
}
// Now check aliases.
- const TargetInfoImpl::GCCRegAlias *Aliases;
+ const GCCRegAlias *Aliases;
unsigned NumAliases;
- Target->getGCCRegAliases(Aliases, NumAliases);
+ getGCCRegAliases(Aliases, NumAliases);
for (unsigned i = 0; i < NumAliases; i++) {
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
if (!Aliases[i].Aliases[j])
@@ -200,7 +155,7 @@
while (*Name) {
switch (*Name) {
default:
- if (!Target->validateAsmConstraint(*Name, info)) {
+ if (!validateAsmConstraint(*Name, info)) {
// 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'.
@@ -227,8 +182,7 @@
bool TargetInfo::validateInputConstraint(const char *Name,
unsigned NumOutputs,
- ConstraintInfo &info) const
-{
+ ConstraintInfo &info) const {
while (*Name) {
switch (*Name) {
default:
@@ -239,7 +193,7 @@
// Check if matching constraint is out of bounds.
if (i >= NumOutputs)
return false;
- } else if (!Target->validateAsmConstraint(*Name, info)) {
+ } else if (!validateAsmConstraint(*Name, info)) {
// 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'.
@@ -267,13 +221,3 @@
return true;
}
-
-std::string TargetInfo::convertConstraint(const char Constraint) const {
- return Target->convertConstraint(Constraint);
-}
-
-const char *TargetInfo::getClobbers() const {
- return Target->getClobbers();
-}
-
-
Modified: cfe/trunk/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/Targets.cpp?rev=48049&r1=48048&r2=48049&view=diff
==============================================================================
--- cfe/trunk/Basic/Targets.cpp (original)
+++ cfe/trunk/Basic/Targets.cpp Sat Mar 8 02:24:01 2008
@@ -36,9 +36,9 @@
namespace {
-class DarwinTargetInfo : public TargetInfoImpl {
+class DarwinTargetInfo : public TargetInfo {
public:
- DarwinTargetInfo(const std::string& triple) : TargetInfoImpl(triple) {}
+ DarwinTargetInfo(const std::string& triple) : TargetInfo(triple) {}
virtual void getTargetDefines(std::vector<char> &Defs) const {
// FIXME: we need a real target configuration system. For now, only define
@@ -67,9 +67,9 @@
};
-class SolarisTargetInfo : public TargetInfoImpl {
+class SolarisTargetInfo : public TargetInfo {
public:
- SolarisTargetInfo(const std::string& triple) : TargetInfoImpl(triple) {}
+ SolarisTargetInfo(const std::string& triple) : TargetInfo(triple) {}
virtual void getTargetDefines(std::vector<char> &Defs) const {
// FIXME: we need a real target configuration system. For now, only define
@@ -362,7 +362,7 @@
NumNames = llvm::array_lengthof(GCCRegNames);
}
- static const TargetInfoImpl::GCCRegAlias GCCRegAliases[] = {
+ static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
// While some of these aliases do map to different registers
// they still share the same register name.
{ { "cc", "cr0", "fr0", "r0", "v0"}, "0" },
@@ -399,7 +399,7 @@
{ { "fr31", "r31", "v31"}, "31" },
};
- static void getGCCRegAliases(const TargetInfoImpl::GCCRegAlias *&Aliases,
+ static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases,
unsigned &NumAliases) {
Aliases = GCCRegAliases;
NumAliases = llvm::array_lengthof(GCCRegAliases);
@@ -456,7 +456,7 @@
NumNames = llvm::array_lengthof(GCCRegNames);
}
- static const TargetInfoImpl::GCCRegAlias GCCRegAliases[] = {
+ static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
{ { "al", "ah", "eax", "rax" }, "ax" },
{ { "bl", "bh", "ebx", "rbx" }, "bx" },
{ { "cl", "ch", "ecx", "rcx" }, "cx" },
@@ -466,7 +466,7 @@
{ { "ebp", "rbp" }, "bp" },
};
- static void getGCCRegAliases(const TargetInfoImpl::GCCRegAlias *&Aliases,
+ static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases,
unsigned &NumAliases) {
Aliases = GCCRegAliases;
NumAliases = llvm::array_lengthof(GCCRegAliases);
@@ -736,19 +736,19 @@
/// triple.
TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
if (T.find("ppc-") == 0 || T.find("powerpc-") == 0)
- return new TargetInfo(new DarwinPPCTargetInfo(T));
+ return new DarwinPPCTargetInfo(T);
if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0)
- return new TargetInfo(new DarwinPPC64TargetInfo(T));
+ return new DarwinPPC64TargetInfo(T);
if (T.find("sparc-") == 0)
- return new TargetInfo(new SolarisSparcV8TargetInfo(T)); // ugly hack
+ return new SolarisSparcV8TargetInfo(T); // ugly hack
if (T.find("x86_64-") == 0)
- return new TargetInfo(new DarwinX86_64TargetInfo(T));
+ return new DarwinX86_64TargetInfo(T);
if (IsX86(T))
- return new TargetInfo(new DarwinI386TargetInfo(T));
+ return new DarwinI386TargetInfo(T);
return NULL;
}
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=48049&r1=48048&r2=48049&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Sat Mar 8 02:24:01 2008
@@ -22,7 +22,6 @@
namespace clang {
-class TargetInfoImpl;
class Diagnostic;
class SourceManager;
@@ -31,105 +30,105 @@
/// TargetInfo - This class exposes information about the current target.
///
class TargetInfo {
- /// Primary - This tracks the primary target in the target set.
- ///
- const TargetInfoImpl *Target;
-
+ std::string Triple;
+protected:
/// These are all caches for target values.
unsigned WCharWidth, WCharAlign;
//==----------------------------------------------------------------==/
// TargetInfo Construction.
//==----------------------------------------------------------------==/
-
- TargetInfo(const TargetInfoImpl *TII);
+ TargetInfo(const std::string &T) : Triple(T) {
+ // Set defaults.
+ WCharWidth = WCharAlign = 32;
+ }
public:
/// CreateTargetInfo - Return the target info object for the specified target
/// triple.
static TargetInfo* CreateTargetInfo(const std::string &Triple);
- ~TargetInfo();
+ virtual ~TargetInfo();
///===---- Target property query methods --------------------------------===//
/// getTargetDefines - Appends the target-specific #define values for this
/// target set to the specified buffer.
- void getTargetDefines(std::vector<char> &DefineBuffer);
+ virtual void getTargetDefines(std::vector<char> &DefineBuffer) const = 0;
/// 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() {
+ bool isCharSigned() const {
// 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) {
+ void getPointerInfo(uint64_t &Size, unsigned &Align) const {
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) {
+ void getBoolInfo(uint64_t &Size, unsigned &Align) const {
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) {
+ void getCharInfo(uint64_t &Size, unsigned &Align) const {
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) {
+ void getShortInfo(uint64_t &Size, unsigned &Align) const {
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) {
+ void getIntInfo(uint64_t &Size, unsigned &Align) const {
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) {
+ void getLongInfo(uint64_t &Size, unsigned &Align) const {
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) {
+ void getLongLongInfo(uint64_t &Size, unsigned &Align) const {
Size = Align = 64; // FIXME: implement correctly.
}
/// getFloatInfo - Characterize 'float' for this target.
void getFloatInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format);
+ const llvm::fltSemantics *&Format) const;
/// getDoubleInfo - Characterize 'double' for this target.
void getDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format);
+ const llvm::fltSemantics *&Format) const;
/// getLongDoubleInfo - Characterize 'long double' for this target.
void getLongDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format);
+ const llvm::fltSemantics *&Format) const;
/// getWCharInfo - Return the size of wchar_t in bits.
///
- void getWCharInfo(uint64_t &Size, unsigned &Align) {
+ void getWCharInfo(uint64_t &Size, unsigned &Align) const {
Size = WCharWidth;
Align = WCharAlign;
}
/// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
/// target, in bits.
- unsigned getIntMaxTWidth() {
+ unsigned getIntMaxTWidth() const {
// FIXME: implement correctly.
return 64;
}
@@ -137,12 +136,12 @@
/// 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) const;
+ virtual void getTargetBuiltins(const Builtin::Info *&Records,
+ unsigned &NumRecords) const = 0;
/// getVAListDeclaration - Return the declaration to use for
/// __builtin_va_list, which is target-specific.
- const char *getVAListDeclaration() const;
+ virtual const char *getVAListDeclaration() const = 0;
/// isValidGCCRegisterName - Returns whether the passed in string
/// is a valid register name according to GCC. This is used by Sema for
@@ -167,20 +166,22 @@
bool validateInputConstraint (const char *Name, unsigned NumOutputs,
ConstraintInfo &info) const;
- std::string convertConstraint(const char Constraint) const;
+ virtual std::string convertConstraint(const char Constraint) const {
+ return std::string(1, Constraint);
+ }
// Returns a string of target-specific clobbers, in LLVM format.
- const char *getClobbers() const;
+ virtual const char *getClobbers() const = 0;
///===---- Some helper methods ------------------------------------------===//
- unsigned getBoolWidth() {
+ unsigned getBoolWidth() const {
uint64_t Size; unsigned Align;
getBoolInfo(Size, Align);
return static_cast<unsigned>(Size);
}
- unsigned getCharWidth(bool isWide = false) {
+ unsigned getCharWidth(bool isWide = false) const {
uint64_t Size; unsigned Align;
if (isWide)
getWCharInfo(Size, Align);
@@ -189,25 +190,25 @@
return static_cast<unsigned>(Size);
}
- unsigned getWCharWidth() {
+ unsigned getWCharWidth() const {
uint64_t Size; unsigned Align;
getWCharInfo(Size, Align);
return static_cast<unsigned>(Size);
}
- unsigned getIntWidth() {
+ unsigned getIntWidth() const {
uint64_t Size; unsigned Align;
getIntInfo(Size, Align);
return static_cast<unsigned>(Size);
}
- unsigned getLongWidth() {
+ unsigned getLongWidth() const {
uint64_t Size; unsigned Align;
getLongInfo(Size, Align);
return static_cast<unsigned>(Size);
}
- unsigned getLongLongWidth() {
+ unsigned getLongLongWidth() const {
uint64_t Size; unsigned Align;
getLongLongInfo(Size, Align);
return static_cast<unsigned>(Size);
@@ -215,10 +216,12 @@
/// getTargetPrefix - Return the target prefix used for identifying
/// llvm intrinsics.
- const char *getTargetPrefix() const;
+ virtual const char *getTargetPrefix() const = 0;
/// getTargetTriple - Return the target triple of the primary target.
- const char *getTargetTriple() const;
+ virtual const char *getTargetTriple() const {
+ return Triple.c_str();
+ }
const char *getTargetDescription() const {
// FIXME !
@@ -226,76 +229,19 @@
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";
}
-};
-
-
-
-
-/// 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:
- unsigned WCharWidth; /// sizeof(wchar_t) in bits. Default value is 32.
- unsigned WCharAlign; /// alignof(wchar_t) in bits. Default value is 32.
- std::string Triple;
-public:
- TargetInfoImpl(const std::string& triple)
- : WCharWidth(32), WCharAlign(32), Triple(triple) {}
-
- virtual ~TargetInfoImpl() {}
-
- /// getTargetTriple - Return the string representing the target triple this
- /// TargetInfoImpl object was created from.
- const char* getTargetTriple() const { return Triple.c_str(); }
-
- virtual const char *getTargetPrefix() const = 0;
-
- /// getTargetDefines - Return a list of the target-specific #define values set
- /// when compiling to this target. Each string should be of the form
- /// "#define X Y\n".
- virtual void getTargetDefines(std::vector<char> &Defines) const = 0;
-
- /// getVAListDeclaration - Return the declaration to use for
- /// __builtin_va_list, which is target-specific.
- virtual const char *getVAListDeclaration() const = 0;
-
- /// getWCharWidth - Return the size of wchar_t in bits.
- ///
- void getWCharInfo(unsigned &Size, unsigned &Align) const {
- Size = WCharWidth;
- Align = WCharAlign;
- }
-
- /// getTargetBuiltins - Return information about target-specific builtins for
- /// the target.
- virtual void getTargetBuiltins(const Builtin::Info *&Records,
- unsigned &NumRecords) const {
- Records = 0;
- NumRecords = 0;
- }
-
- virtual void getGCCRegNames(const char * const *&Names,
- unsigned &NumNames) const = 0;
struct GCCRegAlias {
const char * const Aliases[5];
const char * const Register;
};
+
+protected:
+ virtual void getGCCRegNames(const char * const *&Names,
+ unsigned &NumNames) const = 0;
virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
unsigned &NumAliases) const = 0;
-
virtual bool validateAsmConstraint(char c,
TargetInfo::ConstraintInfo &info) const= 0;
-
- virtual std::string convertConstraint(const char Constraint) const {
- return std::string(1, Constraint);
- }
-
- virtual const char *getClobbers() const = 0;
-private:
- virtual void ANCHOR(); // out-of-line virtual method for class.
};
} // end namespace clang
More information about the cfe-commits
mailing list