MemCpyOptimizer.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. namespace llvm {
  23. class AAResults;
  24. class BatchAAResults;
  25. class AssumptionCache;
  26. class CallBase;
  27. class CallInst;
  28. class DominatorTree;
  29. class Function;
  30. class Instruction;
  31. class LoadInst;
  32. class MemCpyInst;
  33. class MemMoveInst;
  34. class MemorySSA;
  35. class MemorySSAUpdater;
  36. class MemSetInst;
  37. class StoreInst;
  38. class TargetLibraryInfo;
  39. class Value;
  40. class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
  41. TargetLibraryInfo *TLI = nullptr;
  42. AAResults *AA = nullptr;
  43. AssumptionCache *AC = nullptr;
  44. DominatorTree *DT = nullptr;
  45. MemorySSA *MSSA = nullptr;
  46. MemorySSAUpdater *MSSAU = nullptr;
  47. public:
  48. MemCpyOptPass() = default;
  49. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  50. // Glue for the old PM.
  51. bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA,
  52. AssumptionCache *AC, DominatorTree *DT, MemorySSA *MSSA);
  53. private:
  54. // Helper functions
  55. bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
  56. bool processStoreOfLoad(StoreInst *SI, LoadInst *LI, const DataLayout &DL,
  57. BasicBlock::iterator &BBI);
  58. bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
  59. bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
  60. bool processMemMove(MemMoveInst *M);
  61. bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
  62. Value *cpyDst, Value *cpySrc, TypeSize cpyLen,
  63. Align cpyAlign, BatchAAResults &BAA,
  64. std::function<CallInst *()> GetC);
  65. bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep,
  66. BatchAAResults &BAA);
  67. bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet,
  68. BatchAAResults &BAA);
  69. bool performMemCpyToMemSetOptzn(MemCpyInst *MemCpy, MemSetInst *MemSet,
  70. BatchAAResults &BAA);
  71. bool processByValArgument(CallBase &CB, unsigned ArgNo);
  72. Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
  73. Value *ByteVal);
  74. bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
  75. void eraseInstruction(Instruction *I);
  76. bool iterateOnFunction(Function &F);
  77. };
  78. } // end namespace llvm
  79. #endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
  80. #ifdef __GNUC__
  81. #pragma GCC diagnostic pop
  82. #endif