LLVM 24.0.0git
MemProfInstrumentation.cpp
Go to the documentation of this file.
1//===- MemProfInstrumentation.cpp - memory alloc and access instrumentation ==//
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 MemProf. Memory accesses are instrumented
10// to increment the access count held in a shadow memory location, or
11// alternatively to call into the runtime. Memory intrinsic calls (memmove,
12// memcpy, memset) are changed to call the memory profiling runtime version
13// instead.
14//
15//===----------------------------------------------------------------------===//
16
20#include "llvm/ADT/Statistic.h"
21#include "llvm/ADT/StringRef.h"
25#include "llvm/IR/Constant.h"
26#include "llvm/IR/DataLayout.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/GlobalValue.h"
30#include "llvm/IR/IRBuilder.h"
31#include "llvm/IR/Instruction.h"
33#include "llvm/IR/Module.h"
34#include "llvm/IR/Type.h"
35#include "llvm/IR/Value.h"
38#include "llvm/Support/Debug.h"
42
43using namespace llvm;
44using namespace llvm::memprof;
45
46#define DEBUG_TYPE "memprof"
47
48constexpr int LLVM_MEM_PROFILER_VERSION = 1;
49
50// Size of memory mapped to a single shadow location.
51[[maybe_unused]] constexpr uint64_t DefaultMemGranularity = 64;
52
53// Size of memory mapped to a single histogram bucket.
55
56constexpr char MemProfModuleCtorName[] = "memprof.module_ctor";
58// On Emscripten, the system needs more than one priorities for constructors.
60constexpr char MemProfInitName[] = "__memprof_init";
62 "__memprof_version_mismatch_check_v";
63
65 "__memprof_shadow_memory_dynamic_address";
66
67constexpr char MemProfFilenameVar[] = "__memprof_profile_filename";
68
69constexpr char MemProfHistogramFlagVar[] = "__memprof_histogram";
70
71// Instrumentation statistics
72STATISTIC(NumInstrumentedReads, "Number of instrumented reads");
73STATISTIC(NumInstrumentedWrites, "Number of instrumented writes");
74STATISTIC(NumSkippedStackReads, "Number of non-instrumented stack reads");
75STATISTIC(NumSkippedStackWrites, "Number of non-instrumented stack writes");
76
77namespace {
78
79/// This struct defines the shadow mapping using the rule:
80/// shadow = ((mem & mask) >> Scale) ADD DynamicShadowOffset.
81struct ShadowMapping {
82 ShadowMapping(const InstrumentationOptions &Opts) {
83 Scale = Opts.memprof_mapping_scale;
84 Granularity = Opts.memprof_histogram ? HistogramGranularity
85 : Opts.memprof_mapping_granularity;
86 Mask = ~(Granularity - 1);
87 }
88
89 int Scale;
90 int Granularity;
91 uint64_t Mask; // Computed as ~(Granularity-1)
92};
93
94static uint64_t getCtorAndDtorPriority(Triple &TargetTriple) {
97}
98
99struct InterestingMemoryAccess {
100 Value *Addr = nullptr;
101 bool IsWrite;
102 Type *AccessTy;
103 Value *MaybeMask = nullptr;
104};
105
106/// Instrument the code in module to profile memory accesses.
107class MemProfiler {
108public:
109 MemProfiler(const InstrumentationOptions &Opts, Module &M)
110 : Opts(Opts), Mapping(Opts) {
111 C = &(M.getContext());
112 LongSize = M.getDataLayout().getPointerSizeInBits();
113 IntptrTy = Type::getIntNTy(*C, LongSize);
114 PtrTy = PointerType::getUnqual(*C);
115 }
116
117 /// If it is an interesting memory access, populate information
118 /// about the access and return a InterestingMemoryAccess struct.
119 /// Otherwise return std::nullopt.
120 std::optional<InterestingMemoryAccess>
121 isInterestingMemoryAccess(Instruction *I) const;
122
123 void instrumentMop(Instruction *I, const DataLayout &DL,
124 InterestingMemoryAccess &Access);
125 void instrumentAddress(Instruction *OrigIns, Instruction *InsertBefore,
126 Value *Addr, bool IsWrite);
127 void instrumentMaskedLoadOrStore(const DataLayout &DL, Value *Mask,
128 Instruction *I, Value *Addr, Type *AccessTy,
129 bool IsWrite);
130 void instrumentMemIntrinsic(MemIntrinsic *MI);
131 Value *memToShadow(Value *Shadow, IRBuilder<> &IRB);
132 bool instrumentFunction(Function &F);
133 bool maybeInsertMemProfInitAtFunctionEntry(Function &F);
134 bool insertDynamicShadowAtFunctionEntry(Function &F);
135
136private:
137 void initializeCallbacks(Module &M);
138
139 const InstrumentationOptions &Opts;
140 LLVMContext *C;
141 int LongSize;
142 Type *IntptrTy;
143 PointerType *PtrTy;
144 ShadowMapping Mapping;
145
146 // These arrays is indexed by AccessIsWrite
147 FunctionCallee MemProfMemoryAccessCallback[2];
148
149 FunctionCallee MemProfMemmove, MemProfMemcpy, MemProfMemset;
150 Value *DynamicShadowOffset = nullptr;
151};
152
153class ModuleMemProfiler {
154public:
155 ModuleMemProfiler(const InstrumentationOptions &Opts, Module &M)
156 : Opts(Opts), Mapping(Opts) {
157 TargetTriple = M.getTargetTriple();
158 }
159
160 bool instrumentModule(Module &);
161
162private:
163 const InstrumentationOptions &Opts;
164 Triple TargetTriple;
165 ShadowMapping Mapping;
166 Function *MemProfCtorFunction = nullptr;
167};
168
169} // end anonymous namespace
170
172
175 const InstrumentationOptions &Opts = getInstrumentationOptions(F);
176 assert((!Opts.memprof_histogram ||
177 Opts.memprof_mapping_granularity == DefaultMemGranularity) &&
178 "Memprof with histogram only supports default mapping granularity");
179 Module &M = *F.getParent();
180 MemProfiler Profiler(Opts, M);
181 if (Profiler.instrumentFunction(F))
183 return PreservedAnalyses::all();
184}
185
187
190
191 const InstrumentationOptions &Opts = getInstrumentationOptions(M);
192 ModuleMemProfiler Profiler(Opts, M);
193 if (Profiler.instrumentModule(M))
195 return PreservedAnalyses::all();
196}
197
198Value *MemProfiler::memToShadow(Value *Shadow, IRBuilder<> &IRB) {
199 // (Shadow & mask) >> scale
200 Shadow = IRB.CreateAnd(Shadow, Mapping.Mask);
201 Shadow = IRB.CreateLShr(Shadow, Mapping.Scale);
202 // (Shadow >> scale) | offset
203 assert(DynamicShadowOffset);
204 return IRB.CreateAdd(Shadow, DynamicShadowOffset);
205}
206
207// Instrument memset/memmove/memcpy
208void MemProfiler::instrumentMemIntrinsic(MemIntrinsic *MI) {
209 IRBuilder<> IRB(MI);
211 IRB.CreateCall(isa<MemMoveInst>(MI) ? MemProfMemmove : MemProfMemcpy,
212 {MI->getOperand(0), MI->getOperand(1),
213 IRB.CreateIntCast(MI->getOperand(2), IntptrTy, false)});
214 } else if (isa<MemSetInst>(MI)) {
215 IRB.CreateCall(
216 MemProfMemset,
217 {MI->getOperand(0),
218 IRB.CreateIntCast(MI->getOperand(1), IRB.getInt32Ty(), false),
219 IRB.CreateIntCast(MI->getOperand(2), IntptrTy, false)});
220 }
221 MI->eraseFromParent();
222}
223
224std::optional<InterestingMemoryAccess>
225MemProfiler::isInterestingMemoryAccess(Instruction *I) const {
226 // Do not instrument the load fetching the dynamic shadow address.
227 if (DynamicShadowOffset == I)
228 return std::nullopt;
229
230 InterestingMemoryAccess Access;
231
232 if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
233 if (!Opts.memprof_instrument_reads)
234 return std::nullopt;
235 Access.IsWrite = false;
236 Access.AccessTy = LI->getType();
237 Access.Addr = LI->getPointerOperand();
238 } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
239 if (!Opts.memprof_instrument_writes)
240 return std::nullopt;
241 Access.IsWrite = true;
242 Access.AccessTy = SI->getValueOperand()->getType();
243 Access.Addr = SI->getPointerOperand();
244 } else if (AtomicRMWInst *RMW = dyn_cast<AtomicRMWInst>(I)) {
245 if (!Opts.memprof_instrument_atomics)
246 return std::nullopt;
247 Access.IsWrite = true;
248 Access.AccessTy = RMW->getValOperand()->getType();
249 Access.Addr = RMW->getPointerOperand();
250 } else if (AtomicCmpXchgInst *XCHG = dyn_cast<AtomicCmpXchgInst>(I)) {
251 if (!Opts.memprof_instrument_atomics)
252 return std::nullopt;
253 Access.IsWrite = true;
254 Access.AccessTy = XCHG->getCompareOperand()->getType();
255 Access.Addr = XCHG->getPointerOperand();
256 } else if (auto *CI = dyn_cast<CallInst>(I)) {
257 auto *F = CI->getCalledFunction();
258 if (F && (F->getIntrinsicID() == Intrinsic::masked_load ||
259 F->getIntrinsicID() == Intrinsic::masked_store)) {
260 unsigned OpOffset = 0;
261 if (F->getIntrinsicID() == Intrinsic::masked_store) {
262 if (!Opts.memprof_instrument_writes)
263 return std::nullopt;
264 // Masked store has an initial operand for the value.
265 OpOffset = 1;
266 Access.AccessTy = CI->getArgOperand(0)->getType();
267 Access.IsWrite = true;
268 } else {
269 if (!Opts.memprof_instrument_reads)
270 return std::nullopt;
271 Access.AccessTy = CI->getType();
272 Access.IsWrite = false;
273 }
274
275 auto *BasePtr = CI->getOperand(0 + OpOffset);
276 Access.MaybeMask = CI->getOperand(1 + OpOffset);
277 Access.Addr = BasePtr;
278 }
279 }
280
281 if (!Access.Addr)
282 return std::nullopt;
283
284 // Do not instrument accesses from different address spaces; we cannot deal
285 // with them.
286 Type *PtrTy = cast<PointerType>(Access.Addr->getType()->getScalarType());
287 if (PtrTy->getPointerAddressSpace() != 0)
288 return std::nullopt;
289
290 // Ignore swifterror addresses.
291 // swifterror memory addresses are mem2reg promoted by instruction
292 // selection. As such they cannot have regular uses like an instrumentation
293 // function and it makes no sense to track them as memory.
294 if (Access.Addr->isSwiftError())
295 return std::nullopt;
296
297 // Peel off GEPs and BitCasts.
298 auto *Addr = Access.Addr->stripInBoundsOffsets();
299
301 // Do not instrument PGO counter updates.
302 if (GV->hasSection()) {
303 StringRef SectionName = GV->getSection();
304 // Check if the global is in the PGO counters section.
305 auto OF = I->getModule()->getTargetTriple().getObjectFormat();
306 if (SectionName.ends_with(
307 getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false)))
308 return std::nullopt;
309 }
310
311 // Do not instrument accesses to LLVM internal variables.
312 if (GV->getName().starts_with("__llvm") ||
313 GV->getName().starts_with(getInstrProfVarPrefix()))
314 return std::nullopt;
315 }
316
317 return Access;
318}
319
320void MemProfiler::instrumentMaskedLoadOrStore(const DataLayout &DL, Value *Mask,
321 Instruction *I, Value *Addr,
322 Type *AccessTy, bool IsWrite) {
323 auto *VTy = cast<FixedVectorType>(AccessTy);
324 unsigned Num = VTy->getNumElements();
325 auto *Zero = ConstantInt::get(IntptrTy, 0);
326 for (unsigned Idx = 0; Idx < Num; ++Idx) {
327 Value *InstrumentedAddress = nullptr;
328 Instruction *InsertBefore = I;
329 if (auto *Vector = dyn_cast<ConstantVector>(Mask)) {
330 // dyn_cast as we might get UndefValue
331 if (auto *Masked = dyn_cast<ConstantInt>(Vector->getOperand(Idx))) {
332 if (Masked->isZero())
333 // Mask is constant false, so no instrumentation needed.
334 continue;
335 // If we have a true or undef value, fall through to instrumentAddress.
336 // with InsertBefore == I
337 }
338 } else {
339 IRBuilder<> IRB(I);
340 Value *MaskElem = IRB.CreateExtractElement(Mask, Idx);
341 Instruction *ThenTerm = SplitBlockAndInsertIfThen(MaskElem, I, false);
342 InsertBefore = ThenTerm;
343 }
344
345 IRBuilder<> IRB(InsertBefore);
346 InstrumentedAddress =
347 IRB.CreateGEP(VTy, Addr, {Zero, ConstantInt::get(IntptrTy, Idx)});
348 instrumentAddress(I, InsertBefore, InstrumentedAddress, IsWrite);
349 }
350}
351
352void MemProfiler::instrumentMop(Instruction *I, const DataLayout &DL,
353 InterestingMemoryAccess &Access) {
354 // Skip instrumentation of stack accesses unless requested.
355 if (!Opts.memprof_instrument_stack &&
357 if (Access.IsWrite)
358 ++NumSkippedStackWrites;
359 else
360 ++NumSkippedStackReads;
361 return;
362 }
363
364 if (Access.IsWrite)
365 NumInstrumentedWrites++;
366 else
367 NumInstrumentedReads++;
368
369 if (Access.MaybeMask) {
370 instrumentMaskedLoadOrStore(DL, Access.MaybeMask, I, Access.Addr,
371 Access.AccessTy, Access.IsWrite);
372 } else {
373 // Since the access counts will be accumulated across the entire allocation,
374 // we only update the shadow access count for the first location and thus
375 // don't need to worry about alignment and type size.
376 instrumentAddress(I, I, Access.Addr, Access.IsWrite);
377 }
378}
379
380void MemProfiler::instrumentAddress(Instruction *OrigIns,
381 Instruction *InsertBefore, Value *Addr,
382 bool IsWrite) {
383 IRBuilder<> IRB(InsertBefore);
384 Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
385
386 if (Opts.memprof_use_callbacks) {
387 IRB.CreateCall(MemProfMemoryAccessCallback[IsWrite], AddrLong);
388 return;
389 }
390
391 Type *ShadowTy =
392 Opts.memprof_histogram ? Type::getInt8Ty(*C) : Type::getInt64Ty(*C);
393 Type *ShadowPtrTy = PointerType::get(*C, 0);
394
395 Value *ShadowPtr = memToShadow(AddrLong, IRB);
396 Value *ShadowAddr = IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy);
397 Value *ShadowValue = IRB.CreateLoad(ShadowTy, ShadowAddr);
398 // If we are profiling with histograms, add overflow protection at 255.
399 if (Opts.memprof_histogram) {
400 Value *MaxCount = ConstantInt::get(Type::getInt8Ty(*C), 255);
401 Value *Cmp = IRB.CreateICmpULT(ShadowValue, MaxCount);
402 Instruction *IncBlock =
403 SplitBlockAndInsertIfThen(Cmp, InsertBefore, /*Unreachable=*/false);
404 IRB.SetInsertPoint(IncBlock);
405 }
406 Value *Inc = ConstantInt::get(ShadowTy, 1);
407 ShadowValue = IRB.CreateAdd(ShadowValue, Inc);
408 IRB.CreateStore(ShadowValue, ShadowAddr);
409}
410
411// Create the variable for the profile file name.
413 const MDString *MemProfFilename =
414 dyn_cast_or_null<MDString>(M.getModuleFlag("MemProfProfileFilename"));
415 if (!MemProfFilename)
416 return;
417 assert(!MemProfFilename->getString().empty() &&
418 "Unexpected MemProfProfileFilename metadata with empty string");
419 Constant *ProfileNameConst = ConstantDataArray::getString(
420 M.getContext(), MemProfFilename->getString(), true);
421 GlobalVariable *ProfileNameVar = new GlobalVariable(
422 M, ProfileNameConst->getType(), /*isConstant=*/true,
424 const Triple &TT = M.getTargetTriple();
425 if (TT.supportsCOMDAT()) {
427 ProfileNameVar->setComdat(M.getOrInsertComdat(MemProfFilenameVar));
428 }
429}
430
431// Set MemprofHistogramFlag as a Global variable in IR. This makes it accessible
432// to the runtime, changing shadow count behavior.
433void createMemprofHistogramFlagVar(const InstrumentationOptions &Opts,
434 Module &M) {
435 const StringRef VarName(MemProfHistogramFlagVar);
436 Type *IntTy1 = Type::getInt1Ty(M.getContext());
437 auto MemprofHistogramFlag = new GlobalVariable(
438 M, IntTy1, true, GlobalValue::WeakAnyLinkage,
439 Constant::getIntegerValue(IntTy1, APInt(1, Opts.memprof_histogram)),
440 VarName);
441 const Triple &TT = M.getTargetTriple();
442 if (TT.supportsCOMDAT()) {
443 MemprofHistogramFlag->setLinkage(GlobalValue::ExternalLinkage);
444 MemprofHistogramFlag->setComdat(M.getOrInsertComdat(VarName));
445 }
446 appendToCompilerUsed(M, MemprofHistogramFlag);
447}
448
449void createMemprofDefaultOptionsVar(const InstrumentationOptions &Opts,
450 Module &M) {
452 M.getContext(), Opts.memprof_runtime_default_options, /*AddNull=*/true);
453 GlobalVariable *OptionsVar =
454 new GlobalVariable(M, OptionsConst->getType(), /*isConstant=*/true,
455 GlobalValue::WeakAnyLinkage, OptionsConst,
457 const Triple &TT = M.getTargetTriple();
458 if (TT.supportsCOMDAT()) {
460 OptionsVar->setComdat(M.getOrInsertComdat(OptionsVar->getName()));
461 }
462}
463
464bool ModuleMemProfiler::instrumentModule(Module &M) {
465
466 // Create a module constructor.
467 std::string MemProfVersion = std::to_string(LLVM_MEM_PROFILER_VERSION);
468 std::string VersionCheckName =
469 Opts.memprof_guard_against_version_mismatch
470 ? (MemProfVersionCheckNamePrefix + MemProfVersion)
471 : "";
472 std::tie(MemProfCtorFunction, std::ignore) =
474 MemProfInitName, /*InitArgTypes=*/{},
475 /*InitArgs=*/{}, VersionCheckName);
476
477 const uint64_t Priority = getCtorAndDtorPriority(TargetTriple);
478 appendToGlobalCtors(M, MemProfCtorFunction, Priority);
479
481
483
485
486 return true;
487}
488
489void MemProfiler::initializeCallbacks(Module &M) {
490 IRBuilder<> IRB(M);
491
492 for (size_t AccessIsWrite = 0; AccessIsWrite <= 1; AccessIsWrite++) {
493 const std::string TypeStr = AccessIsWrite ? "store" : "load";
494 const std::string HistPrefix = Opts.memprof_histogram ? "hist_" : "";
495
496 SmallVector<Type *, 2> Args1{1, IntptrTy};
497 MemProfMemoryAccessCallback[AccessIsWrite] = M.getOrInsertFunction(
498 (Opts.memprof_memory_access_callback_prefix + HistPrefix + TypeStr)
499 .str(),
500 FunctionType::get(IRB.getVoidTy(), Args1, false));
501 }
502 MemProfMemmove = M.getOrInsertFunction(
503 (Opts.memprof_memory_access_callback_prefix + "memmove").str(), PtrTy,
504 PtrTy, PtrTy, IntptrTy);
505 MemProfMemcpy = M.getOrInsertFunction(
506 (Opts.memprof_memory_access_callback_prefix + "memcpy").str(), PtrTy,
507 PtrTy, PtrTy, IntptrTy);
508 MemProfMemset = M.getOrInsertFunction(
509 (Opts.memprof_memory_access_callback_prefix + "memset").str(), PtrTy,
510 PtrTy, IRB.getInt32Ty(), IntptrTy);
511}
512
513bool MemProfiler::maybeInsertMemProfInitAtFunctionEntry(Function &F) {
514 // For each NSObject descendant having a +load method, this method is invoked
515 // by the ObjC runtime before any of the static constructors is called.
516 // Therefore we need to instrument such methods with a call to __memprof_init
517 // at the beginning in order to initialize our runtime before any access to
518 // the shadow memory.
519 // We cannot just ignore these methods, because they may call other
520 // instrumented functions.
521 if (F.getName().contains(" load]")) {
522 FunctionCallee MemProfInitFunction =
524 IRBuilder<> IRB(F.front().begin());
525 IRB.CreateCall(MemProfInitFunction, {});
526 return true;
527 }
528 return false;
529}
530
531bool MemProfiler::insertDynamicShadowAtFunctionEntry(Function &F) {
532 IRBuilder<> IRB(&F.front().front());
533 Value *GlobalDynamicAddress = F.getParent()->getOrInsertGlobal(
535 if (F.getParent()->getPICLevel() == PICLevel::NotPIC)
536 cast<GlobalVariable>(GlobalDynamicAddress)->setDSOLocal(true);
537 DynamicShadowOffset = IRB.CreateLoad(IntptrTy, GlobalDynamicAddress);
538 return true;
539}
540
541bool MemProfiler::instrumentFunction(Function &F) {
542 if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage)
543 return false;
544 if (Opts.memprof_debug_func == F.getName())
545 return false;
546 if (F.getName().starts_with("__memprof_"))
547 return false;
548
549 bool FunctionModified = false;
550
551 // If needed, insert __memprof_init.
552 // This function needs to be called even if the function body is not
553 // instrumented.
554 if (maybeInsertMemProfInitAtFunctionEntry(F))
555 FunctionModified = true;
556
557 LLVM_DEBUG(dbgs() << "MEMPROF instrumenting:\n" << F << "\n");
558
559 initializeCallbacks(*F.getParent());
560
562
563 // Fill the set of memory operations to instrument.
564 for (auto &BB : F) {
565 for (auto &Inst : BB) {
566 if (isInterestingMemoryAccess(&Inst) || isa<MemIntrinsic>(Inst))
567 ToInstrument.push_back(&Inst);
568 }
569 }
570
571 if (ToInstrument.empty()) {
572 LLVM_DEBUG(dbgs() << "MEMPROF done instrumenting: " << FunctionModified
573 << " " << F << "\n");
574
575 return FunctionModified;
576 }
577
578 FunctionModified |= insertDynamicShadowAtFunctionEntry(F);
579
580 int NumInstrumented = 0;
581 for (auto *Inst : ToInstrument) {
582 if (Opts.memprof_debug_min < 0 || Opts.memprof_debug_max < 0 ||
583 (NumInstrumented >= Opts.memprof_debug_min &&
584 NumInstrumented <= Opts.memprof_debug_max)) {
585 std::optional<InterestingMemoryAccess> Access =
586 isInterestingMemoryAccess(Inst);
587 if (Access)
588 instrumentMop(Inst, F.getDataLayout(), *Access);
589 else
590 instrumentMemIntrinsic(cast<MemIntrinsic>(Inst));
591 }
592 NumInstrumented++;
593 }
594
595 if (NumInstrumented > 0)
596 FunctionModified = true;
597
598 LLVM_DEBUG(dbgs() << "MEMPROF done instrumenting: " << FunctionModified << " "
599 << F << "\n");
600
601 return FunctionModified;
602}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
DXIL Resource Access
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
constexpr char MemProfVersionCheckNamePrefix[]
constexpr uint64_t MemProfEmscriptenCtorAndDtorPriority
constexpr char MemProfShadowMemoryDynamicAddress[]
constexpr uint64_t MemProfCtorAndDtorPriority
constexpr int LLVM_MEM_PROFILER_VERSION
constexpr char MemProfInitName[]
constexpr char MemProfFilenameVar[]
constexpr uint64_t DefaultMemGranularity
constexpr uint64_t HistogramGranularity
constexpr char MemProfModuleCtorName[]
void createMemprofDefaultOptionsVar(const InstrumentationOptions &Opts, Module &M)
constexpr char MemProfHistogramFlagVar[]
void createMemprofHistogramFlagVar(const InstrumentationOptions &Opts, Module &M)
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
Class for arbitrary precision integers.
Definition APInt.h:78
A container for analyses that lazily runs them and caches their results.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true, bool ByteString=false)
This method constructs a CDS and initializes it with a text string.
This is an important base class in LLVM.
Definition Constant.h:44
static LLVM_ABI Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
LLVM_ABI void setComdat(Comdat *C)
Definition Globals.cpp:287
void setLinkage(LinkageTypes LT)
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition GlobalValue.h:57
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2398
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2657
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2297
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2238
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1528
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition IRBuilder.h:522
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:2011
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition IRBuilder.h:1907
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1566
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1925
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1418
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2561
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition IRBuilder.h:2323
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition IRBuilder.h:196
Type * getVoidTy()
Fetch the type representing void.
Definition IRBuilder.h:560
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2909
An instruction for reading from memory.
A single uniqued string.
Definition Metadata.h:733
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:615
This is the common base class for memset/memcpy/memmove.
LLVM_ABI MemProfilerPass()
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:887
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
bool isOSEmscripten() const
Tests whether the OS is Emscripten.
Definition Triple.h:846
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:296
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:315
void instrumentAddress(Module &M, IRBuilder<> &IRB, Instruction *OrigIns, Instruction *InsertBefore, Value *Addr, Align Alignment, TypeSize TypeStoreSize, bool IsWrite, Value *SizeArgument, bool UseCalls, bool Recover, int AsanScale, int AsanOffset)
Instrument the memory operand Addr.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
llvm::StringRef getMemprofOptionsSymbolName()
Definition MemProf.h:60
This is an optimization pass for GlobalISel generic memory operations.
const InstrumentationOptions & getInstrumentationOptions(const LLVMContext &C)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
LLVM_ABI FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes, bool Weak=false)
LLVM_ABI std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef(), bool Weak=false)
Creates sanitizer constructor function, and calls sanitizer's init function from it.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth, bool MustPreserveProvenance=false)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
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...
Definition Casting.h:547
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
StringRef getInstrProfVarPrefix()
Return the prefix of the name of the variables to function as a filter.
Definition InstrProf.h:123
LLVM_ABI void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
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.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...