[TableGen] Fix validateOperandClass for non Phyical Reg (#118146)
[llvm-project.git] / llvm / lib / Analysis / MemDerefPrinter.cpp
blobe1245e2ed44c0fc8e50945e09dd89ab5961c0458
1 //===- MemDerefPrinter.cpp - Printer for isDereferenceablePointer ---------===//
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 //===----------------------------------------------------------------------===//
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"
16 using namespace llvm;
18 PreservedAnalyses MemDerefPrinterPass::run(Function &F,
19 FunctionAnalysisManager &AM) {
20 OS << "Memory Dereferencibility of pointers in function '" << F.getName()
21 << "'\n";
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))
31 Deref.push_back(PO);
32 if (isDereferenceableAndAlignedPointer(PO, LI->getType(), LI->getAlign(),
33 DL, LI))
34 DerefAndAligned.insert(PO);
38 OS << "The following are dereferenceable:\n";
39 for (Value *V : Deref) {
40 OS << " ";
41 V->print(OS);
42 if (DerefAndAligned.count(V))
43 OS << "\t(aligned)";
44 else
45 OS << "\t(unaligned)";
46 OS << "\n";
48 return PreservedAnalyses::all();