simplify all the type info accessors in TargeTInfo to return scalars,

which is simpler to use and provide.

llvm-svn: 48051
This commit is contained in:
Chris Lattner 2008-03-08 08:52:55 +00:00
parent 2dca6ff505
commit 7570e9c518
4 changed files with 90 additions and 126 deletions

View File

@ -182,7 +182,7 @@ void ASTContext::InitBuiltinTypes() {
std::pair<uint64_t, unsigned>
ASTContext::getTypeInfo(QualType T) {
T = T.getCanonicalType();
uint64_t Size;
uint64_t Width;
unsigned Align;
switch (T->getTypeClass()) {
case Type::TypeName: assert(0 && "Not a canonical type!");
@ -196,7 +196,7 @@ ASTContext::getTypeInfo(QualType T) {
ConstantArrayType *CAT = cast<ConstantArrayType>(T);
std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType());
Size = EltInfo.first*CAT->getSize().getZExtValue();
Width = EltInfo.first*CAT->getSize().getZExtValue();
Align = EltInfo.second;
break;
}
@ -204,68 +204,75 @@ ASTContext::getTypeInfo(QualType T) {
case Type::Vector: {
std::pair<uint64_t, unsigned> EltInfo =
getTypeInfo(cast<VectorType>(T)->getElementType());
Size = EltInfo.first*cast<VectorType>(T)->getNumElements();
Width = EltInfo.first*cast<VectorType>(T)->getNumElements();
// FIXME: Vector alignment is not the alignment of its elements.
Align = EltInfo.second;
break;
}
case Type::Builtin: {
case Type::Builtin:
// FIXME: need to use TargetInfo to derive the target specific sizes. This
// implementation will suffice for play with vector support.
const llvm::fltSemantics *F;
switch (cast<BuiltinType>(T)->getKind()) {
default: assert(0 && "Unknown builtin type!");
case BuiltinType::Void:
assert(0 && "Incomplete types have no size!");
case BuiltinType::Bool:
Target.getBoolInfo(Size, Align);
Width = Target.getBoolWidth();
Align = Target.getBoolAlign();
break;
case BuiltinType::Char_S:
case BuiltinType::Char_U:
case BuiltinType::UChar:
case BuiltinType::SChar:
Target.getCharInfo(Size, Align);
Width = Target.getCharWidth();
Align = Target.getCharAlign();
break;
case BuiltinType::UShort:
case BuiltinType::Short:
Target.getShortInfo(Size, Align);
Width = Target.getShortWidth();
Align = Target.getShortAlign();
break;
case BuiltinType::UInt:
case BuiltinType::Int:
Target.getIntInfo(Size, Align);
Width = Target.getIntWidth();
Align = Target.getIntAlign();
break;
case BuiltinType::ULong:
case BuiltinType::Long:
Target.getLongInfo(Size, Align);
Width = Target.getLongWidth();
Align = Target.getLongAlign();
break;
case BuiltinType::ULongLong:
case BuiltinType::LongLong:
Target.getLongLongInfo(Size, Align);
Width = Target.getLongLongWidth();
Align = Target.getLongLongAlign();
break;
case BuiltinType::Float:
Target.getFloatInfo(Size, Align, F);
Width = Target.getFloatWidth();
Align = Target.getFloatAlign();
break;
case BuiltinType::Double:
Target.getDoubleInfo(Size, Align, F);
Width = Target.getDoubleWidth();
Align = Target.getDoubleAlign();
break;
case BuiltinType::LongDouble:
Target.getLongDoubleInfo(Size, Align, F);
Width = Target.getLongDoubleWidth();
Align = Target.getLongDoubleAlign();
break;
}
break;
}
case Type::ASQual:
// FIXME: Pointers into different addr spaces could have different sizes and
// alignment requirements: getPointerInfo should take an AddrSpace.
return getTypeInfo(QualType(cast<ASQualType>(T)->getBaseType(), 0));
case Type::ObjCQualifiedId:
Size = Target.getPointerWidth(0);
Width = Target.getPointerWidth(0);
Align = Target.getPointerAlign(0);
break;
case Type::Pointer: {
unsigned AS = cast<PointerType>(T)->getPointeeType().getAddressSpace();
Size = Target.getPointerWidth(AS);
Width = Target.getPointerWidth(AS);
Align = Target.getPointerAlign(AS);
break;
}
@ -281,7 +288,7 @@ ASTContext::getTypeInfo(QualType T) {
// size.
std::pair<uint64_t, unsigned> EltInfo =
getTypeInfo(cast<ComplexType>(T)->getElementType());
Size = EltInfo.first*2;
Width = EltInfo.first*2;
Align = EltInfo.second;
break;
}
@ -289,7 +296,7 @@ ASTContext::getTypeInfo(QualType T) {
TagType *TT = cast<TagType>(T);
if (RecordType *RT = dyn_cast<RecordType>(TT)) {
const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl());
Size = Layout.getSize();
Width = Layout.getSize();
Align = Layout.getAlignment();
} else if (EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) {
return getTypeInfo(ED->getIntegerType());
@ -300,7 +307,7 @@ ASTContext::getTypeInfo(QualType T) {
}
assert(Align && (Align & (Align-1)) == 0 && "Alignment must be power of 2");
return std::make_pair(Size, Align);
return std::make_pair(Width, Align);
}
/// getASTRecordLayout - Get or compute information about the layout of the

View File

@ -24,24 +24,16 @@ TargetInfo::~TargetInfo() {}
//===----------------------------------------------------------------------===//
// FIXME: These are temporary hacks.
void TargetInfo::getFloatInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format) const {
Align = 32; // FIXME: implement correctly.
Size = 32;
Format = &llvm::APFloat::IEEEsingle;
const llvm::fltSemantics *TargetInfo::getFloatFormat() const {
return &llvm::APFloat::IEEEsingle;
}
void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format) const {
Size = 64; // FIXME: implement correctly.
Align = 32;
Format = &llvm::APFloat::IEEEdouble;
const llvm::fltSemantics *TargetInfo::getDoubleFormat() const {
return &llvm::APFloat::IEEEdouble;
}
void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format) const {
Size = Align = 64; // FIXME: implement correctly.
Format = &llvm::APFloat::IEEEdouble;
const llvm::fltSemantics *TargetInfo::getLongDoubleFormat() const {
//Size = 80; Align = 32; // FIXME: implement correctly.
//Format = &llvm::APFloat::x87DoubleExtended;
return &llvm::APFloat::IEEEdouble;
}

View File

@ -190,17 +190,16 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
if (Literal.isFloatingLiteral()) {
QualType Ty;
const llvm::fltSemantics *Format;
uint64_t Size; unsigned Align;
if (Literal.isFloat) {
Ty = Context.FloatTy;
Context.Target.getFloatInfo(Size, Align, Format);
} else if (Literal.isLong) {
Ty = Context.LongDoubleTy;
Context.Target.getLongDoubleInfo(Size, Align, Format);
} else {
Format = Context.Target.getFloatFormat();
} else if (!Literal.isLong) {
Ty = Context.DoubleTy;
Context.Target.getDoubleInfo(Size, Align, Format);
Format = Context.Target.getDoubleFormat();
} else {
Ty = Context.LongDoubleTy;
Format = Context.Target.getLongDoubleFormat();
}
// isExact will be set by GetFloatValue().

View File

@ -33,13 +33,13 @@ class TargetInfo {
std::string Triple;
protected:
/// These are all caches for target values.
bool CharIsSigned;
unsigned WCharWidth, WCharAlign;
//==----------------------------------------------------------------==/
// TargetInfo Construction.
//==----------------------------------------------------------------==/
// TargetInfo Constructor.
TargetInfo(const std::string &T) : Triple(T) {
// Set defaults.
// Set defaults. These should be overridden by concrete targets as needed.
CharIsSigned = true;
WCharWidth = WCharAlign = 32;
}
@ -59,67 +59,67 @@ public:
/// 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() const {
// FIXME: implement correctly.
return true;
}
bool isCharSigned() const { return CharIsSigned; }
/// getPointerWidth - Return the width of pointers on this target, for the
/// specified address space. FIXME: implement correctly.
uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; }
uint64_t getPointerAlign(unsigned AddrSpace) const { return 32; }
/// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target,
/// in bits.
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) 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) const {
Size = Align = 16; // FIXME: implement correctly.
}
/// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this
/// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
/// target, in bits.
void getIntInfo(uint64_t &Size, unsigned &Align) const {
Size = Align = 32; // FIXME: implement correctly.
unsigned getBoolWidth(bool isWide = false) const { return 8; } // FIXME
unsigned getBoolAlign(bool isWide = false) const { return 8; } // FIXME
unsigned getCharWidth(bool isWide = false) const {
return isWide ? getWCharWidth() : 8; // FIXME
}
unsigned getCharAlign(bool isWide = false) const {
return isWide ? getWCharAlign() : 8; // FIXME
}
/// getLongInfo - Return the size of 'signed long' and 'unsigned long' for
/// getShortWidth/Align - Return the size of 'signed short' and
/// 'unsigned short' for this target, in bits.
unsigned getShortWidth() const { return 16; } // FIXME
unsigned getShortAlign() const { return 16; } // FIXME
/// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
/// this target, in bits.
void getLongInfo(uint64_t &Size, unsigned &Align) const {
Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64
}
unsigned getIntWidth() const { return 32; } // FIXME
unsigned getIntAlign() const { return 32; } // FIXME
/// getLongLongInfo - Return the size of 'signed long long' and
/// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
/// for this target, in bits.
unsigned getLongWidth() const { return 32; } // FIXME
unsigned getLongAlign() const { return 32; } // FIXME
/// getLongLongWidth/Align - Return the size of 'signed long long' and
/// 'unsigned long long' for this target, in bits.
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;
/// getDoubleInfo - Characterize 'double' for this target.
void getDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format) const;
/// getLongDoubleInfo - Characterize 'long double' for this target.
void getLongDoubleInfo(uint64_t &Size, unsigned &Align,
const llvm::fltSemantics *&Format) const;
unsigned getLongLongWidth() const { return 64; } // FIXME
unsigned getLongLongAlign() const { return 64; } // FIXME
/// getWcharWidth/Align - Return the size of 'wchar_t' for this target, in
/// bits.
unsigned getWCharWidth() const { return WCharWidth; }
unsigned getWCharAlign() const { return WCharAlign; }
/// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
unsigned getFloatWidth() const { return 32; } // FIXME
unsigned getFloatAlign() const { return 32; } // FIXME
const llvm::fltSemantics *getFloatFormat() const;
/// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
unsigned getDoubleWidth() const { return 64; } // FIXME
unsigned getDoubleAlign() const { return 32; } // FIXME
const llvm::fltSemantics *getDoubleFormat() const;
/// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
/// double'.
unsigned getLongDoubleWidth() const { return 64; } // FIXME
unsigned getLongDoubleAlign() const { return 64; } // FIXME
const llvm::fltSemantics *getLongDoubleFormat() const;
/// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
/// target, in bits.
unsigned getIntMaxTWidth() const {
@ -167,47 +167,13 @@ public:
// Returns a string of target-specific clobbers, in LLVM format.
virtual const char *getClobbers() const = 0;
///===---- Some helper methods ------------------------------------------===//
unsigned getBoolWidth() const {
uint64_t Size; unsigned Align;
getBoolInfo(Size, Align);
return static_cast<unsigned>(Size);
}
unsigned getCharWidth(bool isWide = false) const {
if (isWide)
return WCharWidth;
uint64_t Size; unsigned Align;
getCharInfo(Size, Align);
return static_cast<unsigned>(Size);
}
unsigned getIntWidth() const {
uint64_t Size; unsigned Align;
getIntInfo(Size, Align);
return static_cast<unsigned>(Size);
}
unsigned getLongWidth() const {
uint64_t Size; unsigned Align;
getLongInfo(Size, Align);
return static_cast<unsigned>(Size);
}
unsigned getLongLongWidth() const {
uint64_t Size; unsigned Align;
getLongLongInfo(Size, Align);
return static_cast<unsigned>(Size);
}
/// getTargetPrefix - Return the target prefix used for identifying
/// llvm intrinsics.
virtual const char *getTargetPrefix() const = 0;
/// getTargetTriple - Return the target triple of the primary target.
virtual const char *getTargetTriple() const {
const char *getTargetTriple() const {
return Triple.c_str();
}