LLVM  13.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"
16 #include "llvm/IR/Instructions.h"
17 #include <algorithm>
18 
19 using namespace llvm;
20 
22  for (Use &U : I.uses()) {
23  if (VisitedUses.insert(&U).second) {
24  UseToVisit NewU = {
26  Offset
27  };
28  Worklist.push_back(std::move(NewU));
29  }
30  }
31 }
32 
34  if (!IsOffsetKnown)
35  return false;
36 
37  APInt TmpOffset(DL.getIndexTypeSizeInBits(GEPI.getType()), 0);
38  if (GEPI.accumulateConstantOffset(DL, TmpOffset)) {
39  Offset += TmpOffset.sextOrTrunc(Offset.getBitWidth());
40  return true;
41  }
42 
43  return false;
44 }
PtrUseVisitor.h
llvm::detail::PtrUseVisitorBase::enqueueUsers
void enqueueUsers(Instruction &I)
Enqueue the users of this instruction in the visit worklist.
Definition: PtrUseVisitor.cpp:21
llvm
Definition: AllocatorList.h:23
llvm::detail::PtrUseVisitorBase::UseToVisit
A struct of the data needed to visit a particular use.
Definition: PtrUseVisitor.h:129
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::detail::PtrUseVisitorBase::VisitedUses
SmallPtrSet< Use *, 8 > VisitedUses
A set of visited uses to break cycles in unreachable code.
Definition: PtrUseVisitor.h:140
Instruction.h
llvm::detail::PtrUseVisitorBase::IsOffsetKnown
bool IsOffsetKnown
True if we have a known constant offset for the use currently being visited.
Definition: PtrUseVisitor.h:153
llvm::Instruction
Definition: Instruction.h:45
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::detail::PtrUseVisitorBase::adjustOffsetForGEP
bool adjustOffsetForGEP(GetElementPtrInst &GEPI)
Walk the operands of a GEP and adjust the offset as appropriate.
Definition: PtrUseVisitor.cpp:33
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::GetElementPtrInst
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:905
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:70
llvm::detail::PtrUseVisitorBase::UseToVisit::UseAndIsOffsetKnownPair
PointerIntPair< Use *, 1, bool > UseAndIsOffsetKnownPair
Definition: PtrUseVisitor.h:130
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::detail::PtrUseVisitorBase::Offset
APInt Offset
The constant offset of the use if that is known.
Definition: PtrUseVisitor.h:156
llvm::GetElementPtrInst::accumulateConstantOffset
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
Definition: Instructions.cpp:1803
llvm::APInt::sextOrTrunc
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:956
Instructions.h
llvm::detail::PtrUseVisitorBase::U
Use * U
The use currently being visited.
Definition: PtrUseVisitor.h:149
llvm::detail::PtrUseVisitorBase::Worklist
SmallVector< UseToVisit, 8 > Worklist
The worklist of to-visit uses.
Definition: PtrUseVisitor.h:137
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:44