MemCpyOptimizer.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MemCpyOptimizer.h - memcpy optimization ------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This pass performs various transformations related to eliminating memcpy
  15. // calls, or transforming sets of stores into memset's.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
  19. #define LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
  20. #include "llvm/IR/BasicBlock.h"
  21. #include "llvm/IR/PassManager.h"
  22. #include <cstdint>
  23. #include <functional>
  24. namespace llvm {
  25. class AAResults;
  26. class AssumptionCache;
  27. class CallBase;
  28. class CallInst;
  29. class DominatorTree;
  30. class Function;
  31. class Instruction;
  32. class LoadInst;
  33. class MemCpyInst;
  34. class MemMoveInst;
  35. class MemorySSA;
  36. class MemorySSAUpdater;
  37. class MemSetInst;
  38. class StoreInst;
  39. class TargetLibraryInfo;
  40. class Value;
  41. class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
  42. TargetLibraryInfo *TLI = nullptr;
  43. AAResults *AA = nullptr;
  44. AssumptionCache *AC = nullptr;
  45. DominatorTree *DT = nullptr;
  46. MemorySSA *MSSA = nullptr;
  47. MemorySSAUpdater *MSSAU = nullptr;
  48. public:
  49. MemCpyOptPass() = default;
  50. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  51. // Glue for the old PM.
  52. bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA,
  53. AssumptionCache *AC, DominatorTree *DT, MemorySSA *MSSA);
  54. private:
  55. // Helper functions
  56. bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
  57. bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
  58. bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
  59. bool processMemMove(MemMoveInst *M);
  60. bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
  61. Value *cpyDst, Value *cpySrc, TypeSize cpyLen,
  62. Align cpyAlign, CallInst *C);
  63. bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
  64. bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet);
  65. bool performMemCpyToMemSetOptzn(MemCpyInst *MemCpy, MemSetInst *MemSet);
  66. bool processByValArgument(CallBase &CB, unsigned ArgNo);
  67. Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
  68. Value *ByteVal);
  69. bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
  70. void eraseInstruction(Instruction *I);
  71. bool iterateOnFunction(Function &F);
  72. };
  73. } // end namespace llvm
  74. #endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
  75. #ifdef __GNUC__
  76. #pragma GCC diagnostic pop
  77. #endif