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

View File

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

View File

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

View File

@ -33,13 +33,13 @@ class TargetInfo {
std::string Triple; std::string Triple;
protected: protected:
/// These are all caches for target values. /// These are all caches for target values.
bool CharIsSigned;
unsigned WCharWidth, WCharAlign; unsigned WCharWidth, WCharAlign;
//==----------------------------------------------------------------==/ // TargetInfo Constructor.
// TargetInfo Construction.
//==----------------------------------------------------------------==/
TargetInfo(const std::string &T) : Triple(T) { 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; WCharWidth = WCharAlign = 32;
} }
@ -59,67 +59,67 @@ public:
/// isCharSigned - Return true if 'char' is 'signed char' or false if it is /// isCharSigned - Return true if 'char' is 'signed char' or false if it is
/// treated as 'unsigned char'. This is implementation defined according to /// treated as 'unsigned char'. This is implementation defined according to
/// C99 6.2.5p15. In our implementation, this is target-specific. /// C99 6.2.5p15. In our implementation, this is target-specific.
bool isCharSigned() const { bool isCharSigned() const { return CharIsSigned; }
// FIXME: implement correctly.
return true;
}
/// getPointerWidth - Return the width of pointers on this target, for the /// getPointerWidth - Return the width of pointers on this target, for the
/// specified address space. FIXME: implement correctly. /// specified address space. FIXME: implement correctly.
uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; } uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; }
uint64_t getPointerAlign(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, /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
/// in bits. /// target, in bits.
void getBoolInfo(uint64_t &Size, unsigned &Align) const { unsigned getBoolWidth(bool isWide = false) const { return 8; } // FIXME
Size = Align = 8; // FIXME: implement correctly: wrong for ppc32. 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
} }
/// getCharInfo - Return the size of 'char', 'signed char' and /// getShortWidth/Align - Return the size of 'signed short' and
/// 'unsigned char' for this target, in bits. /// 'unsigned short' for this target, in bits.
void getCharInfo(uint64_t &Size, unsigned &Align) const { unsigned getShortWidth() const { return 16; } // FIXME
Size = Align = 8; // FIXME: implement correctly. unsigned getShortAlign() const { return 16; } // FIXME
}
/// getShortInfo - Return the size of 'signed short' and 'unsigned short' for /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
/// this target, in bits. /// this target, in bits.
void getShortInfo(uint64_t &Size, unsigned &Align) const { unsigned getIntWidth() const { return 32; } // FIXME
Size = Align = 16; // FIXME: implement correctly. unsigned getIntAlign() const { return 32; } // FIXME
}
/// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
/// target, in bits. /// for this target, in bits.
void getIntInfo(uint64_t &Size, unsigned &Align) const { unsigned getLongWidth() const { return 32; } // FIXME
Size = Align = 32; // FIXME: implement correctly. unsigned getLongAlign() const { return 32; } // FIXME
}
/// getLongInfo - Return the size of 'signed long' and 'unsigned long' for /// getLongLongWidth/Align - Return the size of 'signed long long' and
/// this target, in bits. /// 'unsigned long long' for this target, in bits.
void getLongInfo(uint64_t &Size, unsigned &Align) const { unsigned getLongLongWidth() const { return 64; } // FIXME
Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64 unsigned getLongLongAlign() const { return 64; } // FIXME
}
/// getLongLongInfo - 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;
/// getWcharWidth/Align - Return the size of 'wchar_t' for this target, in
/// bits.
unsigned getWCharWidth() const { return WCharWidth; } unsigned getWCharWidth() const { return WCharWidth; }
unsigned getWCharAlign() const { return WCharAlign; } 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 /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
/// target, in bits. /// target, in bits.
unsigned getIntMaxTWidth() const { unsigned getIntMaxTWidth() const {
@ -167,47 +167,13 @@ public:
// Returns a string of target-specific clobbers, in LLVM format. // Returns a string of target-specific clobbers, in LLVM format.
virtual const char *getClobbers() const = 0; 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 /// getTargetPrefix - Return the target prefix used for identifying
/// llvm intrinsics. /// llvm intrinsics.
virtual const char *getTargetPrefix() const = 0; virtual const char *getTargetPrefix() const = 0;
/// getTargetTriple - Return the target triple of the primary target. /// getTargetTriple - Return the target triple of the primary target.
virtual const char *getTargetTriple() const { const char *getTargetTriple() const {
return Triple.c_str(); return Triple.c_str();
} }