Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===// |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 7ed47a1 | 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. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 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 | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 18 | #include "llvm/BasicBlock.h" |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 19 | #include "llvm/Pass.h" |
Nate Begeman | f15485a | 2006-03-27 01:32:24 +0000 | [diff] [blame] | 20 | #include "llvm/Constant.h" |
Evan Cheng | fe8dc2e | 2006-08-07 22:16:08 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/SelectionDAG.h" |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame] | 24 | class FastISel; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 25 | class SelectionDAGLowering; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 26 | class SDValue; |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 27 | class MachineRegisterInfo; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 28 | class MachineBasicBlock; |
| 29 | class MachineFunction; |
| 30 | class MachineInstr; |
Dan Gohman | d57dd5f | 2008-09-23 21:53:34 +0000 | [diff] [blame] | 31 | class MachineModuleInfo; |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 32 | class DwarfWriter; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 33 | class TargetLowering; |
Dan Gohman | dd5b58a | 2008-10-14 23:54:11 +0000 | [diff] [blame] | 34 | class TargetInstrInfo; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 35 | class FunctionLoweringInfo; |
Chris Lattner | 37e30cf | 2006-03-06 00:20:29 +0000 | [diff] [blame] | 36 | class HazardRecognizer; |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 37 | class GCFunctionInfo; |
Dan Gohman | 5e84368 | 2008-07-14 18:19:29 +0000 | [diff] [blame] | 38 | class ScheduleDAG; |
Anton Korobeynikov | d0b82b3 | 2007-03-07 16:25:09 +0000 | [diff] [blame] | 39 | |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 40 | /// SelectionDAGISel - This is the common base class used for SelectionDAG-based |
| 41 | /// pattern-matching instruction selectors. |
| 42 | class SelectionDAGISel : public FunctionPass { |
| 43 | public: |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame^] | 44 | const TargetMachine &TM; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 45 | TargetLowering &TLI; |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 46 | FunctionLoweringInfo *FuncInfo; |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame^] | 47 | MachineFunction *MF; |
| 48 | MachineRegisterInfo *RegInfo; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 49 | SelectionDAG *CurDAG; |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 50 | SelectionDAGLowering *SDL; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 51 | MachineBasicBlock *BB; |
Dan Gohman | 5f43f92 | 2007-08-27 16:26:13 +0000 | [diff] [blame] | 52 | AliasAnalysis *AA; |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 53 | GCFunctionInfo *GFI; |
Dan Gohman | 925a7e8 | 2008-08-13 19:47:40 +0000 | [diff] [blame] | 54 | bool Fast; |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 55 | static char ID; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 56 | |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame^] | 57 | explicit SelectionDAGISel(TargetMachine &tm, bool fast = false); |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 58 | virtual ~SelectionDAGISel(); |
Jim Laskey | 9373beb | 2006-08-01 19:14:14 +0000 | [diff] [blame] | 59 | |
| 60 | TargetLowering &getTargetLowering() { return TLI; } |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 61 | |
Chris Lattner | c809b68 | 2005-08-17 06:46:50 +0000 | [diff] [blame] | 62 | virtual void getAnalysisUsage(AnalysisUsage &AU) const; |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 63 | |
| 64 | virtual bool runOnFunction(Function &Fn); |
| 65 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 66 | unsigned MakeReg(MVT VT); |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 67 | |
Chris Lattner | cc13b76 | 2005-05-13 07:23:03 +0000 | [diff] [blame] | 68 | virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {} |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 69 | virtual void InstructionSelect() = 0; |
Evan Cheng | db8d56b | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 70 | |
Dan Gohman | 815ffa2 | 2008-08-21 16:06:51 +0000 | [diff] [blame] | 71 | void SelectRootInit() { |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 72 | DAGSize = CurDAG->AssignTopologicalOrder(); |
Evan Cheng | fe8dc2e | 2006-08-07 22:16:08 +0000 | [diff] [blame] | 73 | } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 4c12e71 | 2006-02-24 02:12:52 +0000 | [diff] [blame] | 75 | /// SelectInlineAsmMemoryOperand - Select the specified address as a target |
| 76 | /// addressing mode, according to the specified constraint code. If this does |
| 77 | /// not match or is not implemented, return true. The resultant operands |
| 78 | /// (which will appear in the machine instruction) should be added to the |
| 79 | /// OutOps vector. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 80 | virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, |
Chris Lattner | 4c12e71 | 2006-02-24 02:12:52 +0000 | [diff] [blame] | 81 | char ConstraintCode, |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 82 | std::vector<SDValue> &OutOps) { |
Chris Lattner | 4c12e71 | 2006-02-24 02:12:52 +0000 | [diff] [blame] | 83 | return true; |
| 84 | } |
Evan Cheng | b2c121a | 2006-07-27 06:36:49 +0000 | [diff] [blame] | 85 | |
Evan Cheng | 884c70c | 2008-11-27 00:49:46 +0000 | [diff] [blame] | 86 | /// IsLegalAndProfitableToFold - Returns true if the specific operand node N of |
| 87 | /// U can be folded during instruction selection that starts at Root and |
| 88 | /// folding N is profitable. |
| 89 | virtual |
| 90 | bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U, SDNode *Root) const { |
Dan Gohman | dc9b3d0 | 2007-07-24 23:00:27 +0000 | [diff] [blame] | 91 | return true; |
| 92 | } |
Chris Lattner | 4c12e71 | 2006-02-24 02:12:52 +0000 | [diff] [blame] | 93 | |
Jim Laskey | 9ff542f | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 94 | /// CreateTargetHazardRecognizer - Return a newly allocated hazard recognizer |
| 95 | /// to use for this target when scheduling the DAG. |
| 96 | virtual HazardRecognizer *CreateTargetHazardRecognizer(); |
| 97 | |
Chris Lattner | 66bac3c | 2005-08-18 18:44:33 +0000 | [diff] [blame] | 98 | protected: |
Evan Cheng | e2c0a4f | 2008-07-01 18:49:06 +0000 | [diff] [blame] | 99 | /// DAGSize - Size of DAG being instruction selected. |
| 100 | /// |
| 101 | unsigned DAGSize; |
| 102 | |
Chris Lattner | 4c12e71 | 2006-02-24 02:12:52 +0000 | [diff] [blame] | 103 | /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated |
| 104 | /// by tblgen. Others should not call it. |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 105 | void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops); |
Evan Cheng | b2c121a | 2006-07-27 06:36:49 +0000 | [diff] [blame] | 106 | |
Chris Lattner | 7554806 | 2006-10-11 03:58:02 +0000 | [diff] [blame] | 107 | // Calls to these predicates are generated by tblgen. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 108 | bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS, |
Dan Gohman | dc9b3d0 | 2007-07-24 23:00:27 +0000 | [diff] [blame] | 109 | int64_t DesiredMaskS) const; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 110 | bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS, |
Dan Gohman | dc9b3d0 | 2007-07-24 23:00:27 +0000 | [diff] [blame] | 111 | int64_t DesiredMaskS) const; |
Chris Lattner | 7554806 | 2006-10-11 03:58:02 +0000 | [diff] [blame] | 112 | |
Chris Lattner | 80d8a93 | 2005-01-17 17:14:43 +0000 | [diff] [blame] | 113 | private: |
Dan Gohman | d57dd5f | 2008-09-23 21:53:34 +0000 | [diff] [blame] | 114 | void SelectAllBasicBlocks(Function &Fn, MachineFunction &MF, |
Dan Gohman | dd5b58a | 2008-10-14 23:54:11 +0000 | [diff] [blame] | 115 | MachineModuleInfo *MMI, |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 116 | DwarfWriter *DW, |
Dan Gohman | dd5b58a | 2008-10-14 23:54:11 +0000 | [diff] [blame] | 117 | const TargetInstrInfo &TII); |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 118 | void FinishBasicBlock(); |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 119 | |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 120 | void SelectBasicBlock(BasicBlock *LLVMBB, |
| 121 | BasicBlock::iterator Begin, |
Dan Gohman | 5edd361 | 2008-08-28 20:28:56 +0000 | [diff] [blame] | 122 | BasicBlock::iterator End); |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 123 | void CodeGenAndEmitDAG(); |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 124 | void LowerArguments(BasicBlock *BB); |
Chris Lattner | ead0d88 | 2008-06-17 06:09:18 +0000 | [diff] [blame] | 125 | |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 126 | void ComputeLiveOutVRegInfo(); |
| 127 | |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 128 | void HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB); |
Nate Begeman | f15485a | 2006-03-27 01:32:24 +0000 | [diff] [blame] | 129 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame] | 130 | bool HandlePHINodesInSuccessorBlocksFast(BasicBlock *LLVMBB, FastISel *F); |
| 131 | |
Dan Gohman | 5e84368 | 2008-07-14 18:19:29 +0000 | [diff] [blame] | 132 | /// Pick a safe ordering for instructions for each target node in the |
Evan Cheng | db8d56b | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 133 | /// graph. |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 134 | ScheduleDAG *Schedule(); |
Chris Lattner | cc524ca | 2005-01-07 07:46:03 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | } |
| 138 | |
| 139 | #endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */ |