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