LLVM API Documentation

HexagonCallingConvLower.h
Go to the documentation of this file.
00001 //===-- HexagonCallingConvLower.h - Calling Conventions ---------*- 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 declares the Hexagon_CCState class, used for lowering
00011 // and implementing calling conventions. Adapted from the target independent
00012 // version but this handles calls to varargs functions
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONCALLINGCONVLOWER_H
00017 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONCALLINGCONVLOWER_H
00018 
00019 #include "llvm/ADT/SmallVector.h"
00020 #include "llvm/CodeGen/CallingConvLower.h"
00021 #include "llvm/CodeGen/SelectionDAGNodes.h"
00022 
00023 //
00024 // Need to handle varargs.
00025 //
00026 namespace llvm {
00027   class TargetRegisterInfo;
00028   class TargetMachine;
00029   class Hexagon_CCState;
00030   class SDNode;
00031   struct EVT;
00032 
00033 /// Hexagon_CCAssignFn - This function assigns a location for Val, updating
00034 /// State to reflect the change.
00035 typedef bool Hexagon_CCAssignFn(unsigned ValNo, EVT ValVT,
00036                               EVT LocVT, CCValAssign::LocInfo LocInfo,
00037                               ISD::ArgFlagsTy ArgFlags, Hexagon_CCState &State,
00038                               int NonVarArgsParams,
00039                               int CurrentParam,
00040                               bool ForceMem);
00041 
00042 
00043 /// CCState - This class holds information needed while lowering arguments and
00044 /// return values.  It captures which registers are already assigned and which
00045 /// stack slots are used.  It provides accessors to allocate these values.
00046 class Hexagon_CCState {
00047   CallingConv::ID CallingConv;
00048   bool IsVarArg;
00049   const TargetMachine &TM;
00050   SmallVectorImpl<CCValAssign> &Locs;
00051   LLVMContext &Context;
00052 
00053   unsigned StackOffset;
00054   SmallVector<uint32_t, 16> UsedRegs;
00055 public:
00056   Hexagon_CCState(CallingConv::ID CC, bool isVarArg, const TargetMachine &TM,
00057                   SmallVectorImpl<CCValAssign> &locs, LLVMContext &c);
00058 
00059   void addLoc(const CCValAssign &V) {
00060     Locs.push_back(V);
00061   }
00062 
00063   LLVMContext &getContext() const { return Context; }
00064   const TargetMachine &getTarget() const { return TM; }
00065   unsigned getCallingConv() const { return CallingConv; }
00066   bool isVarArg() const { return IsVarArg; }
00067 
00068   unsigned getNextStackOffset() const { return StackOffset; }
00069 
00070   /// isAllocated - Return true if the specified register (or an alias) is
00071   /// allocated.
00072   bool isAllocated(unsigned Reg) const {
00073     return UsedRegs[Reg/32] & (1 << (Reg&31));
00074   }
00075 
00076   /// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node,
00077   /// incorporating info about the formals into this state.
00078   void AnalyzeFormalArguments(const SmallVectorImpl<ISD::InputArg> &Ins,
00079                               Hexagon_CCAssignFn Fn, unsigned SretValueInRegs);
00080 
00081   /// AnalyzeReturn - Analyze the returned values of an ISD::RET node,
00082   /// incorporating info about the result values into this state.
00083   void AnalyzeReturn(const SmallVectorImpl<ISD::OutputArg> &Outs,
00084                      Hexagon_CCAssignFn Fn, unsigned SretValueInRegs);
00085 
00086   /// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
00087   /// about the passed values into this state.
00088   void AnalyzeCallOperands(const SmallVectorImpl<ISD::OutputArg> &Outs,
00089                            Hexagon_CCAssignFn Fn, int NonVarArgsParams,
00090                            unsigned SretValueSize);
00091 
00092   /// AnalyzeCallOperands - Same as above except it takes vectors of types
00093   /// and argument flags.
00094   void AnalyzeCallOperands(SmallVectorImpl<EVT> &ArgVTs,
00095                            SmallVectorImpl<ISD::ArgFlagsTy> &Flags,
00096                            Hexagon_CCAssignFn Fn);
00097 
00098   /// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
00099   /// incorporating info about the passed values into this state.
00100   void AnalyzeCallResult(const SmallVectorImpl<ISD::InputArg> &Ins,
00101                          Hexagon_CCAssignFn Fn, unsigned SretValueInRegs);
00102 
00103   /// AnalyzeCallResult - Same as above except it's specialized for calls which
00104   /// produce a single value.
00105   void AnalyzeCallResult(EVT VT, Hexagon_CCAssignFn Fn);
00106 
00107   /// getFirstUnallocated - Return the first unallocated register in the set, or
00108   /// NumRegs if they are all allocated.
00109   unsigned getFirstUnallocated(const unsigned *Regs, unsigned NumRegs) const {
00110     for (unsigned i = 0; i != NumRegs; ++i)
00111       if (!isAllocated(Regs[i]))
00112         return i;
00113     return NumRegs;
00114   }
00115 
00116   /// AllocateReg - Attempt to allocate one register.  If it is not available,
00117   /// return zero.  Otherwise, return the register, marking it and any aliases
00118   /// as allocated.
00119   unsigned AllocateReg(unsigned Reg) {
00120     if (isAllocated(Reg)) return 0;
00121     MarkAllocated(Reg);
00122     return Reg;
00123   }
00124 
00125   /// Version of AllocateReg with extra register to be shadowed.
00126   unsigned AllocateReg(unsigned Reg, unsigned ShadowReg) {
00127     if (isAllocated(Reg)) return 0;
00128     MarkAllocated(Reg);
00129     MarkAllocated(ShadowReg);
00130     return Reg;
00131   }
00132 
00133   /// AllocateReg - Attempt to allocate one of the specified registers.  If none
00134   /// are available, return zero.  Otherwise, return the first one available,
00135   /// marking it and any aliases as allocated.
00136   unsigned AllocateReg(const unsigned *Regs, unsigned NumRegs) {
00137     unsigned FirstUnalloc = getFirstUnallocated(Regs, NumRegs);
00138     if (FirstUnalloc == NumRegs)
00139       return 0;    // Didn't find the reg.
00140 
00141     // Mark the register and any aliases as allocated.
00142     unsigned Reg = Regs[FirstUnalloc];
00143     MarkAllocated(Reg);
00144     return Reg;
00145   }
00146 
00147   /// Version of AllocateReg with list of registers to be shadowed.
00148   unsigned AllocateReg(const unsigned *Regs, const unsigned *ShadowRegs,
00149                        unsigned NumRegs) {
00150     unsigned FirstUnalloc = getFirstUnallocated(Regs, NumRegs);
00151     if (FirstUnalloc == NumRegs)
00152       return 0;    // Didn't find the reg.
00153 
00154     // Mark the register and any aliases as allocated.
00155     unsigned Reg = Regs[FirstUnalloc], ShadowReg = ShadowRegs[FirstUnalloc];
00156     MarkAllocated(Reg);
00157     MarkAllocated(ShadowReg);
00158     return Reg;
00159   }
00160 
00161   /// AllocateStack - Allocate a chunk of stack space with the specified size
00162   /// and alignment.
00163   unsigned AllocateStack(unsigned Size, unsigned Align) {
00164     assert(Align && ((Align-1) & Align) == 0); // Align is power of 2.
00165     StackOffset = ((StackOffset + Align-1) & ~(Align-1));
00166     unsigned Result = StackOffset;
00167     StackOffset += Size;
00168     return Result;
00169   }
00170 
00171   // HandleByVal - Allocate a stack slot large enough to pass an argument by
00172   // value. The size and alignment information of the argument is encoded in its
00173   // parameter attribute.
00174   void HandleByVal(unsigned ValNo, EVT ValVT,
00175                    EVT LocVT, CCValAssign::LocInfo LocInfo,
00176                    int MinSize, int MinAlign, ISD::ArgFlagsTy ArgFlags);
00177 
00178 private:
00179   /// MarkAllocated - Mark a register and all of its aliases as allocated.
00180   void MarkAllocated(unsigned Reg);
00181 };
00182 
00183 
00184 
00185 } // end namespace llvm
00186 
00187 #endif