[llvm-commits] CVS: llvm/lib/Bytecode/Writer/SlotCalculator.cpp SlotCalculator.h
Chris Lattner
sabre at nondot.org
Fri Feb 9 20:48:07 PST 2007
Changes in directory llvm/lib/Bytecode/Writer:
SlotCalculator.cpp updated: 1.94 -> 1.95
SlotCalculator.h updated: 1.36 -> 1.37
---
Log message:
simplify code.
---
Diffs of the changes: (+13 -33)
SlotCalculator.cpp | 40 ++++++++++------------------------------
SlotCalculator.h | 6 +++---
2 files changed, 13 insertions(+), 33 deletions(-)
Index: llvm/lib/Bytecode/Writer/SlotCalculator.cpp
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.94 llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.95
--- llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.94 Fri Feb 9 22:42:30 2007
+++ llvm/lib/Bytecode/Writer/SlotCalculator.cpp Fri Feb 9 22:47:51 2007
@@ -64,12 +64,11 @@
}
SlotCalculator::SlotCalculator(const Module *M) {
+ assert(M);
ModuleTypeLevel = 0;
TheModule = M;
insertPrimitives();
-
- if (M == 0) return; // Empty table...
processModule();
}
@@ -324,19 +323,7 @@
}
}
- unsigned TyPlane;
- if (Ty->isDerivedType()) {
- int ValSlot = getTypeSlot(Ty);
- if (ValSlot == -1) { // Have we already entered this type?
- // Nope, this is the first we have seen the type, process it.
- ValSlot = insertType(Ty);
- assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
- }
- TyPlane = (unsigned)ValSlot;
- } else {
- TyPlane = Ty->getTypeID();
- }
-
+ unsigned TyPlane = getOrCreateTypeSlot(Ty);
if (Table.size() <= TyPlane) // Make sure we have the type plane allocated.
Table.resize(TyPlane+1, TypePlane());
@@ -369,13 +356,13 @@
}
-int SlotCalculator::getOrCreateTypeSlot(const Type* T) {
+unsigned SlotCalculator::getOrCreateTypeSlot(const Type* T) {
int SlotNo = getTypeSlot(T); // Check to see if it's already in!
- if (SlotNo != -1) return SlotNo;
+ if (SlotNo != -1) return (unsigned)SlotNo;
return insertType(T);
}
-int SlotCalculator::insertType(const Type *Ty) {
+unsigned SlotCalculator::insertType(const Type *Ty) {
assert(Ty && "Can't insert a null type!");
assert(getTypeSlot(Ty) == -1 && "Type is already in the table!");
@@ -385,7 +372,7 @@
//
// global { \2 * } { { \2 }* null }
//
- int ResultSlot = doInsertType(Ty);
+ unsigned ResultSlot = doInsertType(Ty);
SC_DEBUG(" Inserted type: " << Ty->getDescription() << " slot=" <<
ResultSlot << "\n");
@@ -394,13 +381,8 @@
for (po_iterator<const Type*> I = po_begin(Ty), E = po_end(Ty);
I != E; ++I) {
if (*I != Ty) {
- const Type *SubTy = *I;
// If we haven't seen this sub type before, add it to our type table!
- if (getTypeSlot(SubTy) == -1) {
- SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << "\n");
- doInsertType(SubTy);
- SC_DEBUG(" Inserted subtype: " << SubTy->getDescription() << "\n");
- }
+ getOrCreateTypeSlot(*I);
}
}
return ResultSlot;
@@ -410,12 +392,10 @@
// doInsertType - This is a small helper function to be called only
// be insertType.
//
-int SlotCalculator::doInsertType(const Type *Ty) {
-
- // Insert node into table and NodeMap...
+unsigned SlotCalculator::doInsertType(const Type *Ty) {
+ // Insert into TypeMap.
unsigned DestSlot = TypeMap[Ty] = Types.size();
Types.push_back(Ty);
-
SC_DEBUG(" Inserting type [" << DestSlot << "] = " << *Ty << "\n" );
- return (int)DestSlot;
+ return DestSlot;
}
Index: llvm/lib/Bytecode/Writer/SlotCalculator.h
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.36 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.37
--- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.36 Fri Feb 9 22:38:34 2007
+++ llvm/lib/Bytecode/Writer/SlotCalculator.h Fri Feb 9 22:47:51 2007
@@ -109,16 +109,16 @@
// they are ignored.
//
int getOrCreateSlot(const Value *V);
- int getOrCreateTypeSlot(const Type *T);
+ unsigned getOrCreateTypeSlot(const Type *T);
// insertValue - Insert a value into the value table... Return the
// slot that it occupies, or -1 if the declaration is to be ignored
// because of the IgnoreNamedNodes flag.
//
- int insertType(const Type *T);
+ unsigned insertType(const Type *T);
// doInsertValue - Small helper function to be called only be insertVal.
- int doInsertType(const Type *T);
+ unsigned doInsertType(const Type *T);
// processModule - Process all of the module level function declarations and
// types that are available.
More information about the llvm-commits
mailing list