blob: 1cbd89957629a775dc4a70493c49445f1ab3e5ff [file] [log] [blame]
Quentin Colombetba2a0162016-02-16 19:26:02 +00001//===-- 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 Northover406024a2016-08-10 21:44:01 +000019#include "llvm/CodeGen/CallingConvLower.h"
20#include "llvm/CodeGen/ValueTypes.h"
Quentin Colombetba2a0162016-02-16 19:26:02 +000021
22namespace llvm {
23
24class AArch64TargetLowering;
Tom Stellardb72a65f2016-04-14 17:23:33 +000025
Quentin Colombetba2a0162016-02-16 19:26:02 +000026class AArch64CallLowering: public CallLowering {
27 public:
Tim Northovera5e38fa2016-09-22 13:49:25 +000028
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 Colombetba2a0162016-02-16 19:26:02 +000068 AArch64CallLowering(const AArch64TargetLowering &TLI);
Tom Stellardb72a65f2016-04-14 17:23:33 +000069
70 bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val,
Quentin Colombetba2a0162016-02-16 19:26:02 +000071 unsigned VReg) const override;
Tim Northover406024a2016-08-10 21:44:01 +000072
Tim Northover862758ec2016-09-21 12:57:35 +000073 bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F,
Tim Northover406024a2016-08-10 21:44:01 +000074 ArrayRef<unsigned> VRegs) const override;
75
Tim Northoveredb3c8c2016-08-29 19:07:16 +000076 bool lowerCall(MachineIRBuilder &MIRBuilder, const MachineOperand &Callee,
Tim Northover9a467182016-09-21 12:57:45 +000077 const ArgInfo &OrigRet,
78 ArrayRef<ArgInfo> OrigArgs) const override;
Tim Northover406024a2016-08-10 21:44:01 +000079
80private:
Tim Northover9a467182016-09-21 12:57:45 +000081 typedef std::function<void(MachineIRBuilder &, Type *, unsigned,
82 CCValAssign &)>
Tim Northovera5e38fa2016-09-22 13:49:25 +000083 RegHandler;
84
85 typedef std::function<void(MachineIRBuilder &, int, CCValAssign &)>
86 MemHandler;
Tim Northover406024a2016-08-10 21:44:01 +000087
Tim Northoverb18ea162016-09-20 15:20:36 +000088 typedef std::function<void(ArrayRef<unsigned>, ArrayRef<uint64_t>)>
89 SplitArgTy;
90
Tim Northover9a467182016-09-21 12:57:45 +000091 void splitToValueTypes(const ArgInfo &OrigArgInfo,
92 SmallVectorImpl<ArgInfo> &SplitArgs,
Tim Northoverb18ea162016-09-20 15:20:36 +000093 const DataLayout &DL, MachineRegisterInfo &MRI,
94 SplitArgTy SplitArg) const;
95
Tim Northover406024a2016-08-10 21:44:01 +000096 bool handleAssignments(MachineIRBuilder &MIRBuilder, CCAssignFn *AssignFn,
Tim Northover9a467182016-09-21 12:57:45 +000097 ArrayRef<ArgInfo> Args,
Tim Northovera5e38fa2016-09-22 13:49:25 +000098 ValueHandler &Callback) const;
Quentin Colombetba2a0162016-02-16 19:26:02 +000099};
100} // End of namespace llvm;
101#endif