blob: 3408982c8d5fd11027160972c5645074eaaad02f [file] [log] [blame]
Chris Lattnercf3056d2003-10-13 03:32:08 +00001//===-- SlotCalculator.cpp - Calculate what slots values land in ----------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
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 Lattner00950542001-06-06 20:29:01 +00009//
Chris Lattner68e3dbc2004-01-20 00:57:32 +000010// 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 Lattner00950542001-06-06 20:29:01 +000012//
Chris Lattner68e3dbc2004-01-20 00:57:32 +000013// This is used when writing a file to disk, either in bytecode or assembly.
Chris Lattner00950542001-06-06 20:29:01 +000014//
15//===----------------------------------------------------------------------===//
16
Chris Lattnerf2d577b2004-01-20 19:50:34 +000017#include "llvm/Analysis/SlotCalculator.h"
Chris Lattnerdcea6302004-01-14 23:34:39 +000018#include "llvm/Constants.h"
Chris Lattner00950542001-06-06 20:29:01 +000019#include "llvm/DerivedTypes.h"
Chris Lattnerdcea6302004-01-14 23:34:39 +000020#include "llvm/iOther.h"
21#include "llvm/Module.h"
Chris Lattner9a297902001-09-07 16:31:52 +000022#include "llvm/SymbolTable.h"
Chris Lattnerf2d577b2004-01-20 19:50:34 +000023#include "llvm/Analysis/ConstantsScanner.h"
Alkis Evlogimenos088eb452003-10-31 03:02:34 +000024#include "Support/PostOrderIterator.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000025#include "Support/STLExtras.h"
Chris Lattner9a297902001-09-07 16:31:52 +000026#include <algorithm>
Chris Lattner31f84992003-11-21 20:23:48 +000027using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000028
Chris Lattner9a297902001-09-07 16:31:52 +000029#if 0
Chris Lattner3413d152003-03-19 20:57:22 +000030#define SC_DEBUG(X) std::cerr << X
Chris Lattner9a297902001-09-07 16:31:52 +000031#else
32#define SC_DEBUG(X)
33#endif
Chris Lattner00950542001-06-06 20:29:01 +000034
Reid Spencer798ff642004-05-26 07:37:11 +000035SlotCalculator::SlotCalculator(const Module *M ) {
Chris Lattner614cdcd2004-01-18 21:07:07 +000036 ModuleContainsAllFunctionConstants = false;
Chris Lattner00950542001-06-06 20:29:01 +000037 TheModule = M;
38
39 // Preload table... Make sure that all of the primitive types are in the table
40 // and that their Primitive ID is equal to their slot #
41 //
Alkis Evlogimenos5d1bdcd2003-10-29 03:12:12 +000042 SC_DEBUG("Inserting primitive types:\n");
Chris Lattner00950542001-06-06 20:29:01 +000043 for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
44 assert(Type::getPrimitiveType((Type::PrimitiveID)i));
Alkis Evlogimenos60596382003-10-17 02:02:40 +000045 insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
Chris Lattner00950542001-06-06 20:29:01 +000046 }
47
48 if (M == 0) return; // Empty table...
Chris Lattner9a297902001-09-07 16:31:52 +000049 processModule();
Chris Lattner00950542001-06-06 20:29:01 +000050}
51
Reid Spencer798ff642004-05-26 07:37:11 +000052SlotCalculator::SlotCalculator(const Function *M ) {
Chris Lattner614cdcd2004-01-18 21:07:07 +000053 ModuleContainsAllFunctionConstants = false;
Chris Lattner00950542001-06-06 20:29:01 +000054 TheModule = M ? M->getParent() : 0;
55
56 // Preload table... Make sure that all of the primitive types are in the table
57 // and that their Primitive ID is equal to their slot #
58 //
Alkis Evlogimenos5d1bdcd2003-10-29 03:12:12 +000059 SC_DEBUG("Inserting primitive types:\n");
Chris Lattner00950542001-06-06 20:29:01 +000060 for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
61 assert(Type::getPrimitiveType((Type::PrimitiveID)i));
Alkis Evlogimenos60596382003-10-17 02:02:40 +000062 insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
Chris Lattner00950542001-06-06 20:29:01 +000063 }
64
65 if (TheModule == 0) return; // Empty table...
66
Chris Lattner9a297902001-09-07 16:31:52 +000067 processModule(); // Process module level stuff
Chris Lattner68e3dbc2004-01-20 00:57:32 +000068 incorporateFunction(M); // Start out in incorporated state
Chris Lattner00950542001-06-06 20:29:01 +000069}
70
Chris Lattner614cdcd2004-01-18 21:07:07 +000071unsigned SlotCalculator::getGlobalSlot(const Value *V) const {
72 assert(!CompactionTable.empty() &&
73 "This method can only be used when compaction is enabled!");
74 if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V))
75 V = CPR->getValue();
76 std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(V);
Chris Lattner68e3dbc2004-01-20 00:57:32 +000077 assert(I != NodeMap.end() && "Didn't find global slot entry!");
Chris Lattner614cdcd2004-01-18 21:07:07 +000078 return I->second;
79}
80
Chris Lattner68e3dbc2004-01-20 00:57:32 +000081SlotCalculator::TypePlane &SlotCalculator::getPlane(unsigned Plane) {
82 unsigned PIdx = Plane;
83 if (CompactionTable.empty()) { // No compaction table active?
84 // fall out
85 } else if (!CompactionTable[Plane].empty()) { // Compaction table active.
86 assert(Plane < CompactionTable.size());
87 return CompactionTable[Plane];
88 } else {
89 // Final case: compaction table active, but this plane is not
90 // compactified. If the type plane is compactified, unmap back to the
91 // global type plane corresponding to "Plane".
92 if (!CompactionTable[Type::TypeTyID].empty()) {
93 const Type *Ty = cast<Type>(CompactionTable[Type::TypeTyID][Plane]);
94 std::map<const Value*, unsigned>::iterator It = NodeMap.find(Ty);
95 assert(It != NodeMap.end() && "Type not in global constant map?");
96 PIdx = It->second;
97 }
98 }
99
100 // Okay we are just returning an entry out of the main Table. Make sure the
101 // plane exists and return it.
102 if (PIdx >= Table.size())
103 Table.resize(PIdx+1);
104 return Table[PIdx];
105}
Chris Lattner614cdcd2004-01-18 21:07:07 +0000106
Chris Lattner9a297902001-09-07 16:31:52 +0000107
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000108// processModule - Process all of the module level function declarations and
Chris Lattner9a297902001-09-07 16:31:52 +0000109// types that are available.
110//
111void SlotCalculator::processModule() {
112 SC_DEBUG("begin processModule!\n");
Chris Lattner70cc3392001-09-10 07:58:01 +0000113
Chris Lattner3413d152003-03-19 20:57:22 +0000114 // Add all of the global variables to the value table...
Chris Lattnerf1fef652001-10-13 06:35:09 +0000115 //
116 for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
Chris Lattner479b54b2002-10-14 00:48:57 +0000117 I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000118 getOrCreateSlot(I);
Chris Lattner70cc3392001-09-10 07:58:01 +0000119
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000120 // Scavenge the types out of the functions, then add the functions themselves
121 // to the value table...
Chris Lattner9a297902001-09-07 16:31:52 +0000122 //
Chris Lattner3413d152003-03-19 20:57:22 +0000123 for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
124 I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000125 getOrCreateSlot(I);
Chris Lattner9a297902001-09-07 16:31:52 +0000126
Chris Lattner3413d152003-03-19 20:57:22 +0000127 // Add all of the module level constants used as initializers
128 //
129 for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
130 I != E; ++I)
131 if (I->hasInitializer())
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000132 getOrCreateSlot(I->getInitializer());
Chris Lattner3413d152003-03-19 20:57:22 +0000133
Chris Lattnerdcea6302004-01-14 23:34:39 +0000134 // Now that all global constants have been added, rearrange constant planes
135 // that contain constant strings so that the strings occur at the start of the
136 // plane, not somewhere in the middle.
137 //
Reid Spencer798ff642004-05-26 07:37:11 +0000138 TypePlane &Types = Table[Type::TypeTyID];
139 for (unsigned plane = 0, e = Table.size(); plane != e; ++plane) {
140 if (const ArrayType *AT = dyn_cast<ArrayType>(Types[plane]))
141 if (AT->getElementType() == Type::SByteTy ||
142 AT->getElementType() == Type::UByteTy) {
143 TypePlane &Plane = Table[plane];
144 unsigned FirstNonStringID = 0;
145 for (unsigned i = 0, e = Plane.size(); i != e; ++i)
146 if (isa<ConstantAggregateZero>(Plane[i]) ||
147 cast<ConstantArray>(Plane[i])->isString()) {
148 // Check to see if we have to shuffle this string around. If not,
149 // don't do anything.
150 if (i != FirstNonStringID) {
151 // Swap the plane entries....
152 std::swap(Plane[i], Plane[FirstNonStringID]);
153
154 // Keep the NodeMap up to date.
155 NodeMap[Plane[i]] = i;
156 NodeMap[Plane[FirstNonStringID]] = FirstNonStringID;
157 }
158 ++FirstNonStringID;
159 }
160 }
Chris Lattnerdcea6302004-01-14 23:34:39 +0000161 }
162
Chris Lattnera14b0d42004-01-10 23:46:13 +0000163 // If we are emitting a bytecode file, scan all of the functions for their
164 // constants, which allows us to emit more compact modules. This is optional,
165 // and is just used to compactify the constants used by different functions
166 // together.
Chris Lattner614cdcd2004-01-18 21:07:07 +0000167 //
168 // This functionality is completely optional for the bytecode writer, but
169 // tends to produce smaller bytecode files. This should not be used in the
170 // future by clients that want to, for example, build and emit functions on
171 // the fly. For now, however, it is unconditionally enabled when building
172 // bytecode information.
173 //
Reid Spencer798ff642004-05-26 07:37:11 +0000174 ModuleContainsAllFunctionConstants = true;
Chris Lattner614cdcd2004-01-18 21:07:07 +0000175
Reid Spencer798ff642004-05-26 07:37:11 +0000176 SC_DEBUG("Inserting function constants:\n");
177 for (Module::const_iterator F = TheModule->begin(), E = TheModule->end();
178 F != E; ++F) {
179 for (const_inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
180 for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op)
181 if (isa<Constant>(I->getOperand(op)))
182 getOrCreateSlot(I->getOperand(op));
183 getOrCreateSlot(I->getType());
184 if (const VANextInst *VAN = dyn_cast<VANextInst>(&*I))
185 getOrCreateSlot(VAN->getArgType());
Chris Lattner614cdcd2004-01-18 21:07:07 +0000186 }
Reid Spencer798ff642004-05-26 07:37:11 +0000187 processSymbolTableConstants(&F->getSymbolTable());
Chris Lattnera14b0d42004-01-10 23:46:13 +0000188 }
Chris Lattnera14b0d42004-01-10 23:46:13 +0000189
Chris Lattner70cc3392001-09-10 07:58:01 +0000190 // Insert constants that are named at module level into the slot pool so that
191 // the module symbol table can refer to them...
Reid Spencer798ff642004-05-26 07:37:11 +0000192 SC_DEBUG("Inserting SymbolTable values:\n");
193 processSymbolTable(&TheModule->getSymbolTable());
Chris Lattner9a297902001-09-07 16:31:52 +0000194
Chris Lattnera14b0d42004-01-10 23:46:13 +0000195 // Now that we have collected together all of the information relevant to the
196 // module, compactify the type table if it is particularly big and outputting
197 // a bytecode file. The basic problem we run into is that some programs have
198 // a large number of types, which causes the type field to overflow its size,
199 // which causes instructions to explode in size (particularly call
200 // instructions). To avoid this behavior, we "sort" the type table so that
201 // all non-value types are pushed to the end of the type table, giving nice
202 // low numbers to the types that can be used by instructions, thus reducing
203 // the amount of explodage we suffer.
Reid Spencer798ff642004-05-26 07:37:11 +0000204 if (Table[Type::TypeTyID].size() >= 64) {
Chris Lattnera14b0d42004-01-10 23:46:13 +0000205 // Scan through the type table moving value types to the start of the table.
Chris Lattner93802972004-01-11 23:29:26 +0000206 TypePlane *Types = &Table[Type::TypeTyID];
Chris Lattnera14b0d42004-01-10 23:46:13 +0000207 unsigned FirstNonValueTypeID = 0;
Chris Lattner93802972004-01-11 23:29:26 +0000208 for (unsigned i = 0, e = Types->size(); i != e; ++i)
209 if (cast<Type>((*Types)[i])->isFirstClassType() ||
210 cast<Type>((*Types)[i])->isPrimitiveType()) {
Chris Lattnera14b0d42004-01-10 23:46:13 +0000211 // Check to see if we have to shuffle this type around. If not, don't
212 // do anything.
213 if (i != FirstNonValueTypeID) {
Chris Lattner93802972004-01-11 23:29:26 +0000214 assert(i != Type::TypeTyID && FirstNonValueTypeID != Type::TypeTyID &&
215 "Cannot move around the type plane!");
216
Chris Lattnera14b0d42004-01-10 23:46:13 +0000217 // Swap the type ID's.
Chris Lattner93802972004-01-11 23:29:26 +0000218 std::swap((*Types)[i], (*Types)[FirstNonValueTypeID]);
Chris Lattnera14b0d42004-01-10 23:46:13 +0000219
220 // Keep the NodeMap up to date.
Chris Lattner93802972004-01-11 23:29:26 +0000221 NodeMap[(*Types)[i]] = i;
222 NodeMap[(*Types)[FirstNonValueTypeID]] = FirstNonValueTypeID;
Chris Lattnera14b0d42004-01-10 23:46:13 +0000223
224 // When we move a type, make sure to move its value plane as needed.
Chris Lattner93802972004-01-11 23:29:26 +0000225 if (Table.size() > FirstNonValueTypeID) {
226 if (Table.size() <= i) Table.resize(i+1);
227 std::swap(Table[i], Table[FirstNonValueTypeID]);
228 Types = &Table[Type::TypeTyID];
229 }
Chris Lattnera14b0d42004-01-10 23:46:13 +0000230 }
231 ++FirstNonValueTypeID;
232 }
233 }
234
Chris Lattner9a297902001-09-07 16:31:52 +0000235 SC_DEBUG("end processModule!\n");
236}
237
238// processSymbolTable - Insert all of the values in the specified symbol table
239// into the values table...
240//
241void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
Reid Spencer9231ac82004-05-25 08:53:40 +0000242 // Do the types first.
243 for (SymbolTable::type_const_iterator TI = ST->type_begin(),
244 TE = ST->type_end(); TI != TE; ++TI )
245 getOrCreateSlot(TI->second);
246
247 // Now do the values.
248 for (SymbolTable::plane_const_iterator PI = ST->plane_begin(),
249 PE = ST->plane_end(); PI != PE; ++PI)
250 for (SymbolTable::value_const_iterator VI = PI->second.begin(),
251 VE = PI->second.end(); VI != VE; ++VI)
252 getOrCreateSlot(VI->second);
Chris Lattner9a297902001-09-07 16:31:52 +0000253}
254
255void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
Reid Spencer9231ac82004-05-25 08:53:40 +0000256 // Do the types first
257 for (SymbolTable::type_const_iterator TI = ST->type_begin(),
258 TE = ST->type_end(); TI != TE; ++TI )
259 getOrCreateSlot(TI->second);
260
261 // Now do the constant values in all planes
262 for (SymbolTable::plane_const_iterator PI = ST->plane_begin(),
263 PE = ST->plane_end(); PI != PE; ++PI)
264 for (SymbolTable::value_const_iterator VI = PI->second.begin(),
265 VE = PI->second.end(); VI != VE; ++VI)
266 if (isa<Constant>(VI->second))
267 getOrCreateSlot(VI->second);
Chris Lattner9a297902001-09-07 16:31:52 +0000268}
269
270
Chris Lattnerce439b52003-10-20 19:10:06 +0000271void SlotCalculator::incorporateFunction(const Function *F) {
Chris Lattner00950542001-06-06 20:29:01 +0000272 assert(ModuleLevel.size() == 0 && "Module already incorporated!");
273
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000274 SC_DEBUG("begin processFunction!\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000275
Chris Lattner614cdcd2004-01-18 21:07:07 +0000276 // If we emitted all of the function constants, build a compaction table.
Reid Spencer798ff642004-05-26 07:37:11 +0000277 if ( ModuleContainsAllFunctionConstants)
Chris Lattner614cdcd2004-01-18 21:07:07 +0000278 buildCompactionTable(F);
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000279
280 // Update the ModuleLevel entries to be accurate.
281 ModuleLevel.resize(getNumPlanes());
282 for (unsigned i = 0, e = getNumPlanes(); i != e; ++i)
283 ModuleLevel[i] = getPlane(i).size();
Chris Lattner9a297902001-09-07 16:31:52 +0000284
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000285 // Iterate over function arguments, adding them to the value table...
Chris Lattnerce439b52003-10-20 19:10:06 +0000286 for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000287 getOrCreateSlot(I);
Chris Lattner9a297902001-09-07 16:31:52 +0000288
Reid Spencer798ff642004-05-26 07:37:11 +0000289 if ( !ModuleContainsAllFunctionConstants ) {
Chris Lattner614cdcd2004-01-18 21:07:07 +0000290 // Iterate over all of the instructions in the function, looking for
291 // constant values that are referenced. Add these to the value pools
292 // before any nonconstant values. This will be turned into the constant
293 // pool for the bytecode writer.
294 //
295
296 // Emit all of the constants that are being used by the instructions in
297 // the function...
Chris Lattnerce439b52003-10-20 19:10:06 +0000298 for_each(constant_begin(F), constant_end(F),
Chris Lattner614cdcd2004-01-18 21:07:07 +0000299 bind_obj(this, &SlotCalculator::getOrCreateSlot));
300
Chris Lattner9a297902001-09-07 16:31:52 +0000301 // If there is a symbol table, it is possible that the user has names for
302 // constants that are not being used. In this case, we will have problems
303 // if we don't emit the constants now, because otherwise we will get
Chris Lattnera14b0d42004-01-10 23:46:13 +0000304 // symbol table references to constants not in the output. Scan for these
Chris Lattner9a297902001-09-07 16:31:52 +0000305 // constants now.
306 //
Chris Lattnerce439b52003-10-20 19:10:06 +0000307 processSymbolTableConstants(&F->getSymbolTable());
Chris Lattner00950542001-06-06 20:29:01 +0000308 }
309
Chris Lattner9a297902001-09-07 16:31:52 +0000310 SC_DEBUG("Inserting Instructions:\n");
311
312 // Add all of the instructions to the type planes...
Chris Lattnerd5c59d52004-01-15 20:24:09 +0000313 for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
314 getOrCreateSlot(BB);
Chris Lattner389dbfb2003-10-21 17:39:59 +0000315 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
316 getOrCreateSlot(I);
Chris Lattner2765c412003-10-21 17:40:54 +0000317 if (const VANextInst *VAN = dyn_cast<VANextInst>(I))
318 getOrCreateSlot(VAN->getArgType());
Chris Lattner389dbfb2003-10-21 17:39:59 +0000319 }
Chris Lattner9a297902001-09-07 16:31:52 +0000320 }
321
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000322 // If we are building a compaction table, prune out planes that do not benefit
323 // from being compactified.
324 if (!CompactionTable.empty())
325 pruneCompactionTable();
326
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000327 SC_DEBUG("end processFunction!\n");
Chris Lattner00950542001-06-06 20:29:01 +0000328}
329
Chris Lattnerb5794002002-04-07 22:49:37 +0000330void SlotCalculator::purgeFunction() {
Chris Lattner00950542001-06-06 20:29:01 +0000331 assert(ModuleLevel.size() != 0 && "Module not incorporated!");
332 unsigned NumModuleTypes = ModuleLevel.size();
333
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000334 SC_DEBUG("begin purgeFunction!\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000335
Chris Lattner614cdcd2004-01-18 21:07:07 +0000336 // First, free the compaction map if used.
337 CompactionNodeMap.clear();
338
339 // Next, remove values from existing type planes
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000340 for (unsigned i = 0; i != NumModuleTypes; ++i) {
341 // Size of plane before function came
342 unsigned ModuleLev = getModuleLevel(i);
343 assert(int(ModuleLev) >= 0 && "BAD!");
344
345 TypePlane &Plane = getPlane(i);
346
347 assert(ModuleLev <= Plane.size() && "module levels higher than elements?");
348 while (Plane.size() != ModuleLev) {
349 assert(!isa<GlobalValue>(Plane.back()) &&
350 "Functions cannot define globals!");
351 NodeMap.erase(Plane.back()); // Erase from nodemap
352 Plane.pop_back(); // Shrink plane
Chris Lattner00950542001-06-06 20:29:01 +0000353 }
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000354 }
Chris Lattner00950542001-06-06 20:29:01 +0000355
356 // We don't need this state anymore, free it up.
357 ModuleLevel.clear();
358
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000359 // Finally, remove any type planes defined by the function...
Chris Lattner614cdcd2004-01-18 21:07:07 +0000360 if (!CompactionTable.empty()) {
361 CompactionTable.clear();
362 } else {
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000363 while (Table.size() > NumModuleTypes) {
Chris Lattner614cdcd2004-01-18 21:07:07 +0000364 TypePlane &Plane = Table.back();
365 SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size "
366 << Plane.size() << "\n");
367 while (Plane.size()) {
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000368 assert(!isa<GlobalValue>(Plane.back()) &&
369 "Functions cannot define globals!");
370 NodeMap.erase(Plane.back()); // Erase from nodemap
371 Plane.pop_back(); // Shrink plane
Chris Lattner614cdcd2004-01-18 21:07:07 +0000372 }
373
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000374 Table.pop_back(); // Nuke the plane, we don't like it.
Chris Lattner00950542001-06-06 20:29:01 +0000375 }
Chris Lattner00950542001-06-06 20:29:01 +0000376 }
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000377
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000378 SC_DEBUG("end purgeFunction!\n");
Chris Lattner00950542001-06-06 20:29:01 +0000379}
380
Chris Lattner614cdcd2004-01-18 21:07:07 +0000381static inline bool hasNullValue(unsigned TyID) {
382 return TyID != Type::LabelTyID && TyID != Type::TypeTyID &&
383 TyID != Type::VoidTyID;
384}
385
386/// getOrCreateCompactionTableSlot - This method is used to build up the initial
387/// approximation of the compaction table.
388unsigned SlotCalculator::getOrCreateCompactionTableSlot(const Value *V) {
Chris Lattner71151ae2004-02-09 00:15:41 +0000389 if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V))
390 V = CPR->getValue();
Chris Lattner614cdcd2004-01-18 21:07:07 +0000391 std::map<const Value*, unsigned>::iterator I =
392 CompactionNodeMap.lower_bound(V);
393 if (I != CompactionNodeMap.end() && I->first == V)
394 return I->second; // Already exists?
395
396 // Make sure the type is in the table.
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000397 unsigned Ty;
398 if (!CompactionTable[Type::TypeTyID].empty())
399 Ty = getOrCreateCompactionTableSlot(V->getType());
400 else // If the type plane was decompactified, use the global plane ID
401 Ty = getSlot(V->getType());
Chris Lattner614cdcd2004-01-18 21:07:07 +0000402 if (CompactionTable.size() <= Ty)
403 CompactionTable.resize(Ty+1);
404
405 assert(!isa<Type>(V) || ModuleLevel.empty());
406
407 TypePlane &TyPlane = CompactionTable[Ty];
408
409 // Make sure to insert the null entry if the thing we are inserting is not a
410 // null constant.
411 if (TyPlane.empty() && hasNullValue(V->getType()->getPrimitiveID())) {
412 Value *ZeroInitializer = Constant::getNullValue(V->getType());
413 if (V != ZeroInitializer) {
414 TyPlane.push_back(ZeroInitializer);
415 CompactionNodeMap[ZeroInitializer] = 0;
416 }
417 }
418
419 unsigned SlotNo = TyPlane.size();
420 TyPlane.push_back(V);
421 CompactionNodeMap.insert(std::make_pair(V, SlotNo));
422 return SlotNo;
423}
424
425
426/// buildCompactionTable - Since all of the function constants and types are
427/// stored in the module-level constant table, we don't need to emit a function
428/// constant table. Also due to this, the indices for various constants and
429/// types might be very large in large programs. In order to avoid blowing up
430/// the size of instructions in the bytecode encoding, we build a compaction
431/// table, which defines a mapping from function-local identifiers to global
432/// identifiers.
433void SlotCalculator::buildCompactionTable(const Function *F) {
434 assert(CompactionNodeMap.empty() && "Compaction table already built!");
435 // First step, insert the primitive types.
436 CompactionTable.resize(Type::TypeTyID+1);
437 for (unsigned i = 0; i != Type::FirstDerivedTyID; ++i) {
438 const Type *PrimTy = Type::getPrimitiveType((Type::PrimitiveID)i);
439 CompactionTable[Type::TypeTyID].push_back(PrimTy);
440 CompactionNodeMap[PrimTy] = i;
441 }
442
443 // Next, include any types used by function arguments.
444 for (Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
445 getOrCreateCompactionTableSlot(I->getType());
446
447 // Next, find all of the types and values that are referred to by the
448 // instructions in the program.
449 for (const_inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
450 getOrCreateCompactionTableSlot(I->getType());
451 for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op)
452 if (isa<Constant>(I->getOperand(op)) ||
453 isa<GlobalValue>(I->getOperand(op)))
454 getOrCreateCompactionTableSlot(I->getOperand(op));
Chris Lattner6ffe5512004-04-27 15:13:33 +0000455 if (const VANextInst *VAN = dyn_cast<VANextInst>(&*I))
Chris Lattner614cdcd2004-01-18 21:07:07 +0000456 getOrCreateCompactionTableSlot(VAN->getArgType());
457 }
458
Reid Spencer9231ac82004-05-25 08:53:40 +0000459 // Do the types in the symbol table
Chris Lattner614cdcd2004-01-18 21:07:07 +0000460 const SymbolTable &ST = F->getSymbolTable();
Reid Spencer9231ac82004-05-25 08:53:40 +0000461 for (SymbolTable::type_const_iterator TI = ST.type_begin(),
462 TE = ST.type_end(); TI != TE; ++TI)
463 getOrCreateCompactionTableSlot(TI->second);
464
465 // Now do the constants and global values
466 for (SymbolTable::plane_const_iterator PI = ST.plane_begin(),
467 PE = ST.plane_end(); PI != PE; ++PI)
468 for (SymbolTable::value_const_iterator VI = PI->second.begin(),
469 VE = PI->second.end(); VI != VE; ++VI)
470 if (isa<Constant>(VI->second) || isa<GlobalValue>(VI->second))
471 getOrCreateCompactionTableSlot(VI->second);
Chris Lattner614cdcd2004-01-18 21:07:07 +0000472
473 // Now that we have all of the values in the table, and know what types are
474 // referenced, make sure that there is at least the zero initializer in any
475 // used type plane. Since the type was used, we will be emitting instructions
476 // to the plane even if there are no constants in it.
477 CompactionTable.resize(CompactionTable[Type::TypeTyID].size());
478 for (unsigned i = 0, e = CompactionTable.size(); i != e; ++i)
479 if (CompactionTable[i].empty() && i != Type::VoidTyID &&
480 i != Type::LabelTyID) {
481 const Type *Ty = cast<Type>(CompactionTable[Type::TypeTyID][i]);
482 getOrCreateCompactionTableSlot(Constant::getNullValue(Ty));
483 }
484
485 // Okay, now at this point, we have a legal compaction table. Since we want
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000486 // to emit the smallest possible binaries, do not compactify the type plane if
487 // it will not save us anything. Because we have not yet incorporated the
488 // function body itself yet, we don't know whether or not it's a good idea to
489 // compactify other planes. We will defer this decision until later.
490 TypePlane &GlobalTypes = Table[Type::TypeTyID];
491
492 // All of the values types will be scrunched to the start of the types plane
493 // of the global table. Figure out just how many there are.
494 assert(!GlobalTypes.empty() && "No global types???");
495 unsigned NumFCTypes = GlobalTypes.size()-1;
496 while (!cast<Type>(GlobalTypes[NumFCTypes])->isFirstClassType())
497 --NumFCTypes;
Chris Lattner614cdcd2004-01-18 21:07:07 +0000498
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000499 // If there are fewer that 64 types, no instructions will be exploded due to
500 // the size of the type operands. Thus there is no need to compactify types.
501 // Also, if the compaction table contains most of the entries in the global
502 // table, there really is no reason to compactify either.
503 if (NumFCTypes < 64) {
504 // Decompactifying types is tricky, because we have to move type planes all
505 // over the place. At least we don't need to worry about updating the
506 // CompactionNodeMap for non-types though.
507 std::vector<TypePlane> TmpCompactionTable;
508 std::swap(CompactionTable, TmpCompactionTable);
509 TypePlane Types;
510 std::swap(Types, TmpCompactionTable[Type::TypeTyID]);
511
512 // Move each plane back over to the uncompactified plane
513 while (!Types.empty()) {
514 const Type *Ty = cast<Type>(Types.back());
515 Types.pop_back();
516 CompactionNodeMap.erase(Ty); // Decompactify type!
Chris Lattner614cdcd2004-01-18 21:07:07 +0000517
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000518 if (Ty != Type::TypeTy) {
519 // Find the global slot number for this type.
520 int TySlot = getSlot(Ty);
521 assert(TySlot != -1 && "Type doesn't exist in global table?");
522
523 // Now we know where to put the compaction table plane.
524 if (CompactionTable.size() <= unsigned(TySlot))
525 CompactionTable.resize(TySlot+1);
526 // Move the plane back into the compaction table.
527 std::swap(CompactionTable[TySlot], TmpCompactionTable[Types.size()]);
Chris Lattner614cdcd2004-01-18 21:07:07 +0000528
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000529 // And remove the empty plane we just moved in.
530 TmpCompactionTable.pop_back();
531 }
532 }
533 }
Chris Lattner614cdcd2004-01-18 21:07:07 +0000534}
535
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000536
537/// pruneCompactionTable - Once the entire function being processed has been
538/// incorporated into the current compaction table, look over the compaction
539/// table and check to see if there are any values whose compaction will not
540/// save us any space in the bytecode file. If compactifying these values
541/// serves no purpose, then we might as well not even emit the compactification
542/// information to the bytecode file, saving a bit more space.
543///
544/// Note that the type plane has already been compactified if possible.
545///
546void SlotCalculator::pruneCompactionTable() {
547 TypePlane &TyPlane = CompactionTable[Type::TypeTyID];
548 for (unsigned ctp = 0, e = CompactionTable.size(); ctp != e; ++ctp)
549 if (ctp != Type::TypeTyID && !CompactionTable[ctp].empty()) {
550 TypePlane &CPlane = CompactionTable[ctp];
551 unsigned GlobalSlot = ctp;
552 if (!TyPlane.empty())
553 GlobalSlot = getGlobalSlot(TyPlane[ctp]);
554
555 if (GlobalSlot >= Table.size())
556 Table.resize(GlobalSlot+1);
557 TypePlane &GPlane = Table[GlobalSlot];
558
559 unsigned ModLevel = getModuleLevel(ctp);
560 unsigned NumFunctionObjs = CPlane.size()-ModLevel;
561
562 // If the maximum index required if all entries in this plane were merged
563 // into the global plane is less than 64, go ahead and eliminate the
564 // plane.
565 bool PrunePlane = GPlane.size() + NumFunctionObjs < 64;
566
567 // If there are no function-local values defined, and the maximum
568 // referenced global entry is less than 64, we don't need to compactify.
569 if (!PrunePlane && NumFunctionObjs == 0) {
570 unsigned MaxIdx = 0;
571 for (unsigned i = 0; i != ModLevel; ++i) {
572 unsigned Idx = NodeMap[CPlane[i]];
573 if (Idx > MaxIdx) MaxIdx = Idx;
574 }
575 PrunePlane = MaxIdx < 64;
576 }
577
578 // Ok, finally, if we decided to prune this plane out of the compaction
579 // table, do so now.
580 if (PrunePlane) {
581 TypePlane OldPlane;
582 std::swap(OldPlane, CPlane);
583
584 // Loop over the function local objects, relocating them to the global
585 // table plane.
586 for (unsigned i = ModLevel, e = OldPlane.size(); i != e; ++i) {
587 const Value *V = OldPlane[i];
588 CompactionNodeMap.erase(V);
589 assert(NodeMap.count(V) == 0 && "Value already in table??");
590 getOrCreateSlot(V);
591 }
592
593 // For compactified global values, just remove them from the compaction
594 // node map.
595 for (unsigned i = 0; i != ModLevel; ++i)
596 CompactionNodeMap.erase(OldPlane[i]);
597
598 // Update the new modulelevel for this plane.
599 assert(ctp < ModuleLevel.size() && "Cannot set modulelevel!");
600 ModuleLevel[ctp] = GPlane.size()-NumFunctionObjs;
601 assert((int)ModuleLevel[ctp] >= 0 && "Bad computation!");
602 }
603 }
604}
605
606
Chris Lattner8c202cd2004-01-15 18:47:15 +0000607int SlotCalculator::getSlot(const Value *V) const {
Chris Lattner614cdcd2004-01-18 21:07:07 +0000608 // If there is a CompactionTable active...
609 if (!CompactionNodeMap.empty()) {
610 std::map<const Value*, unsigned>::const_iterator I =
611 CompactionNodeMap.find(V);
612 if (I != CompactionNodeMap.end())
613 return (int)I->second;
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000614 // Otherwise, if it's not in the compaction table, it must be in a
615 // non-compactified plane.
Chris Lattner614cdcd2004-01-18 21:07:07 +0000616 }
617
Chris Lattner8c202cd2004-01-15 18:47:15 +0000618 std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(V);
619 if (I != NodeMap.end())
620 return (int)I->second;
621
622 // Do not number ConstantPointerRef's at all. They are an abomination.
623 if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V))
624 return getSlot(CPR->getValue());
625
626 return -1;
Chris Lattner00950542001-06-06 20:29:01 +0000627}
628
Chris Lattner9a297902001-09-07 16:31:52 +0000629
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000630int SlotCalculator::getOrCreateSlot(const Value *V) {
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000631 if (V->getType() == Type::VoidTy) return -1;
632
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000633 int SlotNo = getSlot(V); // Check to see if it's already in!
Chris Lattner9a297902001-09-07 16:31:52 +0000634 if (SlotNo != -1) return SlotNo;
Chris Lattner3413d152003-03-19 20:57:22 +0000635
Chris Lattner8c202cd2004-01-15 18:47:15 +0000636 // Do not number ConstantPointerRef's at all. They are an abomination.
637 if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V))
638 return getOrCreateSlot(CPR->getValue());
639
Chris Lattner614cdcd2004-01-18 21:07:07 +0000640 if (!isa<GlobalValue>(V)) // Initializers for globals are handled explicitly
Chris Lattner3413d152003-03-19 20:57:22 +0000641 if (const Constant *C = dyn_cast<Constant>(V)) {
Chris Lattner614cdcd2004-01-18 21:07:07 +0000642 assert(CompactionNodeMap.empty() &&
643 "All needed constants should be in the compaction map already!");
644
Reid Spencer798ff642004-05-26 07:37:11 +0000645 // Do not index the characters that make up constant strings. We emit
646 // constant strings as special entities that don't require their
647 // individual characters to be emitted.
648 if (!isa<ConstantArray>(C) || !cast<ConstantArray>(C)->isString()) {
Chris Lattnerdcea6302004-01-14 23:34:39 +0000649 // This makes sure that if a constant has uses (for example an array of
650 // const ints), that they are inserted also.
651 //
652 for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
653 I != E; ++I)
654 getOrCreateSlot(*I);
655 } else {
656 assert(ModuleLevel.empty() &&
657 "How can a constant string be directly accessed in a function?");
658 // Otherwise, if we are emitting a bytecode file and this IS a string,
659 // remember it.
660 if (!C->isNullValue())
661 ConstantStrings.push_back(cast<ConstantArray>(C));
662 }
Chris Lattner3413d152003-03-19 20:57:22 +0000663 }
664
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000665 return insertValue(V);
Chris Lattner9a297902001-09-07 16:31:52 +0000666}
667
668
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000669int SlotCalculator::insertValue(const Value *D, bool dontIgnore) {
Chris Lattner9a297902001-09-07 16:31:52 +0000670 assert(D && "Can't insert a null value!");
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000671 assert(getSlot(D) == -1 && "Value is already in the table!");
Chris Lattner00950542001-06-06 20:29:01 +0000672
Chris Lattner614cdcd2004-01-18 21:07:07 +0000673 // If we are building a compaction map, and if this plane is being compacted,
674 // insert the value into the compaction map, not into the global map.
675 if (!CompactionNodeMap.empty()) {
676 if (D->getType() == Type::VoidTy) return -1; // Do not insert void values
677 assert(!isa<Type>(D) && !isa<Constant>(D) && !isa<GlobalValue>(D) &&
678 "Types, constants, and globals should be in global SymTab!");
679
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000680 int Plane = getSlot(D->getType());
681 assert(Plane != -1 && CompactionTable.size() > (unsigned)Plane &&
682 "Didn't find value type!");
683 if (!CompactionTable[Plane].empty())
684 return getOrCreateCompactionTableSlot(D);
Chris Lattner614cdcd2004-01-18 21:07:07 +0000685 }
686
Chris Lattner00950542001-06-06 20:29:01 +0000687 // If this node does not contribute to a plane, or if the node has a
Chris Lattner9a297902001-09-07 16:31:52 +0000688 // name and we don't want names, then ignore the silly node... Note that types
689 // do need slot numbers so that we can keep track of where other values land.
Chris Lattner00950542001-06-06 20:29:01 +0000690 //
Chris Lattner9b50c152001-07-26 16:28:37 +0000691 if (!dontIgnore) // Don't ignore nonignorables!
Reid Spencer798ff642004-05-26 07:37:11 +0000692 if (D->getType() == Type::VoidTy ) { // Ignore void type nodes
Chris Lattner3413d152003-03-19 20:57:22 +0000693 SC_DEBUG("ignored value " << *D << "\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000694 return -1; // We do need types unconditionally though
695 }
Chris Lattner00950542001-06-06 20:29:01 +0000696
Chris Lattner9a297902001-09-07 16:31:52 +0000697 // If it's a type, make sure that all subtypes of the type are included...
Chris Lattner949a3622003-07-23 15:30:06 +0000698 if (const Type *TheTy = dyn_cast<Type>(D)) {
Chris Lattnerf1fef652001-10-13 06:35:09 +0000699
700 // Insert the current type before any subtypes. This is important because
701 // recursive types elements are inserted in a bottom up order. Changing
702 // this here can break things. For example:
703 //
704 // global { \2 * } { { \2 }* null }
705 //
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000706 int ResultSlot = doInsertValue(TheTy);
707 SC_DEBUG(" Inserted type: " << TheTy->getDescription() << " slot=" <<
708 ResultSlot << "\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000709
Alkis Evlogimenos088eb452003-10-31 03:02:34 +0000710 // Loop over any contained types in the definition... in post
711 // order.
Chris Lattner9a297902001-09-07 16:31:52 +0000712 //
Alkis Evlogimenos088eb452003-10-31 03:02:34 +0000713 for (po_iterator<const Type*> I = po_begin(TheTy), E = po_end(TheTy);
Alkis Evlogimenos74fa84f2003-10-30 21:04:44 +0000714 I != E; ++I) {
Chris Lattner9a297902001-09-07 16:31:52 +0000715 if (*I != TheTy) {
Alkis Evlogimenos74fa84f2003-10-30 21:04:44 +0000716 const Type *SubTy = *I;
Alkis Evlogimenos088eb452003-10-31 03:02:34 +0000717 // If we haven't seen this sub type before, add it to our type table!
718 if (getSlot(SubTy) == -1) {
719 SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << "\n");
720 int Slot = doInsertValue(SubTy);
721 SC_DEBUG(" Inserted subtype: " << SubTy->getDescription() <<
722 " slot=" << Slot << "\n");
723 }
Alkis Evlogimenos74fa84f2003-10-30 21:04:44 +0000724 }
725 }
Chris Lattnerf1fef652001-10-13 06:35:09 +0000726 return ResultSlot;
Chris Lattner9a297902001-09-07 16:31:52 +0000727 }
728
729 // Okay, everything is happy, actually insert the silly value now...
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000730 return doInsertValue(D);
Chris Lattner9a297902001-09-07 16:31:52 +0000731}
732
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000733// doInsertValue - This is a small helper function to be called only
734// be insertValue.
Chris Lattner9a297902001-09-07 16:31:52 +0000735//
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000736int SlotCalculator::doInsertValue(const Value *D) {
Chris Lattner00950542001-06-06 20:29:01 +0000737 const Type *Typ = D->getType();
Chris Lattner9b50c152001-07-26 16:28:37 +0000738 unsigned Ty;
739
740 // Used for debugging DefSlot=-1 assertion...
741 //if (Typ == Type::TypeTy)
Chris Lattnercfe26c92001-10-01 18:26:53 +0000742 // cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n";
Chris Lattner9b50c152001-07-26 16:28:37 +0000743
Chris Lattner00950542001-06-06 20:29:01 +0000744 if (Typ->isDerivedType()) {
Chris Lattner68e3dbc2004-01-20 00:57:32 +0000745 int ValSlot;
746 if (CompactionTable.empty())
747 ValSlot = getSlot(Typ);
748 else
749 ValSlot = getGlobalSlot(Typ);
Chris Lattner3413d152003-03-19 20:57:22 +0000750 if (ValSlot == -1) { // Have we already entered this type?
Chris Lattner9a297902001-09-07 16:31:52 +0000751 // Nope, this is the first we have seen the type, process it.
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000752 ValSlot = insertValue(Typ, true);
Chris Lattner3413d152003-03-19 20:57:22 +0000753 assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
Chris Lattner00950542001-06-06 20:29:01 +0000754 }
Chris Lattner3413d152003-03-19 20:57:22 +0000755 Ty = (unsigned)ValSlot;
Chris Lattner9b50c152001-07-26 16:28:37 +0000756 } else {
757 Ty = Typ->getPrimitiveID();
Chris Lattner00950542001-06-06 20:29:01 +0000758 }
759
760 if (Table.size() <= Ty) // Make sure we have the type plane allocated...
761 Table.resize(Ty+1, TypePlane());
Chris Lattner3413d152003-03-19 20:57:22 +0000762
763 // If this is the first value to get inserted into the type plane, make sure
764 // to insert the implicit null value...
Reid Spencer798ff642004-05-26 07:37:11 +0000765 if (Table[Ty].empty() && hasNullValue(Ty)) {
Chris Lattner3413d152003-03-19 20:57:22 +0000766 Value *ZeroInitializer = Constant::getNullValue(Typ);
767
768 // If we are pushing zeroinit, it will be handled below.
769 if (D != ZeroInitializer) {
770 Table[Ty].push_back(ZeroInitializer);
771 NodeMap[ZeroInitializer] = 0;
772 }
773 }
774
Chris Lattner9a297902001-09-07 16:31:52 +0000775 // Insert node into table and NodeMap...
776 unsigned DestSlot = NodeMap[D] = Table[Ty].size();
Chris Lattner00950542001-06-06 20:29:01 +0000777 Table[Ty].push_back(D);
Chris Lattner9a297902001-09-07 16:31:52 +0000778
Chris Lattnerf1fef652001-10-13 06:35:09 +0000779 SC_DEBUG(" Inserting value [" << Ty << "] = " << D << " slot=" <<
780 DestSlot << " [");
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000781 // G = Global, C = Constant, T = Type, F = Function, o = other
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000782 SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" :
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000783 (isa<Type>(D) ? "T" : (isa<Function>(D) ? "F" : "o")))));
Chris Lattnerf1fef652001-10-13 06:35:09 +0000784 SC_DEBUG("]\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000785 return (int)DestSlot;
Chris Lattner00950542001-06-06 20:29:01 +0000786}