Skip to content

Commit b31279d

Browse files
committed
working with hack
1 parent 2e8aef7 commit b31279d

File tree

7 files changed

+37
-52
lines changed

7 files changed

+37
-52
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include "llvm/Transforms/Scalar/EarlyCSE.h"
8787
#include "llvm/Transforms/Scalar/GVN.h"
8888
#include "llvm/Transforms/Scalar/JumpThreading.h"
89+
#include "llvm/Transforms/Scalar/SROA.h"
8990
#include "llvm/Transforms/Utils/Debugify.h"
9091
#include "llvm/Transforms/Utils/ModuleUtils.h"
9192
#include <memory>
@@ -992,13 +993,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
992993
});
993994

994995
if (LangOpts.Sanitize.has(SanitizerKind::Realtime)) {
995-
PB.registerLoopOptimizerEndEPCallback(
996-
[](LoopPassManager &LPM, OptimizationLevel Level) {
997-
LPM.addPass(RealtimeSanitizerLoopPass());
998-
});
999996
PB.registerScalarOptimizerLateEPCallback(
1000997
[](FunctionPassManager &FPM, OptimizationLevel Level) {
1001998
RealtimeSanitizerOptions Opts;
999+
FPM.addPass(SROAPass(SROAOptions::PreserveCFG));
10021000
FPM.addPass(RealtimeSanitizerPass(Opts));
10031001
});
10041002
}

llvm/include/llvm/Transforms/Instrumentation/RealtimeSanitizer.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define LLVM_TRANSFORMS_INSTRUMENTATION_REALTIMESANITIZER_H
2121

2222
#include "llvm/IR/PassManager.h"
23-
#include "llvm/Transforms/Scalar/LoopPassManager.h"
2423

2524
namespace llvm {
2625

@@ -34,12 +33,6 @@ class RealtimeSanitizerPass : public PassInfoMixin<RealtimeSanitizerPass> {
3433
static bool isRequired() { return true; }
3534
};
3635

37-
struct RealtimeSanitizerLoopPass : PassInfoMixin<RealtimeSanitizerLoopPass> {
38-
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
39-
LoopStandardAnalysisResults &AR, LPMUpdater &U);
40-
static bool isRequired() { return true; }
41-
};
42-
4336
} // namespace llvm
4437

4538
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_REALTIMESANITIZER_H

llvm/lib/Passes/PassRegistry.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@ LOOP_PASS("print<ddg>", DDGAnalysisPrinterPass(dbgs()))
659659
LOOP_PASS("print<iv-users>", IVUsersPrinterPass(dbgs()))
660660
LOOP_PASS("print<loop-cache-cost>", LoopCachePrinterPass(dbgs()))
661661
LOOP_PASS("print<loopnest>", LoopNestPrinterPass(dbgs()))
662-
LOOP_PASS("sanitize-unbound-loops", RealtimeSanitizerLoopPass())
663662
#undef LOOP_PASS
664663

665664
#ifndef LOOP_PASS_WITH_PARAMS

llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,54 +63,49 @@ RealtimeSanitizerPass::RealtimeSanitizerPass(
6363

6464
PreservedAnalyses RealtimeSanitizerPass::run(Function &F,
6565
AnalysisManager<Function> &AM) {
66+
PreservedAnalyses PA = PreservedAnalyses::all();
6667
if (F.hasFnAttribute(Attribute::SanitizeRealtime)) {
6768
insertCallAtFunctionEntryPoint(F, "__rtsan_realtime_enter");
6869
insertCallAtAllFunctionExitPoints(F, "__rtsan_realtime_exit");
69-
70-
PreservedAnalyses PA;
70+
PA = PreservedAnalyses::none();
7171
PA.preserveSet<CFGAnalyses>();
72-
return PA;
7372
}
7473

75-
return PreservedAnalyses::all();
76-
}
77-
78-
PreservedAnalyses
79-
RealtimeSanitizerLoopPass::run(Loop &L, LoopAnalysisManager &AM,
80-
LoopStandardAnalysisResults &AR, LPMUpdater &U) {
81-
BasicBlock *Context =
82-
L.getLoopPreheader() ? L.getLoopPreheader() : L.getHeader();
83-
assert(Context && "Loop has no preheader or header block");
74+
const LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
75+
ScalarEvolution &SE = AM.getResult<ScalarEvolutionAnalysis>(F);
76+
for (Loop *L : LI) {
77+
BasicBlock *Context =
78+
L->getLoopPreheader() ? L->getLoopPreheader() : L->getHeader();
79+
assert(Context && "Loop has no preheader or header block");
8480

85-
Function *F = Context->getParent();
86-
assert(F && "Loop has no parent function");
81+
const bool HasNoExits = L->hasNoExitBlocks();
82+
const bool CannotPredictLoopCount =
83+
isa<SCEVCouldNotCompute>(SE.getConstantMaxBackedgeTakenCount(L)) ||
84+
isa<SCEVCouldNotCompute>(SE.getBackedgeTakenCount(L));
85+
const bool LoopIsPotentiallyUnbound = HasNoExits || CannotPredictLoopCount;
8786

88-
const bool HasNoExits = L.hasNoExitBlocks();
89-
const bool CannotPredictLoopCount =
90-
isa<SCEVCouldNotCompute>(AR.SE.getConstantMaxBackedgeTakenCount(&L)) ||
91-
isa<SCEVCouldNotCompute>(AR.SE.getBackedgeTakenCount(&L));
92-
const bool LoopIsPotentiallyUnbound = HasNoExits || CannotPredictLoopCount;
87+
if (LoopIsPotentiallyUnbound) {
88+
IRBuilder<> Builder{&Context->back()};
9389

94-
if (LoopIsPotentiallyUnbound) {
95-
IRBuilder<> Builder{&Context->back()};
9690

9791
std::string ReasonStr =
98-
demangle(F->getName().str()) + " contains a possibly unbounded loop ";
99-
100-
if (HasNoExits)
101-
ReasonStr += "(reason: no exit blocks).";
102-
else if (CannotPredictLoopCount)
103-
ReasonStr += "(reason: backedge taken count cannot be computed).";
104-
else
105-
assert(false);
106-
107-
Value *Reason = Builder.CreateGlobalStringPtr(ReasonStr);
108-
insertCallBeforeInstruction(*F, Builder, "__rtsan_expect_not_realtime",
109-
{Reason});
110-
111-
// TODO: What is preserved here??
112-
return PreservedAnalyses::none();
92+
demangle(F.getName().str()) + " contains a possibly unbounded loop ";
93+
94+
if (HasNoExits)
95+
ReasonStr += "(reason: no exit blocks).";
96+
else if (CannotPredictLoopCount)
97+
ReasonStr += "(reason: backedge taken count cannot be computed).";
98+
else
99+
assert(false);
100+
101+
Value *Reason = Builder.CreateGlobalStringPtr(ReasonStr);
102+
insertCallBeforeInstruction(F, Builder, "__rtsan_expect_not_realtime",
103+
{Reason});
104+
105+
// TODO: What is preserved here??
106+
PA = PreservedAnalyses::none();
107+
}
113108
}
114109

115-
return PreservedAnalyses::all();
110+
return PA;
116111
}

llvm/test/Instrumentation/RealtimeSanitizer/rtsan_bound_loop.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt < %s -passes='sroa,sanitize-unbound-loops' -S | FileCheck %s
1+
; RUN: opt < %s -passes='sroa,rtsan' -S | FileCheck %s
22

33

44
define void @procces(ptr noundef %buffer, i32 noundef %size) #0 {

llvm/test/Instrumentation/RealtimeSanitizer/rtsan_cas_spinlock.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt < %s -passes='sanitize-unbound-loops' -S | FileCheck %s
1+
; RUN: opt < %s -passes=rtsan -S | FileCheck %s
22

33
%class.SpinLockTestAndSet = type { %"struct.std::__1::atomic_flag" }
44
%"struct.std::__1::atomic_flag" = type { %"struct.std::__1::__cxx_atomic_impl" }

llvm/test/Instrumentation/RealtimeSanitizer/rtsan_infinite_loop.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt < %s -passes='sanitize-unbound-loops' -S | FileCheck %s
1+
; RUN: opt < %s -passes=rtsan -S | FileCheck %s
22

33
define void @process() #0 {
44
entry:

0 commit comments

Comments
 (0)