2004-04-25 15:04:49 +08:00
|
|
|
//===-- EmitAssembly.cpp - Emit SparcV9 Specific .s File -------------------==//
|
2003-10-21 03:43:21 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-19 21:47:27 +08:00
|
|
|
//
|
2003-08-18 22:43:39 +08:00
|
|
|
// This file implements all of the stuff necessary to output a .s file from
|
2001-09-19 21:47:27 +08:00
|
|
|
// LLVM. The code in this file assumes that the specified module has already
|
|
|
|
// been compiled into the internal data structures of the Module.
|
|
|
|
//
|
2002-04-27 14:56:12 +08:00
|
|
|
// This code largely consists of two LLVM Pass's: a FunctionPass and a Pass.
|
|
|
|
// The FunctionPass is pipelined together with all of the rest of the code
|
|
|
|
// generation stages, and the Pass runs at the end to emit code for global
|
|
|
|
// variables and such.
|
2001-09-19 21:47:27 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-04-29 03:55:58 +08:00
|
|
|
#include "llvm/Constants.h"
|
2001-10-29 05:38:52 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2001-09-19 21:47:27 +08:00
|
|
|
#include "llvm/Module.h"
|
2002-04-29 04:40:59 +08:00
|
|
|
#include "llvm/Pass.h"
|
2002-04-19 02:15:38 +08:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2004-08-18 13:29:08 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2003-12-18 06:06:28 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2004-01-16 06:44:19 +08:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
2004-02-26 02:44:15 +08:00
|
|
|
#include "SparcV9Internals.h"
|
2004-08-17 05:55:02 +08:00
|
|
|
#include "MachineFunctionInfo.h"
|
2003-08-06 00:01:50 +08:00
|
|
|
#include <string>
|
2003-11-13 08:22:19 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2001-09-19 21:47:27 +08:00
|
|
|
namespace {
|
2003-11-13 08:22:19 +08:00
|
|
|
Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
|
2004-08-18 13:29:08 +08:00
|
|
|
}
|
2003-11-13 08:22:19 +08:00
|
|
|
|
|
|
|
namespace {
|
2004-08-18 13:29:08 +08:00
|
|
|
struct SparcV9AsmPrinter : public AsmPrinter {
|
2003-11-13 08:22:19 +08:00
|
|
|
public:
|
|
|
|
enum Sections {
|
|
|
|
Unknown,
|
|
|
|
Text,
|
|
|
|
ReadOnlyData,
|
|
|
|
InitRWData,
|
|
|
|
ZeroInitRWData,
|
|
|
|
} CurSection;
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
SparcV9AsmPrinter(std::ostream &OS, TargetMachine &TM)
|
|
|
|
: AsmPrinter(OS, TM), CurSection(Unknown) {
|
|
|
|
ZeroDirective = 0; // No way to get zeros.
|
|
|
|
Data16bitsDirective = "\t.half\t";
|
|
|
|
Data32bitsDirective = "\t.word\t";
|
|
|
|
Data64bitsDirective = "\t.xword\t";
|
|
|
|
CommentString = "!";
|
2003-11-08 01:45:28 +08:00
|
|
|
}
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
const char *getPassName() const {
|
|
|
|
return "SparcV9 Assembly Printer";
|
2003-11-13 08:22:19 +08:00
|
|
|
}
|
2003-11-08 01:45:28 +08:00
|
|
|
|
2003-11-13 08:22:19 +08:00
|
|
|
// Print a constant (which may be an aggregate) prefixed by all the
|
|
|
|
// appropriate directives. Uses printConstantValueOnly() to print the
|
|
|
|
// value or values.
|
2004-08-18 13:29:08 +08:00
|
|
|
void printConstant(const Constant* CV, const std::string &valID) {
|
|
|
|
emitAlignment(TM.getTargetData().getTypeAlignmentShift(CV->getType()));
|
|
|
|
O << "\t.type" << "\t" << valID << ",#object\n";
|
2003-11-08 01:45:28 +08:00
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
unsigned constSize = TM.getTargetData().getTypeSize(CV->getType());
|
|
|
|
O << "\t.size" << "\t" << valID << "," << constSize << "\n";
|
2003-11-08 01:45:28 +08:00
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
O << valID << ":\n";
|
2003-11-08 01:45:28 +08:00
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
emitGlobalConstant(CV);
|
2003-11-13 08:22:19 +08:00
|
|
|
}
|
2003-11-08 01:45:28 +08:00
|
|
|
|
2003-11-13 08:22:19 +08:00
|
|
|
// enterSection - Use this method to enter a different section of the output
|
|
|
|
// executable. This is used to only output necessary section transitions.
|
|
|
|
//
|
|
|
|
void enterSection(enum Sections S) {
|
|
|
|
if (S == CurSection) return; // Only switch section if necessary
|
|
|
|
CurSection = S;
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\n\t.section ";
|
2003-11-13 08:22:19 +08:00
|
|
|
switch (S)
|
2003-05-31 15:27:17 +08:00
|
|
|
{
|
|
|
|
default: assert(0 && "Bad section name!");
|
2004-08-18 13:29:08 +08:00
|
|
|
case Text: O << "\".text\""; break;
|
|
|
|
case ReadOnlyData: O << "\".rodata\",#alloc"; break;
|
|
|
|
case InitRWData: O << "\".data\",#alloc,#write"; break;
|
|
|
|
case ZeroInitRWData: O << "\".bss\",#alloc,#write"; break;
|
2003-05-31 15:27:17 +08:00
|
|
|
}
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\n";
|
2003-11-13 08:22:19 +08:00
|
|
|
}
|
2001-09-19 21:47:27 +08:00
|
|
|
|
2004-01-16 06:44:19 +08:00
|
|
|
// getID Wrappers - Ensure consistent usage
|
2004-02-26 02:44:15 +08:00
|
|
|
// Symbol names in SparcV9 assembly language have these rules:
|
2004-01-16 06:44:19 +08:00
|
|
|
// (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
|
|
|
|
// (b) A name beginning in "." is treated as a local name.
|
2003-11-13 08:22:19 +08:00
|
|
|
std::string getID(const Function *F) {
|
2004-01-16 06:44:19 +08:00
|
|
|
return Mang->getValueName(F);
|
2003-11-13 08:22:19 +08:00
|
|
|
}
|
|
|
|
std::string getID(const BasicBlock *BB) {
|
2004-01-16 06:44:19 +08:00
|
|
|
return ".L_" + getID(BB->getParent()) + "_" + Mang->getValueName(BB);
|
2003-11-13 08:22:19 +08:00
|
|
|
}
|
|
|
|
std::string getID(const GlobalVariable *GV) {
|
2004-01-16 06:44:19 +08:00
|
|
|
return Mang->getValueName(GV);
|
2003-11-13 08:22:19 +08:00
|
|
|
}
|
|
|
|
std::string getID(const Constant *CV) {
|
2004-01-16 06:44:19 +08:00
|
|
|
return ".C_" + Mang->getValueName(CV);
|
2003-11-13 08:22:19 +08:00
|
|
|
}
|
|
|
|
std::string getID(const GlobalValue *GV) {
|
|
|
|
if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
|
|
|
|
return getID(V);
|
|
|
|
else if (const Function *F = dyn_cast<Function>(GV))
|
|
|
|
return getID(F);
|
|
|
|
assert(0 && "Unexpected type of GlobalValue!");
|
|
|
|
return "";
|
|
|
|
}
|
2002-08-22 10:58:36 +08:00
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
setupMachineFunction(MF);
|
|
|
|
emitFunction(MF);
|
2003-11-13 08:22:19 +08:00
|
|
|
return false;
|
|
|
|
}
|
2002-04-29 05:27:06 +08:00
|
|
|
|
2003-11-13 08:22:19 +08:00
|
|
|
virtual bool doFinalization(Module &M) {
|
|
|
|
emitGlobals(M);
|
2004-08-18 13:29:08 +08:00
|
|
|
AsmPrinter::doFinalization(M);
|
2003-11-13 08:22:19 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
void emitFunction(MachineFunction &F);
|
2003-11-13 08:22:19 +08:00
|
|
|
private :
|
|
|
|
void emitBasicBlock(const MachineBasicBlock &MBB);
|
|
|
|
void emitMachineInst(const MachineInstr *MI);
|
2002-02-04 07:41:08 +08:00
|
|
|
|
2003-11-13 08:22:19 +08:00
|
|
|
unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
|
|
|
|
void printOneOperand(const MachineOperand &Op, MachineOpCode opCode);
|
2002-02-04 07:41:08 +08:00
|
|
|
|
2003-11-13 08:22:19 +08:00
|
|
|
bool OpIsBranchTargetLabel(const MachineInstr *MI, unsigned int opNum);
|
|
|
|
bool OpIsMemoryAddressBase(const MachineInstr *MI, unsigned int opNum);
|
2002-02-04 07:41:08 +08:00
|
|
|
|
2003-11-13 08:22:19 +08:00
|
|
|
unsigned getOperandMask(unsigned Opcode) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case V9::SUBccr:
|
|
|
|
case V9::SUBcci: return 1 << 3; // Remove CC argument
|
|
|
|
default: return 0; // By default, don't hack operands...
|
|
|
|
}
|
2002-02-04 07:41:08 +08:00
|
|
|
}
|
2003-11-13 08:22:19 +08:00
|
|
|
|
|
|
|
void emitGlobals(const Module &M);
|
|
|
|
void printGlobalVariable(const GlobalVariable *GV);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End anonymous namespace
|
2001-11-27 08:03:19 +08:00
|
|
|
|
2001-10-29 05:38:52 +08:00
|
|
|
inline bool
|
2004-02-26 02:44:15 +08:00
|
|
|
SparcV9AsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
|
2003-11-13 08:22:19 +08:00
|
|
|
unsigned int opNum) {
|
2004-02-12 04:47:34 +08:00
|
|
|
switch (MI->getOpcode()) {
|
2003-05-28 06:35:43 +08:00
|
|
|
case V9::JMPLCALLr:
|
|
|
|
case V9::JMPLCALLi:
|
|
|
|
case V9::JMPLRETr:
|
|
|
|
case V9::JMPLRETi:
|
2003-05-21 04:32:24 +08:00
|
|
|
return (opNum == 0);
|
|
|
|
default:
|
|
|
|
return false;
|
2001-10-16 03:21:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-29 05:38:52 +08:00
|
|
|
inline bool
|
2004-02-26 02:44:15 +08:00
|
|
|
SparcV9AsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
|
2003-11-13 08:22:19 +08:00
|
|
|
unsigned int opNum) {
|
2004-08-18 13:29:08 +08:00
|
|
|
if (TM.getInstrInfo()->isLoad(MI->getOpcode()))
|
2001-10-29 05:38:52 +08:00
|
|
|
return (opNum == 0);
|
2004-08-18 13:29:08 +08:00
|
|
|
else if (TM.getInstrInfo()->isStore(MI->getOpcode()))
|
2001-10-29 05:38:52 +08:00
|
|
|
return (opNum == 1);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2001-09-19 21:47:27 +08:00
|
|
|
|
2001-10-29 05:38:52 +08:00
|
|
|
unsigned int
|
2004-08-18 13:29:08 +08:00
|
|
|
SparcV9AsmPrinter::printOperands(const MachineInstr *MI, unsigned opNum) {
|
2002-07-11 05:41:21 +08:00
|
|
|
const MachineOperand& mop = MI->getOperand(opNum);
|
2003-11-13 08:22:19 +08:00
|
|
|
if (OpIsBranchTargetLabel(MI, opNum)) {
|
2004-08-18 13:29:08 +08:00
|
|
|
printOneOperand(mop, MI->getOpcode());
|
|
|
|
O << "+";
|
|
|
|
printOneOperand(MI->getOperand(opNum+1), MI->getOpcode());
|
2003-11-13 08:22:19 +08:00
|
|
|
return 2;
|
|
|
|
} else if (OpIsMemoryAddressBase(MI, opNum)) {
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "[";
|
|
|
|
printOneOperand(mop, MI->getOpcode());
|
|
|
|
O << "+";
|
|
|
|
printOneOperand(MI->getOperand(opNum+1), MI->getOpcode());
|
|
|
|
O << "]";
|
2003-11-13 08:22:19 +08:00
|
|
|
return 2;
|
|
|
|
} else {
|
2004-02-12 04:47:34 +08:00
|
|
|
printOneOperand(mop, MI->getOpcode());
|
2003-11-13 08:22:19 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2001-10-29 05:38:52 +08:00
|
|
|
}
|
2001-10-25 06:05:34 +08:00
|
|
|
|
2001-10-29 05:38:52 +08:00
|
|
|
void
|
2004-02-26 02:44:15 +08:00
|
|
|
SparcV9AsmPrinter::printOneOperand(const MachineOperand &mop,
|
2004-08-18 13:29:08 +08:00
|
|
|
MachineOpCode opCode)
|
2001-10-29 05:38:52 +08:00
|
|
|
{
|
2002-07-11 05:41:21 +08:00
|
|
|
bool needBitsFlag = true;
|
|
|
|
|
2003-12-14 21:24:17 +08:00
|
|
|
if (mop.isHiBits32())
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "%lm(";
|
2003-12-14 21:24:17 +08:00
|
|
|
else if (mop.isLoBits32())
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "%lo(";
|
2003-12-14 21:24:17 +08:00
|
|
|
else if (mop.isHiBits64())
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "%hh(";
|
2003-12-14 21:24:17 +08:00
|
|
|
else if (mop.isLoBits64())
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "%hm(";
|
2002-07-11 05:41:21 +08:00
|
|
|
else
|
|
|
|
needBitsFlag = false;
|
|
|
|
|
2002-10-28 12:45:29 +08:00
|
|
|
switch (mop.getType())
|
2003-05-31 15:27:17 +08:00
|
|
|
{
|
2003-07-07 04:13:59 +08:00
|
|
|
case MachineOperand::MO_VirtualRegister:
|
2003-07-11 03:42:11 +08:00
|
|
|
case MachineOperand::MO_CCRegister:
|
2003-05-31 15:27:17 +08:00
|
|
|
case MachineOperand::MO_MachineRegister:
|
|
|
|
{
|
2004-02-14 05:01:20 +08:00
|
|
|
int regNum = (int)mop.getReg();
|
2003-07-11 03:42:11 +08:00
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
if (regNum == TM.getRegInfo()->getInvalidRegNum()) {
|
2003-05-31 15:27:17 +08:00
|
|
|
// better to print code with NULL registers than to die
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "<NULL VALUE>";
|
2003-05-31 15:27:17 +08:00
|
|
|
} else {
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "%" << TM.getRegInfo()->getUnifiedRegName(regNum);
|
2003-05-31 15:27:17 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-10-29 05:38:52 +08:00
|
|
|
|
2003-11-08 01:45:28 +08:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
{
|
2004-08-18 13:29:08 +08:00
|
|
|
O << ".CPI_" << CurrentFnName << "_" << mop.getConstantPoolIndex();
|
2003-11-08 01:45:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-31 15:27:17 +08:00
|
|
|
case MachineOperand::MO_PCRelativeDisp:
|
|
|
|
{
|
|
|
|
const Value *Val = mop.getVRegValue();
|
2004-02-26 02:44:15 +08:00
|
|
|
assert(Val && "\tNULL Value in SparcV9AsmPrinter");
|
2002-05-19 23:25:51 +08:00
|
|
|
|
2003-07-23 23:30:06 +08:00
|
|
|
if (const BasicBlock *BB = dyn_cast<BasicBlock>(Val))
|
2004-08-18 13:29:08 +08:00
|
|
|
O << getID(BB);
|
2004-05-05 05:09:02 +08:00
|
|
|
else if (const Function *F = dyn_cast<Function>(Val))
|
2004-08-18 13:29:08 +08:00
|
|
|
O << getID(F);
|
2003-05-31 15:27:17 +08:00
|
|
|
else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Val))
|
2004-08-18 13:29:08 +08:00
|
|
|
O << getID(GV);
|
2003-05-31 15:27:17 +08:00
|
|
|
else if (const Constant *CV = dyn_cast<Constant>(Val))
|
2004-08-18 13:29:08 +08:00
|
|
|
O << getID(CV);
|
2003-05-31 15:27:17 +08:00
|
|
|
else
|
2004-02-26 02:44:15 +08:00
|
|
|
assert(0 && "Unrecognized value in SparcV9AsmPrinter");
|
2003-05-31 15:27:17 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-10-29 05:38:52 +08:00
|
|
|
|
2003-05-31 15:27:17 +08:00
|
|
|
case MachineOperand::MO_SignExtendedImmed:
|
2004-08-18 13:29:08 +08:00
|
|
|
O << mop.getImmedValue();
|
2003-05-31 15:27:17 +08:00
|
|
|
break;
|
2002-05-19 23:25:51 +08:00
|
|
|
|
2003-05-31 15:27:17 +08:00
|
|
|
case MachineOperand::MO_UnextendedImmed:
|
2004-08-18 13:29:08 +08:00
|
|
|
O << (uint64_t) mop.getImmedValue();
|
2003-05-31 15:27:17 +08:00
|
|
|
break;
|
2001-10-29 05:38:52 +08:00
|
|
|
|
2003-05-31 15:27:17 +08:00
|
|
|
default:
|
2004-08-18 13:29:08 +08:00
|
|
|
O << mop; // use dump field
|
2003-05-31 15:27:17 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-07-11 05:41:21 +08:00
|
|
|
|
|
|
|
if (needBitsFlag)
|
2004-08-18 13:29:08 +08:00
|
|
|
O << ")";
|
2001-10-29 05:38:52 +08:00
|
|
|
}
|
2001-10-25 06:05:34 +08:00
|
|
|
|
2004-02-26 02:44:15 +08:00
|
|
|
void SparcV9AsmPrinter::emitMachineInst(const MachineInstr *MI) {
|
2004-02-12 04:47:34 +08:00
|
|
|
unsigned Opcode = MI->getOpcode();
|
2001-10-25 06:05:34 +08:00
|
|
|
|
2004-08-19 04:04:24 +08:00
|
|
|
if (Opcode == V9::PHI)
|
|
|
|
return; // Ignore Machine-PHI nodes.
|
2001-10-25 06:05:34 +08:00
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\t" << TM.getInstrInfo()->getName(Opcode) << "\t";
|
2001-10-25 06:05:34 +08:00
|
|
|
|
2001-09-19 21:47:27 +08:00
|
|
|
unsigned Mask = getOperandMask(Opcode);
|
2001-10-29 05:38:52 +08:00
|
|
|
|
2001-09-19 21:47:27 +08:00
|
|
|
bool NeedComma = false;
|
2001-10-29 05:38:52 +08:00
|
|
|
unsigned N = 1;
|
|
|
|
for (unsigned OpNum = 0; OpNum < MI->getNumOperands(); OpNum += N)
|
|
|
|
if (! ((1 << OpNum) & Mask)) { // Ignore this operand?
|
2004-08-18 13:29:08 +08:00
|
|
|
if (NeedComma) O << ", "; // Handle comma outputting
|
2001-10-29 05:38:52 +08:00
|
|
|
NeedComma = true;
|
|
|
|
N = printOperands(MI, OpNum);
|
2002-11-18 06:57:23 +08:00
|
|
|
} else
|
|
|
|
N = 1;
|
2001-10-29 05:38:52 +08:00
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\n";
|
2003-10-06 23:41:21 +08:00
|
|
|
++EmittedInsts;
|
2001-09-19 21:47:27 +08:00
|
|
|
}
|
|
|
|
|
2004-02-26 02:44:15 +08:00
|
|
|
void SparcV9AsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
|
2001-09-19 21:47:27 +08:00
|
|
|
// Emit a label for the basic block
|
2004-08-18 13:29:08 +08:00
|
|
|
O << getID(MBB.getBasicBlock()) << ":\n";
|
2001-09-19 21:47:27 +08:00
|
|
|
|
|
|
|
// Loop over all of the instructions in the basic block...
|
2002-10-29 04:01:13 +08:00
|
|
|
for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
|
2002-10-28 09:41:47 +08:00
|
|
|
MII != MIE; ++MII)
|
2004-02-12 10:27:10 +08:00
|
|
|
emitMachineInst(MII);
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\n"; // Separate BB's with newlines
|
2001-09-19 21:47:27 +08:00
|
|
|
}
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
void SparcV9AsmPrinter::emitFunction(MachineFunction &MF) {
|
|
|
|
O << "!****** Outputing Function: " << CurrentFnName << " ******\n";
|
2003-11-08 01:45:28 +08:00
|
|
|
|
|
|
|
// Emit constant pool for this function
|
2004-08-18 13:29:08 +08:00
|
|
|
const MachineConstantPool *MCP = MF.getConstantPool();
|
2003-11-08 01:45:28 +08:00
|
|
|
const std::vector<Constant*> &CP = MCP->getConstants();
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
enterSection(ReadOnlyData);
|
2003-11-08 01:45:28 +08:00
|
|
|
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
2004-08-18 13:29:08 +08:00
|
|
|
std::string cpiName = ".CPI_" + CurrentFnName + "_" + utostr(i);
|
2003-11-08 01:45:28 +08:00
|
|
|
printConstant(CP[i], cpiName);
|
|
|
|
}
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
enterSection(Text);
|
|
|
|
O << "\t.align\t4\n\t.global\t" << CurrentFnName << "\n";
|
|
|
|
//O << "\t.type\t" << CurrentFnName << ",#function\n";
|
|
|
|
O << "\t.type\t" << CurrentFnName << ", 2\n";
|
|
|
|
O << CurrentFnName << ":\n";
|
2001-09-19 21:47:27 +08:00
|
|
|
|
2002-04-08 04:49:59 +08:00
|
|
|
// Output code for all of the basic blocks in the function...
|
2002-12-29 04:15:01 +08:00
|
|
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E;++I)
|
2002-10-29 04:01:13 +08:00
|
|
|
emitBasicBlock(*I);
|
2001-09-19 21:47:27 +08:00
|
|
|
|
|
|
|
// Output a .size directive so the debugger knows the extents of the function
|
2004-08-18 13:29:08 +08:00
|
|
|
O << ".EndOf_" << CurrentFnName << ":\n\t.size "
|
|
|
|
<< CurrentFnName << ", .EndOf_"
|
|
|
|
<< CurrentFnName << "-" << CurrentFnName << "\n";
|
2001-09-19 21:47:27 +08:00
|
|
|
|
2002-04-08 04:49:59 +08:00
|
|
|
// Put some spaces between the functions
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\n\n";
|
2002-02-04 07:41:08 +08:00
|
|
|
}
|
2001-09-19 21:47:27 +08:00
|
|
|
|
2004-02-26 02:44:15 +08:00
|
|
|
void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
|
2002-09-16 23:54:02 +08:00
|
|
|
if (GV->hasExternalLinkage())
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\t.global\t" << getID(GV) << "\n";
|
2001-10-29 05:38:52 +08:00
|
|
|
|
2003-11-13 08:22:19 +08:00
|
|
|
if (GV->hasInitializer() && ! GV->getInitializer()->isNullValue()) {
|
2001-10-29 05:38:52 +08:00
|
|
|
printConstant(GV->getInitializer(), getID(GV));
|
2003-11-13 08:22:19 +08:00
|
|
|
} else {
|
2004-08-18 13:29:08 +08:00
|
|
|
const Type *ValTy = GV->getType()->getElementType();
|
|
|
|
emitAlignment(TM.getTargetData().getTypeAlignmentShift(ValTy));
|
|
|
|
O << "\t.type\t" << getID(GV) << ",#object\n";
|
|
|
|
O << "\t.reserve\t" << getID(GV) << ","
|
|
|
|
<< TM.getTargetData().getTypeSize(GV->getType()->getElementType())
|
|
|
|
<< "\n";
|
2001-10-29 05:38:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-26 02:44:15 +08:00
|
|
|
void SparcV9AsmPrinter::emitGlobals(const Module &M) {
|
2002-08-08 05:39:48 +08:00
|
|
|
// Output global variables...
|
2002-10-13 08:32:18 +08:00
|
|
|
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI)
|
|
|
|
if (! GI->isExternal()) {
|
|
|
|
assert(GI->hasInitializer());
|
|
|
|
if (GI->isConstant())
|
2004-08-18 13:29:08 +08:00
|
|
|
enterSection(ReadOnlyData); // read-only, initialized data
|
2002-10-13 08:32:18 +08:00
|
|
|
else if (GI->getInitializer()->isNullValue())
|
2004-08-18 13:29:08 +08:00
|
|
|
enterSection(ZeroInitRWData); // read-write zero data
|
2002-10-13 08:32:18 +08:00
|
|
|
else
|
2004-08-18 13:29:08 +08:00
|
|
|
enterSection(InitRWData); // read-write non-zero data
|
2002-10-13 08:32:18 +08:00
|
|
|
|
|
|
|
printGlobalVariable(GI);
|
2002-08-08 05:39:48 +08:00
|
|
|
}
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
O << "\n";
|
2001-10-29 05:38:52 +08:00
|
|
|
}
|
|
|
|
|
2004-08-18 13:29:08 +08:00
|
|
|
FunctionPass *llvm::createAsmPrinterPass(std::ostream &Out, TargetMachine &TM) {
|
2004-02-26 02:44:15 +08:00
|
|
|
return new SparcV9AsmPrinter(Out, TM);
|
2001-09-19 21:47:27 +08:00
|
|
|
}
|