Change references from Method to Function

change references from MethodARgument to FunctionArgument


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1991 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-03-26 18:01:55 +00:00
parent b0d04726db
commit 79df7c0aaa
21 changed files with 397 additions and 393 deletions

View File

@ -10,7 +10,7 @@
#include "llvm/SymbolTable.h"
#include "llvm/Module.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/DerivedTypes.h"
#include "llvm/iTerminators.h"
@ -135,8 +135,8 @@ static struct PerModuleInfo {
} CurModule;
static struct PerMethodInfo {
Method *CurrentMethod; // Pointer to current method being created
static struct PerFunctionInfo {
Function *CurrentFunction; // Pointer to current method being created
vector<ValueList> Values; // Keep track of numbered definitions
vector<ValueList> LateResolveValues;
@ -144,30 +144,30 @@ static struct PerMethodInfo {
map<ValID, PATypeHolder<Type> > LateResolveTypes;
bool isDeclare; // Is this method a forward declararation?
inline PerMethodInfo() {
CurrentMethod = 0;
inline PerFunctionInfo() {
CurrentFunction = 0;
isDeclare = false;
}
inline ~PerMethodInfo() {}
inline ~PerFunctionInfo() {}
inline void MethodStart(Method *M) {
CurrentMethod = M;
inline void FunctionStart(Function *M) {
CurrentFunction = M;
}
void MethodDone() {
void FunctionDone() {
// If we could not resolve some blocks at parsing time (forward branches)
// resolve the branches now...
ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
Values.clear(); // Clear out method local definitions
Types.clear();
CurrentMethod = 0;
CurrentFunction = 0;
isDeclare = false;
}
} CurMeth; // Info for the current method...
static bool inMethodScope() { return CurMeth.CurrentMethod != 0; }
static bool inFunctionScope() { return CurMeth.CurrentFunction != 0; }
//===----------------------------------------------------------------------===//
@ -210,7 +210,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
case 1: { // Is it a named definition?
string Name(D.Name);
SymbolTable *SymTab = 0;
if (inMethodScope()) SymTab = CurMeth.CurrentMethod->getSymbolTable();
if (inFunctionScope()) SymTab = CurMeth.CurrentFunction->getSymbolTable();
Value *N = SymTab ? SymTab->lookup(Type::TypeTy, Name) : 0;
if (N == 0) {
@ -236,7 +236,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
//
if (DoNotImprovise) return 0; // Do we just want a null to be returned?
map<ValID, PATypeHolder<Type> > &LateResolver = inMethodScope() ?
map<ValID, PATypeHolder<Type> > &LateResolver = inFunctionScope() ?
CurMeth.LateResolveTypes : CurModule.LateResolveTypes;
map<ValID, PATypeHolder<Type> >::iterator I = LateResolver.find(D);
@ -251,7 +251,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
static Value *lookupInSymbolTable(const Type *Ty, const string &Name) {
SymbolTable *SymTab =
inMethodScope() ? CurMeth.CurrentMethod->getSymbolTable() : 0;
inFunctionScope() ? CurMeth.CurrentFunction->getSymbolTable() : 0;
Value *N = SymTab ? SymTab->lookup(Ty, Name) : 0;
if (N == 0) {
@ -271,8 +271,9 @@ static Value *lookupInSymbolTable(const Type *Ty, const string &Name) {
// it. Otherwise return null.
//
static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
if (isa<MethodType>(Ty))
ThrowException("Methods are not values and must be referenced as pointers");
if (isa<FunctionType>(Ty))
ThrowException("Functions are not values and "
"must be referenced as pointers");
switch (D.Type) {
case ValID::NumberVal: { // Is it a numbered definition?
@ -377,7 +378,7 @@ static Value *getVal(const Type *Ty, const ValID &D) {
}
assert(d != 0 && "How did we not make something?");
if (inMethodScope())
if (inFunctionScope())
InsertValue(d, CurMeth.LateResolveValues);
else
InsertValue(d, CurModule.LateResolveValues);
@ -417,7 +418,7 @@ static void ResolveDefinitions(vector<ValueList> &LateResolvers,
V->replaceAllUsesWith(TheRealValue);
delete V;
} else if (FutureLateResolvers) {
// Methods have their unresolved items forwarded to the module late
// Functions have their unresolved items forwarded to the module late
// resolver table
InsertValue(V, *FutureLateResolvers);
} else {
@ -442,14 +443,14 @@ static void ResolveDefinitions(vector<ValueList> &LateResolvers,
// refering to the number can be resolved. Do this now.
//
static void ResolveTypeTo(char *Name, const Type *ToTy) {
vector<PATypeHolder<Type> > &Types = inMethodScope() ?
vector<PATypeHolder<Type> > &Types = inFunctionScope() ?
CurMeth.Types : CurModule.Types;
ValID D;
if (Name) D = ValID::create(Name);
else D = ValID::create((int)Types.size());
map<ValID, PATypeHolder<Type> > &LateResolver = inMethodScope() ?
map<ValID, PATypeHolder<Type> > &LateResolver = inFunctionScope() ?
CurMeth.LateResolveTypes : CurModule.LateResolveTypes;
map<ValID, PATypeHolder<Type> >::iterator I = LateResolver.find(D);
@ -492,8 +493,8 @@ static bool setValueName(Value *V, char *NameStr) {
ThrowException("Can't assign name '" + Name +
"' to a null valued instruction!");
SymbolTable *ST = inMethodScope() ?
CurMeth.CurrentMethod->getSymbolTableSure() :
SymbolTable *ST = inFunctionScope() ?
CurMeth.CurrentFunction->getSymbolTableSure() :
CurModule.CurrentModule->getSymbolTableSure();
Value *Existing = ST->lookup(V->getType(), Name);
@ -626,8 +627,8 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
%union {
Module *ModuleVal;
Method *MethodVal;
std::pair<MethodArgument*,char*> *MethArgVal;
Function *FunctionVal;
std::pair<FunctionArgument*,char*> *MethArgVal;
BasicBlock *BasicBlockVal;
TerminatorInst *TermInstVal;
Instruction *InstVal;
@ -637,7 +638,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
PATypeHolder<Type> *TypeVal;
Value *ValueVal;
std::list<std::pair<MethodArgument*,char*> > *MethodArgList;
std::list<std::pair<FunctionArgument*,char*> > *FunctionArgList;
std::vector<Value*> *ValueList;
std::list<PATypeHolder<Type> > *TypeList;
std::list<std::pair<Value*,
@ -662,14 +663,14 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
Instruction::OtherOps OtherOpVal;
}
%type <ModuleVal> Module MethodList
%type <MethodVal> Method MethodProto MethodHeader BasicBlockList
%type <ModuleVal> Module FunctionList
%type <FunctionVal> Function FunctionProto FunctionHeader BasicBlockList
%type <BasicBlockVal> BasicBlock InstructionList
%type <TermInstVal> BBTerminatorInst
%type <InstVal> Inst InstVal MemoryInst
%type <ConstVal> ConstVal
%type <ConstVector> ConstVector
%type <MethodArgList> ArgList ArgListH
%type <FunctionArgList> ArgList ArgListH
%type <MethArgVal> ArgVal
%type <PHIList> PHIList
%type <ValueList> ValueRefList ValueRefListE // For call param lists
@ -807,14 +808,14 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
$$ = newTH<Type>(OT);
UR_OUT("New Upreference!\n");
}
| UpRTypesV '(' ArgTypeListI ')' { // Method derived type?
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
vector<const Type*> Params;
mapto($3->begin(), $3->end(), std::back_inserter(Params),
std::mem_fun_ref(&PATypeHandle<Type>::get));
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
if (isVarArg) Params.pop_back();
$$ = newTH(HandleUpRefs(MethodType::get(*$1, Params, isVarArg)));
$$ = newTH(HandleUpRefs(FunctionType::get(*$1, Params, isVarArg)));
delete $3; // Delete the argument list
delete $1; // Delete the old type handle
}
@ -1049,13 +1050,13 @@ ConstPool : ConstPool OptAssign CONST ConstVal {
// If this is not a redefinition of a type...
if (!$2) {
InsertType($4->get(),
inMethodScope() ? CurMeth.Types : CurModule.Types);
inFunctionScope() ? CurMeth.Types : CurModule.Types);
}
}
delete $4;
}
| ConstPool MethodProto { // Method prototypes can be in const pool
| ConstPool FunctionProto { // Function prototypes can be in const pool
}
| ConstPool OptAssign OptInternal GlobalType ConstVal {
const Type *Ty = $5->getType();
@ -1105,20 +1106,20 @@ ConstPool : ConstPool OptAssign CONST ConstVal {
// Module rule: Capture the result of parsing the whole file into a result
// variable...
//
Module : MethodList {
Module : FunctionList {
$$ = ParserResult = $1;
CurModule.ModuleDone();
}
// MethodList - A list of methods, preceeded by a constant pool.
// FunctionList - A list of methods, preceeded by a constant pool.
//
MethodList : MethodList Method {
FunctionList : FunctionList Function {
$$ = $1;
assert($2->getParent() == 0 && "Method already in module!");
$1->getMethodList().push_back($2);
CurMeth.MethodDone();
assert($2->getParent() == 0 && "Function already in module!");
$1->getFunctionList().push_back($2);
CurMeth.FunctionDone();
}
| MethodList MethodProto {
| FunctionList FunctionProto {
$$ = $1;
}
| ConstPool IMPLEMENTATION {
@ -1129,13 +1130,13 @@ MethodList : MethodList Method {
//===----------------------------------------------------------------------===//
// Rules to match Method Headers
// Rules to match Function Headers
//===----------------------------------------------------------------------===//
OptVAR_ID : VAR_ID | /*empty*/ { $$ = 0; }
ArgVal : Types OptVAR_ID {
$$ = new pair<MethodArgument*,char*>(new MethodArgument(*$1), $2);
$$ = new pair<FunctionArgument*,char*>(new FunctionArgument(*$1), $2);
delete $1; // Delete the type handle..
}
@ -1145,14 +1146,14 @@ ArgListH : ArgVal ',' ArgListH {
delete $1;
}
| ArgVal {
$$ = new list<pair<MethodArgument*,char*> >();
$$ = new list<pair<FunctionArgument*,char*> >();
$$->push_front(*$1);
delete $1;
}
| DOTDOTDOT {
$$ = new list<pair<MethodArgument*, char*> >();
$$->push_front(pair<MethodArgument*,char*>(
new MethodArgument(Type::VoidTy), 0));
$$ = new list<pair<FunctionArgument*, char*> >();
$$->push_front(pair<FunctionArgument*,char*>(
new FunctionArgument(Type::VoidTy), 0));
}
ArgList : ArgListH {
@ -1162,54 +1163,55 @@ ArgList : ArgListH {
$$ = 0;
}
MethodHeaderH : OptInternal TypesV STRINGCONSTANT '(' ArgList ')' {
FunctionHeaderH : OptInternal TypesV STRINGCONSTANT '(' ArgList ')' {
UnEscapeLexed($3);
string MethodName($3);
string FunctionName($3);
vector<const Type*> ParamTypeList;
if ($5)
for (list<pair<MethodArgument*,char*> >::iterator I = $5->begin();
for (list<pair<FunctionArgument*,char*> >::iterator I = $5->begin();
I != $5->end(); ++I)
ParamTypeList.push_back(I->first->getType());
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
if (isVarArg) ParamTypeList.pop_back();
const MethodType *MT = MethodType::get(*$2, ParamTypeList, isVarArg);
const FunctionType *MT = FunctionType::get(*$2, ParamTypeList, isVarArg);
const PointerType *PMT = PointerType::get(MT);
delete $2;
Method *M = 0;
Function *M = 0;
if (SymbolTable *ST = CurModule.CurrentModule->getSymbolTable()) {
if (Value *V = ST->lookup(PMT, MethodName)) { // Method already in symtab?
M = cast<Method>(V);
// Is the function already in symtab?
if (Value *V = ST->lookup(PMT, FunctionName)) {
M = cast<Function>(V);
// Yes it is. If this is the case, either we need to be a forward decl,
// or it needs to be.
if (!CurMeth.isDeclare && !M->isExternal())
ThrowException("Redefinition of method '" + MethodName + "'!");
ThrowException("Redefinition of method '" + FunctionName + "'!");
// If we found a preexisting method prototype, remove it from the module,
// so that we don't get spurious conflicts with global & local variables.
//
CurModule.CurrentModule->getMethodList().remove(M);
CurModule.CurrentModule->getFunctionList().remove(M);
}
}
if (M == 0) { // Not already defined?
M = new Method(MT, $1, MethodName);
M = new Function(MT, $1, FunctionName);
InsertValue(M, CurModule.Values);
CurModule.DeclareNewGlobalValue(M, ValID::create($3));
}
free($3); // Free strdup'd memory!
CurMeth.MethodStart(M);
CurMeth.FunctionStart(M);
// Add all of the arguments we parsed to the method...
if ($5 && !CurMeth.isDeclare) { // Is null if empty...
Method::ArgumentListType &ArgList = M->getArgumentList();
Function::ArgumentListType &ArgList = M->getArgumentList();
for (list<pair<MethodArgument*, char*> >::iterator I = $5->begin();
for (list<pair<FunctionArgument*, char*> >::iterator I = $5->begin();
I != $5->end(); ++I) {
if (setValueName(I->first, I->second)) { // Insert into symtab...
assert(0 && "No arg redef allowed!");
@ -1221,29 +1223,29 @@ MethodHeaderH : OptInternal TypesV STRINGCONSTANT '(' ArgList ')' {
delete $5; // We're now done with the argument list
} else if ($5) {
// If we are a declaration, we should free the memory for the argument list!
for (list<pair<MethodArgument*, char*> >::iterator I = $5->begin();
for (list<pair<FunctionArgument*, char*> >::iterator I = $5->begin();
I != $5->end(); ++I)
if (I->second) free(I->second); // Free the memory for the name...
delete $5; // Free the memory for the list itself
}
}
MethodHeader : MethodHeaderH ConstPool BEGINTOK {
$$ = CurMeth.CurrentMethod;
FunctionHeader : FunctionHeaderH ConstPool BEGINTOK {
$$ = CurMeth.CurrentFunction;
// Resolve circular types before we parse the body of the method.
ResolveTypes(CurMeth.LateResolveTypes);
}
Method : BasicBlockList END {
Function : BasicBlockList END {
$$ = $1;
}
MethodProto : DECLARE { CurMeth.isDeclare = true; } MethodHeaderH {
$$ = CurMeth.CurrentMethod;
assert($$->getParent() == 0 && "Method already in module!");
CurModule.CurrentModule->getMethodList().push_back($$);
CurMeth.MethodDone();
FunctionProto : DECLARE { CurMeth.isDeclare = true; } FunctionHeaderH {
$$ = CurMeth.CurrentFunction;
assert($$->getParent() == 0 && "Function already in module!");
CurModule.CurrentModule->getFunctionList().push_back($$);
CurMeth.FunctionDone();
}
//===----------------------------------------------------------------------===//
@ -1300,7 +1302,7 @@ ResolvedVal : Types ValueRef {
BasicBlockList : BasicBlockList BasicBlock {
($$ = $1)->getBasicBlocks().push_back($2);
}
| MethodHeader BasicBlock { // Do not allow methods with 0 basic blocks
| FunctionHeader BasicBlock { // Do not allow methods with 0 basic blocks
($$ = $1)->getBasicBlocks().push_back($2);
}
@ -1362,10 +1364,10 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
| INVOKE TypesV ValueRef '(' ValueRefListE ')' TO ResolvedVal
EXCEPT ResolvedVal {
const PointerType *PMTy;
const MethodType *Ty;
const FunctionType *Ty;
if (!(PMTy = dyn_cast<PointerType>($2->get())) ||
!(Ty = dyn_cast<MethodType>(PMTy->getElementType()))) {
!(Ty = dyn_cast<FunctionType>(PMTy->getElementType()))) {
// Pull out the types of all of the arguments...
vector<const Type*> ParamTypes;
if ($5) {
@ -1376,7 +1378,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
if (isVarArg) ParamTypes.pop_back();
Ty = MethodType::get($2->get(), ParamTypes, isVarArg);
Ty = FunctionType::get($2->get(), ParamTypes, isVarArg);
PMTy = PointerType::get(Ty);
}
delete $2;
@ -1393,11 +1395,11 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
if (!$5) { // Has no arguments?
$$ = new InvokeInst(V, Normal, Except, vector<Value*>());
} else { // Has arguments?
// Loop through MethodType's arguments and ensure they are specified
// Loop through FunctionType's arguments and ensure they are specified
// correctly!
//
MethodType::ParamTypes::const_iterator I = Ty->getParamTypes().begin();
MethodType::ParamTypes::const_iterator E = Ty->getParamTypes().end();
FunctionType::ParamTypes::const_iterator I = Ty->getParamTypes().begin();
FunctionType::ParamTypes::const_iterator E = Ty->getParamTypes().end();
vector<Value*>::iterator ArgI = $5->begin(), ArgE = $5->end();
for (; ArgI != ArgE && I != E; ++ArgI, ++I)
@ -1498,10 +1500,10 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef {
}
| CALL TypesV ValueRef '(' ValueRefListE ')' {
const PointerType *PMTy;
const MethodType *Ty;
const FunctionType *Ty;
if (!(PMTy = dyn_cast<PointerType>($2->get())) ||
!(Ty = dyn_cast<MethodType>(PMTy->getElementType()))) {
!(Ty = dyn_cast<FunctionType>(PMTy->getElementType()))) {
// Pull out the types of all of the arguments...
vector<const Type*> ParamTypes;
if ($5) {
@ -1512,7 +1514,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef {
bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
if (isVarArg) ParamTypes.pop_back();
Ty = MethodType::get($2->get(), ParamTypes, isVarArg);
Ty = FunctionType::get($2->get(), ParamTypes, isVarArg);
PMTy = PointerType::get(Ty);
}
delete $2;
@ -1523,11 +1525,11 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef {
if (!$5) { // Has no arguments?
$$ = new CallInst(V, vector<Value*>());
} else { // Has arguments?
// Loop through MethodType's arguments and ensure they are specified
// Loop through FunctionType's arguments and ensure they are specified
// correctly!
//
MethodType::ParamTypes::const_iterator I = Ty->getParamTypes().begin();
MethodType::ParamTypes::const_iterator E = Ty->getParamTypes().end();
FunctionType::ParamTypes::const_iterator I = Ty->getParamTypes().begin();
FunctionType::ParamTypes::const_iterator E = Ty->getParamTypes().end();
vector<Value*>::iterator ArgI = $5->begin(), ArgE = $5->end();
for (; ArgI != ArgE && I != E; ++ArgI, ++I)

View File

@ -280,12 +280,12 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
const MethodType::ParamTypes &Params = MTy->getParamTypes();
for (MethodType::ParamTypes::const_iterator It = Params.begin();
It != Params.end(); ++It) {
MethodArgument *MA = new MethodArgument(*It);
if (insertValue(MA, Values) == -1) {
FunctionArgument *FA = new FunctionArgument(*It);
if (insertValue(FA, Values) == -1) {
Error = "Error reading method arguments!\n";
delete M; return failure(true);
}
M->getArgumentList().push_back(MA);
M->getArgumentList().push_back(FA);
}
while (Buf < EndBuf) {
@ -352,7 +352,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
getTypeSlot(PMTy, type);
C->getMethodList().push_back(M);
C->getFunctionList().push_back(M);
// Replace placeholder with the real method pointer...
ModuleValues[type][MethSlot] = M;

View File

@ -25,7 +25,7 @@
#include "WriterInternals.h"
#include "llvm/Module.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/ConstantVals.h"
#include "llvm/SymbolTable.h"
@ -61,7 +61,7 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M)
outputSymbolTable(*M->getSymbolTable());
}
void BytecodeWriter::outputConstants(bool isMethod) {
void BytecodeWriter::outputConstants(bool isFunction) {
BytecodeBlock CPool(BytecodeFormat::ConstantPool, Out);
unsigned NumPlanes = Table.getNumPlanes();
@ -70,13 +70,13 @@ void BytecodeWriter::outputConstants(bool isMethod) {
if (Plane.empty()) continue; // Skip empty type planes...
unsigned ValNo = 0;
if (isMethod) // Don't reemit module constants
if (isFunction) // Don't reemit module constants
ValNo = Table.getModuleLevel(pno);
else if (pno == Type::TypeTyID)
ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types...
// Scan through and ignore method arguments...
for (; ValNo < Plane.size() && isa<MethodArgument>(Plane[ValNo]); ValNo++)
for (; ValNo < Plane.size() && isa<FunctionArgument>(Plane[ValNo]); ValNo++)
/*empty*/;
unsigned NC = ValNo; // Number of constants
@ -149,8 +149,8 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
align32(Out);
}
void BytecodeWriter::processMethod(const Method *M) {
BytecodeBlock MethodBlock(BytecodeFormat::Method, Out);
void BytecodeWriter::processMethod(const Function *M) {
BytecodeBlock FunctionBlock(BytecodeFormat::Method, Out);
output_vbr((unsigned)M->hasInternalLinkage(), Out);
// Only output the constant pool and other goodies if needed...
if (!M->isExternal()) {
@ -175,14 +175,14 @@ void BytecodeWriter::processMethod(const Method *M) {
void BytecodeWriter::processBasicBlock(const BasicBlock *BB) {
BytecodeBlock MethodBlock(BytecodeFormat::BasicBlock, Out);
BytecodeBlock FunctionBlock(BytecodeFormat::BasicBlock, Out);
// Process all the instructions in the bb...
for_each(BB->begin(), BB->end(),
bind_obj(this, &BytecodeWriter::processInstruction));
}
void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
BytecodeBlock MethodBlock(BytecodeFormat::SymbolTable, Out);
BytecodeBlock FunctionBlock(BytecodeFormat::SymbolTable, Out);
for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) {
SymbolTable::type_const_iterator I = MST.type_begin(TI->first);

View File

@ -24,7 +24,7 @@
#include "llvm/CodeGen/InstrForest.h"
#include "llvm/CodeGen/MachineCodeForInstruction.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/iTerminators.h"
#include "llvm/iMemory.h"
#include "llvm/iPHINode.h"
@ -188,10 +188,10 @@ LabelNode::dumpNode(int indent) const
// A forest of instruction trees, usually for a single method.
//------------------------------------------------------------------------
InstrForest::InstrForest(Method *M)
InstrForest::InstrForest(Function *F)
{
for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
BasicBlock *BB = *MI;
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
BasicBlock *BB = *FI;
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
buildTreeForInstruction(*I);
}
@ -302,11 +302,11 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
// Check latter condition here just to simplify the next IF.
bool includeAddressOperand =
(isa<BasicBlock>(operand) || isa<Method>(operand))
(isa<BasicBlock>(operand) || isa<Function>(operand))
&& !instr->isTerminator();
if (includeAddressOperand || isa<Instruction>(operand) ||
isa<Constant>(operand) || isa<MethodArgument>(operand) ||
isa<Constant>(operand) || isa<FunctionArgument>(operand) ||
isa<GlobalVariable>(operand))
{
// This operand is a data value

View File

@ -11,7 +11,7 @@
#include "llvm/Transforms/Linker.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/GlobalVariable.h"
#include "llvm/SymbolTable.h"
@ -165,8 +165,8 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
(V = ST->lookup(SGV->getType(), SGV->getName())) &&
cast<GlobalVariable>(V)->hasExternalLinkage()) {
// The same named thing is a global variable, because the only two things
// that may be in a module level symbol table are Global Vars and Methods,
// and they both have distinct, nonoverlapping, possible types.
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
GlobalVariable *DGV = cast<GlobalVariable>(V);
@ -231,11 +231,11 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
return false;
}
// LinkMethodProtos - Link the methods together between the two modules, without
// doing method bodies... this just adds external method prototypes to the Dest
// method...
// LinkFunctionProtos - Link the functions together between the two modules,
// without doing method bodies... this just adds external method prototypes to
// the Dest function...
//
static bool LinkMethodProtos(Module *Dest, const Module *Src,
static bool LinkFunctionProtos(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap,
string *Err = 0) {
// We will need a module level symbol table if the src module has a module
@ -245,7 +245,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
// Loop over all of the methods in the src module, mapping them over as we go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Method *SM = *I; // SrcMethod
const Function *SM = *I; // SrcFunction
Value *V;
// If the method has a name, and that name is already in use in the
@ -253,29 +253,29 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
//
if (SM->hasExternalLinkage() && SM->hasName() &&
(V = ST->lookup(SM->getType(), SM->getName())) &&
cast<Method>(V)->hasExternalLinkage()) {
// The same named thing is a Method, because the only two things
// that may be in a module level symbol table are Global Vars and Methods,
// and they both have distinct, nonoverlapping, possible types.
cast<Function>(V)->hasExternalLinkage()) {
// The same named thing is a Function, because the only two things
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
Method *DM = cast<Method>(V); // DestMethod
Function *DM = cast<Function>(V); // DestFunction
// Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Method '" +
return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" +
SM->getName() + "\" - Method is already defined!");
SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
ValueMap.insert(std::make_pair(SM, DM));
} else {
// Method does not already exist, simply insert an external method
// Function does not already exist, simply insert an external method
// signature identical to SM into the dest module...
Method *DM = new Method(SM->getMethodType(), SM->hasInternalLinkage(),
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(),
SM->getName());
// Add the method signature to the dest module...
Dest->getMethodList().push_back(DM);
Dest->getFunctionList().push_back(DM);
// ... and remember this mapping...
ValueMap.insert(std::make_pair(SM, DM));
@ -284,24 +284,24 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
return false;
}
// LinkMethodBody - Copy the source method over into the dest method and fix up
// references to values. At this point we know that Dest is an external method,
// and that Src is not.
// LinkFunctionBody - Copy the source method over into the dest method
// and fix up references to values. At this point we know that Dest
// is an external method, and that Src is not.
//
static bool LinkMethodBody(Method *Dest, const Method *Src,
static bool LinkFunctionBody(Function *Dest, const Function *Src,
const map<const Value*, Value*> &GlobalMap,
string *Err = 0) {
assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
map<const Value*, Value*> LocalMap; // Map for method local values
// Go through and convert method arguments over...
for (Method::ArgumentListType::const_iterator
for (Function::ArgumentListType::const_iterator
I = Src->getArgumentList().begin(),
E = Src->getArgumentList().end(); I != E; ++I) {
const MethodArgument *SMA = *I;
const FunctionArgument *SMA = *I;
// Create the new method argument and add to the dest method...
MethodArgument *DMA = new MethodArgument(SMA->getType(), SMA->getName());
FunctionArgument *DMA = new FunctionArgument(SMA->getType(),SMA->getName());
Dest->getArgumentList().push_back(DMA);
// Add a mapping to our local map
@ -310,7 +310,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
// Loop over all of the basic blocks, copying the instructions over...
//
for (Method::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const BasicBlock *SBB = *I;
// Create new basic block and add to mapping and the Dest method...
@ -338,7 +338,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
// in the Source method as operands. Loop through all of the operands of the
// methods and patch them up to point to the local versions...
//
for (Method::iterator BI = Dest->begin(), BE = Dest->end();
for (Function::iterator BI = Dest->begin(), BE = Dest->end();
BI != BE; ++BI) {
BasicBlock *BB = *BI;
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
@ -354,30 +354,30 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
}
// LinkMethodBodies - Link in the method bodies that are defined in the source
// LinkFunctionBodies - Link in the method bodies that are defined in the source
// module into the DestModule. This consists basically of copying the method
// over and fixing up references to values.
//
static bool LinkMethodBodies(Module *Dest, const Module *Src,
static bool LinkFunctionBodies(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap,
string *Err = 0) {
// Loop over all of the methods in the src module, mapping them over as we go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Method *SM = *I; // Source Method
const Function *SM = *I; // Source Function
if (!SM->isExternal()) { // No body if method is external
Method *DM = cast<Method>(ValueMap[SM]); // Destination method
Function *DM = cast<Function>(ValueMap[SM]); // Destination method
// DM not external SM external?
if (!DM->isExternal()) {
if (Err)
*Err = "Method '" + (SM->hasName() ? SM->getName() : string("")) +
*Err = "Function '" + (SM->hasName() ? SM->getName() : string("")) +
"' body multiply defined!";
return true;
}
if (LinkMethodBody(DM, SM, ValueMap, Err)) return true;
if (LinkFunctionBody(DM, SM, ValueMap, Err)) return true;
}
}
return false;
@ -418,13 +418,13 @@ bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0) {
// We do this so that when we begin processing method bodies, all of the
// global values that may be referenced are available in our ValueMap.
//
if (LinkMethodProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link in the method bodies that are defined in the source module into the
// DestModule. This consists basically of copying the method over and fixing
// up references to values.
//
if (LinkMethodBodies(Dest, Src, ValueMap, ErrorMsg)) return true;
if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true;
return false;
}

View File

@ -24,7 +24,7 @@
#include "llvm/CodeGen/InstrForest.h"
#include "llvm/CodeGen/MachineCodeForInstruction.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/iTerminators.h"
#include "llvm/iMemory.h"
#include "llvm/iPHINode.h"
@ -188,10 +188,10 @@ LabelNode::dumpNode(int indent) const
// A forest of instruction trees, usually for a single method.
//------------------------------------------------------------------------
InstrForest::InstrForest(Method *M)
InstrForest::InstrForest(Function *F)
{
for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
BasicBlock *BB = *MI;
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
BasicBlock *BB = *FI;
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
buildTreeForInstruction(*I);
}
@ -302,11 +302,11 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
// Check latter condition here just to simplify the next IF.
bool includeAddressOperand =
(isa<BasicBlock>(operand) || isa<Method>(operand))
(isa<BasicBlock>(operand) || isa<Function>(operand))
&& !instr->isTerminator();
if (includeAddressOperand || isa<Instruction>(operand) ||
isa<Constant>(operand) || isa<MethodArgument>(operand) ||
isa<Constant>(operand) || isa<FunctionArgument>(operand) ||
isa<GlobalVariable>(operand))
{
// This operand is a data value

View File

@ -153,7 +153,7 @@ static bool PatchUpMethodReferences(Module *M) {
// used later.
//
if (Methods[i]->use_size() == 0) {
M->getMethodList().remove(Methods[i]);
M->getFunctionList().remove(Methods[i]);
delete Methods[i];
Methods.erase(Methods.begin()+i);
Changed = true;

View File

@ -273,7 +273,7 @@ void MutateStructTypes::processGlobals(Module *M) {
Meth->setName("OLD."+Meth->getName());
// Insert the new method into the method list... to be filled in later...
M->getMethodList().push_back(NewMeth);
M->getFunctionList().push_back(NewMeth);
// Keep track of the association...
GlobalMap[Meth] = NewMeth;
@ -320,7 +320,7 @@ void MutateStructTypes::removeDeadGlobals(Module *M) {
#endif
for(Module::iterator I = M->begin(); I != M->end();) {
if (GlobalMap.find(*I) != GlobalMap.end())
delete M->getMethodList().remove(I);
delete M->getFunctionList().remove(I);
else
++I;
}
@ -341,8 +341,8 @@ void MutateStructTypes::transformMethod(Method *m) {
// Okay, first order of business, create the arguments...
for (unsigned i = 0; i < M->getArgumentList().size(); ++i) {
const MethodArgument *OMA = M->getArgumentList()[i];
MethodArgument *NMA = new MethodArgument(ConvertType(OMA->getType()),
const FunctionArgument *OMA = M->getArgumentList()[i];
FunctionArgument *NMA = new FunctionArgument(ConvertType(OMA->getType()),
OMA->getName());
NewMeth->getArgumentList().push_back(NMA);
LocalValueMap[OMA] = NMA; // Keep track of value mapping

View File

@ -12,7 +12,7 @@
#include "llvm/iMemory.h"
#include "llvm/iTerminators.h"
#include "llvm/iOther.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
#include "llvm/Pass.h"
@ -24,12 +24,12 @@ using std::string;
namespace {
class InsertTraceCode : public MethodPass {
bool TraceBasicBlockExits, TraceMethodExits;
Method *PrintfMeth;
bool TraceBasicBlockExits, TraceFunctionExits;
Function *PrintfFunc;
public:
InsertTraceCode(bool traceBasicBlockExits, bool traceMethodExits)
InsertTraceCode(bool traceBasicBlockExits, bool traceFunctionExits)
: TraceBasicBlockExits(traceBasicBlockExits),
TraceMethodExits(traceMethodExits) {}
TraceFunctionExits(traceFunctionExits) {}
// Add a prototype for printf if it is not already in the program.
//
@ -39,15 +39,15 @@ namespace {
// Function InsertCodeToTraceValues
//
// Inserts tracing code for all live values at basic block and/or method
// exits as specified by `traceBasicBlockExits' and `traceMethodExits'.
// exits as specified by `traceBasicBlockExits' and `traceFunctionExits'.
//
static bool doit(Method *M, bool traceBasicBlockExits,
bool traceMethodExits, Method *Printf);
static bool doit(Function *M, bool traceBasicBlockExits,
bool traceFunctionExits, Function *Printf);
// runOnMethod - This method does the work. Always successful.
//
bool runOnMethod(Method *M) {
return doit(M, TraceBasicBlockExits, TraceMethodExits, PrintfMeth);
bool runOnMethod(Function *F) {
return doit(F, TraceBasicBlockExits, TraceFunctionExits, PrintfFunc);
}
};
} // end anonymous namespace
@ -72,14 +72,14 @@ bool InsertTraceCode::doInitialization(Module *M) {
const MethodType *MTy =
MethodType::get(Type::IntTy, vector<const Type*>(1, SBP), true);
if (Value *Meth = ST->lookup(PointerType::get(MTy), "printf")) {
PrintfMeth = cast<Method>(Meth);
if (Value *Func = ST->lookup(PointerType::get(MTy), "printf")) {
PrintfFunc = cast<Function>(Func);
return false;
}
// Create a new method and add it to the module
PrintfMeth = new Method(MTy, false, "printf");
M->getMethodList().push_back(PrintfMeth);
PrintfFunc = new Function(MTy, false, "printf");
M->getFunctionList().push_back(PrintfFunc);
return true;
}
@ -153,7 +153,7 @@ static string getPrintfCodeFor(const Value *V) {
static void InsertPrintInst(Value *V, BasicBlock *BB, BasicBlock::iterator &BBI,
string Message, Method *Printf) {
string Message, Function *Printf) {
// Escape Message by replacing all % characters with %% chars.
unsigned Offset = 0;
while ((Offset = Message.find('%', Offset)) != string::npos) {
@ -184,7 +184,7 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, BasicBlock::iterator &BBI,
static void InsertVerbosePrintInst(Value *V, BasicBlock *BB,
BasicBlock::iterator &BBI,
const string &Message, Method *Printf) {
const string &Message, Function *Printf) {
std::ostringstream OutStr;
if (V) WriteAsOperand(OutStr, V);
InsertPrintInst(V, BB, BBI, Message+OutStr.str()+" = ", Printf);
@ -195,15 +195,15 @@ static void InsertVerbosePrintInst(Value *V, BasicBlock *BB,
// for each value in valueVec[] that is live at the end of that basic block,
// or that is stored to memory in this basic block.
// If the value is stored to memory, we load it back before printing
// We also return all such loaded values in the vector valuesStoredInMethod
// We also return all such loaded values in the vector valuesStoredInFunction
// for printing at the exit from the method. (Note that in each invocation
// of the method, this will only get the last value stored for each static
// store instruction).
// *bb must be the block in which the value is computed;
// this is not checked here.
//
static void TraceValuesAtBBExit(BasicBlock *BB, Method *Printf,
vector<Instruction*> *valuesStoredInMethod) {
static void TraceValuesAtBBExit(BasicBlock *BB, Function *Printf,
vector<Instruction*> *valuesStoredInFunction) {
// Get an iterator to point to the insertion location, which is
// just before the terminator instruction.
//
@ -239,19 +239,19 @@ static void TraceValuesAtBBExit(BasicBlock *BB, Method *Printf,
IE = Insts.end(); II != IE; ++II) {
Instruction *I = *II;
if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
assert(valuesStoredInMethod &&
assert(valuesStoredInFunction &&
"Should not be printing a store instruction at method exit");
LoadInst *LI = new LoadInst(SI->getPointerOperand(), SI->copyIndices(),
"reload");
InsertPos = BB->getInstList().insert(InsertPos, LI) + 1;
valuesStoredInMethod->push_back(LI);
valuesStoredInFunction->push_back(LI);
}
if (ShouldTraceValue(I))
InsertVerbosePrintInst(I, BB, InsertPos, " ", Printf);
}
}
static inline void InsertCodeToShowMethodEntry(Method *M, Method *Printf) {
static inline void InsertCodeToShowFunctionEntry(Function *M, Function *Printf){
// Get an iterator to point to the insertion location
BasicBlock *BB = M->getEntryNode();
BasicBlock::iterator BBI = BB->begin();
@ -261,9 +261,9 @@ static inline void InsertCodeToShowMethodEntry(Method *M, Method *Printf) {
InsertPrintInst(0, BB, BBI, "ENTERING METHOD: " + OutStr.str(), Printf);
// Now print all the incoming arguments
const Method::ArgumentListType &argList = M->getArgumentList();
const Function::ArgumentListType &argList = M->getArgumentList();
unsigned ArgNo = 0;
for (Method::ArgumentListType::const_iterator
for (Function::ArgumentListType::const_iterator
I = argList.begin(), E = argList.end(); I != E; ++I, ++ArgNo) {
InsertVerbosePrintInst(*I, BB, BBI,
" Arg #" + utostr(ArgNo), Printf);
@ -271,7 +271,8 @@ static inline void InsertCodeToShowMethodEntry(Method *M, Method *Printf) {
}
static inline void InsertCodeToShowMethodExit(BasicBlock *BB, Method *Printf) {
static inline void InsertCodeToShowFunctionExit(BasicBlock *BB,
Function *Printf) {
// Get an iterator to point to the insertion location
BasicBlock::iterator BBI = BB->end()-1;
ReturnInst *Ret = cast<ReturnInst>(*BBI);
@ -286,34 +287,34 @@ static inline void InsertCodeToShowMethodExit(BasicBlock *BB, Method *Printf) {
}
bool InsertTraceCode::doit(Method *M, bool traceBasicBlockExits,
bool traceMethodEvents, Method *Printf) {
if (!traceBasicBlockExits && !traceMethodEvents)
bool InsertTraceCode::doit(Function *M, bool traceBasicBlockExits,
bool traceFunctionEvents, Function *Printf) {
if (!traceBasicBlockExits && !traceFunctionEvents)
return false;
vector<Instruction*> valuesStoredInMethod;
vector<Instruction*> valuesStoredInFunction;
vector<BasicBlock*> exitBlocks;
if (traceMethodEvents)
InsertCodeToShowMethodEntry(M, Printf);
if (traceFunctionEvents)
InsertCodeToShowFunctionEntry(M, Printf);
for (Method::iterator BI = M->begin(); BI != M->end(); ++BI) {
for (Function::iterator BI = M->begin(); BI != M->end(); ++BI) {
BasicBlock *BB = *BI;
if (isa<ReturnInst>(BB->getTerminator()))
exitBlocks.push_back(BB); // record this as an exit block
if (traceBasicBlockExits)
TraceValuesAtBBExit(BB, Printf, &valuesStoredInMethod);
TraceValuesAtBBExit(BB, Printf, &valuesStoredInFunction);
}
if (traceMethodEvents)
if (traceFunctionEvents)
for (unsigned i=0; i < exitBlocks.size(); ++i) {
#if 0
TraceValuesAtBBExit(valuesStoredInMethod, exitBlocks[i], module,
/*indent*/ 0, /*isMethodExit*/ true,
/*valuesStoredInMethod*/ NULL);
TraceValuesAtBBExit(valuesStoredInFunction, exitBlocks[i], module,
/*indent*/ 0, /*isFunctionExit*/ true,
/*valuesStoredInFunction*/ NULL);
#endif
InsertCodeToShowMethodExit(exitBlocks[i], Printf);
InsertCodeToShowFunctionExit(exitBlocks[i], Printf);
}
return true;

View File

@ -26,7 +26,7 @@
#include "llvm/Transforms/Scalar/DCE.h"
#include "llvm/Module.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
@ -91,7 +91,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
//cerr << "Killing PHIs from " << BB;
//cerr << "Pred #0 = " << *pred_begin(BB);
//cerr << "Method == " << BB->getParent();
//cerr << "Function == " << BB->getParent();
do {
PHINode *PN = cast<PHINode>(I);
@ -167,9 +167,9 @@ static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
//
// WARNING: The entry node of a method may not be simplified.
//
bool SimplifyCFG(Method::iterator &BBIt) {
bool SimplifyCFG(Function::iterator &BBIt) {
BasicBlock *BB = *BBIt;
Method *M = BB->getParent();
Function *M = BB->getParent();
assert(BB && BB->getParent() && "Block not embedded in method!");
assert(BB->getTerminator() && "Degenerate basic block encountered!");
@ -226,7 +226,7 @@ bool SimplifyCFG(Method::iterator &BBIt) {
Succ->setName(BB->getName());
delete BB; // Delete basic block
//cerr << "Method after removal: \n" << M;
//cerr << "Function after removal: \n" << M;
return true;
}
}
@ -279,13 +279,13 @@ bool SimplifyCFG(Method::iterator &BBIt) {
return false;
}
static bool DoDCEPass(Method *M) {
Method::iterator BBIt, BBEnd = M->end();
if (M->begin() == BBEnd) return false; // Nothing to do
static bool DoDCEPass(Function *F) {
Function::iterator BBIt, BBEnd = F->end();
if (F->begin() == BBEnd) return false; // Nothing to do
bool Changed = false;
// Loop through now and remove instructions that have no uses...
for (BBIt = M->begin(); BBIt != BBEnd; ++BBIt) {
for (BBIt = F->begin(); BBIt != BBEnd; ++BBIt) {
Changed |= RemoveUnusedDefs((*BBIt)->getInstList());
Changed |= RemoveSingularPHIs(*BBIt);
}
@ -293,7 +293,7 @@ static bool DoDCEPass(Method *M) {
// Loop over all of the basic blocks (except the first one) and remove them
// if they are unneeded...
//
for (BBIt = M->begin(), ++BBIt; BBIt != M->end(); ) {
for (BBIt = F->begin(), ++BBIt; BBIt != F->end(); ) {
if (SimplifyCFG(BBIt)) {
Changed = true;
} else {
@ -312,11 +312,11 @@ static bool RemoveUnusedGlobalValues(Module *Mod) {
bool Changed = false;
for (Module::iterator MI = Mod->begin(); MI != Mod->end(); ) {
Method *Meth = *MI;
Function *Meth = *MI;
if (Meth->isExternal() && Meth->use_size() == 0) {
// No references to prototype?
//cerr << "Removing method proto: " << Meth->getName() << endl;
delete Mod->getMethodList().remove(MI); // Remove prototype
delete Mod->getFunctionList().remove(MI); // Remove prototype
// Remove moves iterator to point to the next one automatically
Changed = true;
} else {
@ -351,9 +351,9 @@ namespace {
// It is possible that we may require multiple passes over the code to fully
// eliminate dead code. Iterate until we are done.
//
virtual bool runOnMethod(Method *M) {
virtual bool runOnMethod(Function *F) {
bool Changed = false;
while (DoDCEPass(M)) Changed = true;
while (DoDCEPass(F)) Changed = true;
return Changed;
}

View File

@ -25,7 +25,7 @@
#include "llvm/Assembly/Writer.h"
#include "llvm/SymbolTable.h"
#include "llvm/iPHINode.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/InstrTypes.h"
#include "llvm/Support/CFG.h"
@ -38,7 +38,7 @@ using std::cerr;
// an interval invariant computation.
//
static bool isLoopInvariant(cfg::Interval *Int, Value *V) {
assert(isa<Constant>(V) || isa<Instruction>(V) || isa<MethodArgument>(V));
assert(isa<Constant>(V) || isa<Instruction>(V) || isa<FunctionArgument>(V));
if (!isa<Instruction>(V))
return true; // Constants and arguments are always loop invariant
@ -181,7 +181,7 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) {
std::string PHIName, AddName;
BasicBlock *Header = Int->getHeaderNode();
Method *M = Header->getParent();
Function *M = Header->getParent();
if (M->hasSymbolTable()) {
// Only name the induction variable if the method isn't stripped.
@ -373,7 +373,7 @@ static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) {
// This function loops over an interval partition of a program, reducing it
// until the graph is gone.
//
bool InductionVariableCannonicalize::doIt(Method *M,
bool InductionVariableCannonicalize::doIt(Function *M,
cfg::IntervalPartition &IP) {
bool Changed = false;
@ -399,8 +399,8 @@ bool InductionVariableCannonicalize::doIt(Method *M,
}
bool InductionVariableCannonicalize::runOnMethod(Method *M) {
return doIt(M, getAnalysis<cfg::IntervalPartition>());
bool InductionVariableCannonicalize::runOnMethod(Function *F) {
return doIt(F, getAnalysis<cfg::IntervalPartition>());
}
// getAnalysisUsageInfo - This function works on the call graph of a module.

View File

@ -17,10 +17,9 @@
#include "llvm/Transforms/Scalar/ConstantProp.h"
#include "llvm/Transforms/Scalar/ConstantHandling.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/ConstantVals.h"
#include "llvm/InstrTypes.h"
#include "llvm/iPHINode.h"
#include "llvm/iMemory.h"
#include "llvm/iTerminators.h"
@ -87,7 +86,7 @@ public:
// It's public interface consists of a constructor and a doSCCP() method.
//
class SCCP {
Method *M; // The method that we are working on...
Function *M; // The function that we are working on
std::set<BasicBlock*> BBExecutable;// The basic blocks that are executable
std::map<Value*, InstVal> ValueState; // The state each value is in...
@ -101,7 +100,7 @@ class SCCP {
public:
// SCCP Ctor - Save the method to operate on...
inline SCCP(Method *m) : M(m) {}
inline SCCP(Function *f) : M(f) {}
// doSCCP() - Run the Sparse Conditional Constant Propogation algorithm, and
// return true if the method was modified.
@ -142,8 +141,8 @@ private:
// getValueState - Return the InstVal object that corresponds to the value.
// This function is neccesary because not all values should start out in the
// underdefined state... MethodArgument's should be overdefined, and constants
// should be marked as constants. If a value is not known to be an
// underdefined state... FunctionArgument's should be overdefined, and
// constants should be marked as constants. If a value is not known to be an
// Instruction object, then use this accessor to get its value from the map.
//
inline InstVal &getValueState(Value *V) {
@ -152,7 +151,7 @@ private:
if (Constant *CPV = dyn_cast<Constant>(V)) { // Constants are constant
ValueState[CPV].markConstant(CPV);
} else if (isa<MethodArgument>(V)) { // MethodArgs are overdefined
} else if (isa<FunctionArgument>(V)) { // FuncArgs are overdefined
ValueState[V].markOverdefined();
}
// All others are underdefined by default...
@ -235,7 +234,8 @@ bool SCCP::doSCCP() {
}
#if 0
for (Method::iterator BBI = M->begin(), BBEnd = M->end(); BBI != BBEnd; ++BBI)
for (Function::iterator BBI = M->begin(), BBEnd = M->end();
BBI != BBEnd; ++BBI)
if (!BBExecutable.count(*BBI))
cerr << "BasicBlock Dead:" << *BBI;
#endif
@ -245,7 +245,7 @@ bool SCCP::doSCCP() {
// constants if we have found them to be of constant values.
//
bool MadeChanges = false;
for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
for (Function::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
BasicBlock *BB = *MI;
for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
Instruction *Inst = *BI;
@ -380,7 +380,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
//===-----------------------------------------------------------------===//
// Handle Terminator instructions...
//
case Instruction::Ret: return; // Method return doesn't affect anything
case Instruction::Ret: return; // Function return doesn't affect anything
case Instruction::Br: { // Handle conditional branches...
BranchInst *BI = cast<BranchInst>(I);
if (BI->isUnconditional())
@ -509,8 +509,8 @@ namespace {
// to prove whether a value is constant and whether blocks are used.
//
struct SCCPPass : public MethodPass {
inline bool runOnMethod(Method *M) {
SCCP S(M);
inline bool runOnMethod(Function *F) {
SCCP S(F);
return S.doSCCP();
}
};

View File

@ -11,7 +11,7 @@
#include "llvm/Transforms/Linker.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/GlobalVariable.h"
#include "llvm/SymbolTable.h"
@ -165,8 +165,8 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
(V = ST->lookup(SGV->getType(), SGV->getName())) &&
cast<GlobalVariable>(V)->hasExternalLinkage()) {
// The same named thing is a global variable, because the only two things
// that may be in a module level symbol table are Global Vars and Methods,
// and they both have distinct, nonoverlapping, possible types.
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
GlobalVariable *DGV = cast<GlobalVariable>(V);
@ -231,11 +231,11 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
return false;
}
// LinkMethodProtos - Link the methods together between the two modules, without
// doing method bodies... this just adds external method prototypes to the Dest
// method...
// LinkFunctionProtos - Link the functions together between the two modules,
// without doing method bodies... this just adds external method prototypes to
// the Dest function...
//
static bool LinkMethodProtos(Module *Dest, const Module *Src,
static bool LinkFunctionProtos(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap,
string *Err = 0) {
// We will need a module level symbol table if the src module has a module
@ -245,7 +245,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
// Loop over all of the methods in the src module, mapping them over as we go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Method *SM = *I; // SrcMethod
const Function *SM = *I; // SrcFunction
Value *V;
// If the method has a name, and that name is already in use in the
@ -253,29 +253,29 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
//
if (SM->hasExternalLinkage() && SM->hasName() &&
(V = ST->lookup(SM->getType(), SM->getName())) &&
cast<Method>(V)->hasExternalLinkage()) {
// The same named thing is a Method, because the only two things
// that may be in a module level symbol table are Global Vars and Methods,
// and they both have distinct, nonoverlapping, possible types.
cast<Function>(V)->hasExternalLinkage()) {
// The same named thing is a Function, because the only two things
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
Method *DM = cast<Method>(V); // DestMethod
Function *DM = cast<Function>(V); // DestFunction
// Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Method '" +
return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" +
SM->getName() + "\" - Method is already defined!");
SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
ValueMap.insert(std::make_pair(SM, DM));
} else {
// Method does not already exist, simply insert an external method
// Function does not already exist, simply insert an external method
// signature identical to SM into the dest module...
Method *DM = new Method(SM->getMethodType(), SM->hasInternalLinkage(),
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(),
SM->getName());
// Add the method signature to the dest module...
Dest->getMethodList().push_back(DM);
Dest->getFunctionList().push_back(DM);
// ... and remember this mapping...
ValueMap.insert(std::make_pair(SM, DM));
@ -284,24 +284,24 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
return false;
}
// LinkMethodBody - Copy the source method over into the dest method and fix up
// references to values. At this point we know that Dest is an external method,
// and that Src is not.
// LinkFunctionBody - Copy the source method over into the dest method
// and fix up references to values. At this point we know that Dest
// is an external method, and that Src is not.
//
static bool LinkMethodBody(Method *Dest, const Method *Src,
static bool LinkFunctionBody(Function *Dest, const Function *Src,
const map<const Value*, Value*> &GlobalMap,
string *Err = 0) {
assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
map<const Value*, Value*> LocalMap; // Map for method local values
// Go through and convert method arguments over...
for (Method::ArgumentListType::const_iterator
for (Function::ArgumentListType::const_iterator
I = Src->getArgumentList().begin(),
E = Src->getArgumentList().end(); I != E; ++I) {
const MethodArgument *SMA = *I;
const FunctionArgument *SMA = *I;
// Create the new method argument and add to the dest method...
MethodArgument *DMA = new MethodArgument(SMA->getType(), SMA->getName());
FunctionArgument *DMA = new FunctionArgument(SMA->getType(),SMA->getName());
Dest->getArgumentList().push_back(DMA);
// Add a mapping to our local map
@ -310,7 +310,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
// Loop over all of the basic blocks, copying the instructions over...
//
for (Method::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const BasicBlock *SBB = *I;
// Create new basic block and add to mapping and the Dest method...
@ -338,7 +338,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
// in the Source method as operands. Loop through all of the operands of the
// methods and patch them up to point to the local versions...
//
for (Method::iterator BI = Dest->begin(), BE = Dest->end();
for (Function::iterator BI = Dest->begin(), BE = Dest->end();
BI != BE; ++BI) {
BasicBlock *BB = *BI;
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
@ -354,30 +354,30 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
}
// LinkMethodBodies - Link in the method bodies that are defined in the source
// LinkFunctionBodies - Link in the method bodies that are defined in the source
// module into the DestModule. This consists basically of copying the method
// over and fixing up references to values.
//
static bool LinkMethodBodies(Module *Dest, const Module *Src,
static bool LinkFunctionBodies(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap,
string *Err = 0) {
// Loop over all of the methods in the src module, mapping them over as we go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Method *SM = *I; // Source Method
const Function *SM = *I; // Source Function
if (!SM->isExternal()) { // No body if method is external
Method *DM = cast<Method>(ValueMap[SM]); // Destination method
Function *DM = cast<Function>(ValueMap[SM]); // Destination method
// DM not external SM external?
if (!DM->isExternal()) {
if (Err)
*Err = "Method '" + (SM->hasName() ? SM->getName() : string("")) +
*Err = "Function '" + (SM->hasName() ? SM->getName() : string("")) +
"' body multiply defined!";
return true;
}
if (LinkMethodBody(DM, SM, ValueMap, Err)) return true;
if (LinkFunctionBody(DM, SM, ValueMap, Err)) return true;
}
}
return false;
@ -418,13 +418,13 @@ bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0) {
// We do this so that when we begin processing method bodies, all of the
// global values that may be referenced are available in our ValueMap.
//
if (LinkMethodProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link in the method bodies that are defined in the source module into the
// DestModule. This consists basically of copying the method over and fixing
// up references to values.
//
if (LinkMethodBodies(Dest, Src, ValueMap, ErrorMsg)) return true;
if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true;
return false;
}

View File

@ -25,13 +25,13 @@ namespace {
// calls.
//
class LowerAllocations : public BasicBlockPass {
Method *MallocMeth; // Methods in the module we are processing
Method *FreeMeth; // Initialized by doInitialization
Function *MallocFunc; // Functions in the module we are processing
Function *FreeFunc; // Initialized by doInitialization
const TargetData &DataLayout;
public:
inline LowerAllocations(const TargetData &TD) : DataLayout(TD) {
MallocMeth = FreeMeth = 0;
MallocFunc = FreeFunc = 0;
}
// doPassInitialization - For the lower allocations pass, this ensures that a
@ -49,10 +49,10 @@ public:
// instruction.
//
class RaiseAllocations : public BasicBlockPass {
Method *MallocMeth; // Methods in the module we are processing
Method *FreeMeth; // Initialized by doPassInitializationVirt
Function *MallocFunc; // Functions in the module we are processing
Function *FreeFunc; // Initialized by doPassInitializationVirt
public:
inline RaiseAllocations() : MallocMeth(0), FreeMeth(0) {}
inline RaiseAllocations() : MallocFunc(0), FreeFunc(0) {}
// doPassInitialization - For the raise allocations pass, this finds a
// declaration for malloc and free if they exist.
@ -82,9 +82,9 @@ bool LowerAllocations::doInitialization(Module *M) {
// Check for a definition of malloc
if (Value *V = SymTab->lookup(PointerType::get(MallocType), "malloc")) {
MallocMeth = cast<Method>(V); // Yup, got it
MallocFunc = cast<Function>(V); // Yup, got it
} else { // Nope, add one
M->getMethodList().push_back(MallocMeth = new Method(MallocType, false,
M->getFunctionList().push_back(MallocFunc = new Function(MallocType, false,
"malloc"));
Changed = true;
}
@ -96,9 +96,10 @@ bool LowerAllocations::doInitialization(Module *M) {
// Check for a definition of free
if (Value *V = SymTab->lookup(PointerType::get(FreeType), "free")) {
FreeMeth = cast<Method>(V); // Yup, got it
FreeFunc = cast<Function>(V); // Yup, got it
} else { // Nope, add one
M->getMethodList().push_back(FreeMeth = new Method(FreeType, false,"free"));
FreeFunc = new Function(FreeType, false,"free");
M->getFunctionList().push_back(FreeFunc);
Changed = true;
}
@ -110,7 +111,7 @@ bool LowerAllocations::doInitialization(Module *M) {
//
bool LowerAllocations::runOnBasicBlock(BasicBlock *BB) {
bool Changed = false;
assert(MallocMeth && FreeMeth && BB && "Pass not initialized!");
assert(MallocFunc && FreeFunc && BB && "Pass not initialized!");
// Loop over all of the instructions, looking for malloc or free instructions
for (unsigned i = 0; i < BB->size(); ++i) {
@ -136,7 +137,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock *BB) {
}
// Create the call to Malloc...
CallInst *MCall = new CallInst(MallocMeth,
CallInst *MCall = new CallInst(MallocFunc,
vector<Value*>(1, MallocArg));
BBIL.insert(BBIL.begin()+i, MCall);
@ -157,7 +158,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock *BB) {
BBIL.insert(BBIL.begin()+i, MCast);
// Insert a call to the free function...
CallInst *FCall = new CallInst(FreeMeth,
CallInst *FCall = new CallInst(FreeFunc,
vector<Value*>(1, MCast));
BBIL.insert(BBIL.begin()+i+1, FCall);
@ -185,16 +186,16 @@ bool RaiseAllocations::doInitialization(Module *M) {
const PointerType *MallocType = // Get the type for malloc
PointerType::get(MethodType::get(PointerType::get(Type::SByteTy),
vector<const Type*>(1, Type::UIntTy), false));
MallocMeth = cast_or_null<Method>(ST->lookup(MallocType, "malloc"));
if (MallocMeth && !MallocMeth->isExternal())
MallocMeth = 0; // Don't mess with locally defined versions of the fn
MallocFunc = cast_or_null<Function>(ST->lookup(MallocType, "malloc"));
if (MallocFunc && !MallocFunc->isExternal())
MallocFunc = 0; // Don't mess with locally defined versions of the fn
const PointerType *FreeType = // Get the type for free
PointerType::get(MethodType::get(Type::VoidTy,
vector<const Type*>(1, PointerType::get(Type::SByteTy)), false));
FreeMeth = cast_or_null<Method>(ST->lookup(FreeType, "free"));
if (FreeMeth && !FreeMeth->isExternal())
FreeMeth = 0; // Don't mess with locally defined versions of the fn
FreeFunc = cast_or_null<Function>(ST->lookup(FreeType, "free"));
if (FreeFunc && !FreeFunc->isExternal())
FreeFunc = 0; // Don't mess with locally defined versions of the fn
return false;
}
@ -209,7 +210,7 @@ bool RaiseAllocations::runOnBasicBlock(BasicBlock *BB) {
Instruction *I = *BI;
if (CallInst *CI = dyn_cast<CallInst>(I)) {
if (CI->getCalledValue() == MallocMeth) { // Replace call to malloc?
if (CI->getCalledValue() == MallocFunc) { // Replace call to malloc?
const Type *PtrSByte = PointerType::get(Type::SByteTy);
MallocInst *MallocI = new MallocInst(PtrSByte, CI->getOperand(1),
CI->getName());
@ -217,7 +218,7 @@ bool RaiseAllocations::runOnBasicBlock(BasicBlock *BB) {
ReplaceInstWithInst(BIL, BI, MallocI);
Changed = true;
continue; // Skip the ++BI
} else if (CI->getCalledValue() == FreeMeth) { // Replace call to free?
} else if (CI->getCalledValue() == FreeFunc) { // Replace call to free?
ReplaceInstWithInst(BIL, BI, new FreeInst(CI->getOperand(1)));
Changed = true;
continue; // Skip the ++BI

View File

@ -13,7 +13,7 @@
#include "llvm/Assembly/CachedWriter.h"
#include "llvm/Analysis/SlotCalculator.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/BasicBlock.h"
#include "llvm/ConstantVals.h"
@ -32,12 +32,12 @@ using std::vector;
using std::ostream;
static const Module *getModuleFromVal(const Value *V) {
if (const MethodArgument *MA =dyn_cast<const MethodArgument>(V))
if (const FunctionArgument *MA = dyn_cast<const FunctionArgument>(V))
return MA->getParent() ? MA->getParent()->getParent() : 0;
else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(V))
return BB->getParent() ? BB->getParent()->getParent() : 0;
else if (const Instruction *I = dyn_cast<const Instruction>(V)) {
const Method *M = I->getParent() ? I->getParent()->getParent() : 0;
const Function *M = I->getParent() ? I->getParent()->getParent() : 0;
return M ? M->getParent() : 0;
} else if (const GlobalValue *GV = dyn_cast<const GlobalValue>(V))
return GV->getParent();
@ -48,16 +48,16 @@ static const Module *getModuleFromVal(const Value *V) {
static SlotCalculator *createSlotCalculator(const Value *V) {
assert(!isa<Type>(V) && "Can't create an SC for a type!");
if (const MethodArgument *MA =dyn_cast<const MethodArgument>(V)){
return new SlotCalculator(MA->getParent(), true);
if (const FunctionArgument *FA = dyn_cast<const FunctionArgument>(V)) {
return new SlotCalculator(FA->getParent(), true);
} else if (const Instruction *I = dyn_cast<const Instruction>(V)) {
return new SlotCalculator(I->getParent()->getParent(), true);
} else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(V)) {
return new SlotCalculator(BB->getParent(), true);
} else if (const GlobalVariable *GV = dyn_cast<const GlobalVariable>(V)){
return new SlotCalculator(GV->getParent(), true);
} else if (const Method *Meth = dyn_cast<const Method>(V)) {
return new SlotCalculator(Meth, true);
} else if (const Function *Func = dyn_cast<const Function>(V)) {
return new SlotCalculator(Func, true);
} else if (const Module *Mod = dyn_cast<const Module>(V)) {
return new SlotCalculator(Mod, true);
}
@ -276,7 +276,7 @@ public:
inline void write(const Module *M) { printModule(M); }
inline void write(const GlobalVariable *G) { printGlobal(G); }
inline void write(const Method *M) { printMethod(M); }
inline void write(const Function *F) { printFunction(F); }
inline void write(const BasicBlock *BB) { printBasicBlock(BB); }
inline void write(const Instruction *I) { printInstruction(I); }
inline void write(const Constant *CPV) { printConstant(CPV); }
@ -287,8 +287,8 @@ private :
void printSymbolTable(const SymbolTable &ST);
void printConstant(const Constant *CPV);
void printGlobal(const GlobalVariable *GV);
void printMethod(const Method *M);
void printMethodArgument(const MethodArgument *MA);
void printFunction(const Function *F);
void printFunctionArgument(const FunctionArgument *FA);
void printBasicBlock(const BasicBlock *BB);
void printInstruction(const Instruction *I);
ostream &printType(const Type *Ty);
@ -319,7 +319,7 @@ void AssemblyWriter::printModule(const Module *M) {
Out << "implementation\n";
// Output all of the methods...
for_each(M->begin(), M->end(), bind_obj(this,&AssemblyWriter::printMethod));
for_each(M->begin(), M->end(), bind_obj(this,&AssemblyWriter::printFunction));
}
void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
@ -385,9 +385,9 @@ void AssemblyWriter::printConstant(const Constant *CPV) {
Out << "\n";
}
// printMethod - Print all aspects of a method.
// printFunction - Print all aspects of a method.
//
void AssemblyWriter::printMethod(const Method *M) {
void AssemblyWriter::printFunction(const Function *M) {
// Print out the return type and name...
Out << "\n" << (M->isExternal() ? "declare " : "")
<< (M->hasInternalLinkage() ? "internal " : "");
@ -399,7 +399,7 @@ void AssemblyWriter::printMethod(const Method *M) {
if (!M->isExternal()) {
for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
bind_obj(this, &AssemblyWriter::printMethodArgument));
bind_obj(this, &AssemblyWriter::printFunctionArgument));
} else {
// Loop over the arguments, printing them...
const MethodType *MT = cast<const MethodType>(M->getMethodType());
@ -434,10 +434,10 @@ void AssemblyWriter::printMethod(const Method *M) {
Table.purgeMethod();
}
// printMethodArgument - 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
//
void AssemblyWriter::printMethodArgument(const MethodArgument *Arg) {
void AssemblyWriter::printFunctionArgument(const FunctionArgument *Arg) {
// Insert commas as we go... the first arg doesn't get a comma
if (Arg != Arg->getParent()->getArgumentList().front()) Out << ", ";
@ -651,12 +651,12 @@ void WriteToAssembly(const GlobalVariable *G, ostream &o) {
W.write(G);
}
void WriteToAssembly(const Method *M, ostream &o) {
if (M == 0) { o << "<null> method\n"; return; }
SlotCalculator SlotTable(M->getParent(), true);
AssemblyWriter W(o, SlotTable, M->getParent());
void WriteToAssembly(const Function *F, ostream &o) {
if (F == 0) { o << "<null> function\n"; return; }
SlotCalculator SlotTable(F->getParent(), true);
AssemblyWriter W(o, SlotTable, F->getParent());
W.write(M);
W.write(F);
}
@ -678,9 +678,9 @@ void WriteToAssembly(const Constant *CPV, ostream &o) {
void WriteToAssembly(const Instruction *I, ostream &o) {
if (I == 0) { o << "<null> instruction\n"; return; }
const Method *M = I->getParent() ? I->getParent()->getParent() : 0;
SlotCalculator SlotTable(M, true);
AssemblyWriter W(o, SlotTable, M ? M->getParent() : 0);
const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
SlotCalculator SlotTable(F, true);
AssemblyWriter W(o, SlotTable, F ? F->getParent() : 0);
W.write(I);
}
@ -706,12 +706,12 @@ CachedWriter &CachedWriter::operator<<(const Value *V) {
case Value::ConstantVal:
Out << " "; AW->write(V->getType());
Out << " " << cast<Constant>(V)->getStrValue(); break;
case Value::MethodArgumentVal:
case Value::FunctionArgumentVal:
AW->write(V->getType()); Out << " " << V->getName(); break;
case Value::TypeVal: AW->write(cast<const Type>(V)); break;
case Value::InstructionVal: AW->write(cast<Instruction>(V)); break;
case Value::BasicBlockVal: AW->write(cast<BasicBlock>(V)); break;
case Value::MethodVal: AW->write(cast<Method>(V)); break;
case Value::FunctionVal: AW->write(cast<Function>(V)); break;
case Value::GlobalVariableVal: AW->write(cast<GlobalVariable>(V)); break;
case Value::ModuleVal: AW->write(cast<Module>(V)); break;
default: Out << "<unknown value type: " << V->getValueType() << ">"; break;

View File

@ -1,6 +1,6 @@
//===-- Method.cpp - Implement the Method class ------------------*- C++ -*--=//
//===-- Function.cpp - Implement the Global object classes -------*- C++ -*--=//
//
// This file implements the Method & GlobalVariable classes for the VMCore
// This file implements the Function & GlobalVariable classes for the VMCore
// library.
//
//===----------------------------------------------------------------------===//
@ -9,27 +9,27 @@
#include "llvm/DerivedTypes.h"
#include "llvm/SymbolTable.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/BasicBlock.h"
#include "llvm/iOther.h"
//===----------------------------------------------------------------------===//
// Method Implementation
// Function Implementation
//===----------------------------------------------------------------------===//
// Instantiate Templates - This ugliness is the price we have to pay
// for having a ValueHolderImpl.h file seperate from ValueHolder.h! :(
//
template class ValueHolder<MethodArgument, Method, Method>;
template class ValueHolder<BasicBlock , Method, Method>;
template class ValueHolder<FunctionArgument, Function, Function>;
template class ValueHolder<BasicBlock , Function, Function>;
Function::Function(const MethodType *Ty, bool isInternal,
const std::string &name)
: GlobalValue(PointerType::get(Ty), Value::MethodVal, isInternal, name),
: GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name),
SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) {
assert(::isa<MethodType>(Ty) && "Method signature must be of method type!");
assert(::isa<MethodType>(Ty) && "Function signature must be of method type!");
}
Function::~Function() {

View File

@ -7,7 +7,7 @@
#include "llvm/iOther.h"
#include "llvm/iPHINode.h"
#include "llvm/BasicBlock.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/SymbolTable.h"
#include "llvm/Type.h"
#include <algorithm> // find
@ -27,12 +27,12 @@ TerminatorInst::TerminatorInst(const Type *Ty, Instruction::TermOps iType,
//===----------------------------------------------------------------------===//
// MethodArgument Class
// FunctionArgument Class
//===----------------------------------------------------------------------===//
// Specialize setName to take care of symbol table majik
void MethodArgument::setName(const std::string &name, SymbolTable *ST) {
Method *P;
void FunctionArgument::setName(const std::string &name, SymbolTable *ST) {
Function *P;
assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
"Invalid symtab argument!");
if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);

View File

@ -11,7 +11,7 @@
#include "llvm/Transforms/Linker.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/GlobalVariable.h"
#include "llvm/SymbolTable.h"
@ -165,8 +165,8 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
(V = ST->lookup(SGV->getType(), SGV->getName())) &&
cast<GlobalVariable>(V)->hasExternalLinkage()) {
// The same named thing is a global variable, because the only two things
// that may be in a module level symbol table are Global Vars and Methods,
// and they both have distinct, nonoverlapping, possible types.
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
GlobalVariable *DGV = cast<GlobalVariable>(V);
@ -231,11 +231,11 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
return false;
}
// LinkMethodProtos - Link the methods together between the two modules, without
// doing method bodies... this just adds external method prototypes to the Dest
// method...
// LinkFunctionProtos - Link the functions together between the two modules,
// without doing method bodies... this just adds external method prototypes to
// the Dest function...
//
static bool LinkMethodProtos(Module *Dest, const Module *Src,
static bool LinkFunctionProtos(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap,
string *Err = 0) {
// We will need a module level symbol table if the src module has a module
@ -245,7 +245,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
// Loop over all of the methods in the src module, mapping them over as we go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Method *SM = *I; // SrcMethod
const Function *SM = *I; // SrcFunction
Value *V;
// If the method has a name, and that name is already in use in the
@ -253,29 +253,29 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
//
if (SM->hasExternalLinkage() && SM->hasName() &&
(V = ST->lookup(SM->getType(), SM->getName())) &&
cast<Method>(V)->hasExternalLinkage()) {
// The same named thing is a Method, because the only two things
// that may be in a module level symbol table are Global Vars and Methods,
// and they both have distinct, nonoverlapping, possible types.
cast<Function>(V)->hasExternalLinkage()) {
// The same named thing is a Function, because the only two things
// that may be in a module level symbol table are Global Vars and
// Functions, and they both have distinct, nonoverlapping, possible types.
//
Method *DM = cast<Method>(V); // DestMethod
Function *DM = cast<Function>(V); // DestFunction
// Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Method '" +
return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" +
SM->getName() + "\" - Method is already defined!");
SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
ValueMap.insert(std::make_pair(SM, DM));
} else {
// Method does not already exist, simply insert an external method
// Function does not already exist, simply insert an external method
// signature identical to SM into the dest module...
Method *DM = new Method(SM->getMethodType(), SM->hasInternalLinkage(),
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(),
SM->getName());
// Add the method signature to the dest module...
Dest->getMethodList().push_back(DM);
Dest->getFunctionList().push_back(DM);
// ... and remember this mapping...
ValueMap.insert(std::make_pair(SM, DM));
@ -284,24 +284,24 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src,
return false;
}
// LinkMethodBody - Copy the source method over into the dest method and fix up
// references to values. At this point we know that Dest is an external method,
// and that Src is not.
// LinkFunctionBody - Copy the source method over into the dest method
// and fix up references to values. At this point we know that Dest
// is an external method, and that Src is not.
//
static bool LinkMethodBody(Method *Dest, const Method *Src,
static bool LinkFunctionBody(Function *Dest, const Function *Src,
const map<const Value*, Value*> &GlobalMap,
string *Err = 0) {
assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
map<const Value*, Value*> LocalMap; // Map for method local values
// Go through and convert method arguments over...
for (Method::ArgumentListType::const_iterator
for (Function::ArgumentListType::const_iterator
I = Src->getArgumentList().begin(),
E = Src->getArgumentList().end(); I != E; ++I) {
const MethodArgument *SMA = *I;
const FunctionArgument *SMA = *I;
// Create the new method argument and add to the dest method...
MethodArgument *DMA = new MethodArgument(SMA->getType(), SMA->getName());
FunctionArgument *DMA = new FunctionArgument(SMA->getType(),SMA->getName());
Dest->getArgumentList().push_back(DMA);
// Add a mapping to our local map
@ -310,7 +310,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
// Loop over all of the basic blocks, copying the instructions over...
//
for (Method::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const BasicBlock *SBB = *I;
// Create new basic block and add to mapping and the Dest method...
@ -338,7 +338,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
// in the Source method as operands. Loop through all of the operands of the
// methods and patch them up to point to the local versions...
//
for (Method::iterator BI = Dest->begin(), BE = Dest->end();
for (Function::iterator BI = Dest->begin(), BE = Dest->end();
BI != BE; ++BI) {
BasicBlock *BB = *BI;
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
@ -354,30 +354,30 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
}
// LinkMethodBodies - Link in the method bodies that are defined in the source
// LinkFunctionBodies - Link in the method bodies that are defined in the source
// module into the DestModule. This consists basically of copying the method
// over and fixing up references to values.
//
static bool LinkMethodBodies(Module *Dest, const Module *Src,
static bool LinkFunctionBodies(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap,
string *Err = 0) {
// Loop over all of the methods in the src module, mapping them over as we go
//
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Method *SM = *I; // Source Method
const Function *SM = *I; // Source Function
if (!SM->isExternal()) { // No body if method is external
Method *DM = cast<Method>(ValueMap[SM]); // Destination method
Function *DM = cast<Function>(ValueMap[SM]); // Destination method
// DM not external SM external?
if (!DM->isExternal()) {
if (Err)
*Err = "Method '" + (SM->hasName() ? SM->getName() : string("")) +
*Err = "Function '" + (SM->hasName() ? SM->getName() : string("")) +
"' body multiply defined!";
return true;
}
if (LinkMethodBody(DM, SM, ValueMap, Err)) return true;
if (LinkFunctionBody(DM, SM, ValueMap, Err)) return true;
}
}
return false;
@ -418,13 +418,13 @@ bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0) {
// We do this so that when we begin processing method bodies, all of the
// global values that may be referenced are available in our ValueMap.
//
if (LinkMethodProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link in the method bodies that are defined in the source module into the
// DestModule. This consists basically of copying the method over and fixing
// up references to values.
//
if (LinkMethodBodies(Dest, Src, ValueMap, ErrorMsg)) return true;
if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true;
return false;
}

View File

@ -5,7 +5,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/InstrTypes.h"
#include "llvm/ValueHolderImpl.h"
@ -18,7 +18,7 @@
// for having a DefHolderImpl.h file seperate from DefHolder.h! :(
//
template class ValueHolder<GlobalVariable, Module, Module>;
template class ValueHolder<Method, Module, Module>;
template class ValueHolder<Function, Module, Module>;
// Define the GlobalValueRefMap as a struct that wraps a map so that we don't
// have Module.h depend on <map>
@ -29,15 +29,15 @@ struct GlobalValueRefMap : public std::map<GlobalValue*, ConstantPointerRef*>{
Module::Module()
: Value(Type::VoidTy, Value::ModuleVal, ""), SymTabValue(this),
GlobalList(this, this), MethodList(this, this), GVRefMap(0) {
GlobalList(this, this), FunctionList(this, this), GVRefMap(0) {
}
Module::~Module() {
dropAllReferences();
GlobalList.delete_all();
GlobalList.setParent(0);
MethodList.delete_all();
MethodList.setParent(0);
FunctionList.delete_all();
FunctionList.setParent(0);
}
@ -50,8 +50,8 @@ Module::~Module() {
// delete.
//
void Module::dropAllReferences() {
for_each(MethodList.begin(), MethodList.end(),
std::mem_fun(&Method::dropAllReferences));
for_each(FunctionList.begin(), FunctionList.end(),
std::mem_fun(&Function::dropAllReferences));
for_each(GlobalList.begin(), GlobalList.end(),
std::mem_fun(&GlobalVariable::dropAllReferences));
@ -80,10 +80,10 @@ bool Module::reduceApply(bool (*Func)(GlobalVariable*)) {
bool Module::reduceApply(bool (*Func)(const GlobalVariable*)) const {
return reduce_apply_bool(gbegin(), gend(), Func);
}
bool Module::reduceApply(bool (*Func)(Method*)) {
bool Module::reduceApply(bool (*Func)(Function*)) {
return reduce_apply_bool(begin(), end(), Func);
}
bool Module::reduceApply(bool (*Func)(const Method*)) const {
bool Module::reduceApply(bool (*Func)(const Function*)) const {
return reduce_apply_bool(begin(), end(), Func);
}

View File

@ -8,7 +8,7 @@
#include "llvm/PassManager.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "Support/STLExtras.h"
#include <algorithm>
@ -59,8 +59,8 @@ void PMDebug::PrintPassInformation(unsigned Depth, const char *Action,
switch (V->getValueType()) {
case Value::ModuleVal:
std::cerr << "Module\n"; return;
case Value::MethodVal:
std::cerr << "Method '" << V->getName(); break;
case Value::FunctionVal:
std::cerr << "Function '" << V->getName(); break;
case Value::BasicBlockVal:
std::cerr << "BasicBlock '" << V->getName(); break;
default:
@ -119,11 +119,11 @@ bool MethodPass::run(Module *M) {
// run - On a method, we simply initialize, run the method, then finalize.
//
bool MethodPass::run(Method *M) {
if (M->isExternal()) return false; // Passes are not run on external methods!
bool MethodPass::run(Function *F) {
if (F->isExternal()) return false; // Passes are not run on external methods!
return doInitialization(M->getParent()) | runOnMethod(M)
| doFinalization(M->getParent());
return doInitialization(F->getParent()) | runOnMethod(F)
| doFinalization(F->getParent());
}
void MethodPass::addToPassManager(PassManagerT<Module> *PM,
@ -132,7 +132,7 @@ void MethodPass::addToPassManager(PassManagerT<Module> *PM,
PM->addPass(this, Required, Destroyed, Provided);
}
void MethodPass::addToPassManager(PassManagerT<Method> *PM,
void MethodPass::addToPassManager(PassManagerT<Function> *PM,
AnalysisSet &Required, AnalysisSet &Destroyed,
AnalysisSet &Provided) {
PM->addPass(this, Required, Destroyed, Provided);
@ -145,9 +145,9 @@ void MethodPass::addToPassManager(PassManagerT<Method> *PM,
// To run this pass on a method, we simply call runOnBasicBlock once for each
// method.
//
bool BasicBlockPass::runOnMethod(Method *M) {
bool BasicBlockPass::runOnMethod(Function *F) {
bool Changed = false;
for (Method::iterator I = M->begin(), E = M->end(); I != E; ++I)
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
Changed |= runOnBasicBlock(*I);
return Changed;
}
@ -160,7 +160,7 @@ bool BasicBlockPass::run(BasicBlock *BB) {
return doInitialization(M) | runOnBasicBlock(BB) | doFinalization(M);
}
void BasicBlockPass::addToPassManager(PassManagerT<Method> *PM,
void BasicBlockPass::addToPassManager(PassManagerT<Function> *PM,
AnalysisSet &Required,
AnalysisSet &Destroyed,
AnalysisSet &Provided) {

View File

@ -8,7 +8,7 @@
#include "llvm/InstrTypes.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/Function.h"
#include "Support/StringExtras.h"
#include <iostream>
@ -238,8 +238,8 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType,
// The only thing we are allowing for now is two method prototypes being
// folded into one.
//
Method *ExistM = dyn_cast<Method>(TI->second);
Method *NewM = dyn_cast<Method>(V.second);
Function *ExistM = dyn_cast<Function>(TI->second);
Function *NewM = dyn_cast<Function>(V.second);
if (ExistM && NewM && ExistM->isExternal() && NewM->isExternal()) {
// Ok we have two external methods. Make all uses of the new one
@ -264,7 +264,7 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType,
InternallyInconsistent = false;
// Now we can remove this method from the module entirely...
NewM->getParent()->getMethodList().remove(NewM);
NewM->getParent()->getFunctionList().remove(NewM);
delete NewM;
} else {