- /// Ensures there is space before the given machine instruction, returns the
- /// instruction's new number.
- SlotIndex makeSpaceBefore(MachineInstr *mi) {
- //if (!lis->hasGapBeforeInstr(lis->getInstructionIndex(mi))) {
- // FIXME: Should be updated to use rewrite-in-place methods when they're
- // introduced. Currently broken.
- //lis->scaleNumbering(2);
- //ls->scaleNumbering(2);
- //}
-
- SlotIndex miIdx = lis->getInstructionIndex(mi);
-
- //assert(lis->hasGapBeforeInstr(miIdx));
-
- return miIdx;
- }
-
- /// Ensure there is space after the given machine instruction, returns the
- /// instruction's new number.
- SlotIndex makeSpaceAfter(MachineInstr *mi) {
- //if (!lis->hasGapAfterInstr(lis->getInstructionIndex(mi))) {
- // FIXME: Should be updated to use rewrite-in-place methods when they're
- // introduced. Currently broken.
- // lis->scaleNumbering(2);
- // ls->scaleNumbering(2);
- //}
-
- SlotIndex miIdx = lis->getInstructionIndex(mi);
-
- //assert(lis->hasGapAfterInstr(miIdx));
-
- return miIdx;
- }
-
- /// Insert a store of the given vreg to the given stack slot immediately
- /// after the given instruction. Returns the base index of the inserted
- /// instruction. The caller is responsible for adding an appropriate
- /// LiveInterval to the LiveIntervals analysis.
- SlotIndex insertStoreAfter(MachineInstr *mi, unsigned ss,
- unsigned vreg,
- const TargetRegisterClass *trc) {
-
- MachineBasicBlock::iterator nextInstItr(next(mi));
-
- SlotIndex miIdx = makeSpaceAfter(mi);
-
- tii->storeRegToStackSlot(*mi->getParent(), nextInstItr, vreg,
- true, ss, trc);
- MachineBasicBlock::iterator storeInstItr(next(mi));
- MachineInstr *storeInst = &*storeInstItr;
-
- return lis->InsertMachineInstrInMaps(storeInst);
- }
-
- /// Insert a store of the given vreg to the given stack slot immediately
- /// before the given instructnion. Returns the base index of the inserted
- /// Instruction.
- SlotIndex insertStoreBefore(MachineInstr *mi, unsigned ss,
- unsigned vreg,
- const TargetRegisterClass *trc) {
- SlotIndex miIdx = makeSpaceBefore(mi);
-
- tii->storeRegToStackSlot(*mi->getParent(), mi, vreg, true, ss, trc);
- MachineBasicBlock::iterator storeInstItr(prior(mi));
- MachineInstr *storeInst = &*storeInstItr;
-
- return lis->InsertMachineInstrInMaps(storeInst);
- }
-
- void insertStoreAfterInstOnInterval(LiveInterval *li,
- MachineInstr *mi, unsigned ss,
- unsigned vreg,
- const TargetRegisterClass *trc) {
-
- SlotIndex storeInstIdx = insertStoreAfter(mi, ss, vreg, trc);
- SlotIndex start = lis->getInstructionIndex(mi).getDefIndex(),
- end = storeInstIdx.getUseIndex();
-
- VNInfo *vni =
- li->getNextValue(storeInstIdx, 0, true, lis->getVNInfoAllocator());
- vni->addKill(storeInstIdx);
- DEBUG(errs() << " Inserting store range: [" << start
- << ", " << end << ")\n");
- LiveRange lr(start, end, vni);
-
- li->addRange(lr);
- }
-
- /// Insert a load of the given vreg from the given stack slot immediately
- /// after the given instruction. Returns the base index of the inserted
- /// instruction. The caller is responsibel for adding/removing an appropriate
- /// range vreg's LiveInterval.
- SlotIndex insertLoadAfter(MachineInstr *mi, unsigned ss,
- unsigned vreg,
- const TargetRegisterClass *trc) {
-
- MachineBasicBlock::iterator nextInstItr(next(mi));
-
- SlotIndex miIdx = makeSpaceAfter(mi);
-
- tii->loadRegFromStackSlot(*mi->getParent(), nextInstItr, vreg, ss, trc);
- MachineBasicBlock::iterator loadInstItr(next(mi));
- MachineInstr *loadInst = &*loadInstItr;
-
- return lis->InsertMachineInstrInMaps(loadInst);
- }
-
- /// Insert a load of the given vreg from the given stack slot immediately
- /// before the given instruction. Returns the base index of the inserted
- /// instruction. The caller is responsible for adding an appropriate
- /// LiveInterval to the LiveIntervals analysis.
- SlotIndex insertLoadBefore(MachineInstr *mi, unsigned ss,
- unsigned vreg,
- const TargetRegisterClass *trc) {
- SlotIndex miIdx = makeSpaceBefore(mi);
-
- tii->loadRegFromStackSlot(*mi->getParent(), mi, vreg, ss, trc);
- MachineBasicBlock::iterator loadInstItr(prior(mi));
- MachineInstr *loadInst = &*loadInstItr;
-
- return lis->InsertMachineInstrInMaps(loadInst);
- }
-
- void insertLoadBeforeInstOnInterval(LiveInterval *li,
- MachineInstr *mi, unsigned ss,
- unsigned vreg,
- const TargetRegisterClass *trc) {
-
- SlotIndex loadInstIdx = insertLoadBefore(mi, ss, vreg, trc);
- SlotIndex start = loadInstIdx.getDefIndex(),
- end = lis->getInstructionIndex(mi).getUseIndex();
-
- VNInfo *vni =
- li->getNextValue(loadInstIdx, 0, true, lis->getVNInfoAllocator());
- vni->addKill(lis->getInstructionIndex(mi));
- DEBUG(errs() << " Intserting load range: [" << start
- << ", " << end << ")\n");
- LiveRange lr(start, end, vni);
-
- li->addRange(lr);
- }
-
-
-