예제 #1
0
void DAGTypeLegalizer::ExpandRes_NormalLoad(SDNode *N, SDValue &Lo,
        SDValue &Hi) {
    assert(ISD::isNormalLoad(N) && "This routine only for normal loads!");
    SDLoc dl(N);

    LoadSDNode *LD = cast<LoadSDNode>(N);
    EVT ValueVT = LD->getValueType(0);
    EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), ValueVT);
    SDValue Chain = LD->getChain();
    SDValue Ptr = LD->getBasePtr();
    unsigned Alignment = LD->getAlignment();
    AAMDNodes AAInfo = LD->getAAInfo();

    assert(NVT.isByteSized() && "Expanded type not byte sized!");

    Lo = DAG.getLoad(NVT, dl, Chain, Ptr, LD->getPointerInfo(), Alignment,
                     LD->getMemOperand()->getFlags(), AAInfo);

    // Increment the pointer to the other half.
    unsigned IncrementSize = NVT.getSizeInBits() / 8;
    Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
                      DAG.getConstant(IncrementSize, dl, Ptr.getValueType()));
    Hi = DAG.getLoad(NVT, dl, Chain, Ptr,
                     LD->getPointerInfo().getWithOffset(IncrementSize),
                     MinAlign(Alignment, IncrementSize),
                     LD->getMemOperand()->getFlags(), AAInfo);

    // Build a factor node to remember that this load is independent of the
    // other one.
    Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
                        Hi.getValue(1));

    // Handle endianness of the load.
    if (TLI.hasBigEndianPartOrdering(ValueVT, DAG.getDataLayout()))
        std::swap(Lo, Hi);

    // Modified the chain - switch anything that used the old chain to use
    // the new one.
    ReplaceValueWith(SDValue(N, 1), Chain);
}