LLVM 19.0.0git
ARMMachineFunctionInfo.cpp
Go to the documentation of this file.
1//===-- ARMMachineFunctionInfo.cpp - ARM 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
10#include "ARMSubtarget.h"
11#include "llvm/IR/Module.h"
12
13using namespace llvm;
14
15void ARMFunctionInfo::anchor() {}
16
18 : LRSpilled(MFI.isLRSpilled()) {}
19
22}
23
25 const yaml::ARMFunctionInfo &YamlMFI) {
26 LRSpilled = YamlMFI.LRSpilled;
27}
28
30 const ARMSubtarget *Subtarget) {
31 if (!Subtarget->isMClass() || !Subtarget->hasV7Ops())
32 return false;
33
34 if (!F.hasFnAttribute("branch-target-enforcement")) {
35 if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
36 F.getParent()->getModuleFlag("branch-target-enforcement")))
37 return BTE->getZExtValue();
38 return false;
39 }
40
41 const StringRef BTIEnable =
42 F.getFnAttribute("branch-target-enforcement").getValueAsString();
43 assert(BTIEnable == "true" || BTIEnable == "false");
44 return BTIEnable == "true";
45}
46
47// The pair returns values for the ARMFunctionInfo members
48// SignReturnAddress and SignReturnAddressAll respectively.
49static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
50 if (!F.hasFnAttribute("sign-return-address")) {
51 const Module &M = *F.getParent();
52 if (const auto *Sign = mdconst::extract_or_null<ConstantInt>(
53 M.getModuleFlag("sign-return-address"))) {
54 if (Sign->getZExtValue()) {
55 if (const auto *All = mdconst::extract_or_null<ConstantInt>(
56 M.getModuleFlag("sign-return-address-all")))
57 return {true, All->getZExtValue()};
58 return {true, false};
59 }
60 }
61 return {false, false};
62 }
63
64 StringRef Scope = F.getFnAttribute("sign-return-address").getValueAsString();
65 if (Scope == "none")
66 return {false, false};
67
68 if (Scope == "all")
69 return {true, true};
70
71 assert(Scope == "non-leaf");
72 return {true, false};
73}
74
76 const ARMSubtarget *Subtarget)
77 : isThumb(Subtarget->isThumb()), hasThumb2(Subtarget->hasThumb2()),
78 IsCmseNSEntry(F.hasFnAttribute("cmse_nonsecure_entry")),
79 IsCmseNSCall(F.hasFnAttribute("cmse_nonsecure_call")),
80 BranchTargetEnforcement(GetBranchTargetEnforcement(F, Subtarget)) {
81 if (Subtarget->isMClass() && Subtarget->hasV7Ops())
82 std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
83}
84
88 &Src2DstMBB) const {
89 return DestMF.cloneInfo<ARMFunctionInfo>(*this);
90}
static std::pair< bool, bool > GetSignReturnAddress(const Function &F)
static bool isLRSpilled(const MachineFunction &MF)
static bool isThumb(const MCSubtargetInfo &STI)
static bool GetBranchTargetEnforcement(const Function &F, const ARMSubtarget *Subtarget)
IO & YamlIO
Definition: ELFYAML.cpp:1292
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
void initializeBaseYamlFields(const yaml::ARMFunctionInfo &YamlMFI)
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
bool isMClass() const
Definition: ARMSubtarget.h:366
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
Ty * cloneInfo(const Ty &Old)
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
void mappingImpl(yaml::IO &YamlIO) override