blob: 8e034203f4d5692f84d4af5883c0bd0f693b42ff [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
Dan Gohman343f0c02008-11-19 23:18:57 +000031void ScheduleDAG::EmitNoop() {
Dan Gohman47ac0f02009-02-11 04:27:20 +000032 TII->insertNoop(*BB, InsertPos);
Dan Gohman343f0c02008-11-19 23:18:57 +000033}
34
Evan Chengc29a56d2009-01-12 03:19:55 +000035void ScheduleDAG::EmitPhysRegCopy(SUnit *SU,
Dan Gohman343f0c02008-11-19 23:18:57 +000036 DenseMap<SUnit*, unsigned> &VRBaseMap) {
37 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
38 I != E; ++I) {
Dan Gohman54e4c362008-12-09 22:54:47 +000039 if (I->isCtrl()) continue; // ignore chain preds
40 if (I->getSUnit()->CopyDstRC) {
Dan Gohman343f0c02008-11-19 23:18:57 +000041 // Copy to physical register.
Dan Gohman54e4c362008-12-09 22:54:47 +000042 DenseMap<SUnit*, unsigned>::iterator VRI = VRBaseMap.find(I->getSUnit());
Dan Gohman343f0c02008-11-19 23:18:57 +000043 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
44 // Find the destination physical register.
45 unsigned Reg = 0;
46 for (SUnit::const_succ_iterator II = SU->Succs.begin(),
47 EE = SU->Succs.end(); II != EE; ++II) {
Evan Chengc29a56d2009-01-12 03:19:55 +000048 if (II->getReg()) {
49 Reg = II->getReg();
Dan Gohman343f0c02008-11-19 23:18:57 +000050 break;
51 }
52 }
Dan Gohman1410b762009-10-30 23:59:06 +000053 bool Success = TII->copyRegToReg(*BB, InsertPos, Reg, VRI->second,
54 SU->CopyDstRC, SU->CopySrcRC);
55 (void)Success;
56 assert(Success && "copyRegToReg failed!");
Dan Gohman343f0c02008-11-19 23:18:57 +000057 } else {
58 // Copy from physical register.
Dan Gohman54e4c362008-12-09 22:54:47 +000059 assert(I->getReg() && "Unknown physical register!");
Dan Gohman343f0c02008-11-19 23:18:57 +000060 unsigned VRBase = MRI.createVirtualRegister(SU->CopyDstRC);
61 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)).second;
62 isNew = isNew; // Silence compiler warning.
63 assert(isNew && "Node emitted out of order - early");
Dan Gohman1410b762009-10-30 23:59:06 +000064 bool Success = TII->copyRegToReg(*BB, InsertPos, VRBase, I->getReg(),
65 SU->CopyDstRC, SU->CopySrcRC);
66 (void)Success;
67 assert(Success && "copyRegToReg failed!");
Dan Gohman343f0c02008-11-19 23:18:57 +000068 }
69 break;
70 }
71}