LLVM 22.0.0git
AllocToken.cpp
Go to the documentation of this file.
1//===- AllocToken.cpp - Allocation token 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 implements AllocToken, an instrumentation pass that
10// replaces allocation calls with token-enabled versions.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/Statistic.h"
20#include "llvm/ADT/StringRef.h"
24#include "llvm/IR/Analysis.h"
25#include "llvm/IR/Attributes.h"
26#include "llvm/IR/Constants.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/GlobalValue.h"
30#include "llvm/IR/IRBuilder.h"
32#include "llvm/IR/InstrTypes.h"
34#include "llvm/IR/Metadata.h"
35#include "llvm/IR/Module.h"
36#include "llvm/IR/PassManager.h"
37#include "llvm/IR/Type.h"
45#include <cassert>
46#include <cstddef>
47#include <cstdint>
48#include <limits>
49#include <memory>
50#include <optional>
51#include <string>
52#include <utility>
53#include <variant>
54
55using namespace llvm;
56
57#define DEBUG_TYPE "alloc-token"
58
59namespace {
60
61//===--- Constants --------------------------------------------------------===//
62
63enum class TokenMode : unsigned {
64 /// Incrementally increasing token ID.
65 Increment = 0,
66
67 /// Simple mode that returns a statically-assigned random token ID.
68 Random = 1,
69
70 /// Token ID based on allocated type hash.
71 TypeHash = 2,
72
73 /// Token ID based on allocated type hash, where the top half ID-space is
74 /// reserved for types that contain pointers and the bottom half for types
75 /// that do not contain pointers.
76 TypeHashPointerSplit = 3,
77};
78
79//===--- Command-line options ---------------------------------------------===//
80
82 "alloc-token-mode", cl::Hidden, cl::desc("Token assignment mode"),
83 cl::init(TokenMode::TypeHashPointerSplit),
85 clEnumValN(TokenMode::Increment, "increment",
86 "Incrementally increasing token ID"),
87 clEnumValN(TokenMode::Random, "random",
88 "Statically-assigned random token ID"),
89 clEnumValN(TokenMode::TypeHash, "typehash",
90 "Token ID based on allocated type hash"),
92 TokenMode::TypeHashPointerSplit, "typehashpointersplit",
93 "Token ID based on allocated type hash, where the top half "
94 "ID-space is reserved for types that contain pointers and the "
95 "bottom half for types that do not contain pointers. ")));
96
97cl::opt<std::string> ClFuncPrefix("alloc-token-prefix",
98 cl::desc("The allocation function prefix"),
99 cl::Hidden, cl::init("__alloc_token_"));
100
101cl::opt<uint64_t> ClMaxTokens("alloc-token-max",
102 cl::desc("Maximum number of tokens (0 = no max)"),
103 cl::Hidden, cl::init(0));
104
106 ClFastABI("alloc-token-fast-abi",
107 cl::desc("The token ID is encoded in the function name"),
108 cl::Hidden, cl::init(false));
109
110// Instrument libcalls only by default - compatible allocators only need to take
111// care of providing standard allocation functions. With extended coverage, also
112// instrument non-libcall allocation function calls with !alloc_token
113// metadata.
115 ClExtended("alloc-token-extended",
116 cl::desc("Extend coverage to custom allocation functions"),
117 cl::Hidden, cl::init(false));
118
119// C++ defines ::operator new (and variants) as replaceable (vs. standard
120// library versions), which are nobuiltin, and are therefore not covered by
121// isAllocationFn(). Cover by default, as users of AllocToken are already
122// required to provide token-aware allocation functions (no defaults).
123cl::opt<bool> ClCoverReplaceableNew("alloc-token-cover-replaceable-new",
124 cl::desc("Cover replaceable operator new"),
125 cl::Hidden, cl::init(true));
126
127cl::opt<uint64_t> ClFallbackToken(
128 "alloc-token-fallback",
129 cl::desc("The default fallback token where none could be determined"),
130 cl::Hidden, cl::init(0));
131
132//===--- Statistics -------------------------------------------------------===//
133
134STATISTIC(NumFunctionsInstrumented, "Functions instrumented");
135STATISTIC(NumAllocationsInstrumented, "Allocations instrumented");
136
137//===----------------------------------------------------------------------===//
138
139/// Returns the !alloc_token metadata if available.
140///
141/// Expected format is: !{<type-name>, <contains-pointer>}
142MDNode *getAllocTokenMetadata(const CallBase &CB) {
143 MDNode *Ret = CB.getMetadata(LLVMContext::MD_alloc_token);
144 if (!Ret)
145 return nullptr;
146 assert(Ret->getNumOperands() == 2 && "bad !alloc_token");
147 assert(isa<MDString>(Ret->getOperand(0)));
148 assert(isa<ConstantAsMetadata>(Ret->getOperand(1)));
149 return Ret;
150}
151
152bool containsPointer(const MDNode *MD) {
154 auto *CI = cast<ConstantInt>(C->getValue());
155 return CI->getValue().getBoolValue();
156}
157
158class ModeBase {
159public:
160 explicit ModeBase(const IntegerType &TokenTy, uint64_t MaxTokens)
161 : MaxTokens(MaxTokens ? MaxTokens : TokenTy.getBitMask()) {
162 assert(MaxTokens <= TokenTy.getBitMask());
163 }
164
165protected:
166 uint64_t boundedToken(uint64_t Val) const {
167 assert(MaxTokens != 0);
168 return Val % MaxTokens;
169 }
170
171 const uint64_t MaxTokens;
172};
173
174/// Implementation for TokenMode::Increment.
175class IncrementMode : public ModeBase {
176public:
177 using ModeBase::ModeBase;
178
179 uint64_t operator()(const CallBase &CB, OptimizationRemarkEmitter &) {
180 return boundedToken(Counter++);
181 }
182
183private:
184 uint64_t Counter = 0;
185};
186
187/// Implementation for TokenMode::Random.
188class RandomMode : public ModeBase {
189public:
190 RandomMode(const IntegerType &TokenTy, uint64_t MaxTokens,
191 std::unique_ptr<RandomNumberGenerator> RNG)
192 : ModeBase(TokenTy, MaxTokens), RNG(std::move(RNG)) {}
193 uint64_t operator()(const CallBase &CB, OptimizationRemarkEmitter &) {
194 return boundedToken((*RNG)());
195 }
196
197private:
198 std::unique_ptr<RandomNumberGenerator> RNG;
199};
200
201/// Implementation for TokenMode::TypeHash. The implementation ensures
202/// hashes are stable across different compiler invocations. Uses SipHash as the
203/// hash function.
204class TypeHashMode : public ModeBase {
205public:
206 using ModeBase::ModeBase;
207
208 uint64_t operator()(const CallBase &CB, OptimizationRemarkEmitter &ORE) {
209 const auto [N, H] = getHash(CB, ORE);
210 return N ? boundedToken(H) : H;
211 }
212
213protected:
214 std::pair<MDNode *, uint64_t> getHash(const CallBase &CB,
216 if (MDNode *N = getAllocTokenMetadata(CB)) {
217 MDString *S = cast<MDString>(N->getOperand(0));
218 return {N, getStableSipHash(S->getString())};
219 }
220 // Fallback.
221 remarkNoMetadata(CB, ORE);
222 return {nullptr, ClFallbackToken};
223 }
224
225 /// Remark that there was no precise type information.
226 static void remarkNoMetadata(const CallBase &CB,
228 ORE.emit([&] {
229 ore::NV FuncNV("Function", CB.getParent()->getParent());
230 const Function *Callee = CB.getCalledFunction();
231 ore::NV CalleeNV("Callee", Callee ? Callee->getName() : "<unknown>");
232 return OptimizationRemark(DEBUG_TYPE, "NoAllocToken", &CB)
233 << "Call to '" << CalleeNV << "' in '" << FuncNV
234 << "' without source-level type token";
235 });
236 }
237};
238
239/// Implementation for TokenMode::TypeHashPointerSplit.
240class TypeHashPointerSplitMode : public TypeHashMode {
241public:
242 using TypeHashMode::TypeHashMode;
243
244 uint64_t operator()(const CallBase &CB, OptimizationRemarkEmitter &ORE) {
245 if (MaxTokens == 1)
246 return 0;
247 const uint64_t HalfTokens = MaxTokens / 2;
248 const auto [N, H] = getHash(CB, ORE);
249 if (!N) {
250 // Pick the fallback token (ClFallbackToken), which by default is 0,
251 // meaning it'll fall into the pointer-less bucket. Override by setting
252 // -alloc-token-fallback if that is the wrong choice.
253 return H;
254 }
255 uint64_t Hash = H % HalfTokens; // base hash
256 if (containsPointer(N))
257 Hash += HalfTokens;
258 return Hash;
259 }
260};
261
262// Apply opt overrides.
263AllocTokenOptions transformOptionsFromCl(AllocTokenOptions Opts) {
264 if (!Opts.MaxTokens.has_value())
265 Opts.MaxTokens = ClMaxTokens;
266 Opts.FastABI |= ClFastABI;
267 Opts.Extended |= ClExtended;
268 return Opts;
269}
270
271class AllocToken {
272public:
273 explicit AllocToken(AllocTokenOptions Opts, Module &M,
275 : Options(transformOptionsFromCl(std::move(Opts))), Mod(M),
276 FAM(MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager()),
277 Mode(IncrementMode(*IntPtrTy, *Options.MaxTokens)) {
278 switch (ClMode.getValue()) {
279 case TokenMode::Increment:
280 break;
281 case TokenMode::Random:
282 Mode.emplace<RandomMode>(*IntPtrTy, *Options.MaxTokens,
283 M.createRNG(DEBUG_TYPE));
284 break;
285 case TokenMode::TypeHash:
286 Mode.emplace<TypeHashMode>(*IntPtrTy, *Options.MaxTokens);
287 break;
288 case TokenMode::TypeHashPointerSplit:
289 Mode.emplace<TypeHashPointerSplitMode>(*IntPtrTy, *Options.MaxTokens);
290 break;
291 }
292 }
293
294 bool instrumentFunction(Function &F);
295
296private:
297 /// Returns the LibFunc (or NotLibFunc) if this call should be instrumented.
298 std::optional<LibFunc>
299 shouldInstrumentCall(const CallBase &CB, const TargetLibraryInfo &TLI) const;
300
301 /// Returns true for functions that are eligible for instrumentation.
302 static bool isInstrumentableLibFunc(LibFunc Func, const CallBase &CB,
303 const TargetLibraryInfo &TLI);
304
305 /// Returns true for isAllocationFn() functions that we should ignore.
306 static bool ignoreInstrumentableLibFunc(LibFunc Func);
307
308 /// Replace a call/invoke with a call/invoke to the allocation function
309 /// with token ID.
310 bool replaceAllocationCall(CallBase *CB, LibFunc Func,
312 const TargetLibraryInfo &TLI);
313
314 /// Return replacement function for a LibFunc that takes a token ID.
315 FunctionCallee getTokenAllocFunction(const CallBase &CB, uint64_t TokenID,
316 LibFunc OriginalFunc);
317
318 /// Return the token ID from metadata in the call.
320 return std::visit([&](auto &&Mode) { return Mode(CB, ORE); }, Mode);
321 }
322
324 Module &Mod;
325 IntegerType *IntPtrTy = Mod.getDataLayout().getIntPtrType(Mod.getContext());
327 // Cache for replacement functions.
329 // Selected mode.
330 std::variant<IncrementMode, RandomMode, TypeHashMode,
331 TypeHashPointerSplitMode>
332 Mode;
333};
334
335bool AllocToken::instrumentFunction(Function &F) {
336 // Do not apply any instrumentation for naked functions.
337 if (F.hasFnAttribute(Attribute::Naked))
338 return false;
339 if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
340 return false;
341 // Don't touch available_externally functions, their actual body is elsewhere.
342 if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage)
343 return false;
344 // Only instrument functions that have the sanitize_alloc_token attribute.
345 if (!F.hasFnAttribute(Attribute::SanitizeAllocToken))
346 return false;
347
348 auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
349 auto &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
351
352 // Collect all allocation calls to avoid iterator invalidation.
353 for (Instruction &I : instructions(F)) {
354 auto *CB = dyn_cast<CallBase>(&I);
355 if (!CB)
356 continue;
357 if (std::optional<LibFunc> Func = shouldInstrumentCall(*CB, TLI))
358 AllocCalls.emplace_back(CB, Func.value());
359 }
360
361 bool Modified = false;
362 for (auto &[CB, Func] : AllocCalls)
363 Modified |= replaceAllocationCall(CB, Func, ORE, TLI);
364
365 if (Modified)
366 NumFunctionsInstrumented++;
367 return Modified;
368}
369
370std::optional<LibFunc>
371AllocToken::shouldInstrumentCall(const CallBase &CB,
372 const TargetLibraryInfo &TLI) const {
373 const Function *Callee = CB.getCalledFunction();
374 if (!Callee)
375 return std::nullopt;
376
377 // Ignore nobuiltin of the CallBase, so that we can cover nobuiltin libcalls
378 // if requested via isInstrumentableLibFunc(). Note that isAllocationFn() is
379 // returning false for nobuiltin calls.
380 LibFunc Func;
381 if (TLI.getLibFunc(*Callee, Func)) {
382 if (isInstrumentableLibFunc(Func, CB, TLI))
383 return Func;
384 } else if (Options.Extended && getAllocTokenMetadata(CB)) {
385 return NotLibFunc;
386 }
387
388 return std::nullopt;
389}
390
391bool AllocToken::isInstrumentableLibFunc(LibFunc Func, const CallBase &CB,
392 const TargetLibraryInfo &TLI) {
393 if (ignoreInstrumentableLibFunc(Func))
394 return false;
395
396 if (isAllocationFn(&CB, &TLI))
397 return true;
398
399 switch (Func) {
400 // These libfuncs don't return normal pointers, and are therefore not handled
401 // by isAllocationFn().
402 case LibFunc_posix_memalign:
403 case LibFunc_size_returning_new:
404 case LibFunc_size_returning_new_hot_cold:
405 case LibFunc_size_returning_new_aligned:
406 case LibFunc_size_returning_new_aligned_hot_cold:
407 return true;
408
409 // See comment above ClCoverReplaceableNew.
410 case LibFunc_Znwj:
411 case LibFunc_ZnwjRKSt9nothrow_t:
412 case LibFunc_ZnwjSt11align_val_t:
413 case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
414 case LibFunc_Znwm:
415 case LibFunc_Znwm12__hot_cold_t:
416 case LibFunc_ZnwmRKSt9nothrow_t:
417 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
418 case LibFunc_ZnwmSt11align_val_t:
419 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
420 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
421 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
422 case LibFunc_Znaj:
423 case LibFunc_ZnajRKSt9nothrow_t:
424 case LibFunc_ZnajSt11align_val_t:
425 case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
426 case LibFunc_Znam:
427 case LibFunc_Znam12__hot_cold_t:
428 case LibFunc_ZnamRKSt9nothrow_t:
429 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
430 case LibFunc_ZnamSt11align_val_t:
431 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
432 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
433 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
434 return ClCoverReplaceableNew;
435
436 default:
437 return false;
438 }
439}
440
441bool AllocToken::ignoreInstrumentableLibFunc(LibFunc Func) {
442 switch (Func) {
443 case LibFunc_strdup:
444 case LibFunc_dunder_strdup:
445 case LibFunc_strndup:
446 case LibFunc_dunder_strndup:
447 return true;
448 default:
449 return false;
450 }
451}
452
453bool AllocToken::replaceAllocationCall(CallBase *CB, LibFunc Func,
455 const TargetLibraryInfo &TLI) {
456 uint64_t TokenID = getToken(*CB, ORE);
457
458 FunctionCallee TokenAlloc = getTokenAllocFunction(*CB, TokenID, Func);
459 if (!TokenAlloc)
460 return false;
461 NumAllocationsInstrumented++;
462
463 if (Options.FastABI) {
464 assert(TokenAlloc.getFunctionType()->getNumParams() == CB->arg_size());
465 CB->setCalledFunction(TokenAlloc);
466 return true;
467 }
468
469 IRBuilder<> IRB(CB);
470 // Original args.
471 SmallVector<Value *, 4> NewArgs{CB->args()};
472 // Add token ID, truncated to IntPtrTy width.
473 NewArgs.push_back(ConstantInt::get(IntPtrTy, TokenID));
474 assert(TokenAlloc.getFunctionType()->getNumParams() == NewArgs.size());
475
476 // Preserve invoke vs call semantics for exception handling.
477 CallBase *NewCall;
478 if (auto *II = dyn_cast<InvokeInst>(CB)) {
479 NewCall = IRB.CreateInvoke(TokenAlloc, II->getNormalDest(),
480 II->getUnwindDest(), NewArgs);
481 } else {
482 NewCall = IRB.CreateCall(TokenAlloc, NewArgs);
483 cast<CallInst>(NewCall)->setTailCall(CB->isTailCall());
484 }
485 NewCall->setCallingConv(CB->getCallingConv());
486 NewCall->copyMetadata(*CB);
487 NewCall->setAttributes(CB->getAttributes());
488
489 // Replace all uses and delete the old call.
490 CB->replaceAllUsesWith(NewCall);
491 CB->eraseFromParent();
492 return true;
493}
494
495FunctionCallee AllocToken::getTokenAllocFunction(const CallBase &CB,
496 uint64_t TokenID,
497 LibFunc OriginalFunc) {
498 std::optional<std::pair<LibFunc, uint64_t>> Key;
499 if (OriginalFunc != NotLibFunc) {
500 Key = std::make_pair(OriginalFunc, Options.FastABI ? TokenID : 0);
501 auto It = TokenAllocFunctions.find(*Key);
502 if (It != TokenAllocFunctions.end())
503 return It->second;
504 }
505
506 const Function *Callee = CB.getCalledFunction();
507 if (!Callee)
508 return FunctionCallee();
509 const FunctionType *OldFTy = Callee->getFunctionType();
510 if (OldFTy->isVarArg())
511 return FunctionCallee();
512 // Copy params, and append token ID type.
513 Type *RetTy = OldFTy->getReturnType();
514 SmallVector<Type *, 4> NewParams{OldFTy->params()};
515 std::string TokenAllocName = ClFuncPrefix;
516 if (Options.FastABI)
517 TokenAllocName += utostr(TokenID) + "_";
518 else
519 NewParams.push_back(IntPtrTy); // token ID
520 TokenAllocName += Callee->getName();
521 FunctionType *NewFTy = FunctionType::get(RetTy, NewParams, false);
522 FunctionCallee TokenAlloc = Mod.getOrInsertFunction(TokenAllocName, NewFTy);
523 if (Function *F = dyn_cast<Function>(TokenAlloc.getCallee()))
524 F->copyAttributesFrom(Callee); // preserve attrs
525
526 if (Key.has_value())
527 TokenAllocFunctions[*Key] = TokenAlloc;
528 return TokenAlloc;
529}
530
531} // namespace
532
535
537 AllocToken Pass(Options, M, MAM);
538 bool Modified = false;
539
540 for (Function &F : M) {
541 if (F.empty())
542 continue; // declaration
543 Modified |= Pass.instrumentFunction(F);
544 }
545
548}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
This file contains the simple types necessary to represent the attributes associated with functions a...
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
#define DEBUG_TYPE
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
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
#define H(x, y, z)
Definition MD5.cpp:57
print mir2vec MIR2Vec Vocabulary Printer Pass
Definition MIR2Vec.cpp:273
This file contains the declarations for metadata subclasses.
uint64_t IntrinsicInst * II
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallPtrSet class.
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
This file contains some functions that are useful when dealing with strings.
LLVM_ABI AllocTokenPass(AllocTokenOptions Opts={})
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void setCallingConv(CallingConv::ID CC)
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
CallingConv::ID getCallingConv() const
void setAttributes(AttributeList A)
Set the attributes for this call.
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
LLVM_ABI bool isTailCall() const
Tests if this call site is marked as a tail call.
void setTailCall(bool IsTc=true)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
FunctionType * getFunctionType()
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Create an invoke instruction.
Definition IRBuilder.h:1235
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2511
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2783
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Class to represent integer types.
uint64_t getBitMask() const
Return a bitmask with ones set for all of the bits that can be set by an unsigned version of this typ...
Metadata node.
Definition Metadata.h:1078
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1442
A single uniqued string.
Definition Metadata.h:721
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:618
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
The optimization diagnostic interface.
LLVM_ABI void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
Diagnostic information for applied optimization remarks.
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
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
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:546
const ParentTy * getParent() const
Definition ilist_node.h:34
Pass manager infrastructure for declaring and invalidating analyses.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:644
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
std::string utostr(uint64_t X, bool isNeg=false)
LLVM_ABI uint64_t getStableSipHash(StringRef Str)
Compute a stable 64-bit hash of the given string.
Definition SipHash.cpp:39
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:548
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1869
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:560
LLVM_ABI bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
#define N
std::optional< uint64_t > MaxTokens
Definition AllocToken.h:26