Eliminate some extraneous code in SlotCalculator::insertVal().

Rename SlotCalculator::getValSlot() to SlotCalculator::getSlot(),
       SlotCalculator::insertValue() to SlotCalculator::getOrCreateSlot(),
       SlotCalculator::insertVal() to SlotCalculator::insertValue(), and
       SlotCalculator::doInsertVal() to SlotCalculator::doInsertValue().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9190 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alkis Evlogimenos 2003-10-17 02:02:40 +00:00
parent e7d4022f36
commit 60596382aa
10 changed files with 127 additions and 128 deletions

View File

@ -39,8 +39,8 @@ public:
SlotCalculator(const Function *M, bool IgnoreNamed);
inline ~SlotCalculator() {}
// getValSlot returns < 0 on error!
int getValSlot(const Value *D) const;
// getSlot returns < 0 on error!
int getSlot(const Value *D) const;
inline unsigned getNumPlanes() const { return Table.size(); }
inline unsigned getModuleLevel(unsigned Plane) const {
@ -58,19 +58,20 @@ public:
void purgeFunction();
protected:
// insertVal - Insert a value into the value table... Return the slot that it
// occupies, or -1 if the declaration is to be ignored because of the
// IgnoreNamedNodes flag.
// getOrCreateSlot - Values can be crammed into here at will... if
// they haven't been inserted already, they get inserted, otherwise
// they are ignored.
//
int insertVal(const Value *D, bool dontIgnore = false);
int getOrCreateSlot(const Value *D);
// insertValue - Values can be crammed into here at will... if they haven't
// been inserted already, they get inserted, otherwise they are ignored.
// insertValue - Insert a value into the value table... Return the
// slot that it occupies, or -1 if the declaration is to be ignored
// because of the IgnoreNamedNodes flag.
//
int insertValue(const Value *D);
int insertValue(const Value *D, bool dontIgnore = false);
// doInsertVal - Small helper function to be called only be insertVal.
int doInsertVal(const Value *D);
// doInsertValue - Small helper function to be called only be insertVal.
int doInsertValue(const Value *D);
// processModule - Process all of the module level function declarations and
// types that are available.

View File

@ -39,8 +39,8 @@ public:
SlotCalculator(const Function *M, bool IgnoreNamed);
inline ~SlotCalculator() {}
// getValSlot returns < 0 on error!
int getValSlot(const Value *D) const;
// getSlot returns < 0 on error!
int getSlot(const Value *D) const;
inline unsigned getNumPlanes() const { return Table.size(); }
inline unsigned getModuleLevel(unsigned Plane) const {
@ -58,19 +58,20 @@ public:
void purgeFunction();
protected:
// insertVal - Insert a value into the value table... Return the slot that it
// occupies, or -1 if the declaration is to be ignored because of the
// IgnoreNamedNodes flag.
// getOrCreateSlot - Values can be crammed into here at will... if
// they haven't been inserted already, they get inserted, otherwise
// they are ignored.
//
int insertVal(const Value *D, bool dontIgnore = false);
int getOrCreateSlot(const Value *D);
// insertValue - Values can be crammed into here at will... if they haven't
// been inserted already, they get inserted, otherwise they are ignored.
// insertValue - Insert a value into the value table... Return the
// slot that it occupies, or -1 if the declaration is to be ignored
// because of the IgnoreNamedNodes flag.
//
int insertValue(const Value *D);
int insertValue(const Value *D, bool dontIgnore = false);
// doInsertVal - Small helper function to be called only be insertVal.
int doInsertVal(const Value *D);
// doInsertValue - Small helper function to be called only be insertVal.
int doInsertValue(const Value *D);
// processModule - Process all of the module level function declarations and
// types that are available.

View File

@ -20,7 +20,7 @@ void BytecodeWriter::outputType(const Type *T) {
switch (T->getPrimitiveID()) { // Handle derived types now.
case Type::FunctionTyID: {
const FunctionType *MT = cast<FunctionType>(T);
int Slot = Table.getValSlot(MT->getReturnType());
int Slot = Table.getSlot(MT->getReturnType());
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
@ -30,7 +30,7 @@ void BytecodeWriter::outputType(const Type *T) {
// Output all of the arguments...
FunctionType::ParamTypes::const_iterator I = MT->getParamTypes().begin();
for (; I != MT->getParamTypes().end(); ++I) {
Slot = Table.getValSlot(*I);
Slot = Table.getSlot(*I);
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
}
@ -43,7 +43,7 @@ void BytecodeWriter::outputType(const Type *T) {
case Type::ArrayTyID: {
const ArrayType *AT = cast<ArrayType>(T);
int Slot = Table.getValSlot(AT->getElementType());
int Slot = Table.getSlot(AT->getElementType());
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
//std::cerr << "Type slot = " << Slot << " Type = " << T->getName() << endl;
@ -58,7 +58,7 @@ void BytecodeWriter::outputType(const Type *T) {
// Output all of the element types...
StructType::ElementTypes::const_iterator I = ST->getElementTypes().begin();
for (; I != ST->getElementTypes().end(); ++I) {
int Slot = Table.getValSlot(*I);
int Slot = Table.getSlot(*I);
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
}
@ -70,7 +70,7 @@ void BytecodeWriter::outputType(const Type *T) {
case Type::PointerTyID: {
const PointerType *PT = cast<PointerType>(T);
int Slot = Table.getValSlot(PT->getElementType());
int Slot = Table.getSlot(PT->getElementType());
assert(Slot != -1 && "Type used but not available!!");
output_vbr((unsigned)Slot, Out);
break;
@ -103,10 +103,10 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) {
output_vbr(CE->getOpcode(), Out); // flags as an expr
for (User::const_op_iterator OI = CE->op_begin(); OI != CE->op_end(); ++OI){
int Slot = Table.getValSlot(*OI);
int Slot = Table.getSlot(*OI);
assert(Slot != -1 && "Unknown constant used in ConstantExpr!!");
output_vbr((unsigned)Slot, Out);
Slot = Table.getValSlot((*OI)->getType());
Slot = Table.getSlot((*OI)->getType());
output_vbr((unsigned)Slot, Out);
}
return false;
@ -146,7 +146,7 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) {
assert(size == cast<ArrayType>(CPA->getType())->getNumElements()
&& "ConstantArray out of whack!");
for (unsigned i = 0; i < size; i++) {
int Slot = Table.getValSlot(CPA->getOperand(i));
int Slot = Table.getSlot(CPA->getOperand(i));
assert(Slot != -1 && "Constant used but not available!!");
output_vbr((unsigned)Slot, Out);
}
@ -158,7 +158,7 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) {
const std::vector<Use> &Vals = CPS->getValues();
for (unsigned i = 0; i < Vals.size(); ++i) {
int Slot = Table.getValSlot(Vals[i]);
int Slot = Table.getSlot(Vals[i]);
assert(Slot != -1 && "Constant used but not available!!");
output_vbr((unsigned)Slot, Out);
}
@ -169,7 +169,7 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) {
const ConstantPointer *CPP = cast<ConstantPointer>(CPV);
assert(!isa<ConstantPointerNull>(CPP) && "Null should be already emitted!");
const ConstantPointerRef *CPR = cast<ConstantPointerRef>(CPP);
int Slot = Table.getValSlot((Value*)CPR->getValue());
int Slot = Table.getSlot((Value*)CPR->getValue());
assert(Slot != -1 && "Global used but not available!!");
output_vbr((unsigned)Slot, Out);
break;

View File

@ -33,13 +33,13 @@ static void outputInstructionFormat0(const Instruction *I, unsigned Opcode,
output_vbr(NumArgs + (isa<CastInst>(I) || isa<VarArgInst>(I)), Out);
for (unsigned i = 0; i < NumArgs; ++i) {
int Slot = Table.getValSlot(I->getOperand(i));
int Slot = Table.getSlot(I->getOperand(i));
assert(Slot >= 0 && "No slot number for value!?!?");
output_vbr((unsigned)Slot, Out);
}
if (isa<CastInst>(I) || isa<VarArgInst>(I)) {
int Slot = Table.getValSlot(I->getType());
int Slot = Table.getSlot(I->getType());
assert(Slot != -1 && "Cast/VarArg return type unknown?");
output_vbr((unsigned)Slot, Out);
}
@ -72,7 +72,7 @@ static void outputInstrVarArgsCall(const Instruction *I, unsigned Opcode,
// The type for the function has already been emitted in the type field of the
// instruction. Just emit the slot # now.
int Slot = Table.getValSlot(I->getOperand(0));
int Slot = Table.getSlot(I->getOperand(0));
assert(Slot >= 0 && "No slot number for value!?!?");
output_vbr((unsigned)Slot, Out);
@ -84,12 +84,12 @@ static void outputInstrVarArgsCall(const Instruction *I, unsigned Opcode,
for (unsigned i = 1; i < NumArgs; ++i) {
// Output Arg Type ID
Slot = Table.getValSlot(I->getOperand(i)->getType());
Slot = Table.getSlot(I->getOperand(i)->getType());
assert(Slot >= 0 && "No slot number for value!?!?");
output_vbr((unsigned)Slot, Out);
// Output arg ID itself
Slot = Table.getValSlot(I->getOperand(i));
Slot = Table.getSlot(I->getOperand(i));
assert(Slot >= 0 && "No slot number for value!?!?");
output_vbr((unsigned)Slot, Out);
}
@ -176,7 +176,7 @@ void BytecodeWriter::processInstruction(const Instruction &I) {
for (unsigned i = 0; i < NumOperands; ++i) {
const Value *Def = I.getOperand(i);
int slot = Table.getValSlot(Def);
int slot = Table.getSlot(Def);
assert(slot != -1 && "Broken bytecode!");
if (slot > MaxOpSlot) MaxOpSlot = slot;
if (i < 3) Slots[i] = slot;
@ -204,7 +204,7 @@ void BytecodeWriter::processInstruction(const Instruction &I) {
}
unsigned Type;
int Slot = Table.getValSlot(Ty);
int Slot = Table.getSlot(Ty);
assert(Slot != -1 && "Type not available!!?!");
Type = (unsigned)Slot;
@ -217,7 +217,7 @@ void BytecodeWriter::processInstruction(const Instruction &I) {
if (isa<CastInst>(I) || isa<VarArgInst>(I)) {
// Cast has to encode the destination type as the second argument in the
// packet, or else we won't know what type to cast to!
Slots[1] = Table.getValSlot(I.getType());
Slots[1] = Table.getSlot(I.getType());
assert(Slots[1] != -1 && "Cast return type unknown?");
if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1];
NumOperands++;

View File

@ -35,7 +35,7 @@ SlotCalculator::SlotCalculator(const Module *M, bool IgnoreNamed) {
//
for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
assert(Type::getPrimitiveType((Type::PrimitiveID)i));
insertVal(Type::getPrimitiveType((Type::PrimitiveID)i), true);
insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
}
if (M == 0) return; // Empty table...
@ -51,7 +51,7 @@ SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
//
for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
assert(Type::getPrimitiveType((Type::PrimitiveID)i));
insertVal(Type::getPrimitiveType((Type::PrimitiveID)i), true);
insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
}
if (TheModule == 0) return; // Empty table...
@ -71,21 +71,21 @@ void SlotCalculator::processModule() {
//
for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
// Scavenge the types out of the functions, then add the functions themselves
// to the value table...
//
for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
// Add all of the module level constants used as initializers
//
for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
I != E; ++I)
if (I->hasInitializer())
insertValue(I->getInitializer());
getOrCreateSlot(I->getInitializer());
// Insert constants that are named at module level into the slot pool so that
// the module symbol table can refer to them...
@ -105,7 +105,7 @@ void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
for (SymbolTable::type_const_iterator TI = I->second.begin(),
TE = I->second.end(); TI != TE; ++TI)
insertValue(TI->second);
getOrCreateSlot(TI->second);
}
void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
@ -113,7 +113,7 @@ void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
for (SymbolTable::type_const_iterator TI = I->second.begin(),
TE = I->second.end(); TI != TE; ++TI)
if (isa<Constant>(TI->second))
insertValue(TI->second);
getOrCreateSlot(TI->second);
}
@ -130,7 +130,7 @@ void SlotCalculator::incorporateFunction(const Function *M) {
// Iterate over function arguments, adding them to the value table...
for(Function::const_aiterator I = M->abegin(), E = M->aend(); I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
// Iterate over all of the instructions in the function, looking for constant
// values that are referenced. Add these to the value pools before any
@ -147,7 +147,7 @@ void SlotCalculator::incorporateFunction(const Function *M) {
// Emit all of the constants that are being used by the instructions in the
// function...
for_each(constant_begin(M), constant_end(M),
bind_obj(this, &SlotCalculator::insertValue));
bind_obj(this, &SlotCalculator::getOrCreateSlot));
// If there is a symbol table, it is possible that the user has names for
// constants that are not being used. In this case, we will have problems
@ -162,13 +162,13 @@ void SlotCalculator::incorporateFunction(const Function *M) {
// Iterate over basic blocks, adding them to the value table...
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
SC_DEBUG("Inserting Instructions:\n");
// Add all of the instructions to the type planes...
for_each(inst_begin(M), inst_end(M),
bind_obj(this, &SlotCalculator::insertValue));
bind_obj(this, &SlotCalculator::getOrCreateSlot));
if (!IgnoreNamedNodes) {
SC_DEBUG("Inserting SymbolTable values:\n");
@ -219,7 +219,7 @@ void SlotCalculator::purgeFunction() {
SC_DEBUG("end purgeFunction!\n");
}
int SlotCalculator::getValSlot(const Value *D) const {
int SlotCalculator::getSlot(const Value *D) const {
std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(D);
if (I == NodeMap.end()) return -1;
@ -227,8 +227,8 @@ int SlotCalculator::getValSlot(const Value *D) const {
}
int SlotCalculator::insertValue(const Value *V) {
int SlotNo = getValSlot(V); // Check to see if it's already in!
int SlotCalculator::getOrCreateSlot(const Value *V) {
int SlotNo = getSlot(V); // Check to see if it's already in!
if (SlotNo != -1) return SlotNo;
if (!isa<GlobalValue>(V))
@ -238,16 +238,16 @@ int SlotCalculator::insertValue(const Value *V) {
//
for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
I != E; ++I)
insertValue(*I);
getOrCreateSlot(*I);
}
return insertVal(V);
return insertValue(V);
}
int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
int SlotCalculator::insertValue(const Value *D, bool dontIgnore) {
assert(D && "Can't insert a null value!");
assert(getValSlot(D) == -1 && "Value is already in the table!");
assert(getSlot(D) == -1 && "Value is already in the table!");
// If this node does not contribute to a plane, or if the node has a
// name and we don't want names, then ignore the silly node... Note that types
@ -270,12 +270,9 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
//
// global { \2 * } { { \2 }* null }
//
int ResultSlot;
if ((ResultSlot = getValSlot(TheTy)) == -1) {
ResultSlot = doInsertVal(TheTy);
SC_DEBUG(" Inserted type: " << TheTy->getDescription() << " slot=" <<
ResultSlot << "\n");
}
int ResultSlot = doInsertValue(TheTy);
SC_DEBUG(" Inserted type: " << TheTy->getDescription() << " slot=" <<
ResultSlot << "\n");
// Loop over any contained types in the definition... in depth first order.
//
@ -284,9 +281,9 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
if (*I != TheTy) {
// If we haven't seen this sub type before, add it to our type table!
const Type *SubTy = *I;
if (getValSlot(SubTy) == -1) {
if (getSlot(SubTy) == -1) {
SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << "\n");
int Slot = doInsertVal(SubTy);
int Slot = doInsertValue(SubTy);
SC_DEBUG(" Inserted subtype: " << SubTy->getDescription() <<
" slot=" << Slot << "\n");
}
@ -295,13 +292,14 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
}
// Okay, everything is happy, actually insert the silly value now...
return doInsertVal(D);
return doInsertValue(D);
}
// doInsertVal - This is a small helper function to be called only be insertVal.
// doInsertValue - This is a small helper function to be called only
// be insertValue.
//
int SlotCalculator::doInsertVal(const Value *D) {
int SlotCalculator::doInsertValue(const Value *D) {
const Type *Typ = D->getType();
unsigned Ty;
@ -310,10 +308,10 @@ int SlotCalculator::doInsertVal(const Value *D) {
// cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n";
if (Typ->isDerivedType()) {
int ValSlot = getValSlot(Typ);
int ValSlot = getSlot(Typ);
if (ValSlot == -1) { // Have we already entered this type?
// Nope, this is the first we have seen the type, process it.
ValSlot = insertVal(Typ, true);
ValSlot = insertValue(Typ, true);
assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
}
Ty = (unsigned)ValSlot;

View File

@ -39,8 +39,8 @@ public:
SlotCalculator(const Function *M, bool IgnoreNamed);
inline ~SlotCalculator() {}
// getValSlot returns < 0 on error!
int getValSlot(const Value *D) const;
// getSlot returns < 0 on error!
int getSlot(const Value *D) const;
inline unsigned getNumPlanes() const { return Table.size(); }
inline unsigned getModuleLevel(unsigned Plane) const {
@ -58,19 +58,20 @@ public:
void purgeFunction();
protected:
// insertVal - Insert a value into the value table... Return the slot that it
// occupies, or -1 if the declaration is to be ignored because of the
// IgnoreNamedNodes flag.
// getOrCreateSlot - Values can be crammed into here at will... if
// they haven't been inserted already, they get inserted, otherwise
// they are ignored.
//
int insertVal(const Value *D, bool dontIgnore = false);
int getOrCreateSlot(const Value *D);
// insertValue - Values can be crammed into here at will... if they haven't
// been inserted already, they get inserted, otherwise they are ignored.
// insertValue - Insert a value into the value table... Return the
// slot that it occupies, or -1 if the declaration is to be ignored
// because of the IgnoreNamedNodes flag.
//
int insertValue(const Value *D);
int insertValue(const Value *D, bool dontIgnore = false);
// doInsertVal - Small helper function to be called only be insertVal.
int doInsertVal(const Value *D);
// doInsertValue - Small helper function to be called only be insertVal.
int doInsertValue(const Value *D);
// processModule - Process all of the module level function declarations and
// types that are available.

View File

@ -105,7 +105,7 @@ void BytecodeWriter::outputConstantsInPlane(const std::vector<const Value*>
output_vbr(NC, Out);
// Output the Type ID Number...
int Slot = Table.getValSlot(Plane.front()->getType());
int Slot = Table.getSlot(Plane.front()->getType());
assert (Slot != -1 && "Type in constant pool but not in function!!");
output_vbr((unsigned)Slot, Out);
@ -174,7 +174,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// Output the types for the global variables in the module...
for (Module::const_giterator I = M->gbegin(), End = M->gend(); I != End;++I) {
int Slot = Table.getValSlot(I->getType());
int Slot = Table.getSlot(I->getType());
assert(Slot != -1 && "Module global vars is broken!");
// Fields: bit0 = isConstant, bit1 = hasInitializer, bit2,3=Linkage,
@ -185,21 +185,21 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// If we have an initializer, output it now.
if (I->hasInitializer()) {
Slot = Table.getValSlot((Value*)I->getInitializer());
Slot = Table.getSlot((Value*)I->getInitializer());
assert(Slot != -1 && "No slot for global var initializer!");
output_vbr((unsigned)Slot, Out);
}
}
output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out);
output_vbr((unsigned)Table.getSlot(Type::VoidTy), Out);
// Output the types of the functions in this module...
for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) {
int Slot = Table.getValSlot(I->getType());
int Slot = Table.getSlot(I->getType());
assert(Slot != -1 && "Module const pool is broken!");
assert(Slot >= Type::FirstDerivedTyID && "Derived type not in range!");
output_vbr((unsigned)Slot, Out);
}
output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out);
output_vbr((unsigned)Table.getSlot(Type::VoidTy), Out);
align32(Out);
}
@ -248,13 +248,13 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
// Symtab block header: [num entries][type id number]
output_vbr(MST.type_size(TI->first), Out);
Slot = Table.getValSlot(TI->first);
Slot = Table.getSlot(TI->first);
assert(Slot != -1 && "Type in symtab, but not in table!");
output_vbr((unsigned)Slot, Out);
for (; I != End; ++I) {
// Symtab entry: [def slot #][name]
Slot = Table.getValSlot(I->second);
Slot = Table.getSlot(I->second);
assert(Slot != -1 && "Value in symtab but has no slot number!!");
output_vbr((unsigned)Slot, Out);
output(I->first, Out, false); // Don't force alignment...

View File

@ -148,7 +148,7 @@ public:
// Qualify all internal names with a unique id.
if (!isExternal(V)) {
int valId = idTable->Table.getValSlot(V);
int valId = idTable->Table.getSlot(V);
if (valId == -1) {
GlobalIdTable::ValIdMapConstIterator I = idTable->valToIdMap.find(V);
if (I == idTable->valToIdMap.end())

View File

@ -357,7 +357,7 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
if (V->hasName()) {
Out << getLLVMName(V->getName());
} else if (Table) {
int Slot = Table->getValSlot(V);
int Slot = Table->getSlot(V);
if (Slot >= 0)
Out << "%" << Slot;
else
@ -405,7 +405,7 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
} else {
int Slot;
if (Table) {
Slot = Table->getValSlot(V);
Slot = Table->getSlot(V);
} else {
if (const Type *Ty = dyn_cast<Type>(V)) {
Out << Ty->getDescription();
@ -415,7 +415,7 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
Table = createSlotCalculator(V);
if (Table == 0) { Out << "BAD VALUE TYPE!"; return; }
Slot = Table->getValSlot(V);
Slot = Table->getSlot(V);
delete Table;
}
if (Slot >= 0) Out << "%" << Slot;
@ -706,7 +706,7 @@ void AssemblyWriter::printArgument(const Argument *Arg) {
// Output name, if available...
if (Arg->hasName())
Out << " " << getLLVMName(Arg->getName());
else if (Table.getValSlot(Arg) < 0)
else if (Table.getSlot(Arg) < 0)
Out << "<badref>";
}
@ -716,7 +716,7 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
if (BB->hasName()) { // Print out the label if it exists...
Out << "\n" << BB->getName() << ":";
} else if (!BB->use_empty()) { // Don't print block # of no uses...
int Slot = Table.getValSlot(BB);
int Slot = Table.getSlot(BB);
Out << "\n; <label>:";
if (Slot >= 0)
Out << Slot; // Extra newline separates out label's
@ -756,7 +756,7 @@ void AssemblyWriter::printInfoComment(const Value &V) {
printType(V.getType()) << ">";
if (!V.hasName()) {
int Slot = Table.getValSlot(&V); // Print out the def slot taken...
int Slot = Table.getSlot(&V); // Print out the def slot taken...
if (Slot >= 0) Out << ":" << Slot;
else Out << ":<badref>";
}

View File

@ -35,7 +35,7 @@ SlotCalculator::SlotCalculator(const Module *M, bool IgnoreNamed) {
//
for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
assert(Type::getPrimitiveType((Type::PrimitiveID)i));
insertVal(Type::getPrimitiveType((Type::PrimitiveID)i), true);
insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
}
if (M == 0) return; // Empty table...
@ -51,7 +51,7 @@ SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
//
for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
assert(Type::getPrimitiveType((Type::PrimitiveID)i));
insertVal(Type::getPrimitiveType((Type::PrimitiveID)i), true);
insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
}
if (TheModule == 0) return; // Empty table...
@ -71,21 +71,21 @@ void SlotCalculator::processModule() {
//
for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
// Scavenge the types out of the functions, then add the functions themselves
// to the value table...
//
for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
// Add all of the module level constants used as initializers
//
for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
I != E; ++I)
if (I->hasInitializer())
insertValue(I->getInitializer());
getOrCreateSlot(I->getInitializer());
// Insert constants that are named at module level into the slot pool so that
// the module symbol table can refer to them...
@ -105,7 +105,7 @@ void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
for (SymbolTable::type_const_iterator TI = I->second.begin(),
TE = I->second.end(); TI != TE; ++TI)
insertValue(TI->second);
getOrCreateSlot(TI->second);
}
void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
@ -113,7 +113,7 @@ void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
for (SymbolTable::type_const_iterator TI = I->second.begin(),
TE = I->second.end(); TI != TE; ++TI)
if (isa<Constant>(TI->second))
insertValue(TI->second);
getOrCreateSlot(TI->second);
}
@ -130,7 +130,7 @@ void SlotCalculator::incorporateFunction(const Function *M) {
// Iterate over function arguments, adding them to the value table...
for(Function::const_aiterator I = M->abegin(), E = M->aend(); I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
// Iterate over all of the instructions in the function, looking for constant
// values that are referenced. Add these to the value pools before any
@ -147,7 +147,7 @@ void SlotCalculator::incorporateFunction(const Function *M) {
// Emit all of the constants that are being used by the instructions in the
// function...
for_each(constant_begin(M), constant_end(M),
bind_obj(this, &SlotCalculator::insertValue));
bind_obj(this, &SlotCalculator::getOrCreateSlot));
// If there is a symbol table, it is possible that the user has names for
// constants that are not being used. In this case, we will have problems
@ -162,13 +162,13 @@ void SlotCalculator::incorporateFunction(const Function *M) {
// Iterate over basic blocks, adding them to the value table...
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
insertValue(I);
getOrCreateSlot(I);
SC_DEBUG("Inserting Instructions:\n");
// Add all of the instructions to the type planes...
for_each(inst_begin(M), inst_end(M),
bind_obj(this, &SlotCalculator::insertValue));
bind_obj(this, &SlotCalculator::getOrCreateSlot));
if (!IgnoreNamedNodes) {
SC_DEBUG("Inserting SymbolTable values:\n");
@ -219,7 +219,7 @@ void SlotCalculator::purgeFunction() {
SC_DEBUG("end purgeFunction!\n");
}
int SlotCalculator::getValSlot(const Value *D) const {
int SlotCalculator::getSlot(const Value *D) const {
std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(D);
if (I == NodeMap.end()) return -1;
@ -227,8 +227,8 @@ int SlotCalculator::getValSlot(const Value *D) const {
}
int SlotCalculator::insertValue(const Value *V) {
int SlotNo = getValSlot(V); // Check to see if it's already in!
int SlotCalculator::getOrCreateSlot(const Value *V) {
int SlotNo = getSlot(V); // Check to see if it's already in!
if (SlotNo != -1) return SlotNo;
if (!isa<GlobalValue>(V))
@ -238,16 +238,16 @@ int SlotCalculator::insertValue(const Value *V) {
//
for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
I != E; ++I)
insertValue(*I);
getOrCreateSlot(*I);
}
return insertVal(V);
return insertValue(V);
}
int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
int SlotCalculator::insertValue(const Value *D, bool dontIgnore) {
assert(D && "Can't insert a null value!");
assert(getValSlot(D) == -1 && "Value is already in the table!");
assert(getSlot(D) == -1 && "Value is already in the table!");
// If this node does not contribute to a plane, or if the node has a
// name and we don't want names, then ignore the silly node... Note that types
@ -270,12 +270,9 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
//
// global { \2 * } { { \2 }* null }
//
int ResultSlot;
if ((ResultSlot = getValSlot(TheTy)) == -1) {
ResultSlot = doInsertVal(TheTy);
SC_DEBUG(" Inserted type: " << TheTy->getDescription() << " slot=" <<
ResultSlot << "\n");
}
int ResultSlot = doInsertValue(TheTy);
SC_DEBUG(" Inserted type: " << TheTy->getDescription() << " slot=" <<
ResultSlot << "\n");
// Loop over any contained types in the definition... in depth first order.
//
@ -284,9 +281,9 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
if (*I != TheTy) {
// If we haven't seen this sub type before, add it to our type table!
const Type *SubTy = *I;
if (getValSlot(SubTy) == -1) {
if (getSlot(SubTy) == -1) {
SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << "\n");
int Slot = doInsertVal(SubTy);
int Slot = doInsertValue(SubTy);
SC_DEBUG(" Inserted subtype: " << SubTy->getDescription() <<
" slot=" << Slot << "\n");
}
@ -295,13 +292,14 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
}
// Okay, everything is happy, actually insert the silly value now...
return doInsertVal(D);
return doInsertValue(D);
}
// doInsertVal - This is a small helper function to be called only be insertVal.
// doInsertValue - This is a small helper function to be called only
// be insertValue.
//
int SlotCalculator::doInsertVal(const Value *D) {
int SlotCalculator::doInsertValue(const Value *D) {
const Type *Typ = D->getType();
unsigned Ty;
@ -310,10 +308,10 @@ int SlotCalculator::doInsertVal(const Value *D) {
// cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n";
if (Typ->isDerivedType()) {
int ValSlot = getValSlot(Typ);
int ValSlot = getSlot(Typ);
if (ValSlot == -1) { // Have we already entered this type?
// Nope, this is the first we have seen the type, process it.
ValSlot = insertVal(Typ, true);
ValSlot = insertValue(Typ, true);
assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
}
Ty = (unsigned)ValSlot;