LLVM API Documentation

PIC16ISelLowering.h

Go to the documentation of this file.
00001 //===-- PIC16ISelLowering.h - PIC16 DAG Lowering Interface ------*- 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 defines the interfaces that PIC16 uses to lower LLVM code into a
00011 // selection DAG.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef PIC16ISELLOWERING_H
00016 #define PIC16ISELLOWERING_H
00017 
00018 #include "PIC16.h"
00019 #include "PIC16Subtarget.h"
00020 #include "llvm/CodeGen/SelectionDAG.h"
00021 #include "llvm/Target/TargetLowering.h"
00022 
00023 namespace llvm {
00024   namespace PIC16ISD {
00025     enum NodeType {
00026       // Start the numbering from where ISD NodeType finishes.
00027       FIRST_NUMBER = ISD::BUILTIN_OP_END,
00028 
00029       Lo,            // Low 8-bits of GlobalAddress.
00030       Hi,            // High 8-bits of GlobalAddress.
00031       PIC16Load,
00032       PIC16LdWF,
00033       PIC16Store,
00034       PIC16StWF,
00035       Banksel,
00036       MTLO,
00037       MTHI,
00038       BCF,
00039       LSLF,          // PIC16 Logical shift left
00040       LRLF,          // PIC16 Logical shift right
00041       RLF,           // Rotate left through carry
00042       RRF,           // Rotate right through carry
00043       CALL,          // PIC16 Call instruction 
00044       SUBCC,       // Compare for equality or inequality.
00045       SELECT_ICC,    // Psuedo to be caught in schedular and expanded to brcond.
00046       BRCOND,        // Conditional branch.
00047       Dummy
00048     };
00049 
00050     // Keep track of different address spaces. 
00051     enum AddressSpace {
00052       RAM_SPACE = 0,   // RAM address space
00053       ROM_SPACE = 1    // ROM address space number is 1
00054     };
00055     enum PIC16Libcall {
00056       MUL_I8,
00057       SRA_I8,
00058       SLL_I8,
00059       SRL_I8,
00060       PIC16UnknownCall
00061     };
00062   }
00063 
00064 
00065   //===--------------------------------------------------------------------===//
00066   // TargetLowering Implementation
00067   //===--------------------------------------------------------------------===//
00068   class PIC16TargetLowering : public TargetLowering {
00069   public:
00070     explicit PIC16TargetLowering(PIC16TargetMachine &TM);
00071 
00072     /// getTargetNodeName - This method returns the name of a target specific
00073     /// DAG node.
00074     virtual const char *getTargetNodeName(unsigned Opcode) const;
00075     /// getSetCCResultType - Return the ISD::SETCC ValueType
00076     virtual MVT getSetCCResultType(MVT ValType) const;
00077     SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
00078     SDValue LowerShift(SDValue Op, SelectionDAG &DAG);
00079     SDValue LowerADD(SDValue Op, SelectionDAG &DAG);
00080     SDValue LowerSUB(SDValue Op, SelectionDAG &DAG);
00081     SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG);
00082     SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
00083     SDValue LowerRET(SDValue Op, SelectionDAG &DAG);
00084     SDValue LowerCallReturn(SDValue Op, SDValue Chain, SDValue FrameAddress,
00085                             SDValue InFlag, SelectionDAG &DAG);
00086     SDValue LowerCallArguments(SDValue Op, SDValue Chain, SDValue FrameAddress,
00087                                SDValue InFlag, SelectionDAG &DAG);
00088     SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG);
00089     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
00090     SDValue getPIC16Cmp(SDValue LHS, SDValue RHS, unsigned OrigCC, SDValue &CC,
00091                         SelectionDAG &DAG);
00092     virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
00093                                                         MachineBasicBlock *MBB);
00094 
00095 
00096     virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
00097     virtual void ReplaceNodeResults(SDNode *N,
00098                                     SmallVectorImpl<SDValue> &Results,
00099                                     SelectionDAG &DAG);
00100     virtual void LowerOperationWrapper(SDNode *N,
00101                                        SmallVectorImpl<SDValue> &Results,
00102                                        SelectionDAG &DAG);
00103 
00104     SDValue ExpandStore(SDNode *N, SelectionDAG &DAG);
00105     SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG);
00106     //SDValue ExpandAdd(SDNode *N, SelectionDAG &DAG);
00107     SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG);
00108     SDValue ExpandExternalSymbol(SDNode *N, SelectionDAG &DAG);
00109     SDValue ExpandFrameIndex(SDNode *N, SelectionDAG &DAG);
00110 
00111     SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 
00112     SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const; 
00113 
00114   private:
00115     // If the Node is a BUILD_PAIR representing representing an Address
00116     // then this function will return true
00117     bool isDirectAddress(const SDValue &Op);
00118 
00119     // If the Node is a DirectAddress in ROM_SPACE then this 
00120     // function will return true
00121     bool isRomAddress(const SDValue &Op);
00122 
00123     // To extract chain value from the SDValue Nodes
00124     // This function will help to maintain the chain extracting
00125     // code at one place. In case of any change in future it will
00126     // help maintain the code
00127     SDValue getChain(SDValue &Op);
00128     
00129     SDValue getOutFlag(SDValue &Op);
00130 
00131 
00132     // Extract the Lo and Hi component of Op. 
00133     void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo, 
00134                           SDValue &Hi); 
00135 
00136 
00137     // Load pointer can be a direct or indirect address. In PIC16 direct
00138     // addresses need Banksel and Indirect addresses need to be loaded to
00139     // FSR first. Handle address specific cases here.
00140     void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain, 
00141                          SDValue &NewPtr, unsigned &Offset);
00142 
00143     // FrameIndex should be broken down into ExternalSymbol and FrameOffset. 
00144     void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES, 
00145                             int &Offset);
00146 
00147     // We can not have both operands of a binary operation in W.
00148     // This function is used to put one operand on stack and generate a load.
00149     SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG); 
00150 
00151     // This function checks if we need to put an operand of an operation on
00152     // stack and generate a load or not.
00153     bool NeedToConvertToMemOp(SDValue Op, unsigned &MemOp); 
00154 
00155     /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can
00156     /// make the right decision when generating code for different targets.
00157     const PIC16Subtarget *Subtarget;
00158 
00159 
00160     // Extending the LIB Call framework of LLVM
00161     // To hold the names of PIC16Libcalls
00162     const char *PIC16LibcallNames[PIC16ISD::PIC16UnknownCall]; 
00163 
00164     // To set and retrieve the lib call names
00165     void setPIC16LibcallName(PIC16ISD::PIC16Libcall Call, const char *Name);
00166     const char *getPIC16LibcallName(PIC16ISD::PIC16Libcall Call);
00167 
00168     // Make PIC16 Libcall
00169     SDValue MakePIC16Libcall(PIC16ISD::PIC16Libcall Call, MVT RetVT, 
00170                              const SDValue *Ops, unsigned NumOps, bool isSigned,
00171                              SelectionDAG &DAG, DebugLoc dl);
00172 
00173     // Check if operation has a direct load operand.
00174     inline bool isDirectLoad(const SDValue Op);
00175 
00176     // Create the symbol and index for function frame
00177     void getCurrentFrameIndex(SelectionDAG &DAG, SDValue &ES, 
00178                               unsigned SlotSize, int &FI);
00179 
00180     SDValue getCurrentFrame(SelectionDAG &DAG);
00181   };
00182 } // namespace llvm
00183 
00184 #endif // PIC16ISELLOWERING_H