LLVM 19.0.0git
Go to the documentation of this file.
1//===- MemDerefPrinter.cpp - Printer for isDereferenceablePointer ---------===//
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
10#include "llvm/Analysis/Loads.h"
14#include "llvm/IR/Module.h"
16#include "llvm/Pass.h"
19using namespace llvm;
23 OS << "Memory Dereferencibility of pointers in function '" << F.getName()
24 << "'\n";
27 SmallPtrSet<Value *, 4> DerefAndAligned;
29 const DataLayout &DL = F.getParent()->getDataLayout();
30 for (auto &I : instructions(F)) {
31 if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
32 Value *PO = LI->getPointerOperand();
33 if (isDereferenceablePointer(PO, LI->getType(), DL))
34 Deref.push_back(PO);
35 if (isDereferenceableAndAlignedPointer(PO, LI->getType(), LI->getAlign(),
36 DL))
37 DerefAndAligned.insert(PO);
38 }
39 }
41 OS << "The following are dereferenceable:\n";
42 for (Value *V : Deref) {
43 OS << " ";
44 V->print(OS);
45 if (DerefAndAligned.count(V))
46 OS << "\t(aligned)";
47 else
48 OS << "\t(unaligned)";
49 OS << "\n";
50 }
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Select target instructions out of generic instructions
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Module.h This file contains the declarations for the Module class.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:348
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
An instruction for reading from memory.
Definition: Instructions.h:178
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:360
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:342
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, Align Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested.
Definition: Loads.cpp:199
bool isDereferenceablePointer(const Value *V, Type *Ty, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if this is always a dereferenceable pointer.
Definition: Loads.cpp:219