#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"
} 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;
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; }
//===----------------------------------------------------------------------===//
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) {
//
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);
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) {
// 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?
}
assert(d != 0 && "How did we not make something?");
- if (inMethodScope())
+ if (inFunctionScope())
InsertValue(d, CurMeth.LateResolveValues);
else
InsertValue(d, CurModule.LateResolveValues);
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 {
// 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);
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);
%union {
Module *ModuleVal;
- Method *MethodVal;
- std::pair<MethodArgument*,char*> *MethArgVal;
+ Function *FunctionVal;
+ std::pair<FunctionArgument*,char*> *MethArgVal;
BasicBlock *BasicBlockVal;
TerminatorInst *TermInstVal;
Instruction *InstVal;
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*,
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
$$ = 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
}
// 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();
// 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 {
//===----------------------------------------------------------------------===//
-// 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..
}
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 {
$$ = 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!");
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();
}
//===----------------------------------------------------------------------===//
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);
}
| 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) {
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;
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)
}
| 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) {
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;
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)
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) {
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;
#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"
outputSymbolTable(*M->getSymbolTable());
}
-void BytecodeWriter::outputConstants(bool isMethod) {
+void BytecodeWriter::outputConstants(bool isFunction) {
BytecodeBlock CPool(BytecodeFormat::ConstantPool, Out);
unsigned NumPlanes = Table.getNumPlanes();
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
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()) {
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);
#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"
// 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);
}
// 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
#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"
(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);
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,
- map<const Value*, Value*> &ValueMap,
- string *Err = 0) {
+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
// level symbol table...
SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 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; // SrcMethod
+ const Function *SM = *I; // SrcFunction
Value *V;
// If the method has a name, and that name is already in use in the
//
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(),
- SM->getName());
+ 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));
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,
- const map<const Value*, Value*> &GlobalMap,
- string *Err = 0) {
+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
// 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...
// 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) {
}
-// 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,
- map<const Value*, Value*> &ValueMap,
- string *Err = 0) {
+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;
// 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;
}
#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"
// 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);
}
// 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
// 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;
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;
#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;
}
// 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()),
- OMA->getName());
+ 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
}
#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"
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.
//
// 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
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;
}
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) {
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);
// 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.
//
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();
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);
}
-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);
}
-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;
#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"
//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);
//
// 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!");
Succ->setName(BB->getName());
delete BB; // Delete basic block
- //cerr << "Method after removal: \n" << M;
+ //cerr << "Function after removal: \n" << M;
return true;
}
}
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);
}
// 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 {
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 {
// 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;
}
#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"
// 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
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.
// 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;
}
-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.
#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"
// 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...
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.
// 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) {
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...
}
#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
// 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;
//===-----------------------------------------------------------------===//
// Handle Terminator instructions...
//
- case Instruction::Ret: return; // Method return doesn't affect anything
- case Instruction::Br: { // Handle conditional branches...
+ case Instruction::Ret: return; // Function return doesn't affect anything
+ case Instruction::Br: { // Handle conditional branches...
BranchInst *BI = cast<BranchInst>(I);
if (BI->isUnconditional())
return; // Unconditional branches are already handled!
// 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();
}
};
#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"
(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);
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,
- map<const Value*, Value*> &ValueMap,
- string *Err = 0) {
+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
// level symbol table...
SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 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; // SrcMethod
+ const Function *SM = *I; // SrcFunction
Value *V;
// If the method has a name, and that name is already in use in the
//
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(),
- SM->getName());
+ 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));
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,
- const map<const Value*, Value*> &GlobalMap,
- string *Err = 0) {
+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
// 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...
// 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) {
}
-// 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,
- map<const Value*, Value*> &ValueMap,
- string *Err = 0) {
+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;
// 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;
}
// 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
// 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.
// 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,
- "malloc"));
+ M->getFunctionList().push_back(MallocFunc = new Function(MallocType, false,
+ "malloc"));
Changed = true;
}
// 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;
}
//
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) {
}
// 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);
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);
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;
}
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());
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
#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"
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))
+ } else if (const GlobalValue *GV = dyn_cast<const GlobalValue>(V))
return GV->getParent();
else if (const Module *Mod = dyn_cast<const Module>(V))
return Mod;
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)){
+ } 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);
}
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); }
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);
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) {
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 " : "");
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());
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 << ", ";
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);
}
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);
}
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;
-//===-- 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.
//
//===----------------------------------------------------------------------===//
#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() {
#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
//===----------------------------------------------------------------------===//
-// 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);
#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"
(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);
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,
- map<const Value*, Value*> &ValueMap,
- string *Err = 0) {
+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
// level symbol table...
SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 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; // SrcMethod
+ const Function *SM = *I; // SrcFunction
Value *V;
// If the method has a name, and that name is already in use in the
//
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(),
- SM->getName());
+ 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));
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,
- const map<const Value*, Value*> &GlobalMap,
- string *Err = 0) {
+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
// 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...
// 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) {
}
-// 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,
- map<const Value*, Value*> &ValueMap,
- string *Err = 0) {
+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;
// 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;
}
//===----------------------------------------------------------------------===//
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/InstrTypes.h"
#include "llvm/ValueHolderImpl.h"
// 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>
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);
}
// 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));
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);
}
#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>
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:
// 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,
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);
// 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;
}
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) {
#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>
// 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
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 {