blob: ce3283dc3df1adda09f7c74886fa44db3c99217d [file] [log] [blame]
Dan Gohman343f0c02008-11-19 23:18:57 +00001//===---- ScheduleDAGEmit.cpp - Emit routines for the ScheduleDAG class ---===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This implements the Emit routines for the ScheduleDAG class, which creates
11// MachineInstrs according to the computed schedule.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "pre-RA-sched"
16#include "llvm/CodeGen/ScheduleDAG.h"
17#include "llvm/CodeGen/MachineConstantPool.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/MachineInstrBuilder.h"
20#include "llvm/CodeGen/MachineRegisterInfo.h"
21#include "llvm/Target/TargetData.h"
22#include "llvm/Target/TargetMachine.h"
23#include "llvm/Target/TargetInstrInfo.h"
24#include "llvm/Target/TargetLowering.h"
25#include "llvm/ADT/Statistic.h"
26#include "llvm/Support/CommandLine.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Support/MathExtras.h"
29using namespace llvm;
30
31void ScheduleDAG::AddMemOperand(MachineInstr *MI, const MachineMemOperand &MO) {
32 MI->addMemOperand(*MF, MO);
33}
34
35void ScheduleDAG::EmitNoop() {
36 TII->insertNoop(*BB, BB->end());
37}
38
39void ScheduleDAG::EmitCrossRCCopy(SUnit *SU,
40 DenseMap<SUnit*, unsigned> &VRBaseMap) {
41 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
42 I != E; ++I) {
43 if (I->isCtrl) continue; // ignore chain preds
44 if (I->Dep->CopyDstRC) {
45 // Copy to physical register.
46 DenseMap<SUnit*, unsigned>::iterator VRI = VRBaseMap.find(I->Dep);
47 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
48 // Find the destination physical register.
49 unsigned Reg = 0;
50 for (SUnit::const_succ_iterator II = SU->Succs.begin(),
51 EE = SU->Succs.end(); II != EE; ++II) {
52 if (I->Reg) {
53 Reg = I->Reg;
54 break;
55 }
56 }
57 assert(I->Reg && "Unknown physical register!");
58 TII->copyRegToReg(*BB, BB->end(), Reg, VRI->second,
59 SU->CopyDstRC, SU->CopySrcRC);
60 } else {
61 // Copy from physical register.
62 assert(I->Reg && "Unknown physical register!");
63 unsigned VRBase = MRI.createVirtualRegister(SU->CopyDstRC);
64 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)).second;
65 isNew = isNew; // Silence compiler warning.
66 assert(isNew && "Node emitted out of order - early");
67 TII->copyRegToReg(*BB, BB->end(), VRBase, I->Reg,
68 SU->CopyDstRC, SU->CopySrcRC);
69 }
70 break;
71 }
72}