PtrUseVisitor.cpp 1.3 KB

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