Add some hooks for selecting memory addresses.
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/Pass.h"
19 #include "llvm/CodeGen/ValueTypes.h"
20
21 namespace llvm {
22   class SelectionDAG;
23   class SelectionDAGLowering;
24   class SDOperand;
25   class SSARegMap;
26   class MachineBasicBlock;
27   class MachineFunction;
28   class MachineInstr;
29   class TargetLowering;
30   class FunctionLoweringInfo;
31
32 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
33 /// pattern-matching instruction selectors.
34 class SelectionDAGISel : public FunctionPass {
35 public:
36   TargetLowering &TLI;
37   SSARegMap *RegMap;
38   SelectionDAG *CurDAG;
39   MachineBasicBlock *BB;
40
41   SelectionDAGISel(TargetLowering &tli) : TLI(tli) {}
42
43   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
44
45   virtual bool runOnFunction(Function &Fn);
46
47   unsigned MakeReg(MVT::ValueType VT);
48
49   virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {}
50   virtual void InstructionSelectBasicBlock(SelectionDAG &SD) = 0;
51
52   /// SelectInlineAsmMemoryOperand - Select the specified address as a target
53   /// addressing mode, according to the specified constraint code.  If this does
54   /// not match or is not implemented, return true.  The resultant operands
55   /// (which will appear in the machine instruction) should be added to the
56   /// OutOps vector.
57   virtual bool SelectInlineAsmMemoryOperand(const SDOperand &Op,
58                                             char ConstraintCode,
59                                             std::vector<SDOperand> &OutOps,
60                                             SelectionDAG &DAG) {
61     return true;
62   }
63   
64 protected:
65   /// Pick a safe ordering and emit instructions for each target node in the
66   /// graph.
67   void ScheduleAndEmitDAG(SelectionDAG &DAG);
68   
69   /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
70   /// by tblgen.  Others should not call it.
71   void SelectInlineAsmMemoryOperands(std::vector<SDOperand> &Ops,
72                                      SelectionDAG &DAG);
73   
74 private:
75   SDOperand CopyValueToVirtualRegister(SelectionDAGLowering &SDL,
76                                        Value *V, unsigned Reg);
77   void SelectBasicBlock(BasicBlock *BB, MachineFunction &MF,
78                         FunctionLoweringInfo &FuncInfo);
79
80   void BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB,
81            std::vector<std::pair<MachineInstr*, unsigned> > &PHINodesToUpdate,
82                          FunctionLoweringInfo &FuncInfo);
83   void LowerArguments(BasicBlock *BB, SelectionDAGLowering &SDL,
84                       std::vector<SDOperand> &UnorderedChains);
85 };
86
87 }
88
89 #endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */