[llvm-commits] CVS: llvm/lib/Target/SparcV8/SparcV8AsmPrinter.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Dec 16 23:04:41 PST 2005
Changes in directory llvm/lib/Target/SparcV8:
SparcV8AsmPrinter.cpp updated: 1.41 -> 1.42
---
Log message:
Use the shared AsmPrinter code for some basic stuff. No functionality
change except for fewer .section directives emitted
---
Diffs of the changes: (+14 -41)
SparcV8AsmPrinter.cpp | 55 ++++++++++++--------------------------------------
1 files changed, 14 insertions(+), 41 deletions(-)
Index: llvm/lib/Target/SparcV8/SparcV8AsmPrinter.cpp
diff -u llvm/lib/Target/SparcV8/SparcV8AsmPrinter.cpp:1.41 llvm/lib/Target/SparcV8/SparcV8AsmPrinter.cpp:1.42
--- llvm/lib/Target/SparcV8/SparcV8AsmPrinter.cpp:1.41 Sat Dec 17 00:54:41 2005
+++ llvm/lib/Target/SparcV8/SparcV8AsmPrinter.cpp Sat Dec 17 01:04:29 2005
@@ -18,6 +18,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/Assembly/Writer.h"
+#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineInstr.h"
@@ -33,21 +34,8 @@
namespace {
Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
- struct SparcV8AsmPrinter : public MachineFunctionPass {
- /// Output stream on which we're printing assembly code.
- ///
- std::ostream &O;
-
- /// Target machine description which we query for reg. names, data
- /// layout, etc.
- ///
- TargetMachine &TM;
-
- /// Name-mangler for global names.
- ///
- Mangler *Mang;
-
- SparcV8AsmPrinter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) { }
+ struct SparcV8AsmPrinter : public AsmPrinter {
+ SparcV8AsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {}
/// We name each basic block in a Function with a unique number, so
/// that we can consistently refer to them later. This is cleared
@@ -56,12 +44,6 @@
typedef std::map<const Value *, unsigned> ValueMapTy;
ValueMapTy NumberForBB;
- /// Cache of mangled name for current function. This is
- /// recalculated at the beginning of each call to
- /// runOnMachineFunction().
- ///
- std::string CurrentFnName;
-
virtual const char *getPassName() const {
return "SparcV8 Assembly Printer";
}
@@ -306,8 +288,8 @@
if (CP.empty()) return;
+ SwitchSection(".section \".rodata\"\n", 0);
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
- O << "\t.section \".rodata\"\n";
O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType())
<< "\n";
O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t!"
@@ -320,6 +302,8 @@
/// method to print assembly for each instruction.
///
bool SparcV8AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+ SetupMachineFunction(MF);
+
// BBNumber is used here so that a given Printer will never give two
// BBs the same name. (If you have a better way, please let me know!)
static unsigned BBNumber = 0;
@@ -358,6 +342,7 @@
// Print the assembly for the instruction.
O << "\t";
printInstruction(II);
+ ++EmittedInsts;
}
}
@@ -426,21 +411,8 @@
return false; // success
}
-// SwitchSection - Switch to the specified section of the executable if we are
-// not already in it!
-//
-static void SwitchSection(std::ostream &OS, std::string &CurSection,
- const char *NewSection) {
- if (CurSection != NewSection) {
- CurSection = NewSection;
- if (!CurSection.empty())
- OS << "\t.section \"" << NewSection << "\"\n";
- }
-}
-
bool SparcV8AsmPrinter::doFinalization(Module &M) {
const TargetData &TD = TM.getTargetData();
- std::string CurSection;
// Print out module-level global variables here.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
@@ -454,7 +426,7 @@
if (C->isNullValue() &&
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
I->hasWeakLinkage() /* FIXME: Verify correct */)) {
- SwitchSection(O, CurSection, ".data");
+ SwitchSection(".data", I);
if (I->hasInternalLinkage())
O << "\t.local " << name << "\n";
@@ -469,8 +441,9 @@
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
// Nonnull linkonce -> weak
O << "\t.weak " << name << "\n";
- SwitchSection(O, CurSection, "");
- O << "\t.section\t\".llvm.linkonce.d." << name << "\",\"aw\", at progbits\n";
+ SwitchSection("", I);
+ O << "\t.section\t\".llvm.linkonce.d." << name
+ << "\",\"aw\", at progbits\n";
break;
case GlobalValue::AppendingLinkage:
@@ -482,9 +455,9 @@
// FALL THROUGH
case GlobalValue::InternalLinkage:
if (C->isNullValue())
- SwitchSection(O, CurSection, ".bss");
+ SwitchSection(".bss", I);
else
- SwitchSection(O, CurSection, ".data");
+ SwitchSection(".data", I);
break;
case GlobalValue::GhostLinkage:
std::cerr << "Should not have any unmaterialized functions!\n";
@@ -503,6 +476,6 @@
}
}
- delete Mang;
+ AsmPrinter::doFinalization(M);
return false; // success
}
More information about the llvm-commits
mailing list