blob: aef71763c44dd7f4ab82ccca5325235fb79dc73d [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//
10// This file implements a useful analysis step to figure out what numbered
11// slots values in a program will land in (keeping track of per plane
12// information as required.
13//
14// This is used primarily for when writing a file to disk, either in bytecode
15// or source format.
16//
17//===----------------------------------------------------------------------===//
18
Chris Lattnerb5794002002-04-07 22:49:37 +000019#include "llvm/SlotCalculator.h"
Chris Lattner9a297902001-09-07 16:31:52 +000020#include "llvm/Analysis/ConstantsScanner.h"
Chris Lattner00950542001-06-06 20:29:01 +000021#include "llvm/Module.h"
Chris Lattner00950542001-06-06 20:29:01 +000022#include "llvm/iOther.h"
Chris Lattner31bcdb82002-04-28 19:55:58 +000023#include "llvm/Constant.h"
Chris Lattner00950542001-06-06 20:29:01 +000024#include "llvm/DerivedTypes.h"
Chris Lattner9a297902001-09-07 16:31:52 +000025#include "llvm/SymbolTable.h"
Alkis Evlogimenos088eb452003-10-31 03:02:34 +000026#include "Support/PostOrderIterator.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000027#include "Support/STLExtras.h"
Chris Lattner9a297902001-09-07 16:31:52 +000028#include <algorithm>
29
30#if 0
Chris Lattner3413d152003-03-19 20:57:22 +000031#define SC_DEBUG(X) std::cerr << X
Chris Lattner9a297902001-09-07 16:31:52 +000032#else
33#define SC_DEBUG(X)
34#endif
Chris Lattner00950542001-06-06 20:29:01 +000035
36SlotCalculator::SlotCalculator(const Module *M, bool IgnoreNamed) {
37 IgnoreNamedNodes = IgnoreNamed;
38 TheModule = M;
39
40 // Preload table... Make sure that all of the primitive types are in the table
41 // and that their Primitive ID is equal to their slot #
42 //
Alkis Evlogimenos5d1bdcd2003-10-29 03:12:12 +000043 SC_DEBUG("Inserting primitive types:\n");
Chris Lattner00950542001-06-06 20:29:01 +000044 for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
45 assert(Type::getPrimitiveType((Type::PrimitiveID)i));
Alkis Evlogimenos60596382003-10-17 02:02:40 +000046 insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
Chris Lattner00950542001-06-06 20:29:01 +000047 }
48
49 if (M == 0) return; // Empty table...
Chris Lattner9a297902001-09-07 16:31:52 +000050 processModule();
Chris Lattner00950542001-06-06 20:29:01 +000051}
52
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000053SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
Chris Lattner00950542001-06-06 20:29:01 +000054 IgnoreNamedNodes = IgnoreNamed;
55 TheModule = M ? M->getParent() : 0;
56
57 // Preload table... Make sure that all of the primitive types are in the table
58 // and that their Primitive ID is equal to their slot #
59 //
Alkis Evlogimenos5d1bdcd2003-10-29 03:12:12 +000060 SC_DEBUG("Inserting primitive types:\n");
Chris Lattner00950542001-06-06 20:29:01 +000061 for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
62 assert(Type::getPrimitiveType((Type::PrimitiveID)i));
Alkis Evlogimenos60596382003-10-17 02:02:40 +000063 insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
Chris Lattner00950542001-06-06 20:29:01 +000064 }
65
66 if (TheModule == 0) return; // Empty table...
67
Chris Lattner9a297902001-09-07 16:31:52 +000068 processModule(); // Process module level stuff
Chris Lattnerb5794002002-04-07 22:49:37 +000069 incorporateFunction(M); // Start out in incorporated state
Chris Lattner00950542001-06-06 20:29:01 +000070}
71
Chris Lattner9a297902001-09-07 16:31:52 +000072
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000073// processModule - Process all of the module level function declarations and
Chris Lattner9a297902001-09-07 16:31:52 +000074// types that are available.
75//
76void SlotCalculator::processModule() {
77 SC_DEBUG("begin processModule!\n");
Chris Lattner70cc3392001-09-10 07:58:01 +000078
Chris Lattner3413d152003-03-19 20:57:22 +000079 // Add all of the global variables to the value table...
Chris Lattnerf1fef652001-10-13 06:35:09 +000080 //
81 for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
Chris Lattner479b54b2002-10-14 00:48:57 +000082 I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +000083 getOrCreateSlot(I);
Chris Lattner70cc3392001-09-10 07:58:01 +000084
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000085 // Scavenge the types out of the functions, then add the functions themselves
86 // to the value table...
Chris Lattner9a297902001-09-07 16:31:52 +000087 //
Chris Lattner3413d152003-03-19 20:57:22 +000088 for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
89 I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +000090 getOrCreateSlot(I);
Chris Lattner9a297902001-09-07 16:31:52 +000091
Chris Lattner3413d152003-03-19 20:57:22 +000092 // Add all of the module level constants used as initializers
93 //
94 for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
95 I != E; ++I)
96 if (I->hasInitializer())
Alkis Evlogimenos60596382003-10-17 02:02:40 +000097 getOrCreateSlot(I->getInitializer());
Chris Lattner3413d152003-03-19 20:57:22 +000098
Chris Lattner70cc3392001-09-10 07:58:01 +000099 // Insert constants that are named at module level into the slot pool so that
100 // the module symbol table can refer to them...
101 //
Chris Lattner6e6026b2002-11-20 18:36:02 +0000102 if (!IgnoreNamedNodes) {
Chris Lattner9a297902001-09-07 16:31:52 +0000103 SC_DEBUG("Inserting SymbolTable values:\n");
Chris Lattner6e6026b2002-11-20 18:36:02 +0000104 processSymbolTable(&TheModule->getSymbolTable());
Chris Lattner9a297902001-09-07 16:31:52 +0000105 }
106
107 SC_DEBUG("end processModule!\n");
108}
109
110// processSymbolTable - Insert all of the values in the specified symbol table
111// into the values table...
112//
113void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
114 for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
115 for (SymbolTable::type_const_iterator TI = I->second.begin(),
116 TE = I->second.end(); TI != TE; ++TI)
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000117 getOrCreateSlot(TI->second);
Chris Lattner9a297902001-09-07 16:31:52 +0000118}
119
120void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
121 for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
122 for (SymbolTable::type_const_iterator TI = I->second.begin(),
123 TE = I->second.end(); TI != TE; ++TI)
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000124 if (isa<Constant>(TI->second))
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000125 getOrCreateSlot(TI->second);
Chris Lattner9a297902001-09-07 16:31:52 +0000126}
127
128
Chris Lattnerce439b52003-10-20 19:10:06 +0000129void SlotCalculator::incorporateFunction(const Function *F) {
Chris Lattner00950542001-06-06 20:29:01 +0000130 assert(ModuleLevel.size() == 0 && "Module already incorporated!");
131
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000132 SC_DEBUG("begin processFunction!\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000133
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000134 // Save the Table state before we process the function...
Chris Lattner9a297902001-09-07 16:31:52 +0000135 for (unsigned i = 0; i < Table.size(); ++i)
Chris Lattner00950542001-06-06 20:29:01 +0000136 ModuleLevel.push_back(Table[i].size());
Chris Lattner9a297902001-09-07 16:31:52 +0000137
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000138 SC_DEBUG("Inserting function arguments\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000139
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000140 // Iterate over function arguments, adding them to the value table...
Chris Lattnerce439b52003-10-20 19:10:06 +0000141 for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000142 getOrCreateSlot(I);
Chris Lattner9a297902001-09-07 16:31:52 +0000143
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000144 // Iterate over all of the instructions in the function, looking for constant
Chris Lattner9a297902001-09-07 16:31:52 +0000145 // values that are referenced. Add these to the value pools before any
146 // nonconstant values. This will be turned into the constant pool for the
147 // bytecode writer.
148 //
149 if (!IgnoreNamedNodes) { // Assembly writer does not need this!
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000150 SC_DEBUG("Inserting function constants:\n";
Chris Lattnerce439b52003-10-20 19:10:06 +0000151 for (constant_iterator I = constant_begin(F), E = constant_end(F);
Chris Lattner9a297902001-09-07 16:31:52 +0000152 I != E; ++I) {
Chris Lattner3413d152003-03-19 20:57:22 +0000153 std::cerr << " " << *I->getType() << " " << *I << "\n";
Chris Lattner9a297902001-09-07 16:31:52 +0000154 });
155
156 // Emit all of the constants that are being used by the instructions in the
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000157 // function...
Chris Lattnerce439b52003-10-20 19:10:06 +0000158 for_each(constant_begin(F), constant_end(F),
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000159 bind_obj(this, &SlotCalculator::getOrCreateSlot));
Chris Lattner9a297902001-09-07 16:31:52 +0000160
161 // If there is a symbol table, it is possible that the user has names for
162 // constants that are not being used. In this case, we will have problems
163 // if we don't emit the constants now, because otherwise we will get
164 // symboltable references to constants not in the output. Scan for these
165 // constants now.
166 //
Chris Lattnerce439b52003-10-20 19:10:06 +0000167 processSymbolTableConstants(&F->getSymbolTable());
Chris Lattner00950542001-06-06 20:29:01 +0000168 }
169
Chris Lattner9a297902001-09-07 16:31:52 +0000170 SC_DEBUG("Inserting Labels:\n");
171
172 // Iterate over basic blocks, adding them to the value table...
Chris Lattnerce439b52003-10-20 19:10:06 +0000173 for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000174 getOrCreateSlot(I);
Chris Lattner9a297902001-09-07 16:31:52 +0000175
176 SC_DEBUG("Inserting Instructions:\n");
177
178 // Add all of the instructions to the type planes...
Chris Lattner389dbfb2003-10-21 17:39:59 +0000179 for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
180 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
181 getOrCreateSlot(I);
Chris Lattner2765c412003-10-21 17:40:54 +0000182 if (const VANextInst *VAN = dyn_cast<VANextInst>(I))
183 getOrCreateSlot(VAN->getArgType());
Chris Lattner389dbfb2003-10-21 17:39:59 +0000184 }
Chris Lattner9a297902001-09-07 16:31:52 +0000185
Chris Lattner6e6026b2002-11-20 18:36:02 +0000186 if (!IgnoreNamedNodes) {
Chris Lattner9a297902001-09-07 16:31:52 +0000187 SC_DEBUG("Inserting SymbolTable values:\n");
Chris Lattnerce439b52003-10-20 19:10:06 +0000188 processSymbolTable(&F->getSymbolTable());
Chris Lattner9a297902001-09-07 16:31:52 +0000189 }
190
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000191 SC_DEBUG("end processFunction!\n");
Chris Lattner00950542001-06-06 20:29:01 +0000192}
193
Chris Lattnerb5794002002-04-07 22:49:37 +0000194void SlotCalculator::purgeFunction() {
Chris Lattner00950542001-06-06 20:29:01 +0000195 assert(ModuleLevel.size() != 0 && "Module not incorporated!");
196 unsigned NumModuleTypes = ModuleLevel.size();
197
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000198 SC_DEBUG("begin purgeFunction!\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000199
Chris Lattner00950542001-06-06 20:29:01 +0000200 // First, remove values from existing type planes
201 for (unsigned i = 0; i < NumModuleTypes; ++i) {
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000202 unsigned ModuleSize = ModuleLevel[i]; // Size of plane before function came
Chris Lattner9a297902001-09-07 16:31:52 +0000203 TypePlane &CurPlane = Table[i];
Chris Lattner479b54b2002-10-14 00:48:57 +0000204 //SC_DEBUG("Processing Plane " <<i<< " of size " << CurPlane.size() <<"\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000205
206 while (CurPlane.size() != ModuleSize) {
Chris Lattnerf1fef652001-10-13 06:35:09 +0000207 //SC_DEBUG(" Removing [" << i << "] Value=" << CurPlane.back() << "\n");
Chris Lattner697954c2002-01-20 22:54:45 +0000208 std::map<const Value *, unsigned>::iterator NI =
209 NodeMap.find(CurPlane.back());
Chris Lattner9a297902001-09-07 16:31:52 +0000210 assert(NI != NodeMap.end() && "Node not in nodemap?");
211 NodeMap.erase(NI); // Erase from nodemap
212 CurPlane.pop_back(); // Shrink plane
Chris Lattner00950542001-06-06 20:29:01 +0000213 }
214 }
215
216 // We don't need this state anymore, free it up.
217 ModuleLevel.clear();
218
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000219 // Next, remove any type planes defined by the function...
Chris Lattner00950542001-06-06 20:29:01 +0000220 while (NumModuleTypes != Table.size()) {
221 TypePlane &Plane = Table.back();
Chris Lattner9a297902001-09-07 16:31:52 +0000222 SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size "
Chris Lattner479b54b2002-10-14 00:48:57 +0000223 << Plane.size() << "\n");
Chris Lattner00950542001-06-06 20:29:01 +0000224 while (Plane.size()) {
225 NodeMap.erase(NodeMap.find(Plane.back())); // Erase from nodemap
226 Plane.pop_back(); // Shrink plane
227 }
228
229 Table.pop_back(); // Nuke the plane, we don't like it.
230 }
Chris Lattner00950542001-06-06 20:29:01 +0000231
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000232 SC_DEBUG("end purgeFunction!\n");
Chris Lattner00950542001-06-06 20:29:01 +0000233}
234
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000235int SlotCalculator::getSlot(const Value *D) const {
Chris Lattner697954c2002-01-20 22:54:45 +0000236 std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(D);
Chris Lattner00950542001-06-06 20:29:01 +0000237 if (I == NodeMap.end()) return -1;
238
239 return (int)I->second;
240}
241
Chris Lattner9a297902001-09-07 16:31:52 +0000242
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000243int SlotCalculator::getOrCreateSlot(const Value *V) {
244 int SlotNo = getSlot(V); // Check to see if it's already in!
Chris Lattner9a297902001-09-07 16:31:52 +0000245 if (SlotNo != -1) return SlotNo;
Chris Lattner3413d152003-03-19 20:57:22 +0000246
247 if (!isa<GlobalValue>(V))
248 if (const Constant *C = dyn_cast<Constant>(V)) {
249 // This makes sure that if a constant has uses (for example an array of
250 // const ints), that they are inserted also.
251 //
252 for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
253 I != E; ++I)
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000254 getOrCreateSlot(*I);
Chris Lattner3413d152003-03-19 20:57:22 +0000255 }
256
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000257 return insertValue(V);
Chris Lattner9a297902001-09-07 16:31:52 +0000258}
259
260
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000261int SlotCalculator::insertValue(const Value *D, bool dontIgnore) {
Chris Lattner9a297902001-09-07 16:31:52 +0000262 assert(D && "Can't insert a null value!");
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000263 assert(getSlot(D) == -1 && "Value is already in the table!");
Chris Lattner00950542001-06-06 20:29:01 +0000264
265 // If this node does not contribute to a plane, or if the node has a
Chris Lattner9a297902001-09-07 16:31:52 +0000266 // name and we don't want names, then ignore the silly node... Note that types
267 // do need slot numbers so that we can keep track of where other values land.
Chris Lattner00950542001-06-06 20:29:01 +0000268 //
Chris Lattner9b50c152001-07-26 16:28:37 +0000269 if (!dontIgnore) // Don't ignore nonignorables!
270 if (D->getType() == Type::VoidTy || // Ignore void type nodes
Chris Lattner9a297902001-09-07 16:31:52 +0000271 (IgnoreNamedNodes && // Ignore named and constants
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000272 (D->hasName() || isa<Constant>(D)) && !isa<Type>(D))) {
Chris Lattner3413d152003-03-19 20:57:22 +0000273 SC_DEBUG("ignored value " << *D << "\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000274 return -1; // We do need types unconditionally though
275 }
Chris Lattner00950542001-06-06 20:29:01 +0000276
Chris Lattner9a297902001-09-07 16:31:52 +0000277 // If it's a type, make sure that all subtypes of the type are included...
Chris Lattner949a3622003-07-23 15:30:06 +0000278 if (const Type *TheTy = dyn_cast<Type>(D)) {
Chris Lattnerf1fef652001-10-13 06:35:09 +0000279
280 // Insert the current type before any subtypes. This is important because
281 // recursive types elements are inserted in a bottom up order. Changing
282 // this here can break things. For example:
283 //
284 // global { \2 * } { { \2 }* null }
285 //
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000286 int ResultSlot = doInsertValue(TheTy);
287 SC_DEBUG(" Inserted type: " << TheTy->getDescription() << " slot=" <<
288 ResultSlot << "\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000289
Alkis Evlogimenos088eb452003-10-31 03:02:34 +0000290 // Loop over any contained types in the definition... in post
291 // order.
Chris Lattner9a297902001-09-07 16:31:52 +0000292 //
Alkis Evlogimenos088eb452003-10-31 03:02:34 +0000293 for (po_iterator<const Type*> I = po_begin(TheTy), E = po_end(TheTy);
Alkis Evlogimenos74fa84f2003-10-30 21:04:44 +0000294 I != E; ++I) {
Chris Lattner9a297902001-09-07 16:31:52 +0000295 if (*I != TheTy) {
Alkis Evlogimenos74fa84f2003-10-30 21:04:44 +0000296 const Type *SubTy = *I;
Alkis Evlogimenos088eb452003-10-31 03:02:34 +0000297 // If we haven't seen this sub type before, add it to our type table!
298 if (getSlot(SubTy) == -1) {
299 SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << "\n");
300 int Slot = doInsertValue(SubTy);
301 SC_DEBUG(" Inserted subtype: " << SubTy->getDescription() <<
302 " slot=" << Slot << "\n");
303 }
Alkis Evlogimenos74fa84f2003-10-30 21:04:44 +0000304 }
305 }
Chris Lattnerf1fef652001-10-13 06:35:09 +0000306 return ResultSlot;
Chris Lattner9a297902001-09-07 16:31:52 +0000307 }
308
309 // Okay, everything is happy, actually insert the silly value now...
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000310 return doInsertValue(D);
Chris Lattner9a297902001-09-07 16:31:52 +0000311}
312
313
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000314// doInsertValue - This is a small helper function to be called only
315// be insertValue.
Chris Lattner9a297902001-09-07 16:31:52 +0000316//
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000317int SlotCalculator::doInsertValue(const Value *D) {
Chris Lattner00950542001-06-06 20:29:01 +0000318 const Type *Typ = D->getType();
Chris Lattner9b50c152001-07-26 16:28:37 +0000319 unsigned Ty;
320
321 // Used for debugging DefSlot=-1 assertion...
322 //if (Typ == Type::TypeTy)
Chris Lattnercfe26c92001-10-01 18:26:53 +0000323 // cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n";
Chris Lattner9b50c152001-07-26 16:28:37 +0000324
Chris Lattner00950542001-06-06 20:29:01 +0000325 if (Typ->isDerivedType()) {
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000326 int ValSlot = getSlot(Typ);
Chris Lattner3413d152003-03-19 20:57:22 +0000327 if (ValSlot == -1) { // Have we already entered this type?
Chris Lattner9a297902001-09-07 16:31:52 +0000328 // Nope, this is the first we have seen the type, process it.
Alkis Evlogimenos60596382003-10-17 02:02:40 +0000329 ValSlot = insertValue(Typ, true);
Chris Lattner3413d152003-03-19 20:57:22 +0000330 assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
Chris Lattner00950542001-06-06 20:29:01 +0000331 }
Chris Lattner3413d152003-03-19 20:57:22 +0000332 Ty = (unsigned)ValSlot;
Chris Lattner9b50c152001-07-26 16:28:37 +0000333 } else {
334 Ty = Typ->getPrimitiveID();
Chris Lattner00950542001-06-06 20:29:01 +0000335 }
336
337 if (Table.size() <= Ty) // Make sure we have the type plane allocated...
338 Table.resize(Ty+1, TypePlane());
Chris Lattner3413d152003-03-19 20:57:22 +0000339
340 // If this is the first value to get inserted into the type plane, make sure
341 // to insert the implicit null value...
342 if (Table[Ty].empty() && Ty >= Type::FirstDerivedTyID && !IgnoreNamedNodes) {
343 Value *ZeroInitializer = Constant::getNullValue(Typ);
344
345 // If we are pushing zeroinit, it will be handled below.
346 if (D != ZeroInitializer) {
347 Table[Ty].push_back(ZeroInitializer);
348 NodeMap[ZeroInitializer] = 0;
349 }
350 }
351
Chris Lattner9a297902001-09-07 16:31:52 +0000352 // Insert node into table and NodeMap...
353 unsigned DestSlot = NodeMap[D] = Table[Ty].size();
Chris Lattner00950542001-06-06 20:29:01 +0000354 Table[Ty].push_back(D);
Chris Lattner9a297902001-09-07 16:31:52 +0000355
Chris Lattnerf1fef652001-10-13 06:35:09 +0000356 SC_DEBUG(" Inserting value [" << Ty << "] = " << D << " slot=" <<
357 DestSlot << " [");
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000358 // G = Global, C = Constant, T = Type, F = Function, o = other
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000359 SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" :
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000360 (isa<Type>(D) ? "T" : (isa<Function>(D) ? "F" : "o")))));
Chris Lattnerf1fef652001-10-13 06:35:09 +0000361 SC_DEBUG("]\n");
Chris Lattner9a297902001-09-07 16:31:52 +0000362 return (int)DestSlot;
Chris Lattner00950542001-06-06 20:29:01 +0000363}