* Move include/llvm/Analysis/SlotCalculator.h to include/llvm/SlotCalculator.h

because the slot calculator is already part of the VMCore library.
* Rename incorporateMethod and purgeMethod to *Function


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2154 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-04-07 22:49:37 +00:00
parent 94202988a8
commit b579400cd7
10 changed files with 82 additions and 72 deletions

View File

@ -1,13 +1,17 @@
//===-- llvm/Analysis/SlotCalculator.h - Calculate value slots ---*- C++ -*-==// //===-- llvm/SlotCalculator.h - Calculate value slots ------------*- C++ -*-==//
// //
// This ModuleAnalyzer subclass calculates the slots that values will land in. // This class calculates the slots that values will land in. This is useful for
// This is useful for when writing bytecode or assembly out, because you have // when writing bytecode or assembly out, because you have to know these things.
// to know these things. //
// Specifically, this class calculates the "type plane numbering" that you see
// for a function if you strip out all of the symbols in it. For assembly
// writing, this is used when a symbol does not have a name. For bytecode
// writing, this is always used, and the symbol table is added on later.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H #ifndef LLVM_SLOTCALCULATOR_H
#define LLVM_ANALYSIS_SLOTCALCULATOR_H #define LLVM_SLOTCALCULATOR_H
#include "llvm/SymTabValue.h" #include "llvm/SymTabValue.h"
#include <vector> #include <vector>
@ -25,7 +29,7 @@ class SlotCalculator {
std::map<const Value *, unsigned> NodeMap; std::map<const Value *, unsigned> NodeMap;
// ModuleLevel - Used to keep track of which values belong to the module, // ModuleLevel - Used to keep track of which values belong to the module,
// and which values belong to the currently incorporated method. // and which values belong to the currently incorporated function.
// //
std::vector<unsigned> ModuleLevel; std::vector<unsigned> ModuleLevel;
@ -47,11 +51,11 @@ public:
return Table[Plane]; return Table[Plane];
} }
// If you'd like to deal with a method, use these two methods to get its data // If you'd like to deal with a function, use these two methods to get its
// into the SlotCalculator! // data into the SlotCalculator!
// //
void incorporateMethod(const Function *F); void incorporateFunction(const Function *F);
void purgeMethod(); void purgeFunction();
protected: protected:
// insertVal - Insert a value into the value table... Return the slot that it // insertVal - Insert a value into the value table... Return the slot that it
@ -68,7 +72,7 @@ protected:
// doInsertVal - Small helper function to be called only be insertVal. // doInsertVal - Small helper function to be called only be insertVal.
int doInsertVal(const Value *D); int doInsertVal(const Value *D);
// processModule - Process all of the module level method declarations and // processModule - Process all of the module level function declarations and
// types that are available. // types that are available.
// //
void processModule(); void processModule();

View File

@ -1,13 +1,17 @@
//===-- llvm/Analysis/SlotCalculator.h - Calculate value slots ---*- C++ -*-==// //===-- llvm/SlotCalculator.h - Calculate value slots ------------*- C++ -*-==//
// //
// This ModuleAnalyzer subclass calculates the slots that values will land in. // This class calculates the slots that values will land in. This is useful for
// This is useful for when writing bytecode or assembly out, because you have // when writing bytecode or assembly out, because you have to know these things.
// to know these things. //
// Specifically, this class calculates the "type plane numbering" that you see
// for a function if you strip out all of the symbols in it. For assembly
// writing, this is used when a symbol does not have a name. For bytecode
// writing, this is always used, and the symbol table is added on later.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H #ifndef LLVM_SLOTCALCULATOR_H
#define LLVM_ANALYSIS_SLOTCALCULATOR_H #define LLVM_SLOTCALCULATOR_H
#include "llvm/SymTabValue.h" #include "llvm/SymTabValue.h"
#include <vector> #include <vector>
@ -25,7 +29,7 @@ class SlotCalculator {
std::map<const Value *, unsigned> NodeMap; std::map<const Value *, unsigned> NodeMap;
// ModuleLevel - Used to keep track of which values belong to the module, // ModuleLevel - Used to keep track of which values belong to the module,
// and which values belong to the currently incorporated method. // and which values belong to the currently incorporated function.
// //
std::vector<unsigned> ModuleLevel; std::vector<unsigned> ModuleLevel;
@ -47,11 +51,11 @@ public:
return Table[Plane]; return Table[Plane];
} }
// If you'd like to deal with a method, use these two methods to get its data // If you'd like to deal with a function, use these two methods to get its
// into the SlotCalculator! // data into the SlotCalculator!
// //
void incorporateMethod(const Function *F); void incorporateFunction(const Function *F);
void purgeMethod(); void purgeFunction();
protected: protected:
// insertVal - Insert a value into the value table... Return the slot that it // insertVal - Insert a value into the value table... Return the slot that it
@ -68,7 +72,7 @@ protected:
// doInsertVal - Small helper function to be called only be insertVal. // doInsertVal - Small helper function to be called only be insertVal.
int doInsertVal(const Value *D); int doInsertVal(const Value *D);
// processModule - Process all of the module level method declarations and // processModule - Process all of the module level function declarations and
// types that are available. // types that are available.
// //
void processModule(); void processModule();

