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