-//===-- EmitAssembly.cpp - Emit Sparc Specific .s File ---------------------==//
+//===-- EmitAssembly.cpp - Emit SparcV9 Specific .s File -------------------==//
//
// The LLVM Compiler Infrastructure
//
#include "llvm/Support/Mangler.h"
#include "Support/StringExtras.h"
#include "Support/Statistic.h"
-#include "SparcInternals.h"
+#include "SparcV9Internals.h"
#include <string>
using namespace llvm;
arrayType->getElementType() == Type::SByteTy);
}
+ unsigned findOptimalStorageSize(const TargetMachine &TM, const Type *Ty) {
+ // All integer types smaller than ints promote to 4 byte integers.
+ if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4)
+ return 4;
+
+ return TM.getTargetData().getTypeSize(Ty);
+ }
+
+
inline const std::string
TypeToDataDirective(const Type* type) {
- switch(type->getPrimitiveID())
- {
+ switch(type->getTypeID()) {
case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID:
return ".byte";
case Type::UShortTyID: case Type::ShortTyID:
return 1 + CVA->getNumOperands();
}
- return target.findOptimalStorageSize(CV->getType());
+ return findOptimalStorageSize(target, CV->getType());
}
/// Align data larger than one L1 cache line on L1 cache line boundaries.
///
inline unsigned int
SizeToAlignment(unsigned int size, const TargetMachine& target) {
- unsigned short cacheLineSize = target.getCacheInfo().getCacheLineSize(1);
+ const unsigned short cacheLineSize = 16;
if (size > (unsigned) cacheLineSize / 2)
return cacheLineSize;
else
///
inline unsigned int
TypeToAlignment(const Type* type, const TargetMachine& target) {
- return SizeToAlignment(target.findOptimalStorageSize(type), target);
+ return SizeToAlignment(findOptimalStorageSize(target, type), target);
}
/// Get the size of the constant and then use SizeToAlignment.
}
// getID Wrappers - Ensure consistent usage
- // Symbol names in Sparc assembly language have these rules:
+ // Symbol names in SparcV9 assembly language have these rules:
// (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
// (b) A name beginning in "." is treated as a local name.
std::string getID(const Function *F) {
///
void AsmPrinter::printSingleConstantValue(const Constant* CV) {
assert(CV->getType() != Type::VoidTy &&
- CV->getType() != Type::TypeTy &&
CV->getType() != Type::LabelTy &&
"Unexpected type for Constant");
toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
- if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(CV)) {
- // This is a constant address for a global variable or method.
- // Use the name of the variable or method as the address value.
- assert(isa<GlobalValue>(CPR->getValue()) && "Unexpected non-global");
- toAsm << getID(CPR->getValue()) << "\n";
+ if (const GlobalValue* GV = dyn_cast<GlobalValue>(CV)) {
+ toAsm << getID(GV) << "\n";
} else if (isa<ConstantPointerNull>(CV)) {
// Null pointer value
toAsm << "0\n";
toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
} else {
// Not a string. Print the values in successive locations
- const std::vector<Use> &constValues = CVA->getValues();
- for (unsigned i=0; i < constValues.size(); i++)
- printConstantValueOnly(cast<Constant>(constValues[i].get()));
+ for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
+ printConstantValueOnly(CVA->getOperand(i));
}
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
// Print the fields in successive locations. Pad to align if needed!
const StructLayout *cvsLayout =
Target.getTargetData().getStructLayout(CVS->getType());
- const std::vector<Use>& constValues = CVS->getValues();
unsigned sizeSoFar = 0;
- for (unsigned i=0, N = constValues.size(); i < N; i++) {
- const Constant* field = cast<Constant>(constValues[i].get());
+ for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
+ const Constant* field = CVS->getOperand(i);
// Check if padding is needed and insert one or more 0s.
unsigned fieldSize =
Target.getTargetData().getTypeSize(field->getType());
- int padSize = ((i == N-1? cvsLayout->StructSize
+ int padSize = ((i == e-1? cvsLayout->StructSize
: cvsLayout->MemberOffsets[i+1])
- cvsLayout->MemberOffsets[i]) - fieldSize;
sizeSoFar += (fieldSize + padSize);
const TargetMachine& target) {
std::string S;
bool failed = false;
- if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
+ if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
+ S += getID(GV);
+ } else if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
S += std::string(CB == ConstantBool::True ? "1" : "0");
else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
S += ftostr(CFP->getValue());
else if (isa<ConstantPointerNull>(CV))
S += "0";
- else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
- S += valToExprString(CPR->getValue(), target);
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
S += ConstantExprToString(CE, target);
else
failed = true;
- } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
- S += getID(GV);
} else
failed = true;
//===----------------------------------------------------------------------===//
-// SparcAsmPrinter Code
+// SparcV9AsmPrinter Code
//===----------------------------------------------------------------------===//
namespace {
- struct SparcAsmPrinter : public FunctionPass, public AsmPrinter {
- inline SparcAsmPrinter(std::ostream &os, const TargetMachine &t)
+ struct SparcV9AsmPrinter : public FunctionPass, public AsmPrinter {
+ inline SparcV9AsmPrinter(std::ostream &os, const TargetMachine &t)
: AsmPrinter(os, t) {}
const Function *currFunction;
const char *getPassName() const {
- return "Output Sparc Assembly for Functions";
+ return "Output SparcV9 Assembly for Functions";
}
virtual bool doInitialization(Module &M) {
} // End anonymous namespace
inline bool
-SparcAsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
+SparcV9AsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
unsigned int opNum) {
switch (MI->getOpcode()) {
case V9::JMPLCALLr:
}
inline bool
-SparcAsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
+SparcV9AsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
unsigned int opNum) {
- if (Target.getInstrInfo().isLoad(MI->getOpcode()))
+ if (Target.getInstrInfo()->isLoad(MI->getOpcode()))
return (opNum == 0);
- else if (Target.getInstrInfo().isStore(MI->getOpcode()))
+ else if (Target.getInstrInfo()->isStore(MI->getOpcode()))
return (opNum == 1);
else
return false;
printOneOperand(mop2, opCode);
unsigned int
-SparcAsmPrinter::printOperands(const MachineInstr *MI,
+SparcV9AsmPrinter::printOperands(const MachineInstr *MI,
unsigned int opNum)
{
const MachineOperand& mop = MI->getOperand(opNum);
}
void
-SparcAsmPrinter::printOneOperand(const MachineOperand &mop,
+SparcV9AsmPrinter::printOneOperand(const MachineOperand &mop,
MachineOpCode opCode)
{
bool needBitsFlag = true;
{
int regNum = (int)mop.getReg();
- if (regNum == Target.getRegInfo().getInvalidRegNum()) {
+ if (regNum == Target.getRegInfo()->getInvalidRegNum()) {
// better to print code with NULL registers than to die
toAsm << "<NULL VALUE>";
} else {
- toAsm << "%" << Target.getRegInfo().getUnifiedRegName(regNum);
+ toAsm << "%" << Target.getRegInfo()->getUnifiedRegName(regNum);
}
break;
}
case MachineOperand::MO_ConstantPoolIndex:
{
- toAsm << ".CPI_" << currFunction->getName()
+ toAsm << ".CPI_" << getID(currFunction)
<< "_" << mop.getConstantPoolIndex();
break;
}
case MachineOperand::MO_PCRelativeDisp:
{
const Value *Val = mop.getVRegValue();
- assert(Val && "\tNULL Value in SparcAsmPrinter");
+ assert(Val && "\tNULL Value in SparcV9AsmPrinter");
if (const BasicBlock *BB = dyn_cast<BasicBlock>(Val))
toAsm << getID(BB);
- else if (const Function *M = dyn_cast<Function>(Val))
- toAsm << getID(M);
+ else if (const Function *F = dyn_cast<Function>(Val))
+ toAsm << getID(F);
else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Val))
toAsm << getID(GV);
else if (const Constant *CV = dyn_cast<Constant>(Val))
toAsm << getID(CV);
else
- assert(0 && "Unrecognized value in SparcAsmPrinter");
+ assert(0 && "Unrecognized value in SparcV9AsmPrinter");
break;
}
toAsm << ")";
}
-void SparcAsmPrinter::emitMachineInst(const MachineInstr *MI) {
+void SparcV9AsmPrinter::emitMachineInst(const MachineInstr *MI) {
unsigned Opcode = MI->getOpcode();
- if (Target.getInstrInfo().isDummyPhiInstr(Opcode))
+ if (Target.getInstrInfo()->isDummyPhiInstr(Opcode))
return; // IGNORE PHI NODES
- toAsm << "\t" << Target.getInstrInfo().getName(Opcode) << "\t";
+ toAsm << "\t" << Target.getInstrInfo()->getName(Opcode) << "\t";
unsigned Mask = getOperandMask(Opcode);
++EmittedInsts;
}
-void SparcAsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
+void SparcV9AsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
// Emit a label for the basic block
toAsm << getID(MBB.getBasicBlock()) << ":\n";
toAsm << "\n"; // Separate BB's with newlines
}
-void SparcAsmPrinter::emitFunction(const Function &F) {
+void SparcV9AsmPrinter::emitFunction(const Function &F) {
std::string methName = getID(&F);
toAsm << "!****** Outputing Function: " << methName << " ******\n";
enterSection(AsmPrinter::ReadOnlyData);
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
- std::string cpiName = ".CPI_" + F.getName() + "_" + utostr(i);
+ std::string cpiName = ".CPI_" + methName + "_" + utostr(i);
printConstant(CP[i], cpiName);
}
toAsm << "\n\n";
}
-void SparcAsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
+void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
if (GV->hasExternalLinkage())
toAsm << "\t.global\t" << getID(GV) << "\n";
Target) << "\n";
toAsm << "\t.type\t" << getID(GV) << ",#object\n";
toAsm << "\t.reserve\t" << getID(GV) << ","
- << Target.findOptimalStorageSize(GV->getType()->getElementType())
+ << findOptimalStorageSize(Target, GV->getType()->getElementType())
<< "\n";
}
}
-void SparcAsmPrinter::emitGlobals(const Module &M) {
+void SparcV9AsmPrinter::emitGlobals(const Module &M) {
// Output global variables...
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI)
if (! GI->isExternal()) {
FunctionPass *llvm::createAsmPrinterPass(std::ostream &Out,
const TargetMachine &TM) {
- return new SparcAsmPrinter(Out, TM);
+ return new SparcV9AsmPrinter(Out, TM);
}