// graph of some sort. This iterator is parametric, allowing iterator over the
// following types of graphs:
//
-// 1. A Method* object, composed of BasicBlock nodes.
+// 1. A Function* object, composed of BasicBlock nodes.
// 2. An IntervalPartition& object, composed of Interval nodes.
//
// This iterator is defined to walk the control flow graph, returning intervals
#define LLVM_INTERVAL_ITERATOR_H
#include "llvm/Analysis/IntervalPartition.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Support/CFG.h"
#include <stack>
// source graph node that corresponds to the BasicBlock. This is the opposite
// of getNodeHeader.
//
-inline BasicBlock *getSourceGraphNode(Method *, BasicBlock *BB) {
+inline BasicBlock *getSourceGraphNode(Function *, BasicBlock *BB) {
return BB;
}
inline Interval *getSourceGraphNode(IntervalPartition *IP, BasicBlock *BB) {
typedef std::forward_iterator_tag iterator_category;
IntervalIterator() {} // End iterator, empty stack
- IntervalIterator(Method *M, bool OwnMemory) : IOwnMem(OwnMemory) {
+ IntervalIterator(Function *M, bool OwnMemory) : IOwnMem(OwnMemory) {
OrigContainer = M;
if (!ProcessInterval(M->front())) {
assert(0 && "ProcessInterval should never fail for first interval!");
}
};
-typedef IntervalIterator<BasicBlock, Method> method_interval_iterator;
+typedef IntervalIterator<BasicBlock, Function> function_interval_iterator;
typedef IntervalIterator<Interval, IntervalPartition> interval_part_interval_iterator;
-inline method_interval_iterator intervals_begin(Method *M,
- bool DeleteInts = true) {
- return method_interval_iterator(M, DeleteInts);
+inline function_interval_iterator intervals_begin(Function *F,
+ bool DeleteInts = true) {
+ return function_interval_iterator(F, DeleteInts);
}
-inline method_interval_iterator intervals_end(Method *M) {
- return method_interval_iterator();
+inline function_interval_iterator intervals_end(Function *) {
+ return function_interval_iterator();
}
inline interval_part_interval_iterator
//===-- llvm/Support/CFG.h - Process LLVM structures as graphs ---*- C++ -*--=//
//
-// This file defines specializations of GraphTraits that allow Methods and
+// This file defines specializations of GraphTraits that allow Function and
// BasicBlock graphs to be treated as proper graphs for generic algorithms.
//
//===----------------------------------------------------------------------===//
#define LLVM_CFG_H
#include "Support/GraphTraits.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/InstrTypes.h"
#include <iterator>
// GraphTraits specializations for basic block graphs (CFGs)
//===--------------------------------------------------------------------===//
-// Provide specializations of GraphTraits to be able to treat a method as a
+// Provide specializations of GraphTraits to be able to treat a function as a
// graph of basic blocks...
template <> struct GraphTraits<BasicBlock*> {
}
};
-// Provide specializations of GraphTraits to be able to treat a method as a
+// Provide specializations of GraphTraits to be able to treat a function as a
// graph of basic blocks... and to walk it in inverse order. Inverse order for
-// a method is considered to be when traversing the predecessor edges of a BB
+// a function is considered to be when traversing the predecessor edges of a BB
// instead of the successor edges.
//
template <> struct GraphTraits<Inverse<BasicBlock*> > {
//===--------------------------------------------------------------------===//
-// GraphTraits specializations for method basic block graphs (CFGs)
+// GraphTraits specializations for function basic block graphs (CFGs)
//===--------------------------------------------------------------------===//
-// Provide specializations of GraphTraits to be able to treat a method as a
+// Provide specializations of GraphTraits to be able to treat a function as a
// graph of basic blocks... these are the same as the basic block iterators,
-// except that the root node is implicitly the first node of the method.
+// except that the root node is implicitly the first node of the function.
//
-template <> struct GraphTraits<Method*> : public GraphTraits<BasicBlock*> {
- static NodeType *getEntryNode(Method *M) { return M->front(); }
+template <> struct GraphTraits<Function*> : public GraphTraits<BasicBlock*> {
+ static NodeType *getEntryNode(Function *F) { return F->getEntryNode(); }
};
-template <> struct GraphTraits<const Method*> :
+template <> struct GraphTraits<const Function*> :
public GraphTraits<const BasicBlock*> {
- static NodeType *getEntryNode(const Method *M) { return M->front(); }
+ static NodeType *getEntryNode(const Function *F) { return F->getEntryNode(); }
};
-// Provide specializations of GraphTraits to be able to treat a method as a
+// Provide specializations of GraphTraits to be able to treat a function as a
// graph of basic blocks... and to walk it in inverse order. Inverse order for
-// a method is considered to be when traversing the predecessor edges of a BB
+// a function is considered to be when traversing the predecessor edges of a BB
// instead of the successor edges.
//
-template <> struct GraphTraits<Inverse<Method*> > :
+template <> struct GraphTraits<Inverse<Function*> > :
public GraphTraits<Inverse<BasicBlock*> > {
- static NodeType *getEntryNode(Inverse<Method *> G) { return G.Graph->front();}
+ static NodeType *getEntryNode(Inverse<Function*> G) {
+ return G.Graph->front();
+ }
};
-template <> struct GraphTraits<Inverse<const Method*> > :
+template <> struct GraphTraits<Inverse<const Function*> > :
public GraphTraits<Inverse<const BasicBlock*> > {
- static NodeType *getEntryNode(Inverse<const Method *> G) {
+ static NodeType *getEntryNode(Inverse<const Function *> G) {
return G.Graph->front();
}
};
//===-- llvm/Support/InstIterator.h - Classes for inst iteration -*- C++ -*--=//
//
// This file contains definitions of two iterators for iterating over the
-// instructions in a method. This is effectively a wrapper around a two level
+// instructions in a function. This is effectively a wrapper around a two level
// iterator that can probably be genericized later.
//
// Note that this iterator gets invalidated any time that basic blocks or
#define LLVM_INST_ITERATOR_H
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
// This class is implements inst_begin() & inst_end() for
// inst_iterator and const_inst_iterator's.
};
-typedef InstIterator<ValueHolder<BasicBlock, Method, Method>, Method::iterator,
- BasicBlock::iterator, Instruction*> inst_iterator;
-typedef InstIterator<const ValueHolder<BasicBlock, Method, Method>,
- Method::const_iterator,
+typedef InstIterator<ValueHolder<BasicBlock, Function, Function>,
+ Function::iterator, BasicBlock::iterator,
+ Instruction*> inst_iterator;
+typedef InstIterator<const ValueHolder<BasicBlock, Function, Function>,
+ Function::const_iterator,
BasicBlock::const_iterator,
const Instruction*> const_inst_iterator;
-inline inst_iterator inst_begin(Method *M) { return inst_iterator(*M); }
-inline inst_iterator inst_end(Method *M) { return inst_iterator(*M, true); }
-inline const_inst_iterator inst_begin(const Method *M) {
- return const_inst_iterator(*M);
+inline inst_iterator inst_begin(Function *F) { return inst_iterator(*F); }
+inline inst_iterator inst_end(Function *F) { return inst_iterator(*F, true); }
+inline const_inst_iterator inst_begin(const Function *F) {
+ return const_inst_iterator(*F);
}
-inline const_inst_iterator inst_end(const Method *M) {
- return const_inst_iterator(*M, true);
+inline const_inst_iterator inst_end(const Function *F) {
+ return const_inst_iterator(*F, true);
}
#endif
#ifndef LLVM_TRANSFORMS_SCALAR_DCE_H
#define LLVM_TRANSFORMS_SCALAR_DCE_H
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
class Pass;
//
// WARNING: The entry node of a method may not be simplified.
//
-bool SimplifyCFG(Method::iterator &BBIt);
+bool SimplifyCFG(Function::iterator &BBIt);
#endif
-//===- SafePointerAccess.cpp - Check pointer usage safety -------------------=//
+//===- FindUnsafePointerTypes.cpp - Check pointer usage safety --------------=//
//
// This file defines a pass that can be used to determine, interprocedurally,
// which pointer types are accessed unsafely in a program. If there is an
#include "llvm/Assembly/CachedWriter.h"
#include "llvm/Type.h"
#include "llvm/Instruction.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Support/InstIterator.h"
#include "Support/CommandLine.h"
}
-// runOnMethod - Inspect the operations that the specified method does on
-// values of various types. If they are deemed to be 'unsafe' note that the
-// type is not safe to transform.
-//
bool FindUnsafePointerTypes::run(Module *Mod) {
for (Module::iterator MI = Mod->begin(), ME = Mod->end();
MI != ME; ++MI) {
- const Method *M = *MI; // We don't need/want write access
+ const Function *M = *MI; // We don't need/want write access
for (const_inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I) {
const Instruction *Inst = *I;
const Type *ITy = Inst->getType();
-//===- FindUsedTypes.h - Find all Types used by a module --------------------=//
+//===- FindUsedTypes.cpp - Find all Types used by a module ------------------=//
//
// This pass is used to seek out all of the types in use by the program.
//
#include "llvm/GlobalVariable.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Instruction.h"
#include "llvm/Support/InstIterator.h"
assert(0 && "Unimp");
}
-// doPerMethodWork - This incorporates all types used by the specified method
+// run - This incorporates all types used by the specified module
//
bool FindUsedTypes::run(Module *m) {
UsedTypes.clear(); // reset if run multiple times...
IncorporateType((*I)->getType());
for (Module::iterator MI = m->begin(), ME = m->end(); MI != ME; ++MI) {
- const Method *M = *MI;
+ const Function *M = *MI;
if (IncludeSymbolTables && M->hasSymbolTable())
IncorporateSymbolTable(M->getSymbolTable()); // Add symtab first...
- // Loop over all of the instructions in the method, adding their return type
- // as well as the types of their operands.
+ // Loop over all of the instructions in the function, adding their return
+ // type as well as the types of their operands.
//
for (const_inst_iterator II = inst_begin(M), IE = inst_end(M);
II != IE; ++II) {
//===- IntervalPartition.cpp - Interval Partition module code ----*- C++ -*--=//
//
// This file contains the definition of the cfg::IntervalPartition class, which
-// calculates and represent the interval partition of a method.
+// calculates and represent the interval partition of a function.
//
//===----------------------------------------------------------------------===//
// IntervalPartition Implementation
//===----------------------------------------------------------------------===//
-// destroy - Reset state back to before method was analyzed
+// destroy - Reset state back to before function was analyzed
void IntervalPartition::destroy() {
for_each(begin(), end(), deleter<cfg::Interval>);
IntervalMap.clear();
}
// IntervalPartition ctor - Build the first level interval partition for the
-// specified method...
+// specified function...
//
-bool IntervalPartition::runOnMethod(Method *M) {
+bool IntervalPartition::runOnMethod(Function *M) {
assert(M->front() && "Cannot operate on prototypes!");
// Pass false to intervals_begin because we take ownership of it's memory
- method_interval_iterator I = intervals_begin(M, false);
- assert(I != intervals_end(M) && "No intervals in method!?!?!");
+ function_interval_iterator I = intervals_begin(M, false);
+ assert(I != intervals_end(M) && "No intervals in function!?!?!");
addIntervalToPartition(RootInterval = *I);
// distinguish it from a copy constructor. Always pass in false for now.
//
IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) {
- Interval *MethodStart = IP.getRootInterval();
- assert(MethodStart && "Cannot operate on empty IntervalPartitions!");
+ Interval *FunctionStart = IP.getRootInterval();
+ assert(FunctionStart && "Cannot operate on empty IntervalPartitions!");
// Pass false to intervals_begin because we take ownership of it's memory
interval_part_interval_iterator I = intervals_begin(IP, false);
//===- DominatorSet.cpp - Dominator Set Calculation --------------*- C++ -*--=//
//
-// This file provides a simple class to calculate the dominator set of a method.
+// This file provides a simple class to calculate the dominator set of a
+// function.
//
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/Dominators.h"
#include "llvm/Transforms/UnifyMethodExitNodes.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h"
#include "Support/STLExtras.h"
AnalysisID cfg::DominatorSet::ID(AnalysisID::create<cfg::DominatorSet>());
AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create<cfg::DominatorSet>());
-bool cfg::DominatorSet::runOnMethod(Method *M) {
+bool cfg::DominatorSet::runOnMethod(Function *F) {
Doms.clear(); // Reset from the last time we were run...
if (isPostDominator())
- calcPostDominatorSet(M);
+ calcPostDominatorSet(F);
else
- calcForwardDominatorSet(M);
+ calcForwardDominatorSet(F);
return false;
}
// calcForwardDominatorSet - This method calculates the forward dominator sets
-// for the specified method.
+// for the specified function.
//
-void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
+void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
Root = M->getEntryNode();
assert(pred_begin(Root) == pred_end(Root) &&
- "Root node has predecessors in method!");
+ "Root node has predecessors in function!");
bool Changed;
do {
Changed = false;
DomSetType WorkingSet;
- df_iterator<Method*> It = df_begin(M), End = df_end(M);
+ df_iterator<Function*> It = df_begin(M), End = df_end(M);
for ( ; It != End; ++It) {
const BasicBlock *BB = *It;
pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
} while (Changed);
}
-// Postdominator set constructor. This ctor converts the specified method to
+// Postdominator set constructor. This ctor converts the specified function to
// only have a single exit node (return stmt), then calculates the post
-// dominance sets for the method.
+// dominance sets for the function.
//
-void cfg::DominatorSet::calcPostDominatorSet(Method *M) {
+void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
// Since we require that the unify all exit nodes pass has been run, we know
- // that there can be at most one return instruction in the method left.
+ // that there can be at most one return instruction in the function left.
// Get it.
//
Root = getAnalysis<UnifyMethodExitNodes>().getExitNode();
- if (Root == 0) { // No exit node for the method? Postdomsets are all empty
- for (Method::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
+ if (Root == 0) { // No exit node for the function? Postdomsets are all empty
+ for (Function::const_iterator MI = M->begin(), ME = M->end(); MI!=ME; ++MI)
Doms[*MI] = DomSetType();
return;
}
// Given immediate dominators, we can also calculate the dominator tree
cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
: DominatorBase(IDoms.getRoot()) {
- const Method *M = Root->getParent();
+ const Function *M = Root->getParent();
Nodes[Root] = new Node(Root, 0); // Add a node for the root...
// Iterate over all nodes in depth first order...
- for (df_iterator<const Method*> I = df_begin(M), E = df_end(M); I != E; ++I) {
+ for (df_iterator<const Function*> I = df_begin(M), E = df_end(M); I!=E; ++I) {
const BasicBlock *BB = *I, *IDom = IDoms[*I];
if (IDom != 0) { // Ignore the root node and other nasty nodes
// current node, and it is our idom! We know that we have already added
// a DominatorTree node for our idom, because the idom must be a
// predecessor in the depth first order that we are iterating through the
- // method.
+ // function.
//
DominatorSet::DomSetType::const_iterator I = Dominators.begin();
DominatorSet::DomSetType::const_iterator End = Dominators.end();
// chain than the current node, and it is our idom! We know that we have
// already added a DominatorTree node for our idom, because the idom must
// be a predecessor in the depth first order that we are iterating through
- // the method.
+ // the function.
//
DominatorSet::DomSetType::const_iterator I = Dominators.begin();
DominatorSet::DomSetType::const_iterator End = Dominators.end();
#include "WriterInternals.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Instruction.h"
#include "llvm/DerivedTypes.h"
}
-// outputInstrVarArgsCall - Output the obsurdly annoying varargs method calls.
+// outputInstrVarArgsCall - Output the obsurdly annoying varargs function calls.
// This are more annoying than most because the signature of the call does not
// tell us anything about the types of the arguments in the varargs portion.
// Because of this, we encode (as type 0) all of the argument types explicitly
unsigned NumArgs = I->getNumOperands();
output_vbr(NumArgs*2, Out);
- // TODO: Don't need to emit types for the fixed types of the varargs method
+ // TODO: Don't need to emit types for the fixed types of the varargs function
// prototype...
- // The type for the method has already been emitted in the type field of the
+ // The type for the function has already been emitted in the type field of the
// instruction. Just emit the slot # now.
int Slot = Table.getValSlot(I->getOperand(0));
assert(Slot >= 0 && "No slot number for value!?!?");
#include "llvm/Analysis/SlotCalculator.h"
#include "llvm/Analysis/ConstantsScanner.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Module.h"
#include "llvm/BasicBlock.h"
processModule();
}
-SlotCalculator::SlotCalculator(const Method *M, bool IgnoreNamed) {
+SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
IgnoreNamedNodes = IgnoreNamed;
TheModule = M ? M->getParent() : 0;
}
-// processModule - Process all of the module level method declarations and
+// processModule - Process all of the module level function declarations and
// types that are available.
//
void SlotCalculator::processModule() {
for_each(TheModule->gbegin(), TheModule->gend(),
bind_obj(this, &SlotCalculator::insertValue));
- // Scavenge the types out of the methods, then add the methods themselves to
- // the value table...
+ // Scavenge the types out of the functions, then add the functions themselves
+ // to the value table...
//
- for_each(TheModule->begin(), TheModule->end(), // Insert methods...
+ for_each(TheModule->begin(), TheModule->end(), // Insert functions...
bind_obj(this, &SlotCalculator::insertValue));
// Insert constants that are named at module level into the slot pool so that
}
-void SlotCalculator::incorporateMethod(const Method *M) {
+void SlotCalculator::incorporateMethod(const Function *M) {
assert(ModuleLevel.size() == 0 && "Module already incorporated!");
- SC_DEBUG("begin processMethod!\n");
+ SC_DEBUG("begin processFunction!\n");
- // Save the Table state before we process the method...
+ // Save the Table state before we process the function...
for (unsigned i = 0; i < Table.size(); ++i)
ModuleLevel.push_back(Table[i].size());
- SC_DEBUG("Inserting method arguments\n");
+ SC_DEBUG("Inserting function arguments\n");
- // Iterate over method arguments, adding them to the value table...
+ // Iterate over function arguments, adding them to the value table...
for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
bind_obj(this, &SlotCalculator::insertValue));
- // Iterate over all of the instructions in the method, looking for constant
+ // Iterate over all of the instructions in the function, looking for constant
// values that are referenced. Add these to the value pools before any
// nonconstant values. This will be turned into the constant pool for the
// bytecode writer.
//
if (!IgnoreNamedNodes) { // Assembly writer does not need this!
- SC_DEBUG("Inserting method constants:\n";
+ SC_DEBUG("Inserting function constants:\n";
for (constant_iterator I = constant_begin(M), E = constant_end(M);
I != E; ++I) {
cerr << " " << I->getType()->getDescription()
});
// Emit all of the constants that are being used by the instructions in the
- // method...
+ // function...
for_each(constant_begin(M), constant_end(M),
bind_obj(this, &SlotCalculator::insertValue));
processSymbolTable(M->getSymbolTable());
}
- SC_DEBUG("end processMethod!\n");
+ SC_DEBUG("end processFunction!\n");
}
void SlotCalculator::purgeMethod() {
assert(ModuleLevel.size() != 0 && "Module not incorporated!");
unsigned NumModuleTypes = ModuleLevel.size();
- SC_DEBUG("begin purgeMethod!\n");
+ SC_DEBUG("begin purgeFunction!\n");
// First, remove values from existing type planes
for (unsigned i = 0; i < NumModuleTypes; ++i) {
- unsigned ModuleSize = ModuleLevel[i]; // Size of plane before method came
+ unsigned ModuleSize = ModuleLevel[i]; // Size of plane before function came
TypePlane &CurPlane = Table[i];
//SC_DEBUG("Processing Plane " <<i<< " of size " << CurPlane.size() <<endl);
// We don't need this state anymore, free it up.
ModuleLevel.clear();
- // Next, remove any type planes defined by the method...
+ // Next, remove any type planes defined by the function...
while (NumModuleTypes != Table.size()) {
TypePlane &Plane = Table.back();
SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size "
Table.pop_back(); // Nuke the plane, we don't like it.
}
- SC_DEBUG("end purgeMethod!\n");
+ SC_DEBUG("end purgeFunction!\n");
}
int SlotCalculator::getValSlot(const Value *D) const {
SC_DEBUG(" Inserting value [" << Ty << "] = " << D << " slot=" <<
DestSlot << " [");
- // G = Global, C = Constant, T = Type, M = Method, o = other
+ // G = Global, C = Constant, T = Type, F = Function, o = other
SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" :
- (isa<Type>(D) ? "T" : (isa<Method>(D) ? "M" : "o")))));
+ (isa<Type>(D) ? "T" : (isa<Function>(D) ? "F" : "o")))));
SC_DEBUG("]\n");
return (int)DestSlot;
}
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iOther.h"
#include "Support/StringExtras.h"
#include "Support/STLExtras.h"
//
/*ctor*/
-SchedGraphSet::SchedGraphSet(const Method* _method,
+SchedGraphSet::SchedGraphSet(const Function* _function,
const TargetMachine& target) :
- method(_method)
+ method(_function)
{
buildGraphsForMethod(method, target);
}
void
SchedGraphSet::dump() const
{
- cerr << "======== Sched graphs for method `" << method->getName()
+ cerr << "======== Sched graphs for function `" << method->getName()
<< "' ========\n\n";
for (const_iterator I=begin(); I != end(); ++I)
(*I)->dump();
- cerr << "\n====== End graphs for method `" << method->getName()
+ cerr << "\n====== End graphs for function `" << method->getName()
<< "' ========\n\n";
}
void
-SchedGraphSet::buildGraphsForMethod(const Method *method,
+SchedGraphSet::buildGraphsForMethod(const Function *F,
const TargetMachine& target)
{
- for (Method::const_iterator BI = method->begin(); BI != method->end(); ++BI)
- this->addGraph(new SchedGraph(*BI, target));
+ for (Function::const_iterator BI = F->begin(); BI != F->end(); ++BI)
+ addGraph(new SchedGraph(*BI, target));
}
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iPHINode.h"
#include "Support/CommandLine.h"
#include <iostream>
short* nts,
TargetMachine &target);
-static void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target);
+static void InsertCode4AllPhisInMeth(Function *F, TargetMachine &target);
//---------------------------------------------------------------------------
bool
-SelectInstructionsForMethod(Method* method, TargetMachine &target)
+SelectInstructionsForMethod(Function *F, TargetMachine &target)
{
bool failed = false;
//
// Build the instruction trees to be given as inputs to BURG.
//
- InstrForest instrForest(method);
+ InstrForest instrForest(F);
if (SelectDebugLevel >= Select_DebugInstTrees)
{
- cerr << "\n\n*** Input to instruction selection for method "
- << (method->hasName()? method->getName() : "")
- << "\n\n";
- method->dump();
+ cerr << "\n\n*** Input to instruction selection for function "
+ << F->getName() << "\n\n";
+ F->dump();
- cerr << "\n\n*** Instruction trees for method "
- << (method->hasName()? method->getName() : "")
- << "\n\n";
+ cerr << "\n\n*** Instruction trees for function "
+ << F->getName() << "\n\n";
instrForest.dump();
}
//
// Record instructions in the vector for each basic block
//
- for (Method::iterator BI = method->begin(); BI != method->end(); ++BI)
+ for (Function::iterator BI = F->begin(), BE = F->end(); BI != BE; ++BI)
{
MachineCodeForBasicBlock& bbMvec = (*BI)->getMachineInstrVec();
for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II)
}
// Insert phi elimination code -- added by Ruchira
- InsertCode4AllPhisInMeth(method, target);
+ InsertCode4AllPhisInMeth(F, target);
if (SelectDebugLevel >= Select_PrintMachineCode)
{
cerr << "\n*** Machine instructions after INSTRUCTION SELECTION\n";
- MachineCodeForMethod::get(method).dump();
+ MachineCodeForMethod::get(F).dump();
}
return false;
//-------------------------------------------------------------------------
void
-InsertCode4AllPhisInMeth(Method *method, TargetMachine &target)
+InsertCode4AllPhisInMeth(Function *F, TargetMachine &target)
{
- // for all basic blocks in method
+ // for all basic blocks in function
//
- for (Method::iterator BI = method->begin(); BI != method->end(); ++BI) {
+ for (Function::iterator BI = F->begin(); BI != F->end(); ++BI) {
BasicBlock *BB = *BI;
const BasicBlock::InstListType &InstList = BB->getInstList();
else break; // since PHI nodes can only be at the top
} // for each Phi Instr in BB
-
- } // for all BBs in method
-
+ } // for all BBs in function
}
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/ConstantVals.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Type.h"
#include "llvm/iMemory.h"
static TmpInstruction*
-InsertCodeToLoadConstant(Method* method,
+InsertCodeToLoadConstant(Function *F,
Value* opValue,
Instruction* vmInstr,
vector<MachineInstr*>& loadConstVec,
MachineCodeForInstruction &MCFI = MachineCodeForInstruction::get(vmInstr);
MCFI.addTemp(tmpReg);
- target.getInstrInfo().CreateCodeToLoadConst(method, opValue, tmpReg,
+ target.getInstrInfo().CreateCodeToLoadConst(F, opValue, tmpReg,
loadConstVec, tempVec);
// Register the new tmp values created for this m/c instruction sequence
const MachineInstrDescriptor& instrDesc =
target.getInstrInfo().getDescriptor(minstr->getOpCode());
- Method* method = vmInstr->getParent()->getParent();
+ Function *F = vmInstr->getParent()->getParent();
for (unsigned op=0; op < minstr->getNumOperands(); op++)
{
if (constantThatMustBeLoaded || isa<GlobalValue>(opValue))
{ // opValue is a constant that must be explicitly loaded into a reg.
- TmpInstruction* tmpReg = InsertCodeToLoadConstant(method, opValue, vmInstr,
- loadConstVec, target);
+ TmpInstruction* tmpReg = InsertCodeToLoadConstant(F, opValue, vmInstr,
+ loadConstVec,
+ target);
minstr->SetMachineOperandVal(op, MachineOperand::MO_VirtualRegister,
tmpReg);
}
{
Value* oldVal = minstr->getImplicitRef(i);
TmpInstruction* tmpReg =
- InsertCodeToLoadConstant(method, oldVal, vmInstr, loadConstVec, target);
+ InsertCodeToLoadConstant(F, oldVal, vmInstr, loadConstVec, target);
minstr->setImplicitRef(i, tmpReg);
}
-//===-- MachineCodeForMethod.cpp --------------------------------------------=//
+//===-- MachineCodeForFunction.cpp ------------------------------------------=//
//
// Purpose:
-// Collect native machine code information for a method.
+// Collect native machine code information for a function.
// This allows target-specific information about the generated code
-// to be stored with each method.
+// to be stored with each function.
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/MachineCodeForMethod.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/MachineFrameInfo.h"
#include "llvm/Target/MachineCacheInfo.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/iOther.h"
#include <limits.h>
const int INVALID_FRAME_OFFSET = INT_MAX; // std::numeric_limits<int>::max();
static AnnotationID MCFM_AID(
- AnnotationManager::getID("CodeGen::MachineCodeForMethod"));
+ AnnotationManager::getID("CodeGen::MachineCodeForFunction"));
// The next two methods are used to construct and to retrieve
-// the MachineCodeForMethod object for the given method.
-// construct() -- Allocates and initializes for a given method and target
+// the MachineCodeForFunction object for the given function.
+// construct() -- Allocates and initializes for a given function and target
// get() -- Returns a handle to the object.
// This should not be called before "construct()"
-// for a given Method.
+// for a given Function.
//
MachineCodeForMethod&
-MachineCodeForMethod::construct(const Method *M, const TargetMachine &Tar)
+MachineCodeForMethod::construct(const Function *M, const TargetMachine &Tar)
{
assert(M->getAnnotation(MCFM_AID) == 0 &&
- "Object already exists for this method!");
+ "Object already exists for this function!");
MachineCodeForMethod* mcInfo = new MachineCodeForMethod(M, Tar);
M->addAnnotation(mcInfo);
return *mcInfo;
}
void
-MachineCodeForMethod::destruct(const Method *M)
+MachineCodeForMethod::destruct(const Function *M)
{
bool Deleted = M->deleteAnnotation(MCFM_AID);
- assert(Deleted && "Machine code did not exist for method!");
+ assert(Deleted && "Machine code did not exist for function!");
}
MachineCodeForMethod&
-MachineCodeForMethod::get(const Method* method)
+MachineCodeForMethod::get(const Function *F)
{
- MachineCodeForMethod* mc = (MachineCodeForMethod*)
- method->getAnnotation(MCFM_AID);
+ MachineCodeForMethod *mc = (MachineCodeForMethod*)F->getAnnotation(MCFM_AID);
assert(mc && "Call construct() method first to allocate the object");
return *mc;
}
static unsigned
-ComputeMaxOptionalArgsSize(const TargetMachine& target, const Method* method)
+ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F)
{
const MachineFrameInfo& frameInfo = target.getFrameInfo();
unsigned int maxSize = 0;
- for (Method::const_iterator MI=method->begin(), ME=method->end();
- MI != ME; ++MI)
+ for (Function::const_iterator MI = F->begin(), ME = F->end(); MI != ME; ++MI)
{
const BasicBlock *BB = *MI;
- for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+ for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I)
if (CallInst *callInst = dyn_cast<CallInst>(*I))
{
unsigned int numOperands = callInst->getNumOperands() - 1;
- int numExtra = (int) numOperands - frameInfo.getNumFixedOutgoingArgs();
+ int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs();
if (numExtra <= 0)
continue;
}
else
{
- assert(0 && "UNTESTED CODE: Size per stack argument is not fixed on this architecture: use actual arg sizes to compute MaxOptionalArgsSize");
+ assert(0 && "UNTESTED CODE: Size per stack argument is not "
+ "fixed on this architecture: use actual arg sizes to "
+ "compute MaxOptionalArgsSize");
sizeForThisCall = 0;
for (unsigned i=0; i < numOperands; ++i)
sizeForThisCall += target.findOptimalStorageSize(callInst->
/*ctor*/
-MachineCodeForMethod::MachineCodeForMethod(const Method* _M,
+MachineCodeForMethod::MachineCodeForMethod(const Function *F,
const TargetMachine& target)
: Annotation(MCFM_AID),
- method(_M), compiledAsLeaf(false), staticStackSize(0),
+ method(F), compiledAsLeaf(false), staticStackSize(0),
automaticVarsSize(0), regSpillsSize(0),
currentOptionalArgsSize(0), maxOptionalArgsSize(0),
currentTmpValuesSize(0), maxTmpValuesSize(0)
std::cerr << "\n" << method->getReturnType()
<< " \"" << method->getName() << "\"\n";
- for (Method::const_iterator BI = method->begin(); BI != method->end(); ++BI)
+ for (Function::const_iterator BI = method->begin(); BI != method->end(); ++BI)
{
BasicBlock* bb = *BI;
std::cerr << "\n" << bb->getName() << " (" << bb << ")" << ":\n";
for (unsigned i=0; i < mvec.size(); i++)
std::cerr << "\t" << *mvec[i];
}
- std::cerr << "\nEnd method \"" << method->getName() << "\"\n\n";
+ std::cerr << "\nEnd function \"" << method->getName() << "\"\n\n";
}
#include "llvm/CodeGen/RegClass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "Support/SetOperations.h"
#include <iostream>
using std::cerr;
-LiveRangeInfo::LiveRangeInfo(const Method *M, const TargetMachine &tm,
+LiveRangeInfo::LiveRangeInfo(const Function *F, const TargetMachine &tm,
std::vector<RegClass *> &RCL)
- : Meth(M), TM(tm), RegClassList(RCL), MRI(tm.getRegInfo()) { }
+ : Meth(F), TM(tm), RegClassList(RCL), MRI(tm.getRegInfo()) { }
LiveRangeInfo::~LiveRangeInfo() {
//assert(( L1->getTypeID() == L2->getTypeID()) && "Merge:Different types");
L1->insert(*L2It); // add the var in L2 to L1
- LiveRangeMap[*L2It] = L1; // now the elements in L2 should map
+ LiveRangeMap[*L2It] = L1; // now the elements in L2 should map
//to L1
}
//---------------------------------------------------------------------------
-// Method for constructing all live ranges in a method. It creates live
+// Method for constructing all live ranges in a function. It creates live
// ranges for all values defined in the instruction stream. Also, it
-// creates live ranges for all incoming arguments of the method.
+// creates live ranges for all incoming arguments of the function.
//---------------------------------------------------------------------------
void LiveRangeInfo::constructLiveRanges() {
if (DEBUG_RA)
cerr << "Consturcting Live Ranges ...\n";
- // first find the live ranges for all incoming args of the method since
- // those LRs start from the start of the method
+ // first find the live ranges for all incoming args of the function since
+ // those LRs start from the start of the function
- // get the argument list
- const Method::ArgumentListType& ArgList = Meth->getArgumentList();
- // get an iterator to arg list
- Method::ArgumentListType::const_iterator ArgIt = ArgList.begin();
+ // get the argument list
+ const Function::ArgumentListType& ArgList = Meth->getArgumentList();
-
+ Function::ArgumentListType::const_iterator ArgIt = ArgList.begin();
for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument
LiveRange * ArgRange = new LiveRange(); // creates a new LR and
const Value *Val = (const Value *) *ArgIt;
}
}
- // Now suggest hardware registers for these method args
+ // Now suggest hardware registers for these function args
MRI.suggestRegs4MethodArgs(Meth, *this);
-
// Now find speical LLVM instructions (CALL, RET) and LRs in machine
// instructions.
//
- for (Method::const_iterator BBI = Meth->begin(); BBI != Meth->end(); ++BBI) {
+ for (Function::const_iterator BBI = Meth->begin(); BBI != Meth->end(); ++BBI){
// Now find all LRs for machine the instructions. A new LR will be created
// only for defs in the machine instr since, we assume that all Values are
// defined before they are used. However, there can be multiple defs for
} // for all machine instructions in the BB
- } // for all BBs in method
+ } // for all BBs in function
// Now we have to suggest clors for call and return arg live ranges.
//---------------------------------------------------------------------------
// If some live ranges must be colored with specific hardware registers
// (e.g., for outgoing call args), suggesting of colors for such live
-// ranges is done using target specific method. Those methods are called
+// ranges is done using target specific function. Those functions are called
// from this function. The target specific methods must:
// 1) suggest colors for call and return args.
// 2) create new LRs for implicit defs in machine instructions
//---------------------------------------------------------------------------
void LiveRangeInfo::suggestRegs4CallRets()
{
-
CallRetInstrListType::const_iterator It = CallRetInstrList.begin();
-
for( ; It != CallRetInstrList.end(); ++It ) {
const MachineInstr *MInst = *It;
/* Algorithm:
- for each BB in method
+ for each BB in function
for each machine instruction (inst)
for each definition (def) in inst
for each operand (op) of inst that is a use
//---------------------------------------------------------------------------
void LiveRangeInfo::coalesceLRs()
{
- if( DEBUG_RA)
+ if(DEBUG_RA)
cerr << "\nCoalscing LRs ...\n";
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
+ for(Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
// get the iterator for machine instructions
const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/MachineFrameInfo.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Type.h"
#include <iostream>
#include <math.h>
public:
inline RegisterAllocator(TargetMachine &T) : Target(T) {}
- bool runOnMethod(Method *M) {
+ bool runOnMethod(Function *F) {
if (DEBUG_RA)
- cerr << "\n******************** Method "<< M->getName()
+ cerr << "\n******************** Method "<< F->getName()
<< " ********************\n";
- PhyRegAlloc PRA(M, Target, &getAnalysis<MethodLiveVarInfo>(),
+ PhyRegAlloc PRA(F, Target, &getAnalysis<MethodLiveVarInfo>(),
&getAnalysis<cfg::LoopInfo>());
PRA.allocateRegisters();
//----------------------------------------------------------------------------
// Constructor: Init local composite objects and create register classes.
//----------------------------------------------------------------------------
-PhyRegAlloc::PhyRegAlloc(Method *M,
+PhyRegAlloc::PhyRegAlloc(Function *F,
const TargetMachine& tm,
MethodLiveVarInfo *Lvi,
cfg::LoopInfo *LDC)
- : TM(tm), Meth(M),
- mcInfo(MachineCodeForMethod::get(M)),
- LVI(Lvi), LRI(M, tm, RegClassList),
- MRI( tm.getRegInfo() ),
+ : TM(tm), Meth(F),
+ mcInfo(MachineCodeForMethod::get(F)),
+ LVI(Lvi), LRI(F, tm, RegClassList),
+ MRI(tm.getRegInfo()),
NumOfRegClasses(MRI.getNumOfRegClasses()),
LoopDepthCalc(LDC) {
// create each RegisterClass and put in RegClassList
//
for(unsigned int rc=0; rc < NumOfRegClasses; rc++)
- RegClassList.push_back( new RegClass(M, MRI.getMachineRegClass(rc),
- &ResColList) );
+ RegClassList.push_back(new RegClass(F, MRI.getMachineRegClass(rc),
+ &ResColList));
}
if(DEBUG_RA) cerr << "Creating interference graphs ...\n";
unsigned BBLoopDepthCost;
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
+ for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
// find the 10^(loop_depth) of this BB
//
- BBLoopDepthCost = (unsigned) pow( 10.0, LoopDepthCalc->getLoopDepth(*BBI));
+ BBLoopDepthCost = (unsigned) pow(10.0, LoopDepthCalc->getLoopDepth(*BBI));
// get the iterator for machine instructions
//
} // for all machine instructions in BB
-
- } // for all BBs in method
+ } // for all BBs in function
- // add interferences for method arguments. Since there are no explict
- // defs in method for args, we have to add them manually
+ // add interferences for function arguments. Since there are no explict
+ // defs in the function for args, we have to add them manually
//
addInterferencesForArgs();
//----------------------------------------------------------------------------
-// This method will add interferences for incoming arguments to a method.
+// This method will add interferences for incoming arguments to a function.
//----------------------------------------------------------------------------
void PhyRegAlloc::addInterferencesForArgs() {
// get the InSet of root BB
const ValueSet &InSet = LVI->getInSetOfBB(Meth->front());
// get the argument list
- const Method::ArgumentListType& ArgList = Meth->getArgumentList();
+ const Function::ArgumentListType &ArgList = Meth->getArgumentList();
// get an iterator to arg list
- Method::ArgumentListType::const_iterator ArgIt = ArgList.begin();
+ Function::ArgumentListType::const_iterator ArgIt = ArgList.begin();
for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument
void PhyRegAlloc::updateMachineCode()
{
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
-
+ for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
// get the iterator for machine instructions
//
MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
void PhyRegAlloc::printMachineCode()
{
- cerr << "\n;************** Method " << Meth->getName()
+ cerr << "\n;************** Function " << Meth->getName()
<< " *****************\n";
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
-
- cerr << "\n"; printLabel( *BBI); cerr << ": ";
+ for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
+ cerr << "\n"; printLabel(*BBI); cerr << ": ";
// get the iterator for machine instructions
MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
// iterate over all the machine instructions in BB
for( ; MInstIterator != MIVec.end(); ++MInstIterator) {
-
MachineInstr *const MInst = *MInstIterator;
-
cerr << "\n\t";
cerr << TargetInstrDescriptors[MInst->getOpCode()].opCodeString;
-
-
- //for(MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done();++OpI) {
for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
-
MachineOperand& Op = MInst->getOperand(OpNum);
if( Op.getOperandType() == MachineOperand::MO_VirtualRegister ||
// So reset it before we call each such method
//mcInfo.popAllTempValues(TM);
-
if (TM.getInstrInfo().isCall(OpCode))
MRI.colorCallArgs(CRMI, LRI, AI, *this);
// This annotation will only be created on GlobalValue objects...
GlobalValue *GVal = cast<GlobalValue>((Value*)O);
- if (isa<Method>(GVal)) {
- // The GlobalAddress object for a method is just a pointer to method itself.
- // Don't delete it when the annotation is gone though!
+ if (isa<Function>(GVal)) {
+ // The GlobalAddress object for a function is just a pointer to function
+ // itself. Don't delete it when the annotation is gone though!
return new GlobalAddress(GVal, false);
}
// Handle the case of a global variable...
assert(isa<GlobalVariable>(GVal) &&
- "Global value found that isn't a method or global variable!");
+ "Global value found that isn't a function or global variable!");
GlobalVariable *GV = cast<GlobalVariable>(GVal);
// First off, we must allocate space for the global variable to point at...
}
// Save previously executing meth
- const Method *M = ECStack.back().CurMethod;
+ const Function *M = ECStack.back().CurMethod;
// Pop the current stack frame... this invalidates SF
ECStack.pop_back();
if (ECStack.empty()) { // Finished main. Put result into exit code...
if (RetTy) { // Nonvoid return type?
if (!QuietMode) {
- CW << "Method " << M->getType() << " \"" << M->getName()
+ CW << "Function " << M->getType() << " \"" << M->getName()
<< "\" returned ";
print(RetTy, Result);
cout << "\n";
} else if (!QuietMode) {
// This must be a function that is executing because of a user 'call'
// instruction.
- CW << "Method " << M->getType() << " \"" << M->getName()
+ CW << "Function " << M->getType() << " \"" << M->getName()
<< "\" returned ";
print(RetTy, Result);
cout << "\n";
ArgVals.push_back(getOperandValue(I->getOperand(i), SF));
// To handle indirect calls, we must get the pointer value from the argument
- // and treat it as a method pointer.
+ // and treat it as a function pointer.
GenericValue SRC = getOperandValue(I->getCalledValue(), SF);
- callMethod((Method*)SRC.PointerVal, ArgVals);
+ callMethod((Function*)SRC.PointerVal, ArgVals);
}
static void executePHINode(PHINode *I, ExecutionContext &SF) {
// Dispatch and Execution Code
//===----------------------------------------------------------------------===//
-MethodInfo::MethodInfo(Method *M) : Annotation(MethodInfoAID) {
- // Assign slot numbers to the method arguments...
- const Method::ArgumentListType &ArgList = M->getArgumentList();
- for (Method::ArgumentListType::const_iterator AI = ArgList.begin(),
+MethodInfo::MethodInfo(Function *M) : Annotation(MethodInfoAID) {
+ // Assign slot numbers to the function arguments...
+ const Function::ArgumentListType &ArgList = M->getArgumentList();
+ for (Function::ArgumentListType::const_iterator AI = ArgList.begin(),
AE = ArgList.end(); AI != AE; ++AI)
(*AI)->addAnnotation(new SlotNumber(getValueSlot(*AI)));
// Iterate over all of the instructions...
unsigned InstNum = 0;
- 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 II = BB->begin(), IE = BB->end(); II != IE; ++II){
Instruction *I = *II; // For each instruction... Add Annote
//===----------------------------------------------------------------------===//
-// callMethod - Execute the specified method...
+// callMethod - Execute the specified function...
//
-void Interpreter::callMethod(Method *M, const vector<GenericValue> &ArgVals) {
+void Interpreter::callMethod(Function *M, const vector<GenericValue> &ArgVals) {
assert((ECStack.empty() || ECStack.back().Caller == 0 ||
ECStack.back().Caller->getNumOperands()-1 == ArgVals.size()) &&
"Incorrect number of arguments passed into function call!");
SF.Caller = 0; // We returned from the call...
} else if (!QuietMode) {
// print it.
- CW << "Method " << M->getType() << " \"" << M->getName()
+ CW << "Function " << M->getType() << " \"" << M->getName()
<< "\" returned ";
print(RetTy, Result);
cout << "\n";
return;
}
- // Process the method, assigning instruction numbers to the instructions in
- // the method. Also calculate the number of values for each type slot active.
+ // Process the function, assigning instruction numbers to the instructions in
+ // the function. Also calculate the number of values for each type slot
+ // active.
//
MethodInfo *MethInfo = (MethodInfo*)M->getOrCreateAnnotation(MethodInfoAID);
ECStack.push_back(ExecutionContext()); // Make a new stack frame...
StackFrame.PrevBB = 0; // No previous BB for PHI nodes...
- // Run through the method arguments and initialize their values...
+ // Run through the function arguments and initialize their values...
assert(ArgVals.size() == M->getArgumentList().size() &&
- "Invalid number of values passed to method invocation!");
+ "Invalid number of values passed to function invocation!");
unsigned i = 0;
- for (Method::ArgumentListType::iterator MI = M->getArgumentList().begin(),
+ for (Function::ArgumentListType::iterator MI = M->getArgumentList().begin(),
ME = M->getArgumentList().end(); MI != ME; ++MI, ++i) {
SetValue(*MI, ArgVals[i], StackFrame);
}
Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
if (!PickedVal) return;
- if (const Method *M = dyn_cast<const Method>(PickedVal)) {
- CW << M; // Print the method
+ if (const Function *F = dyn_cast<const Function>(PickedVal)) {
+ CW << F; // Print the function
} else if (const Type *Ty = dyn_cast<const Type>(PickedVal)) {
CW << "type %" << Name << " = " << Ty->getDescription() << "\n";
} else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(PickedVal)) {
//
void Interpreter::printStackFrame(int FrameNo = -1) {
if (FrameNo == -1) FrameNo = CurFrame;
- Method *Meth = ECStack[FrameNo].CurMethod;
- const Type *RetTy = Meth->getReturnType();
+ Function *Func = ECStack[FrameNo].CurMethod;
+ const Type *RetTy = Func->getReturnType();
CW << ((FrameNo == CurFrame) ? '>' : '-') << "#" << FrameNo << ". "
- << (Value*)RetTy << " \"" << Meth->getName() << "\"(";
+ << (Value*)RetTy << " \"" << Func->getName() << "\"(";
- Method::ArgumentListType &Args = Meth->getArgumentList();
+ Function::ArgumentListType &Args = Func->getArgumentList();
for (unsigned i = 0; i < Args.size(); ++i) {
if (i != 0) cout << ", ";
CW << (Value*)Args[i] << "=";
// Support for MethodInfo annotations
//===----------------------------------------------------------------------===//
-// This annotation (attached only to Method objects) is used to cache useful
-// information about the method, including the number of types present in the
-// method, and the number of values for each type.
+// This annotation (attached only to Function objects) is used to cache useful
+// information about the function, including the number of types present in the
+// function, and the number of values for each type.
//
// This annotation object is created on demand, and attaches other annotation
-// objects to the instructions in the method when it's created.
+// objects to the instructions in the function when it's created.
//
static AnnotationID MethodInfoAID(
- AnnotationManager::getID("Interpreter::MethodInfo"));
+ AnnotationManager::getID("Interpreter::FunctionInfo"));
struct MethodInfo : public Annotation {
- MethodInfo(Method *M);
+ MethodInfo(Function *F);
std::vector<unsigned> NumPlaneElements;
//
static Annotation *Create(AnnotationID AID, const Annotable *O, void *) {
assert(AID == MethodInfoAID);
- return new MethodInfo(cast<Method>((Value*)O)); // Simply invoke the ctor
+ return new MethodInfo(cast<Function>((Value*)O)); // Simply invoke the ctor
}
private:
// used to hold the the slot number for the value in its type plane.
//
// Entities have this annotation attached to them when the containing
-// method has it's MethodInfo created (by the MethodInfo ctor).
+// function has it's MethodInfo created (by the MethodInfo ctor).
//
static AnnotationID SlotNumberAID(
AnnotationManager::getID("Interpreter::SlotNumber"));
// its type plane. InstNumber's are used for user interaction, and for
// calculating which value slot to store the result of the instruction in.
//
-// Instructions have this annotation attached to them when the containing method
-// has it's MethodInfo created (by the MethodInfo ctor).
+// Instructions have this annotation attached to them when the containing
+// function has it's MethodInfo created (by the MethodInfo ctor).
//
struct InstNumber : public SlotNumber {
unsigned InstNum; // Ranges from 1->
//===----------------------------------------------------------------------===//
// This annotation (attached only to GlobalValue objects) is used to hold the
-// address of the chunk of memory that represents a global value. For Method's,
-// this pointer is the Method object pointer that represents it. For global
-// variables, this is the dynamically allocated (and potentially initialized)
-// chunk of memory for the global. This annotation is created on demand.
+// address of the chunk of memory that represents a global value. For
+// Functions, this pointer is the Function object pointer that represents it.
+// For global variables, this is the dynamically allocated (and potentially
+// initialized) chunk of memory for the global. This annotation is created on
+// demand.
//
static AnnotationID GlobalAddressAID(
AnnotationManager::getID("Interpreter::GlobalAddress"));
-//===-- ExternalMethods.cpp - Implement External Functions ----------------===//
+//===-- ExternalFunctions.cpp - Implement External Functions --------------===//
//
-// This file contains both code to deal with invoking "external" methods, but
-// also contains code that implements "exported" external methods.
+// This file contains both code to deal with invoking "external" functions, but
+// also contains code that implements "exported" external functions.
//
-// External methods in LLI are implemented by dlopen'ing the lli executable and
-// using dlsym to look op the methods that we want to invoke. If a method is
-// found, then the arguments are mangled and passed in to the function call.
+// External functions in LLI are implemented by dlopen'ing the lli executable
+// and using dlsym to look op the functions that we want to invoke. If a
+// function is found, then the arguments are mangled and passed in to the
+// function call.
//
//===----------------------------------------------------------------------===//
const vector<GenericValue> &ArgVals) {
TheInterpreter = this;
- // Do a lookup to see if the method is in our cache... this should just be a
+ // Do a lookup to see if the function is in our cache... this should just be a
// defered annotation!
std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
if (Fn == 0) {
- cout << "Tried to execute an unknown external method: "
+ cout << "Tried to execute an unknown external function: "
<< M->getType()->getDescription() << " " << M->getName() << "\n";
return GenericValue();
}
// TODO: FIXME when types are not const!
- GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),ArgVals);
+ GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),
+ ArgVals);
return Result;
}
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "Support/DataTypes.h"
#include "llvm/Assembly/CachedWriter.h"
// executing.
//
struct ExecutionContext {
- Method *CurMethod; // The currently executing method
+ Function *CurMethod; // The currently executing function
BasicBlock *CurBB; // The currently executing BB
BasicBlock::iterator CurInst; // The next instruction to execute
- MethodInfo *MethInfo; // The MethInfo annotation for the method
+ MethodInfo *MethInfo; // The MethInfo annotation for the function
std::vector<ValuePlaneTy> Values;// ValuePlanes for each type
BasicBlock *PrevBB; // The previous BB or null if in first BB
int CurFrame; // The current stack frame being inspected
// The runtime stack of executing code. The top of the stack is the current
- // method record.
+ // function record.
std::vector<ExecutionContext> ECStack;
public:
void printStackTrace(); // Do the 'backtrace' command
// Code execution methods...
- void callMethod(Method *Meth, const std::vector<GenericValue> &ArgVals);
+ void callMethod(Function *F, const std::vector<GenericValue> &ArgVals);
bool executeInstruction(); // Execute one instruction...
void stepInstruction(); // Do the 'step' command
void executeRetInst(ReturnInst *I, ExecutionContext &SF);
void executeBrInst(BranchInst *I, ExecutionContext &SF);
void executeAllocInst(AllocationInst *I, ExecutionContext &SF);
- GenericValue callExternalMethod(Method *Meth,
+ GenericValue callExternalMethod(Function *F,
const std::vector<GenericValue> &ArgVals);
void exitCalled(GenericValue GV);
// getCurrentMethod - Return the currently executing method
- inline Method *getCurrentMethod() const {
+ inline Function *getCurrentMethod() const {
return CurFrame < 0 ? 0 : ECStack[CurFrame].CurMethod;
}
//
void printStackFrame(int FrameNo = -1);
- // LookupMatchingNames - Search the current method namespace, then the global
- // namespace looking for values that match the specified name. Return ALL
- // matches to that name. This is obviously slow, and should only be used for
- // user interaction.
+ // LookupMatchingNames - Search the current function namespace, then the
+ // global namespace looking for values that match the specified name. Return
+ // ALL matches to that name. This is obviously slow, and should only be used
+ // for user interaction.
//
std::vector<Value*> LookupMatchingNames(const std::string &Name);
}
}
-// LookupMatchingNames - Search the current method namespace, then the global
+// LookupMatchingNames - Search the current function namespace, then the global
// namespace looking for values that match the specified name. Return ALL
// matches to that name. This is obviously slow, and should only be used for
// user interaction.
//
std::vector<Value*> Interpreter::LookupMatchingNames(const std::string &Name) {
std::vector<Value*> Results;
- Method *CurMeth = getCurrentMethod();
+ Function *CurMeth = getCurrentMethod();
if (CurMeth) ::LookupMatchingNames(Name, *CurMeth, Results);
if (CurMod ) ::LookupMatchingNames(Name, *CurMod , Results);
case Finish: finish(); break;
case Call:
cin >> Command;
- callMethod(Command); // Enter the specified method
+ callMethod(Command); // Enter the specified function
finish(); // Run until it's complete
break;
bool Interpreter::callMethod(const string &Name) {
std::vector<Value*> Options = LookupMatchingNames(Name);
- for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
+ for (unsigned i = 0; i < Options.size(); ++i) { // Remove non-fn matches...
if (!isa<Function>(Options[i])) {
Options.erase(Options.begin()+i);
--i;
const std::vector<string> &InputArgv) {
std::vector<Value*> Options = LookupMatchingNames(Name);
- for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
+ for (unsigned i = 0; i < Options.size(); ++i) { // Remove non-fn matches...
if (!isa<Function>(Options[i])) {
Options.erase(Options.begin()+i);
--i;
if (ECStack.empty())
cout << "Error: No program executing!\n";
else
- CW << ECStack[CurFrame].CurMethod; // Just print the method out...
+ CW << ECStack[CurFrame].CurMethod; // Just print the function out...
}
void Interpreter::printStackTrace() {
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iOther.h"
#include "Support/StringExtras.h"
#include "Support/STLExtras.h"
//
/*ctor*/
-SchedGraphSet::SchedGraphSet(const Method* _method,
+SchedGraphSet::SchedGraphSet(const Function* _function,
const TargetMachine& target) :
- method(_method)
+ method(_function)
{
buildGraphsForMethod(method, target);
}
void
SchedGraphSet::dump() const
{
- cerr << "======== Sched graphs for method `" << method->getName()
+ cerr << "======== Sched graphs for function `" << method->getName()
<< "' ========\n\n";
for (const_iterator I=begin(); I != end(); ++I)
(*I)->dump();
- cerr << "\n====== End graphs for method `" << method->getName()
+ cerr << "\n====== End graphs for function `" << method->getName()
<< "' ========\n\n";
}
void
-SchedGraphSet::buildGraphsForMethod(const Method *method,
+SchedGraphSet::buildGraphsForMethod(const Function *F,
const TargetMachine& target)
{
- for (Method::const_iterator BI = method->begin(); BI != method->end(); ++BI)
- this->addGraph(new SchedGraph(*BI, target));
+ for (Function::const_iterator BI = F->begin(); BI != F->end(); ++BI)
+ addGraph(new SchedGraph(*BI, target));
}
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iPHINode.h"
#include "Support/CommandLine.h"
#include <iostream>
short* nts,
TargetMachine &target);
-static void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target);
+static void InsertCode4AllPhisInMeth(Function *F, TargetMachine &target);
//---------------------------------------------------------------------------
bool
-SelectInstructionsForMethod(Method* method, TargetMachine &target)
+SelectInstructionsForMethod(Function *F, TargetMachine &target)
{
bool failed = false;
//
// Build the instruction trees to be given as inputs to BURG.
//
- InstrForest instrForest(method);
+ InstrForest instrForest(F);
if (SelectDebugLevel >= Select_DebugInstTrees)
{
- cerr << "\n\n*** Input to instruction selection for method "
- << (method->hasName()? method->getName() : "")
- << "\n\n";
- method->dump();
+ cerr << "\n\n*** Input to instruction selection for function "
+ << F->getName() << "\n\n";
+ F->dump();
- cerr << "\n\n*** Instruction trees for method "
- << (method->hasName()? method->getName() : "")
- << "\n\n";
+ cerr << "\n\n*** Instruction trees for function "
+ << F->getName() << "\n\n";
instrForest.dump();
}
//
// Record instructions in the vector for each basic block
//
- for (Method::iterator BI = method->begin(); BI != method->end(); ++BI)
+ for (Function::iterator BI = F->begin(), BE = F->end(); BI != BE; ++BI)
{
MachineCodeForBasicBlock& bbMvec = (*BI)->getMachineInstrVec();
for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II)
}
// Insert phi elimination code -- added by Ruchira
- InsertCode4AllPhisInMeth(method, target);
+ InsertCode4AllPhisInMeth(F, target);
if (SelectDebugLevel >= Select_PrintMachineCode)
{
cerr << "\n*** Machine instructions after INSTRUCTION SELECTION\n";
- MachineCodeForMethod::get(method).dump();
+ MachineCodeForMethod::get(F).dump();
}
return false;
//-------------------------------------------------------------------------
void
-InsertCode4AllPhisInMeth(Method *method, TargetMachine &target)
+InsertCode4AllPhisInMeth(Function *F, TargetMachine &target)
{
- // for all basic blocks in method
+ // for all basic blocks in function
//
- for (Method::iterator BI = method->begin(); BI != method->end(); ++BI) {
+ for (Function::iterator BI = F->begin(); BI != F->end(); ++BI) {
BasicBlock *BB = *BI;
const BasicBlock::InstListType &InstList = BB->getInstList();
else break; // since PHI nodes can only be at the top
} // for each Phi Instr in BB
-
- } // for all BBs in method
-
+ } // for all BBs in function
}
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/MachineRegInfo.h"
#include "llvm/ConstantVals.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Type.h"
#include "llvm/iMemory.h"
static TmpInstruction*
-InsertCodeToLoadConstant(Method* method,
+InsertCodeToLoadConstant(Function *F,
Value* opValue,
Instruction* vmInstr,
vector<MachineInstr*>& loadConstVec,
MachineCodeForInstruction &MCFI = MachineCodeForInstruction::get(vmInstr);
MCFI.addTemp(tmpReg);
- target.getInstrInfo().CreateCodeToLoadConst(method, opValue, tmpReg,
+ target.getInstrInfo().CreateCodeToLoadConst(F, opValue, tmpReg,
loadConstVec, tempVec);
// Register the new tmp values created for this m/c instruction sequence
const MachineInstrDescriptor& instrDesc =
target.getInstrInfo().getDescriptor(minstr->getOpCode());
- Method* method = vmInstr->getParent()->getParent();
+ Function *F = vmInstr->getParent()->getParent();
for (unsigned op=0; op < minstr->getNumOperands(); op++)
{
if (constantThatMustBeLoaded || isa<GlobalValue>(opValue))
{ // opValue is a constant that must be explicitly loaded into a reg.
- TmpInstruction* tmpReg = InsertCodeToLoadConstant(method, opValue, vmInstr,
- loadConstVec, target);
+ TmpInstruction* tmpReg = InsertCodeToLoadConstant(F, opValue, vmInstr,
+ loadConstVec,
+ target);
minstr->SetMachineOperandVal(op, MachineOperand::MO_VirtualRegister,
tmpReg);
}
{
Value* oldVal = minstr->getImplicitRef(i);
TmpInstruction* tmpReg =
- InsertCodeToLoadConstant(method, oldVal, vmInstr, loadConstVec, target);
+ InsertCodeToLoadConstant(F, oldVal, vmInstr, loadConstVec, target);
minstr->setImplicitRef(i, tmpReg);
}
#include "llvm/CodeGen/RegClass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "Support/SetOperations.h"
#include <iostream>
using std::cerr;
-LiveRangeInfo::LiveRangeInfo(const Method *M, const TargetMachine &tm,
+LiveRangeInfo::LiveRangeInfo(const Function *F, const TargetMachine &tm,
std::vector<RegClass *> &RCL)
- : Meth(M), TM(tm), RegClassList(RCL), MRI(tm.getRegInfo()) { }
+ : Meth(F), TM(tm), RegClassList(RCL), MRI(tm.getRegInfo()) { }
LiveRangeInfo::~LiveRangeInfo() {
//assert(( L1->getTypeID() == L2->getTypeID()) && "Merge:Different types");
L1->insert(*L2It); // add the var in L2 to L1
- LiveRangeMap[*L2It] = L1; // now the elements in L2 should map
+ LiveRangeMap[*L2It] = L1; // now the elements in L2 should map
//to L1
}
//---------------------------------------------------------------------------
-// Method for constructing all live ranges in a method. It creates live
+// Method for constructing all live ranges in a function. It creates live
// ranges for all values defined in the instruction stream. Also, it
-// creates live ranges for all incoming arguments of the method.
+// creates live ranges for all incoming arguments of the function.
//---------------------------------------------------------------------------
void LiveRangeInfo::constructLiveRanges() {
if (DEBUG_RA)
cerr << "Consturcting Live Ranges ...\n";
- // first find the live ranges for all incoming args of the method since
- // those LRs start from the start of the method
+ // first find the live ranges for all incoming args of the function since
+ // those LRs start from the start of the function
- // get the argument list
- const Method::ArgumentListType& ArgList = Meth->getArgumentList();
- // get an iterator to arg list
- Method::ArgumentListType::const_iterator ArgIt = ArgList.begin();
+ // get the argument list
+ const Function::ArgumentListType& ArgList = Meth->getArgumentList();
-
+ Function::ArgumentListType::const_iterator ArgIt = ArgList.begin();
for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument
LiveRange * ArgRange = new LiveRange(); // creates a new LR and
const Value *Val = (const Value *) *ArgIt;
}
}
- // Now suggest hardware registers for these method args
+ // Now suggest hardware registers for these function args
MRI.suggestRegs4MethodArgs(Meth, *this);
-
// Now find speical LLVM instructions (CALL, RET) and LRs in machine
// instructions.
//
- for (Method::const_iterator BBI = Meth->begin(); BBI != Meth->end(); ++BBI) {
+ for (Function::const_iterator BBI = Meth->begin(); BBI != Meth->end(); ++BBI){
// Now find all LRs for machine the instructions. A new LR will be created
// only for defs in the machine instr since, we assume that all Values are
// defined before they are used. However, there can be multiple defs for
} // for all machine instructions in the BB
- } // for all BBs in method
+ } // for all BBs in function
// Now we have to suggest clors for call and return arg live ranges.
//---------------------------------------------------------------------------
// If some live ranges must be colored with specific hardware registers
// (e.g., for outgoing call args), suggesting of colors for such live
-// ranges is done using target specific method. Those methods are called
+// ranges is done using target specific function. Those functions are called
// from this function. The target specific methods must:
// 1) suggest colors for call and return args.
// 2) create new LRs for implicit defs in machine instructions
//---------------------------------------------------------------------------
void LiveRangeInfo::suggestRegs4CallRets()
{
-
CallRetInstrListType::const_iterator It = CallRetInstrList.begin();
-
for( ; It != CallRetInstrList.end(); ++It ) {
const MachineInstr *MInst = *It;
/* Algorithm:
- for each BB in method
+ for each BB in function
for each machine instruction (inst)
for each definition (def) in inst
for each operand (op) of inst that is a use
//---------------------------------------------------------------------------
void LiveRangeInfo::coalesceLRs()
{
- if( DEBUG_RA)
+ if(DEBUG_RA)
cerr << "\nCoalscing LRs ...\n";
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
+ for(Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
// get the iterator for machine instructions
const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/MachineFrameInfo.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Type.h"
#include <iostream>
#include <math.h>
public:
inline RegisterAllocator(TargetMachine &T) : Target(T) {}
- bool runOnMethod(Method *M) {
+ bool runOnMethod(Function *F) {
if (DEBUG_RA)
- cerr << "\n******************** Method "<< M->getName()
+ cerr << "\n******************** Method "<< F->getName()
<< " ********************\n";
- PhyRegAlloc PRA(M, Target, &getAnalysis<MethodLiveVarInfo>(),
+ PhyRegAlloc PRA(F, Target, &getAnalysis<MethodLiveVarInfo>(),
&getAnalysis<cfg::LoopInfo>());
PRA.allocateRegisters();
//----------------------------------------------------------------------------
// Constructor: Init local composite objects and create register classes.
//----------------------------------------------------------------------------
-PhyRegAlloc::PhyRegAlloc(Method *M,
+PhyRegAlloc::PhyRegAlloc(Function *F,
const TargetMachine& tm,
MethodLiveVarInfo *Lvi,
cfg::LoopInfo *LDC)
- : TM(tm), Meth(M),
- mcInfo(MachineCodeForMethod::get(M)),
- LVI(Lvi), LRI(M, tm, RegClassList),
- MRI( tm.getRegInfo() ),
+ : TM(tm), Meth(F),
+ mcInfo(MachineCodeForMethod::get(F)),
+ LVI(Lvi), LRI(F, tm, RegClassList),
+ MRI(tm.getRegInfo()),
NumOfRegClasses(MRI.getNumOfRegClasses()),
LoopDepthCalc(LDC) {
// create each RegisterClass and put in RegClassList
//
for(unsigned int rc=0; rc < NumOfRegClasses; rc++)
- RegClassList.push_back( new RegClass(M, MRI.getMachineRegClass(rc),
- &ResColList) );
+ RegClassList.push_back(new RegClass(F, MRI.getMachineRegClass(rc),
+ &ResColList));
}
if(DEBUG_RA) cerr << "Creating interference graphs ...\n";
unsigned BBLoopDepthCost;
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
+ for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
// find the 10^(loop_depth) of this BB
//
- BBLoopDepthCost = (unsigned) pow( 10.0, LoopDepthCalc->getLoopDepth(*BBI));
+ BBLoopDepthCost = (unsigned) pow(10.0, LoopDepthCalc->getLoopDepth(*BBI));
// get the iterator for machine instructions
//
} // for all machine instructions in BB
-
- } // for all BBs in method
+ } // for all BBs in function
- // add interferences for method arguments. Since there are no explict
- // defs in method for args, we have to add them manually
+ // add interferences for function arguments. Since there are no explict
+ // defs in the function for args, we have to add them manually
//
addInterferencesForArgs();
//----------------------------------------------------------------------------
-// This method will add interferences for incoming arguments to a method.
+// This method will add interferences for incoming arguments to a function.
//----------------------------------------------------------------------------
void PhyRegAlloc::addInterferencesForArgs() {
// get the InSet of root BB
const ValueSet &InSet = LVI->getInSetOfBB(Meth->front());
// get the argument list
- const Method::ArgumentListType& ArgList = Meth->getArgumentList();
+ const Function::ArgumentListType &ArgList = Meth->getArgumentList();
// get an iterator to arg list
- Method::ArgumentListType::const_iterator ArgIt = ArgList.begin();
+ Function::ArgumentListType::const_iterator ArgIt = ArgList.begin();
for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument
void PhyRegAlloc::updateMachineCode()
{
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
-
+ for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
// get the iterator for machine instructions
//
MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
void PhyRegAlloc::printMachineCode()
{
- cerr << "\n;************** Method " << Meth->getName()
+ cerr << "\n;************** Function " << Meth->getName()
<< " *****************\n";
- Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
-
- for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
-
- cerr << "\n"; printLabel( *BBI); cerr << ": ";
+ for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
+ BBI != BBE; ++BBI) {
+ cerr << "\n"; printLabel(*BBI); cerr << ": ";
// get the iterator for machine instructions
MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
// iterate over all the machine instructions in BB
for( ; MInstIterator != MIVec.end(); ++MInstIterator) {
-
MachineInstr *const MInst = *MInstIterator;
-
cerr << "\n\t";
cerr << TargetInstrDescriptors[MInst->getOpCode()].opCodeString;
-
-
- //for(MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done();++OpI) {
for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
-
MachineOperand& Op = MInst->getOperand(OpNum);
if( Op.getOperandType() == MachineOperand::MO_VirtualRegister ||
// So reset it before we call each such method
//mcInfo.popAllTempValues(TM);
-
if (TM.getInstrInfo().isCall(OpCode))
MRI.colorCallArgs(CRMI, LRI, AI, *this);
#include "llvm/DerivedTypes.h"
#include "llvm/Annotation.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Module.h"
#include "Support/StringExtras.h"
#include "Support/HashExtras.h"
AsmPrinter(std::ostream &os, const TargetMachine &T)
: idTable(0), toAsm(os), Target(T), CurSection(Unknown) {}
- // (start|end)(Module|Method) - Callback methods to be invoked by subclasses
+ // (start|end)(Module|Function) - Callback methods to be invoked by subclasses
void startModule(Module *M) {
// Create the global id table if it does not already exist
idTable = (GlobalIdTable*) M->getAnnotation(GlobalIdTable::AnnotId);
M->addAnnotation(idTable);
}
}
- void startMethod(Method *M) {
+ void startFunction(Function *F) {
// Make sure the slot table has information about this method...
- idTable->Table->incorporateMethod(M);
+ idTable->Table->incorporateMethod(F);
}
- void endMethod(Method *M) {
- idTable->Table->purgeMethod(); // Forget all about M.
+ void endFunction(Function *F) {
+ idTable->Table->purgeMethod(); // Forget all about F
}
void endModule() {
}
// Only functions can currently be external. "main" is the only name
// that is visible externally.
bool isExternal(const Value* V) {
- const Method* meth = dyn_cast<Method>(V);
- return bool(meth != NULL
- && (meth->isExternal() || meth->getName() == "main"));
+ const Function *F = dyn_cast<Function>(V);
+ return F && (F->isExternal() || F->getName() == "main");
}
// enterSection - Use this method to enter a different section of the output
string getID(const Module *M) {
return getID(M, "LLVMModule_");
}
- string getID(const Method *M) {
- return getID(M, "LLVMMethod_");
+ string getID(const Function *F) {
+ return getID(F, "LLVMFunction_");
}
string getID(const BasicBlock *BB) {
return getID(BB, "LL", (".L_"+getID(BB->getParent())+"_").c_str());
//===----------------------------------------------------------------------===//
-// SparcMethodAsmPrinter Code
+// SparcFunctionAsmPrinter Code
//===----------------------------------------------------------------------===//
-struct SparcMethodAsmPrinter : public MethodPass, public AsmPrinter {
- inline SparcMethodAsmPrinter(std::ostream &os, const TargetMachine &t)
+struct SparcFunctionAsmPrinter : public MethodPass, public AsmPrinter {
+ inline SparcFunctionAsmPrinter(std::ostream &os, const TargetMachine &t)
: AsmPrinter(os, t) {}
virtual bool doInitialization(Module *M) {
return false;
}
- virtual bool runOnMethod(Method *M) {
- startMethod(M);
- emitMethod(M);
- endMethod(M);
+ virtual bool runOnMethod(Function *F) {
+ startFunction(F);
+ emitFunction(F);
+ endFunction(F);
return false;
}
return false;
}
- void emitMethod(const Method *M);
+ void emitFunction(const Function *F);
private :
void emitBasicBlock(const BasicBlock *BB);
void emitMachineInst(const MachineInstr *MI);
};
inline bool
-SparcMethodAsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
- unsigned int opNum) {
+SparcFunctionAsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
+ unsigned int opNum) {
switch (MI->getOpCode()) {
case JMPLCALL:
case JMPLRET: return (opNum == 0);
inline bool
-SparcMethodAsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
- unsigned int opNum) {
+SparcFunctionAsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
+ unsigned int opNum) {
if (Target.getInstrInfo().isLoad(MI->getOpCode()))
return (opNum == 0);
else if (Target.getInstrInfo().isStore(MI->getOpCode()))
printOneOperand(Op2);
unsigned int
-SparcMethodAsmPrinter::printOperands(const MachineInstr *MI,
+SparcFunctionAsmPrinter::printOperands(const MachineInstr *MI,
unsigned int opNum)
{
const MachineOperand& Op = MI->getOperand(opNum);
void
-SparcMethodAsmPrinter::printOneOperand(const MachineOperand &op)
+SparcFunctionAsmPrinter::printOneOperand(const MachineOperand &op)
{
switch (op.getOperandType())
{
toAsm << "\t<*NULL Value*>";
else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(Val))
toAsm << getID(BB);
- else if (const Method *M = dyn_cast<const Method>(Val))
+ else if (const Function *M = dyn_cast<const Function>(Val))
toAsm << getID(M);
else if (const GlobalVariable *GV=dyn_cast<const GlobalVariable>(Val))
toAsm << getID(GV);
void
-SparcMethodAsmPrinter::emitMachineInst(const MachineInstr *MI)
+SparcFunctionAsmPrinter::emitMachineInst(const MachineInstr *MI)
{
unsigned Opcode = MI->getOpCode();
}
void
-SparcMethodAsmPrinter::emitBasicBlock(const BasicBlock *BB)
+SparcFunctionAsmPrinter::emitBasicBlock(const BasicBlock *BB)
{
// Emit a label for the basic block
toAsm << getID(BB) << ":\n";
}
void
-SparcMethodAsmPrinter::emitMethod(const Method *M)
+SparcFunctionAsmPrinter::emitFunction(const Function *M)
{
string methName = getID(M);
- toAsm << "!****** Outputing Method: " << methName << " ******\n";
+ toAsm << "!****** Outputing Function: " << methName << " ******\n";
enterSection(AsmPrinter::Text);
toAsm << "\t.align\t4\n\t.global\t" << methName << "\n";
//toAsm << "\t.type\t" << methName << ",#function\n";
toAsm << "\t.type\t" << methName << ", 2\n";
toAsm << methName << ":\n";
- // Output code for all of the basic blocks in the method...
- for (Method::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
+ // Output code for all of the basic blocks in the function...
+ for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
emitBasicBlock(*I);
// Output a .size directive so the debugger knows the extents of the function
<< methName << ", .EndOf_"
<< methName << "-" << methName << "\n";
- // Put some spaces between the methods
+ // Put some spaces between the functions
toAsm << "\n\n";
}
} // End anonymous namespace
Pass *UltraSparc::getMethodAsmPrinterPass(PassManager &PM, std::ostream &Out) {
- return new SparcMethodAsmPrinter(Out, *this);
+ return new SparcFunctionAsmPrinter(Out, *this);
}
//===----------------------------------------------------------------------===//
-// SparcMethodAsmPrinter Code
+// SparcFunctionAsmPrinter Code
//===----------------------------------------------------------------------===//
namespace {
#include "llvm/CodeGen/InstrSelectionSupport.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineCodeForMethod.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/ConstantVals.h"
#include "llvm/DerivedTypes.h"
// Any temp. registers (TmpInstruction) created are returned in `tempVec'.
//
void
-UltraSparcInstrInfo::CreateCodeToLoadConst(Method* method,
- Value* val,
+UltraSparcInstrInfo::CreateCodeToLoadConst(Function *F, Value* val,
Instruction* dest,
- std::vector<MachineInstr*>& minstrVec,
- std::vector<TmpInstruction*>& tempVec) const
+ std::vector<MachineInstr*>&minstrVec,
+ std::vector<TmpInstruction*>& tempVec) const
{
MachineInstr* minstr;
minstr = new MachineInstr(SETX);
minstr->SetMachineOperandVal(0, MachineOperand::MO_PCRelativeDisp, val);
- minstr->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, tmpReg,
+ minstr->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister,tmpReg,
/*isdef*/ true);
- minstr->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister,addrVal);
+ minstr->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister,
+ addrVal);
minstrVec.push_back(minstr);
if (isa<Constant>(val))
{
// Make sure constant is emitted to constant pool in assembly code.
- MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(method);
+ MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(F);
mcinfo.addToConstantPool(cast<Constant>(val));
// Generate the load instruction
minstr = new MachineInstr(ChooseLoadInstruction(val->getType()));
minstr->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister,
addrVal);
- minstr->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed,
+ minstr->SetMachineOperandConst(1,MachineOperand::MO_SignExtendedImmed,
zeroOffset);
minstr->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister,
dest);
// Any temp. registers (TmpInstruction) created are returned in `tempVec'.
//
void
-UltraSparcInstrInfo::CreateCodeToCopyIntToFloat(Method* method,
+UltraSparcInstrInfo::CreateCodeToCopyIntToFloat(Function *F,
Value* val,
Instruction* dest,
std::vector<MachineInstr*>& minstrVec,
{
assert((val->getType()->isIntegral() || val->getType()->isPointerType())
&& "Source type must be integral");
- assert((dest->getType() ==Type::FloatTy || dest->getType() ==Type::DoubleTy)
+ assert((dest->getType() == Type::FloatTy || dest->getType() == Type::DoubleTy)
&& "Dest type must be float/double");
- MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(method);
+ MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(F);
int offset = mcinfo.allocateLocalVar(target, val);
// Store instruction stores `val' to [%fp+offset].
MachineInstr* store = new MachineInstr(ChooseStoreInstruction(tmpType));
store->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, val);
store->SetMachineOperandReg(1, target.getRegInfo().getFramePointer());
- store->SetMachineOperandConst(2, MachineOperand::MO_SignExtendedImmed, offset);
+ store->SetMachineOperandConst(2,MachineOperand::MO_SignExtendedImmed, offset);
minstrVec.push_back(store);
// Load instruction loads [%fp+offset] to `dest'.
// See the previous function for information about return values.
//
void
-UltraSparcInstrInfo::CreateCodeToCopyFloatToInt(Method* method,
+UltraSparcInstrInfo::CreateCodeToCopyFloatToInt(Function *F,
Value* val,
Instruction* dest,
std::vector<MachineInstr*>& minstrVec,
assert((dest->getType()->isIntegral() || dest->getType()->isPointerType())
&& "Dest type must be integral");
- MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(method);
+ MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(F);
int offset = mcinfo.allocateLocalVar(target, val);
// Store instruction stores `val' to [%fp+offset].
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/ConstantVals.h"
#include "Support/MathExtras.h"
#include <math.h>
// Eventually the entire BURG instruction selection should be put
// into a separate class that can hold such information.
// The static cache is not too bad because the memory for these
-// TmpInstructions will be freed along with the rest of the Method anyway.
+// TmpInstructions will be freed along with the rest of the Function anyway.
//
static TmpInstruction*
-GetTmpForCC(Value* boolVal, const Method* method, const Type* ccType)
+GetTmpForCC(Value* boolVal, const Function *F, const Type* ccType)
{
typedef std::hash_map<const Value*, TmpInstruction*> BoolTmpCache;
static BoolTmpCache boolToTmpCache; // Map boolVal -> TmpInstruction*
- static const Method* lastMethod = NULL; // Use to flush cache between methods
+ static const Function *lastFunction = 0;// Use to flush cache between funcs
assert(boolVal->getType() == Type::BoolTy && "Weird but ok! Delete assert");
- if (lastMethod != method)
+ if (lastFunction != F)
{
- lastMethod = method;
+ lastFunction = F;
boolToTmpCache.clear();
}
// Get the constant offset from SP for dynamically allocated storage
// and create a temporary Value to hold it.
- assert(result && result->getParent() && "Result value is not part of a method?");
- Method* method = result->getParent()->getParent();
- MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(method);
+ assert(result && result->getParent() && "Result value is not part of a fn?");
+ Function *F = result->getParent()->getParent();
+ MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(F);
bool growUp;
ConstantSInt* dynamicAreaOffset =
ConstantSInt::get(Type::IntTy,
vector<MachineInstr*>& getMvec)
{
assert(result && result->getParent() &&
- "Result value is not part of a method?");
- Method* method = result->getParent()->getParent();
- MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(method);
-
- // Check if the offset would small enough to use as an immediate in load/stores
- // (check LDX because all load/stores have the same-size immediate field).
- // If not, put the variable in the dynamically sized area of the frame.
+ "Result value is not part of a function?");
+ Function *F = result->getParent()->getParent();
+ MachineCodeForMethod &mcInfo = MachineCodeForMethod::get(F);
+
+ // Check if the offset would small enough to use as an immediate in
+ // load/stores (check LDX because all load/stores have the same-size immediate
+ // field). If not, put the variable in the dynamically sized area of the
+ // frame.
unsigned int paddedSizeIgnored;
int offsetFromFP = mcInfo.computeOffsetforLocalVar(target, result,
paddedSizeIgnored,
void UltraSparcInstrInfo::
CreateCopyInstructionsByType(const TargetMachine& target,
- Method* method,
+ Function *F,
Value* src,
Instruction* dest,
vector<MachineInstr*>& minstrVec) const
{ // `src' is constant and cannot fit in immed field for the ADD
// Insert instructions to "load" the constant into a register
vector<TmpInstruction*> tempVec;
- target.getInstrInfo().CreateCodeToLoadConst(method, src, dest,
- minstrVec,tempVec);
+ target.getInstrInfo().CreateCodeToLoadConst(F, src, dest,
+ minstrVec, tempVec);
for (unsigned i=0; i < tempVec.size(); i++)
MachineCodeForInstruction::get(dest).addTemp(tempVec[i]);
}
// We will assume that local register `l0' is unused since the SAVE
// instruction must be the first instruction in each procedure.
//
- Method* method = entryBB->getParent();
- MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(method);
+ Function *F = entryBB->getParent();
+ MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(F);
unsigned int staticStackSize = mcInfo.getStaticStackSize();
if (staticStackSize < (unsigned) frameInfo.getMinStackFrameSize())
#include "llvm/CodeGen/MachineCodeForMethod.h"
#include "llvm/CodeGen/RegisterAllocation.h"
#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/PassManager.h"
#include <iostream>
//---------------------------------------------------------------------------
// class InsertPrologEpilogCode
//
-// Insert SAVE/RESTORE instructions for the method
+// Insert SAVE/RESTORE instructions for the function
//
-// Insert prolog code at the unique method entry point.
-// Insert epilog code at each method exit point.
-// InsertPrologEpilog invokes these only if the method is not compiled
-// with the leaf method optimization.
+// Insert prolog code at the unique function entry point.
+// Insert epilog code at each function exit point.
+// InsertPrologEpilog invokes these only if the function is not compiled
+// with the leaf function optimization.
//
//---------------------------------------------------------------------------
static MachineInstr* minstrVec[MAX_INSTR_PER_VMINSTR];
TargetMachine &Target;
public:
inline InsertPrologEpilogCode(TargetMachine &T) : Target(T) {}
- bool runOnMethod(Method *M) {
- MachineCodeForMethod &mcodeInfo = MachineCodeForMethod::get(M);
+ bool runOnMethod(Function *F) {
+ MachineCodeForMethod &mcodeInfo = MachineCodeForMethod::get(F);
if (!mcodeInfo.isCompiledAsLeafMethod()) {
- InsertPrologCode(M);
- InsertEpilogCode(M);
+ InsertPrologCode(F);
+ InsertEpilogCode(F);
}
return false;
}
- void InsertPrologCode(Method *M);
- void InsertEpilogCode(Method *M);
+ void InsertPrologCode(Function *F);
+ void InsertEpilogCode(Function *F);
};
-void InsertPrologEpilogCode::InsertPrologCode(Method* method)
+void InsertPrologEpilogCode::InsertPrologCode(Function *F)
{
- BasicBlock* entryBB = method->getEntryNode();
+ BasicBlock *entryBB = F->getEntryNode();
unsigned N = GetInstructionsForProlog(entryBB, Target, minstrVec);
assert(N <= MAX_INSTR_PER_VMINSTR);
MachineCodeForBasicBlock& bbMvec = entryBB->getMachineInstrVec();
}
-void InsertPrologEpilogCode::InsertEpilogCode(Method* method)
+void InsertPrologEpilogCode::InsertEpilogCode(Function *F)
{
- for (Method::iterator I=method->begin(), E=method->end(); I != E; ++I) {
+ for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
Instruction *TermInst = (Instruction*)(*I)->getTerminator();
if (TermInst->getOpcode() == Instruction::Ret)
{
// Native code generation for a specified target.
//===---------------------------------------------------------------------===//
-class ConstructMachineCodeForMethod : public MethodPass {
+class ConstructMachineCodeForFunction : public MethodPass {
TargetMachine &Target;
public:
- inline ConstructMachineCodeForMethod(TargetMachine &T) : Target(T) {}
- bool runOnMethod(Method *M) {
- MachineCodeForMethod::construct(M, Target);
+ inline ConstructMachineCodeForFunction(TargetMachine &T) : Target(T) {}
+ bool runOnMethod(Function *F) {
+ MachineCodeForMethod::construct(F, Target);
return false;
}
};
TargetMachine &Target;
public:
inline InstructionSelection(TargetMachine &T) : Target(T) {}
- bool runOnMethod(Method *M) {
- if (SelectInstructionsForMethod(M, Target))
- cerr << "Instr selection failed for method " << M->getName() << "\n";
+ bool runOnMethod(Function *F) {
+ if (SelectInstructionsForMethod(F, Target)) {
+ cerr << "Instr selection failed for function " << F->getName() << "\n";
+ abort();
+ }
return false;
}
};
-struct FreeMachineCodeForMethod : public MethodPass {
+struct FreeMachineCodeForFunction : public MethodPass {
static void freeMachineCode(Instruction *I) {
MachineCodeForInstruction::destroy(I);
}
- bool runOnMethod(Method *M) {
- for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
- for (BasicBlock::iterator I = (*MI)->begin(), E = (*MI)->end();
+ bool runOnMethod(Function *F) {
+ for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
+ for (BasicBlock::iterator I = (*FI)->begin(), E = (*FI)->end();
I != E; ++I)
MachineCodeForInstruction::get(*I).dropAllReferences();
- for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
- for (BasicBlock::iterator I = (*MI)->begin(), E = (*MI)->end();
+ for (Method::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
+ for (BasicBlock::iterator I = (*FI)->begin(), E = (*FI)->end();
I != E; ++I)
freeMachineCode(*I);
// process for the ultra sparc.
//
void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
- // Construct and initialize the MachineCodeForMethod object for this method.
- PM.add(new ConstructMachineCodeForMethod(*this));
+ // Construct and initialize the MachineCodeForMethod object for this fn.
+ PM.add(new ConstructMachineCodeForFunction(*this));
PM.add(new InstructionSelection(*this));
PM.add(new InsertPrologEpilogCode(*this));
// Output assembly language to the .s file. Assembly emission is split into
- // two parts: Method output and Global value output. This is because method
- // output is pipelined with all of the rest of code generation stuff,
- // allowing machine code representations for methods to be free'd after the
- // method has been emitted.
+ // two parts: Function output and Global value output. This is because
+ // function output is pipelined with all of the rest of code generation stuff,
+ // allowing machine code representations for functions to be free'd after the
+ // function has been emitted.
//
PM.add(getMethodAsmPrinterPass(PM, Out));
- PM.add(new FreeMachineCodeForMethod()); // Free stuff no longer needed
+ PM.add(new FreeMachineCodeForFunction()); // Free stuff no longer needed
- // Emit Module level assembly after all of the methods have been processed.
+ // Emit Module level assembly after all of the functions have been processed.
PM.add(getModuleAsmPrinterPass(PM, Out));
// Emit bytecode to the sparc assembly file into its special section next
//===----------------------------------------------------------------------===//
#include "TransformInternals.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iOther.h"
#include "llvm/iPHINode.h"
#include "llvm/iMemory.h"
assert (OI != I->op_end() && "Not using value!");
unsigned OpNum = OI - I->op_begin();
- // Are we trying to change the method pointer value to a new type?
+ // Are we trying to change the function pointer value to a new type?
if (OpNum == 0) {
PointerType *PTy = dyn_cast<PointerType>(Ty);
if (PTy == 0) return false; // Can't convert to a non-pointer type...
FunctionType *MTy = dyn_cast<FunctionType>(PTy->getElementType());
- if (MTy == 0) return false; // Can't convert to a non ptr to method...
+ if (MTy == 0) return false; // Can't convert to a non ptr to function...
- // Perform sanity checks to make sure that new method type has the
+ // Perform sanity checks to make sure that new function type has the
// correct number of arguments...
//
- unsigned NumArgs = I->getNumOperands()-1; // Don't include method ptr
+ unsigned NumArgs = I->getNumOperands()-1; // Don't include function ptr
// Cannot convert to a type that requires more fixed arguments than
// the call provides...
//
if (NumArgs < MTy->getParamTypes().size()) return false;
- // Unless this is a vararg method type, we cannot provide more arguments
+ // Unless this is a vararg function type, we cannot provide more arguments
// than are desired...
//
if (!MTy->isVarArg() && NumArgs > MTy->getParamTypes().size())
return false;
- // Okay, at this point, we know that the call and the method type match
+ // Okay, at this point, we know that the call and the function type match
// number of arguments. Now we see if we can convert the arguments
// themselves. Note that we do not require operands to be convertable,
// we can insert casts if they are convertible but not compatible. The
- // reason for this is that we prefer to have resolved methods but casted
+ // reason for this is that we prefer to have resolved functions but casted
// arguments if possible.
//
const FunctionType::ParamTypes &PTs = MTy->getParamTypes();
return false; // It's not in the varargs section...
// If we get this far, we know the value is in the varargs section of the
- // method! We can convert if we don't reinterpret the value...
+ // function! We can convert if we don't reinterpret the value...
//
return Ty->isLosslesslyConvertableTo(V->getType());
}
Value *Meth = I->getOperand(0);
std::vector<Value*> Params(I->op_begin()+1, I->op_end());
- if (Meth == OldVal) { // Changing the method pointer?
+ if (Meth == OldVal) { // Changing the function pointer?
PointerType *NewPTy = cast<PointerType>(NewVal->getType());
FunctionType *NewTy = cast<FunctionType>(NewPTy->getElementType());
const FunctionType::ParamTypes &PTs = NewTy->getParamTypes();
// operands if needbe. Note that we do not require operands to be
// convertable, we can insert casts if they are convertible but not
// compatible. The reason for this is that we prefer to have resolved
- // methods but casted arguments if possible.
+ // functions but casted arguments if possible.
//
BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
#include "llvm/iPHINode.h"
#include "llvm/iOther.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Pass.h"
#include <map>
#include <vector>
// Entry point for normalizing constant args in PHIs
//---------------------------------------------------------------------------
-static bool doHoistPHIConstants(Method *M) {
+static bool doHoistPHIConstants(Function *M) {
CachedCopyMap Cache;
bool Changed = false;
- for (Method::iterator BI = M->begin(), BE = M->end(); BI != BE; ++BI) {
+ for (Function::iterator BI = M->begin(), BE = M->end(); BI != BE; ++BI) {
std::vector<PHINode*> phis; // normalizing invalidates BB iterator
for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) {
namespace {
struct HoistPHIConstants : public MethodPass {
- virtual bool runOnMethod(Method *M) { return doHoistPHIConstants(M); }
+ virtual bool runOnMethod(Function *F) { return doHoistPHIConstants(F); }
};
}
// and elminate duplicates when it is initialized.
//
// The DynamicConstantMerge method is a superset of the ConstantMerge algorithm
-// that checks for each method to see if constants have been added to the
+// that checks for each function to see if constants have been added to the
// constant pool since it was last run... if so, it processes them.
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/ConstantMerge.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Pass.h"
// mergeDuplicateConstants - Workhorse for the pass. This eliminates duplicate
return ::mergeDuplicateConstants(M, LastConstantSeen, Constants);
}
- bool runOnMethod(Method*) { return false; }
+ bool runOnMethod(Function *) { return false; }
// doFinalization - Clean up internal state for this module
//
};
struct DynamicConstantMerge : public ConstantMerge {
- // doPerMethodWork - Check to see if any globals have been added to the
+ // runOnMethod - Check to see if any globals have been added to the
// global list for the module. If so, eliminate them.
//
- bool runOnMethod(Method *M) {
- return ::mergeDuplicateConstants(M->getParent(), LastConstantSeen,
+ bool runOnMethod(Function *F) {
+ return ::mergeDuplicateConstants(F->getParent(), LastConstantSeen,
Constants);
}
};
-//===-- GlobalDCE.cpp - DCE unreachable internal methods ---------*- C++ -*--=//
+//===-- GlobalDCE.cpp - DCE unreachable internal functions ----------------===//
//
// This transform is designed to eliminate unreachable internal globals
//
#include "llvm/Transforms/IPO/GlobalDCE.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Pass.h"
#include "Support/DepthFirstIterator.h"
#include <set>
-static bool RemoveUnreachableMethods(Module *M, CallGraph &CallGraph) {
- // Calculate which methods are reachable from the external methods in the call
- // graph.
+static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) {
+ // Calculate which functions are reachable from the external functions in the
+ // call graph.
//
std::set<CallGraphNode*> ReachableNodes(df_begin(&CallGraph),
df_end(&CallGraph));
- // Loop over the methods in the module twice. The first time is used to drop
- // references that methods have to each other before they are deleted. The
- // second pass removes the methods that need to be removed.
+ // Loop over the functions in the module twice. The first time is used to
+ // drop references that functions have to each other before they are deleted.
+ // The second pass removes the functions that need to be removed.
//
- std::vector<CallGraphNode*> MethodsToDelete; // Track unused methods
+ std::vector<CallGraphNode*> FunctionsToDelete; // Track unused functions
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
CallGraphNode *N = CallGraph[*I];
if (!ReachableNodes.count(N)) { // Not reachable??
(*I)->dropAllReferences();
N->removeAllCalledMethods();
- MethodsToDelete.push_back(N);
+ FunctionsToDelete.push_back(N);
}
}
- // Nothing to do if no unreachable methods have been found...
- if (MethodsToDelete.empty()) return false;
+ // Nothing to do if no unreachable functions have been found...
+ if (FunctionsToDelete.empty()) return false;
- // Unreachables methods have been found and should have no references to them,
- // delete them now.
+ // Unreachables functions have been found and should have no references to
+ // them, delete them now.
//
- for (std::vector<CallGraphNode*>::iterator I = MethodsToDelete.begin(),
- E = MethodsToDelete.end(); I != E; ++I)
+ for (std::vector<CallGraphNode*>::iterator I = FunctionsToDelete.begin(),
+ E = FunctionsToDelete.end(); I != E; ++I)
delete CallGraph.removeMethodFromModule(*I);
return true;
// the specified callgraph to reflect the changes.
//
bool run(Module *M) {
- return RemoveUnreachableMethods(M, getAnalysis<CallGraph>());
+ return RemoveUnreachableFunctions(M, getAnalysis<CallGraph>());
}
// getAnalysisUsageInfo - This function works on the call graph of a module.
-//===- MethodInlining.cpp - Code to perform method inlining ---------------===//
+//===- FunctionInlining.cpp - Code to perform function inlining -----------===//
//
-// This file implements inlining of methods.
+// This file implements inlining of functions.
//
// Specifically, this:
-// * Exports functionality to inline any method call
-// * Inlines methods that consist of a single basic block
-// * Is able to inline ANY method call
-// . Has a smart heuristic for when to inline a method
+// * Exports functionality to inline any function call
+// * Inlines functions that consist of a single basic block
+// * Is able to inline ANY function call
+// . Has a smart heuristic for when to inline a function
//
// Notice that:
// * This pass opens up a lot of opportunities for constant propogation. It
// is a good idea to to run a constant propogation pass, then a DCE pass
// sometime after running this pass.
//
-// TODO: Currently this throws away all of the symbol names in the method being
-// inlined. This shouldn't happen.
-//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/MethodInlining.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Pass.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
}
}
-// InlineMethod - This function forcibly inlines the called method into the
+// InlineMethod - This function forcibly inlines the called function into the
// basic block of the caller. This returns false if it is not possible to
// inline this call. The program is still in a well defined state if this
// occurs though.
// Note that this only does one level of inlining. For example, if the
// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now
// exists in the instruction stream. Similiarly this will inline a recursive
-// method by one level.
+// function by one level.
//
bool InlineMethod(BasicBlock::iterator CIIt) {
assert(isa<CallInst>(*CIIt) && "InlineMethod only works on CallInst nodes!");
assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
- assert((*CIIt)->getParent()->getParent() && "Instruction not in method!");
+ assert((*CIIt)->getParent()->getParent() && "Instruction not in function!");
CallInst *CI = cast<CallInst>(*CIIt);
const Function *CalledMeth = CI->getCalledFunction();
- if (CalledMeth == 0 || // Can't inline external method or indirect call!
+ if (CalledMeth == 0 || // Can't inline external function or indirect call!
CalledMeth->isExternal()) return false;
//cerr << "Inlining " << CalledMeth->getName() << " into "
// If we have a return value generated by this call, convert it into a PHI
// node that gets values from each of the old RET instructions in the original
- // method.
+ // function.
//
PHINode *PHI = 0;
if (CalledMeth->getReturnType() != Type::VoidTy) {
CI->replaceAllUsesWith(PHI);
}
- // Keep a mapping between the original method's values and the new duplicated
- // code's values. This includes all of: Method arguments, instruction values,
- // constant pool entries, and basic blocks.
+ // Keep a mapping between the original function's values and the new
+ // duplicated code's values. This includes all of: Function arguments,
+ // instruction values, constant pool entries, and basic blocks.
//
std::map<const Value *, Value*> ValueMap;
- // Add the method arguments to the mapping: (start counting at 1 to skip the
- // method reference itself)
+ // Add the function arguments to the mapping: (start counting at 1 to skip the
+ // function reference itself)
//
- Method::ArgumentListType::const_iterator PTI =
+ Function::ArgumentListType::const_iterator PTI =
CalledMeth->getArgumentList().begin();
for (unsigned a = 1, E = CI->getNumOperands(); a != E; ++a, ++PTI)
ValueMap[*PTI] = CI->getOperand(a);
ValueMap[NewBB] = NewBB; // Returns get converted to reference NewBB
- // Loop over all of the basic blocks in the method, inlining them as
- // appropriate. Keep track of the first basic block of the method...
+ // Loop over all of the basic blocks in the function, inlining them as
+ // appropriate. Keep track of the first basic block of the function...
//
- for (Method::const_iterator BI = CalledMeth->begin();
+ for (Function::const_iterator BI = CalledMeth->begin();
BI != CalledMeth->end(); ++BI) {
const BasicBlock *BB = *BI;
assert(BB->getTerminator() && "BasicBlock doesn't have terminator!?!?");
if (PHI) { // The PHI node should include this value!
assert(RI->getReturnValue() && "Ret should have value!");
assert(RI->getReturnValue()->getType() == PHI->getType() &&
- "Ret value not consistent in method!");
+ "Ret value not consistent in function!");
PHI->addIncoming((Value*)RI->getReturnValue(), cast<BasicBlock>(BB));
}
break;
default:
- cerr << "MethodInlining: Don't know how to handle terminator: " << TI;
+ cerr << "FunctionInlining: Don't know how to handle terminator: " << TI;
abort();
}
}
- // Loop over all of the instructions in the method, fixing up operand
+ // Loop over all of the instructions in the function, fixing up operand
// references as we go. This uses ValueMap to do all the hard work.
//
- for (Method::const_iterator BI = CalledMeth->begin();
+ for (Function::const_iterator BI = CalledMeth->begin();
BI != CalledMeth->end(); ++BI) {
const BasicBlock *BB = *BI;
BasicBlock *NBB = (BasicBlock*)ValueMap[BB];
if (PHI) RemapInstruction(PHI, ValueMap); // Fix the PHI node also...
// Change the branch that used to go to NewBB to branch to the first basic
- // block of the inlined method.
+ // block of the inlined function.
//
TerminatorInst *Br = OrigBB->getTerminator();
assert(Br && Br->getOpcode() == Instruction::Br &&
return InlineMethod(CallIt);
}
-static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) {
+static inline bool ShouldInlineFunction(const CallInst *CI, const Function *F) {
assert(CI->getParent() && CI->getParent()->getParent() &&
"Call not embedded into a method!");
// Don't inline a recursive call.
- if (CI->getParent()->getParent() == M) return false;
+ if (CI->getParent()->getParent() == F) return false;
// Don't inline something too big. This is a really crappy heuristic
- if (M->size() > 3) return false;
+ if (F->size() > 3) return false;
// Don't inline into something too big. This is a **really** crappy heuristic
if (CI->getParent()->getParent()->size() > 10) return false;
}
-static inline bool DoMethodInlining(BasicBlock *BB) {
+static inline bool DoFunctionInlining(BasicBlock *BB) {
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
if (CallInst *CI = dyn_cast<CallInst>(*I)) {
- // Check to see if we should inline this method
- Method *F = CI->getCalledFunction();
- if (F && ShouldInlineMethod(CI, F))
+ // Check to see if we should inline this function
+ Function *F = CI->getCalledFunction();
+ if (F && ShouldInlineFunction(CI, F))
return InlineMethod(I);
}
}
return false;
}
-// doMethodInlining - Use a heuristic based approach to inline methods that
+// doFunctionInlining - Use a heuristic based approach to inline functions that
// seem to look good.
//
-static bool doMethodInlining(Method *M) {
+static bool doFunctionInlining(Function *F) {
bool Changed = false;
// Loop through now and inline instructions a basic block at a time...
- for (Method::iterator I = M->begin(); I != M->end(); )
- if (DoMethodInlining(*I)) {
+ for (Function::iterator I = F->begin(); I != F->end(); )
+ if (DoFunctionInlining(*I)) {
Changed = true;
// Iterator is now invalidated by new basic blocks inserted
- I = M->begin();
+ I = F->begin();
} else {
++I;
}
}
namespace {
- struct MethodInlining : public MethodPass {
- virtual bool runOnMethod(Method *M) {
- return doMethodInlining(M);
+ struct FunctionInlining : public MethodPass {
+ virtual bool runOnMethod(Function *F) {
+ return doFunctionInlining(F);
}
};
}
-Pass *createMethodInliningPass() { return new MethodInlining(); }
+Pass *createMethodInliningPass() { return new FunctionInlining(); }
//===-- ProfilePaths.cpp - interface to insert instrumentation ---*- C++ -*--=//
//
// This inserts intrumentation for counting
-// execution of paths though a given method
-// Its implemented as a "Method" Pass, and called using opt
+// execution of paths though a given function
+// Its implemented as a "Function" Pass, and called using opt
//
// This pass is implemented by using algorithms similar to
// 1."Efficient Path Profiling": Ball, T. and Larus, J. R.,
// (code inserted through EdgeCode.cpp).
//
// The algorithm inserts code such that every acyclic path in the CFG
-// of a method is identified through a unique number. the code insertion
+// of a function is identified through a unique number. the code insertion
// is optimal in the sense that its inserted over a minimal set of edges. Also,
// the algorithm makes sure than initialization, path increment and counter
// update can be collapsed into minmimum number of edges.
#include "llvm/Transforms/Instrumentation/ProfilePaths.h"
#include "llvm/Transforms/UnifyMethodExitNodes.h"
#include "llvm/Support/CFG.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/ConstantVals.h"
#include "llvm/DerivedTypes.h"
class ProfilePaths: public MethodPass {
public:
- bool runOnMethod(Method *M);
+ bool runOnMethod(Function *M);
// Before this pass, make sure that there is only one
- // entry and only one exit node for the method in the CFG of the method
+ // entry and only one exit node for the function in the CFG of the function
//
void ProfilePaths::getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
Pass::AnalysisSet &Destroyed,
return NULL;
}
-//Per method pass for inserting counters and trigger code
-bool ProfilePaths::runOnMethod(Method *M){
+//Per function pass for inserting counters and trigger code
+bool ProfilePaths::runOnMethod(Function *M){
//Transform the cfg s.t. we have just one exit node
BasicBlock *ExitNode =
getAnalysis<UnifyMethodExitNodes>().getExitNode();
//That is, no two nodes must hav same BB*
//First enter just nodes: later enter edges
- for (Method::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
+ for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
Node *nd=new Node(*BB);
nodes.insert(nd);
if(*BB==ExitNode)
}
//now do it againto insert edges
- for (Method::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
+ for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
Node *nd=findBB(nodes, *BB);
assert(nd && "No node for this edge!");
for(BasicBlock::succ_iterator s=succ_begin(*BB), se=succ_end(*BB);
processGraph(g, rVar, countVar, be, stDummy, exDummy);
}
- return true; // Always modifies method
+ return true; // Always modifies function
}
#include "llvm/Transforms/LevelChange.h"
#include "TransformInternals.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iOther.h"
#include "llvm/iMemory.h"
#include "llvm/ConstantVals.h"
-static bool DoRaisePass(Method *M) {
+static bool DoRaisePass(Function *F) {
bool Changed = false;
- for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
+ for (Method::iterator MI = F->begin(), ME = F->end(); MI != ME; ++MI) {
BasicBlock *BB = *MI;
BasicBlock::InstListType &BIL = BB->getInstList();
// RaisePointerReferences::doit - Raise a method representation to a higher
// level.
//
-static bool doRPR(Method *M) {
+static bool doRPR(Function *F) {
#ifdef DEBUG_PEEPHOLE_INSTS
- cerr << "\n\n\nStarting to work on Method '" << M->getName() << "'\n";
+ cerr << "\n\n\nStarting to work on Function '" << F->getName() << "'\n";
#endif
// Insert casts for all incoming pointer pointer values that are treated as
do {
#ifdef DEBUG_PEEPHOLE_INSTS
- cerr << "Looping: \n" << M;
+ cerr << "Looping: \n" << F;
#endif
// Iterate over the method, refining it, until it converges on a stable
// state
LocalChange = false;
- while (DoRaisePass(M)) LocalChange = true;
+ while (DoRaisePass(F)) LocalChange = true;
Changed |= LocalChange;
} while (LocalChange);
namespace {
struct RaisePointerReferences : public MethodPass {
- virtual bool runOnMethod(Method *M) { return doRPR(M); }
+ virtual bool runOnMethod(Function *F) { return doRPR(F); }
};
}
#include "llvm/Transforms/Scalar/ConstantProp.h"
#include "llvm/Transforms/Scalar/ConstantHandling.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
BasicBlock *Destination = Cond->getValue() ? Dest1 : Dest2;
BasicBlock *OldDest = Cond->getValue() ? Dest2 : Dest1;
- //cerr << "Method: " << T->getParent()->getParent()
+ //cerr << "Function: " << T->getParent()->getParent()
// << "\nRemoving branch from " << T->getParent()
// << "\n\nTo: " << OldDest << endl;
// DoConstPropPass - Propogate constants and do constant folding on instructions
// this returns true if something was changed, false if nothing was changed.
//
-static bool DoConstPropPass(Method *M) {
+static bool DoConstPropPass(Function *F) {
bool SomethingChanged = false;
- for (Method::iterator BBI = M->begin(); BBI != M->end(); ++BBI) {
+ for (Method::iterator BBI = F->begin(); BBI != F->end(); ++BBI) {
BasicBlock *BB = *BBI;
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); )
if (doConstantPropogation(BB, I))
namespace {
struct ConstantPropogation : public MethodPass {
- inline bool runOnMethod(Method *M) {
+ inline bool runOnMethod(Function *F) {
bool Modified = false;
// Fold constants until we make no progress...
- while (DoConstPropPass(M)) Modified = true;
+ while (DoConstPropPass(F)) Modified = true;
return Modified;
}
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Pass.h"
//---------------------------------------------------------------------------
static bool
-doDecomposeMultiDimRefs(Method *M)
+doDecomposeMultiDimRefs(Function *F)
{
bool changed = false;
- for (Method::iterator BI = M->begin(), BE = M->end(); BI != BE; ++BI)
- for (BasicBlock::iterator newI, II=(*BI)->begin();
+ for (Method::iterator BI = F->begin(), BE = F->end(); BI != BE; ++BI)
+ for (BasicBlock::iterator newI, II = (*BI)->begin();
II != (*BI)->end(); II = ++newI)
{
newI = II;
namespace {
struct DecomposeMultiDimRefsPass : public MethodPass {
- virtual bool runOnMethod(Method *M) { return doDecomposeMultiDimRefs(M); }
+ virtual bool runOnMethod(Function *F) { return doDecomposeMultiDimRefs(F); }
};
}
#include "llvm/Transforms/Scalar/InstructionCombining.h"
#include "llvm/Transforms/Scalar/ConstantHandling.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iMemory.h"
#include "llvm/InstrTypes.h"
#include "llvm/Pass.h"
return true;
}
-static bool doInstCombining(Method *M) {
- // Start the worklist out with all of the instructions in the method in it.
+static bool doInstCombining(Function *M) {
+ // Start the worklist out with all of the instructions in the function in it.
std::vector<Instruction*> WorkList(inst_begin(M), inst_end(M));
while (!WorkList.empty()) {
namespace {
struct InstructionCombining : public MethodPass {
- virtual bool runOnMethod(Method *M) { return doInstCombining(M); }
+ virtual bool runOnMethod(Function *F) { return doInstCombining(F); }
};
}
-//===- SymbolStripping.cpp - Code to string symbols for methods and modules -=//
+//===- SymbolStripping.cpp - Strip symbols for functions and modules ------===//
//
// This file implements stripping symbols out of symbol tables.
//
// Specifically, this allows you to strip all of the symbols out of:
-// * A method
-// * All methods in a module
-// * All symbols in a module (all method symbols + all module scope symbols)
+// * A function
+// * All functions in a module
+// * All symbols in a module (all function symbols + all module scope symbols)
//
// Notice that:
// * This pass makes code much less readable, so it should only be used in
#include "llvm/Transforms/SymbolStripping.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/SymbolTable.h"
#include "llvm/Pass.h"
}
-// DoSymbolStripping - Remove all symbolic information from a method
+// DoSymbolStripping - Remove all symbolic information from a function
//
-static bool doSymbolStripping(Method *M) {
- return StripSymbolTable(M->getSymbolTable());
+static bool doSymbolStripping(Function *F) {
+ return StripSymbolTable(F->getSymbolTable());
}
-// doStripGlobalSymbols - Remove all symbolic information from all methods
-// in a module, and all module level symbols. (method names, etc...)
+// doStripGlobalSymbols - Remove all symbolic information from all functions
+// in a module, and all module level symbols. (function names, etc...)
//
static bool doStripGlobalSymbols(Module *M) {
- // Remove all symbols from methods in this module... and then strip all of the
- // symbols in this module...
+ // Remove all symbols from functions in this module... and then strip all of
+ // the symbols in this module...
//
return StripSymbolTable(M->getSymbolTable());
}
namespace {
struct SymbolStripping : public MethodPass {
- virtual bool runOnMethod(Method *M) {
- return doSymbolStripping(M);
+ virtual bool runOnMethod(Function *F) {
+ return doSymbolStripping(F);
}
};
//===----------------------------------------------------------------------===//
#include "TransformInternals.h"
-#include "llvm/Method.h"
#include "llvm/Type.h"
#include "llvm/ConstantVals.h"
#include "llvm/Analysis/Expressions.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/iMemory.h"
#include "llvm/Pass.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Assembly/Writer.h" // For debugging
#include "llvm/iPHINode.h"
namespace {
-//instance of the promoter -- to keep all the local method data.
-// gets re-created for each method processed
+//instance of the promoter -- to keep all the local function data.
+// gets re-created for each function processed
class PromoteInstance
{
protected:
void traverse(BasicBlock *f, BasicBlock * predecessor);
- bool PromoteMethod(Method *M, DominanceFrontier & DF);
+ bool PromoteFunction(Function *F, DominanceFrontier &DF);
bool queuePhiNode(BasicBlock *bb, int alloca_index);
- void findSafeAllocas(Method *M);
+ void findSafeAllocas(Function *M);
bool didchange;
public:
// I do this so that I can force the deconstruction of the local variables
- PromoteInstance(Method *M, DominanceFrontier & DF)
+ PromoteInstance(Function *F, DominanceFrontier &DF)
{
- didchange=PromoteMethod(M, DF);
+ didchange=PromoteFunction(F, DF);
}
//This returns whether the pass changes anything
operator bool () { return didchange; }
// findSafeAllocas - Find allocas that are safe to promote
//
-void PromoteInstance::findSafeAllocas(Method *M)
+void PromoteInstance::findSafeAllocas(Function *F)
{
- BasicBlock *BB = M->front(); // Get the entry node for the method
+ BasicBlock *BB = F->getEntryNode(); // Get the entry node for the function
// Look at all instructions in the entry node
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
-bool PromoteInstance::PromoteMethod(Method *M, DominanceFrontier & DF) {
+bool PromoteInstance::PromoteFunction(Function *F, DominanceFrontier & DF) {
// Calculate the set of safe allocas
- findSafeAllocas(M);
+ findSafeAllocas(F);
// Add each alloca to the killlist
// note: killlist is destroyed MOST recently added to least recently.
}
}
- // Walks all basic blocks in the method
+ // Walks all basic blocks in the function
// performing the SSA rename algorithm
// and inserting the phi nodes we marked as necessary
- BasicBlock * f = M->front(); //get root basic-block
+ BasicBlock * f = F->front(); //get root basic-block
CurrentValue.push_back(vector<Value *>(Allocas.size()));
namespace {
- class PromotePass : public MethodPass {
- public:
+ struct PromotePass : public MethodPass {
// runOnMethod - To run this pass, first we calculate the alloca
// instructions that are safe for promotion, then we promote each one.
//
- virtual bool runOnMethod(Method *M)
- {
- PromoteInstance inst(M, getAnalysis<DominanceFrontier>());
- return (bool)inst;
+ virtual bool runOnMethod(Function *F) {
+ return (bool)PromoteInstance(F, getAnalysis<DominanceFrontier>());
}
-//===- SimplifyCFG.cpp - CFG Simplification Routines -------------*- C++ -*--=//
+//===- UnifyFunctionExitNodes.cpp - Make all functions have a single exit -===//
//
// This file provides several routines that are useful for simplifying CFGs in
// various ways...
#include "llvm/Transforms/UnifyMethodExitNodes.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
#include "llvm/Type.h"
// BasicBlock, and converting all returns to unconditional branches to this
// new basic block. The singular exit node is returned.
//
-// If there are no return stmts in the Method, a null pointer is returned.
+// If there are no return stmts in the Function, a null pointer is returned.
//
-bool UnifyMethodExitNodes::doit(Method *M, BasicBlock *&ExitNode) {
- // Loop over all of the blocks in a method, tracking all of the blocks that
+bool UnifyMethodExitNodes::doit(Function *M, BasicBlock *&ExitNode) {
+ // Loop over all of the blocks in a function, tracking all of the blocks that
// return.
//
vector<BasicBlock*> ReturningBlocks;
- for(Method::iterator I = M->begin(), E = M->end(); I != E; ++I)
+ for(Function::iterator I = M->begin(), E = M->end(); I != E; ++I)
if (isa<ReturnInst>((*I)->getTerminator()))
ReturningBlocks.push_back(*I);
return false;
}
- // Otherwise, we need to insert a new basic block into the method, add a PHI
+ // Otherwise, we need to insert a new basic block into the function, add a PHI
// node (if the function returns a value), and convert all of the return
// instructions into unconditional branches.
//
BasicBlock *NewRetBlock = new BasicBlock("UnifiedExitNode", M);
if (M->getReturnType() != Type::VoidTy) {
- // If the method doesn't return void... add a PHI node to the block...
+ // If the function doesn't return void... add a PHI node to the block...
PHINode *PN = new PHINode(M->getReturnType());
NewRetBlock->getInstList().push_back(PN);
//===- DominatorSet.cpp - Dominator Set Calculation --------------*- C++ -*--=//
//
-// This file provides a simple class to calculate the dominator set of a method.
+// This file provides a simple class to calculate the dominator set of a
+// function.
//
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/Dominators.h"
#include "llvm/Transforms/UnifyMethodExitNodes.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h"
#include "Support/STLExtras.h"
AnalysisID cfg::DominatorSet::ID(AnalysisID::create<cfg::DominatorSet>());
AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create<cfg::DominatorSet>());
-bool cfg::DominatorSet::runOnMethod(Method *M) {
+bool cfg::DominatorSet::runOnMethod(Function *F) {
Doms.clear(); // Reset from the last time we were run...
if (isPostDominator())
- calcPostDominatorSet(M);
+ calcPostDominatorSet(F);
else
- calcForwardDominatorSet(M);
+ calcForwardDominatorSet(F);
return false;
}
// calcForwardDominatorSet - This method calculates the forward dominator sets
-// for the specified method.
+// for the specified function.
//
-void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
+void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
Root = M->getEntryNode();
assert(pred_begin(Root) == pred_end(Root) &&
- "Root node has predecessors in method!");
+ "Root node has predecessors in function!");
bool Changed;
do {
Changed = false;
DomSetType WorkingSet;
- df_iterator<Method*> It = df_begin(M), End = df_end(M);
+ df_iterator<Function*> It = df_begin(M), End = df_end(M);
for ( ; It != End; ++It) {
const BasicBlock *BB = *It;
pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
} while (Changed);
}
-// Postdominator set constructor. This ctor converts the specified method to
+// Postdominator set constructor. This ctor converts the specified function to
// only have a single exit node (return stmt), then calculates the post
-// dominance sets for the method.
+// dominance sets for the function.
//
-void cfg::DominatorSet::calcPostDominatorSet(Method *M) {
+void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
// Since we require that the unify all exit nodes pass has been run, we know
- // that there can be at most one return instruction in the method left.
+ // that there can be at most one return instruction in the function left.
// Get it.
//
Root = getAnalysis<UnifyMethodExitNodes>().getExitNode();
- if (Root == 0) { // No exit node for the method? Postdomsets are all empty
- for (Method::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
+ if (Root == 0) { // No exit node for the function? Postdomsets are all empty
+ for (Function::const_iterator MI = M->begin(), ME = M->end(); MI!=ME; ++MI)
Doms[*MI] = DomSetType();
return;
}
// Given immediate dominators, we can also calculate the dominator tree
cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
: DominatorBase(IDoms.getRoot()) {
- const Method *M = Root->getParent();
+ const Function *M = Root->getParent();
Nodes[Root] = new Node(Root, 0); // Add a node for the root...
// Iterate over all nodes in depth first order...
- for (df_iterator<const Method*> I = df_begin(M), E = df_end(M); I != E; ++I) {
+ for (df_iterator<const Function*> I = df_begin(M), E = df_end(M); I!=E; ++I) {
const BasicBlock *BB = *I, *IDom = IDoms[*I];
if (IDom != 0) { // Ignore the root node and other nasty nodes
// current node, and it is our idom! We know that we have already added
// a DominatorTree node for our idom, because the idom must be a
// predecessor in the depth first order that we are iterating through the
- // method.
+ // function.
//
DominatorSet::DomSetType::const_iterator I = Dominators.begin();
DominatorSet::DomSetType::const_iterator End = Dominators.end();
// chain than the current node, and it is our idom! We know that we have
// already added a DominatorTree node for our idom, because the idom must
// be a predecessor in the depth first order that we are iterating through
- // the method.
+ // the function.
//
DominatorSet::DomSetType::const_iterator I = Dominators.begin();
DominatorSet::DomSetType::const_iterator End = Dominators.end();
#include "llvm/Instruction.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/SymbolTable.h"
Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name)
// Specialize setName to take care of symbol table majik
void Instruction::setName(const std::string &name, SymbolTable *ST) {
- BasicBlock *P = 0; Method *PP = 0;
+ BasicBlock *P = 0; Function *PP = 0;
assert((ST == 0 || !getParent() || !getParent()->getParent() ||
ST == getParent()->getParent()->getSymbolTable()) &&
"Invalid symtab argument!");
#include "llvm/Analysis/SlotCalculator.h"
#include "llvm/Analysis/ConstantsScanner.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Module.h"
#include "llvm/BasicBlock.h"
processModule();
}
-SlotCalculator::SlotCalculator(const Method *M, bool IgnoreNamed) {
+SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
IgnoreNamedNodes = IgnoreNamed;
TheModule = M ? M->getParent() : 0;
}
-// processModule - Process all of the module level method declarations and
+// processModule - Process all of the module level function declarations and
// types that are available.
//
void SlotCalculator::processModule() {
for_each(TheModule->gbegin(), TheModule->gend(),
bind_obj(this, &SlotCalculator::insertValue));
- // Scavenge the types out of the methods, then add the methods themselves to
- // the value table...
+ // Scavenge the types out of the functions, then add the functions themselves
+ // to the value table...
//
- for_each(TheModule->begin(), TheModule->end(), // Insert methods...
+ for_each(TheModule->begin(), TheModule->end(), // Insert functions...
bind_obj(this, &SlotCalculator::insertValue));
// Insert constants that are named at module level into the slot pool so that
}
-void SlotCalculator::incorporateMethod(const Method *M) {
+void SlotCalculator::incorporateMethod(const Function *M) {
assert(ModuleLevel.size() == 0 && "Module already incorporated!");
- SC_DEBUG("begin processMethod!\n");
+ SC_DEBUG("begin processFunction!\n");
- // Save the Table state before we process the method...
+ // Save the Table state before we process the function...
for (unsigned i = 0; i < Table.size(); ++i)
ModuleLevel.push_back(Table[i].size());
- SC_DEBUG("Inserting method arguments\n");
+ SC_DEBUG("Inserting function arguments\n");
- // Iterate over method arguments, adding them to the value table...
+ // Iterate over function arguments, adding them to the value table...
for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
bind_obj(this, &SlotCalculator::insertValue));
- // Iterate over all of the instructions in the method, looking for constant
+ // Iterate over all of the instructions in the function, looking for constant
// values that are referenced. Add these to the value pools before any
// nonconstant values. This will be turned into the constant pool for the
// bytecode writer.
//
if (!IgnoreNamedNodes) { // Assembly writer does not need this!
- SC_DEBUG("Inserting method constants:\n";
+ SC_DEBUG("Inserting function constants:\n";
for (constant_iterator I = constant_begin(M), E = constant_end(M);
I != E; ++I) {
cerr << " " << I->getType()->getDescription()
});
// Emit all of the constants that are being used by the instructions in the
- // method...
+ // function...
for_each(constant_begin(M), constant_end(M),
bind_obj(this, &SlotCalculator::insertValue));
processSymbolTable(M->getSymbolTable());
}
- SC_DEBUG("end processMethod!\n");
+ SC_DEBUG("end processFunction!\n");
}
void SlotCalculator::purgeMethod() {
assert(ModuleLevel.size() != 0 && "Module not incorporated!");
unsigned NumModuleTypes = ModuleLevel.size();
- SC_DEBUG("begin purgeMethod!\n");
+ SC_DEBUG("begin purgeFunction!\n");
// First, remove values from existing type planes
for (unsigned i = 0; i < NumModuleTypes; ++i) {
- unsigned ModuleSize = ModuleLevel[i]; // Size of plane before method came
+ unsigned ModuleSize = ModuleLevel[i]; // Size of plane before function came
TypePlane &CurPlane = Table[i];
//SC_DEBUG("Processing Plane " <<i<< " of size " << CurPlane.size() <<endl);
// We don't need this state anymore, free it up.
ModuleLevel.clear();
- // Next, remove any type planes defined by the method...
+ // Next, remove any type planes defined by the function...
while (NumModuleTypes != Table.size()) {
TypePlane &Plane = Table.back();
SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size "
Table.pop_back(); // Nuke the plane, we don't like it.
}
- SC_DEBUG("end purgeMethod!\n");
+ SC_DEBUG("end purgeFunction!\n");
}
int SlotCalculator::getValSlot(const Value *D) const {
SC_DEBUG(" Inserting value [" << Ty << "] = " << D << " slot=" <<
DestSlot << " [");
- // G = Global, C = Constant, T = Type, M = Method, o = other
+ // G = Global, C = Constant, T = Type, F = Function, o = other
SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" :
- (isa<Type>(D) ? "T" : (isa<Method>(D) ? "M" : "o")))));
+ (isa<Type>(D) ? "T" : (isa<Function>(D) ? "F" : "o")))));
SC_DEBUG("]\n");
return (int)DestSlot;
}
#include "llvm/iOther.h"
#include "llvm/iTerminators.h"
#include "llvm/DerivedTypes.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
//===----------------------------------------------------------------------===//
// CallInst Implementation
//===----------------------------------------------------------------------===//
-CallInst::CallInst(Value *Meth, const std::vector<Value*> ¶ms,
+CallInst::CallInst(Value *Func, const std::vector<Value*> ¶ms,
const std::string &Name)
- : Instruction(cast<FunctionType>(cast<PointerType>(Meth->getType())
+ : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
Instruction::Call, Name) {
Operands.reserve(1+params.size());
- Operands.push_back(Use(Meth, this));
+ Operands.push_back(Use(Func, this));
const FunctionType *MTy =
- cast<FunctionType>(cast<PointerType>(Meth->getType())->getElementType());
+ cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
const FunctionType::ParamTypes &PL = MTy->getParamTypes();
assert((params.size() == PL.size()) ||
// InvokeInst Implementation
//===----------------------------------------------------------------------===//
-InvokeInst::InvokeInst(Value *Meth, BasicBlock *IfNormal, \
+InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal, \
BasicBlock *IfException,
const std::vector<Value*> ¶ms,
const std::string &Name)
- : TerminatorInst(cast<FunctionType>(cast<PointerType>(Meth->getType())
+ : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
Instruction::Invoke, Name) {
Operands.reserve(3+params.size());
- Operands.push_back(Use(Meth, this));
+ Operands.push_back(Use(Func, this));
Operands.push_back(Use(IfNormal, this));
Operands.push_back(Use(IfException, this));
const FunctionType *MTy =
- cast<FunctionType>(cast<PointerType>(Meth->getType())->getElementType());
+ cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
const FunctionType::ParamTypes &PL = MTy->getParamTypes();
assert((params.size() == PL.size()) ||
#include "llvm/Instruction.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/iPHINode.h"
#include "llvm/PassManager.h"
#include "llvm/Bytecode/Reader.h"
}
template<class PassType>
-static void printPass(PassType &P, ostream &O, Method *M) {
+static void printPass(PassType &P, ostream &O, Function *F) {
O << P;
}
public:
PassPrinter(const string &M, AnalysisID id) : Message(M), ID(id) {}
- virtual bool runOnMethod(Method *M) {
- std::cout << Message << " on method '" << M->getName() << "'\n";
- printPass(getAnalysis<PassName>(ID), std::cout, M);
+ virtual bool runOnMethod(Function *F) {
+ std::cout << Message << " on method '" << F->getName() << "'\n";
+ printPass(getAnalysis<PassName>(ID), std::cout, F);
return false;
}
-Pass *NewPrintMethod(const string &Message) {
+Pass *NewPrintFunction(const string &Message) {
return new PrintMethodPass(Message, &std::cout);
}
Pass *NewPrintModule(const string &Message) {
}
struct InstForest : public MethodPass {
- void doit(Method *M) {
- std::cout << analysis::InstForest<char>(M);
+ void doit(Function *F) {
+ std::cout << analysis::InstForest<char>(F);
}
};
struct IndVars : public MethodPass {
- void doit(Method *M) {
+ void doit(Function *F) {
cfg::LoopInfo &LI = getAnalysis<cfg::LoopInfo>();
- for (inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I)
+ for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
if (PHINode *PN = dyn_cast<PHINode>(*I)) {
InductionVariable IV(PN, &LI);
if (IV.InductionType != InductionVariable::Unknown)
};
struct Exprs : public MethodPass {
- static void doit(Method *M) {
- std::cout << "Classified expressions for: " << M->getName() << "\n";
- for (inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I) {
+ static void doit(Function *F) {
+ std::cout << "Classified expressions for: " << F->getName() << "\n";
+ for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
std::cout << *I;
if ((*I)->getType() == Type::VoidTy) continue;
public:
PrinterPass(const string &M) : Message(M) {}
- virtual bool runOnMethod(Method *M) {
- std::cout << Message << " on method '" << M->getName() << "'\n";
+ virtual bool runOnMethod(Function *F) {
+ std::cout << Message << " on method '" << F->getName() << "'\n";
- TraitClass::doit(M);
+ TraitClass::doit(F);
return false;
}
};
cl::Flag Quiet ("q", "Don't print analysis pass names");
cl::Alias QuietA ("quiet", "Alias for -q", cl::NoFlags, Quiet);
cl::EnumList<enum Ans> AnalysesList(cl::NoFlags,
- clEnumVal(print , "Print each method"),
+ clEnumVal(print , "Print each function"),
clEnumVal(intervals , "Print Interval Partitions"),
clEnumVal(exprs , "Classify Expressions"),
clEnumVal(instforest , "Print Instruction Forest"),
Pass *(*PassConstructor)(const string &Message);
} AnTable[] = {
// Global analyses
- { print , NewPrintMethod },
+ { print , NewPrintFunction },
{ intervals , New<MethodPass, cfg::IntervalPartition> },
{ loops , New<MethodPass, cfg::LoopInfo> },
{ instforest , Create<PrinterPass<InstForest> > },
#include "llvm/Module.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Bytecode/Reader.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h"
#include "Support/PostOrderIterator.h"
// OutputMode - The different orderings to print basic blocks in...
enum OutputMode {
- Default = 0, // Method Order (list order)
+ Default = 0, // Function Order (list order)
dfo, // Depth First ordering
rdfo, // Reverse Depth First ordering
po, // Post Order
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
std::ostream *Out = &std::cout; // Default to printing to stdout...
- Module *C = ParseBytecodeFile(InputFilename);
- if (C == 0) {
+ Module *M = ParseBytecodeFile(InputFilename);
+ if (M == 0) {
cerr << "bytecode didn't read correctly.\n";
return 1;
}
// what the writer library is supposed to do...
//
if (WriteMode == Default) {
- (*Out) << C; // Print out in list order
+ (*Out) << M; // Print out in list order
} else {
// TODO: This does not print anything other than the basic blocks in the
- // methods... more should definately be printed. It should be valid output
- // consumable by the assembler.
+ // functions... more should definately be printed. It should be valid
+ // output consumable by the assembler.
//
- for (Module::iterator I = C->begin(), End = C->end(); I != End; ++I) {
- Method *M = *I;
- (*Out) << "-------------- Method: " << M->getName() << " -------------\n";
+ for (Module::iterator I = M->begin(), End = M->end(); I != End; ++I) {
+ Function *F = *I;
+ (*Out) << "-------------- Method: " << F->getName() << " -------------\n";
switch (WriteMode) {
case dfo: // Depth First ordering
- copy(df_begin(M), df_end(M),
+ copy(df_begin(F), df_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rdfo: // Reverse Depth First ordering
- copy(df_begin(M, true), df_end(M),
+ copy(df_begin(F, true), df_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case po: // Post Order
- copy(po_begin(M), po_end(M),
+ copy(po_begin(F), po_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rpo: { // Reverse Post Order
#if 0 // FIXME, GCC 3.0.4 bug
- ReversePostOrderTraversal<Method*> RPOT(M());
+ ReversePostOrderTraversal<Function*> RPOT(F);
copy(RPOT.begin(), RPOT.end(),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
#endif
}
}
}
- delete C;
+ delete M;
if (Out != &std::cout) delete Out;
return 0;
#include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/Writer.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
#include "Support/CommandLine.h"
#include <fstream>
#include <memory>
}
}
+ // Now that composite has been compiled, scan through the module, looking for
+ // a main function. If main is defined, mark all other functions internal.
+ //
+
+ // Next run globaldce...
+
+ // next ?
+
+
std::ofstream Out((OutputFilename+".bc").c_str());
if (!Out.good()) {
cerr << "Error opening '" << OutputFilename << ".bc' for writing!\n";
#include "llvm/Bytecode/Writer.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
#include "Support/CommandLine.h"
#include <fstream>
#include <memory>
#include "llvm/Bytecode/WriteBytecodePass.h"
#include "llvm/Transforms/ConstantMerge.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/PassManager.h"
#include "Support/CommandLine.h"
#include <memory>
static cl::Flag DumpAsm ("d", "Print bytecode before native code generation", cl::Hidden);
enum TraceLevel {
- TraceOff, TraceMethods, TraceBasicBlocks
+ TraceOff, TraceFunctions, TraceBasicBlocks
};
static cl::Enum<enum TraceLevel> TraceValues("trace", cl::NoFlags,
- "Trace values through methods or basic blocks",
+ "Trace values through functions or basic blocks",
clEnumValN(TraceOff , "off", "Disable trace code"),
- clEnumValN(TraceMethods , "method", "Trace each method"),
+ clEnumValN(TraceFunctions , "function", "Trace each function"),
clEnumValN(TraceBasicBlocks, "basicblock", "Trace each basic block"), 0);
Passes.add(createHoistPHIConstantsPass());
if (TraceValues != TraceOff) { // If tracing enabled...
- // Insert trace code in all methods in the module
+ // Insert trace code in all functions in the module
if (TraceValues == TraceBasicBlocks)
Passes.add(createTraceValuesPassForBasicBlocks());
- else if (TraceValues == TraceMethods)
+ else if (TraceValues == TraceFunctions)
Passes.add(createTraceValuesPassForMethod());
else
assert(0 && "Bad value for TraceValues!");
#include "llvm/Module.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Bytecode/Reader.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h"
#include "Support/PostOrderIterator.h"
// OutputMode - The different orderings to print basic blocks in...
enum OutputMode {
- Default = 0, // Method Order (list order)
+ Default = 0, // Function Order (list order)
dfo, // Depth First ordering
rdfo, // Reverse Depth First ordering
po, // Post Order
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
std::ostream *Out = &std::cout; // Default to printing to stdout...
- Module *C = ParseBytecodeFile(InputFilename);
- if (C == 0) {
+ Module *M = ParseBytecodeFile(InputFilename);
+ if (M == 0) {
cerr << "bytecode didn't read correctly.\n";
return 1;
}
// what the writer library is supposed to do...
//
if (WriteMode == Default) {
- (*Out) << C; // Print out in list order
+ (*Out) << M; // Print out in list order
} else {
// TODO: This does not print anything other than the basic blocks in the
- // methods... more should definately be printed. It should be valid output
- // consumable by the assembler.
+ // functions... more should definately be printed. It should be valid
+ // output consumable by the assembler.
//
- for (Module::iterator I = C->begin(), End = C->end(); I != End; ++I) {
- Method *M = *I;
- (*Out) << "-------------- Method: " << M->getName() << " -------------\n";
+ for (Module::iterator I = M->begin(), End = M->end(); I != End; ++I) {
+ Function *F = *I;
+ (*Out) << "-------------- Method: " << F->getName() << " -------------\n";
switch (WriteMode) {
case dfo: // Depth First ordering
- copy(df_begin(M), df_end(M),
+ copy(df_begin(F), df_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rdfo: // Reverse Depth First ordering
- copy(df_begin(M, true), df_end(M),
+ copy(df_begin(F, true), df_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case po: // Post Order
- copy(po_begin(M), po_end(M),
+ copy(po_begin(F), po_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rpo: { // Reverse Post Order
#if 0 // FIXME, GCC 3.0.4 bug
- ReversePostOrderTraversal<Method*> RPOT(M());
+ ReversePostOrderTraversal<Function*> RPOT(F);
copy(RPOT.begin(), RPOT.end(),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
#endif
}
}
}
- delete C;
+ delete M;
if (Out != &std::cout) delete Out;
return 0;
#include "llvm/Module.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Bytecode/Reader.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
#include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h"
#include "Support/PostOrderIterator.h"
// OutputMode - The different orderings to print basic blocks in...
enum OutputMode {
- Default = 0, // Method Order (list order)
+ Default = 0, // Function Order (list order)
dfo, // Depth First ordering
rdfo, // Reverse Depth First ordering
po, // Post Order
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
std::ostream *Out = &std::cout; // Default to printing to stdout...
- Module *C = ParseBytecodeFile(InputFilename);
- if (C == 0) {
+ Module *M = ParseBytecodeFile(InputFilename);
+ if (M == 0) {
cerr << "bytecode didn't read correctly.\n";
return 1;
}
// what the writer library is supposed to do...
//
if (WriteMode == Default) {
- (*Out) << C; // Print out in list order
+ (*Out) << M; // Print out in list order
} else {
// TODO: This does not print anything other than the basic blocks in the
- // methods... more should definately be printed. It should be valid output
- // consumable by the assembler.
+ // functions... more should definately be printed. It should be valid
+ // output consumable by the assembler.
//
- for (Module::iterator I = C->begin(), End = C->end(); I != End; ++I) {
- Method *M = *I;
- (*Out) << "-------------- Method: " << M->getName() << " -------------\n";
+ for (Module::iterator I = M->begin(), End = M->end(); I != End; ++I) {
+ Function *F = *I;
+ (*Out) << "-------------- Method: " << F->getName() << " -------------\n";
switch (WriteMode) {
case dfo: // Depth First ordering
- copy(df_begin(M), df_end(M),
+ copy(df_begin(F), df_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rdfo: // Reverse Depth First ordering
- copy(df_begin(M, true), df_end(M),
+ copy(df_begin(F, true), df_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case po: // Post Order
- copy(po_begin(M), po_end(M),
+ copy(po_begin(F), po_end(F),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rpo: { // Reverse Post Order
#if 0 // FIXME, GCC 3.0.4 bug
- ReversePostOrderTraversal<Method*> RPOT(M());
+ ReversePostOrderTraversal<Function*> RPOT(F);
copy(RPOT.begin(), RPOT.end(),
std::ostream_iterator<BasicBlock*>(*Out, "\n"));
#endif
}
}
}
- delete C;
+ delete M;
if (Out != &std::cout) delete Out;
return 0;
#include "llvm/Bytecode/Writer.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Module.h"
-#include "llvm/Method.h"
#include "Support/CommandLine.h"
#include <fstream>
#include <memory>