Skip to content

Commit

Permalink
[UBSAN] Rename remove-traps to lower-allow-check (#84853)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed Apr 5, 2024
1 parent 24e4429 commit 49f0b53
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
#include "llvm/Transforms/Instrumentation/KCFI.h"
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
Expand Down Expand Up @@ -746,13 +746,13 @@ static void addSanitizers(const Triple &TargetTriple,
PB.registerOptimizerLastEPCallback(SanitizersCallback);
}

if (RemoveTrapsPass::IsRequested()) {
if (LowerAllowCheckPass::IsRequested()) {
// We can optimize after inliner, and PGO profile matching. The hook below
// is called at the end `buildFunctionSimplificationPipeline`, which called
// from `buildInlinerPipeline`, which called after profile matching.
PB.registerScalarOptimizerLateEPCallback(
[](FunctionPassManager &FPM, OptimizationLevel Level) {
FPM.addPass(RemoveTrapsPass());
FPM.addPass(LowerAllowCheckPass());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- RemoveTrapsPass.h ----------------------------------------*- C++ -*-===//
//===- LowerAllowCheckPass.h ------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -11,8 +11,8 @@
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_UBSANOPTIMIZATIONPASS_H
#define LLVM_TRANSFORMS_INSTRUMENTATION_UBSANOPTIMIZATIONPASS_H
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_LOWERALLOWCHECKPASS_H
#define LLVM_TRANSFORMS_INSTRUMENTATION_LOWERALLOWCHECKPASS_H

#include "llvm/IR/Function.h"
#include "llvm/IR/PassManager.h"
Expand All @@ -22,7 +22,7 @@ namespace llvm {

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

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
#include "llvm/Transforms/Instrumentation/KCFI.h"
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
#include "llvm/Transforms/Instrumentation/PoisonChecking.h"
#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass())
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
FUNCTION_PASS("loop-sink", LoopSinkPass())
FUNCTION_PASS("loop-versioning", LoopVersioningPass())
FUNCTION_PASS("lower-allow-check", LowerAllowCheckPass())
FUNCTION_PASS("lower-atomic", LowerAtomicPass())
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
Expand Down Expand Up @@ -422,7 +423,6 @@ FUNCTION_PASS("print<uniformity>", UniformityInfoPrinterPass(dbgs()))
FUNCTION_PASS("reassociate", ReassociatePass())
FUNCTION_PASS("redundant-dbg-inst-elim", RedundantDbgInstEliminationPass())
FUNCTION_PASS("reg2mem", RegToMemPass())
FUNCTION_PASS("remove-traps", RemoveTrapsPass())
FUNCTION_PASS("safe-stack", SafeStackPass(TM))
FUNCTION_PASS("scalarize-masked-mem-intrin", ScalarizeMaskedMemIntrinPass())
FUNCTION_PASS("scalarizer", ScalarizerPass())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ add_llvm_component_library(LLVMInstrumentation
InstrOrderFile.cpp
InstrProfiling.cpp
KCFI.cpp
LowerAllowCheckPass.cpp
PGOForceFunctionAttrs.cpp
PGOInstrumentation.cpp
PGOMemOPSizeOpt.cpp
PoisonChecking.cpp
RemoveTrapsPass.cpp
SanitizerCoverage.cpp
SanitizerBinaryMetadata.cpp
ValueProfileCollector.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//===- RemoveTrapsPass.cpp --------------------------------------*- C++ -*-===//
//===- LowerAllowCheckPass.cpp ----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
Expand All @@ -21,13 +21,14 @@

using namespace llvm;

#define DEBUG_TYPE "remove-traps"
#define DEBUG_TYPE "lower-allow-check"

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

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

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

PreservedAnalyses RemoveTrapsPass::run(Function &F,
FunctionAnalysisManager &AM) {
PreservedAnalyses LowerAllowCheckPass::run(Function &F,
FunctionAnalysisManager &AM) {
if (F.isDeclaration())
return PreservedAnalyses::all();
auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
Expand All @@ -103,7 +104,7 @@ PreservedAnalyses RemoveTrapsPass::run(Function &F,
: PreservedAnalyses::all();
}

bool RemoveTrapsPass::IsRequested() {
bool LowerAllowCheckPass::IsRequested() {
return RandomRate.getNumOccurrences() ||
HotPercentileCutoff.getNumOccurrences();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes='function(remove-traps)' -S | FileCheck %s --check-prefixes=NOPROFILE
; RUN: opt < %s -passes='function(remove-traps)' -remove-traps-random-rate=1 -S | FileCheck %s --check-prefixes=ALL
; RUN: opt < %s -passes='require<profile-summary>,function(remove-traps)' -remove-traps-percentile-cutoff-hot=990000 -S | FileCheck %s --check-prefixes=HOT99
; RUN: opt < %s -passes='require<profile-summary>,function(remove-traps)' -remove-traps-percentile-cutoff-hot=700000 -S | FileCheck %s --check-prefixes=HOT70
; RUN: opt < %s -passes='function(lower-allow-check)' -S | FileCheck %s --check-prefixes=NOPROFILE
; RUN: opt < %s -passes='function(lower-allow-check)' -lower-allow-check-random-rate=1 -S | FileCheck %s --check-prefixes=ALL
; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=990000 -S | FileCheck %s --check-prefixes=HOT99
; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=700000 -S | FileCheck %s --check-prefixes=HOT70

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ static_library("Instrumentation") {
"InstrProfiling.cpp",
"Instrumentation.cpp",
"KCFI.cpp",
"LowerAllowCheckPass.cpp",
"MemProfiler.cpp",
"MemorySanitizer.cpp",
"PGOForceFunctionAttrs.cpp",
"PGOInstrumentation.cpp",
"PGOMemOPSizeOpt.cpp",
"PoisonChecking.cpp",
"RemoveTrapsPass.cpp",
"SanitizerBinaryMetadata.cpp",
"SanitizerCoverage.cpp",
"ThreadSanitizer.cpp",
Expand Down

0 comments on commit 49f0b53

Please sign in to comment.