LLVM  16.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, const MachineFunction &MF) {
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();
75  return true;
76  return false;
77  }
78 
79  const StringRef Key =
80  F.getFnAttribute("sign-return-address-key").getValueAsString();
81  assert(Key.equals_insensitive("a_key") || Key.equals_insensitive("b_key"));
82  return Key.equals_insensitive("b_key");
83 }
84 
86  // If we already know that the function doesn't have a redzone, set
87  // HasRedZone here.
88  if (MF->getFunction().hasFnAttribute(Attribute::NoRedZone))
89  HasRedZone = false;
90 
91  const Function &F = MF->getFunction();
92  std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
93  SignWithBKey = ShouldSignWithBKey(F, *MF);
94  // TODO: skip functions that have no instrumented allocas for optimization
95  IsMTETagged = F.hasFnAttribute(Attribute::SanitizeMemTag);
96 
97  if (!F.hasFnAttribute("branch-target-enforcement")) {
98  if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
99  F.getParent()->getModuleFlag("branch-target-enforcement")))
100  BranchTargetEnforcement = BTE->getZExtValue();
101  return;
102  }
103 
104  const StringRef BTIEnable =
105  F.getFnAttribute("branch-target-enforcement").getValueAsString();
106  assert(BTIEnable.equals_insensitive("true") ||
107  BTIEnable.equals_insensitive("false"));
108  BranchTargetEnforcement = BTIEnable.equals_insensitive("true");
109 }
110 
114  const {
115  AArch64FunctionInfo *InfoClone = DestMF.cloneInfo<AArch64FunctionInfo>(*this);
116  InfoClone->MF = &DestMF;
117  return InfoClone;
118 }
119 
121  if (!SignReturnAddress)
122  return false;
123  if (SignReturnAddressAll)
124  return true;
125  return SpillsLR;
126 }
127 
131  [](const auto &Info) { return Info.getReg() == AArch64::LR; }));
132 }
133 
135  if (!NeedsDwarfUnwindInfo)
136  NeedsDwarfUnwindInfo = MF->needsFrameMoves() &&
138 
139  return *NeedsDwarfUnwindInfo;
140 }
141 
143  if (!NeedsAsyncDwarfUnwindInfo) {
144  const Function &F = MF->getFunction();
145  // The check got "minsize" is because epilogue unwind info is not emitted
146  // (yet) for homogeneous epilogues, outlined functions, and functions
147  // outlined from.
148  NeedsAsyncDwarfUnwindInfo = needsDwarfUnwindInfo() &&
149  F.getUWTableKind() == UWTableKind::Async &&
150  !F.hasMinSize();
151  }
152  return *NeedsAsyncDwarfUnwindInfo;
153 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1250
ShouldSignWithBKey
static bool ShouldSignWithBKey(const Function &F, const MachineFunction &MF)
Definition: AArch64MachineFunctionInfo.cpp:69
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:53
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:111
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:128
llvm::AArch64FunctionInfo::needsAsyncDwarfUnwindInfo
bool needsAsyncDwarfUnwindInfo() const
Definition: AArch64MachineFunctionInfo.cpp:142
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:629
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:134
llvm::DenseMap
Definition: DenseMap.h:714
llvm::AArch64FunctionInfo
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
Definition: AArch64MachineFunctionInfo.h:38
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:673
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:787
llvm::TargetMachine::getMCAsmInfo
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
Definition: TargetMachine.h:204
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:1741
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::MachineFunction::cloneInfo
Ty * cloneInfo(const Ty &Old)
Definition: MachineFunction.h:766
llvm::Triple::isOSWindows
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:582
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:623
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:653
llvm::AArch64FunctionInfo::initializeBaseYamlFields
void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI)
Definition: AArch64MachineFunctionInfo.cpp:34
llvm::StringRef::equals_insensitive
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Definition: StringRef.h:170
AArch64Subtarget.h
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
llvm::yaml::AArch64FunctionInfo::HasRedZone
Optional< bool > HasRedZone
Definition: AArch64MachineFunctionInfo.h:460
llvm::TargetMachine::getTargetTriple
const Triple & getTargetTriple() const
Definition: TargetMachine.h:125
GetSignReturnAddress
static std::pair< bool, bool > GetSignReturnAddress(const Function &F)
Definition: AArch64MachineFunctionInfo.cpp:40
llvm::MCAsmInfo::usesWindowsCFI
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:797
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:459