LLVM API Documentation

SelectionDAGISel.h

Go to the documentation of this file.
00001 //===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the SelectionDAGISel class, which is used as the common
00011 // base class for SelectionDAG-based instruction selectors.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CODEGEN_SELECTIONDAG_ISEL_H
00016 #define LLVM_CODEGEN_SELECTIONDAG_ISEL_H
00017 
00018 #include "llvm/BasicBlock.h"
00019 #include "llvm/Pass.h"
00020 #include "llvm/Constant.h"
00021 #include "llvm/CodeGen/SelectionDAG.h"
00022 
00023 namespace llvm {
00024   class FastISel;
00025   class SelectionDAGLowering;
00026   class SDValue;
00027   class MachineRegisterInfo;
00028   class MachineBasicBlock;
00029   class MachineFunction;
00030   class MachineInstr;
00031   class MachineModuleInfo;
00032   class DwarfWriter;
00033   class TargetLowering;
00034   class TargetInstrInfo;
00035   class FunctionLoweringInfo;
00036   class ScheduleHazardRecognizer;
00037   class GCFunctionInfo;
00038   class ScheduleDAG;
00039  
00040 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
00041 /// pattern-matching instruction selectors.
00042 class SelectionDAGISel : public FunctionPass {
00043 public:
00044   const TargetMachine &TM;
00045   TargetLowering &TLI;
00046   FunctionLoweringInfo *FuncInfo;
00047   MachineFunction *MF;
00048   MachineRegisterInfo *RegInfo;
00049   SelectionDAG *CurDAG;
00050   SelectionDAGLowering *SDL;
00051   MachineBasicBlock *BB;
00052   AliasAnalysis *AA;
00053   GCFunctionInfo *GFI;
00054   bool Fast;
00055   static char ID;
00056 
00057   explicit SelectionDAGISel(TargetMachine &tm, bool fast = false);
00058   virtual ~SelectionDAGISel();
00059   
00060   TargetLowering &getTargetLowering() { return TLI; }
00061 
00062   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
00063 
00064   virtual bool runOnFunction(Function &Fn);
00065 
00066   unsigned MakeReg(MVT VT);
00067 
00068   virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {}
00069   virtual void InstructionSelect() = 0;
00070   
00071   void SelectRootInit() {
00072     DAGSize = CurDAG->AssignTopologicalOrder();
00073   }
00074 
00075   /// SelectInlineAsmMemoryOperand - Select the specified address as a target
00076   /// addressing mode, according to the specified constraint code.  If this does
00077   /// not match or is not implemented, return true.  The resultant operands
00078   /// (which will appear in the machine instruction) should be added to the
00079   /// OutOps vector.
00080   virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
00081                                             char ConstraintCode,
00082                                             std::vector<SDValue> &OutOps) {
00083     return true;
00084   }
00085 
00086   /// IsLegalAndProfitableToFold - Returns true if the specific operand node N of
00087   /// U can be folded during instruction selection that starts at Root and
00088   /// folding N is profitable.
00089   virtual
00090   bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U, SDNode *Root) const {
00091     return true;
00092   }
00093   
00094   /// CreateTargetHazardRecognizer - Return a newly allocated hazard recognizer
00095   /// to use for this target when scheduling the DAG.
00096   virtual ScheduleHazardRecognizer *CreateTargetHazardRecognizer();
00097   
00098 protected:
00099   /// DAGSize - Size of DAG being instruction selected.
00100   ///
00101   unsigned DAGSize;
00102 
00103   /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
00104   /// by tblgen.  Others should not call it.
00105   void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops);
00106 
00107   // Calls to these predicates are generated by tblgen.
00108   bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS,
00109                     int64_t DesiredMaskS) const;
00110   bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS,
00111                     int64_t DesiredMaskS) const;
00112   
00113 private:
00114   void SelectAllBasicBlocks(Function &Fn, MachineFunction &MF,
00115                             MachineModuleInfo *MMI,
00116                             DwarfWriter *DW,
00117                             const TargetInstrInfo &TII);
00118   void FinishBasicBlock();
00119 
00120   void SelectBasicBlock(BasicBlock *LLVMBB,
00121                         BasicBlock::iterator Begin,
00122                         BasicBlock::iterator End);
00123   void CodeGenAndEmitDAG();
00124   void LowerArguments(BasicBlock *BB);
00125   
00126   void ComputeLiveOutVRegInfo();
00127 
00128   void HandlePHINodesInSuccessorBlocks(BasicBlock *LLVMBB);
00129 
00130   bool HandlePHINodesInSuccessorBlocksFast(BasicBlock *LLVMBB, FastISel *F);
00131 
00132   /// Pick a safe ordering for instructions for each target node in the
00133   /// graph.
00134   ScheduleDAG *Schedule();
00135 };
00136 
00137 }
00138 
00139 #endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */