1 //===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the SelectionDAGISel class, which is used as the common
11 // base class for SelectionDAG-based instruction selectors.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_SELECTIONDAG_ISEL_H
16 #define LLVM_CODEGEN_SELECTIONDAG_ISEL_H
18 #include "llvm/BasicBlock.h"
19 #include "llvm/Pass.h"
20 #include "llvm/Constant.h"
21 #include "llvm/CodeGen/SelectionDAG.h"
24 class SelectionDAGLowering;
26 class MachineRegisterInfo;
27 class MachineBasicBlock;
28 class MachineFunction;
31 class FunctionLoweringInfo;
32 class HazardRecognizer;
36 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
37 /// pattern-matching instruction selectors.
38 class SelectionDAGISel : public FunctionPass {
41 MachineRegisterInfo *RegInfo;
42 FunctionLoweringInfo *FuncInfo;
44 SelectionDAGLowering *SDL;
45 MachineBasicBlock *BB;
49 std::vector<SDNode*> TopOrder;
52 explicit SelectionDAGISel(TargetLowering &tli, bool fast = false);
53 virtual ~SelectionDAGISel();
55 TargetLowering &getTargetLowering() { return TLI; }
57 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
59 virtual bool runOnFunction(Function &Fn);
61 unsigned MakeReg(MVT VT);
63 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {}
64 virtual void InstructionSelect() = 0;
65 virtual void InstructionSelectPostProcessing() {}
67 void SelectRootInit() {
68 DAGSize = CurDAG->AssignTopologicalOrder(TopOrder);
71 /// SelectInlineAsmMemoryOperand - Select the specified address as a target
72 /// addressing mode, according to the specified constraint code. If this does
73 /// not match or is not implemented, return true. The resultant operands
74 /// (which will appear in the machine instruction) should be added to the
76 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
78 std::vector<SDValue> &OutOps) {
82 /// CanBeFoldedBy - Returns true if the specific operand node N of U can be
83 /// folded during instruction selection that starts at Root?
84 virtual bool CanBeFoldedBy(SDNode *N, SDNode *U, SDNode *Root) const {
88 /// CreateTargetHazardRecognizer - Return a newly allocated hazard recognizer
89 /// to use for this target when scheduling the DAG.
90 virtual HazardRecognizer *CreateTargetHazardRecognizer();
93 /// DAGSize - Size of DAG being instruction selected.
97 /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
98 /// by tblgen. Others should not call it.
99 void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops);
101 // Calls to these predicates are generated by tblgen.
102 bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS,
103 int64_t DesiredMaskS) const;
104 bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS,
105 int64_t DesiredMaskS) const;
108 void SelectAllBasicBlocks(Function &Fn, MachineFunction &MF);
109 void FinishBasicBlock();
111 void SelectBasicBlock(BasicBlock *LLVMBB,
112 BasicBlock::iterator Begin,
113 BasicBlock::iterator End,
115 void CodeGenAndEmitDAG();
116 void LowerArguments(BasicBlock *BB);
118 void ComputeLiveOutVRegInfo();
120 void HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB);
122 /// Pick a safe ordering for instructions for each target node in the
124 ScheduleDAG *Schedule();
129 #endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */