Avoid redundant cast<>s / simplify type dispatch.

llvm-svn: 58892
This commit is contained in:
Daniel Dunbar 2008-11-08 06:12:46 +00:00
parent bbc0af7e37
commit 238475c8ca
2 changed files with 34 additions and 45 deletions

View File

@ -214,14 +214,10 @@ CGDebugInfo::getOrCreateCVRType(QualType type, llvm::CompileUnitDesc *Unit)
/// getOrCreateBuiltinType - Get the Basic type from the cache or create a new /// getOrCreateBuiltinType - Get the Basic type from the cache or create a new
/// one if necessary. /// one if necessary.
llvm::TypeDesc * llvm::TypeDesc *
CGDebugInfo::getOrCreateBuiltinType(QualType type, llvm::CompileUnitDesc *Unit) CGDebugInfo::getOrCreateBuiltinType(const BuiltinType *type,
{ llvm::CompileUnitDesc *Unit) {
assert (type->getTypeClass() == Type::Builtin);
const BuiltinType *BT = type->getAsBuiltinType();
unsigned Encoding = 0; unsigned Encoding = 0;
switch (BT->getKind()) switch (type->getKind())
{ {
case BuiltinType::Void: case BuiltinType::Void:
return NULL; return NULL;
@ -261,7 +257,7 @@ CGDebugInfo::getOrCreateBuiltinType(QualType type, llvm::CompileUnitDesc *Unit)
llvm::BasicTypeDesc *BTy = new llvm::BasicTypeDesc(); llvm::BasicTypeDesc *BTy = new llvm::BasicTypeDesc();
// Get the name and location early to assist debugging. // Get the name and location early to assist debugging.
const char *TyName = BT->getName(); const char *TyName = type->getName();
// Bit size, align and offset of the type. // Bit size, align and offset of the type.
uint64_t Size = M->getContext().getTypeSize(type); uint64_t Size = M->getContext().getTypeSize(type);
@ -282,15 +278,14 @@ CGDebugInfo::getOrCreateBuiltinType(QualType type, llvm::CompileUnitDesc *Unit)
} }
llvm::TypeDesc * llvm::TypeDesc *
CGDebugInfo::getOrCreatePointerType(QualType type, llvm::CompileUnitDesc *Unit) CGDebugInfo::getOrCreatePointerType(const PointerType *type,
{ llvm::CompileUnitDesc *Unit) {
// type* // type*
llvm::DerivedTypeDesc *DTy = llvm::DerivedTypeDesc *DTy =
new llvm::DerivedTypeDesc(llvm::dwarf::DW_TAG_pointer_type); new llvm::DerivedTypeDesc(llvm::dwarf::DW_TAG_pointer_type);
// Handle the derived type. // Handle the derived type.
const PointerType *PTRT = type->getAsPointerType(); llvm::TypeDesc *FromTy = getOrCreateType(type->getPointeeType(), Unit);
llvm::TypeDesc *FromTy = getOrCreateType(PTRT->getPointeeType(), Unit);
// Get the name and location early to assist debugging. // Get the name and location early to assist debugging.
SourceManager &SM = M->getContext().getSourceManager(); SourceManager &SM = M->getContext().getSourceManager();
@ -315,16 +310,15 @@ CGDebugInfo::getOrCreatePointerType(QualType type, llvm::CompileUnitDesc *Unit)
} }
llvm::TypeDesc * llvm::TypeDesc *
CGDebugInfo::getOrCreateTypedefType(QualType type, llvm::CompileUnitDesc *Unit) CGDebugInfo::getOrCreateTypedefType(const TypedefType *TDT,
{ llvm::CompileUnitDesc *Unit) {
// typedefs are derived from some other type. // typedefs are derived from some other type.
llvm::DerivedTypeDesc *DTy = llvm::DerivedTypeDesc *DTy =
new llvm::DerivedTypeDesc(llvm::dwarf::DW_TAG_typedef); new llvm::DerivedTypeDesc(llvm::dwarf::DW_TAG_typedef);
// Handle derived type. // Handle derived type.
const TypedefType *TDT = type->getAsTypedefType();
llvm::TypeDesc *FromTy = getOrCreateType(TDT->LookThroughTypedefs(), llvm::TypeDesc *FromTy = getOrCreateType(TDT->LookThroughTypedefs(),
Unit); Unit);
// Get the name and location early to assist debugging. // Get the name and location early to assist debugging.
const char *TyName = TDT->getDecl()->getName(); const char *TyName = TDT->getDecl()->getName();
@ -375,7 +369,7 @@ CGDebugInfo::getOrCreateFunctionType(QualType type, llvm::CompileUnitDesc *Unit)
} }
/// getOrCreateRecordType - get structure or union type. /// getOrCreateRecordType - get structure or union type.
void CGDebugInfo::getOrCreateRecordType(QualType type, void CGDebugInfo::getOrCreateRecordType(const RecordType *type,
llvm::CompileUnitDesc *Unit, llvm::CompileUnitDesc *Unit,
llvm::TypeDesc *&Slot) llvm::TypeDesc *&Slot)
{ {
@ -391,7 +385,7 @@ void CGDebugInfo::getOrCreateRecordType(QualType type,
else else
return; return;
RecordDecl *RecDecl = type->getAsRecordType()->getDecl(); RecordDecl *RecDecl = type->getDecl();
// We can not get the type for forward declarations. // We can not get the type for forward declarations.
// FIXME: What *should* we be doing here? // FIXME: What *should* we be doing here?
if (!RecDecl->getDefinition(M->getContext())) if (!RecDecl->getDefinition(M->getContext()))
@ -429,15 +423,12 @@ void CGDebugInfo::getOrCreateRecordType(QualType type,
/// getOrCreateEnumType - get Enum type. /// getOrCreateEnumType - get Enum type.
llvm::TypeDesc * llvm::TypeDesc *
CGDebugInfo::getOrCreateEnumType(QualType type, llvm::CompileUnitDesc *Unit) CGDebugInfo::getOrCreateEnumType(const EnumType *type,
{ llvm::CompileUnitDesc *Unit) {
llvm::CompositeTypeDesc *EnumTy llvm::CompositeTypeDesc *EnumTy
= new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_enumeration_type); = new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_enumeration_type);
EnumType *EType = dyn_cast<EnumType>(type); EnumDecl *EDecl = type->getDecl();
if (!EType) return(NULL);
EnumDecl *EDecl = EType->getDecl();
SourceManager &SM = M->getContext().getSourceManager(); SourceManager &SM = M->getContext().getSourceManager();
uint64_t Line = SM.getLogicalLineNumber(EDecl->getLocation()); uint64_t Line = SM.getLogicalLineNumber(EDecl->getLocation());
@ -481,8 +472,8 @@ CGDebugInfo::getOrCreateEnumType(QualType type, llvm::CompileUnitDesc *Unit)
/// getOrCreateArrayType - get or create array types. /// getOrCreateArrayType - get or create array types.
llvm::TypeDesc * llvm::TypeDesc *
CGDebugInfo::getOrCreateArrayType(QualType type, llvm::CompileUnitDesc *Unit) CGDebugInfo::getOrCreateArrayType(QualType type,
{ llvm::CompileUnitDesc *Unit) {
llvm::CompositeTypeDesc *ArrayTy llvm::CompositeTypeDesc *ArrayTy
= new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_array_type); = new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_array_type);
@ -527,21 +518,19 @@ CGDebugInfo::getOrCreateArrayType(QualType type, llvm::CompileUnitDesc *Unit)
/// getOrCreateTaggedType - get or create structure/union/Enum type. /// getOrCreateTaggedType - get or create structure/union/Enum type.
void CGDebugInfo::getOrCreateTaggedType(QualType type, void CGDebugInfo::getOrCreateTagType(const TagType *type,
llvm::CompileUnitDesc *Unit, llvm::CompileUnitDesc *Unit,
llvm::TypeDesc *&Slot) llvm::TypeDesc *&Slot) {
{ if (const RecordType *RT = dyn_cast<RecordType>(type))
if (type->isStructureType() || type->isUnionType()) getOrCreateRecordType(RT, Unit, Slot);
getOrCreateRecordType(type, Unit, Slot); else if (const EnumType *ET = dyn_cast<EnumType>(type))
else if (type->isEnumeralType()) Slot = getOrCreateEnumType(ET, Unit);
Slot = getOrCreateEnumType(type, Unit);
} }
/// getOrCreateType - Get the type from the cache or create a new /// getOrCreateType - Get the type from the cache or create a new
/// one if necessary. /// one if necessary.
llvm::TypeDesc * llvm::TypeDesc *
CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit) CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit) {
{
if (type.isNull()) if (type.isNull())
return NULL; return NULL;
@ -571,7 +560,7 @@ CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit)
return NULL; return NULL;
case Type::TypeName: case Type::TypeName:
Slot = getOrCreateTypedefType(type, Unit); Slot = getOrCreateTypedefType(cast<TypedefType>(type), Unit);
break; break;
case Type::FunctionProto: case Type::FunctionProto:
@ -580,15 +569,15 @@ CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit)
break; break;
case Type::Builtin: case Type::Builtin:
Slot = getOrCreateBuiltinType(type, Unit); Slot = getOrCreateBuiltinType(cast<BuiltinType>(type), Unit);
break; break;
case Type::Pointer: case Type::Pointer:
Slot = getOrCreatePointerType(type, Unit); Slot = getOrCreatePointerType(cast<PointerType>(type), Unit);
break; break;
case Type::Tagged: case Type::Tagged:
getOrCreateTaggedType(type, Unit, Slot); getOrCreateTagType(cast<TagType>(type), Unit, Slot);
break; break;
case Type::ConstantArray: case Type::ConstantArray:

View File

@ -79,20 +79,20 @@ private:
/// Helper functions for getOrCreateType. /// Helper functions for getOrCreateType.
llvm::TypeDesc *getOrCreateCVRType(QualType type, llvm::TypeDesc *getOrCreateCVRType(QualType type,
llvm::CompileUnitDesc *unit); llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateBuiltinType(QualType type, llvm::TypeDesc *getOrCreateBuiltinType(const BuiltinType *type,
llvm::CompileUnitDesc *unit); llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateTypedefType(QualType type, llvm::TypeDesc *getOrCreateTypedefType(const TypedefType *type,
llvm::CompileUnitDesc *unit); llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreatePointerType(QualType type, llvm::TypeDesc *getOrCreatePointerType(const PointerType *type,
llvm::CompileUnitDesc *unit); llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateFunctionType(QualType type, llvm::TypeDesc *getOrCreateFunctionType(QualType type,
llvm::CompileUnitDesc *unit); llvm::CompileUnitDesc *unit);
void getOrCreateRecordType(QualType type, void getOrCreateRecordType(const RecordType *type,
llvm::CompileUnitDesc *unit, llvm::CompileUnitDesc *unit,
llvm::TypeDesc *&Slot); llvm::TypeDesc *&Slot);
llvm::TypeDesc *getOrCreateEnumType(QualType type, llvm::TypeDesc *getOrCreateEnumType(const EnumType *type,
llvm::CompileUnitDesc *unit); llvm::CompileUnitDesc *unit);
void getOrCreateTaggedType(QualType type, void getOrCreateTagType(const TagType *type,
llvm::CompileUnitDesc *unit, llvm::CompileUnitDesc *unit,
llvm::TypeDesc *&Slot); llvm::TypeDesc *&Slot);
llvm::TypeDesc *getOrCreateArrayType(QualType type, llvm::TypeDesc *getOrCreateArrayType(QualType type,