10
10
11
11
#include " llvm/ADT/SmallVector.h"
12
12
#include " llvm/ADT/Statistic.h"
13
+ #include " llvm/ADT/StringRef.h"
14
+ #include " llvm/Analysis/OptimizationRemarkEmitter.h"
13
15
#include " llvm/Analysis/ProfileSummaryInfo.h"
14
16
#include " llvm/IR/Constant.h"
17
+ #include " llvm/IR/Constants.h"
18
+ #include " llvm/IR/DiagnosticInfo.h"
15
19
#include " llvm/IR/Instructions.h"
16
20
#include " llvm/IR/IntrinsicInst.h"
17
21
#include " llvm/IR/Intrinsics.h"
22
+ #include " llvm/IR/Metadata.h"
18
23
#include " llvm/Support/RandomNumberGenerator.h"
19
24
#include < memory>
20
25
#include < random>
@@ -35,13 +40,41 @@ static cl::opt<float>
35
40
STATISTIC (NumChecksTotal, " Number of checks" );
36
41
STATISTIC (NumChecksRemoved, " Number of removed checks" );
37
42
43
+ struct RemarkInfo {
44
+ ore::NV Kind;
45
+ ore::NV F;
46
+ ore::NV BB;
47
+ explicit RemarkInfo (IntrinsicInst *II)
48
+ : Kind(" Kind" , II->getArgOperand (0 )),
49
+ F(" Function" , II->getParent ()->getParent()),
50
+ BB(" Block" , II->getParent ()->getName()) {}
51
+ };
52
+
53
+ static void emitRemark (IntrinsicInst *II, OptimizationRemarkEmitter &ORE,
54
+ bool Removed) {
55
+ if (Removed) {
56
+ ORE.emit ([&]() {
57
+ RemarkInfo Info (II);
58
+ return OptimizationRemark (DEBUG_TYPE, " Removed" , II)
59
+ << " Removed check: Kind=" << Info.Kind << " F=" << Info.F
60
+ << " BB=" << Info.BB ;
61
+ });
62
+ } else {
63
+ ORE.emit ([&]() {
64
+ RemarkInfo Info (II);
65
+ return OptimizationRemarkMissed (DEBUG_TYPE, " Allowed" , II)
66
+ << " Allowed check: Kind=" << Info.Kind << " F=" << Info.F
67
+ << " BB=" << Info.BB ;
68
+ });
69
+ }
70
+ }
71
+
38
72
static bool removeUbsanTraps (Function &F, const BlockFrequencyInfo &BFI,
39
- const ProfileSummaryInfo *PSI) {
73
+ const ProfileSummaryInfo *PSI,
74
+ OptimizationRemarkEmitter &ORE) {
40
75
SmallVector<std::pair<IntrinsicInst *, bool >, 16 > ReplaceWithValue;
41
76
std::unique_ptr<RandomNumberGenerator> Rng;
42
77
43
- // TODO:
44
- // https://github.com/llvm/llvm-project/pull/84858#discussion_r1520603139
45
78
auto ShouldRemove = [&](bool IsHot) {
46
79
if (!RandomRate.getNumOccurrences ())
47
80
return IsHot;
@@ -75,6 +108,7 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI,
75
108
});
76
109
if (ToRemove)
77
110
++NumChecksRemoved;
111
+ emitRemark (II, ORE, ToRemove);
78
112
break ;
79
113
}
80
114
default :
@@ -99,9 +133,11 @@ PreservedAnalyses LowerAllowCheckPass::run(Function &F,
99
133
ProfileSummaryInfo *PSI =
100
134
MAMProxy.getCachedResult <ProfileSummaryAnalysis>(*F.getParent ());
101
135
BlockFrequencyInfo &BFI = AM.getResult <BlockFrequencyAnalysis>(F);
136
+ OptimizationRemarkEmitter &ORE =
137
+ AM.getResult <OptimizationRemarkEmitterAnalysis>(F);
102
138
103
- return removeUbsanTraps (F, BFI, PSI) ? PreservedAnalyses::none ()
104
- : PreservedAnalyses::all ();
139
+ return removeUbsanTraps (F, BFI, PSI, ORE ) ? PreservedAnalyses::none ()
140
+ : PreservedAnalyses::all ();
105
141
}
106
142
107
143
bool LowerAllowCheckPass::IsRequested () {
0 commit comments