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 | |
9 | #include "ARMMachineFunctionInfo.h" |
10 | #include "ARMSubtarget.h" |
11 | #include "llvm/IR/Module.h" |
12 | |
13 | using namespace llvm; |
14 | |
15 | void ARMFunctionInfo::anchor() {} |
16 | |
17 | yaml::ARMFunctionInfo::ARMFunctionInfo(const llvm::ARMFunctionInfo &MFI) |
18 | : LRSpilled(MFI.isLRSpilled()) {} |
19 | |
20 | void yaml::ARMFunctionInfo::mappingImpl(yaml::IO &YamlIO) { |
21 | MappingTraits<ARMFunctionInfo>::mapping(YamlIO, MFI&: *this); |
22 | } |
23 | |
24 | void ARMFunctionInfo::initializeBaseYamlFields( |
25 | const yaml::ARMFunctionInfo &YamlMFI) { |
26 | LRSpilled = YamlMFI.LRSpilled; |
27 | } |
28 | |
29 | static bool GetBranchTargetEnforcement(const Function &F, |
30 | const ARMSubtarget *Subtarget) { |
31 | if (!Subtarget->isMClass() || !Subtarget->hasV7Ops()) |
32 | return false; |
33 | |
34 | return F.hasFnAttribute(Kind: "branch-target-enforcement" ); |
35 | } |
36 | |
37 | // The pair returns values for the ARMFunctionInfo members |
38 | // SignReturnAddress and SignReturnAddressAll respectively. |
39 | static std::pair<bool, bool> GetSignReturnAddress(const Function &F) { |
40 | if (!F.hasFnAttribute(Kind: "sign-return-address" )) { |
41 | return {false, false}; |
42 | } |
43 | |
44 | StringRef Scope = F.getFnAttribute(Kind: "sign-return-address" ).getValueAsString(); |
45 | if (Scope == "none" ) |
46 | return {false, false}; |
47 | |
48 | if (Scope == "all" ) |
49 | return {true, true}; |
50 | |
51 | assert(Scope == "non-leaf" ); |
52 | return {true, false}; |
53 | } |
54 | |
55 | ARMFunctionInfo::ARMFunctionInfo(const Function &F, |
56 | const ARMSubtarget *Subtarget) |
57 | : isThumb(Subtarget->isThumb()), hasThumb2(Subtarget->hasThumb2()), |
58 | IsCmseNSEntry(F.hasFnAttribute(Kind: "cmse_nonsecure_entry" )), |
59 | IsCmseNSCall(F.hasFnAttribute(Kind: "cmse_nonsecure_call" )), |
60 | BranchTargetEnforcement(GetBranchTargetEnforcement(F, Subtarget)) { |
61 | if (Subtarget->isMClass() && Subtarget->hasV7Ops()) |
62 | std::tie(args&: SignReturnAddress, args&: SignReturnAddressAll) = GetSignReturnAddress(F); |
63 | } |
64 | |
65 | MachineFunctionInfo * |
66 | ARMFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, |
67 | const DenseMap<MachineBasicBlock *, MachineBasicBlock *> |
68 | &Src2DstMBB) const { |
69 | return DestMF.cloneInfo<ARMFunctionInfo>(Old: *this); |
70 | } |
71 | |