xref: /freebsd/contrib/llvm-project/llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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 
anchor()15 void ARMFunctionInfo::anchor() {}
16 
ARMFunctionInfo(const llvm::ARMFunctionInfo & MFI)17 yaml::ARMFunctionInfo::ARMFunctionInfo(const llvm::ARMFunctionInfo &MFI)
18     : LRSpilled(MFI.isLRSpilled()) {}
19 
mappingImpl(yaml::IO & YamlIO)20 void yaml::ARMFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
21   MappingTraits<ARMFunctionInfo>::mapping(YamlIO, *this);
22 }
23 
initializeBaseYamlFields(const yaml::ARMFunctionInfo & YamlMFI)24 void ARMFunctionInfo::initializeBaseYamlFields(
25     const yaml::ARMFunctionInfo &YamlMFI) {
26   LRSpilled = YamlMFI.LRSpilled;
27 }
28 
GetBranchTargetEnforcement(const Function & F,const ARMSubtarget * Subtarget)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("branch-target-enforcement");
35 }
36 
37 // The pair returns values for the ARMFunctionInfo members
38 // SignReturnAddress and SignReturnAddressAll respectively.
GetSignReturnAddress(const Function & F)39 static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
40   if (!F.hasFnAttribute("sign-return-address")) {
41     return {false, false};
42   }
43 
44   StringRef Scope = F.getFnAttribute("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 
ARMFunctionInfo(const Function & F,const ARMSubtarget * Subtarget)55 ARMFunctionInfo::ARMFunctionInfo(const Function &F,
56                                  const ARMSubtarget *Subtarget)
57     : isThumb(Subtarget->isThumb()), hasThumb2(Subtarget->hasThumb2()),
58       IsCmseNSEntry(F.hasFnAttribute("cmse_nonsecure_entry")),
59       IsCmseNSCall(F.hasFnAttribute("cmse_nonsecure_call")),
60       BranchTargetEnforcement(GetBranchTargetEnforcement(F, Subtarget)) {
61   if (Subtarget->isMClass() && Subtarget->hasV7Ops())
62     std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
63 }
64 
65 MachineFunctionInfo *
clone(BumpPtrAllocator & Allocator,MachineFunction & DestMF,const DenseMap<MachineBasicBlock *,MachineBasicBlock * > & Src2DstMBB) const66 ARMFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
67                        const DenseMap<MachineBasicBlock *, MachineBasicBlock *>
68                            &Src2DstMBB) const {
69   return DestMF.cloneInfo<ARMFunctionInfo>(*this);
70 }
71