LLVM  15.0.0git
MemoryTaggingSupport.h
Go to the documentation of this file.
1 //===- MemoryTaggingSupport.h - helpers for memory tagging implementations ===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file declares common infrastructure for HWAddressSanitizer and
9 // Aarch64StackTagging.
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_TRANSFORMS_UTILS_MEMORYTAGGINGSUPPORT_H
13 #define LLVM_TRANSFORMS_UTILS_MEMORYTAGGINGSUPPORT_H
14 
15 #include "llvm/ADT/MapVector.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Support/Alignment.h"
20 
21 namespace llvm {
22 class DominatorTree;
23 class DbgVariableIntrinsic;
24 class IntrinsicInst;
25 class PostDominatorTree;
26 class AllocaInst;
27 class Instruction;
28 namespace memtag {
29 // For an alloca valid between lifetime markers Start and Ends, call the
30 // Callback for all possible exits out of the lifetime in the containing
31 // function, which can return from the instructions in RetVec.
32 //
33 // Returns whether Ends covered all possible exits. If they did not,
34 // the caller should remove Ends to ensure that work done at the other
35 // exits does not happen outside of the lifetime.
36 bool forAllReachableExits(const DominatorTree &DT, const PostDominatorTree &PDT,
37  const LoopInfo &LI, const Instruction *Start,
39  const SmallVectorImpl<Instruction *> &RetVec,
40  llvm::function_ref<void(Instruction *)> Callback);
41 
43  const SmallVectorImpl<IntrinsicInst *> &LifetimeEnd,
44  const DominatorTree *DT, const LoopInfo *LI,
45  size_t MaxLifetimes);
46 
48 
49 struct AllocaInfo {
54 };
55 
56 struct StackInfo {
60  bool CallsReturnTwice = false;
61 };
62 
64 public:
65  StackInfoBuilder(std::function<bool(const AllocaInst &)> IsInterestingAlloca)
66  : IsInterestingAlloca(IsInterestingAlloca) {}
67 
68  void visit(Instruction &Inst);
69  StackInfo &get() { return Info; };
70 
71 private:
72  StackInfo Info;
73  std::function<bool(const AllocaInst &)> IsInterestingAlloca;
74 };
75 
78 
79 } // namespace memtag
80 } // namespace llvm
81 
82 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::memtag::StackInfo
Definition: MemoryTaggingSupport.h:56
llvm::memtag::AllocaInfo::DbgVariableIntrinsics
SmallVector< DbgVariableIntrinsic *, 2 > DbgVariableIntrinsics
Definition: MemoryTaggingSupport.h:53
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::memtag::StackInfo::CallsReturnTwice
bool CallsReturnTwice
Definition: MemoryTaggingSupport.h:60
MapVector.h
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
llvm::memtag::forAllReachableExits
bool forAllReachableExits(const DominatorTree &DT, const PostDominatorTree &PDT, const LoopInfo &LI, const Instruction *Start, const SmallVectorImpl< IntrinsicInst * > &Ends, const SmallVectorImpl< Instruction * > &RetVec, llvm::function_ref< void(Instruction *)> Callback)
Definition: MemoryTaggingSupport.cpp:42
llvm::memtag::AllocaInfo::AI
AllocaInst * AI
Definition: MemoryTaggingSupport.h:50
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
llvm::memtag::StackInfo::RetVec
SmallVector< Instruction *, 8 > RetVec
Definition: MemoryTaggingSupport.h:59
llvm::memtag::StackInfoBuilder
Definition: MemoryTaggingSupport.h:63
llvm::Instruction
Definition: Instruction.h:42
STLFunctionalExtras.h
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
LoopInfo.h
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
uint64_t
llvm::memtag::StackInfo::UnrecognizedLifetimes
SmallVector< Instruction *, 4 > UnrecognizedLifetimes
Definition: MemoryTaggingSupport.h:58
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::memtag::AllocaInfo
Definition: MemoryTaggingSupport.h:49
llvm::memtag::StackInfoBuilder::get
StackInfo & get()
Definition: MemoryTaggingSupport.h:69
llvm::LoopInfo
Definition: LoopInfo.h:1105
llvm::PostDominatorTree
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
Definition: PostDominators.h:28
llvm::memtag::StackInfoBuilder::visit
void visit(Instruction &Inst)
Definition: MemoryTaggingSupport.cpp:110
llvm::memtag::AllocaInfo::LifetimeEnd
SmallVector< IntrinsicInst *, 2 > LifetimeEnd
Definition: MemoryTaggingSupport.h:52
llvm::memtag::isStandardLifetime
bool isStandardLifetime(const SmallVectorImpl< IntrinsicInst * > &LifetimeStart, const SmallVectorImpl< IntrinsicInst * > &LifetimeEnd, const DominatorTree *DT, const LoopInfo *LI, size_t MaxLifetimes)
Definition: MemoryTaggingSupport.cpp:85
llvm::memtag::StackInfoBuilder::StackInfoBuilder
StackInfoBuilder(std::function< bool(const AllocaInst &)> IsInterestingAlloca)
Definition: MemoryTaggingSupport.h:65
Alignment.h
llvm::memtag::alignAndPadAlloca
void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align)
Definition: MemoryTaggingSupport.cpp:160
llvm::memtag::StackInfo::AllocasToInstrument
MapVector< AllocaInst *, AllocaInfo > AllocasToInstrument
Definition: MemoryTaggingSupport.h:57
llvm::memtag::AllocaInfo::LifetimeStart
SmallVector< IntrinsicInst *, 2 > LifetimeStart
Definition: MemoryTaggingSupport.h:51
SmallVector.h
llvm::memtag::getAllocaSizeInBytes
uint64_t getAllocaSizeInBytes(const AllocaInst &AI)
Definition: MemoryTaggingSupport.cpp:155
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:59
llvm::memtag::getUntagLocationIfFunctionExit
Instruction * getUntagLocationIfFunctionExit(Instruction &Inst)
Definition: MemoryTaggingSupport.cpp:98