Skip to content

Commit 6452d9b

Browse files
Add numerical sanitizer
1 parent 89e8e63 commit 6452d9b

File tree

11 files changed

+3835
-0
lines changed

11 files changed

+3835
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===- NumericalStabilitySanitizer.h - NSan Pass ---------------*- C++ -*--===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// \file
10+
// This file defines the numerical stability sanitizer (nsan) pass.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_NUMERICALSTABIITYSANITIZER_H
15+
#define LLVM_TRANSFORMS_INSTRUMENTATION_NUMERICALSTABIITYSANITIZER_H
16+
17+
#include "llvm/IR/PassManager.h"
18+
#include "llvm/Pass.h"
19+
20+
namespace llvm {
21+
22+
/// A function pass for nsan instrumentation.
23+
///
24+
/// Instruments functions to duplicate floating point computations in a
25+
/// higher-precision type.
26+
/// This pass inserts calls to runtime library functions. If the
27+
/// functions aren't declared yet, the pass inserts the declarations.
28+
struct NumericalStabilitySanitizerPass
29+
: public PassInfoMixin<NumericalStabilitySanitizerPass> {
30+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
31+
static bool isRequired() { return true; }
32+
};
33+
34+
} // end namespace llvm
35+
36+
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_NUMERICALSTABIITYSANITIZER_H

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
182182
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
183183
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
184+
#include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
184185
#include "llvm/Transforms/Instrumentation/PGOCtxProfLowering.h"
185186
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"
186187
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ MODULE_PASS("metarenamer", MetaRenamerPass())
9494
MODULE_PASS("module-inline", ModuleInlinerPass())
9595
MODULE_PASS("name-anon-globals", NameAnonGlobalPass())
9696
MODULE_PASS("no-op-module", NoOpModulePass())
97+
MODULE_PASS("nsan", NumericalStabilitySanitizerPass())
9798
MODULE_PASS("objc-arc-apelim", ObjCARCAPElimPass())
9899
MODULE_PASS("openmp-opt", OpenMPOptPass())
99100
MODULE_PASS("openmp-opt-postlink",

llvm/lib/Transforms/Instrumentation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_llvm_component_library(LLVMInstrumentation
88
BlockCoverageInference.cpp
99
MemProfiler.cpp
1010
MemorySanitizer.cpp
11+
NumericalStabilitySanitizer.cpp
1112
IndirectCallPromotion.cpp
1213
Instrumentation.cpp
1314
InstrOrderFile.cpp

0 commit comments

Comments
 (0)