LLVM 19.0.0git
PtrUseVisitor.cpp
Go to the documentation of this file.
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
15#include "llvm/IR/Instruction.h"
17
18using namespace llvm;
19
21 for (Use &U : I.uses()) {
22 if (VisitedUses.insert(&U).second) {
23 UseToVisit NewU = {
25 Offset
26 };
27 Worklist.push_back(std::move(NewU));
28 }
29 }
30}
31
33 if (!IsOffsetKnown)
34 return false;
35
36 APInt TmpOffset(DL.getIndexTypeSizeInBits(GEPI.getType()), 0);
37 if (GEPI.accumulateConstantOffset(DL, TmpOffset)) {
38 Offset += TmpOffset.sextOrTrunc(Offset.getBitWidth());
39 return true;
40 }
41
42 return false;
43}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define I(x, y, z)
Definition: MD5.cpp:58
This file provides a collection of visitors which walk the (instruction) uses of a pointer.
Class for arbitrary precision integers.
Definition: APInt.h:76
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1010
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:973
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
APInt Offset
The constant offset of the use if that is known.
void enqueueUsers(Instruction &I)
Enqueue the users of this instruction in the visit worklist.
SmallVector< UseToVisit, 8 > Worklist
The worklist of to-visit uses.
bool IsOffsetKnown
True if we have a known constant offset for the use currently being visited.
bool adjustOffsetForGEP(GetElementPtrInst &GEPI)
Walk the operands of a GEP and adjust the offset as appropriate.
Use * U
The use currently being visited.
SmallPtrSet< Use *, 8 > VisitedUses
A set of visited uses to break cycles in unreachable code.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
A struct of the data needed to visit a particular use.
PointerIntPair< Use *, 1, bool > UseAndIsOffsetKnownPair