aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineFunction.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-10-30 00:48:05 +0000
committerChris Lattner <sabre@nondot.org>2002-10-30 00:48:05 +0000
commit1049164aa6b06d91d9b3b557a9a213eaf3f6319a (patch)
tree94b2d774a74729ad062218417c1c6088f42d5ca8 /lib/CodeGen/MachineFunction.cpp
parent3dffa7953f1c532944931c6fd77ab02ea3af00c1 (diff)
Implement structured machine code printing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4435 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineFunction.cpp')
-rw-r--r--lib/CodeGen/MachineFunction.cpp72
1 files changed, 46 insertions, 26 deletions
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index f18fb148b2..3dcbabc2a6 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -61,6 +61,19 @@ namespace {
return false;
}
};
+
+ struct Printer : public FunctionPass {
+ const char *getPassName() const { return "MachineFunction Printer"; }
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ }
+
+ bool runOnFunction(Function &F) {
+ MachineFunction::get(&F).dump();
+ return false;
+ }
+ };
}
Pass *createMachineCodeConstructionPass(TargetMachine &Target) {
@@ -71,11 +84,44 @@ Pass *createMachineCodeDestructionPass() {
return new DestroyMachineFunction();
}
+Pass *createMachineFunctionPrinterPass() {
+ return new Printer();
+}
+
//===---------------------------------------------------------------------===//
// MachineFunction implementation
//===---------------------------------------------------------------------===//
+MachineFunction::MachineFunction(const Function *F,
+ const TargetMachine& target)
+ : Annotation(MF_AID),
+ Fn(F), Target(target), staticStackSize(0),
+ automaticVarsSize(0), regSpillsSize(0),
+ maxOptionalArgsSize(0), maxOptionalNumArgs(0),
+ currentTmpValuesSize(0), maxTmpValuesSize(0), compiledAsLeaf(false),
+ spillsAreaFrozen(false), automaticVarsAreaFrozen(false)
+{
+}
+
+void MachineFunction::dump() const { print(std::cerr); }
+
+void MachineFunction::print(std::ostream &OS) const {
+ OS << "\n" << *(Value*)Fn->getReturnType() << " \"" << Fn->getName()<< "\"\n";
+
+ for (const_iterator BB = begin(); BB != end(); ++BB) {
+ BasicBlock *LBB = BB->getBasicBlock();
+ OS << "\n" << LBB->getName() << " ("
+ << (const void*)BB->getBasicBlock() << "):\n";
+ for (MachineBasicBlock::const_iterator I = BB->begin(); I != BB->end();++I){
+ OS << "\t";
+ (*I)->print(OS, Target);
+ }
+ }
+ OS << "\nEnd function \"" << Fn->getName() << "\"\n\n";
+}
+
+
// The next two methods are used to construct and to retrieve
// the MachineCodeForFunction object for the given function.
// construct() -- Allocates and initializes for a given function and target
@@ -173,17 +219,6 @@ SizeToAlignment(unsigned int size, const TargetMachine& target)
}
-MachineFunction::MachineFunction(const Function *F,
- const TargetMachine& target)
- : Annotation(MF_AID),
- Fn(F), Target(target), staticStackSize(0),
- automaticVarsSize(0), regSpillsSize(0),
- maxOptionalArgsSize(0), maxOptionalNumArgs(0),
- currentTmpValuesSize(0), maxTmpValuesSize(0), compiledAsLeaf(false),
- spillsAreaFrozen(false), automaticVarsAreaFrozen(false)
-{
-}
-
void MachineFunction::CalculateArgSize() {
maxOptionalArgsSize = ComputeMaxOptionalArgsSize(Target, Fn,
maxOptionalNumArgs);
@@ -292,18 +327,3 @@ MachineFunction::getOffset(const Value* val) const
hash_map<const Value*, int>::const_iterator pair = offsets.find(val);
return (pair == offsets.end()) ? INVALID_FRAME_OFFSET : pair->second;
}
-
-void
-MachineFunction::dump() const
-{
- std::cerr << "\n" << Fn->getReturnType()
- << " \"" << Fn->getName() << "\"\n";
-
- for (const_iterator BB = begin(); BB != end(); ++BB) {
- std::cerr << "\n" << BB->getBasicBlock()->getName() << " ("
- << (const void*)BB->getBasicBlock() << ")" << ":" << "\n";
- for (MachineBasicBlock::const_iterator I = BB->begin(); I != BB->end(); ++I)
- std::cerr << "\t" << *I;
- }
- std::cerr << "\nEnd function \"" << Fn->getName() << "\"\n\n";
-}