llvm.org GIT mirror llvm / 91e69c3
Add basic infrastructure and x86 support for preserving MachineMemOperand information when unfolding memory references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83656 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
4 changed file(s) with 114 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
328328 unsigned base_alignment);
329329
330330 /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
331 /// an existing one, adjusting by an offset and using the given EVT.
331 /// an existing one, adjusting by an offset and using the given size.
332332 /// MachineMemOperands are owned by the MachineFunction and need not be
333333 /// explicitly deallocated.
334334 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
338338 /// pointers. This array is owned by the MachineFunction.
339339 MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num);
340340
341 /// extractLoadMemRefs - Allocate an array and populate it with just the
342 /// load information from the given MachineMemOperand sequence.
343 std::pair
344 MachineInstr::mmo_iterator>
345 extractLoadMemRefs(MachineInstr::mmo_iterator Begin,
346 MachineInstr::mmo_iterator End);
347
348 /// extractStoreMemRefs - Allocate an array and populate it with just the
349 /// store information from the given MachineMemOperand sequence.
350 std::pair
351 MachineInstr::mmo_iterator>
352 extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
353 MachineInstr::mmo_iterator End);
354
341355 //===--------------------------------------------------------------------===//
342356 // Debug location.
343357 //
234234 return Allocator.Allocate(Num);
235235 }
236236
237 std::pair
238 MachineFunction::extractLoadMemRefs(MachineInstr::mmo_iterator Begin,
239 MachineInstr::mmo_iterator End) {
240 // Count the number of load mem refs.
241 unsigned Num = 0;
242 for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
243 if ((*I)->isLoad())
244 ++Num;
245
246 // Allocate a new array and populate it with the load information.
247 MachineInstr::mmo_iterator Result = allocateMemRefsArray(Num);
248 unsigned Index = 0;
249 for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
250 if ((*I)->isLoad()) {
251 if (!(*I)->isStore())
252 // Reuse the MMO.
253 Result[Index] = *I;
254 else {
255 // Clone the MMO and unset the store flag.
256 MachineMemOperand *JustLoad =
257 getMachineMemOperand((*I)->getValue(),
258 (*I)->getFlags() & ~MachineMemOperand::MOStore,
259 (*I)->getOffset(), (*I)->getSize(),
260 (*I)->getBaseAlignment());
261 Result[Index] = JustLoad;
262 }
263 ++Index;
264 }
265 }
266 return std::make_pair(Result, Result + Num);
267 }
268
269 std::pair
270 MachineFunction::extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
271 MachineInstr::mmo_iterator End) {
272 // Count the number of load mem refs.
273 unsigned Num = 0;
274 for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
275 if ((*I)->isStore())
276 ++Num;
277
278 // Allocate a new array and populate it with the store information.
279 MachineInstr::mmo_iterator Result = allocateMemRefsArray(Num);
280 unsigned Index = 0;
281 for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
282 if ((*I)->isStore()) {
283 if (!(*I)->isLoad())
284 // Reuse the MMO.
285 Result[Index] = *I;
286 else {
287 // Clone the MMO and unset the load flag.
288 MachineMemOperand *JustStore =
289 getMachineMemOperand((*I)->getValue(),
290 (*I)->getFlags() & ~MachineMemOperand::MOLoad,
291 (*I)->getOffset(), (*I)->getSize(),
292 (*I)->getBaseAlignment());
293 Result[Index] = JustStore;
294 }
295 ++Index;
296 }
297 }
298 return std::make_pair(Result, Result + Num);
299 }
300
237301 void MachineFunction::dump() const {
238302 print(errs());
239303 }
18851885 bool isKill,
18861886 SmallVectorImpl &Addr,
18871887 const TargetRegisterClass *RC,
1888 MachineInstr::mmo_iterator MMOBegin,
1889 MachineInstr::mmo_iterator MMOEnd,
18881890 SmallVectorImpl &NewMIs) const {
18891891 bool isAligned = (RI.getStackAlignment() >= 16) ||
18901892 RI.needsStackRealignment(MF);
18941896 for (unsigned i = 0, e = Addr.size(); i != e; ++i)
18951897 MIB.addOperand(Addr[i]);
18961898 MIB.addReg(SrcReg, getKillRegState(isKill));
1899 (*MIB).setMemRefs(MMOBegin, MMOEnd);
18971900 NewMIs.push_back(MIB);
18981901 }
18991902
19761979 void X86InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
19771980 SmallVectorImpl &Addr,
19781981 const TargetRegisterClass *RC,
1982 MachineInstr::mmo_iterator MMOBegin,
1983 MachineInstr::mmo_iterator MMOEnd,
19791984 SmallVectorImpl &NewMIs) const {
19801985 bool isAligned = (RI.getStackAlignment() >= 16) ||
19811986 RI.needsStackRealignment(MF);
19841989 MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg);
19851990 for (unsigned i = 0, e = Addr.size(); i != e; ++i)
19861991 MIB.addOperand(Addr[i]);
1992 (*MIB).setMemRefs(MMOBegin, MMOEnd);
19871993 NewMIs.push_back(MIB);
19881994 }
19891995
24412447
24422448 // Emit the load instruction.
24432449 if (UnfoldLoad) {
2444 loadRegFromAddr(MF, Reg, AddrOps, RC, NewMIs);
2450 std::pair
2451 MachineInstr::mmo_iterator> MMOs =
2452 MF.extractLoadMemRefs(MI->memoperands_begin(),
2453 MI->memoperands_end());
2454 loadRegFromAddr(MF, Reg, AddrOps, RC, MMOs.first, MMOs.second, NewMIs);
24452455 if (UnfoldStore) {
24462456 // Address operands cannot be marked isKill.
24472457 for (unsigned i = 1; i != 1 + X86AddrNumOperands; ++i) {
25012511 // Emit the store instruction.
25022512 if (UnfoldStore) {
25032513 const TargetRegisterClass *DstRC = TID.OpInfo[0].getRegClass(&RI);
2504 storeRegToAddr(MF, Reg, true, AddrOps, DstRC, NewMIs);
2514 std::pair
2515 MachineInstr::mmo_iterator> MMOs =
2516 MF.extractStoreMemRefs(MI->memoperands_begin(),
2517 MI->memoperands_end());
2518 storeRegToAddr(MF, Reg, true, AddrOps, DstRC, MMOs.first, MMOs.second, NewMIs);
25052519 }
25062520
25072521 return true;
25432557
25442558 // Emit the load instruction.
25452559 SDNode *Load = 0;
2546 const MachineFunction &MF = DAG.getMachineFunction();
2560 MachineFunction &MF = DAG.getMachineFunction();
25472561 if (FoldedLoad) {
25482562 EVT VT = *RC->vt_begin();
25492563 bool isAligned = (RI.getStackAlignment() >= 16) ||
25512565 Load = DAG.getMachineNode(getLoadRegOpcode(0, RC, isAligned, TM), dl,
25522566 VT, MVT::Other, &AddrOps[0], AddrOps.size());
25532567 NewNodes.push_back(Load);
2568
2569 // Preserve memory reference information.
2570 std::pair
2571 MachineInstr::mmo_iterator> MMOs =
2572 MF.extractLoadMemRefs(cast(N)->memoperands_begin(),
2573 cast(N)->memoperands_end());
2574 cast(Load)->setMemRefs(MMOs.first, MMOs.second);
25542575 }
25552576
25562577 // Emit the data processing instruction.
25842605 dl, MVT::Other,
25852606 &AddrOps[0], AddrOps.size());
25862607 NewNodes.push_back(Store);
2608
2609 // Preserve memory reference information.
2610 std::pair
2611 MachineInstr::mmo_iterator> MMOs =
2612 MF.extractStoreMemRefs(cast(N)->memoperands_begin(),
2613 cast(N)->memoperands_end());
2614 cast(Load)->setMemRefs(MMOs.first, MMOs.second);
25872615 }
25882616
25892617 return true;
497497 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
498498 SmallVectorImpl &Addr,
499499 const TargetRegisterClass *RC,
500 MachineInstr::mmo_iterator MMOBegin,
501 MachineInstr::mmo_iterator MMOEnd,
500502 SmallVectorImpl &NewMIs) const;
501503
502504 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
507509 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
508510 SmallVectorImpl &Addr,
509511 const TargetRegisterClass *RC,
512 MachineInstr::mmo_iterator MMOBegin,
513 MachineInstr::mmo_iterator MMOEnd,
510514 SmallVectorImpl &NewMIs) const;
511515
512516 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,