LLVM  14.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 <llvm/IR/Metadata.h>
19 #include <llvm/IR/Module.h>
20 
21 using namespace llvm;
22 
24  const llvm::AArch64FunctionInfo &MFI)
25  : HasRedZone(MFI.hasRedZone()) {}
26 
29 }
30 
32  const yaml::AArch64FunctionInfo &YamlMFI) {
33  if (YamlMFI.HasRedZone.hasValue())
34  HasRedZone = YamlMFI.HasRedZone;
35 }
36 
37 static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
38  // The function should be signed in the following situations:
39  // - sign-return-address=all
40  // - sign-return-address=non-leaf and the functions spills the LR
41  if (!F.hasFnAttribute("sign-return-address")) {
42  const Module &M = *F.getParent();
43  if (const auto *Sign = mdconst::extract_or_null<ConstantInt>(
44  M.getModuleFlag("sign-return-address"))) {
45  if (Sign->getZExtValue()) {
46  if (const auto *All = mdconst::extract_or_null<ConstantInt>(
47  M.getModuleFlag("sign-return-address-all")))
48  return {true, All->getZExtValue()};
49  return {true, false};
50  }
51  }
52  return {false, false};
53  }
54 
55  StringRef Scope = F.getFnAttribute("sign-return-address").getValueAsString();
56  if (Scope.equals("none"))
57  return {false, false};
58 
59  if (Scope.equals("all"))
60  return {true, true};
61 
62  assert(Scope.equals("non-leaf"));
63  return {true, false};
64 }
65 
66 static bool ShouldSignWithBKey(const Function &F) {
67  if (!F.hasFnAttribute("sign-return-address-key")) {
68  if (const auto *BKey = mdconst::extract_or_null<ConstantInt>(
69  F.getParent()->getModuleFlag("sign-return-address-with-bkey")))
70  return BKey->getZExtValue();
71  return false;
72  }
73 
74  const StringRef Key =
75  F.getFnAttribute("sign-return-address-key").getValueAsString();
76  assert(Key.equals_insensitive("a_key") || Key.equals_insensitive("b_key"));
77  return Key.equals_insensitive("b_key");
78 }
79 
81  // If we already know that the function doesn't have a redzone, set
82  // HasRedZone here.
83  if (MF.getFunction().hasFnAttribute(Attribute::NoRedZone))
84  HasRedZone = false;
85 
86  const Function &F = MF.getFunction();
87  std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
88  SignWithBKey = ShouldSignWithBKey(F);
89 
90  if (!F.hasFnAttribute("branch-target-enforcement")) {
91  if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
92  F.getParent()->getModuleFlag("branch-target-enforcement")))
93  BranchTargetEnforcement = BTE->getZExtValue();
94  return;
95  }
96 
97  const StringRef BTIEnable =
98  F.getFnAttribute("branch-target-enforcement").getValueAsString();
99  assert(BTIEnable.equals_insensitive("true") ||
100  BTIEnable.equals_insensitive("false"));
101  BranchTargetEnforcement = BTIEnable.equals_insensitive("true");
102 }
103 
105  if (!SignReturnAddress)
106  return false;
107  if (SignReturnAddressAll)
108  return true;
109  return SpillsLR;
110 }
111 
115  [](const auto &Info) { return Info.getReg() == AArch64::LR; }));
116 }
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
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:27
llvm::Function
Definition: Function.h:61
Module.h
YamlIO
IO & YamlIO
Definition: ELFYAML.cpp:1171
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:52
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:288
AArch64InstrInfo.h
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::AArch64FunctionInfo::shouldSignReturnAddress
bool shouldSignReturnAddress() const
Definition: AArch64MachineFunctionInfo.cpp:112
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:626
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
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
Definition: AArch64MachineFunctionInfo.h:37
ShouldSignWithBKey
static bool ShouldSignWithBKey(const Function &F)
Definition: AArch64MachineFunctionInfo.cpp:66
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:642
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::MachineFrameInfo::getCalleeSavedInfo
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
Definition: MachineFrameInfo.h:755
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:1558
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:592
llvm::AArch64FunctionInfo::initializeBaseYamlFields
void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI)
Definition: AArch64MachineFunctionInfo.cpp:31
llvm::yaml::AArch64FunctionInfo::HasRedZone
Optional< bool > HasRedZone
Definition: AArch64MachineFunctionInfo.h:421
GetSignReturnAddress
static std::pair< bool, bool > GetSignReturnAddress(const Function &F)
Definition: AArch64MachineFunctionInfo.cpp:37
llvm::yaml::AArch64FunctionInfo
Definition: AArch64MachineFunctionInfo.h:420