PtrUseVisitor.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "llvm/Analysis/PtrUseVisitor.h"
  14. #include "llvm/IR/Instruction.h"
  15. #include "llvm/IR/Instructions.h"
  16. using namespace llvm;
  17. void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) {
  18. for (Use &U : I.uses()) {
  19. if (VisitedUses.insert(&U).second) {
  20. UseToVisit NewU = {
  21. UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
  22. Offset
  23. };
  24. Worklist.push_back(std::move(NewU));
  25. }
  26. }
  27. }
  28. bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) {
  29. if (!IsOffsetKnown)
  30. return false;
  31. APInt TmpOffset(DL.getIndexTypeSizeInBits(GEPI.getType()), 0);
  32. if (GEPI.accumulateConstantOffset(DL, TmpOffset)) {
  33. Offset += TmpOffset.sextOrTrunc(Offset.getBitWidth());
  34. return true;
  35. }
  36. return false;
  37. }