2008-11-19 23:18:57 +00:00
|
|
|
//===---- ScheduleDAGEmit.cpp - Emit routines for the ScheduleDAG class ---===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements the Emit routines for the ScheduleDAG class, which creates
|
|
|
|
// MachineInstrs according to the computed schedule.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "pre-RA-sched"
|
|
|
|
#include "llvm/CodeGen/ScheduleDAG.h"
|
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
void ScheduleDAG::EmitNoop() {
|
2009-02-11 04:27:20 +00:00
|
|
|
TII->insertNoop(*BB, InsertPos);
|
2008-11-19 23:18:57 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 03:19:55 +00:00
|
|
|
void ScheduleDAG::EmitPhysRegCopy(SUnit *SU,
|
2008-11-19 23:18:57 +00:00
|
|
|
DenseMap<SUnit*, unsigned> &VRBaseMap) {
|
|
|
|
for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
|
|
|
|
I != E; ++I) {
|
2008-12-09 22:54:47 +00:00
|
|
|
if (I->isCtrl()) continue; // ignore chain preds
|
|
|
|
if (I->getSUnit()->CopyDstRC) {
|
2008-11-19 23:18:57 +00:00
|
|
|
// Copy to physical register.
|
2008-12-09 22:54:47 +00:00
|
|
|
DenseMap<SUnit*, unsigned>::iterator VRI = VRBaseMap.find(I->getSUnit());
|
2008-11-19 23:18:57 +00:00
|
|
|
assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
|
|
|
|
// Find the destination physical register.
|
|
|
|
unsigned Reg = 0;
|
|
|
|
for (SUnit::const_succ_iterator II = SU->Succs.begin(),
|
|
|
|
EE = SU->Succs.end(); II != EE; ++II) {
|
2011-07-06 19:45:42 +00:00
|
|
|
if (II->isCtrl()) continue; // ignore chain preds
|
2009-01-12 03:19:55 +00:00
|
|
|
if (II->getReg()) {
|
|
|
|
Reg = II->getReg();
|
2008-11-19 23:18:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-10 19:08:25 +00:00
|
|
|
BuildMI(*BB, InsertPos, DebugLoc(), TII->get(TargetOpcode::COPY), Reg)
|
|
|
|
.addReg(VRI->second);
|
2008-11-19 23:18:57 +00:00
|
|
|
} else {
|
|
|
|
// Copy from physical register.
|
2008-12-09 22:54:47 +00:00
|
|
|
assert(I->getReg() && "Unknown physical register!");
|
2008-11-19 23:18:57 +00:00
|
|
|
unsigned VRBase = MRI.createVirtualRegister(SU->CopyDstRC);
|
|
|
|
bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)).second;
|
2010-12-23 00:58:24 +00:00
|
|
|
(void)isNew; // Silence compiler warning.
|
2008-11-19 23:18:57 +00:00
|
|
|
assert(isNew && "Node emitted out of order - early");
|
2010-07-10 19:08:25 +00:00
|
|
|
BuildMI(*BB, InsertPos, DebugLoc(), TII->get(TargetOpcode::COPY), VRBase)
|
|
|
|
.addReg(I->getReg());
|
2008-11-19 23:18:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|