Home | History | Annotate | Download | only in Mips
      1 //===- MipsCallLowering.h ---------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 /// \file
     11 /// This file describes how to lower LLVM calls to machine code calls.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_LIB_TARGET_MIPS_MIPSCALLLOWERING_H
     16 #define LLVM_LIB_TARGET_MIPS_MIPSCALLLOWERING_H
     17 
     18 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
     19 
     20 namespace llvm {
     21 
     22 class MipsTargetLowering;
     23 
     24 class MipsCallLowering : public CallLowering {
     25 
     26 public:
     27   class MipsHandler {
     28   public:
     29     MipsHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
     30         : MIRBuilder(MIRBuilder), MRI(MRI) {}
     31 
     32     virtual ~MipsHandler() = default;
     33 
     34   protected:
     35     bool assign(const CCValAssign &VA, unsigned vreg);
     36 
     37     MachineIRBuilder &MIRBuilder;
     38     MachineRegisterInfo &MRI;
     39 
     40   private:
     41     virtual unsigned getStackAddress(uint64_t Size, int64_t Offset,
     42                                      MachinePointerInfo &MPO) = 0;
     43 
     44     virtual void assignValueToReg(unsigned ValVReg, unsigned PhysReg) = 0;
     45 
     46     virtual void assignValueToAddress(unsigned ValVReg, unsigned Addr,
     47                                       uint64_t Size,
     48                                       MachinePointerInfo &MPO) = 0;
     49   };
     50 
     51   MipsCallLowering(const MipsTargetLowering &TLI);
     52 
     53   bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val,
     54                    unsigned VReg) const override;
     55 
     56   bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F,
     57                             ArrayRef<unsigned> VRegs) const override;
     58 
     59   bool lowerCall(MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv,
     60                  const MachineOperand &Callee, const ArgInfo &OrigRet,
     61                  ArrayRef<ArgInfo> OrigArgs) const override;
     62 
     63 private:
     64   using FunTy =
     65       std::function<void(ISD::ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
     66                          unsigned origIdx, unsigned partOffs)>;
     67 
     68   /// Based on registers available on target machine split or extend
     69   /// type if needed, also change pointer type to appropriate integer
     70   /// type. Lambda will fill some info so we can tell MipsCCState to
     71   /// assign physical registers.
     72   void subTargetRegTypeForCallingConv(MachineIRBuilder &MIRBuilder,
     73                                       ArrayRef<ArgInfo> Args,
     74                                       ArrayRef<unsigned> OrigArgIndices,
     75                                       const FunTy &PushBack) const;
     76 
     77   /// Split structures and arrays, save original argument indices since
     78   /// Mips calling conv needs info about original argument type.
     79   void splitToValueTypes(const ArgInfo &OrigArg, unsigned OriginalIndex,
     80                          SmallVectorImpl<ArgInfo> &SplitArgs,
     81                          SmallVectorImpl<unsigned> &SplitArgsOrigIndices) const;
     82 };
     83 
     84 } // end namespace llvm
     85 
     86 #endif // LLVM_LIB_TARGET_MIPS_MIPSCALLLOWERING_H
     87