Petar Jovanovic | fac93e2 | 2018-02-23 11:06:40 +0000 | [diff] [blame] | 1 | //===- MipsCallLowering.h ---------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Petar Jovanovic | fac93e2 | 2018-02-23 11:06:40 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | /// \file |
| 10 | /// This file describes how to lower LLVM calls to machine code calls. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_LIB_TARGET_MIPS_MIPSCALLLOWERING_H |
| 15 | #define LLVM_LIB_TARGET_MIPS_MIPSCALLLOWERING_H |
| 16 | |
Petar Jovanovic | fac93e2 | 2018-02-23 11:06:40 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/GlobalISel/CallLowering.h" |
Petar Jovanovic | fac93e2 | 2018-02-23 11:06:40 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
| 20 | |
| 21 | class MipsTargetLowering; |
| 22 | |
| 23 | class MipsCallLowering : public CallLowering { |
| 24 | |
| 25 | public: |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 26 | class MipsHandler { |
| 27 | public: |
| 28 | MipsHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI) |
| 29 | : MIRBuilder(MIRBuilder), MRI(MRI) {} |
| 30 | |
| 31 | virtual ~MipsHandler() = default; |
| 32 | |
Petar Jovanovic | ff1bc62 | 2018-09-28 13:28:47 +0000 | [diff] [blame] | 33 | bool handle(ArrayRef<CCValAssign> ArgLocs, |
| 34 | ArrayRef<CallLowering::ArgInfo> Args); |
| 35 | |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 36 | protected: |
Petar Jovanovic | ff1bc62 | 2018-09-28 13:28:47 +0000 | [diff] [blame] | 37 | bool assignVRegs(ArrayRef<unsigned> VRegs, ArrayRef<CCValAssign> ArgLocs, |
Petar Avramovic | 5a457e0 | 2019-03-25 11:23:41 +0000 | [diff] [blame] | 38 | unsigned ArgLocsStartIndex, const EVT &VT); |
Petar Jovanovic | ff1bc62 | 2018-09-28 13:28:47 +0000 | [diff] [blame] | 39 | |
Petar Avramovic | 2624c8d | 2018-11-07 11:45:43 +0000 | [diff] [blame] | 40 | void setLeastSignificantFirst(SmallVectorImpl<unsigned> &VRegs); |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 41 | |
| 42 | MachineIRBuilder &MIRBuilder; |
| 43 | MachineRegisterInfo &MRI; |
Petar Jovanovic | 226e611 | 2018-07-03 09:31:48 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
Petar Avramovic | 5a457e0 | 2019-03-25 11:23:41 +0000 | [diff] [blame] | 46 | bool assign(unsigned VReg, const CCValAssign &VA, const EVT &VT); |
Petar Jovanovic | ff1bc62 | 2018-09-28 13:28:47 +0000 | [diff] [blame] | 47 | |
Petar Jovanovic | 65d463b | 2018-08-23 20:41:09 +0000 | [diff] [blame] | 48 | virtual unsigned getStackAddress(const CCValAssign &VA, |
| 49 | MachineMemOperand *&MMO) = 0; |
Petar Jovanovic | 226e611 | 2018-07-03 09:31:48 +0000 | [diff] [blame] | 50 | |
Petar Avramovic | 5a457e0 | 2019-03-25 11:23:41 +0000 | [diff] [blame] | 51 | virtual void assignValueToReg(unsigned ValVReg, const CCValAssign &VA, |
| 52 | const EVT &VT) = 0; |
Petar Jovanovic | 226e611 | 2018-07-03 09:31:48 +0000 | [diff] [blame] | 53 | |
Petar Jovanovic | 65d463b | 2018-08-23 20:41:09 +0000 | [diff] [blame] | 54 | virtual void assignValueToAddress(unsigned ValVReg, |
| 55 | const CCValAssign &VA) = 0; |
Petar Jovanovic | ff1bc62 | 2018-09-28 13:28:47 +0000 | [diff] [blame] | 56 | |
| 57 | virtual bool handleSplit(SmallVectorImpl<unsigned> &VRegs, |
| 58 | ArrayRef<CCValAssign> ArgLocs, |
Petar Avramovic | 5a457e0 | 2019-03-25 11:23:41 +0000 | [diff] [blame] | 59 | unsigned ArgLocsStartIndex, unsigned ArgsReg, |
| 60 | const EVT &VT) = 0; |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Petar Jovanovic | fac93e2 | 2018-02-23 11:06:40 +0000 | [diff] [blame] | 63 | MipsCallLowering(const MipsTargetLowering &TLI); |
| 64 | |
Alexander Ivchenko | 49168f6 | 2018-08-02 08:33:31 +0000 | [diff] [blame] | 65 | bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, |
Alexander Ivchenko | 48eba54 | 2018-08-02 08:55:05 +0000 | [diff] [blame] | 66 | ArrayRef<unsigned> VRegs) const override; |
Petar Jovanovic | fac93e2 | 2018-02-23 11:06:40 +0000 | [diff] [blame] | 67 | |
| 68 | bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, |
| 69 | ArrayRef<unsigned> VRegs) const override; |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 70 | |
Petar Jovanovic | 326ec32 | 2018-06-06 07:24:52 +0000 | [diff] [blame] | 71 | bool lowerCall(MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, |
| 72 | const MachineOperand &Callee, const ArgInfo &OrigRet, |
| 73 | ArrayRef<ArgInfo> OrigArgs) const override; |
| 74 | |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 75 | private: |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 76 | /// Based on registers available on target machine split or extend |
| 77 | /// type if needed, also change pointer type to appropriate integer |
Petar Jovanovic | ff1bc62 | 2018-09-28 13:28:47 +0000 | [diff] [blame] | 78 | /// type. |
| 79 | template <typename T> |
| 80 | void subTargetRegTypeForCallingConv(const Function &F, ArrayRef<ArgInfo> Args, |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 81 | ArrayRef<unsigned> OrigArgIndices, |
Petar Jovanovic | ff1bc62 | 2018-09-28 13:28:47 +0000 | [diff] [blame] | 82 | SmallVectorImpl<T> &ISDArgs) const; |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 83 | |
| 84 | /// Split structures and arrays, save original argument indices since |
Petar Avramovic | e72a743 | 2018-10-22 13:27:50 +0000 | [diff] [blame] | 85 | /// Mips calling convention needs info about original argument type. |
Petar Jovanovic | 366857a | 2018-04-11 15:12:32 +0000 | [diff] [blame] | 86 | void splitToValueTypes(const ArgInfo &OrigArg, unsigned OriginalIndex, |
| 87 | SmallVectorImpl<ArgInfo> &SplitArgs, |
| 88 | SmallVectorImpl<unsigned> &SplitArgsOrigIndices) const; |
Petar Jovanovic | fac93e2 | 2018-02-23 11:06:40 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // end namespace llvm |
| 92 | |
| 93 | #endif // LLVM_LIB_TARGET_MIPS_MIPSCALLLOWERING_H |