LLVM  15.0.0git
AArch64MachineFunctionInfo.cpp
Go to the documentation of this file.
1 //=- AArch64MachineFunctionInfo.cpp - AArch64 Machine Function Info ---------=//
2 
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file implements AArch64-specific per-machine-function
12 /// information.
13 ///
14 //===----------------------------------------------------------------------===//
15 
17 #include "AArch64InstrInfo.h"
18 #include "AArch64Subtarget.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/Metadata.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 
24 using namespace llvm;
25 
27  const llvm::AArch64FunctionInfo &MFI)
28  : HasRedZone(MFI.hasRedZone()) {}
29 
32 }
33 
35  const yaml::AArch64FunctionInfo &YamlMFI) {
36  if (YamlMFI.HasRedZone)
37  HasRedZone = YamlMFI.HasRedZone;
38 }
39 
40 static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
41  // The function should be signed in the following situations:
42  // - sign-return-address=all
43  // - sign-return-address=non-leaf and the functions spills the LR
44  if (!F.hasFnAttribute("sign-return-address")) {
45  const Module &M = *F.getParent();
46  if (const auto *Sign = mdconst::extract_or_null<ConstantInt>(
47  M.getModuleFlag("sign-return-address"))) {
48  if (Sign->getZExtValue()) {
49  if (const auto *All = mdconst::extract_or_null<ConstantInt>(
50  M.getModuleFlag("sign-return-address-all")))
51  return {true, All->getZExtValue()};
52  return {true, false};
53  }
54  }
55  return {false, false};
56  }
57 
58  StringRef Scope = F.getFnAttribute("sign-return-address").getValueAsString();
59  if (Scope.equals("none"))
60  return {false, false};
61 
62  if (Scope.equals("all"))
63  return {true, true};
64 
65  assert(Scope.equals("non-leaf"));
66  return {true, false};
67 }
68 
69 static bool ShouldSignWithBKey(const Function &F) {
70  if (!F.hasFnAttribute("sign-return-address-key")) {
71  if (const auto *BKey = mdconst::extract_or_null<ConstantInt>(
72  F.getParent()->getModuleFlag("sign-return-address-with-bkey")))
73  return BKey->getZExtValue();
74  return false;
75  }
76 
77  const StringRef Key =
78  F.getFnAttribute("sign-return-address-key").getValueAsString();
79  assert(Key.equals_insensitive("a_key") || Key.equals_insensitive("b_key"));
80  return Key.equals_insensitive("b_key");
81 }
82 
84  // If we already know that the function doesn't have a redzone, set
85  // HasRedZone here.
86  if (MF->getFunction().hasFnAttribute(Attribute::NoRedZone))
87  HasRedZone = false;
88 
89  const Function &F = MF->getFunction();
90  std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
91  SignWithBKey = ShouldSignWithBKey(F);
92  // TODO: skip functions that have no instrumented allocas for optimization
93  IsMTETagged = F.hasFnAttribute(Attribute::SanitizeMemTag);
94 
95  if (!F.hasFnAttribute("branch-target-enforcement")) {
96  if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
97  F.getParent()->getModuleFlag("branch-target-enforcement")))
98  BranchTargetEnforcement = BTE->getZExtValue();
99  return;
100  }
101 
102  const StringRef BTIEnable =
103  F.getFnAttribute("branch-target-enforcement").getValueAsString();
104  assert(BTIEnable.equals_insensitive("true") ||
105  BTIEnable.equals_insensitive("false"));
106  BranchTargetEnforcement = BTIEnable.equals_insensitive("true");
107 }
108 
112  const {
113  AArch64FunctionInfo *InfoClone = DestMF.cloneInfo<AArch64FunctionInfo>(*this);
114  InfoClone->MF = &DestMF;
115  return InfoClone;
116 }
117 
119  if (!SignReturnAddress)
120  return false;
121  if (SignReturnAddressAll)
122  return true;
123  return SpillsLR;
124 }
125 
129  [](const auto &Info) { return Info.getReg() == AArch64::LR; }));
130 }
131 
133  if (!NeedsDwarfUnwindInfo)
134  NeedsDwarfUnwindInfo = MF->needsFrameMoves() &&
136 
137  return *NeedsDwarfUnwindInfo;
138 }
139 
141  if (!NeedsAsyncDwarfUnwindInfo) {
142  const Function &F = MF->getFunction();
143  // The check got "minsize" is because epilogue unwind info is not emitted
144  // (yet) for homogeneous epilogues, outlined functions, and functions
145  // outlined from.
146  NeedsAsyncDwarfUnwindInfo = needsDwarfUnwindInfo() &&
147  F.getUWTableKind() == UWTableKind::Async &&
148  !F.hasMinSize();
149  }
150  return *NeedsAsyncDwarfUnwindInfo;
151 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
AArch64MachineFunctionInfo.h
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
Metadata.h
llvm::yaml::AArch64FunctionInfo::mappingImpl
void mappingImpl(yaml::IO &YamlIO) override
Definition: AArch64MachineFunctionInfo.cpp:30
llvm::Function
Definition: Function.h:60
Module.h
YamlIO
IO & YamlIO
Definition: ELFYAML.cpp:1235
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:51
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::AArch64FunctionInfo::clone
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
Definition: AArch64MachineFunctionInfo.cpp:109
AArch64InstrInfo.h
Constants.h
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
llvm::AArch64FunctionInfo::shouldSignReturnAddress
bool shouldSignReturnAddress() const
Definition: AArch64MachineFunctionInfo.cpp:126
llvm::AArch64FunctionInfo::needsAsyncDwarfUnwindInfo
bool needsAsyncDwarfUnwindInfo() const
Definition: AArch64MachineFunctionInfo.cpp:140
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:625
llvm::StringRef::equals_insensitive
LLVM_NODISCARD bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Definition: StringRef.h:194
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::yaml::AArch64FunctionInfo::AArch64FunctionInfo
AArch64FunctionInfo()=default
llvm::AArch64FunctionInfo::needsDwarfUnwindInfo
bool needsDwarfUnwindInfo() const
Definition: AArch64MachineFunctionInfo.cpp:132
llvm::DenseMap
Definition: DenseMap.h:716
llvm::AArch64FunctionInfo
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
Definition: AArch64MachineFunctionInfo.h:38
ShouldSignWithBKey
static bool ShouldSignWithBKey(const Function &F)
Definition: AArch64MachineFunctionInfo.cpp:69
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:672
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::MachineFrameInfo::getCalleeSavedInfo
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
Definition: MachineFrameInfo.h:779
llvm::TargetMachine::getMCAsmInfo
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
Definition: TargetMachine.h:205
MCAsmInfo.h
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1624
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MachineFunction::cloneInfo
Ty * cloneInfo(const Ty &Old)
Definition: MachineFunction.h:765
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:622
llvm::MachineFunction::needsFrameMoves
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
Definition: MachineFunction.cpp:611
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:652
llvm::AArch64FunctionInfo::initializeBaseYamlFields
void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI)
Definition: AArch64MachineFunctionInfo.cpp:34
AArch64Subtarget.h
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:142
llvm::yaml::AArch64FunctionInfo::HasRedZone
Optional< bool > HasRedZone
Definition: AArch64MachineFunctionInfo.h:440
GetSignReturnAddress
static std::pair< bool, bool > GetSignReturnAddress(const Function &F)
Definition: AArch64MachineFunctionInfo.cpp:40
llvm::MCAsmInfo::usesWindowsCFI
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:793
llvm::MachineFunctionInfo
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Definition: MachineFunction.h:95
llvm::UWTableKind::Async
@ Async
"Asynchronous" unwind tables (instr precise)
llvm::yaml::AArch64FunctionInfo
Definition: AArch64MachineFunctionInfo.h:439