ARMMachineFunctionInfo.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //===-- ARMMachineFunctionInfo.cpp - ARM machine function info ------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "ARMMachineFunctionInfo.h"
  9. #include "ARMSubtarget.h"
  10. using namespace llvm;
  11. void ARMFunctionInfo::anchor() {}
  12. static bool GetBranchTargetEnforcement(const Function &F,
  13. const ARMSubtarget *Subtarget) {
  14. if (!Subtarget->isMClass() || !Subtarget->hasV7Ops())
  15. return false;
  16. if (!F.hasFnAttribute("branch-target-enforcement")) {
  17. if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
  18. F.getParent()->getModuleFlag("branch-target-enforcement")))
  19. return BTE->getZExtValue();
  20. return false;
  21. }
  22. const StringRef BTIEnable =
  23. F.getFnAttribute("branch-target-enforcement").getValueAsString();
  24. assert(BTIEnable.equals_insensitive("true") ||
  25. BTIEnable.equals_insensitive("false"));
  26. return BTIEnable.equals_insensitive("true");
  27. }
  28. // The pair returns values for the ARMFunctionInfo members
  29. // SignReturnAddress and SignReturnAddressAll respectively.
  30. static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
  31. if (!F.hasFnAttribute("sign-return-address")) {
  32. const Module &M = *F.getParent();
  33. if (const auto *Sign = mdconst::extract_or_null<ConstantInt>(
  34. M.getModuleFlag("sign-return-address"))) {
  35. if (Sign->getZExtValue()) {
  36. if (const auto *All = mdconst::extract_or_null<ConstantInt>(
  37. M.getModuleFlag("sign-return-address-all")))
  38. return {true, All->getZExtValue()};
  39. return {true, false};
  40. }
  41. }
  42. return {false, false};
  43. }
  44. StringRef Scope = F.getFnAttribute("sign-return-address").getValueAsString();
  45. if (Scope.equals("none"))
  46. return {false, false};
  47. if (Scope.equals("all"))
  48. return {true, true};
  49. assert(Scope.equals("non-leaf"));
  50. return {true, false};
  51. }
  52. ARMFunctionInfo::ARMFunctionInfo(const Function &F,
  53. const ARMSubtarget *Subtarget)
  54. : isThumb(Subtarget->isThumb()), hasThumb2(Subtarget->hasThumb2()),
  55. IsCmseNSEntry(F.hasFnAttribute("cmse_nonsecure_entry")),
  56. IsCmseNSCall(F.hasFnAttribute("cmse_nonsecure_call")),
  57. BranchTargetEnforcement(GetBranchTargetEnforcement(F, Subtarget)) {
  58. if (Subtarget->isMClass() && Subtarget->hasV7Ops())
  59. std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
  60. }
  61. MachineFunctionInfo *
  62. ARMFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
  63. const DenseMap<MachineBasicBlock *, MachineBasicBlock *>
  64. &Src2DstMBB) const {
  65. return DestMF.cloneInfo<ARMFunctionInfo>(*this);
  66. }