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.hasValue())
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 
93  if (!F.hasFnAttribute("branch-target-enforcement")) {
94  if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
95  F.getParent()->getModuleFlag("branch-target-enforcement")))
96  BranchTargetEnforcement = BTE->getZExtValue();
97  return;
98  }
99 
100  const StringRef BTIEnable =
101  F.getFnAttribute("branch-target-enforcement").getValueAsString();
102  assert(BTIEnable.equals_insensitive("true") ||
103  BTIEnable.equals_insensitive("false"));
104  BranchTargetEnforcement = BTIEnable.equals_insensitive("true");
105 }
106 
108  if (!SignReturnAddress)
109  return false;
110  if (SignReturnAddressAll)
111  return true;
112  return SpillsLR;
113 }
114 
118  [](const auto &Info) { return Info.getReg() == AArch64::LR; }));
119 }
120 
122  if (!NeedsDwarfUnwindInfo)
123  NeedsDwarfUnwindInfo = MF.needsFrameMoves() &&
125 
126  return *NeedsDwarfUnwindInfo;
127 }
128 
130  if (!NeedsAsyncDwarfUnwindInfo) {
131  const Function &F = MF.getFunction();
132  // The check got "minsize" is because epilogue unwind info is not emitted
133  // (yet) for homogeneous epilogues, outlined functions, and functions
134  // outlined from.
135  NeedsAsyncDwarfUnwindInfo = needsDwarfUnwindInfo() &&
136  F.getUWTableKind() == UWTableKind::Async &&
137  !F.hasMinSize();
138  }
139  return *NeedsAsyncDwarfUnwindInfo;
140 }
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:1224
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:51
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:283
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:115
llvm::AArch64FunctionInfo::needsAsyncDwarfUnwindInfo
bool needsAsyncDwarfUnwindInfo() const
Definition: AArch64MachineFunctionInfo.cpp:129
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::yaml::AArch64FunctionInfo::AArch64FunctionInfo
AArch64FunctionInfo()=default
llvm::AArch64FunctionInfo::needsDwarfUnwindInfo
bool needsDwarfUnwindInfo() const
Definition: AArch64MachineFunctionInfo.cpp:121
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:656
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:241
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:1612
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:606
llvm::MachineFunction::needsFrameMoves
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
Definition: MachineFunction.cpp:613
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:636
llvm::AArch64FunctionInfo::initializeBaseYamlFields
void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI)
Definition: AArch64MachineFunctionInfo.cpp:34
AArch64Subtarget.h
llvm::yaml::AArch64FunctionInfo::HasRedZone
Optional< bool > HasRedZone
Definition: AArch64MachineFunctionInfo.h:432
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::UWTableKind::Async
@ Async
"Asynchronous" unwind tables (instr precise)
llvm::yaml::AArch64FunctionInfo
Definition: AArch64MachineFunctionInfo.h:431