View File

@ -9,7 +9,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Analysis/SlotCalculator.h" #include "llvm/SlotCalculator.h"
#include "llvm/Analysis/ConstantsScanner.h" #include "llvm/Analysis/ConstantsScanner.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
@ -60,7 +60,7 @@ SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
if (TheModule == 0) return; // Empty table... if (TheModule == 0) return; // Empty table...
processModule(); // Process module level stuff processModule(); // Process module level stuff
incorporateMethod(M); // Start out in incorporated state incorporateFunction(M); // Start out in incorporated state
} }
@ -119,7 +119,7 @@ void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
} }
void SlotCalculator::incorporateMethod(const Function *M) { void SlotCalculator::incorporateFunction(const Function *M) {
assert(ModuleLevel.size() == 0 && "Module already incorporated!"); assert(ModuleLevel.size() == 0 && "Module already incorporated!");
SC_DEBUG("begin processFunction!\n"); SC_DEBUG("begin processFunction!\n");
@ -182,7 +182,7 @@ void SlotCalculator::incorporateMethod(const Function *M) {
SC_DEBUG("end processFunction!\n"); SC_DEBUG("end processFunction!\n");
} }
void SlotCalculator::purgeMethod() { void SlotCalculator::purgeFunction() {
assert(ModuleLevel.size() != 0 && "Module not incorporated!"); assert(ModuleLevel.size() != 0 && "Module not incorporated!");
unsigned NumModuleTypes = ModuleLevel.size(); unsigned NumModuleTypes = ModuleLevel.size();

View File

@ -1,13 +1,17 @@
//===-- llvm/Analysis/SlotCalculator.h - Calculate value slots ---*- C++ -*-==// //===-- llvm/SlotCalculator.h - Calculate value slots ------------*- C++ -*-==//
// //
// This ModuleAnalyzer subclass calculates the slots that values will land in. // This class calculates the slots that values will land in. This is useful for
// This is useful for when writing bytecode or assembly out, because you have // when writing bytecode or assembly out, because you have to know these things.
// to know these things. //
// Specifically, this class calculates the "type plane numbering" that you see
// for a function if you strip out all of the symbols in it. For assembly
// writing, this is used when a symbol does not have a name. For bytecode
// writing, this is always used, and the symbol table is added on later.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H #ifndef LLVM_SLOTCALCULATOR_H
#define LLVM_ANALYSIS_SLOTCALCULATOR_H #define LLVM_SLOTCALCULATOR_H
#include "llvm/SymTabValue.h" #include "llvm/SymTabValue.h"
#include <vector> #include <vector>
@ -25,7 +29,7 @@ class SlotCalculator {
std::map<const Value *, unsigned> NodeMap; std::map<const Value *, unsigned> NodeMap;
// ModuleLevel - Used to keep track of which values belong to the module, // ModuleLevel - Used to keep track of which values belong to the module,
// and which values belong to the currently incorporated method. // and which values belong to the currently incorporated function.
// //
std::vector<unsigned> ModuleLevel; std::vector<unsigned> ModuleLevel;
@ -47,11 +51,11 @@ public:
return Table[Plane]; return Table[Plane];
} }
// If you'd like to deal with a method, use these two methods to get its data // If you'd like to deal with a function, use these two methods to get its
// into the SlotCalculator! // data into the SlotCalculator!
// //
void incorporateMethod(const Function *F); void incorporateFunction(const Function *F);
void purgeMethod(); void purgeFunction();
protected: protected:
// insertVal - Insert a value into the value table... Return the slot that it // insertVal - Insert a value into the value table... Return the slot that it
@ -68,7 +72,7 @@ protected:
// doInsertVal - Small helper function to be called only be insertVal. // doInsertVal - Small helper function to be called only be insertVal.
int doInsertVal(const Value *D); int doInsertVal(const Value *D);
// processModule - Process all of the module level method declarations and // processModule - Process all of the module level function declarations and
// types that are available. // types that are available.
// //
void processModule(); void processModule();

View File

@ -2,9 +2,6 @@
// //
// This library implements the functionality defined in llvm/Bytecode/Writer.h // This library implements the functionality defined in llvm/Bytecode/Writer.h
// //
// This library uses the Analysis library to figure out offsets for
// variables in the method tables...
//
// Note that this file uses an unusual technique of outputting all the bytecode // Note that this file uses an unusual technique of outputting all the bytecode
// to a deque of unsigned char's, then copies the deque to an ostream. The // to a deque of unsigned char's, then copies the deque to an ostream. The
// reason for this is that we must do "seeking" in the stream to do back- // reason for this is that we must do "seeking" in the stream to do back-
@ -46,13 +43,13 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M)
output_vbr((unsigned)Type::FirstDerivedTyID, Out); output_vbr((unsigned)Type::FirstDerivedTyID, Out);
align32(Out); align32(Out);
// Output module level constants, including types used by the method protos // Output module level constants, including types used by the function protos
outputConstants(false); outputConstants(false);
// The ModuleInfoBlock follows directly after the Module constant pool // The ModuleInfoBlock follows directly after the Module constant pool
outputModuleInfoBlock(M); outputModuleInfoBlock(M);
// Do the whole module now! Process each method at a time... // Do the whole module now! Process each function at a time...
for_each(M->begin(), M->end(), for_each(M->begin(), M->end(),
bind_obj(this, &BytecodeWriter::processMethod)); bind_obj(this, &BytecodeWriter::processMethod));
@ -75,7 +72,7 @@ void BytecodeWriter::outputConstants(bool isFunction) {
else if (pno == Type::TypeTyID) else if (pno == Type::TypeTyID)
ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types... ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types...
// Scan through and ignore method arguments... // Scan through and ignore function arguments...
for (; ValNo < Plane.size() && isa<FunctionArgument>(Plane[ValNo]); ValNo++) for (; ValNo < Plane.size() && isa<FunctionArgument>(Plane[ValNo]); ValNo++)
/*empty*/; /*empty*/;
@ -92,7 +89,7 @@ void BytecodeWriter::outputConstants(bool isFunction) {
// Output the Type ID Number... // Output the Type ID Number...
int Slot = Table.getValSlot(Plane.front()->getType()); int Slot = Table.getValSlot(Plane.front()->getType());
assert (Slot != -1 && "Type in constant pool but not in method!!"); assert (Slot != -1 && "Type in constant pool but not in function!!");
output_vbr((unsigned)Slot, Out); output_vbr((unsigned)Slot, Out);
//cerr << "Emitting " << NC << " constants of type '" //cerr << "Emitting " << NC << " constants of type '"
@ -136,7 +133,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
} }
output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out); output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out);
// Output the types of the methods in this module... // Output the types of the functions in this module...
for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) { for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) {
int Slot = Table.getValSlot((*I)->getType()); int Slot = Table.getValSlot((*I)->getType());
assert(Slot != -1 && "Module const pool is broken!"); assert(Slot != -1 && "Module const pool is broken!");
@ -155,21 +152,21 @@ void BytecodeWriter::processMethod(const Function *M) {
// Only output the constant pool and other goodies if needed... // Only output the constant pool and other goodies if needed...
if (!M->isExternal()) { if (!M->isExternal()) {
// Get slot information about the method... // Get slot information about the function...
Table.incorporateMethod(M); Table.incorporateFunction(M);
// Output information about the constants in the method... // Output information about the constants in the function...
outputConstants(true); outputConstants(true);
// Output basic block nodes... // Output basic block nodes...
for_each(M->begin(), M->end(), for_each(M->begin(), M->end(),
bind_obj(this, &BytecodeWriter::processBasicBlock)); bind_obj(this, &BytecodeWriter::processBasicBlock));
// If needed, output the symbol table for the method... // If needed, output the symbol table for the function...
if (M->hasSymbolTable()) if (M->hasSymbolTable())
outputSymbolTable(*M->getSymbolTable()); outputSymbolTable(*M->getSymbolTable());
Table.purgeMethod(); Table.purgeFunction();
} }
} }

