blob: 1fdaf4d55b590be6dbabb01939e99f55d5457089 [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//===----------------------------------------------------------------------===//
Eugene Zelenkobe709f22017-08-18 23:51:26 +00009//
Chandler Carruthe41e7b72012-12-10 08:28:39 +000010/// \file
11/// Implementation of the pointer use visitors.
Eugene Zelenkobe709f22017-08-18 23:51:26 +000012//
Chandler Carruthe41e7b72012-12-10 08:28:39 +000013//===----------------------------------------------------------------------===//
14
15#include "llvm/Analysis/PtrUseVisitor.h"
Eugene Zelenkobe709f22017-08-18 23:51:26 +000016#include "llvm/IR/Instruction.h"
17#include "llvm/IR/Instructions.h"
18#include <algorithm>
Chandler Carruthe41e7b72012-12-10 08:28:39 +000019
20using namespace llvm;
21
22void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) {
Chandler Carruthcdf47882014-03-09 03:16:01 +000023 for (Use &U : I.uses()) {
David Blaikie70573dc2014-11-19 07:49:26 +000024 if (VisitedUses.insert(&U).second) {
Chandler Carruthe41e7b72012-12-10 08:28:39 +000025 UseToVisit NewU = {
Chandler Carruthcdf47882014-03-09 03:16:01 +000026 UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
Chandler Carruthe41e7b72012-12-10 08:28:39 +000027 Offset
28 };
Chandler Carruth002da5d2014-03-02 04:08:41 +000029 Worklist.push_back(std::move(NewU));
Chandler Carruthe41e7b72012-12-10 08:28:39 +000030 }
31 }
32}
33
34bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) {
35 if (!IsOffsetKnown)
36 return false;
37
Chandler Carruth1e140532012-12-11 10:29:10 +000038 return GEPI.accumulateConstantOffset(DL, Offset);
Chandler Carruthe41e7b72012-12-10 08:28:39 +000039}