mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 22:28:18 +00:00
Add support to print constant arrays and structures.
Align data larger than an L1 cache line on L1 cache line boundary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1228 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -59,7 +59,8 @@ private :
|
|||||||
void emitMachineInst(const MachineInstr *MI);
|
void emitMachineInst(const MachineInstr *MI);
|
||||||
|
|
||||||
void printGlobalVariable(const GlobalVariable* GV);
|
void printGlobalVariable(const GlobalVariable* GV);
|
||||||
void printConstant(const ConstPoolVal* CV, string valID = string(""));
|
void printSingleConstant(const ConstPoolVal* CV, string valID = string(""));
|
||||||
|
void printConstant( const ConstPoolVal* CV, string valID = string(""));
|
||||||
|
|
||||||
unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
|
unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
|
||||||
void printOneOperand(const MachineOperand &Op);
|
void printOneOperand(const MachineOperand &Op);
|
||||||
@@ -187,8 +188,9 @@ SparcAsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
|
|||||||
|
|
||||||
|
|
||||||
#define PrintOp1PlusOp2(Op1, Op2) \
|
#define PrintOp1PlusOp2(Op1, Op2) \
|
||||||
printOneOperand(Op1); toAsm << "+"; printOneOperand(Op2);
|
printOneOperand(Op1); \
|
||||||
|
toAsm << "+"; \
|
||||||
|
printOneOperand(Op2);
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
SparcAsmPrinter::printOperands(const MachineInstr *MI,
|
SparcAsmPrinter::printOperands(const MachineInstr *MI,
|
||||||
@@ -347,7 +349,8 @@ ArrayTypeIsString(ArrayType* arrayType)
|
|||||||
arrayType->getElementType() == Type::SByteTy);
|
arrayType->getElementType() == Type::SByteTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const string TypeToDataDirective(const Type* type)
|
inline const string
|
||||||
|
TypeToDataDirective(const Type* type)
|
||||||
{
|
{
|
||||||
switch(type->getPrimitiveID())
|
switch(type->getPrimitiveID())
|
||||||
{
|
{
|
||||||
@@ -373,8 +376,9 @@ inline const string TypeToDataDirective(const Type* type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned int ConstantToSize(const ConstPoolVal* CV,
|
inline unsigned int
|
||||||
const TargetMachine& target) {
|
ConstantToSize(const ConstPoolVal* CV, const TargetMachine& target)
|
||||||
|
{
|
||||||
if (ConstPoolArray* AV = dyn_cast<ConstPoolArray>(CV))
|
if (ConstPoolArray* AV = dyn_cast<ConstPoolArray>(CV))
|
||||||
if (ArrayTypeIsString((ArrayType*) CV->getType()))
|
if (ArrayTypeIsString((ArrayType*) CV->getType()))
|
||||||
return 1 + AV->getNumOperands();
|
return 1 + AV->getNumOperands();
|
||||||
@@ -390,19 +394,25 @@ unsigned int TypeToSize(const Type* type, const TargetMachine& target)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Align data larger than one L1 cache line on L1 cache line boundaries.
|
||||||
|
// Align all smaller types on the next higher 2^x boundary (4, 8, ...).
|
||||||
|
//
|
||||||
inline unsigned int
|
inline unsigned int
|
||||||
TypeToAlignment(const Type* type, const TargetMachine& target)
|
TypeToAlignment(const Type* type, const TargetMachine& target)
|
||||||
{
|
{
|
||||||
if (type->getPrimitiveID() == Type::ArrayTyID &&
|
unsigned int typeSize = target.findOptimalStorageSize(type);
|
||||||
ArrayTypeIsString((ArrayType*) type))
|
unsigned short cacheLineSize = target.getCacheInfo().getCacheLineSize(1);
|
||||||
return target.findOptimalStorageSize(Type::LongTy);
|
if (typeSize > (int) cacheLineSize / 2)
|
||||||
|
return cacheLineSize;
|
||||||
return target.findOptimalStorageSize(type);
|
else
|
||||||
|
for (unsigned sz=1; /*no condition*/; sz *= 2)
|
||||||
|
if (sz >= typeSize)
|
||||||
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SparcAsmPrinter::printConstant(const ConstPoolVal* CV, string valID)
|
SparcAsmPrinter::printSingleConstant(const ConstPoolVal* CV,string valID)
|
||||||
{
|
{
|
||||||
if (valID.length() == 0)
|
if (valID.length() == 0)
|
||||||
valID = getID(CV);
|
valID = getID(CV);
|
||||||
@@ -412,21 +422,12 @@ SparcAsmPrinter::printConstant(const ConstPoolVal* CV, string valID)
|
|||||||
CV->getType() != Type::LabelTy &&
|
CV->getType() != Type::LabelTy &&
|
||||||
"Unexpected type for ConstPoolVal");
|
"Unexpected type for ConstPoolVal");
|
||||||
|
|
||||||
toAsm << "\t.align\t" << TypeToAlignment(CV->getType(), Target)
|
assert((! isa<ConstPoolArray>( CV) && ! isa<ConstPoolStruct>(CV))
|
||||||
<< endl;
|
&& "Collective types should be handled outside this function");
|
||||||
|
|
||||||
toAsm << valID << ":" << endl;
|
|
||||||
|
|
||||||
toAsm << "\t"
|
toAsm << "\t"
|
||||||
<< TypeToDataDirective(CV->getType()) << "\t";
|
<< TypeToDataDirective(CV->getType()) << "\t";
|
||||||
|
|
||||||
if (ConstPoolArray *CPA = dyn_cast<ConstPoolArray>(CV))
|
|
||||||
if (isStringCompatible(CPA))
|
|
||||||
{
|
|
||||||
toAsm << getAsCString(CPA) << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CV->getType()->isPrimitiveType())
|
if (CV->getType()->isPrimitiveType())
|
||||||
{
|
{
|
||||||
if (CV->getType() == Type::FloatTy || CV->getType() == Type::DoubleTy)
|
if (CV->getType() == Type::FloatTy || CV->getType() == Type::DoubleTy)
|
||||||
@@ -446,13 +447,54 @@ SparcAsmPrinter::printConstant(const ConstPoolVal* CV, string valID)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(0 && "Cannot yet print non-primitive constants to assembly");
|
assert(0 && "Unknown elementary type for constant");
|
||||||
// toAsm << CV->getStrValue() << endl;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SparcAsmPrinter::printConstant(const ConstPoolVal* CV, string valID)
|
||||||
|
{
|
||||||
|
if (valID.length() == 0)
|
||||||
|
valID = getID(CV);
|
||||||
|
|
||||||
|
assert(CV->getType() != Type::VoidTy &&
|
||||||
|
CV->getType() != Type::TypeTy &&
|
||||||
|
CV->getType() != Type::LabelTy &&
|
||||||
|
"Unexpected type for ConstPoolVal");
|
||||||
|
|
||||||
|
toAsm << "\t.align\t" << TypeToAlignment(CV->getType(), Target)
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
// Print .size and .type only if it is not a string.
|
||||||
|
ConstPoolArray *CPA = dyn_cast<ConstPoolArray>(CV);
|
||||||
|
|
||||||
|
if (CPA && isStringCompatible(CPA))
|
||||||
|
{ // print it as a string and return
|
||||||
|
toAsm << valID << ":" << endl;
|
||||||
|
toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t"
|
||||||
|
<< getAsCString(CPA) << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
toAsm << "\t.type" << "\t" << valID << ",#object" << endl;
|
toAsm << "\t.type" << "\t" << valID << ",#object" << endl;
|
||||||
toAsm << "\t.size" << "\t" << valID << ","
|
toAsm << "\t.size" << "\t" << valID << ","
|
||||||
<< ConstantToSize(CV, Target) << endl;
|
<< ConstantToSize(CV, Target) << endl;
|
||||||
|
toAsm << valID << ":" << endl;
|
||||||
|
|
||||||
|
if (CPA)
|
||||||
|
{ // Not a string. Print the values in successive locations
|
||||||
|
const vector<Use>& constValues = CPA->getValues();
|
||||||
|
for (unsigned i=1; i < constValues.size(); i++)
|
||||||
|
this->printSingleConstant(cast<ConstPoolVal>(constValues[i].get()));
|
||||||
|
}
|
||||||
|
else if (ConstPoolStruct *CPS = dyn_cast<ConstPoolStruct>(CV))
|
||||||
|
{ // Print the fields in successive locations
|
||||||
|
const vector<Use>& constValues = CPA->getValues();
|
||||||
|
for (unsigned i=1; i < constValues.size(); i++)
|
||||||
|
this->printSingleConstant(cast<ConstPoolVal>(constValues[i].get()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this->printSingleConstant(CV, valID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user