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

olden programs working.

llvm-svn: 80881
This commit is contained in:
Chris Lattner 2009-09-03 04:44:53 +00:00
parent 47455a79ae
commit 5daf61910e
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. // New MCInst printing stuff.
void printInstruction(const MCInst *MI); void printInstruction(const MCInst *MI);
MCSymbol *GetPICBaseSymbol(); MCSymbol *GetPICBaseSymbol();
MCOperand LowerJumpTableOperand(const MachineOperand &MO);
MCOperand LowerGlobalAddressOperand(const MachineOperand &MO); MCOperand LowerGlobalAddressOperand(const MachineOperand &MO);
MCOperand LowerExternalSymbolOperand(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); } virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }

View File

@ -169,6 +169,8 @@ MCOperand X86ATTAsmPrinter::LowerJumpTableOperand(const MachineOperand &MO) {
switch (MO.getTargetFlags()) { switch (MO.getTargetFlags()) {
default: default:
llvm_unreachable("Unknown target flag on GV operand"); 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_PIC_BASE_OFFSET:
case X86II::MO_DARWIN_NONLAZY_PIC_BASE: case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
@ -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:: void X86ATTAsmPrinter::
printInstructionThroughMCStreamer(const MachineInstr *MI) { printInstructionThroughMCStreamer(const MachineInstr *MI) {
@ -246,9 +280,6 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
O.flush(); O.flush();
errs() << "Cannot lower operand #" << i << " of :" << *MI; errs() << "Cannot lower operand #" << i << " of :" << *MI;
llvm_unreachable("Unimp"); llvm_unreachable("Unimp");
case MachineOperand::MO_JumpTableIndex:
MCOp = LowerJumpTableOperand(MO);
break;
case MachineOperand::MO_Register: case MachineOperand::MO_Register:
MCOp = MCOperand::CreateReg(MO.getReg()); MCOp = MCOperand::CreateReg(MO.getReg());
break; break;
@ -265,6 +296,12 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
case MachineOperand::MO_ExternalSymbol: case MachineOperand::MO_ExternalSymbol:
MCOp = LowerExternalSymbolOperand(MO); MCOp = LowerExternalSymbolOperand(MO);
break; break;
case MachineOperand::MO_JumpTableIndex:
MCOp = LowerJumpTableOperand(MO);
break;
case MachineOperand::MO_ConstantPoolIndex:
MCOp = LowerConstantPoolIndexOperand(MO);
break;
} }
TmpInst.addOperand(MCOp); TmpInst.addOperand(MCOp);