LLVM 23.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"
21#include "llvm/IR/IRBuilder.h"
22#include "llvm/IR/Intrinsics.h"
24
25namespace llvm {
26class DominatorTree;
27class IntrinsicInst;
29class AllocaInst;
30class Instruction;
31namespace memtag {
32struct AllocaInfo {
33 struct BBInfo {
36 // This BB calls lifetime.end twice without a start inbetween.
37 // TODO: handle this case smarter than just throwing out lifetime
38 // annotations completely.
39 bool DoubleEnd = false;
40 };
46};
47
48// For an alloca valid between lifetime markers Start and Ends, call the
49// Callback for all possible exits out of the lifetime in the containing
50// function, which can return from the instructions in RetVec.
51//
52// Returns whether Ends covered all possible exits. If they did not,
53// the caller should remove Ends to ensure that work done at the other
54// exits does not happen outside of the lifetime.
56 const LoopInfo &LI, const AllocaInfo &AInfo,
58 llvm::function_ref<void(Instruction *)> Callback);
59
60bool isSupportedLifetime(const AllocaInfo &AInfo, const DominatorTree *DT,
61 const LoopInfo *LI);
62
64
70
72 // Uninteresting because of the nature of the alloca.
74 // Uninteresting because proven safe.
76 // Interesting.
78};
79
81public:
82 StackInfoBuilder(const StackSafetyGlobalInfo *SSI, const char *DebugType)
83 : SSI(SSI), DebugType(DebugType) {}
84
87 StackInfo &get() { return Info; };
88
89private:
90 StackInfo Info;
91 const StackSafetyGlobalInfo *SSI;
92 const char *DebugType;
93};
94
97
100Value *getPC(const Triple &TargetTriple, IRBuilder<> &IRB);
101Value *getAndroidSlotPtr(IRBuilder<> &IRB, int Slot);
102Value *getDarwinSlotPtr(IRBuilder<> &IRB, int Slot);
103
104void annotateDebugRecords(AllocaInfo &Info, unsigned int Tag);
105Value *incrementThreadLong(IRBuilder<> &IRB, Value *ThreadLong,
106 unsigned int Inc, bool IsMemtagDarwin = false);
107
108} // namespace memtag
109} // namespace llvm
110
111#endif
This file implements a map that provides insertion order iteration.
This file defines the SmallVector class.
an instruction to allocate memory on the stack
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:164
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2788
A wrapper class for inspecting calls to intrinsic functions.
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:36
The optimization diagnostic interface.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
void visit(OptimizationRemarkEmitter &ORE, Instruction &Inst)
AllocaInterestingness getAllocaInterestingness(const AllocaInst &AI)
StackInfoBuilder(const StackSafetyGlobalInfo *SSI, const char *DebugType)
Value * getFP(IRBuilder<> &IRB)
bool isSupportedLifetime(const AllocaInfo &AInfo, const DominatorTree *DT, const LoopInfo *LI)
uint64_t getAllocaSizeInBytes(const AllocaInst &AI)
Value * getDarwinSlotPtr(IRBuilder<> &IRB, int Slot)
Value * getAndroidSlotPtr(IRBuilder<> &IRB, int Slot)
Value * readRegister(IRBuilder<> &IRB, StringRef Name)
void annotateDebugRecords(AllocaInfo &Info, unsigned int Tag)
Instruction * getUntagLocationIfFunctionExit(Instruction &Inst)
void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align)
Value * getPC(const Triple &TargetTriple, IRBuilder<> &IRB)
Value * incrementThreadLong(IRBuilder<> &IRB, Value *ThreadLong, unsigned int Inc, bool IsMemtagDarwin=false)
bool forAllReachableExits(const DominatorTree &DT, const PostDominatorTree &PDT, const LoopInfo &LI, const AllocaInfo &AInfo, const SmallVectorImpl< Instruction * > &RetVec, llvm::function_ref< void(Instruction *)> Callback)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
SmallVector< DbgVariableRecord *, 2 > DbgVariableRecords
SmallVector< IntrinsicInst *, 2 > LifetimeEnd
SmallVector< IntrinsicInst *, 2 > LifetimeStart
MapVector< BasicBlock *, struct BBInfo > BBInfos
MapVector< AllocaInst *, AllocaInfo > AllocasToInstrument
SmallVector< Instruction *, 8 > RetVec