aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/Sparc
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2004-04-06 22:10:11 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2004-04-06 22:10:11 +0000
commit1c38175d6b7978768645fac271db435bef337a13 (patch)
treea3896fd6244acf86a5a3d0679943a71fb203e94c /lib/Target/Sparc
parent856e4fc59ee13c84150dbef4e46795ca7883504e (diff)
First attempt at special-casing printing of [%reg + offset] for
ld/st instructions - doesn't seem to work yet, but I think it's just a typo or something somewhere. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12727 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/Sparc')
-rw-r--r--lib/Target/Sparc/SparcAsmPrinter.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp
index 7305031a19..71a797105f 100644
--- a/lib/Target/Sparc/SparcAsmPrinter.cpp
+++ b/lib/Target/Sparc/SparcAsmPrinter.cpp
@@ -69,6 +69,7 @@ namespace {
void emitGlobalConstant(const Constant *CV);
void printConstantPool(MachineConstantPool *MCP);
void printOperand(const MachineOperand &MI);
+ void printBaseOffsetPair (const MachineInstr *MI, int i);
void printMachineInstruction(const MachineInstr *MI);
bool runOnMachineFunction(MachineFunction &F);
bool doInitialization(Module &M);
@@ -419,6 +420,43 @@ void V8Printer::printOperand(const MachineOperand &MO) {
}
}
+static bool isLoadInstruction (const MachineInstr *MI) {
+ switch (MI->getOpcode ()) {
+ case V8::LDSBmr:
+ case V8::LDSHmr:
+ case V8::LDUBmr:
+ case V8::LDUHmr:
+ case V8::LDmr:
+ case V8::LDDmr:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool isStoreInstruction (const MachineInstr *MI) {
+ switch (MI->getOpcode ()) {
+ case V8::STBrm:
+ case V8::STHrm:
+ case V8::STrm:
+ case V8::STDrm:
+ return true;
+ default:
+ return false;
+ }
+}
+
+void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i) {
+ O << "[";
+ printOperand (MI->getOperand (i));
+ assert (MI->getOperand (i + 1).isImmediate()
+ && "2nd half of base-offset pair must be immediate-value machine operand");
+ int Val = (int) MI->getOperand (i + 1).getImmedValue ();
+ O << ((Val >= 0) ? " + " : " - ");
+ O << ((Val >= 0) ? Val : -Val);
+ O << "]";
+}
+
/// printMachineInstruction -- Print out a single SparcV8 LLVM instruction
/// MI in GAS syntax to the current output stream.
///
@@ -428,6 +466,23 @@ void V8Printer::printMachineInstruction(const MachineInstr *MI) {
const TargetInstrDescriptor &Desc = TII.get(Opcode);
O << Desc.Name << " ";
+ // Printing memory instructions is a special case.
+ // for loads: op %base, offset, %dest --> op [%base + offset], %dest
+ // for stores: op %src, %base, offset --> op %src, [%base + offset]
+ if (isLoadInstruction (MI)) {
+ printBaseOffsetPair (MI, 0);
+ O << ", ";
+ printOperand (MI->getOperand (2));
+ O << "\n";
+ return;
+ } else if (isStoreInstruction (MI)) {
+ printOperand (MI->getOperand (0));
+ O << ", ";
+ printBaseOffsetPair (MI, 1);
+ O << "\n";
+ return;
+ }
+
// print non-immediate, non-register-def operands
// then print immediate operands
// then print register-def operands.