Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed jump tables.
  • Loading branch information
jpbonn committed Jun 17, 2011
1 parent 4ecac63 commit bec24ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/Target/Mico32/Mico32ISelLowering.cpp
Expand Up @@ -136,8 +136,6 @@ Mico32TargetLowering::Mico32TargetLowering(Mico32TargetMachine &TM)
setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
// FIXME: need to add this
// setOperationAction(ISD::JumpTable, MVT::i32, Custom);

// Variable Argument support
// Use custom implementation for VASTART.
Expand All @@ -148,8 +146,10 @@ Mico32TargetLowering::Mico32TargetLowering(Mico32TargetMachine &TM)
setOperationAction(ISD::VACOPY, MVT::Other, Expand);


// Mico32 does not have jump table branches.
// Mico32 does not have jump table branches...
setOperationAction(ISD::BR_JT, MVT::Other, Expand);
// ... so we have to lower the loads from the jump table.
setOperationAction(ISD::JumpTable, MVT::i32, Custom);
// Expand BR_CC to BRCOND.
setOperationAction(ISD::BR_CC, MVT::Other, Expand);

Expand Down Expand Up @@ -421,12 +421,29 @@ LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const {
return SDValue(); // Not reached
}

// Derived from PPC.
SDValue Mico32TargetLowering::
LowerJumpTable(SDValue Op, SelectionDAG &DAG) const {
llvm_unreachable("JumpTables not implemented for Mico32.");
return SDValue(); // Not reached
DEBUG(assert(Op.getValueType() == MVT::i32 && "pointers should be 32 bits."));
DebugLoc dl = Op.getDebugLoc();
JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), MVT::i32);
SDValue Hi = DAG.getNode(Mico32ISD::Hi, dl, MVT::i32, JTI);
SDValue Lo = DAG.getNode(Mico32ISD::Lo, dl, MVT::i32, JTI);

// We don't support non-static relo models yet.
if (DAG.getTarget().getRelocationModel() == Reloc::Static ) {
// Generate non-pic code that has direct accesses to the constant pool.
// The address of the global is just (hi(&g)+lo(&g)).
return DAG.getNode(ISD::OR, dl, MVT::i32, Lo, Hi);
} else {
llvm_unreachable("JumpTables are only supported in static mode");
}

return Op; // notreached
}


SDValue Mico32TargetLowering::
LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
{
Expand Down
14 changes: 14 additions & 0 deletions lib/Target/Mico32/Mico32InstrInfo.td
Expand Up @@ -600,6 +600,20 @@ def : Pat<(Mico32Lo tglobaladdr:$in), (ORIsym R0, tglobaladdr:$in)>;
def : Pat<(add GPR:$hi, (Mico32Lo tglobaladdr:$lo)),
(ADDIsym GPR:$hi, tglobaladdr:$lo)>;

// ISel custom lowering generates (Mico32Hi tconstpool:$in) and
// (Mico32Lo tconstpool:$in). We further lower them here:
def : Pat<(Mico32Hi tconstpool:$in), (ORHIsym R0, tconstpool:$in)>;
def : Pat<(Mico32Lo tconstpool:$in), (ORIsym R0, tconstpool:$in)>;
def : Pat<(add GPR:$hi, (Mico32Lo tconstpool:$lo)),
(ADDIsym GPR:$hi, tconstpool:$lo)>;

// ISel custom lowering generates (Mico32Hi tjumptable:$in) and
// (Mico32Lo tjumptable:$in). We further lower them here:
def : Pat<(Mico32Hi tjumptable:$in), (ORHIsym R0, tjumptable:$in)>;
def : Pat<(Mico32Lo tjumptable:$in), (ORIsym R0, tjumptable:$in)>;
def : Pat<(add GPR:$hi, (Mico32Lo tjumptable:$lo)),
(ADDIsym GPR:$hi, tjumptable:$lo)>;

// A conditional move pattern.
// Cond is 0 or 1 on entry.
// %tmp = sub 0, %cond ; = (cond) ? 0xFFFFFFFF : 0
Expand Down

0 comments on commit bec24ba

Please sign in to comment.