View File

@ -14,8 +14,8 @@
#include "llvm/Bytecode/Writer.h" #include "llvm/Bytecode/Writer.h"
#include "llvm/Bytecode/Format.h" #include "llvm/Bytecode/Format.h"
#include "llvm/Analysis/SlotCalculator.h"
#include "llvm/Bytecode/Primitives.h" #include "llvm/Bytecode/Primitives.h"
#include "llvm/SlotCalculator.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include <deque> #include <deque>

View File

@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "SparcInternals.h" #include "SparcInternals.h"
#include "llvm/Analysis/SlotCalculator.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineCodeForMethod.h" #include "llvm/CodeGen/MachineCodeForMethod.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
@ -22,6 +21,7 @@
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/SlotCalculator.h"
#include "Support/StringExtras.h" #include "Support/StringExtras.h"
#include "Support/HashExtras.h" #include "Support/HashExtras.h"
#include <iostream> #include <iostream>
@ -84,11 +84,11 @@ public:
} }
} }
void startFunction(Function *F) { void startFunction(Function *F) {
// Make sure the slot table has information about this method... // Make sure the slot table has information about this function...
idTable->Table->incorporateMethod(F); idTable->Table->incorporateFunction(F);
} }
void endFunction(Function *F) { void endFunction(Function *F) {
idTable->Table->purgeMethod(); // Forget all about F idTable->Table->purgeFunction(); // Forget all about F
} }
void endModule() { void endModule() {
} }

