blob: f78446c6fb49241c9bb49f5b30ec61643fd85b42 [file] [log] [blame]
Chandler Carruthe41e7b72012-12-10 08:28:39 +00001//===- PtrUseVisitor.cpp - InstVisitors over a pointers uses --------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Chandler Carruthe41e7b72012-12-10 08:28:39 +00006//
7//===----------------------------------------------------------------------===//
Eugene Zelenkobe709f22017-08-18 23:51:26 +00008//
Chandler Carruthe41e7b72012-12-10 08:28:39 +00009/// \file
10/// Implementation of the pointer use visitors.
Eugene Zelenkobe709f22017-08-18 23:51:26 +000011//
Chandler Carruthe41e7b72012-12-10 08:28:39 +000012//===----------------------------------------------------------------------===//
13
14#include "llvm/Analysis/PtrUseVisitor.h"
Eugene Zelenkobe709f22017-08-18 23:51:26 +000015#include "llvm/IR/Instruction.h"
16#include "llvm/IR/Instructions.h"
17#include <algorithm>
Chandler Carruthe41e7b72012-12-10 08:28:39 +000018
19using namespace llvm;
20
21void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) {
Chandler Carruthcdf47882014-03-09 03:16:01 +000022 for (Use &U : I.uses()) {
David Blaikie70573dc2014-11-19 07:49:26 +000023 if (VisitedUses.insert(&U).second) {
Chandler Carruthe41e7b72012-12-10 08:28:39 +000024 UseToVisit NewU = {
Chandler Carruthcdf47882014-03-09 03:16:01 +000025 UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
Chandler Carruthe41e7b72012-12-10 08:28:39 +000026 Offset
27 };
Chandler Carruth002da5d2014-03-02 04:08:41 +000028 Worklist.push_back(std::move(NewU));
Chandler Carruthe41e7b72012-12-10 08:28:39 +000029 }
30 }
31}
32
33bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) {
34 if (!IsOffsetKnown)
35 return false;
36
Chandler Carruth1e140532012-12-11 10:29:10 +000037 return GEPI.accumulateConstantOffset(DL, Offset);
Chandler Carruthe41e7b72012-12-10 08:28:39 +000038}