PtrUseVisitor.cpp revision 280031
1239281Sgonzo//===- PtrUseVisitor.cpp - InstVisitors over a pointers uses --------------===//
2239281Sgonzo//
3239281Sgonzo//                     The LLVM Compiler Infrastructure
4239281Sgonzo//
5239281Sgonzo// This file is distributed under the University of Illinois Open Source
6239281Sgonzo// License. See LICENSE.TXT for details.
7239281Sgonzo//
8239281Sgonzo//===----------------------------------------------------------------------===//
9239281Sgonzo/// \file
10239281Sgonzo/// Implementation of the pointer use visitors.
11239281Sgonzo///
12239281Sgonzo//===----------------------------------------------------------------------===//
13239281Sgonzo
14239281Sgonzo#include "llvm/Analysis/PtrUseVisitor.h"
15239281Sgonzo
16239281Sgonzousing namespace llvm;
17239281Sgonzo
18239281Sgonzovoid detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) {
19239281Sgonzo  for (Use &U : I.uses()) {
20239281Sgonzo    if (VisitedUses.insert(&U).second) {
21239281Sgonzo      UseToVisit NewU = {
22239281Sgonzo        UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
23239281Sgonzo        Offset
24239281Sgonzo      };
25239281Sgonzo      Worklist.push_back(std::move(NewU));
26239281Sgonzo    }
27239281Sgonzo  }
28239281Sgonzo}
29275767Sandrew
30269797Sianbool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) {
31239283Sgonzo  if (!IsOffsetKnown)
32239281Sgonzo    return false;
33239281Sgonzo
34239281Sgonzo  return GEPI.accumulateConstantOffset(DL, Offset);
35239281Sgonzo}
36239281Sgonzo