[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Constants.cpp Type.cpp
Andrew Lenharth
alenhar2 at cs.uiuc.edu
Fri Dec 8 10:07:48 PST 2006
Changes in directory llvm/lib/VMCore:
AsmWriter.cpp updated: 1.228 -> 1.229
Constants.cpp updated: 1.183 -> 1.184
Type.cpp updated: 1.151 -> 1.152
---
Log message:
Packed Structures
---
Diffs of the changes: (+32 -12)
AsmWriter.cpp | 8 ++++++++
Constants.cpp | 5 ++---
Type.cpp | 31 ++++++++++++++++++++++---------
3 files changed, 32 insertions(+), 12 deletions(-)
Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.228 llvm/lib/VMCore/AsmWriter.cpp:1.229
--- llvm/lib/VMCore/AsmWriter.cpp:1.228 Thu Dec 7 14:04:42 2006
+++ llvm/lib/VMCore/AsmWriter.cpp Fri Dec 8 12:06:15 2006
@@ -287,6 +287,8 @@
}
case Type::StructTyID: {
const StructType *STy = cast<StructType>(Ty);
+ if (STy->isPacked())
+ Result += '<';
Result += "{ ";
for (StructType::element_iterator I = STy->element_begin(),
E = STy->element_end(); I != E; ++I) {
@@ -295,6 +297,8 @@
calcTypeName(*I, TypeStack, TypeNames, Result);
}
Result += " }";
+ if (STy->isPacked())
+ Result += '>';
break;
}
case Type::PointerTyID:
@@ -699,6 +703,8 @@
}
Out << ')';
} else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
+ if (STy->isPacked())
+ Out << '<';
Out << "{ ";
for (StructType::element_iterator I = STy->element_begin(),
E = STy->element_end(); I != E; ++I) {
@@ -707,6 +713,8 @@
printType(*I);
}
Out << " }";
+ if (STy->isPacked())
+ Out << '>';
} else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
printType(PTy->getElementType()) << '*';
} else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.183 llvm/lib/VMCore/Constants.cpp:1.184
--- llvm/lib/VMCore/Constants.cpp:1.183 Wed Dec 6 22:18:31 2006
+++ llvm/lib/VMCore/Constants.cpp Fri Dec 8 12:06:15 2006
@@ -1150,12 +1150,12 @@
return ConstantAggregateZero::get(Ty);
}
-Constant *ConstantStruct::get(const std::vector<Constant*> &V) {
+Constant *ConstantStruct::get(const std::vector<Constant*> &V, bool packed) {
std::vector<const Type*> StructEls;
StructEls.reserve(V.size());
for (unsigned i = 0, e = V.size(); i != e; ++i)
StructEls.push_back(V[i]->getType());
- return get(StructType::get(StructEls), V);
+ return get(StructType::get(StructEls, packed), V);
}
// destroyConstant - Remove the constant from the constant table...
@@ -2183,4 +2183,3 @@
}
return "";
}
-
Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.151 llvm/lib/VMCore/Type.cpp:1.152
--- llvm/lib/VMCore/Type.cpp:1.151 Sun Nov 26 19:05:10 2006
+++ llvm/lib/VMCore/Type.cpp Fri Dec 8 12:06:16 2006
@@ -22,6 +22,7 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/Debug.h"
#include <algorithm>
using namespace llvm;
@@ -29,7 +30,7 @@
// created and later destroyed, all in an effort to make sure that there is only
// a single canonical version of a type.
//
-//#define DEBUG_MERGE_TYPES 1
+// #define DEBUG_MERGE_TYPES 1
AbstractTypeUser::~AbstractTypeUser() {}
@@ -318,7 +319,10 @@
}
case Type::StructTyID: {
const StructType *STy = cast<StructType>(Ty);
- Result = "{ ";
+ if (STy->isPacked())
+ Result = "<{ ";
+ else
+ Result = "{ ";
for (StructType::element_iterator I = STy->element_begin(),
E = STy->element_end(); I != E; ++I) {
if (I != STy->element_begin())
@@ -326,6 +330,8 @@
Result += getTypeDescription(*I, TypeStack);
}
Result += " }";
+ if (STy->isPacked())
+ Result += ">";
break;
}
case Type::PointerTyID: {
@@ -454,8 +460,9 @@
setAbstract(isAbstract);
}
-StructType::StructType(const std::vector<const Type*> &Types)
+StructType::StructType(const std::vector<const Type*> &Types, bool isPacked)
: CompositeType(StructTyID) {
+ setSubclassData(isPacked);
ContainedTys.reserve(Types.size());
bool isAbstract = false;
for (unsigned i = 0; i < Types.size(); ++i) {
@@ -630,6 +637,7 @@
} else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
const StructType *STy2 = cast<StructType>(Ty2);
if (STy->getNumElements() != STy2->getNumElements()) return false;
+ if (STy->isPacked() != STy2->isPacked()) return false;
for (unsigned i = 0, e = STy2->getNumElements(); i != e; ++i)
if (!TypesEqual(STy->getElementType(i), STy2->getElementType(i), EqTypes))
return false;
@@ -1137,8 +1145,10 @@
//
class StructValType {
std::vector<const Type*> ElTypes;
+ bool packed;
public:
- StructValType(const std::vector<const Type*> &args) : ElTypes(args) {}
+ StructValType(const std::vector<const Type*> &args, bool isPacked)
+ : ElTypes(args), packed(isPacked) {}
static StructValType get(const StructType *ST) {
std::vector<const Type *> ElTypes;
@@ -1146,7 +1156,7 @@
for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i)
ElTypes.push_back(ST->getElementType(i));
- return StructValType(ElTypes);
+ return StructValType(ElTypes, ST->isPacked());
}
static unsigned hashTypeStructure(const StructType *ST) {
@@ -1160,20 +1170,23 @@
}
inline bool operator<(const StructValType &STV) const {
- return ElTypes < STV.ElTypes;
+ if (ElTypes < STV.ElTypes) return true;
+ else if (ElTypes > STV.ElTypes) return false;
+ else return (int)packed < (int)STV.packed;
}
};
}
static ManagedStatic<TypeMap<StructValType, StructType> > StructTypes;
-StructType *StructType::get(const std::vector<const Type*> &ETypes) {
- StructValType STV(ETypes);
+StructType *StructType::get(const std::vector<const Type*> &ETypes,
+ bool isPacked) {
+ StructValType STV(ETypes, isPacked);
StructType *ST = StructTypes->get(STV);
if (ST) return ST;
// Value not found. Derive a new type!
- StructTypes->add(STV, ST = new StructType(ETypes));
+ StructTypes->add(STV, ST = new StructType(ETypes, isPacked));
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *ST << "\n";
More information about the llvm-commits
mailing list