Support printing base+offset pairs where the offset is a register.

Use this for printing the jmpl indirect-call instruction.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14224 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Brian Gaeke
2004-06-18 06:27:59 +00:00
parent 9d67ea0b61
commit ceb224148e
2 changed files with 50 additions and 20 deletions

View File

@@ -69,7 +69,7 @@ namespace {
void emitGlobalConstant(const Constant *CV); void emitGlobalConstant(const Constant *CV);
void printConstantPool(MachineConstantPool *MCP); void printConstantPool(MachineConstantPool *MCP);
void printOperand(const MachineInstr *MI, int opNum); void printOperand(const MachineInstr *MI, int opNum);
void printBaseOffsetPair (const MachineInstr *MI, int i); void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true);
void printMachineInstruction(const MachineInstr *MI); void printMachineInstruction(const MachineInstr *MI);
bool runOnMachineFunction(MachineFunction &F); bool runOnMachineFunction(MachineFunction &F);
bool doInitialization(Module &M); bool doInitialization(Module &M);
@@ -455,17 +455,26 @@ static bool isStoreInstruction (const MachineInstr *MI) {
} }
} }
void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i) { /// printBaseOffsetPair - Print two consecutive operands of MI, starting at #i,
O << "["; /// which form a base + offset pair (which may have brackets around it, if
/// brackets is true, or may be in the form base - constant, if offset is a
/// negative constant).
///
void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i,
bool brackets) {
if (brackets) O << "[";
printOperand (MI, i); printOperand (MI, i);
assert (MI->getOperand (i + 1).isImmediate() if (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 (); int Val = (int) MI->getOperand (i + 1).getImmedValue ();
if (Val != 0) { if (Val != 0) {
O << ((Val >= 0) ? " + " : " - "); O << ((Val >= 0) ? " + " : " - ");
O << ((Val >= 0) ? Val : -Val); O << ((Val >= 0) ? Val : -Val);
} }
O << "]"; } else {
O << " + ";
printOperand (MI, i + 1);
}
if (brackets) O << "]";
} }
/// printMachineInstruction -- Print out a single SparcV8 LLVM instruction /// printMachineInstruction -- Print out a single SparcV8 LLVM instruction
@@ -492,6 +501,12 @@ void V8Printer::printMachineInstruction(const MachineInstr *MI) {
printBaseOffsetPair (MI, 0); printBaseOffsetPair (MI, 0);
O << "\n"; O << "\n";
return; return;
} else if (Opcode == V8::JMPLrr) {
printBaseOffsetPair (MI, 1, false);
O << ", ";
printOperand (MI, 0);
O << "\n";
return;
} }
// print non-immediate, non-register-def operands // print non-immediate, non-register-def operands

View File

@@ -69,7 +69,7 @@ namespace {
void emitGlobalConstant(const Constant *CV); void emitGlobalConstant(const Constant *CV);
void printConstantPool(MachineConstantPool *MCP); void printConstantPool(MachineConstantPool *MCP);
void printOperand(const MachineInstr *MI, int opNum); void printOperand(const MachineInstr *MI, int opNum);
void printBaseOffsetPair (const MachineInstr *MI, int i); void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true);
void printMachineInstruction(const MachineInstr *MI); void printMachineInstruction(const MachineInstr *MI);
bool runOnMachineFunction(MachineFunction &F); bool runOnMachineFunction(MachineFunction &F);
bool doInitialization(Module &M); bool doInitialization(Module &M);
@@ -455,17 +455,26 @@ static bool isStoreInstruction (const MachineInstr *MI) {
} }
} }
void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i) { /// printBaseOffsetPair - Print two consecutive operands of MI, starting at #i,
O << "["; /// which form a base + offset pair (which may have brackets around it, if
/// brackets is true, or may be in the form base - constant, if offset is a
/// negative constant).
///
void V8Printer::printBaseOffsetPair (const MachineInstr *MI, int i,
bool brackets) {
if (brackets) O << "[";
printOperand (MI, i); printOperand (MI, i);
assert (MI->getOperand (i + 1).isImmediate() if (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 (); int Val = (int) MI->getOperand (i + 1).getImmedValue ();
if (Val != 0) { if (Val != 0) {
O << ((Val >= 0) ? " + " : " - "); O << ((Val >= 0) ? " + " : " - ");
O << ((Val >= 0) ? Val : -Val); O << ((Val >= 0) ? Val : -Val);
} }
O << "]"; } else {
O << " + ";
printOperand (MI, i + 1);
}
if (brackets) O << "]";
} }
/// printMachineInstruction -- Print out a single SparcV8 LLVM instruction /// printMachineInstruction -- Print out a single SparcV8 LLVM instruction
@@ -492,6 +501,12 @@ void V8Printer::printMachineInstruction(const MachineInstr *MI) {
printBaseOffsetPair (MI, 0); printBaseOffsetPair (MI, 0);
O << "\n"; O << "\n";
return; return;
} else if (Opcode == V8::JMPLrr) {
printBaseOffsetPair (MI, 1, false);
O << ", ";
printOperand (MI, 0);
O << "\n";
return;
} }
// print non-immediate, non-register-def operands // print non-immediate, non-register-def operands