Split scheduling from instruction selection.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52923 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2008-06-30 20:45:06 +00:00
parent 30389141c9
commit db8d56b825
11 changed files with 62 additions and 70 deletions

View File

@ -58,7 +58,9 @@ public:
unsigned MakeReg(MVT VT); unsigned MakeReg(MVT VT);
virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {} virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {}
virtual void InstructionSelectBasicBlock(SelectionDAG &SD) = 0; virtual void InstructionSelect(SelectionDAG &SD) = 0;
virtual void InstructionSelectPostProcessing(SelectionDAG &DAG) {}
virtual void SelectRootInit() { virtual void SelectRootInit() {
DAGSize = CurDAG->AssignTopologicalOrder(TopOrder); DAGSize = CurDAG->AssignTopologicalOrder(TopOrder);
} }
@ -160,10 +162,6 @@ public:
}; };
protected: protected:
/// Pick a safe ordering and emit instructions for each target node in the
/// graph.
void ScheduleAndEmitDAG(SelectionDAG &DAG);
/// SelectInlineAsmMemoryOperands - Calls to this are automatically generated /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
/// by tblgen. Others should not call it. /// by tblgen. Others should not call it.
void SelectInlineAsmMemoryOperands(std::vector<SDOperand> &Ops, void SelectInlineAsmMemoryOperands(std::vector<SDOperand> &Ops,
@ -187,6 +185,10 @@ private:
void ComputeLiveOutVRegInfo(SelectionDAG &DAG); void ComputeLiveOutVRegInfo(SelectionDAG &DAG);
/// Pick a safe ordering and emit instructions for each target node in the
/// graph.
void ScheduleAndEmitDAG(SelectionDAG &DAG);
/// SwitchCases - Vector of CaseBlock structures used to communicate /// SwitchCases - Vector of CaseBlock structures used to communicate
/// SwitchInst code generation information. /// SwitchInst code generation information.
std::vector<CaseBlock> SwitchCases; std::vector<CaseBlock> SwitchCases;

View File

@ -43,9 +43,10 @@
#include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetOptions.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Timer.h"
#include <algorithm> #include <algorithm>
using namespace llvm; using namespace llvm;
@ -5354,7 +5355,14 @@ void SelectionDAGISel::CodeGenAndEmitDAG(SelectionDAG &DAG) {
// Third, instruction select all of the operations to machine code, adding the // Third, instruction select all of the operations to machine code, adding the
// code to the MachineBasicBlock. // code to the MachineBasicBlock.
InstructionSelectBasicBlock(DAG); InstructionSelect(DAG);
// Emit machine code to BB. This can change 'BB' to the last block being
// inserted into.
ScheduleAndEmitDAG(DAG);
// Perform target specific isel post processing.
InstructionSelectPostProcessing(DAG);
DOUT << "Selected machine code:\n"; DOUT << "Selected machine code:\n";
DEBUG(BB->dump()); DEBUG(BB->dump());

View File

@ -54,7 +54,7 @@ public:
} }
SDNode *Select(SDOperand Op); SDNode *Select(SDOperand Op);
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); virtual void InstructionSelect(SelectionDAG &DAG);
bool SelectAddrMode2(SDOperand Op, SDOperand N, SDOperand &Base, bool SelectAddrMode2(SDOperand Op, SDOperand N, SDOperand &Base,
SDOperand &Offset, SDOperand &Opc); SDOperand &Offset, SDOperand &Opc);
bool SelectAddrMode2Offset(SDOperand Op, SDOperand N, bool SelectAddrMode2Offset(SDOperand Op, SDOperand N,
@ -91,13 +91,11 @@ public:
}; };
} }
void ARMDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { void ARMDAGToDAGISel::InstructionSelect(SelectionDAG &DAG) {
DEBUG(BB->dump()); DEBUG(BB->dump());
DAG.setRoot(SelectRoot(DAG.getRoot())); DAG.setRoot(SelectRoot(DAG.getRoot()));
DAG.RemoveDeadNodes(); DAG.RemoveDeadNodes();
ScheduleAndEmitDAG(DAG);
} }
bool ARMDAGToDAGISel::SelectAddrMode2(SDOperand Op, SDOperand N, bool ARMDAGToDAGISel::SelectAddrMode2(SDOperand Op, SDOperand N,

View File

@ -161,9 +161,9 @@ namespace {
// target-specific node if it hasn't already been changed. // target-specific node if it hasn't already been changed.
SDNode *Select(SDOperand Op); SDNode *Select(SDOperand Op);
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); virtual void InstructionSelect(SelectionDAG &DAG);
virtual const char *getPassName() const { virtual const char *getPassName() const {
return "Alpha DAG->DAG Pattern Instruction Selection"; return "Alpha DAG->DAG Pattern Instruction Selection";
@ -230,17 +230,14 @@ SDOperand AlphaDAGToDAGISel::getGlobalRetAddr() {
RA, MVT::i64); RA, MVT::i64);
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void AlphaDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { void AlphaDAGToDAGISel::InstructionSelect(SelectionDAG &DAG) {
DEBUG(BB->dump()); DEBUG(BB->dump());
// Select target instructions for the DAG. // Select target instructions for the DAG.
DAG.setRoot(SelectRoot(DAG.getRoot())); DAG.setRoot(SelectRoot(DAG.getRoot()));
DAG.RemoveDeadNodes(); DAG.RemoveDeadNodes();
// Emit machine code to BB.
ScheduleAndEmitDAG(DAG);
} }
// Select - Convert the specified operand from a target-independent to a // Select - Convert the specified operand from a target-independent to a

View File

@ -317,9 +317,9 @@ public:
return false; return false;
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); virtual void InstructionSelect(SelectionDAG &DAG);
virtual const char *getPassName() const { virtual const char *getPassName() const {
return "Cell SPU DAG->DAG Pattern Instruction Selection"; return "Cell SPU DAG->DAG Pattern Instruction Selection";
@ -339,19 +339,16 @@ public:
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void void
SPUDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) SPUDAGToDAGISel::InstructionSelect(SelectionDAG &DAG)
{ {
DEBUG(BB->dump()); DEBUG(BB->dump());
// Select target instructions for the DAG. // Select target instructions for the DAG.
DAG.setRoot(SelectRoot(DAG.getRoot())); DAG.setRoot(SelectRoot(DAG.getRoot()));
DAG.RemoveDeadNodes(); DAG.RemoveDeadNodes();
// Emit machine code to BB.
ScheduleAndEmitDAG(DAG);
} }
/*! /*!

View File

@ -78,9 +78,9 @@ namespace {
/// operation. /// operation.
bool SelectAddr(SDOperand Addr, SDOperand &Op1, SDOperand &Op2); bool SelectAddr(SDOperand Addr, SDOperand &Op1, SDOperand &Op2);
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); virtual void InstructionSelect(SelectionDAG &DAG);
virtual const char *getPassName() const { virtual const char *getPassName() const {
return "IA64 (Itanium) DAG->DAG Instruction Selector"; return "IA64 (Itanium) DAG->DAG Instruction Selector";
@ -94,17 +94,14 @@ private:
}; };
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void IA64DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { void IA64DAGToDAGISel::InstructionSelect(SelectionDAG &DAG) {
DEBUG(BB->dump()); DEBUG(BB->dump());
// Select target instructions for the DAG. // Select target instructions for the DAG.
DAG.setRoot(SelectRoot(DAG.getRoot())); DAG.setRoot(SelectRoot(DAG.getRoot()));
DAG.RemoveDeadNodes(); DAG.RemoveDeadNodes();
// Emit machine code to BB.
ScheduleAndEmitDAG(DAG);
} }
SDNode *IA64DAGToDAGISel::SelectDIV(SDOperand Op) { SDNode *IA64DAGToDAGISel::SelectDIV(SDOperand Op) {

View File

@ -66,7 +66,7 @@ public:
SelectionDAGISel(MipsLowering), SelectionDAGISel(MipsLowering),
TM(tm), MipsLowering(*TM.getTargetLowering()) {} TM(tm), MipsLowering(*TM.getTargetLowering()) {}
virtual void InstructionSelectBasicBlock(SelectionDAG &SD); virtual void InstructionSelect(SelectionDAG &SD);
// Pass Name // Pass Name
virtual const char *getPassName() const { virtual const char *getPassName() const {
@ -100,10 +100,10 @@ private:
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void MipsDAGToDAGISel:: void MipsDAGToDAGISel::
InstructionSelectBasicBlock(SelectionDAG &SD) InstructionSelect(SelectionDAG &SD)
{ {
DEBUG(BB->dump()); DEBUG(BB->dump());
// Codegen the basic block. // Codegen the basic block.
@ -120,9 +120,6 @@ InstructionSelectBasicBlock(SelectionDAG &SD)
#endif #endif
SD.RemoveDeadNodes(); SD.RemoveDeadNodes();
// Emit machine code to BB.
ScheduleAndEmitDAG(SD);
} }
/// getGlobalBaseReg - Output the instructions required to put the /// getGlobalBaseReg - Output the instructions required to put the

View File

@ -61,7 +61,7 @@ public:
SelectionDAGISel(PIC16Lowering), SelectionDAGISel(PIC16Lowering),
TM(tm), PIC16Lowering(*TM.getTargetLowering()) {} TM(tm), PIC16Lowering(*TM.getTargetLowering()) {}
virtual void InstructionSelectBasicBlock(SelectionDAG &SD); virtual void InstructionSelect(SelectionDAG &SD);
// Pass Name // Pass Name
virtual const char *getPassName() const { virtual const char *getPassName() const {
@ -97,9 +97,9 @@ private:
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void PIC16DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &SD) void PIC16DAGToDAGISel::InstructionSelect(SelectionDAG &SD)
{ {
DEBUG(BB->dump()); DEBUG(BB->dump());
// Codegen the basic block. // Codegen the basic block.
@ -115,9 +115,6 @@ void PIC16DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &SD)
DOUT << "===== Instruction selection ends:\n"; DOUT << "===== Instruction selection ends:\n";
SD.RemoveDeadNodes(); SD.RemoveDeadNodes();
// Emit machine code to BB.
ScheduleAndEmitDAG(SD);
} }

View File

@ -173,9 +173,9 @@ namespace {
SDOperand BuildSDIVSequence(SDNode *N); SDOperand BuildSDIVSequence(SDNode *N);
SDOperand BuildUDIVSequence(SDNode *N); SDOperand BuildUDIVSequence(SDNode *N);
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); virtual void InstructionSelect(SelectionDAG &DAG);
void InsertVRSaveCode(Function &Fn); void InsertVRSaveCode(Function &Fn);
@ -201,17 +201,14 @@ private:
}; };
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void PPCDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { void PPCDAGToDAGISel::InstructionSelect(SelectionDAG &DAG) {
DEBUG(BB->dump()); DEBUG(BB->dump());
// Select target instructions for the DAG. // Select target instructions for the DAG.
DAG.setRoot(SelectRoot(DAG.getRoot())); DAG.setRoot(SelectRoot(DAG.getRoot()));
DAG.RemoveDeadNodes(); DAG.RemoveDeadNodes();
// Emit machine code to BB.
ScheduleAndEmitDAG(DAG);
} }
/// InsertVRSaveCode - Once the entire function has been instruction selected, /// InsertVRSaveCode - Once the entire function has been instruction selected,

View File

@ -47,9 +47,9 @@ public:
bool SelectADDRri(SDOperand Op, SDOperand N, SDOperand &Base, bool SelectADDRri(SDOperand Op, SDOperand N, SDOperand &Base,
SDOperand &Offset); SDOperand &Offset);
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); virtual void InstructionSelect(SelectionDAG &DAG);
virtual const char *getPassName() const { virtual const char *getPassName() const {
return "SPARC DAG->DAG Pattern Instruction Selection"; return "SPARC DAG->DAG Pattern Instruction Selection";
@ -60,17 +60,14 @@ public:
}; };
} // end anonymous namespace } // end anonymous namespace
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void SparcDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { void SparcDAGToDAGISel::InstructionSelect(SelectionDAG &DAG) {
DEBUG(BB->dump()); DEBUG(BB->dump());
// Select target instructions for the DAG. // Select target instructions for the DAG.
DAG.setRoot(SelectRoot(DAG.getRoot())); DAG.setRoot(SelectRoot(DAG.getRoot()));
DAG.RemoveDeadNodes(); DAG.RemoveDeadNodes();
// Emit machine code to BB.
ScheduleAndEmitDAG(DAG);
} }
bool SparcDAGToDAGISel::SelectADDRri(SDOperand Op, SDOperand Addr, bool SparcDAGToDAGISel::SelectADDRri(SDOperand Op, SDOperand Addr,

View File

@ -32,7 +32,6 @@
#include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/SelectionDAGISel.h" #include "llvm/CodeGen/SelectionDAGISel.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
@ -111,6 +110,10 @@ namespace {
/// base register. /// base register.
unsigned GlobalBaseReg; unsigned GlobalBaseReg;
/// CurBB - Current BB being isel'd.
///
MachineBasicBlock *CurBB;
public: public:
X86DAGToDAGISel(X86TargetMachine &tm, bool fast) X86DAGToDAGISel(X86TargetMachine &tm, bool fast)
: SelectionDAGISel(X86Lowering), : SelectionDAGISel(X86Lowering),
@ -128,9 +131,13 @@ namespace {
return "X86 DAG->DAG Instruction Selection"; return "X86 DAG->DAG Instruction Selection";
} }
/// InstructionSelectBasicBlock - This callback is invoked by /// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen. /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); virtual void InstructionSelect(SelectionDAG &DAG);
/// InstructionSelectPostProcessing - Post processing of selected and
/// scheduled basic blocks.
virtual void InstructionSelectPostProcessing(SelectionDAG &DAG);
virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF); virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
@ -554,10 +561,10 @@ void X86DAGToDAGISel::PreprocessForFPConvert(SelectionDAG &DAG) {
/// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel /// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel
/// when it has created a SelectionDAG for us to codegen. /// when it has created a SelectionDAG for us to codegen.
void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { void X86DAGToDAGISel::InstructionSelect(SelectionDAG &DAG) {
DEBUG(BB->dump()); CurBB = BB; // BB can change as result of isel.
MachineFunction::iterator FirstMBB = BB;
DEBUG(BB->dump());
if (!FastISel) if (!FastISel)
PreprocessForRMW(DAG); PreprocessForRMW(DAG);
@ -575,11 +582,9 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
#endif #endif
DAG.RemoveDeadNodes(); DAG.RemoveDeadNodes();
}
// Emit machine code to BB. This can change 'BB' to the last block being void X86DAGToDAGISel::InstructionSelectPostProcessing(SelectionDAG &DAG) {
// inserted into.
ScheduleAndEmitDAG(DAG);
// If we are emitting FP stack code, scan the basic block to determine if this // If we are emitting FP stack code, scan the basic block to determine if this
// block defines any FP values. If so, put an FP_REG_KILL instruction before // block defines any FP values. If so, put an FP_REG_KILL instruction before
// the terminator of the block. // the terminator of the block.
@ -592,7 +597,7 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
// Scan all of the machine instructions in these MBBs, checking for FP // Scan all of the machine instructions in these MBBs, checking for FP
// stores. (RFP32 and RFP64 will not exist in SSE mode, but RFP80 might.) // stores. (RFP32 and RFP64 will not exist in SSE mode, but RFP80 might.)
MachineFunction::iterator MBBI = FirstMBB; MachineFunction::iterator MBBI = CurBB;
MachineFunction::iterator EndMBB = BB; ++EndMBB; MachineFunction::iterator EndMBB = BB; ++EndMBB;
for (; MBBI != EndMBB; ++MBBI) { for (; MBBI != EndMBB; ++MBBI) {
MachineBasicBlock *MBB = MBBI; MachineBasicBlock *MBB = MBBI;