Mercurial > hg > CbC > CbC_llvm
comparison lib/CodeGen/LiveDebugValues.cpp @ 134:3a76565eade5 LLVM5.0.1
update 5.0.1
author | mir3636 |
---|---|
date | Sat, 17 Feb 2018 09:57:20 +0900 |
parents | 803732b1fca8 |
children | c2174574ed3a |
comparison
equal
deleted
inserted
replaced
133:c60214abe0e8 | 134:3a76565eade5 |
---|---|
31 #include "llvm/CodeGen/MachineFunction.h" | 31 #include "llvm/CodeGen/MachineFunction.h" |
32 #include "llvm/CodeGen/MachineFunctionPass.h" | 32 #include "llvm/CodeGen/MachineFunctionPass.h" |
33 #include "llvm/CodeGen/MachineInstr.h" | 33 #include "llvm/CodeGen/MachineInstr.h" |
34 #include "llvm/CodeGen/MachineInstrBuilder.h" | 34 #include "llvm/CodeGen/MachineInstrBuilder.h" |
35 #include "llvm/CodeGen/MachineMemOperand.h" | 35 #include "llvm/CodeGen/MachineMemOperand.h" |
36 #include "llvm/CodeGen/MachineModuleInfo.h" | |
37 #include "llvm/CodeGen/MachineOperand.h" | 36 #include "llvm/CodeGen/MachineOperand.h" |
38 #include "llvm/CodeGen/PseudoSourceValue.h" | 37 #include "llvm/CodeGen/PseudoSourceValue.h" |
38 #include "llvm/CodeGen/TargetFrameLowering.h" | |
39 #include "llvm/CodeGen/TargetInstrInfo.h" | |
40 #include "llvm/CodeGen/TargetLowering.h" | |
41 #include "llvm/CodeGen/TargetRegisterInfo.h" | |
42 #include "llvm/CodeGen/TargetSubtargetInfo.h" | |
39 #include "llvm/IR/DebugInfoMetadata.h" | 43 #include "llvm/IR/DebugInfoMetadata.h" |
40 #include "llvm/IR/DebugLoc.h" | 44 #include "llvm/IR/DebugLoc.h" |
41 #include "llvm/IR/Function.h" | 45 #include "llvm/IR/Function.h" |
42 #include "llvm/IR/Module.h" | 46 #include "llvm/IR/Module.h" |
43 #include "llvm/MC/MCRegisterInfo.h" | 47 #include "llvm/MC/MCRegisterInfo.h" |
44 #include "llvm/Pass.h" | 48 #include "llvm/Pass.h" |
45 #include "llvm/Support/Casting.h" | 49 #include "llvm/Support/Casting.h" |
46 #include "llvm/Support/Compiler.h" | 50 #include "llvm/Support/Compiler.h" |
47 #include "llvm/Support/Debug.h" | 51 #include "llvm/Support/Debug.h" |
48 #include "llvm/Support/raw_ostream.h" | 52 #include "llvm/Support/raw_ostream.h" |
49 #include "llvm/Target/TargetFrameLowering.h" | |
50 #include "llvm/Target/TargetInstrInfo.h" | |
51 #include "llvm/Target/TargetLowering.h" | |
52 #include "llvm/Target/TargetRegisterInfo.h" | |
53 #include "llvm/Target/TargetSubtargetInfo.h" | |
54 #include <algorithm> | 53 #include <algorithm> |
55 #include <cassert> | 54 #include <cassert> |
56 #include <cstdint> | 55 #include <cstdint> |
57 #include <functional> | 56 #include <functional> |
58 #include <queue> | 57 #include <queue> |
425 if (!((TII->isStoreToStackSlotPostFE(MI, FI) || | 424 if (!((TII->isStoreToStackSlotPostFE(MI, FI) || |
426 TII->hasStoreToStackSlot(MI, MMO, FI)) && | 425 TII->hasStoreToStackSlot(MI, MMO, FI)) && |
427 FrameInfo.isSpillSlotObjectIndex(FI))) | 426 FrameInfo.isSpillSlotObjectIndex(FI))) |
428 return false; | 427 return false; |
429 | 428 |
430 // In a spill instruction generated by the InlineSpiller the spilled register | 429 auto isKilledReg = [&](const MachineOperand MO, unsigned &Reg) { |
431 // has its kill flag set. Return false if we don't find such a register. | 430 if (!MO.isReg() || !MO.isUse()) { |
432 Reg = 0; | 431 Reg = 0; |
432 return false; | |
433 } | |
434 Reg = MO.getReg(); | |
435 return MO.isKill(); | |
436 }; | |
437 | |
433 for (const MachineOperand &MO : MI.operands()) { | 438 for (const MachineOperand &MO : MI.operands()) { |
434 if (MO.isReg() && MO.isUse() && MO.isKill()) { | 439 // In a spill instruction generated by the InlineSpiller the spilled |
435 Reg = MO.getReg(); | 440 // register has its kill flag set. |
436 break; | 441 if (isKilledReg(MO, Reg)) |
437 } | 442 return true; |
438 } | 443 if (Reg != 0) { |
439 return Reg != 0; | 444 // Check whether next instruction kills the spilled register. |
445 // FIXME: Current solution does not cover search for killed register in | |
446 // bundles and instructions further down the chain. | |
447 auto NextI = std::next(MI.getIterator()); | |
448 // Skip next instruction that points to basic block end iterator. | |
449 if (MI.getParent()->end() == NextI) | |
450 continue; | |
451 unsigned RegNext; | |
452 for (const MachineOperand &MONext : NextI->operands()) { | |
453 // Return true if we came across the register from the | |
454 // previous spill instruction that is killed in NextI. | |
455 if (isKilledReg(MONext, RegNext) && RegNext == Reg) | |
456 return true; | |
457 } | |
458 } | |
459 } | |
460 // Return false if we didn't find spilled register. | |
461 return false; | |
440 } | 462 } |
441 | 463 |
442 /// A spilled register may indicate that we have to end the current range of | 464 /// A spilled register may indicate that we have to end the current range of |
443 /// a variable and create a new one for the spill location. | 465 /// a variable and create a new one for the spill location. |
444 /// We don't want to insert any instructions in transfer(), so we just create | 466 /// We don't want to insert any instructions in transfer(), so we just create |
455 return; | 477 return; |
456 | 478 |
457 // Check if the register is the location of a debug value. | 479 // Check if the register is the location of a debug value. |
458 for (unsigned ID : OpenRanges.getVarLocs()) { | 480 for (unsigned ID : OpenRanges.getVarLocs()) { |
459 if (VarLocIDs[ID].isDescribedByReg() == Reg) { | 481 if (VarLocIDs[ID].isDescribedByReg() == Reg) { |
460 DEBUG(dbgs() << "Spilling Register " << PrintReg(Reg, TRI) << '(' | 482 DEBUG(dbgs() << "Spilling Register " << printReg(Reg, TRI) << '(' |
461 << VarLocIDs[ID].Var.getVar()->getName() << ")\n"); | 483 << VarLocIDs[ID].Var.getVar()->getName() << ")\n"); |
462 | 484 |
463 // Create a DBG_VALUE instruction to describe the Var in its spilled | 485 // Create a DBG_VALUE instruction to describe the Var in its spilled |
464 // location, but don't insert it yet to avoid invalidating the | 486 // location, but don't insert it yet to avoid invalidating the |
465 // iterator in our caller. | 487 // iterator in our caller. |
496 OpenRangesSet &OpenRanges, | 518 OpenRangesSet &OpenRanges, |
497 VarLocInMBB &OutLocs, | 519 VarLocInMBB &OutLocs, |
498 const VarLocMap &VarLocIDs) { | 520 const VarLocMap &VarLocIDs) { |
499 bool Changed = false; | 521 bool Changed = false; |
500 const MachineBasicBlock *CurMBB = MI.getParent(); | 522 const MachineBasicBlock *CurMBB = MI.getParent(); |
501 if (!(MI.isTerminator() || (&MI == &CurMBB->instr_back()))) | 523 if (!(MI.isTerminator() || (&MI == &CurMBB->back()))) |
502 return false; | 524 return false; |
503 | 525 |
504 if (OpenRanges.empty()) | 526 if (OpenRanges.empty()) |
505 return false; | 527 return false; |
506 | 528 |
702 DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, "Final InLocs", dbgs())); | 724 DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, "Final InLocs", dbgs())); |
703 return Changed; | 725 return Changed; |
704 } | 726 } |
705 | 727 |
706 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { | 728 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { |
707 if (!MF.getFunction()->getSubprogram()) | 729 if (!MF.getFunction().getSubprogram()) |
708 // LiveDebugValues will already have removed all DBG_VALUEs. | 730 // LiveDebugValues will already have removed all DBG_VALUEs. |
709 return false; | 731 return false; |
710 | 732 |
711 // Skip functions from NoDebug compilation units. | 733 // Skip functions from NoDebug compilation units. |
712 if (MF.getFunction()->getSubprogram()->getUnit()->getEmissionKind() == | 734 if (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() == |
713 DICompileUnit::NoDebug) | 735 DICompileUnit::NoDebug) |
714 return false; | 736 return false; |
715 | 737 |
716 TRI = MF.getSubtarget().getRegisterInfo(); | 738 TRI = MF.getSubtarget().getRegisterInfo(); |
717 TII = MF.getSubtarget().getInstrInfo(); | 739 TII = MF.getSubtarget().getInstrInfo(); |