Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 84e66db | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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 | |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 18 | #include "llvm/BasicBlock.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 19 | #include "llvm/Pass.h" |
| 20 | #include "llvm/Constant.h" |
| 21 | #include "llvm/CodeGen/SelectionDAG.h" |
Dan Gohman | fdf9ee2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
Dan Gohman | ca4857a | 2008-09-03 23:12:08 +0000 | [diff] [blame] | 25 | class FastISel; |
Dan Gohman | 7ec2051 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 26 | class SelectionDAGBuilder; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 27 | class SDValue; |
Chris Lattner | 1b98919 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 28 | class MachineRegisterInfo; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 29 | class MachineBasicBlock; |
| 30 | class MachineFunction; |
| 31 | class MachineInstr; |
Dan Gohman | 76dd96e | 2008-09-23 21:53:34 +0000 | [diff] [blame] | 32 | class MachineModuleInfo; |
Devang Patel | fcf1c75 | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 33 | class DwarfWriter; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 34 | class TargetLowering; |
Dan Gohman | 9dd4358 | 2008-10-14 23:54:11 +0000 | [diff] [blame] | 35 | class TargetInstrInfo; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 36 | class FunctionLoweringInfo; |
Dan Gohman | dd6547d | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 37 | class ScheduleHazardRecognizer; |
Gordon Henriksen | 1aed599 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 38 | class GCFunctionInfo; |
Dan Gohman | 7c968a8 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 39 | class ScheduleDAGSDNodes; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 40 | |
| 41 | /// SelectionDAGISel - This is the common base class used for SelectionDAG-based |
| 42 | /// pattern-matching instruction selectors. |
Dan Gohman | fdf9ee2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 43 | class SelectionDAGISel : public MachineFunctionPass { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 44 | public: |
Dan Gohman | 96eb47a | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 45 | const TargetMachine &TM; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 46 | TargetLowering &TLI; |
Dan Gohman | 0f2d71d | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 47 | FunctionLoweringInfo *FuncInfo; |
Dan Gohman | 96eb47a | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 48 | MachineFunction *MF; |
| 49 | MachineRegisterInfo *RegInfo; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 50 | SelectionDAG *CurDAG; |
Dan Gohman | 7ec2051 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 51 | SelectionDAGBuilder *SDB; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 52 | MachineBasicBlock *BB; |
Dan Gohman | cc863aa | 2007-08-27 16:26:13 +0000 | [diff] [blame] | 53 | AliasAnalysis *AA; |
Gordon Henriksen | 1aed599 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 54 | GCFunctionInfo *GFI; |
Bill Wendling | 5ed22ac | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 55 | CodeGenOpt::Level OptLevel; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 56 | static char ID; |
| 57 | |
Bill Wendling | 5ed22ac | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 58 | explicit SelectionDAGISel(TargetMachine &tm, |
| 59 | CodeGenOpt::Level OL = CodeGenOpt::Default); |
Dan Gohman | 0f2d71d | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 60 | virtual ~SelectionDAGISel(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 61 | |
| 62 | TargetLowering &getTargetLowering() { return TLI; } |
| 63 | |
| 64 | virtual void getAnalysisUsage(AnalysisUsage &AU) const; |
| 65 | |
Dan Gohman | fdf9ee2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 66 | virtual bool runOnMachineFunction(MachineFunction &MF); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 67 | |
Owen Anderson | ac9de03 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 68 | unsigned MakeReg(EVT VT); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 69 | |
| 70 | virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {} |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 71 | virtual void InstructionSelect() = 0; |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 72 | |
Dan Gohman | 6a4a536 | 2008-08-21 16:06:51 +0000 | [diff] [blame] | 73 | void SelectRootInit() { |
Dan Gohman | 2d2a7a3 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 74 | DAGSize = CurDAG->AssignTopologicalOrder(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /// SelectInlineAsmMemoryOperand - Select the specified address as a target |
| 78 | /// addressing mode, according to the specified constraint code. If this does |
| 79 | /// not match or is not implemented, return true. The resultant operands |
| 80 | /// (which will appear in the machine instruction) should be added to the |
| 81 | /// OutOps vector. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 82 | virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 83 | char ConstraintCode, |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 84 | std::vector<SDValue> &OutOps) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 85 | return true; |
| 86 | } |
| 87 | |
Evan Cheng | f80681e | 2010-02-15 19:41:07 +0000 | [diff] [blame] | 88 | /// IsProfitableToFold - Returns true if it's profitable to fold the specific |
| 89 | /// operand node N of U during instruction selection that starts at Root. |
| 90 | virtual bool IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const; |
| 91 | |
| 92 | /// IsLegalToFold - Returns true if the specific operand node N of |
| 93 | /// U can be folded during instruction selection that starts at Root. |
| 94 | virtual bool IsLegalToFold(SDValue N, SDNode *U, SDNode *Root) const; |
Anton Korobeynikov | da76d32 | 2009-05-08 18:51:58 +0000 | [diff] [blame] | 95 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 96 | /// CreateTargetHazardRecognizer - Return a newly allocated hazard recognizer |
| 97 | /// to use for this target when scheduling the DAG. |
Dan Gohman | dd6547d | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 98 | virtual ScheduleHazardRecognizer *CreateTargetHazardRecognizer(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 99 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 100 | protected: |
Evan Cheng | 220dfe8 | 2008-07-01 18:49:06 +0000 | [diff] [blame] | 101 | /// DAGSize - Size of DAG being instruction selected. |
| 102 | /// |
| 103 | unsigned DAGSize; |
| 104 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 105 | /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated |
| 106 | /// by tblgen. Others should not call it. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 107 | void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 108 | |
| 109 | // Calls to these predicates are generated by tblgen. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 110 | bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS, |
Dan Gohman | d609827 | 2007-07-24 23:00:27 +0000 | [diff] [blame] | 111 | int64_t DesiredMaskS) const; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 112 | bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS, |
Dan Gohman | d609827 | 2007-07-24 23:00:27 +0000 | [diff] [blame] | 113 | int64_t DesiredMaskS) const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 114 | |
Chris Lattner | fdbdc8c | 2010-02-16 07:21:10 +0000 | [diff] [blame] | 115 | |
| 116 | /// CheckPatternPredicate - This function is generated by tblgen in the |
| 117 | /// target. It runs the specified pattern predicate and returns true if it |
| 118 | /// succeeds or false if it fails. The number is a private implementation |
| 119 | /// detail to the code tblgen produces. |
| 120 | virtual bool CheckPatternPredicate(unsigned PredNo) const { |
| 121 | assert(0 && "Tblgen should generate the implementation of this!"); |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /// CheckNodePredicate - This function is generated by tblgen in the |
| 126 | /// target. It runs node predicate #PredNo and returns true if it succeeds or |
| 127 | /// false if it fails. The number is a private implementation |
| 128 | /// detail to the code tblgen produces. |
| 129 | virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const { |
| 130 | assert(0 && "Tblgen should generate the implementation of this!"); |
| 131 | return 0; |
| 132 | } |
| 133 | |
Chris Lattner | 4a37ffb2 | 2010-02-17 00:41:34 +0000 | [diff] [blame^] | 134 | virtual bool CheckComplexPattern(SDNode *Root, SDValue N, unsigned PatternNo, |
| 135 | SmallVectorImpl<SDValue> &Result) { |
| 136 | assert(0 && "Tblgen should generate the implementation of this!"); |
| 137 | return false; |
| 138 | } |
| 139 | |
Dan Gohman | b65e3ac | 2009-10-29 22:30:23 +0000 | [diff] [blame] | 140 | // Calls to these functions are generated by tblgen. |
Dan Gohman | 5f082a7 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 141 | SDNode *Select_INLINEASM(SDNode *N); |
| 142 | SDNode *Select_UNDEF(SDNode *N); |
| 143 | SDNode *Select_EH_LABEL(SDNode *N); |
| 144 | void CannotYetSelect(SDNode *N); |
| 145 | void CannotYetSelectIntrinsic(SDNode *N); |
Dan Gohman | b65e3ac | 2009-10-29 22:30:23 +0000 | [diff] [blame] | 146 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 147 | private: |
Dan Gohman | 76dd96e | 2008-09-23 21:53:34 +0000 | [diff] [blame] | 148 | void SelectAllBasicBlocks(Function &Fn, MachineFunction &MF, |
Dan Gohman | 9dd4358 | 2008-10-14 23:54:11 +0000 | [diff] [blame] | 149 | MachineModuleInfo *MMI, |
Devang Patel | fcf1c75 | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 150 | DwarfWriter *DW, |
Dan Gohman | 9dd4358 | 2008-10-14 23:54:11 +0000 | [diff] [blame] | 151 | const TargetInstrInfo &TII); |
Dan Gohman | 0f2d71d | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 152 | void FinishBasicBlock(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 153 | |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 154 | void SelectBasicBlock(BasicBlock *LLVMBB, |
| 155 | BasicBlock::iterator Begin, |
Dan Gohman | 40b0a2e | 2009-11-20 02:51:26 +0000 | [diff] [blame] | 156 | BasicBlock::iterator End, |
| 157 | bool &HadTailCall); |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 158 | void CodeGenAndEmitDAG(); |
Dan Gohman | 0f2d71d | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 159 | void LowerArguments(BasicBlock *BB); |
Chris Lattner | 68068cc | 2008-06-17 06:09:18 +0000 | [diff] [blame] | 160 | |
Evan Cheng | 095dac2 | 2010-01-06 19:38:29 +0000 | [diff] [blame] | 161 | void ShrinkDemandedOps(); |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 162 | void ComputeLiveOutVRegInfo(); |
| 163 | |
Dan Gohman | 0f2d71d | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 164 | void HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 165 | |
Dan Gohman | ca4857a | 2008-09-03 23:12:08 +0000 | [diff] [blame] | 166 | bool HandlePHINodesInSuccessorBlocksFast(BasicBlock *LLVMBB, FastISel *F); |
| 167 | |
Dan Gohman | 29800e2 | 2009-02-06 18:26:51 +0000 | [diff] [blame] | 168 | /// Create the scheduler. If a specific scheduler was specified |
| 169 | /// via the SchedulerRegistry, use it, otherwise select the |
| 170 | /// one preferred by the target. |
| 171 | /// |
Dan Gohman | 7c968a8 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 172 | ScheduleDAGSDNodes *CreateScheduler(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | } |
| 176 | |
| 177 | #endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */ |