LLVM 20.0.0git
RealtimeSanitizer.cpp
Go to the documentation of this file.
1//===- RealtimeSanitizer.cpp - RealtimeSanitizer instrumentation *- 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// This file is a part of the RealtimeSanitizer, an LLVM transformation for
10// detecting and reporting realtime safety violations.
11//
12// See also: llvm-project/compiler-rt/lib/rtsan/
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/IR/Analysis.h"
17#include "llvm/IR/IRBuilder.h"
18#include "llvm/IR/Module.h"
19
21
22using namespace llvm;
23
25 const char *FunctionName) {
26 LLVMContext &Context = Fn.getContext();
27 FunctionType *FuncType = FunctionType::get(Type::getVoidTy(Context), false);
28 FunctionCallee Func =
29 Fn.getParent()->getOrInsertFunction(FunctionName, FuncType);
30 IRBuilder<> Builder{&Instruction};
31 Builder.CreateCall(Func, {});
32}
33
35 const char *InsertFnName) {
36
37 insertCallBeforeInstruction(Fn, Fn.front().front(), InsertFnName);
38}
39
41 const char *InsertFnName) {
42 for (auto &BB : Fn)
43 for (auto &I : BB)
44 if (isa<ReturnInst>(&I))
45 insertCallBeforeInstruction(Fn, I, InsertFnName);
46}
47
50
53 if (F.hasFnAttribute(Attribute::SanitizeRealtime)) {
54 insertCallAtFunctionEntryPoint(F, "__rtsan_realtime_enter");
55 insertCallAtAllFunctionExitPoints(F, "__rtsan_realtime_exit");
56
59 return PA;
60 }
61
63}
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Module.h This file contains the declarations for the Module class.
static void insertCallAtAllFunctionExitPoints(Function &Fn, const char *InsertFnName)
static void insertCallAtFunctionEntryPoint(Function &Fn, const char *InsertFnName)
static void insertCallBeforeInstruction(Function &Fn, Instruction &Instruction, const char *FunctionName)
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
const Instruction & front() const
Definition: BasicBlock.h:471
Represents analyses that only rely on functions' control flow.
Definition: Analysis.h:72
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:168
const BasicBlock & front() const
Definition: Function.h:858
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:380
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2674
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:169
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
void preserveSet()
Mark an analysis set as preserved.
Definition: Analysis.h:146
RealtimeSanitizerPass(const RealtimeSanitizerOptions &Options)
PreservedAnalyses run(Function &F, AnalysisManager< Function > &AM)
static Type * getVoidTy(LLVMContext &C)
Pass manager infrastructure for declaring and invalidating analyses.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18