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