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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/MemDerefPrinter.h"
10 #include "llvm/Analysis/Loads.h"
11 #include "llvm/IR/InstIterator.h"
12 #include "llvm/IR/Instructions.h"
13 #include "llvm/Pass.h"
14 #include "llvm/Support/raw_ostream.h"
18 PreservedAnalyses
MemDerefPrinterPass::run(Function
&F
,
19 FunctionAnalysisManager
&AM
) {
20 OS
<< "Memory Dereferencibility of pointers in function '" << F
.getName()
23 SmallVector
<Value
*, 4> Deref
;
24 SmallPtrSet
<Value
*, 4> DerefAndAligned
;
26 const DataLayout
&DL
= F
.getDataLayout();
27 for (auto &I
: instructions(F
)) {
28 if (LoadInst
*LI
= dyn_cast
<LoadInst
>(&I
)) {
29 Value
*PO
= LI
->getPointerOperand();
30 if (isDereferenceablePointer(PO
, LI
->getType(), DL
, LI
))
32 if (isDereferenceableAndAlignedPointer(PO
, LI
->getType(), LI
->getAlign(),
34 DerefAndAligned
.insert(PO
);
38 OS
<< "The following are dereferenceable:\n";
39 for (Value
*V
: Deref
) {
42 if (DerefAndAligned
.count(V
))
45 OS
<< "\t(unaligned)";
48 return PreservedAnalyses::all();