-/// doFPLoad - This method is used to load an FP value from memory using the
-/// current endianness. NOTE: This method returns a partially constructed load
-/// instruction which needs to have the memory source filled in still.
-///
-MachineInstr *ISel::doFPLoad(MachineBasicBlock *MBB,
- MachineBasicBlock::iterator &MBBI,
- const Type *Ty, unsigned DestReg) {
- assert(Ty == Type::FloatTy || Ty == Type::DoubleTy && "Unknown FP type!");
- unsigned LoadOpcode = Ty == Type::FloatTy ? X86::FLDr32 : X86::FLDr64;
-
- if (TM.getTargetData().isLittleEndian()) // fast path...
- return BMI(MBB, MBBI, LoadOpcode, 4, DestReg);
-
- // If we are big-endian, start by creating an LEA instruction to represent the
- // address of the memory location to load from...
- //
- unsigned SrcAddrReg = makeAnotherReg(Type::UIntTy);
- MachineInstr *Result = BMI(MBB, MBBI, X86::LEAr32, 5, SrcAddrReg);
-
- // Allocate a temporary stack slot to transform the value into...
- int FrameIdx = F->getFrameInfo()->CreateStackObject(Ty, TM.getTargetData());
-
- // Perform the bswaps 32 bits at a time...
- unsigned TmpReg1 = makeAnotherReg(Type::UIntTy);
- unsigned TmpReg2 = makeAnotherReg(Type::UIntTy);
- addDirectMem(BMI(MBB, MBBI, X86::MOVmr32, 4, TmpReg1), SrcAddrReg);
- BMI(MBB, MBBI, X86::BSWAPr32, 1, TmpReg2).addReg(TmpReg1);
- unsigned Offset = (Ty == Type::DoubleTy) << 2;
- addFrameReference(BMI(MBB, MBBI, X86::MOVrm32, 5),
- FrameIdx, Offset).addReg(TmpReg2);
-
- if (Ty == Type::DoubleTy) { // Swap the other 32 bits of a double value...
- TmpReg1 = makeAnotherReg(Type::UIntTy);
- TmpReg2 = makeAnotherReg(Type::UIntTy);
-
- addRegOffset(BMI(MBB, MBBI, X86::MOVmr32, 4, TmpReg1), SrcAddrReg, 4);
- BMI(MBB, MBBI, X86::BSWAPr32, 1, TmpReg2).addReg(TmpReg1);
- unsigned Offset = (Ty == Type::DoubleTy) << 2;
- addFrameReference(BMI(MBB, MBBI, X86::MOVrm32,5), FrameIdx).addReg(TmpReg2);
- }
-
- // Now we can reload the final byteswapped result into the final destination.
- addFrameReference(BMI(MBB, MBBI, LoadOpcode, 4, DestReg), FrameIdx);
- return Result;
-}
-