Chris Lattner | cf3056d | 2003-10-13 03:32:08 +0000 | [diff] [blame] | 1 | //===-- SlotCalculator.cpp - Calculate what slots values land in ----------===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 10 | // This file implements a useful analysis step to figure out what numbered slots |
| 11 | // values in a program will land in (keeping track of per plane information). |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 12 | // |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 13 | // This is used when writing a file to disk, either in bytecode or assembly. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 17 | #include "SlotCalculator.h" |
Chris Lattner | dcea630 | 2004-01-14 23:34:39 +0000 | [diff] [blame] | 18 | #include "llvm/Constants.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 19 | #include "llvm/DerivedTypes.h" |
Chris Lattner | dcea630 | 2004-01-14 23:34:39 +0000 | [diff] [blame] | 20 | #include "llvm/iOther.h" |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 21 | #include "llvm/Function.h" |
Chris Lattner | dcea630 | 2004-01-14 23:34:39 +0000 | [diff] [blame] | 22 | #include "llvm/Module.h" |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 23 | #include "llvm/SymbolTable.h" |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 24 | #include "llvm/Type.h" |
Chris Lattner | f2d577b | 2004-01-20 19:50:34 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/ConstantsScanner.h" |
Alkis Evlogimenos | 088eb45 | 2003-10-31 03:02:34 +0000 | [diff] [blame] | 26 | #include "Support/PostOrderIterator.h" |
Chris Lattner | cee8f9a | 2001-11-27 00:03:19 +0000 | [diff] [blame] | 27 | #include "Support/STLExtras.h" |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 28 | #include <algorithm> |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 29 | #include <functional> |
| 30 | |
Chris Lattner | 31f8499 | 2003-11-21 20:23:48 +0000 | [diff] [blame] | 31 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 33 | #if 0 |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 34 | #include <iostream> |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 35 | #define SC_DEBUG(X) std::cerr << X |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 36 | #else |
| 37 | #define SC_DEBUG(X) |
| 38 | #endif |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 39 | |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 40 | SlotCalculator::SlotCalculator(const Module *M ) { |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 41 | ModuleContainsAllFunctionConstants = false; |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 42 | ModuleTypeLevel = 0; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 43 | TheModule = M; |
| 44 | |
| 45 | // Preload table... Make sure that all of the primitive types are in the table |
| 46 | // and that their Primitive ID is equal to their slot # |
| 47 | // |
Alkis Evlogimenos | 5d1bdcd | 2003-10-29 03:12:12 +0000 | [diff] [blame] | 48 | SC_DEBUG("Inserting primitive types:\n"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 49 | for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 50 | assert(Type::getPrimitiveType((Type::TypeID)i)); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 51 | insertType(Type::getPrimitiveType((Type::TypeID)i), true); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | if (M == 0) return; // Empty table... |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 55 | processModule(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 58 | SlotCalculator::SlotCalculator(const Function *M ) { |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 59 | ModuleContainsAllFunctionConstants = false; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 60 | TheModule = M ? M->getParent() : 0; |
| 61 | |
| 62 | // Preload table... Make sure that all of the primitive types are in the table |
| 63 | // and that their Primitive ID is equal to their slot # |
| 64 | // |
Alkis Evlogimenos | 5d1bdcd | 2003-10-29 03:12:12 +0000 | [diff] [blame] | 65 | SC_DEBUG("Inserting primitive types:\n"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 66 | for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 67 | assert(Type::getPrimitiveType((Type::TypeID)i)); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 68 | insertType(Type::getPrimitiveType((Type::TypeID)i), true); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | if (TheModule == 0) return; // Empty table... |
| 72 | |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 73 | processModule(); // Process module level stuff |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 74 | incorporateFunction(M); // Start out in incorporated state |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 77 | unsigned SlotCalculator::getGlobalSlot(const Value *V) const { |
| 78 | assert(!CompactionTable.empty() && |
| 79 | "This method can only be used when compaction is enabled!"); |
| 80 | if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V)) |
| 81 | V = CPR->getValue(); |
| 82 | std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(V); |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 83 | assert(I != NodeMap.end() && "Didn't find global slot entry!"); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 84 | return I->second; |
| 85 | } |
| 86 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 87 | unsigned SlotCalculator::getGlobalSlot(const Type* T) const { |
| 88 | std::map<const Type*, unsigned>::const_iterator I = TypeMap.find(T); |
| 89 | assert(I != TypeMap.end() && "Didn't find global slot entry!"); |
| 90 | return I->second; |
| 91 | } |
| 92 | |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 93 | SlotCalculator::TypePlane &SlotCalculator::getPlane(unsigned Plane) { |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 94 | if (CompactionTable.empty()) { // No compaction table active? |
| 95 | // fall out |
| 96 | } else if (!CompactionTable[Plane].empty()) { // Compaction table active. |
| 97 | assert(Plane < CompactionTable.size()); |
| 98 | return CompactionTable[Plane]; |
| 99 | } else { |
| 100 | // Final case: compaction table active, but this plane is not |
| 101 | // compactified. If the type plane is compactified, unmap back to the |
| 102 | // global type plane corresponding to "Plane". |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 103 | if (!CompactionTypes.empty()) { |
| 104 | const Type *Ty = CompactionTypes[Plane]; |
| 105 | TypeMapType::iterator It = TypeMap.find(Ty); |
| 106 | assert(It != TypeMap.end() && "Type not in global constant map?"); |
| 107 | Plane = It->second; |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
| 111 | // Okay we are just returning an entry out of the main Table. Make sure the |
| 112 | // plane exists and return it. |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 113 | if (Plane >= Table.size()) |
| 114 | Table.resize(Plane+1); |
| 115 | return Table[Plane]; |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 116 | } |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 117 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 118 | // processModule - Process all of the module level function declarations and |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 119 | // types that are available. |
| 120 | // |
| 121 | void SlotCalculator::processModule() { |
| 122 | SC_DEBUG("begin processModule!\n"); |
Chris Lattner | 70cc339 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 123 | |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 124 | // Add all of the global variables to the value table... |
Chris Lattner | f1fef65 | 2001-10-13 06:35:09 +0000 | [diff] [blame] | 125 | // |
| 126 | for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend(); |
Chris Lattner | 479b54b | 2002-10-14 00:48:57 +0000 | [diff] [blame] | 127 | I != E; ++I) |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 128 | getOrCreateSlot(I); |
Chris Lattner | 70cc339 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 129 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 130 | // Scavenge the types out of the functions, then add the functions themselves |
| 131 | // to the value table... |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 132 | // |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 133 | for (Module::const_iterator I = TheModule->begin(), E = TheModule->end(); |
| 134 | I != E; ++I) |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 135 | getOrCreateSlot(I); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 136 | |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 137 | // Add all of the module level constants used as initializers |
| 138 | // |
| 139 | for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend(); |
| 140 | I != E; ++I) |
| 141 | if (I->hasInitializer()) |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 142 | getOrCreateSlot(I->getInitializer()); |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 143 | |
Chris Lattner | dcea630 | 2004-01-14 23:34:39 +0000 | [diff] [blame] | 144 | // Now that all global constants have been added, rearrange constant planes |
| 145 | // that contain constant strings so that the strings occur at the start of the |
| 146 | // plane, not somewhere in the middle. |
| 147 | // |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 148 | for (unsigned plane = 0, e = Table.size(); plane != e; ++plane) { |
| 149 | if (const ArrayType *AT = dyn_cast<ArrayType>(Types[plane])) |
| 150 | if (AT->getElementType() == Type::SByteTy || |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 151 | AT->getElementType() == Type::UByteTy) { |
| 152 | TypePlane &Plane = Table[plane]; |
| 153 | unsigned FirstNonStringID = 0; |
| 154 | for (unsigned i = 0, e = Plane.size(); i != e; ++i) |
| 155 | if (isa<ConstantAggregateZero>(Plane[i]) || |
| 156 | cast<ConstantArray>(Plane[i])->isString()) { |
| 157 | // Check to see if we have to shuffle this string around. If not, |
| 158 | // don't do anything. |
| 159 | if (i != FirstNonStringID) { |
| 160 | // Swap the plane entries.... |
| 161 | std::swap(Plane[i], Plane[FirstNonStringID]); |
| 162 | |
| 163 | // Keep the NodeMap up to date. |
| 164 | NodeMap[Plane[i]] = i; |
| 165 | NodeMap[Plane[FirstNonStringID]] = FirstNonStringID; |
| 166 | } |
| 167 | ++FirstNonStringID; |
| 168 | } |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 169 | } |
Chris Lattner | dcea630 | 2004-01-14 23:34:39 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 172 | // If we are emitting a bytecode file, scan all of the functions for their |
| 173 | // constants, which allows us to emit more compact modules. This is optional, |
| 174 | // and is just used to compactify the constants used by different functions |
| 175 | // together. |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 176 | // |
| 177 | // This functionality is completely optional for the bytecode writer, but |
| 178 | // tends to produce smaller bytecode files. This should not be used in the |
| 179 | // future by clients that want to, for example, build and emit functions on |
| 180 | // the fly. For now, however, it is unconditionally enabled when building |
| 181 | // bytecode information. |
| 182 | // |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 183 | ModuleContainsAllFunctionConstants = true; |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 184 | |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 185 | SC_DEBUG("Inserting function constants:\n"); |
| 186 | for (Module::const_iterator F = TheModule->begin(), E = TheModule->end(); |
| 187 | F != E; ++F) { |
| 188 | for (const_inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){ |
| 189 | for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op) |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 190 | if (isa<Constant>(I->getOperand(op))) |
| 191 | getOrCreateSlot(I->getOperand(op)); |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 192 | getOrCreateSlot(I->getType()); |
| 193 | if (const VANextInst *VAN = dyn_cast<VANextInst>(&*I)) |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 194 | getOrCreateSlot(VAN->getArgType()); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 195 | } |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 196 | processSymbolTableConstants(&F->getSymbolTable()); |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 197 | } |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 198 | |
Chris Lattner | 70cc339 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 199 | // Insert constants that are named at module level into the slot pool so that |
| 200 | // the module symbol table can refer to them... |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 201 | SC_DEBUG("Inserting SymbolTable values:\n"); |
| 202 | processSymbolTable(&TheModule->getSymbolTable()); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 203 | |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 204 | // Now that we have collected together all of the information relevant to the |
| 205 | // module, compactify the type table if it is particularly big and outputting |
| 206 | // a bytecode file. The basic problem we run into is that some programs have |
| 207 | // a large number of types, which causes the type field to overflow its size, |
| 208 | // which causes instructions to explode in size (particularly call |
| 209 | // instructions). To avoid this behavior, we "sort" the type table so that |
| 210 | // all non-value types are pushed to the end of the type table, giving nice |
| 211 | // low numbers to the types that can be used by instructions, thus reducing |
| 212 | // the amount of explodage we suffer. |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 213 | if (Types.size() >= 64) { |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 214 | unsigned FirstNonValueTypeID = 0; |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 215 | for (unsigned i = 0, e = Types.size(); i != e; ++i) |
| 216 | if (Types[i]->isFirstClassType() || Types[i]->isPrimitiveType()) { |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 217 | // Check to see if we have to shuffle this type around. If not, don't |
| 218 | // do anything. |
| 219 | if (i != FirstNonValueTypeID) { |
| 220 | // Swap the type ID's. |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 221 | std::swap(Types[i], Types[FirstNonValueTypeID]); |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 222 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 223 | // Keep the TypeMap up to date. |
| 224 | TypeMap[Types[i]] = i; |
| 225 | TypeMap[Types[FirstNonValueTypeID]] = FirstNonValueTypeID; |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 226 | |
| 227 | // When we move a type, make sure to move its value plane as needed. |
Chris Lattner | 9380297 | 2004-01-11 23:29:26 +0000 | [diff] [blame] | 228 | if (Table.size() > FirstNonValueTypeID) { |
| 229 | if (Table.size() <= i) Table.resize(i+1); |
| 230 | std::swap(Table[i], Table[FirstNonValueTypeID]); |
Chris Lattner | 9380297 | 2004-01-11 23:29:26 +0000 | [diff] [blame] | 231 | } |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 232 | } |
| 233 | ++FirstNonValueTypeID; |
| 234 | } |
| 235 | } |
| 236 | |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 237 | SC_DEBUG("end processModule!\n"); |
| 238 | } |
| 239 | |
| 240 | // processSymbolTable - Insert all of the values in the specified symbol table |
| 241 | // into the values table... |
| 242 | // |
| 243 | void SlotCalculator::processSymbolTable(const SymbolTable *ST) { |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 244 | // Do the types first. |
| 245 | for (SymbolTable::type_const_iterator TI = ST->type_begin(), |
| 246 | TE = ST->type_end(); TI != TE; ++TI ) |
| 247 | getOrCreateSlot(TI->second); |
| 248 | |
| 249 | // Now do the values. |
| 250 | for (SymbolTable::plane_const_iterator PI = ST->plane_begin(), |
| 251 | PE = ST->plane_end(); PI != PE; ++PI) |
| 252 | for (SymbolTable::value_const_iterator VI = PI->second.begin(), |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 253 | VE = PI->second.end(); VI != VE; ++VI) |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 254 | getOrCreateSlot(VI->second); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) { |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 258 | // Do the types first |
| 259 | for (SymbolTable::type_const_iterator TI = ST->type_begin(), |
| 260 | TE = ST->type_end(); TI != TE; ++TI ) |
| 261 | getOrCreateSlot(TI->second); |
| 262 | |
| 263 | // Now do the constant values in all planes |
| 264 | for (SymbolTable::plane_const_iterator PI = ST->plane_begin(), |
| 265 | PE = ST->plane_end(); PI != PE; ++PI) |
| 266 | for (SymbolTable::value_const_iterator VI = PI->second.begin(), |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 267 | VE = PI->second.end(); VI != VE; ++VI) |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 268 | if (isa<Constant>(VI->second)) |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 269 | getOrCreateSlot(VI->second); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | |
Chris Lattner | ce439b5 | 2003-10-20 19:10:06 +0000 | [diff] [blame] | 273 | void SlotCalculator::incorporateFunction(const Function *F) { |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 274 | assert((ModuleLevel.size() == 0 || |
| 275 | ModuleTypeLevel == 0) && "Module already incorporated!"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 276 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 277 | SC_DEBUG("begin processFunction!\n"); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 278 | |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 279 | // If we emitted all of the function constants, build a compaction table. |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 280 | if ( ModuleContainsAllFunctionConstants) |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 281 | buildCompactionTable(F); |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 282 | |
| 283 | // Update the ModuleLevel entries to be accurate. |
| 284 | ModuleLevel.resize(getNumPlanes()); |
| 285 | for (unsigned i = 0, e = getNumPlanes(); i != e; ++i) |
| 286 | ModuleLevel[i] = getPlane(i).size(); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 287 | ModuleTypeLevel = Types.size(); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 289 | // Iterate over function arguments, adding them to the value table... |
Chris Lattner | ce439b5 | 2003-10-20 19:10:06 +0000 | [diff] [blame] | 290 | for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I) |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 291 | getOrCreateSlot(I); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 292 | |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 293 | if ( !ModuleContainsAllFunctionConstants ) { |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 294 | // Iterate over all of the instructions in the function, looking for |
| 295 | // constant values that are referenced. Add these to the value pools |
| 296 | // before any nonconstant values. This will be turned into the constant |
| 297 | // pool for the bytecode writer. |
| 298 | // |
| 299 | |
| 300 | // Emit all of the constants that are being used by the instructions in |
| 301 | // the function... |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 302 | constant_iterator CI = constant_begin(F); |
| 303 | constant_iterator CE = constant_end(F); |
| 304 | while ( CI != CE ) { |
| 305 | this->getOrCreateSlot(*CI); |
| 306 | ++CI; |
| 307 | } |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 308 | |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 309 | // If there is a symbol table, it is possible that the user has names for |
| 310 | // constants that are not being used. In this case, we will have problems |
| 311 | // if we don't emit the constants now, because otherwise we will get |
Chris Lattner | a14b0d4 | 2004-01-10 23:46:13 +0000 | [diff] [blame] | 312 | // symbol table references to constants not in the output. Scan for these |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 313 | // constants now. |
| 314 | // |
Chris Lattner | ce439b5 | 2003-10-20 19:10:06 +0000 | [diff] [blame] | 315 | processSymbolTableConstants(&F->getSymbolTable()); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 318 | SC_DEBUG("Inserting Instructions:\n"); |
| 319 | |
| 320 | // Add all of the instructions to the type planes... |
Chris Lattner | d5c59d5 | 2004-01-15 20:24:09 +0000 | [diff] [blame] | 321 | for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { |
| 322 | getOrCreateSlot(BB); |
Chris Lattner | 389dbfb | 2003-10-21 17:39:59 +0000 | [diff] [blame] | 323 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) { |
| 324 | getOrCreateSlot(I); |
Chris Lattner | 2765c41 | 2003-10-21 17:40:54 +0000 | [diff] [blame] | 325 | if (const VANextInst *VAN = dyn_cast<VANextInst>(I)) |
| 326 | getOrCreateSlot(VAN->getArgType()); |
Chris Lattner | 389dbfb | 2003-10-21 17:39:59 +0000 | [diff] [blame] | 327 | } |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 330 | // If we are building a compaction table, prune out planes that do not benefit |
| 331 | // from being compactified. |
| 332 | if (!CompactionTable.empty()) |
| 333 | pruneCompactionTable(); |
| 334 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 335 | SC_DEBUG("end processFunction!\n"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 338 | void SlotCalculator::purgeFunction() { |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 339 | assert((ModuleLevel.size() != 0 || |
| 340 | ModuleTypeLevel != 0) && "Module not incorporated!"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 341 | unsigned NumModuleTypes = ModuleLevel.size(); |
| 342 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 343 | SC_DEBUG("begin purgeFunction!\n"); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 344 | |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 345 | // First, free the compaction map if used. |
| 346 | CompactionNodeMap.clear(); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 347 | CompactionTypeMap.clear(); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 348 | |
| 349 | // Next, remove values from existing type planes |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 350 | for (unsigned i = 0; i != NumModuleTypes; ++i) { |
| 351 | // Size of plane before function came |
| 352 | unsigned ModuleLev = getModuleLevel(i); |
| 353 | assert(int(ModuleLev) >= 0 && "BAD!"); |
| 354 | |
| 355 | TypePlane &Plane = getPlane(i); |
| 356 | |
| 357 | assert(ModuleLev <= Plane.size() && "module levels higher than elements?"); |
| 358 | while (Plane.size() != ModuleLev) { |
| 359 | assert(!isa<GlobalValue>(Plane.back()) && |
| 360 | "Functions cannot define globals!"); |
| 361 | NodeMap.erase(Plane.back()); // Erase from nodemap |
| 362 | Plane.pop_back(); // Shrink plane |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 363 | } |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 364 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 365 | |
| 366 | // We don't need this state anymore, free it up. |
| 367 | ModuleLevel.clear(); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 368 | ModuleTypeLevel = 0; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 369 | |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 370 | // Finally, remove any type planes defined by the function... |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 371 | CompactionTypes.clear(); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 372 | if (!CompactionTable.empty()) { |
| 373 | CompactionTable.clear(); |
| 374 | } else { |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 375 | while (Table.size() > NumModuleTypes) { |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 376 | TypePlane &Plane = Table.back(); |
| 377 | SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size " |
| 378 | << Plane.size() << "\n"); |
| 379 | while (Plane.size()) { |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 380 | assert(!isa<GlobalValue>(Plane.back()) && |
| 381 | "Functions cannot define globals!"); |
| 382 | NodeMap.erase(Plane.back()); // Erase from nodemap |
| 383 | Plane.pop_back(); // Shrink plane |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 386 | Table.pop_back(); // Nuke the plane, we don't like it. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 387 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 388 | } |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 389 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 390 | SC_DEBUG("end purgeFunction!\n"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 393 | static inline bool hasNullValue(unsigned TyID) { |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 394 | return TyID != Type::LabelTyID && TyID != Type::VoidTyID; |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /// getOrCreateCompactionTableSlot - This method is used to build up the initial |
| 398 | /// approximation of the compaction table. |
| 399 | unsigned SlotCalculator::getOrCreateCompactionTableSlot(const Value *V) { |
Chris Lattner | 71151ae | 2004-02-09 00:15:41 +0000 | [diff] [blame] | 400 | if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V)) |
| 401 | V = CPR->getValue(); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 402 | std::map<const Value*, unsigned>::iterator I = |
| 403 | CompactionNodeMap.lower_bound(V); |
| 404 | if (I != CompactionNodeMap.end() && I->first == V) |
| 405 | return I->second; // Already exists? |
| 406 | |
| 407 | // Make sure the type is in the table. |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 408 | unsigned Ty; |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 409 | if (!CompactionTypes.empty()) |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 410 | Ty = getOrCreateCompactionTableSlot(V->getType()); |
| 411 | else // If the type plane was decompactified, use the global plane ID |
| 412 | Ty = getSlot(V->getType()); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 413 | if (CompactionTable.size() <= Ty) |
| 414 | CompactionTable.resize(Ty+1); |
| 415 | |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 416 | TypePlane &TyPlane = CompactionTable[Ty]; |
| 417 | |
| 418 | // Make sure to insert the null entry if the thing we are inserting is not a |
| 419 | // null constant. |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 420 | if (TyPlane.empty() && hasNullValue(V->getType()->getTypeID())) { |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 421 | Value *ZeroInitializer = Constant::getNullValue(V->getType()); |
| 422 | if (V != ZeroInitializer) { |
| 423 | TyPlane.push_back(ZeroInitializer); |
| 424 | CompactionNodeMap[ZeroInitializer] = 0; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | unsigned SlotNo = TyPlane.size(); |
| 429 | TyPlane.push_back(V); |
| 430 | CompactionNodeMap.insert(std::make_pair(V, SlotNo)); |
| 431 | return SlotNo; |
| 432 | } |
| 433 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 434 | /// getOrCreateCompactionTableSlot - This method is used to build up the initial |
| 435 | /// approximation of the compaction table. |
| 436 | unsigned SlotCalculator::getOrCreateCompactionTableSlot(const Type *T) { |
| 437 | std::map<const Type*, unsigned>::iterator I = |
| 438 | CompactionTypeMap.lower_bound(T); |
| 439 | if (I != CompactionTypeMap.end() && I->first == T) |
| 440 | return I->second; // Already exists? |
| 441 | |
| 442 | unsigned SlotNo = CompactionTypes.size(); |
| 443 | SC_DEBUG("Inserting Compaction Type #" << SlotNo << ": " << T << "\n"); |
| 444 | CompactionTypes.push_back(T); |
| 445 | CompactionTypeMap.insert(std::make_pair(T, SlotNo)); |
| 446 | return SlotNo; |
| 447 | } |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 448 | |
| 449 | /// buildCompactionTable - Since all of the function constants and types are |
| 450 | /// stored in the module-level constant table, we don't need to emit a function |
| 451 | /// constant table. Also due to this, the indices for various constants and |
| 452 | /// types might be very large in large programs. In order to avoid blowing up |
| 453 | /// the size of instructions in the bytecode encoding, we build a compaction |
| 454 | /// table, which defines a mapping from function-local identifiers to global |
| 455 | /// identifiers. |
| 456 | void SlotCalculator::buildCompactionTable(const Function *F) { |
| 457 | assert(CompactionNodeMap.empty() && "Compaction table already built!"); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 458 | assert(CompactionTypeMap.empty() && "Compaction types already built!"); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 459 | // First step, insert the primitive types. |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 460 | CompactionTable.resize(Type::LastPrimitiveTyID+1); |
| 461 | for (unsigned i = 0; i <= Type::LastPrimitiveTyID; ++i) { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 462 | const Type *PrimTy = Type::getPrimitiveType((Type::TypeID)i); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 463 | CompactionTypes.push_back(PrimTy); |
| 464 | CompactionTypeMap[PrimTy] = i; |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | // Next, include any types used by function arguments. |
| 468 | for (Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I) |
| 469 | getOrCreateCompactionTableSlot(I->getType()); |
| 470 | |
| 471 | // Next, find all of the types and values that are referred to by the |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 472 | // instructions in the function. |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 473 | for (const_inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { |
| 474 | getOrCreateCompactionTableSlot(I->getType()); |
| 475 | for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op) |
| 476 | if (isa<Constant>(I->getOperand(op)) || |
| 477 | isa<GlobalValue>(I->getOperand(op))) |
| 478 | getOrCreateCompactionTableSlot(I->getOperand(op)); |
Chris Lattner | 6ffe551 | 2004-04-27 15:13:33 +0000 | [diff] [blame] | 479 | if (const VANextInst *VAN = dyn_cast<VANextInst>(&*I)) |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 480 | getOrCreateCompactionTableSlot(VAN->getArgType()); |
| 481 | } |
| 482 | |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 483 | // Do the types in the symbol table |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 484 | const SymbolTable &ST = F->getSymbolTable(); |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 485 | for (SymbolTable::type_const_iterator TI = ST.type_begin(), |
| 486 | TE = ST.type_end(); TI != TE; ++TI) |
| 487 | getOrCreateCompactionTableSlot(TI->second); |
| 488 | |
| 489 | // Now do the constants and global values |
| 490 | for (SymbolTable::plane_const_iterator PI = ST.plane_begin(), |
| 491 | PE = ST.plane_end(); PI != PE; ++PI) |
| 492 | for (SymbolTable::value_const_iterator VI = PI->second.begin(), |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 493 | VE = PI->second.end(); VI != VE; ++VI) |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 494 | if (isa<Constant>(VI->second) || isa<GlobalValue>(VI->second)) |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 495 | getOrCreateCompactionTableSlot(VI->second); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 496 | |
| 497 | // Now that we have all of the values in the table, and know what types are |
| 498 | // referenced, make sure that there is at least the zero initializer in any |
| 499 | // used type plane. Since the type was used, we will be emitting instructions |
| 500 | // to the plane even if there are no constants in it. |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 501 | CompactionTable.resize(CompactionTypes.size()); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 502 | for (unsigned i = 0, e = CompactionTable.size(); i != e; ++i) |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 503 | if (CompactionTable[i].empty() && (i != Type::VoidTyID) && |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 504 | i != Type::LabelTyID) { |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 505 | const Type *Ty = CompactionTypes[i]; |
| 506 | SC_DEBUG("Getting Null Value #" << i << " for Type " << Ty << "\n"); |
| 507 | assert(Ty->getTypeID() != Type::VoidTyID); |
| 508 | assert(Ty->getTypeID() != Type::LabelTyID); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 509 | getOrCreateCompactionTableSlot(Constant::getNullValue(Ty)); |
| 510 | } |
| 511 | |
| 512 | // Okay, now at this point, we have a legal compaction table. Since we want |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 513 | // to emit the smallest possible binaries, do not compactify the type plane if |
| 514 | // it will not save us anything. Because we have not yet incorporated the |
| 515 | // function body itself yet, we don't know whether or not it's a good idea to |
| 516 | // compactify other planes. We will defer this decision until later. |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 517 | TypeList &GlobalTypes = Types; |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 518 | |
| 519 | // All of the values types will be scrunched to the start of the types plane |
| 520 | // of the global table. Figure out just how many there are. |
| 521 | assert(!GlobalTypes.empty() && "No global types???"); |
| 522 | unsigned NumFCTypes = GlobalTypes.size()-1; |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 523 | while (!GlobalTypes[NumFCTypes]->isFirstClassType()) |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 524 | --NumFCTypes; |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 525 | |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 526 | // If there are fewer that 64 types, no instructions will be exploded due to |
| 527 | // the size of the type operands. Thus there is no need to compactify types. |
| 528 | // Also, if the compaction table contains most of the entries in the global |
| 529 | // table, there really is no reason to compactify either. |
| 530 | if (NumFCTypes < 64) { |
| 531 | // Decompactifying types is tricky, because we have to move type planes all |
| 532 | // over the place. At least we don't need to worry about updating the |
| 533 | // CompactionNodeMap for non-types though. |
| 534 | std::vector<TypePlane> TmpCompactionTable; |
| 535 | std::swap(CompactionTable, TmpCompactionTable); |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 536 | TypeList TmpTypes; |
| 537 | std::swap(TmpTypes, CompactionTypes); |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 538 | |
| 539 | // Move each plane back over to the uncompactified plane |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 540 | while (!TmpTypes.empty()) { |
| 541 | const Type *Ty = TmpTypes.back(); |
| 542 | TmpTypes.pop_back(); |
| 543 | CompactionTypeMap.erase(Ty); // Decompactify type! |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 544 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 545 | // Find the global slot number for this type. |
| 546 | int TySlot = getSlot(Ty); |
| 547 | assert(TySlot != -1 && "Type doesn't exist in global table?"); |
| 548 | |
| 549 | // Now we know where to put the compaction table plane. |
| 550 | if (CompactionTable.size() <= unsigned(TySlot)) |
| 551 | CompactionTable.resize(TySlot+1); |
| 552 | // Move the plane back into the compaction table. |
| 553 | std::swap(CompactionTable[TySlot], TmpCompactionTable[TmpTypes.size()]); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 554 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 555 | // And remove the empty plane we just moved in. |
| 556 | TmpCompactionTable.pop_back(); |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 557 | } |
| 558 | } |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 561 | |
| 562 | /// pruneCompactionTable - Once the entire function being processed has been |
| 563 | /// incorporated into the current compaction table, look over the compaction |
| 564 | /// table and check to see if there are any values whose compaction will not |
| 565 | /// save us any space in the bytecode file. If compactifying these values |
| 566 | /// serves no purpose, then we might as well not even emit the compactification |
| 567 | /// information to the bytecode file, saving a bit more space. |
| 568 | /// |
| 569 | /// Note that the type plane has already been compactified if possible. |
| 570 | /// |
| 571 | void SlotCalculator::pruneCompactionTable() { |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 572 | TypeList &TyPlane = CompactionTypes; |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 573 | for (unsigned ctp = 0, e = CompactionTable.size(); ctp != e; ++ctp) |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 574 | if (!CompactionTable[ctp].empty()) { |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 575 | TypePlane &CPlane = CompactionTable[ctp]; |
| 576 | unsigned GlobalSlot = ctp; |
| 577 | if (!TyPlane.empty()) |
| 578 | GlobalSlot = getGlobalSlot(TyPlane[ctp]); |
| 579 | |
| 580 | if (GlobalSlot >= Table.size()) |
| 581 | Table.resize(GlobalSlot+1); |
| 582 | TypePlane &GPlane = Table[GlobalSlot]; |
| 583 | |
| 584 | unsigned ModLevel = getModuleLevel(ctp); |
| 585 | unsigned NumFunctionObjs = CPlane.size()-ModLevel; |
| 586 | |
| 587 | // If the maximum index required if all entries in this plane were merged |
| 588 | // into the global plane is less than 64, go ahead and eliminate the |
| 589 | // plane. |
| 590 | bool PrunePlane = GPlane.size() + NumFunctionObjs < 64; |
| 591 | |
| 592 | // If there are no function-local values defined, and the maximum |
| 593 | // referenced global entry is less than 64, we don't need to compactify. |
| 594 | if (!PrunePlane && NumFunctionObjs == 0) { |
| 595 | unsigned MaxIdx = 0; |
| 596 | for (unsigned i = 0; i != ModLevel; ++i) { |
| 597 | unsigned Idx = NodeMap[CPlane[i]]; |
| 598 | if (Idx > MaxIdx) MaxIdx = Idx; |
| 599 | } |
| 600 | PrunePlane = MaxIdx < 64; |
| 601 | } |
| 602 | |
| 603 | // Ok, finally, if we decided to prune this plane out of the compaction |
| 604 | // table, do so now. |
| 605 | if (PrunePlane) { |
| 606 | TypePlane OldPlane; |
| 607 | std::swap(OldPlane, CPlane); |
| 608 | |
| 609 | // Loop over the function local objects, relocating them to the global |
| 610 | // table plane. |
| 611 | for (unsigned i = ModLevel, e = OldPlane.size(); i != e; ++i) { |
| 612 | const Value *V = OldPlane[i]; |
| 613 | CompactionNodeMap.erase(V); |
| 614 | assert(NodeMap.count(V) == 0 && "Value already in table??"); |
| 615 | getOrCreateSlot(V); |
| 616 | } |
| 617 | |
| 618 | // For compactified global values, just remove them from the compaction |
| 619 | // node map. |
| 620 | for (unsigned i = 0; i != ModLevel; ++i) |
| 621 | CompactionNodeMap.erase(OldPlane[i]); |
| 622 | |
| 623 | // Update the new modulelevel for this plane. |
| 624 | assert(ctp < ModuleLevel.size() && "Cannot set modulelevel!"); |
| 625 | ModuleLevel[ctp] = GPlane.size()-NumFunctionObjs; |
| 626 | assert((int)ModuleLevel[ctp] >= 0 && "Bad computation!"); |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
Chris Lattner | 8c202cd | 2004-01-15 18:47:15 +0000 | [diff] [blame] | 631 | int SlotCalculator::getSlot(const Value *V) const { |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 632 | // If there is a CompactionTable active... |
| 633 | if (!CompactionNodeMap.empty()) { |
| 634 | std::map<const Value*, unsigned>::const_iterator I = |
| 635 | CompactionNodeMap.find(V); |
| 636 | if (I != CompactionNodeMap.end()) |
| 637 | return (int)I->second; |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 638 | // Otherwise, if it's not in the compaction table, it must be in a |
| 639 | // non-compactified plane. |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Chris Lattner | 8c202cd | 2004-01-15 18:47:15 +0000 | [diff] [blame] | 642 | std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(V); |
| 643 | if (I != NodeMap.end()) |
| 644 | return (int)I->second; |
| 645 | |
| 646 | // Do not number ConstantPointerRef's at all. They are an abomination. |
| 647 | if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V)) |
| 648 | return getSlot(CPR->getValue()); |
| 649 | |
| 650 | return -1; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 653 | int SlotCalculator::getSlot(const Type*T) const { |
| 654 | // If there is a CompactionTable active... |
| 655 | if (!CompactionTypeMap.empty()) { |
| 656 | std::map<const Type*, unsigned>::const_iterator I = |
| 657 | CompactionTypeMap.find(T); |
| 658 | if (I != CompactionTypeMap.end()) |
| 659 | return (int)I->second; |
| 660 | // Otherwise, if it's not in the compaction table, it must be in a |
| 661 | // non-compactified plane. |
| 662 | } |
| 663 | |
| 664 | std::map<const Type*, unsigned>::const_iterator I = TypeMap.find(T); |
| 665 | if (I != TypeMap.end()) |
| 666 | return (int)I->second; |
| 667 | |
| 668 | return -1; |
| 669 | } |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 670 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 671 | int SlotCalculator::getOrCreateSlot(const Value *V) { |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 672 | if (V->getType() == Type::VoidTy) return -1; |
| 673 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 674 | int SlotNo = getSlot(V); // Check to see if it's already in! |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 675 | if (SlotNo != -1) return SlotNo; |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 676 | |
Chris Lattner | 8c202cd | 2004-01-15 18:47:15 +0000 | [diff] [blame] | 677 | // Do not number ConstantPointerRef's at all. They are an abomination. |
| 678 | if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V)) |
| 679 | return getOrCreateSlot(CPR->getValue()); |
| 680 | |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 681 | if (!isa<GlobalValue>(V)) // Initializers for globals are handled explicitly |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 682 | if (const Constant *C = dyn_cast<Constant>(V)) { |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 683 | assert(CompactionNodeMap.empty() && |
| 684 | "All needed constants should be in the compaction map already!"); |
| 685 | |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 686 | // Do not index the characters that make up constant strings. We emit |
| 687 | // constant strings as special entities that don't require their |
| 688 | // individual characters to be emitted. |
| 689 | if (!isa<ConstantArray>(C) || !cast<ConstantArray>(C)->isString()) { |
Chris Lattner | dcea630 | 2004-01-14 23:34:39 +0000 | [diff] [blame] | 690 | // This makes sure that if a constant has uses (for example an array of |
| 691 | // const ints), that they are inserted also. |
| 692 | // |
| 693 | for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); |
| 694 | I != E; ++I) |
| 695 | getOrCreateSlot(*I); |
| 696 | } else { |
| 697 | assert(ModuleLevel.empty() && |
| 698 | "How can a constant string be directly accessed in a function?"); |
| 699 | // Otherwise, if we are emitting a bytecode file and this IS a string, |
| 700 | // remember it. |
| 701 | if (!C->isNullValue()) |
| 702 | ConstantStrings.push_back(cast<ConstantArray>(C)); |
| 703 | } |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 706 | return insertValue(V); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 709 | int SlotCalculator::getOrCreateSlot(const Type* T) { |
| 710 | int SlotNo = getSlot(T); // Check to see if it's already in! |
| 711 | if (SlotNo != -1) return SlotNo; |
| 712 | return insertType(T); |
| 713 | } |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 714 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 715 | int SlotCalculator::insertValue(const Value *D, bool dontIgnore) { |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 716 | assert(D && "Can't insert a null value!"); |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 717 | assert(getSlot(D) == -1 && "Value is already in the table!"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 718 | |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 719 | // If we are building a compaction map, and if this plane is being compacted, |
| 720 | // insert the value into the compaction map, not into the global map. |
| 721 | if (!CompactionNodeMap.empty()) { |
| 722 | if (D->getType() == Type::VoidTy) return -1; // Do not insert void values |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 723 | assert(!isa<Constant>(D) && !isa<GlobalValue>(D) && |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 724 | "Types, constants, and globals should be in global SymTab!"); |
| 725 | |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 726 | int Plane = getSlot(D->getType()); |
| 727 | assert(Plane != -1 && CompactionTable.size() > (unsigned)Plane && |
| 728 | "Didn't find value type!"); |
| 729 | if (!CompactionTable[Plane].empty()) |
| 730 | return getOrCreateCompactionTableSlot(D); |
Chris Lattner | 614cdcd | 2004-01-18 21:07:07 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 733 | // If this node does not contribute to a plane, or if the node has a |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 734 | // name and we don't want names, then ignore the silly node... Note that types |
| 735 | // do need slot numbers so that we can keep track of where other values land. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 736 | // |
Chris Lattner | 9b50c15 | 2001-07-26 16:28:37 +0000 | [diff] [blame] | 737 | if (!dontIgnore) // Don't ignore nonignorables! |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 738 | if (D->getType() == Type::VoidTy ) { // Ignore void type nodes |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 739 | SC_DEBUG("ignored value " << *D << "\n"); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 740 | return -1; // We do need types unconditionally though |
| 741 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 742 | |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 743 | // Okay, everything is happy, actually insert the silly value now... |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 744 | return doInsertValue(D); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 747 | int SlotCalculator::insertType(const Type *Ty, bool dontIgnore) { |
| 748 | assert(Ty && "Can't insert a null type!"); |
| 749 | assert(getSlot(Ty) == -1 && "Type is already in the table!"); |
| 750 | |
| 751 | // If we are building a compaction map, and if this plane is being compacted, |
| 752 | // insert the value into the compaction map, not into the global map. |
| 753 | if (!CompactionTypeMap.empty()) { |
| 754 | getOrCreateCompactionTableSlot(Ty); |
| 755 | } |
| 756 | |
| 757 | // Insert the current type before any subtypes. This is important because |
| 758 | // recursive types elements are inserted in a bottom up order. Changing |
| 759 | // this here can break things. For example: |
| 760 | // |
| 761 | // global { \2 * } { { \2 }* null } |
| 762 | // |
| 763 | int ResultSlot = doInsertType(Ty); |
| 764 | SC_DEBUG(" Inserted type: " << Ty->getDescription() << " slot=" << |
| 765 | ResultSlot << "\n"); |
| 766 | |
| 767 | // Loop over any contained types in the definition... in post |
| 768 | // order. |
| 769 | for (po_iterator<const Type*> I = po_begin(Ty), E = po_end(Ty); |
| 770 | I != E; ++I) { |
| 771 | if (*I != Ty) { |
| 772 | const Type *SubTy = *I; |
| 773 | // If we haven't seen this sub type before, add it to our type table! |
| 774 | if (getSlot(SubTy) == -1) { |
| 775 | SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << "\n"); |
| 776 | int Slot = doInsertType(SubTy); |
| 777 | SC_DEBUG(" Inserted subtype: " << SubTy->getDescription() << |
| 778 | " slot=" << Slot << "\n"); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | return ResultSlot; |
| 783 | } |
| 784 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 785 | // doInsertValue - This is a small helper function to be called only |
| 786 | // be insertValue. |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 787 | // |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 788 | int SlotCalculator::doInsertValue(const Value *D) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 789 | const Type *Typ = D->getType(); |
Chris Lattner | 9b50c15 | 2001-07-26 16:28:37 +0000 | [diff] [blame] | 790 | unsigned Ty; |
| 791 | |
| 792 | // Used for debugging DefSlot=-1 assertion... |
| 793 | //if (Typ == Type::TypeTy) |
Chris Lattner | cfe26c9 | 2001-10-01 18:26:53 +0000 | [diff] [blame] | 794 | // cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n"; |
Chris Lattner | 9b50c15 | 2001-07-26 16:28:37 +0000 | [diff] [blame] | 795 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 796 | if (Typ->isDerivedType()) { |
Chris Lattner | 68e3dbc | 2004-01-20 00:57:32 +0000 | [diff] [blame] | 797 | int ValSlot; |
| 798 | if (CompactionTable.empty()) |
| 799 | ValSlot = getSlot(Typ); |
| 800 | else |
| 801 | ValSlot = getGlobalSlot(Typ); |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 802 | if (ValSlot == -1) { // Have we already entered this type? |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 803 | // Nope, this is the first we have seen the type, process it. |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 804 | ValSlot = insertType(Typ, true); |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 805 | assert(ValSlot != -1 && "ProcessType returned -1 for a type?"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 806 | } |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 807 | Ty = (unsigned)ValSlot; |
Chris Lattner | 9b50c15 | 2001-07-26 16:28:37 +0000 | [diff] [blame] | 808 | } else { |
Chris Lattner | f70c22b | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 809 | Ty = Typ->getTypeID(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | if (Table.size() <= Ty) // Make sure we have the type plane allocated... |
| 813 | Table.resize(Ty+1, TypePlane()); |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 814 | |
| 815 | // If this is the first value to get inserted into the type plane, make sure |
| 816 | // to insert the implicit null value... |
Reid Spencer | 798ff64 | 2004-05-26 07:37:11 +0000 | [diff] [blame] | 817 | if (Table[Ty].empty() && hasNullValue(Ty)) { |
Chris Lattner | 3413d15 | 2003-03-19 20:57:22 +0000 | [diff] [blame] | 818 | Value *ZeroInitializer = Constant::getNullValue(Typ); |
| 819 | |
| 820 | // If we are pushing zeroinit, it will be handled below. |
| 821 | if (D != ZeroInitializer) { |
| 822 | Table[Ty].push_back(ZeroInitializer); |
| 823 | NodeMap[ZeroInitializer] = 0; |
| 824 | } |
| 825 | } |
| 826 | |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 827 | // Insert node into table and NodeMap... |
| 828 | unsigned DestSlot = NodeMap[D] = Table[Ty].size(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 829 | Table[Ty].push_back(D); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 830 | |
Chris Lattner | f1fef65 | 2001-10-13 06:35:09 +0000 | [diff] [blame] | 831 | SC_DEBUG(" Inserting value [" << Ty << "] = " << D << " slot=" << |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 832 | DestSlot << " ["); |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 833 | // G = Global, C = Constant, T = Type, F = Function, o = other |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 834 | SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" : |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 835 | (isa<Function>(D) ? "F" : "o")))); |
Chris Lattner | f1fef65 | 2001-10-13 06:35:09 +0000 | [diff] [blame] | 836 | SC_DEBUG("]\n"); |
Chris Lattner | 9a29790 | 2001-09-07 16:31:52 +0000 | [diff] [blame] | 837 | return (int)DestSlot; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 838 | } |
Reid Spencer | 24ab28f | 2004-07-04 11:42:49 +0000 | [diff] [blame] | 839 | |
| 840 | // doInsertType - This is a small helper function to be called only |
| 841 | // be insertType. |
| 842 | // |
| 843 | int SlotCalculator::doInsertType(const Type *Ty) { |
| 844 | |
| 845 | // Insert node into table and NodeMap... |
| 846 | unsigned DestSlot = TypeMap[Ty] = Types.size(); |
| 847 | Types.push_back(Ty); |
| 848 | |
| 849 | SC_DEBUG(" Inserting type [" << DestSlot << "] = " << Ty << "\n" ); |
| 850 | return (int)DestSlot; |
| 851 | } |
| 852 | |
| 853 | // vim: sw=2 ai |