diff options
author | paperchalice <lgamma@163.com> | 2023-11-30 12:26:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 13:26:49 +0900 |
commit | a4d5fd4d2ee9470e55345a9540f6b6fb6faf66e1 (patch) | |
tree | f0c76c956e6c55226dbb80b94cd2cfc6e1065591 /llvm/lib/CodeGen/SafeStack.cpp | |
parent | c43d0432ef35ee506bae642408f7140064514c8d (diff) | |
download | llvm-a4d5fd4d2ee9470e55345a9540f6b6fb6faf66e1.zip llvm-a4d5fd4d2ee9470e55345a9540f6b6fb6faf66e1.tar.gz llvm-a4d5fd4d2ee9470e55345a9540f6b6fb6faf66e1.tar.bz2 |
[CodeGen] Port SafeStack to new pass manager (#73747)
Just copy the `runOnFunction` method from `SafeStackLegacyPass` and
remove the workaround for computing analysis lazily, the analysis result
in new pass manager is computed lazily by default.
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, |