Skip to content

Commit 49f0b53

Browse files
authored
[UBSAN] Rename remove-traps to lower-allow-check (#84853)
1 parent 24e4429 commit 49f0b53

File tree

8 files changed

+25
-24
lines changed

8 files changed

+25
-24
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@
7373
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
7474
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
7575
#include "llvm/Transforms/Instrumentation/KCFI.h"
76+
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
7677
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
7778
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
7879
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
79-
#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
8080
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
8181
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
8282
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -746,13 +746,13 @@ static void addSanitizers(const Triple &TargetTriple,
746746
PB.registerOptimizerLastEPCallback(SanitizersCallback);
747747
}
748748

749-
if (RemoveTrapsPass::IsRequested()) {
749+
if (LowerAllowCheckPass::IsRequested()) {
750750
// We can optimize after inliner, and PGO profile matching. The hook below
751751
// is called at the end `buildFunctionSimplificationPipeline`, which called
752752
// from `buildInlinerPipeline`, which called after profile matching.
753753
PB.registerScalarOptimizerLateEPCallback(
754754
[](FunctionPassManager &FPM, OptimizationLevel Level) {
755-
FPM.addPass(RemoveTrapsPass());
755+
FPM.addPass(LowerAllowCheckPass());
756756
});
757757
}
758758
}

llvm/include/llvm/Transforms/Instrumentation/RemoveTrapsPass.h renamed to llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- RemoveTrapsPass.h ----------------------------------------*- C++ -*-===//
1+
//===- LowerAllowCheckPass.h ------------------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,8 +11,8 @@
1111
///
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_UBSANOPTIMIZATIONPASS_H
15-
#define LLVM_TRANSFORMS_INSTRUMENTATION_UBSANOPTIMIZATIONPASS_H
14+
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_LOWERALLOWCHECKPASS_H
15+
#define LLVM_TRANSFORMS_INSTRUMENTATION_LOWERALLOWCHECKPASS_H
1616

1717
#include "llvm/IR/Function.h"
1818
#include "llvm/IR/PassManager.h"
@@ -22,7 +22,7 @@ namespace llvm {
2222

2323
// This pass is responsible for removing optional traps, like llvm.ubsantrap
2424
// from the hot code.
25-
class RemoveTrapsPass : public PassInfoMixin<RemoveTrapsPass> {
25+
class LowerAllowCheckPass : public PassInfoMixin<LowerAllowCheckPass> {
2626
public:
2727
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
2828

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@
172172
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
173173
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
174174
#include "llvm/Transforms/Instrumentation/KCFI.h"
175+
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
175176
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
176177
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
177178
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"
178179
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
179180
#include "llvm/Transforms/Instrumentation/PoisonChecking.h"
180-
#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
181181
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
182182
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
183183
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass())
363363
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
364364
FUNCTION_PASS("loop-sink", LoopSinkPass())
365365
FUNCTION_PASS("loop-versioning", LoopVersioningPass())
366+
FUNCTION_PASS("lower-allow-check", LowerAllowCheckPass())
366367
FUNCTION_PASS("lower-atomic", LowerAtomicPass())
367368
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
368369
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
@@ -422,7 +423,6 @@ FUNCTION_PASS("print<uniformity>", UniformityInfoPrinterPass(dbgs()))
422423
FUNCTION_PASS("reassociate", ReassociatePass())
423424
FUNCTION_PASS("redundant-dbg-inst-elim", RedundantDbgInstEliminationPass())
424425
FUNCTION_PASS("reg2mem", RegToMemPass())
425-
FUNCTION_PASS("remove-traps", RemoveTrapsPass())
426426
FUNCTION_PASS("safe-stack", SafeStackPass(TM))
427427
FUNCTION_PASS("scalarize-masked-mem-intrin", ScalarizeMaskedMemIntrinPass())
428428
FUNCTION_PASS("scalarizer", ScalarizerPass())

llvm/lib/Transforms/Instrumentation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ add_llvm_component_library(LLVMInstrumentation
1313
InstrOrderFile.cpp
1414
InstrProfiling.cpp
1515
KCFI.cpp
16+
LowerAllowCheckPass.cpp
1617
PGOForceFunctionAttrs.cpp
1718
PGOInstrumentation.cpp
1819
PGOMemOPSizeOpt.cpp
1920
PoisonChecking.cpp
20-
RemoveTrapsPass.cpp
2121
SanitizerCoverage.cpp
2222
SanitizerBinaryMetadata.cpp
2323
ValueProfileCollector.cpp

llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp renamed to llvm/lib/Transforms/Instrumentation/LowerAllowCheckPass.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===- RemoveTrapsPass.cpp --------------------------------------*- C++ -*-===//
1+
//===- LowerAllowCheckPass.cpp ----------------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
9+
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
1010

1111
#include "llvm/ADT/SmallVector.h"
1212
#include "llvm/ADT/Statistic.h"
@@ -21,13 +21,14 @@
2121

2222
using namespace llvm;
2323

24-
#define DEBUG_TYPE "remove-traps"
24+
#define DEBUG_TYPE "lower-allow-check"
2525

26-
static cl::opt<int> HotPercentileCutoff("remove-traps-percentile-cutoff-hot",
27-
cl::desc("Hot percentile cuttoff."));
26+
static cl::opt<int>
27+
HotPercentileCutoff("lower-allow-check-percentile-cutoff-hot",
28+
cl::desc("Hot percentile cuttoff."));
2829

2930
static cl::opt<float>
30-
RandomRate("remove-traps-random-rate",
31+
RandomRate("lower-allow-check-random-rate",
3132
cl::desc("Probability value in the range [0.0, 1.0] of "
3233
"unconditional pseudo-random checks removal."));
3334

@@ -90,8 +91,8 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI,
9091
return !ReplaceWithValue.empty();
9192
}
9293

93-
PreservedAnalyses RemoveTrapsPass::run(Function &F,
94-
FunctionAnalysisManager &AM) {
94+
PreservedAnalyses LowerAllowCheckPass::run(Function &F,
95+
FunctionAnalysisManager &AM) {
9596
if (F.isDeclaration())
9697
return PreservedAnalyses::all();
9798
auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
@@ -103,7 +104,7 @@ PreservedAnalyses RemoveTrapsPass::run(Function &F,
103104
: PreservedAnalyses::all();
104105
}
105106

106-
bool RemoveTrapsPass::IsRequested() {
107+
bool LowerAllowCheckPass::IsRequested() {
107108
return RandomRate.getNumOccurrences() ||
108109
HotPercentileCutoff.getNumOccurrences();
109110
}

llvm/test/Transforms/RemoveTraps/remove-traps.ll renamed to llvm/test/Transforms/lower-builtin-allow-check.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2-
; RUN: opt < %s -passes='function(remove-traps)' -S | FileCheck %s --check-prefixes=NOPROFILE
3-
; RUN: opt < %s -passes='function(remove-traps)' -remove-traps-random-rate=1 -S | FileCheck %s --check-prefixes=ALL
4-
; RUN: opt < %s -passes='require<profile-summary>,function(remove-traps)' -remove-traps-percentile-cutoff-hot=990000 -S | FileCheck %s --check-prefixes=HOT99
5-
; RUN: opt < %s -passes='require<profile-summary>,function(remove-traps)' -remove-traps-percentile-cutoff-hot=700000 -S | FileCheck %s --check-prefixes=HOT70
2+
; RUN: opt < %s -passes='function(lower-allow-check)' -S | FileCheck %s --check-prefixes=NOPROFILE
3+
; RUN: opt < %s -passes='function(lower-allow-check)' -lower-allow-check-random-rate=1 -S | FileCheck %s --check-prefixes=ALL
4+
; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=990000 -S | FileCheck %s --check-prefixes=HOT99
5+
; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=700000 -S | FileCheck %s --check-prefixes=HOT70
66

77
target triple = "x86_64-pc-linux-gnu"
88

llvm/utils/gn/secondary/llvm/lib/Transforms/Instrumentation/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ static_library("Instrumentation") {
2323
"InstrProfiling.cpp",
2424
"Instrumentation.cpp",
2525
"KCFI.cpp",
26+
"LowerAllowCheckPass.cpp",
2627
"MemProfiler.cpp",
2728
"MemorySanitizer.cpp",
2829
"PGOForceFunctionAttrs.cpp",
2930
"PGOInstrumentation.cpp",
3031
"PGOMemOPSizeOpt.cpp",
3132
"PoisonChecking.cpp",
32-
"RemoveTrapsPass.cpp",
3333
"SanitizerBinaryMetadata.cpp",
3434
"SanitizerCoverage.cpp",
3535
"ThreadSanitizer.cpp",

0 commit comments

Comments
 (0)