[cfe-commits] r48051 - in /cfe/trunk: AST/ASTContext.cpp Basic/TargetInfo.cpp Sema/SemaExpr.cpp include/clang/Basic/TargetInfo.h
Chris Lattner
sabre at nondot.org
Sat Mar 8 00:52:55 PST 2008
Author: lattner
Date: Sat Mar 8 02:52:55 2008
New Revision: 48051
URL: http://llvm.org/viewvc/llvm-project?rev=48051&view=rev
Log:
simplify all the type info accessors in TargeTInfo to return scalars,
which is simpler to use and provide.
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/Basic/TargetInfo.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/Basic/TargetInfo.h
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=48051&r1=48050&r2=48051&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Sat Mar 8 02:52:55 2008
@@ -182,7 +182,7 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
}
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
Modified: cfe/trunk/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/TargetInfo.cpp?rev=48051&r1=48050&r2=48051&view=diff
==============================================================================
--- cfe/trunk/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/Basic/TargetInfo.cpp Sat Mar 8 02:52:55 2008
@@ -24,24 +24,16 @@
//===----------------------------------------------------------------------===//
// 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;
-}
-void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align,
- 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 {
- Size = Align = 64; // FIXME: implement correctly.
- Format = &llvm::APFloat::IEEEdouble;
+const llvm::fltSemantics *TargetInfo::getFloatFormat() const {
+ return &llvm::APFloat::IEEEsingle;
+}
+const llvm::fltSemantics *TargetInfo::getDoubleFormat() const {
+ return &llvm::APFloat::IEEEdouble;
+}
+const llvm::fltSemantics *TargetInfo::getLongDoubleFormat() const {
//Size = 80; Align = 32; // FIXME: implement correctly.
//Format = &llvm::APFloat::x87DoubleExtended;
+ return &llvm::APFloat::IEEEdouble;
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=48051&r1=48050&r2=48051&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sat Mar 8 02:52:55 2008
@@ -190,17 +190,16 @@
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().
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=48051&r1=48050&r2=48051&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Sat Mar 8 02:52:55 2008
@@ -33,13 +33,13 @@
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 @@
/// 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
- /// target, in bits.
- void getIntInfo(uint64_t &Size, unsigned &Align) const {
- Size = Align = 32; // FIXME: implement correctly.
- }
+ /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
+ /// target, in bits.
+ unsigned getBoolWidth(bool isWide = false) const { return 8; } // FIXME
+ unsigned getBoolAlign(bool isWide = false) const { return 8; } // FIXME
- /// getLongInfo - Return the size of 'signed long' and 'unsigned long' 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 getCharWidth(bool isWide = false) const {
+ return isWide ? getWCharWidth() : 8; // 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.
+ unsigned getCharAlign(bool isWide = false) const {
+ return isWide ? getWCharAlign() : 8; // FIXME
}
- /// 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;
+ /// 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.
+ unsigned getIntWidth() const { return 32; } // FIXME
+ unsigned getIntAlign() const { return 32; } // FIXME
+
+ /// 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.
+ 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 @@
// 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();
}
More information about the cfe-commits
mailing list