Reorganize the lifetimes of the major objects SelectionDAGISel
[oota-llvm.git] / include / llvm / CodeGen / SelectionDAGISel.h
1 //===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===//
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 file implements the SelectionDAGISel class, which is used as the common
11 // base class for SelectionDAG-based instruction selectors.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_SELECTIONDAG_ISEL_H
16 #define LLVM_CODEGEN_SELECTIONDAG_ISEL_H
17
18 #include "llvm/BasicBlock.h"
19 #include "llvm/Pass.h"
20 #include "llvm/Constant.h"
21 #include "llvm/CodeGen/SelectionDAG.h"
22
23 namespace llvm {
24   class SelectionDAGLowering;
25   class SDValue;
26   class MachineRegisterInfo;
27   class MachineBasicBlock;
28   class MachineFunction;
29   class MachineInstr;
30   class TargetLowering;
31   class FunctionLoweringInfo;
32   class HazardRecognizer;
33   class GCFunctionInfo;
34   class ScheduleDAG;
35  
36 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
37 /// pattern-matching instruction selectors.
38 class SelectionDAGISel : public FunctionPass {
39 public:
40   TargetLowering &TLI;
41   MachineRegisterInfo *RegInfo;
42   FunctionLoweringInfo *FuncInfo;
43   SelectionDAG *CurDAG;
44   SelectionDAGLowering *SDL;
45   MachineBasicBlock *BB;
46   AliasAnalysis *AA;
47   GCFunctionInfo *GFI;
48   bool Fast;
49   std::vector<SDNode*> TopOrder;
50   static char ID;
51
52   explicit SelectionDAGISel(TargetLowering &tli, bool fast = false);
53   virtual ~SelectionDAGISel();
54   
55   TargetLowering &getTargetLowering() { return TLI; }
56
57   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
58
59   virtual bool runOnFunction(Function &Fn);
60
61   unsigned MakeReg(MVT VT);
62
63   virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {}
64   virtual void InstructionSelect() = 0;
65   virtual void InstructionSelectPostProcessing() {}
66   
67   void SelectRootInit() {
68     DAGSize = CurDAG->AssignTopologicalOrder(TopOrder);
69   }
70
71   /// SelectInlineAsmMemoryOperand - Select the specified address as a target
72   /// addressing mode, according to the specified constraint code.  If this does
73   /// not match or is not implemented, return true.  The resultant operands
74   /// (which will appear in the machine instruction) should be added to the
75   /// OutOps vector.
76   virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
77                                             char ConstraintCode,
78                                             std::vector<SDValue> &OutOps) {
79     return true;
80   }
81
82   /// CanBeFoldedBy - Returns true if the specific operand node N of U can be
83   /// folded during instruction selection that starts at Root?
84   virtual bool CanBeFoldedBy(SDNode *N, SDNode *U, SDNode *Root) const {
85     return true;
86   }
87   
88   /// CreateTargetHazardRecognizer - Return a newly allocated hazard recognizer
89   /// to use for this target when scheduling the DAG.
90   virtual HazardRecognizer *CreateTargetHazardRecognizer();
91   
92 protected:
93   /// DAGSize - Size of DAG being instruction selected.
94   ///
95   unsigned DAGSize;
96
97   /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
98   /// by tblgen.  Others should not call it.
99   void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops);
100
101   // Calls to these predicates are generated by tblgen.
102   bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS,
103                     int64_t DesiredMaskS) const;
104   bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS,
105                     int64_t DesiredMaskS) const;
106   
107 private:
108   void SelectAllBasicBlocks(Function &Fn, MachineFunction &MF);
109   void FinishBasicBlock();
110
111   void SelectBasicBlock(BasicBlock *LLVMBB,
112                         BasicBlock::iterator Begin,
113                         BasicBlock::iterator End,
114                         bool DoArgs);
115   void CodeGenAndEmitDAG();
116   void LowerArguments(BasicBlock *BB);
117   
118   void ComputeLiveOutVRegInfo();
119
120   void HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB);
121
122   /// Pick a safe ordering for instructions for each target node in the
123   /// graph.
124   ScheduleDAG *Schedule();
125 };
126
127 }
128
129 #endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */