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