summaryrefslogtreecommitdiff
path: root/lib/Target/TargetData.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-26 08:02:17 +0000
committerChris Lattner <sabre@nondot.org>2004-02-26 08:02:17 +0000
commit0e7ac1692675279764a81358f9477e105d2657e3 (patch)
treea360979d80dbbc43fc1a7f8deb6bea33c53dbcef /lib/Target/TargetData.cpp
parentc81493711574375bae500e7c702ca64fc0351e38 (diff)
downloadllvm-0e7ac1692675279764a81358f9477e105d2657e3.tar.gz
llvm-0e7ac1692675279764a81358f9477e105d2657e3.tar.bz2
llvm-0e7ac1692675279764a81358f9477e105d2657e3.tar.xz
Use a map instead of annotations
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r--lib/Target/TargetData.cpp59
1 files changed, 36 insertions, 23 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index 9142f1dfc1..271b6d8f97 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -8,8 +8,7 @@
//===----------------------------------------------------------------------===//
//
// This file defines target properties related to datatype size/offset/alignment
-// information. It uses lazy annotations to cache information about how
-// structure types are laid out and used.
+// information.
//
// This structure should be created once, filled in if the defaults are not
// correct and then passed around by const&. None of the members functions
@@ -33,11 +32,10 @@ static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
uint64_t &Size, unsigned char &Alignment);
//===----------------------------------------------------------------------===//
-// Support for StructLayout Annotation
+// Support for StructLayout
//===----------------------------------------------------------------------===//
-StructLayout::StructLayout(const StructType *ST, const TargetData &TD)
- : Annotation(TD.getStructLayoutAID()) {
+StructLayout::StructLayout(const StructType *ST, const TargetData &TD) {
StructAlignment = 0;
StructSize = 0;
@@ -71,16 +69,6 @@ StructLayout::StructLayout(const StructType *ST, const TargetData &TD)
StructSize = (StructSize/StructAlignment + 1) * StructAlignment;
}
-Annotation *TargetData::TypeAnFactory(AnnotationID AID, const Annotable *T,
- void *D) {
- const TargetData &TD = *(const TargetData*)D;
- assert(AID == TD.AID && "Target data annotation ID mismatch!");
- const Type *Ty = cast<Type>((const Value *)T);
- assert(isa<StructType>(Ty) &&
- "Can only create StructLayout annotation on structs!");
- return new StructLayout(cast<StructType>(Ty), TD);
-}
-
//===----------------------------------------------------------------------===//
// TargetData Class Implementation
//===----------------------------------------------------------------------===//
@@ -90,9 +78,7 @@ TargetData::TargetData(const std::string &TargetName,
unsigned char PtrAl, unsigned char DoubleAl,
unsigned char FloatAl, unsigned char LongAl,
unsigned char IntAl, unsigned char ShortAl,
- unsigned char ByteAl)
- : AID(AnnotationManager::getID("TargetData::" + TargetName)) {
- AnnotationManager::registerAnnotationFactory(AID, TypeAnFactory, this);
+ unsigned char ByteAl) {
// If this assert triggers, a pass "required" TargetData information, but the
// top level tool did not provide once for it. We do not want to default
@@ -114,10 +100,7 @@ TargetData::TargetData(const std::string &TargetName,
ByteAlignment = ByteAl;
}
-TargetData::TargetData(const std::string &ToolName, const Module *M)
- : AID(AnnotationManager::getID("TargetData::" + ToolName)) {
- AnnotationManager::registerAnnotationFactory(AID, TypeAnFactory, this);
-
+TargetData::TargetData(const std::string &ToolName, const Module *M) {
LittleEndian = M->getEndianness() != Module::BigEndian;
PointerSize = M->getPointerSize() != Module::Pointer64 ? 4 : 8;
PointerAlignment = PointerSize;
@@ -129,8 +112,38 @@ TargetData::TargetData(const std::string &ToolName, const Module *M)
ByteAlignment = 1;
}
+static std::map<std::pair<const TargetData*,const StructType*>,
+ StructLayout> *Layouts = 0;
+
+
TargetData::~TargetData() {
- AnnotationManager::registerAnnotationFactory(AID, 0); // Deregister factory
+ if (Layouts) {
+ // Remove any layouts for this TD.
+ std::map<std::pair<const TargetData*,
+ const StructType*>, StructLayout>::iterator
+ I = Layouts->lower_bound(std::make_pair(this, (const StructType*)0));
+ while (I != Layouts->end() && I->first.first == this)
+ Layouts->erase(I++);
+ if (Layouts->empty()) {
+ delete Layouts;
+ Layouts = 0;
+ }
+ }
+}
+
+const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
+ if (Layouts == 0)
+ Layouts = new std::map<std::pair<const TargetData*,const StructType*>,
+ StructLayout>();
+ std::map<std::pair<const TargetData*,const StructType*>,
+ StructLayout>::iterator
+ I = Layouts->lower_bound(std::make_pair(this, Ty));
+ if (I != Layouts->end() && I->first.first == this && I->first.second == Ty)
+ return &I->second;
+ else {
+ return &Layouts->insert(I, std::make_pair(std::make_pair(this, Ty),
+ StructLayout(Ty, *this)))->second;
+ }
}
static inline void getTypeInfo(const Type *Ty, const TargetData *TD,