summaryrefslogtreecommitdiff
path: root/lib/Bytecode/Writer
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-10 06:09:41 +0000
committerChris Lattner <sabre@nondot.org>2007-02-10 06:09:41 +0000
commit7cad3cf44819449e1b3450f74adca4193bb9cff2 (patch)
tree4bcb0158408b88e0fc951ef81c2ced9439909514 /lib/Bytecode/Writer
parent06f94d59026b5de5b22a47c01dd452d8a8bbeaa7 (diff)
downloadllvm-7cad3cf44819449e1b3450f74adca4193bb9cff2.tar.gz
llvm-7cad3cf44819449e1b3450f74adca4193bb9cff2.tar.bz2
llvm-7cad3cf44819449e1b3450f74adca4193bb9cff2.tar.xz
Make the ModuleLevel datastructure more sane. When a function-local value
is inserted into the table, it remembers that the value needs to be popped off. This makes purgeFunction much faster, speeding up bcwriting of 447.dealII from 6.8->4.6s (47%). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34133 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Writer')
-rw-r--r--lib/Bytecode/Writer/SlotCalculator.cpp41
-rw-r--r--lib/Bytecode/Writer/SlotCalculator.h11
2 files changed, 19 insertions, 33 deletions
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp
index 00df27f7c6..8e22a18aa5 100644
--- a/lib/Bytecode/Writer/SlotCalculator.cpp
+++ b/lib/Bytecode/Writer/SlotCalculator.cpp
@@ -64,7 +64,6 @@ void SlotCalculator::insertPrimitives() {
SlotCalculator::SlotCalculator(const Module *M) {
assert(M);
- ModuleTypeLevel = 0;
TheModule = M;
insertPrimitives();
@@ -182,11 +181,8 @@ void SlotCalculator::processModule() {
}
- // Compute the ModuleLevel entries.
- ModuleLevel.resize(getNumPlanes());
- for (unsigned i = 0, e = getNumPlanes(); i != e; ++i)
- ModuleLevel[i] = getPlane(i).size();
- ModuleTypeLevel = Types.size();
+ // Initialize the ModuleLevel entries.
+ ModuleLevel.resize(getNumPlanes(), -1);
SC_DEBUG("end processModule!\n");
}
@@ -222,9 +218,6 @@ void SlotCalculator::CreateSlotIfNeeded(const Value *V) {
// Do not index the characters that make up constant strings. We emit
// constant strings as special entities that don't require their
// individual characters to be emitted.
- assert(ModuleLevel.empty() &&
- "How can a constant string be directly accessed in a function?");
- // Otherwise, this IS a string: remember it.
if (!C->isNullValue())
ConstantStrings.push_back(cast<ConstantArray>(C));
} else {
@@ -313,16 +306,16 @@ void SlotCalculator::purgeFunction() {
// Next, remove values from existing type planes
for (unsigned i = 0; i != NumModuleTypes; ++i) {
- // Size of plane before function came
- unsigned ModuleLev = getModuleLevel(i);
- assert(int(ModuleLev) >= 0 && "BAD!");
+ // If this type is not used by this function, ignore it.
+ int ModuleLev = ModuleLevel[i];
+ if (ModuleLev == -1) continue;
+ ModuleLevel[i] = -1; // Reset for next function.
+
+ // Pop all function-local values in this type-plane off of Table.
TypePlane &Plane = getPlane(i);
-
- assert(ModuleLev <= Plane.size() && "module levels higher than elements?");
- while (Plane.size() != ModuleLev) {
- assert(!isa<GlobalValue>(Plane.back()) &&
- "Functions cannot define globals!");
+ assert(ModuleLev < Plane.size() && "module levels higher than elements?");
+ for (unsigned i = ModuleLev, e = Plane.size(); i != e; ++i) {
NodeMap.erase(Plane.back()); // Erase from nodemap
Plane.pop_back(); // Shrink plane
}
@@ -333,12 +326,8 @@ void SlotCalculator::purgeFunction() {
TypePlane &Plane = Table.back();
SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size "
<< Plane.size() << "\n");
- while (Plane.size()) {
- assert(!isa<GlobalValue>(Plane.back()) &&
- "Functions cannot define globals!");
- NodeMap.erase(Plane.back()); // Erase from nodemap
- Plane.pop_back(); // Shrink plane
- }
+ for (unsigned i = 0, e = Plane.size(); i != e; ++i)
+ NodeMap.erase(Plane[i]); // Erase from nodemap
Table.pop_back(); // Nuke the plane, we don't like it.
}
@@ -357,6 +346,12 @@ void SlotCalculator::CreateFunctionValueSlot(const Value *V) {
if (Table.size() <= TyPlane) // Make sure we have the type plane allocated.
Table.resize(TyPlane+1, TypePlane());
+ // If this is the first value noticed of this type within this function,
+ // remember the module level for this type plane in ModuleLevel. This reminds
+ // us to remove the values in purgeFunction and tells us how many to remove.
+ if (TyPlane < ModuleLevel.size() && ModuleLevel[TyPlane] == -1)
+ ModuleLevel[TyPlane] = Table[TyPlane].size();
+
// If this is the first value to get inserted into the type plane, make sure
// to insert the implicit null value.
if (Table[TyPlane].empty()) {
diff --git a/lib/Bytecode/Writer/SlotCalculator.h b/lib/Bytecode/Writer/SlotCalculator.h
index 229715936e..d39635b107 100644
--- a/lib/Bytecode/Writer/SlotCalculator.h
+++ b/lib/Bytecode/Writer/SlotCalculator.h
@@ -54,7 +54,7 @@ class SlotCalculator {
/// ModuleLevel - Used to keep track of which values belong to the module,
/// and which values belong to the currently incorporated function.
///
- std::vector<unsigned> ModuleLevel;
+ std::vector<int> ModuleLevel;
unsigned ModuleTypeLevel;
SlotCalculator(const SlotCalculator &); // DO NOT IMPLEMENT
@@ -80,15 +80,6 @@ public:
inline unsigned getNumPlanes() const { return Table.size(); }
inline unsigned getNumTypes() const { return Types.size(); }
- inline unsigned getModuleLevel(unsigned Plane) const {
- return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
- }
-
- /// Returns the number of types in the type list that are at module level
- inline unsigned getModuleTypeLevel() const {
- return ModuleTypeLevel;
- }
-
TypePlane &getPlane(unsigned Plane) {
// Okay we are just returning an entry out of the main Table. Make sure the
// plane exists and return it.