Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 1 | //===-- llvm/lib/Target/AArch64/AArch64CallLowering.h - Call lowering -----===// |
| 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_AARCH64_AARCH64CALLLOWERING |
| 16 | #define LLVM_LIB_TARGET_AARCH64_AARCH64CALLLOWERING |
| 17 | |
| 18 | #include "llvm/CodeGen/GlobalISel/CallLowering.h" |
Tim Northover | 406024a | 2016-08-10 21:44:01 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/CallingConvLower.h" |
| 20 | #include "llvm/CodeGen/ValueTypes.h" |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | class AArch64TargetLowering; |
Tom Stellard | b72a65f | 2016-04-14 17:23:33 +0000 | [diff] [blame] | 25 | |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 26 | class AArch64CallLowering: public CallLowering { |
| 27 | public: |
Tim Northover | a5e38fa | 2016-09-22 13:49:25 +0000 | [diff] [blame^] | 28 | |
| 29 | /// Argument handling is mostly uniform between the four places that |
| 30 | /// make these decisions: function formal arguments, call |
| 31 | /// instruction args, call instruction returns and function |
| 32 | /// returns. However, once a decision has been made on where an |
| 33 | /// arugment should go, exactly what happens can vary slightly. This |
| 34 | /// class abstracts the differences. |
| 35 | struct ValueHandler { |
| 36 | /// Materialize a VReg containing the address of the specified |
| 37 | /// stack-based object. This is either based on a FrameIndex or |
| 38 | /// direct SP manipulation, depending on the context. \p MPO |
| 39 | /// should be initialized to an appropriate description of the |
| 40 | /// address created. |
| 41 | virtual unsigned getStackAddress(uint64_t Size, int64_t Offset, |
| 42 | MachinePointerInfo &MPO) = 0; |
| 43 | |
| 44 | /// The specified value has been assigned to a physical register, |
| 45 | /// handle the appropriate COPY (either to or from) and mark any |
| 46 | /// relevant uses/defines as needed. |
| 47 | virtual void assignValueToReg(unsigned ValVReg, unsigned PhysReg, |
| 48 | CCValAssign &VA) = 0; |
| 49 | |
| 50 | /// The specified value has been assigned to a stack |
| 51 | /// location. Load or store it there, with appropriate extension |
| 52 | /// if necessary. |
| 53 | virtual void assignValueToAddress(unsigned ValVReg, unsigned Addr, |
| 54 | uint64_t Size, MachinePointerInfo &MPO, |
| 55 | CCValAssign &VA) = 0; |
| 56 | |
| 57 | unsigned extendRegister(unsigned ValReg, CCValAssign &VA); |
| 58 | |
| 59 | ValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI) |
| 60 | : MIRBuilder(MIRBuilder), MRI(MRI) {} |
| 61 | |
| 62 | virtual ~ValueHandler() {} |
| 63 | |
| 64 | MachineIRBuilder &MIRBuilder; |
| 65 | MachineRegisterInfo &MRI; |
| 66 | }; |
| 67 | |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 68 | AArch64CallLowering(const AArch64TargetLowering &TLI); |
Tom Stellard | b72a65f | 2016-04-14 17:23:33 +0000 | [diff] [blame] | 69 | |
| 70 | bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val, |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 71 | unsigned VReg) const override; |
Tim Northover | 406024a | 2016-08-10 21:44:01 +0000 | [diff] [blame] | 72 | |
Tim Northover | 862758ec | 2016-09-21 12:57:35 +0000 | [diff] [blame] | 73 | bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, |
Tim Northover | 406024a | 2016-08-10 21:44:01 +0000 | [diff] [blame] | 74 | ArrayRef<unsigned> VRegs) const override; |
| 75 | |
Tim Northover | edb3c8c | 2016-08-29 19:07:16 +0000 | [diff] [blame] | 76 | bool lowerCall(MachineIRBuilder &MIRBuilder, const MachineOperand &Callee, |
Tim Northover | 9a46718 | 2016-09-21 12:57:45 +0000 | [diff] [blame] | 77 | const ArgInfo &OrigRet, |
| 78 | ArrayRef<ArgInfo> OrigArgs) const override; |
Tim Northover | 406024a | 2016-08-10 21:44:01 +0000 | [diff] [blame] | 79 | |
| 80 | private: |
Tim Northover | 9a46718 | 2016-09-21 12:57:45 +0000 | [diff] [blame] | 81 | typedef std::function<void(MachineIRBuilder &, Type *, unsigned, |
| 82 | CCValAssign &)> |
Tim Northover | a5e38fa | 2016-09-22 13:49:25 +0000 | [diff] [blame^] | 83 | RegHandler; |
| 84 | |
| 85 | typedef std::function<void(MachineIRBuilder &, int, CCValAssign &)> |
| 86 | MemHandler; |
Tim Northover | 406024a | 2016-08-10 21:44:01 +0000 | [diff] [blame] | 87 | |
Tim Northover | b18ea16 | 2016-09-20 15:20:36 +0000 | [diff] [blame] | 88 | typedef std::function<void(ArrayRef<unsigned>, ArrayRef<uint64_t>)> |
| 89 | SplitArgTy; |
| 90 | |
Tim Northover | 9a46718 | 2016-09-21 12:57:45 +0000 | [diff] [blame] | 91 | void splitToValueTypes(const ArgInfo &OrigArgInfo, |
| 92 | SmallVectorImpl<ArgInfo> &SplitArgs, |
Tim Northover | b18ea16 | 2016-09-20 15:20:36 +0000 | [diff] [blame] | 93 | const DataLayout &DL, MachineRegisterInfo &MRI, |
| 94 | SplitArgTy SplitArg) const; |
| 95 | |
Tim Northover | 406024a | 2016-08-10 21:44:01 +0000 | [diff] [blame] | 96 | bool handleAssignments(MachineIRBuilder &MIRBuilder, CCAssignFn *AssignFn, |
Tim Northover | 9a46718 | 2016-09-21 12:57:45 +0000 | [diff] [blame] | 97 | ArrayRef<ArgInfo> Args, |
Tim Northover | a5e38fa | 2016-09-22 13:49:25 +0000 | [diff] [blame^] | 98 | ValueHandler &Callback) const; |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 99 | }; |
| 100 | } // End of namespace llvm; |
| 101 | #endif |