1//=- LoongArchMachineFunctionInfo.h - LoongArch machine function info -----===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares LoongArch-specific per-machine-function information.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHMACHINEFUNCTIONINFO_H
14#define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHMACHINEFUNCTIONINFO_H
15
16#include "LoongArchSubtarget.h"
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineFunction.h"
20
21namespace llvm {
22
23/// LoongArchMachineFunctionInfo - This class is derived from
24/// MachineFunctionInfo and contains private LoongArch-specific information for
25/// each MachineFunction.
26class LoongArchMachineFunctionInfo : public MachineFunctionInfo {
27private:
28 /// FrameIndex for start of varargs area
29 int VarArgsFrameIndex = 0;
30 /// Size of the save area used for varargs
31 int VarArgsSaveSize = 0;
32
33 /// Size of stack frame to save callee saved registers
34 unsigned CalleeSavedStackSize = 0;
35
36 /// Incoming indirect argument pointers saved as virtual registers, keyed by
37 /// formal parameter index. Used for musttail forwarding of indirect args.
38 /// Virtual registers (not SDValues) are used because the SelectionDAG is
39 /// cleared between basic blocks, and musttail calls may be in non-entry
40 /// blocks.
41 DenseMap<unsigned, Register> IncomingIndirectArgs;
42
43 /// FrameIndex of the spill slot when there is no scavenged register in
44 /// insertIndirectBranch.
45 int BranchRelaxationSpillFrameIndex = -1;
46
47 /// Registers that have been sign extended from i32.
48 SmallVector<Register, 8> SExt32Registers;
49
50 /// Pairs of `jr` instructions and corresponding JTI operands, used for the
51 /// `annotate-tablejump` option.
52 SmallVector<std::pair<MachineInstr *, int>, 4> JumpInfos;
53
54 bool HasDynamicAllocation = false;
55
56public:
57 LoongArchMachineFunctionInfo(const Function &F,
58 const TargetSubtargetInfo *STI) {}
59
60 MachineFunctionInfo *
61 clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
62 const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
63 const override {
64 return DestMF.cloneInfo<LoongArchMachineFunctionInfo>(Old: *this);
65 }
66
67 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
68 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
69
70 unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
71 void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
72
73 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
74 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
75
76 void setIncomingIndirectArg(unsigned ArgIndex, Register Reg) {
77 IncomingIndirectArgs[ArgIndex] = Reg;
78 }
79 Register getIncomingIndirectArg(unsigned ArgIndex) const {
80 auto It = IncomingIndirectArgs.find(Val: ArgIndex);
81 assert(It != IncomingIndirectArgs.end() && "No incoming indirect arg");
82 return It->second;
83 }
84
85 int getBranchRelaxationSpillFrameIndex() {
86 return BranchRelaxationSpillFrameIndex;
87 }
88 void setBranchRelaxationSpillFrameIndex(int Index) {
89 BranchRelaxationSpillFrameIndex = Index;
90 }
91
92 void addSExt32Register(Register Reg) { SExt32Registers.push_back(Elt: Reg); }
93
94 bool isSExt32Register(Register Reg) const {
95 return is_contained(Range: SExt32Registers, Element: Reg);
96 }
97
98 void setJumpInfo(MachineInstr *JrMI, int JTIIdx) {
99 JumpInfos.push_back(Elt: std::make_pair(x&: JrMI, y&: JTIIdx));
100 }
101 unsigned getJumpInfoSize() { return JumpInfos.size(); }
102 MachineInstr *getJumpInfoJrMI(unsigned Idx) { return JumpInfos[Idx].first; }
103 int getJumpInfoJTIIndex(unsigned Idx) { return JumpInfos[Idx].second; }
104
105 bool hasDynamicAllocation() const { return HasDynamicAllocation; }
106 void setDynamicAllocation() { HasDynamicAllocation = true; }
107};
108
109} // end namespace llvm
110
111#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHMACHINEFUNCTIONINFO_H
112