LLVM API Documentation
00001 //===---- ScheduleDAGEmit.cpp - Emit routines for the ScheduleDAG class ---===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This implements the Emit routines for the ScheduleDAG class, which creates 00011 // MachineInstrs according to the computed schedule. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #define DEBUG_TYPE "pre-RA-sched" 00016 #include "llvm/CodeGen/ScheduleDAG.h" 00017 #include "llvm/CodeGen/MachineConstantPool.h" 00018 #include "llvm/CodeGen/MachineFunction.h" 00019 #include "llvm/CodeGen/MachineInstrBuilder.h" 00020 #include "llvm/CodeGen/MachineRegisterInfo.h" 00021 #include "llvm/Target/TargetData.h" 00022 #include "llvm/Target/TargetMachine.h" 00023 #include "llvm/Target/TargetInstrInfo.h" 00024 #include "llvm/Target/TargetLowering.h" 00025 #include "llvm/ADT/Statistic.h" 00026 #include "llvm/Support/CommandLine.h" 00027 #include "llvm/Support/Debug.h" 00028 #include "llvm/Support/MathExtras.h" 00029 using namespace llvm; 00030 00031 void ScheduleDAG::AddMemOperand(MachineInstr *MI, const MachineMemOperand &MO) { 00032 MI->addMemOperand(MF, MO); 00033 } 00034 00035 void ScheduleDAG::EmitNoop() { 00036 TII->insertNoop(*BB, End); 00037 } 00038 00039 void ScheduleDAG::EmitPhysRegCopy(SUnit *SU, 00040 DenseMap<SUnit*, unsigned> &VRBaseMap) { 00041 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); 00042 I != E; ++I) { 00043 if (I->isCtrl()) continue; // ignore chain preds 00044 if (I->getSUnit()->CopyDstRC) { 00045 // Copy to physical register. 00046 DenseMap<SUnit*, unsigned>::iterator VRI = VRBaseMap.find(I->getSUnit()); 00047 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late"); 00048 // Find the destination physical register. 00049 unsigned Reg = 0; 00050 for (SUnit::const_succ_iterator II = SU->Succs.begin(), 00051 EE = SU->Succs.end(); II != EE; ++II) { 00052 if (II->getReg()) { 00053 Reg = II->getReg(); 00054 break; 00055 } 00056 } 00057 TII->copyRegToReg(*BB, End, Reg, VRI->second, 00058 SU->CopyDstRC, SU->CopySrcRC); 00059 } else { 00060 // Copy from physical register. 00061 assert(I->getReg() && "Unknown physical register!"); 00062 unsigned VRBase = MRI.createVirtualRegister(SU->CopyDstRC); 00063 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase)).second; 00064 isNew = isNew; // Silence compiler warning. 00065 assert(isNew && "Node emitted out of order - early"); 00066 TII->copyRegToReg(*BB, End, VRBase, I->getReg(), 00067 SU->CopyDstRC, SU->CopySrcRC); 00068 } 00069 break; 00070 } 00071 }