]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Mips/MipsCallLowering.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Mips / MipsCallLowering.h
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     bool handle(ArrayRef<CCValAssign> ArgLocs,
35                 ArrayRef<CallLowering::ArgInfo> Args);
36
37   protected:
38     bool assignVRegs(ArrayRef<unsigned> VRegs, ArrayRef<CCValAssign> ArgLocs,
39                      unsigned Index);
40
41     void setLeastSignificantFirst(SmallVectorImpl<unsigned> &VRegs);
42
43     MachineIRBuilder &MIRBuilder;
44     MachineRegisterInfo &MRI;
45
46   private:
47     bool assign(unsigned VReg, const CCValAssign &VA);
48
49     virtual unsigned getStackAddress(const CCValAssign &VA,
50                                      MachineMemOperand *&MMO) = 0;
51
52     virtual void assignValueToReg(unsigned ValVReg, const CCValAssign &VA) = 0;
53
54     virtual void assignValueToAddress(unsigned ValVReg,
55                                       const CCValAssign &VA) = 0;
56
57     virtual bool handleSplit(SmallVectorImpl<unsigned> &VRegs,
58                              ArrayRef<CCValAssign> ArgLocs,
59                              unsigned ArgLocsStartIndex, unsigned ArgsReg) = 0;
60   };
61
62   MipsCallLowering(const MipsTargetLowering &TLI);
63
64   bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val,
65                    ArrayRef<unsigned> VRegs) const override;
66
67   bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F,
68                             ArrayRef<unsigned> VRegs) const override;
69
70   bool lowerCall(MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv,
71                  const MachineOperand &Callee, const ArgInfo &OrigRet,
72                  ArrayRef<ArgInfo> OrigArgs) const override;
73
74 private:
75   /// Based on registers available on target machine split or extend
76   /// type if needed, also change pointer type to appropriate integer
77   /// type.
78   template <typename T>
79   void subTargetRegTypeForCallingConv(const Function &F, ArrayRef<ArgInfo> Args,
80                                       ArrayRef<unsigned> OrigArgIndices,
81                                       SmallVectorImpl<T> &ISDArgs) const;
82
83   /// Split structures and arrays, save original argument indices since
84   /// Mips calling convention needs info about original argument type.
85   void splitToValueTypes(const ArgInfo &OrigArg, unsigned OriginalIndex,
86                          SmallVectorImpl<ArgInfo> &SplitArgs,
87                          SmallVectorImpl<unsigned> &SplitArgsOrigIndices) const;
88 };
89
90 } // end namespace llvm
91
92 #endif // LLVM_LIB_TARGET_MIPS_MIPSCALLLOWERING_H