View File

@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Assembly/CachedWriter.h" #include "llvm/Assembly/CachedWriter.h"
#include "llvm/Analysis/SlotCalculator.h" #include "llvm/SlotCalculator.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
@ -319,7 +319,7 @@ void AssemblyWriter::printModule(const Module *M) {
Out << "implementation\n"; Out << "implementation\n";
// Output all of the methods... // Output all of the functions...
for_each(M->begin(), M->end(), bind_obj(this,&AssemblyWriter::printFunction)); for_each(M->begin(), M->end(), bind_obj(this,&AssemblyWriter::printFunction));
} }
@ -386,14 +386,14 @@ void AssemblyWriter::printConstant(const Constant *CPV) {
Out << "\n"; Out << "\n";
} }
// printFunction - Print all aspects of a method. // printFunction - Print all aspects of a function.
// //
void AssemblyWriter::printFunction(const Function *M) { void AssemblyWriter::printFunction(const Function *M) {
// Print out the return type and name... // Print out the return type and name...
Out << "\n" << (M->isExternal() ? "declare " : "") Out << "\n" << (M->isExternal() ? "declare " : "")
<< (M->hasInternalLinkage() ? "internal " : ""); << (M->hasInternalLinkage() ? "internal " : "");
printType(M->getReturnType()) << " \"" << M->getName() << "\"("; printType(M->getReturnType()) << " \"" << M->getName() << "\"(";
Table.incorporateMethod(M); Table.incorporateFunction(M);
// Loop over the arguments, printing them... // Loop over the arguments, printing them...
const FunctionType *MT = M->getFunctionType(); const FunctionType *MT = M->getFunctionType();
@ -425,18 +425,18 @@ void AssemblyWriter::printFunction(const Function *M) {
Out << "begin"; Out << "begin";
// Output all of its basic blocks... for the method // Output all of its basic blocks... for the function
for_each(M->begin(), M->end(), for_each(M->begin(), M->end(),
bind_obj(this, &AssemblyWriter::printBasicBlock)); bind_obj(this, &AssemblyWriter::printBasicBlock));
Out << "end\n"; Out << "end\n";
} }
Table.purgeMethod(); Table.purgeFunction();
} }
// printFunctionArgument - This member is called for every argument that // printFunctionArgument - This member is called for every argument that
// is passed into the method. Simply print it out // is passed into the function. Simply print it out
// //
void AssemblyWriter::printFunctionArgument(const FunctionArgument *Arg) { void AssemblyWriter::printFunctionArgument(const FunctionArgument *Arg) {
// Insert commas as we go... the first arg doesn't get a comma // Insert commas as we go... the first arg doesn't get a comma
@ -543,8 +543,8 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
const Type *RetTy = MTy ? MTy->getReturnType() : 0; const Type *RetTy = MTy ? MTy->getReturnType() : 0;
// If possible, print out the short form of the call instruction, but we can // If possible, print out the short form of the call instruction, but we can
// only do this if the first argument is a pointer to a nonvararg method, // only do this if the first argument is a pointer to a nonvararg function,
// and if the value returned is not a pointer to a method. // and if the value returned is not a pointer to a function.
// //
if (RetTy && !MTy->isVarArg() && if (RetTy && !MTy->isVarArg() &&
(!isa<PointerType>(RetTy)||!isa<FunctionType>(cast<PointerType>(RetTy)))){ (!isa<PointerType>(RetTy)||!isa<FunctionType>(cast<PointerType>(RetTy)))){

View File

@ -10,7 +10,7 @@
#include "llvm/SymbolTable.h" #include "llvm/SymbolTable.h"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Analysis/SlotCalculator.h" #include "llvm/SlotCalculator.h"
#include "Support/StringExtras.h" #include "Support/StringExtras.h"
#include <algorithm> #include <algorithm>
@ -259,6 +259,7 @@ std::string ConstantPointerRef::getStrValue() const {
const GlobalValue *V = getValue(); const GlobalValue *V = getValue();
if (V->hasName()) return "%" + V->getName(); if (V->hasName()) return "%" + V->getName();
// FIXME: This is a gross hack.
SlotCalculator *Table = new SlotCalculator(V->getParent(), true); SlotCalculator *Table = new SlotCalculator(V->getParent(), true);
int Slot = Table->getValSlot(V); int Slot = Table->getValSlot(V);
delete Table; delete Table;

View File

@ -9,7 +9,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Analysis/SlotCalculator.h" #include "llvm/SlotCalculator.h"
#include "llvm/Analysis/ConstantsScanner.h" #include "llvm/Analysis/ConstantsScanner.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
@ -60,7 +60,7 @@ SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
if (TheModule == 0) return; // Empty table... if (TheModule == 0) return; // Empty table...
processModule(); // Process module level stuff processModule(); // Process module level stuff
incorporateMethod(M); // Start out in incorporated state incorporateFunction(M); // Start out in incorporated state
} }
@ -119,7 +119,7 @@ void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
} }
void SlotCalculator::incorporateMethod(const Function *M) { void SlotCalculator::incorporateFunction(const Function *M) {
assert(ModuleLevel.size() == 0 && "Module already incorporated!"); assert(ModuleLevel.size() == 0 && "Module already incorporated!");
SC_DEBUG("begin processFunction!\n"); SC_DEBUG("begin processFunction!\n");
@ -182,7 +182,7 @@ void SlotCalculator::incorporateMethod(const Function *M) {
SC_DEBUG("end processFunction!\n"); SC_DEBUG("end processFunction!\n");
} }
void SlotCalculator::purgeMethod() { void SlotCalculator::purgeFunction() {
assert(ModuleLevel.size() != 0 && "Module not incorporated!"); assert(ModuleLevel.size() != 0 && "Module not incorporated!");
unsigned NumModuleTypes = ModuleLevel.size(); unsigned NumModuleTypes = ModuleLevel.size();