1 | //===- PtrUseVisitor.cpp - InstVisitors over a pointers uses --------------===// |
---|---|
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | /// \file |
10 | /// Implementation of the pointer use visitors. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "llvm/Analysis/PtrUseVisitor.h" |
15 | #include "llvm/IR/Instruction.h" |
16 | #include "llvm/IR/Instructions.h" |
17 | |
18 | using namespace llvm; |
19 | |
20 | void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) { |
21 | for (Use &U : I.uses()) { |
22 | if (VisitedUses.insert(Ptr: &U).second) { |
23 | UseToVisit NewU = { |
24 | .UseAndIsOffsetKnown: UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown), |
25 | .Offset: Offset |
26 | }; |
27 | Worklist.push_back(Elt: std::move(NewU)); |
28 | } |
29 | } |
30 | } |
31 | |
32 | bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) { |
33 | if (!IsOffsetKnown) |
34 | return false; |
35 | |
36 | APInt TmpOffset(DL.getIndexTypeSizeInBits(Ty: GEPI.getType()), 0); |
37 | if (GEPI.accumulateConstantOffset(DL, Offset&: TmpOffset)) { |
38 | Offset += TmpOffset.sextOrTrunc(width: Offset.getBitWidth()); |
39 | return true; |
40 | } |
41 | |
42 | return false; |
43 | } |
44 |