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 #include "llvm/CodeGen/MachineFunctionPass.h"
00023 
00024 namespace llvm {
00025   class FastISel;
00026   class SelectionDAGLowering;
00027   class SDValue;
00028   class MachineRegisterInfo;
00029   class MachineBasicBlock;
00030   class MachineFunction;
00031   class MachineInstr;
00032   class MachineModuleInfo;
00033   class DwarfWriter;
00034   class TargetLowering;
00035   class TargetInstrInfo;
00036   class FunctionLoweringInfo;
00037   class ScheduleHazardRecognizer;
00038   class GCFunctionInfo;
00039   class ScheduleDAGSDNodes;
00040  
00041 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
00042 /// pattern-matching instruction selectors.
00043 class SelectionDAGISel : public MachineFunctionPass {
00044 public:
00045   const TargetMachine &TM;
00046   TargetLowering &TLI;
00047   FunctionLoweringInfo *FuncInfo;
00048   MachineFunction *MF;
00049   MachineRegisterInfo *RegInfo;
00050   SelectionDAG *CurDAG;
00051   SelectionDAGLowering *SDL;
00052   MachineBasicBlock *BB;
00053   AliasAnalysis *AA;
00054   GCFunctionInfo *GFI;
00055   CodeGenOpt::Level OptLevel;
00056   static char ID;
00057 
00058   explicit SelectionDAGISel(TargetMachine &tm,
00059                             CodeGenOpt::Level OL = CodeGenOpt::Default);
00060   virtual ~SelectionDAGISel();
00061   
00062   TargetLowering &getTargetLowering() { return TLI; }
00063 
00064   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
00065 
00066   virtual bool runOnMachineFunction(MachineFunction &MF);
00067 
00068   unsigned MakeReg(EVT VT);
00069 
00070   virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {}
00071   virtual void InstructionSelect() = 0;
00072   
00073   void SelectRootInit() {
00074     DAGSize = CurDAG->AssignTopologicalOrder();
00075   }
00076 
00077   /// SelectInlineAsmMemoryOperand - Select the specified address as a target
00078   /// addressing mode, according to the specified constraint code.  If this does
00079   /// not match or is not implemented, return true.  The resultant operands
00080   /// (which will appear in the machine instruction) should be added to the
00081   /// OutOps vector.
00082   virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
00083                                             char ConstraintCode,
00084                                             std::vector<SDValue> &OutOps) {
00085     return true;
00086   }
00087 
00088   /// IsLegalAndProfitableToFold - Returns true if the specific operand node N of
00089   /// U can be folded during instruction selection that starts at Root and
00090   /// folding N is profitable.
00091   virtual
00092   bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U, SDNode *Root) const;
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   /// Create the scheduler. If a specific scheduler was specified
00133   /// via the SchedulerRegistry, use it, otherwise select the
00134   /// one preferred by the target.
00135   ///
00136   ScheduleDAGSDNodes *CreateScheduler();
00137 };
00138 
00139 }
00140 
00141 #endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */