mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
dc23f7b29b
Differential revision: https://reviews.llvm.org/D72701 The patch adds a new option ABI for Hexagon. It primary deals with the way variable arguments are passed and is use in the Hexagon Linux Musl environment. If a callee function has a variable argument list, it must perform the following operations to set up its function prologue: 1. Determine the number of registers which could have been used for passing unnamed arguments. This can be calculated by counting the number of registers used for passing named arguments. For example, if the callee function is as follows: int foo(int a, ...){ ... } ... then register R0 is used to access the argument ' a '. The registers available for passing unnamed arguments are R1, R2, R3, R4, and R5. 2. Determine the number and size of the named arguments on the stack. 3. If the callee has named arguments on the stack, it should copy all of these arguments to a location below the current position on the stack, and the difference should be the size of the register-saved area plus padding (if any is necessary). The register-saved area constitutes all the registers that could have been used to pass unnamed arguments. If the number of registers forming the register-saved area is odd, it requires 4 bytes of padding; if the number is even, no padding is required. This is done to ensure an 8-byte alignment on the stack. For example, if the callee is as follows: int foo(int a, ...){ ... } ... then the named arguments should be copied to the following location: current_position - 5 (for R1-R5) * 4 (bytes) - 4 (bytes of padding) If the callee is as follows: int foo(int a, int b, ...){ ... } ... then the named arguments should be copied to the following location: current_position - 4 (for R2-R5) * 4 (bytes) - 0 (bytes of padding) 4. After any named arguments have been copied, copy all the registers that could have been used to pass unnamed arguments on the stack. If the number of registers is odd, leave 4 bytes of padding and then start copying them on the stack; if the number is even, no padding is required. This constitutes the register-saved area. If padding is required, ensure that the start location of padding is 8-byte aligned. If no padding is required, ensure that the start location of the on-stack copy of the first register which might have a variable argument is 8-byte aligned. 5. Decrement the stack pointer by the size of register saved area plus the padding. For example, if the callee is as follows: int foo(int a, ...){ ... } ; ... then the decrement value should be the following: 5 (for R1-R5) * 4 (bytes) + 4 (bytes of padding) = 24 bytes The decrement should be performed before the allocframe instruction. Increment the stack-pointer back by the same amount before returning from the function.
91 lines
3.3 KiB
C++
91 lines
3.3 KiB
C++
//=- HexagonMachineFunctionInfo.h - Hexagon machine function info -*- C++ -*-=//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONMACHINEFUNCTIONINFO_H
|
|
#define LLVM_LIB_TARGET_HEXAGON_HEXAGONMACHINEFUNCTIONINFO_H
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
#include <map>
|
|
|
|
namespace llvm {
|
|
|
|
namespace Hexagon {
|
|
|
|
const unsigned int StartPacket = 0x1;
|
|
const unsigned int EndPacket = 0x2;
|
|
|
|
} // end namespace Hexagon
|
|
|
|
/// Hexagon target-specific information for each MachineFunction.
|
|
class HexagonMachineFunctionInfo : public MachineFunctionInfo {
|
|
// SRetReturnReg - Some subtargets require that sret lowering includes
|
|
// returning the value of the returned struct in a register. This field
|
|
// holds the virtual register into which the sret argument is passed.
|
|
unsigned SRetReturnReg = 0;
|
|
unsigned StackAlignBaseVReg = 0; // Aligned-stack base register (virtual)
|
|
unsigned StackAlignBasePhysReg = 0; // (physical)
|
|
int VarArgsFrameIndex;
|
|
int RegSavedAreaStartFrameIndex;
|
|
int FirstNamedArgFrameIndex;
|
|
int LastNamedArgFrameIndex;
|
|
bool HasClobberLR = false;
|
|
bool HasEHReturn = false;
|
|
std::map<const MachineInstr*, unsigned> PacketInfo;
|
|
virtual void anchor();
|
|
|
|
public:
|
|
HexagonMachineFunctionInfo() = default;
|
|
|
|
HexagonMachineFunctionInfo(MachineFunction &MF) {}
|
|
|
|
unsigned getSRetReturnReg() const { return SRetReturnReg; }
|
|
void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
|
|
|
|
void setVarArgsFrameIndex(int v) { VarArgsFrameIndex = v; }
|
|
int getVarArgsFrameIndex() { return VarArgsFrameIndex; }
|
|
|
|
void setRegSavedAreaStartFrameIndex(int v) { RegSavedAreaStartFrameIndex = v;}
|
|
int getRegSavedAreaStartFrameIndex() { return RegSavedAreaStartFrameIndex; }
|
|
|
|
void setFirstNamedArgFrameIndex(int v) { FirstNamedArgFrameIndex = v; }
|
|
int getFirstNamedArgFrameIndex() { return FirstNamedArgFrameIndex; }
|
|
|
|
void setLastNamedArgFrameIndex(int v) { LastNamedArgFrameIndex = v; }
|
|
int getLastNamedArgFrameIndex() { return LastNamedArgFrameIndex; }
|
|
|
|
void setStartPacket(MachineInstr* MI) {
|
|
PacketInfo[MI] |= Hexagon::StartPacket;
|
|
}
|
|
void setEndPacket(MachineInstr* MI) {
|
|
PacketInfo[MI] |= Hexagon::EndPacket;
|
|
}
|
|
bool isStartPacket(const MachineInstr* MI) const {
|
|
return (PacketInfo.count(MI) &&
|
|
(PacketInfo.find(MI)->second & Hexagon::StartPacket));
|
|
}
|
|
bool isEndPacket(const MachineInstr* MI) const {
|
|
return (PacketInfo.count(MI) &&
|
|
(PacketInfo.find(MI)->second & Hexagon::EndPacket));
|
|
}
|
|
void setHasClobberLR(bool v) { HasClobberLR = v; }
|
|
bool hasClobberLR() const { return HasClobberLR; }
|
|
|
|
bool hasEHReturn() const { return HasEHReturn; };
|
|
void setHasEHReturn(bool H = true) { HasEHReturn = H; };
|
|
|
|
void setStackAlignBaseVReg(unsigned R) { StackAlignBaseVReg = R; }
|
|
unsigned getStackAlignBaseVReg() const { return StackAlignBaseVReg; }
|
|
|
|
void setStackAlignBasePhysReg(unsigned R) { StackAlignBasePhysReg = R; }
|
|
unsigned getStackAlignBasePhysReg() const { return StackAlignBasePhysReg; }
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONMACHINEFUNCTIONINFO_H
|