Skip to content

Commit

Permalink
[NFC][Clang] Move functions of BranchProtectionInfo out of line (#98329)
Browse files Browse the repository at this point in the history
Also let's add const to the setFnAttributes.
  • Loading branch information
DanielKristofKiss authored Jul 11, 2024
1 parent d9d977f commit 4710e0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
23 changes: 4 additions & 19 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Frontend/OpenMP/OMPGridValues.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/VersionTuple.h"
Expand All @@ -47,6 +45,8 @@

namespace llvm {
struct fltSemantics;
class Function;
class AttrBuilder;
}

namespace clang {
Expand Down Expand Up @@ -1455,24 +1455,9 @@ class TargetInfo : public TransferrableTargetInfo,
GuardedControlStack = LangOpts.GuardedControlStack;
}

void setFnAttributes(llvm::Function &F) {
llvm::AttrBuilder FuncAttrs(F.getContext());
setFnAttributes(FuncAttrs);
F.addFnAttrs(FuncAttrs);
}
void setFnAttributes(llvm::Function &F) const;

void setFnAttributes(llvm::AttrBuilder &FuncAttrs) {
if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
}
if (BranchTargetEnforcement)
FuncAttrs.addAttribute("branch-target-enforcement");
if (BranchProtectionPAuthLR)
FuncAttrs.addAttribute("branch-protection-pauth-lr");
if (GuardedControlStack)
FuncAttrs.addAttribute("guarded-control-stack");
}
void setFnAttributes(llvm::AttrBuilder &FuncAttrs) const;
};

/// Determine if the Architecture in this TargetInfo supports branch
Expand Down
22 changes: 22 additions & 0 deletions clang/lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/TargetParser/TargetParser.h"
#include <cstdlib>
Expand Down Expand Up @@ -1005,3 +1006,24 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
*Target = *Src;
}

void TargetInfo::BranchProtectionInfo::setFnAttributes(
llvm::Function &F) const {
llvm::AttrBuilder FuncAttrs(F.getContext());
setFnAttributes(FuncAttrs);
F.addFnAttrs(FuncAttrs);
}

void TargetInfo::BranchProtectionInfo::setFnAttributes(
llvm::AttrBuilder &FuncAttrs) const {
if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
}
if (BranchTargetEnforcement)
FuncAttrs.addAttribute("branch-target-enforcement");
if (BranchProtectionPAuthLR)
FuncAttrs.addAttribute("branch-protection-pauth-lr");
if (GuardedControlStack)
FuncAttrs.addAttribute("guarded-control-stack");
}

0 comments on commit 4710e0f

Please sign in to comment.