blob: 68c7535ea59438c4871db05ea5c588f9069cd314 [file] [log] [blame]
Chandler Carruthe41e7b72012-12-10 08:28:39 +00001//===- PtrUseVisitor.cpp - InstVisitors over a pointers uses --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// Implementation of the pointer use visitors.
11///
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Analysis/PtrUseVisitor.h"
15
16using namespace llvm;
17
18void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) {
Chandler Carruthcdf47882014-03-09 03:16:01 +000019 for (Use &U : I.uses()) {
David Blaikie70573dc2014-11-19 07:49:26 +000020 if (VisitedUses.insert(&U).second) {
Chandler Carruthe41e7b72012-12-10 08:28:39 +000021 UseToVisit NewU = {
Chandler Carruthcdf47882014-03-09 03:16:01 +000022 UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
Chandler Carruthe41e7b72012-12-10 08:28:39 +000023 Offset
24 };
Chandler Carruth002da5d2014-03-02 04:08:41 +000025 Worklist.push_back(std::move(NewU));
Chandler Carruthe41e7b72012-12-10 08:28:39 +000026 }
27 }
28}
29
30bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) {
31 if (!IsOffsetKnown)
32 return false;
33
Chandler Carruth1e140532012-12-11 10:29:10 +000034 return GEPI.accumulateConstantOffset(DL, Offset);
Chandler Carruthe41e7b72012-12-10 08:28:39 +000035}