diff options
author | paperchalice <lgamma@163.com> | 2023-12-01 12:55:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 13:55:05 +0900 |
commit | 3bd517205799a152689434ceddf9493765f1e883 (patch) | |
tree | 99091c2fd51d16079b90da8bdfd4b8d933753ca2 /llvm/lib/CodeGen/SafeStack.cpp | |
parent | 54878b80f3e332f3420132f8b4c74412fc29ef6b (diff) | |
download | llvm-3bd517205799a152689434ceddf9493765f1e883.zip llvm-3bd517205799a152689434ceddf9493765f1e883.tar.gz llvm-3bd517205799a152689434ceddf9493765f1e883.tar.bz2 |
Reland "[CodeGen] Port SafeStack to new pass manager (#74027)
Forgot to update related code in `CodeGenPassBuilder.h`, also update it
for `CallBrPreparePass`.
Fix build when `LLVM_ENABLE_MODULES:BOOL=ON`.
Diffstat (limited to 'llvm/lib/CodeGen/SafeStack.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SafeStack.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index ef293fa..88db57a 100644 --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -14,6 +14,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/SafeStack.h" #include "SafeStackLayout.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" @@ -927,6 +928,42 @@ public: } // end anonymous namespace +PreservedAnalyses SafeStackPass::run(Function &F, + FunctionAnalysisManager &FAM) { + LLVM_DEBUG(dbgs() << "[SafeStack] Function: " << F.getName() << "\n"); + + if (!F.hasFnAttribute(Attribute::SafeStack)) { + LLVM_DEBUG(dbgs() << "[SafeStack] safestack is not requested" + " for this function\n"); + return PreservedAnalyses::all(); + } + + if (F.isDeclaration()) { + LLVM_DEBUG(dbgs() << "[SafeStack] function definition" + " is not available\n"); + return PreservedAnalyses::all(); + } + + auto *TL = TM->getSubtargetImpl(F)->getTargetLowering(); + if (!TL) + report_fatal_error("TargetLowering instance is required"); + + auto &DL = F.getParent()->getDataLayout(); + + // preserve DominatorTree + auto &DT = FAM.getResult<DominatorTreeAnalysis>(F); + auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F); + DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy); + + bool Changed = SafeStack(F, *TL, DL, &DTU, SE).run(); + + if (!Changed) + return PreservedAnalyses::all(); + PreservedAnalyses PA; + PA.preserve<DominatorTreeAnalysis>(); + return PA; +} + char SafeStackLegacyPass::ID = 0; INITIALIZE_PASS_BEGIN(SafeStackLegacyPass, DEBUG_TYPE, |