LLVM 22.0.0git
RISCVMachineFunctionInfo.cpp
Go to the documentation of this file.
1//=- RISCVMachineFunctionInfo.cpp - RISC-V machine function info --*- C++ -*-=//
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 RISCV-specific per-machine-function information.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/IR/Module.h"
15
16using namespace llvm;
17
20 : VarArgsFrameIndex(MFI.getVarArgsFrameIndex()),
21 VarArgsSaveSize(MFI.getVarArgsSaveSize()) {}
22
24 BumpPtrAllocator &Allocator, MachineFunction &DestMF,
26 const {
27 return DestMF.cloneInfo<RISCVMachineFunctionInfo>(*this);
28}
29
31 const RISCVSubtarget *STI) {
32
33 // The default stack probe size is 4096 if the function has no
34 // stack-probe-size attribute. This is a safe default because it is the
35 // smallest possible guard page size.
36 uint64_t ProbeSize = 4096;
37 if (F.hasFnAttribute("stack-probe-size"))
38 ProbeSize = F.getFnAttributeAsParsedInteger("stack-probe-size");
39 else if (const auto *PS = mdconst::extract_or_null<ConstantInt>(
40 F.getParent()->getModuleFlag("stack-probe-size")))
41 ProbeSize = PS->getZExtValue();
42 assert(int64_t(ProbeSize) > 0 && "Invalid stack probe size");
43
44 // Round down to the stack alignment.
45 uint64_t StackAlign =
47 ProbeSize = std::max(StackAlign, alignDown(ProbeSize, StackAlign));
48 StringRef ProbeKind;
49 if (F.hasFnAttribute("probe-stack"))
50 ProbeKind = F.getFnAttribute("probe-stack").getValueAsString();
51 else if (const auto *PS = dyn_cast_or_null<MDString>(
52 F.getParent()->getModuleFlag("probe-stack")))
53 ProbeKind = PS->getString();
54 if (ProbeKind.size()) {
55 StackProbeSize = ProbeSize;
56 }
57}
58
61 const MachineFunction &MF) const {
62 if (!MF.getFunction().hasFnAttribute("interrupt"))
63 return InterruptStackKind::None;
64
66 "Interrupt functions should not having incoming varargs");
67
68 StringRef InterruptVal =
70
72 InterruptVal)
73 .Case("qci-nest", InterruptStackKind::QCINest)
74 .Case("qci-nonest", InterruptStackKind::QCINoNest)
75 .Case("SiFive-CLIC-preemptible",
76 InterruptStackKind::SiFiveCLICPreemptible)
77 .Case("SiFive-CLIC-stack-swap", InterruptStackKind::SiFiveCLICStackSwap)
78 .Case("SiFive-CLIC-preemptible-stack-swap",
79 InterruptStackKind::SiFiveCLICPreemptibleStackSwap)
80 .Default(InterruptStackKind::None);
81}
82
85}
86
89 // We cannot use fixed locations for the callee saved spill slots if the
90 // function uses a varargs save area.
91 // TODO: Use a separate placement for vararg registers to enable Zcmp.
92 if (VarArgsSaveSize != 0)
93 return PushPopKind::None;
94
95 // SiFive interrupts are not compatible with push/pop.
96 if (useSiFiveInterrupt(MF))
97 return PushPopKind::None;
98
99 // Zcmp is not compatible with the frame pointer convention.
100 if (MF.getSubtarget<RISCVSubtarget>().hasStdExtZcmp() &&
102 return PushPopKind::StdExtZcmp;
103
104 // Xqccmp is Zcmp but has a push order compatible with the frame-pointer
105 // convention.
106 if (MF.getSubtarget<RISCVSubtarget>().hasVendorXqccmp())
107 return PushPopKind::VendorXqccmp;
108
109 return PushPopKind::None;
110}
111
113 const MachineFunction &MF) const {
114 switch (getInterruptStackKind(MF)) {
115 case InterruptStackKind::QCINest:
116 case InterruptStackKind::QCINoNest:
117 // QC.C.MIENTER and QC.C.MIENTER.NEST both update FP on function entry.
118 return true;
119 default:
120 break;
121 }
122
123 switch (getPushPopKind(MF)) {
124 case PushPopKind::VendorXqccmp:
125 // When using Xqccmp, we will use `QC.CM.PUSHFP` when Frame Pointers are
126 // enabled, which will update FP.
127 return true;
128 default:
129 break;
130 }
131
132 return false;
133}
134
136 const yaml::RISCVMachineFunctionInfo &YamlMFI) {
139}
140
142 SExt32Registers.push_back(Reg);
143}
144
146 return is_contained(SExt32Registers, Reg);
147}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
IO & YamlIO
Definition: ELFYAML.cpp:1327
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:400
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.cpp:762
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:727
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * cloneInfo(const Ty &Old)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
bool hasImplicitFPUpdates(const MachineFunction &MF) const
void initializeBaseYamlFields(const yaml::RISCVMachineFunctionInfo &YamlMFI)
InterruptStackKind getInterruptStackKind(const MachineFunction &MF) const
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
PushPopKind getPushPopKind(const MachineFunction &MF) const
const RISCVFrameLowering * getFrameLowering() const override
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:154
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:68
R Default(T Value)
Definition: StringSwitch.h:177
Align getTransientStackAlign() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
TargetOptions Options
LLVM_ABI bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
Definition: MathExtras.h:551
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1916
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
void mappingImpl(yaml::IO &YamlIO) override