1 //=- RISCVMachineFunctionInfo.cpp - RISC-V machine function info --*- C++ -*-=//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares RISCV-specific per-machine-function information.
11 //===----------------------------------------------------------------------===//
13 #include "RISCVMachineFunctionInfo.h"
14 #include "llvm/IR/Module.h"
18 yaml::RISCVMachineFunctionInfo::RISCVMachineFunctionInfo(
19 const llvm::RISCVMachineFunctionInfo
&MFI
)
20 : VarArgsFrameIndex(MFI
.getVarArgsFrameIndex()),
21 VarArgsSaveSize(MFI
.getVarArgsSaveSize()) {}
23 MachineFunctionInfo
*RISCVMachineFunctionInfo::clone(
24 BumpPtrAllocator
&Allocator
, MachineFunction
&DestMF
,
25 const DenseMap
<MachineBasicBlock
*, MachineBasicBlock
*> &Src2DstMBB
)
27 return DestMF
.cloneInfo
<RISCVMachineFunctionInfo
>(*this);
30 RISCVMachineFunctionInfo::RISCVMachineFunctionInfo(const Function
&F
,
31 const RISCVSubtarget
*STI
) {
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");
44 // Round down to the stack alignment.
46 STI
->getFrameLowering()->getTransientStackAlign().value();
47 ProbeSize
= std::max(StackAlign
, alignDown(ProbeSize
, StackAlign
));
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
;
59 void yaml::RISCVMachineFunctionInfo::mappingImpl(yaml::IO
&YamlIO
) {
60 MappingTraits
<RISCVMachineFunctionInfo
>::mapping(YamlIO
, *this);
63 void RISCVMachineFunctionInfo::initializeBaseYamlFields(
64 const yaml::RISCVMachineFunctionInfo
&YamlMFI
) {
65 VarArgsFrameIndex
= YamlMFI
.VarArgsFrameIndex
;
66 VarArgsSaveSize
= YamlMFI
.VarArgsSaveSize
;
69 void RISCVMachineFunctionInfo::addSExt32Register(Register Reg
) {
70 SExt32Registers
.push_back(Reg
);
73 bool RISCVMachineFunctionInfo::isSExt32Register(Register Reg
) const {
74 return is_contained(SExt32Registers
, Reg
);