Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 1 | //===- PtrUseVisitor.cpp - InstVisitors over a pointers uses --------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 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 |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | be709f2 | 2017-08-18 23:51:26 +0000 | [diff] [blame] | 8 | // |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 9 | /// \file |
| 10 | /// Implementation of the pointer use visitors. |
Eugene Zelenko | be709f2 | 2017-08-18 23:51:26 +0000 | [diff] [blame] | 11 | // |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Analysis/PtrUseVisitor.h" |
Eugene Zelenko | be709f2 | 2017-08-18 23:51:26 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Instruction.h" |
| 16 | #include "llvm/IR/Instructions.h" |
| 17 | #include <algorithm> |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) { |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 22 | for (Use &U : I.uses()) { |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 23 | if (VisitedUses.insert(&U).second) { |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 24 | UseToVisit NewU = { |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 25 | UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown), |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 26 | Offset |
| 27 | }; |
Chandler Carruth | 002da5d | 2014-03-02 04:08:41 +0000 | [diff] [blame] | 28 | Worklist.push_back(std::move(NewU)); |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) { |
| 34 | if (!IsOffsetKnown) |
| 35 | return false; |
| 36 | |
Chandler Carruth | 1e14053 | 2012-12-11 10:29:10 +0000 | [diff] [blame] | 37 | return GEPI.accumulateConstantOffset(DL, Offset); |
Chandler Carruth | e41e7b7 | 2012-12-10 08:28:39 +0000 | [diff] [blame] | 38 | } |