implement lowering support for constant pool index operands, this gets a bunch more

olden programs working.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80881 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-09-03 04:44:53 +00:00
parent d0da6ff3ad
commit 118c27c6d4
2 changed files with 52 additions and 13 deletions

View File

@ -71,9 +71,11 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
// New MCInst printing stuff.
void printInstruction(const MCInst *MI);
MCSymbol *GetPICBaseSymbol();
MCOperand LowerJumpTableOperand(const MachineOperand &MO);
MCOperand LowerGlobalAddressOperand(const MachineOperand &MO);
MCOperand LowerExternalSymbolOperand(const MachineOperand &MO);
MCOperand LowerJumpTableOperand(const MachineOperand &MO);
MCOperand LowerConstantPoolIndexOperand(const MachineOperand &MO);
virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }

View File

@ -163,18 +163,20 @@ LowerExternalSymbolOperand(const MachineOperand &MO) {
MCOperand X86ATTAsmPrinter::LowerJumpTableOperand(const MachineOperand &MO) {
SmallString<256> Name;
raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "JTI"
<< getFunctionNumber() << '_' << MO.getIndex();
<< getFunctionNumber() << '_' << MO.getIndex();
MCSymbol *NegatedSymbol = 0;
switch (MO.getTargetFlags()) {
default:
llvm_unreachable("Unknown target flag on GV operand");
case X86II::MO_PIC_BASE_OFFSET:
case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
// Subtract the pic base.
NegatedSymbol = GetPICBaseSymbol();
break;
default:
llvm_unreachable("Unknown target flag on GV operand");
case X86II::MO_NO_FLAG: // No flag.
break;
case X86II::MO_PIC_BASE_OFFSET:
case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
// Subtract the pic base.
NegatedSymbol = GetPICBaseSymbol();
break;
}
// Create a symbol for the name.
@ -190,6 +192,38 @@ MCOperand X86ATTAsmPrinter::LowerJumpTableOperand(const MachineOperand &MO) {
}
MCOperand X86ATTAsmPrinter::
LowerConstantPoolIndexOperand(const MachineOperand &MO) {
SmallString<256> Name;
raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "CPI"
<< getFunctionNumber() << '_' << MO.getIndex();
MCSymbol *NegatedSymbol = 0;
switch (MO.getTargetFlags()) {
default:
llvm_unreachable("Unknown target flag on GV operand");
case X86II::MO_NO_FLAG: // No flag.
break;
case X86II::MO_PIC_BASE_OFFSET:
case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
// Subtract the pic base.
NegatedSymbol = GetPICBaseSymbol();
break;
}
// Create a symbol for the name.
MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name.str());
// FIXME: We would like an efficient form for this, so we don't have to do a
// lot of extra uniquing.
const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, OutContext);
if (NegatedSymbol)
Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(NegatedSymbol,
OutContext),
OutContext);
return MCOperand::CreateExpr(Expr);
}
void X86ATTAsmPrinter::
printInstructionThroughMCStreamer(const MachineInstr *MI) {
@ -246,9 +280,6 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
O.flush();
errs() << "Cannot lower operand #" << i << " of :" << *MI;
llvm_unreachable("Unimp");
case MachineOperand::MO_JumpTableIndex:
MCOp = LowerJumpTableOperand(MO);
break;
case MachineOperand::MO_Register:
MCOp = MCOperand::CreateReg(MO.getReg());
break;
@ -265,6 +296,12 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
case MachineOperand::MO_ExternalSymbol:
MCOp = LowerExternalSymbolOperand(MO);
break;
case MachineOperand::MO_JumpTableIndex:
MCOp = LowerJumpTableOperand(MO);
break;
case MachineOperand::MO_ConstantPoolIndex:
MCOp = LowerConstantPoolIndexOperand(MO);
break;
}
TmpInst.addOperand(MCOp);