54 "__copyprof_ctor_enter_callback";
56 "__copyprof_ctor_exit_callback";
58 "__copyprof_copy_ctor_enter_callback";
60 "__copyprof_copy_ctor_exit_callback";
62 "__copyprof_copy_assign_op_enter_callback";
64 "__copyprof_copy_assign_op_exit_callback";
66 "__copyprof_dtor_enter_callback";
68 "__copyprof_dtor_exit_callback";
84 Ctor->
addFnAttr(Attribute::DisableSanitizerInstrumentation);
94 if (
F.isDeclaration() ||
95 F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation) ||
96 F.hasFnAttribute(Attribute::Naked))
114 if (BB.getTerminatingMustTailCall())
121 return !
F.isDeclaration() &&
122 !
F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation) &&
123 !
F.hasFnAttribute(Attribute::Naked);
130 [[maybe_unused]]
bool Success =
134 "Unable to parse object size from CopyProf function attribute value.");
143 explicit CopyProf(
Module &M);
147 void insertCallback(
Function &
F,
size_t ObjSize,
unsigned NumArgs,
148 FunctionCallee Callback, FunctionCallee ExitCallback);
151 FunctionCallee CtorEnterCallback;
152 FunctionCallee CtorExitCallback;
153 FunctionCallee CopyCtorEnterCallback;
154 FunctionCallee CopyCtorExitCallback;
155 FunctionCallee CopyAssignOpEnterCallback;
156 FunctionCallee CopyAssignOpExitCallback;
157 FunctionCallee DtorEnterCallback;
158 FunctionCallee DtorExitCallback;
163class CopyProfStores {
165 explicit CopyProfStores(
Module &M);
170 FunctionCallee StoreCallback;
175CopyProf::CopyProf(
Module &M) {
176 LLVMContext &Ctx =
M.getContext();
178 IntPtrTy = IRB.getIntPtrTy(
M.getDataLayout());
179 Type *PtrTy = IRB.getPtrTy();
180 Type *VoidTy = IRB.getVoidTy();
183 Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
188 CopyCtorEnterCallback =
M.getOrInsertFunction(
190 CopyCtorExitCallback =
M.getOrInsertFunction(
192 CopyAssignOpEnterCallback =
195 CopyAssignOpExitCallback =
204bool CopyProf::instrumentFunction(
Function &
F) {
208 CtorEnterCallback, CtorExitCallback);
211 CopyCtorEnterCallback, CopyCtorExitCallback);
214 2, CopyAssignOpEnterCallback,
215 CopyAssignOpExitCallback);
218 DtorEnterCallback, DtorExitCallback);
225void CopyProf::insertCallback(
Function &
F,
size_t ObjSize,
unsigned NumArgs,
226 FunctionCallee EntryCallback,
227 FunctionCallee ExitCallback) {
229 NumArgs](
Function &
F, InstrumentationIRBuilder &&IRB,
235 assert(NumArgs == 1 || NumArgs == 2);
236 for (
unsigned I = 0;
I < NumArgs; ++
I)
237 Args.push_back(
F.getArg(
I));
241 IRB.CreateCall(Callback, Args);
246 InstrumentationIRBuilder{
F.getEntryBlock().getFirstNonPHIOrDbgOrAlloca()},
248 for (BasicBlock &BB :
F) {
251 InsertCallback(
F, InstrumentationIRBuilder{
Term}, ExitCallback);
255CopyProfStores::CopyProfStores(
Module &M) {
256 LLVMContext &Ctx =
M.getContext();
258 IntPtrTy = IRB.getIntPtrTy(
M.getDataLayout());
259 Type *PtrTy = IRB.getPtrTy();
263 Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
268bool CopyProfStores::instrumentFunction(
Function &
F) {
273 const DataLayout &
DL =
F.getDataLayout();
275 for (BasicBlock &BB :
F) {
276 for (Instruction &
I : BB) {
278 SI !=
nullptr &&
SI->getPointerAddressSpace() == 0 &&
279 !
SI->hasMetadata(LLVMContext::MD_nosanitize) &&
282 !
DL.getTypeStoreSize(
SI->getValueOperand()->getType()).isScalable())
286 if (ToInstrument.
empty())
289 for (StoreInst *SI : ToInstrument) {
291 DL.getTypeStoreSize(
SI->getValueOperand()->getType()).getFixedValue();
292 InstrumentationIRBuilder IRB(SI);
293 std::array<Value *, 2>
Args = {
SI->getPointerOperand(),
294 ConstantInt::get(
IntPtrTy, StoredSize)};
295 IRB.CreateCall(StoreCallback, Args);
303 CopyProf Impl(*
F.getParent());
304 if (!Impl.instrumentFunction(
F))
320 CopyProfStores Impl(*
F.getParent());
321 if (!Impl.instrumentFunction(
F))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
constexpr StringRef CopyProfInitName
constexpr StringRef CopyProfCtorEnterCallbackName
constexpr StringRef CopyProfDtorAttr
constexpr StringRef CopyProfCtorAttr
constexpr StringRef CopyProfDtorEnterCallbackName
constexpr StringRef CopyProfCopyCtorEnterCallbackName
static bool isCopyProfStoresCandidate(const Function &F)
constexpr StringRef CopyProfModuleCtorName
constexpr StringRef CopyProfDtorExitCallbackName
static bool isCopyProfCandidate(const Function &F)
constexpr StringRef CopyProfCopyAssignOpEnterCallbackName
constexpr StringRef CopyProfCopyAssignOpExitCallbackName
static bool insertModuleCtor(Module &M)
constexpr StringRef CopyProfStoreCallbackName
constexpr StringRef CopyProfCopyCtorAttr
constexpr StringRef CopyProfCtorExitCallbackName
constexpr StringRef CopyProfCopyCtorExitCallbackName
constexpr StringRef CopyProfCopyAssignAttr
static size_t getAttrValueAsInt(const Function &F, StringRef Attr)
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
This file defines the SmallVector class.
LLVM Basic Block Representation.
Represents analyses that only rely on functions' control flow.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::pair< Function *, FunctionCallee > getOrCreateSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, function_ref< void(Function *, FunctionCallee)> FunctionsCreatedCallback, StringRef VersionCheckName=StringRef(), bool Weak=false)
Creates sanitizer constructor function lazily.
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.