blob: 072cb0c323984a5fbda98bc88b4d39836bc99f99 [file] [log] [blame]
Chris Lattnercc524ca2005-01-07 07:46:03 +00001//===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===//
Misha Brukmanea61c352005-04-21 20:39:54 +00002//
Chris Lattnercc524ca2005-01-07 07:46:03 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner7ed47a12007-12-29 19:59:42 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanea61c352005-04-21 20:39:54 +00007//
Chris Lattnercc524ca2005-01-07 07:46:03 +00008//===----------------------------------------------------------------------===//
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 Gohmanf350b272008-08-23 02:25:05 +000018#include "llvm/BasicBlock.h"
Chris Lattnercc524ca2005-01-07 07:46:03 +000019#include "llvm/Pass.h"
Nate Begemanf15485a2006-03-27 01:32:24 +000020#include "llvm/Constant.h"
Evan Chengfe8dc2e2006-08-07 22:16:08 +000021#include "llvm/CodeGen/SelectionDAG.h"
Chris Lattnercc524ca2005-01-07 07:46:03 +000022
23namespace llvm {
Dan Gohman3df24e62008-09-03 23:12:08 +000024 class FastISel;
Chris Lattnercc524ca2005-01-07 07:46:03 +000025 class SelectionDAGLowering;
Dan Gohman475871a2008-07-27 21:46:04 +000026 class SDValue;
Chris Lattner84bc5422007-12-31 04:13:23 +000027 class MachineRegisterInfo;
Chris Lattnercc524ca2005-01-07 07:46:03 +000028 class MachineBasicBlock;
29 class MachineFunction;
30 class MachineInstr;
Dan Gohmand57dd5f2008-09-23 21:53:34 +000031 class MachineModuleInfo;
Devang Patel83489bb2009-01-13 00:35:13 +000032 class DwarfWriter;
Chris Lattnercc524ca2005-01-07 07:46:03 +000033 class TargetLowering;
Dan Gohmandd5b58a2008-10-14 23:54:11 +000034 class TargetInstrInfo;
Chris Lattnercc524ca2005-01-07 07:46:03 +000035 class FunctionLoweringInfo;
Chris Lattner37e30cf2006-03-06 00:20:29 +000036 class HazardRecognizer;
Gordon Henriksen5eca0752008-08-17 18:44:35 +000037 class GCFunctionInfo;
Dan Gohman5e843682008-07-14 18:19:29 +000038 class ScheduleDAG;
Anton Korobeynikovd0b82b32007-03-07 16:25:09 +000039
Chris Lattnercc524ca2005-01-07 07:46:03 +000040/// SelectionDAGISel - This is the common base class used for SelectionDAG-based
41/// pattern-matching instruction selectors.
42class SelectionDAGISel : public FunctionPass {
43public:
Dan Gohman79ce2762009-01-15 19:20:50 +000044 const TargetMachine &TM;
Chris Lattnercc524ca2005-01-07 07:46:03 +000045 TargetLowering &TLI;
Dan Gohman7c3234c2008-08-27 23:52:12 +000046 FunctionLoweringInfo *FuncInfo;
Dan Gohman79ce2762009-01-15 19:20:50 +000047 MachineFunction *MF;
48 MachineRegisterInfo *RegInfo;
Chris Lattnercc524ca2005-01-07 07:46:03 +000049 SelectionDAG *CurDAG;
Dan Gohman7c3234c2008-08-27 23:52:12 +000050 SelectionDAGLowering *SDL;
Chris Lattnercc524ca2005-01-07 07:46:03 +000051 MachineBasicBlock *BB;
Dan Gohman5f43f922007-08-27 16:26:13 +000052 AliasAnalysis *AA;
Gordon Henriksen5eca0752008-08-17 18:44:35 +000053 GCFunctionInfo *GFI;
Dan Gohman925a7e82008-08-13 19:47:40 +000054 bool Fast;
Devang Patel19974732007-05-03 01:11:54 +000055 static char ID;
Chris Lattnercc524ca2005-01-07 07:46:03 +000056
Dan Gohman79ce2762009-01-15 19:20:50 +000057 explicit SelectionDAGISel(TargetMachine &tm, bool fast = false);
Dan Gohman7c3234c2008-08-27 23:52:12 +000058 virtual ~SelectionDAGISel();
Jim Laskey9373beb2006-08-01 19:14:14 +000059
60 TargetLowering &getTargetLowering() { return TLI; }
Chris Lattnercc524ca2005-01-07 07:46:03 +000061
Chris Lattnerc809b682005-08-17 06:46:50 +000062 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
Chris Lattnercc524ca2005-01-07 07:46:03 +000063
64 virtual bool runOnFunction(Function &Fn);
65
Duncan Sands83ec4b62008-06-06 12:08:01 +000066 unsigned MakeReg(MVT VT);
Chris Lattnercc524ca2005-01-07 07:46:03 +000067
Chris Lattnercc13b762005-05-13 07:23:03 +000068 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {}
Dan Gohmanf350b272008-08-23 02:25:05 +000069 virtual void InstructionSelect() = 0;
Evan Chengdb8d56b2008-06-30 20:45:06 +000070
Dan Gohman815ffa22008-08-21 16:06:51 +000071 void SelectRootInit() {
Dan Gohmanf06c8352008-09-30 18:30:35 +000072 DAGSize = CurDAG->AssignTopologicalOrder();
Evan Chengfe8dc2e2006-08-07 22:16:08 +000073 }
Misha Brukmanea61c352005-04-21 20:39:54 +000074
Chris Lattner4c12e712006-02-24 02:12:52 +000075 /// 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 Gohman475871a2008-07-27 21:46:04 +000080 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
Chris Lattner4c12e712006-02-24 02:12:52 +000081 char ConstraintCode,
Dan Gohmanf350b272008-08-23 02:25:05 +000082 std::vector<SDValue> &OutOps) {
Chris Lattner4c12e712006-02-24 02:12:52 +000083 return true;
84 }
Evan Chengb2c121a2006-07-27 06:36:49 +000085
Evan Cheng884c70c2008-11-27 00:49:46 +000086 /// 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 Gohmandc9b3d02007-07-24 23:00:27 +000091 return true;
92 }
Chris Lattner4c12e712006-02-24 02:12:52 +000093
Jim Laskey9ff542f2006-08-01 18:29:48 +000094 /// CreateTargetHazardRecognizer - Return a newly allocated hazard recognizer
95 /// to use for this target when scheduling the DAG.
96 virtual HazardRecognizer *CreateTargetHazardRecognizer();
97
Chris Lattner66bac3c2005-08-18 18:44:33 +000098protected:
Evan Chenge2c0a4f2008-07-01 18:49:06 +000099 /// DAGSize - Size of DAG being instruction selected.
100 ///
101 unsigned DAGSize;
102
Chris Lattner4c12e712006-02-24 02:12:52 +0000103 /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
104 /// by tblgen. Others should not call it.
Dan Gohmanf350b272008-08-23 02:25:05 +0000105 void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops);
Evan Chengb2c121a2006-07-27 06:36:49 +0000106
Chris Lattner75548062006-10-11 03:58:02 +0000107 // Calls to these predicates are generated by tblgen.
Dan Gohman475871a2008-07-27 21:46:04 +0000108 bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS,
Dan Gohmandc9b3d02007-07-24 23:00:27 +0000109 int64_t DesiredMaskS) const;
Dan Gohman475871a2008-07-27 21:46:04 +0000110 bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS,
Dan Gohmandc9b3d02007-07-24 23:00:27 +0000111 int64_t DesiredMaskS) const;
Chris Lattner75548062006-10-11 03:58:02 +0000112
Chris Lattner80d8a932005-01-17 17:14:43 +0000113private:
Dan Gohmand57dd5f2008-09-23 21:53:34 +0000114 void SelectAllBasicBlocks(Function &Fn, MachineFunction &MF,
Dan Gohmandd5b58a2008-10-14 23:54:11 +0000115 MachineModuleInfo *MMI,
Devang Patel83489bb2009-01-13 00:35:13 +0000116 DwarfWriter *DW,
Dan Gohmandd5b58a2008-10-14 23:54:11 +0000117 const TargetInstrInfo &TII);
Dan Gohman7c3234c2008-08-27 23:52:12 +0000118 void FinishBasicBlock();
Misha Brukmanea61c352005-04-21 20:39:54 +0000119
Dan Gohmanf350b272008-08-23 02:25:05 +0000120 void SelectBasicBlock(BasicBlock *LLVMBB,
121 BasicBlock::iterator Begin,
Dan Gohman5edd3612008-08-28 20:28:56 +0000122 BasicBlock::iterator End);
Dan Gohmanf350b272008-08-23 02:25:05 +0000123 void CodeGenAndEmitDAG();
Dan Gohman7c3234c2008-08-27 23:52:12 +0000124 void LowerArguments(BasicBlock *BB);
Chris Lattneread0d882008-06-17 06:09:18 +0000125
Dan Gohmanf350b272008-08-23 02:25:05 +0000126 void ComputeLiveOutVRegInfo();
127
Dan Gohman7c3234c2008-08-27 23:52:12 +0000128 void HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB);
Nate Begemanf15485a2006-03-27 01:32:24 +0000129
Dan Gohman3df24e62008-09-03 23:12:08 +0000130 bool HandlePHINodesInSuccessorBlocksFast(BasicBlock *LLVMBB, FastISel *F);
131
Dan Gohman5e843682008-07-14 18:19:29 +0000132 /// Pick a safe ordering for instructions for each target node in the
Evan Chengdb8d56b2008-06-30 20:45:06 +0000133 /// graph.
Dan Gohmanf350b272008-08-23 02:25:05 +0000134 ScheduleDAG *Schedule();
Chris Lattnercc524ca2005-01-07 07:46:03 +0000135};
136
137}
138
139#endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */