LLVM  8.0.1
MemCpyOptimizer.h
Go to the documentation of this file.
1 //===- MemCpyOptimizer.h - memcpy optimization ------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass performs various transformations related to eliminating memcpy
11 // calls, or transforming sets of stores into memset's.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
16 #define LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
17 
19 #include "llvm/IR/BasicBlock.h"
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/PassManager.h"
22 #include <cstdint>
23 #include <functional>
24 
25 namespace llvm {
26 
27 class AssumptionCache;
28 class CallInst;
29 class DominatorTree;
30 class Function;
31 class Instruction;
32 class MemCpyInst;
33 class MemMoveInst;
34 class MemoryDependenceResults;
35 class MemSetInst;
36 class StoreInst;
37 class TargetLibraryInfo;
38 class Value;
39 
40 class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
41  MemoryDependenceResults *MD = nullptr;
42  TargetLibraryInfo *TLI = nullptr;
43  std::function<AliasAnalysis &()> LookupAliasAnalysis;
44  std::function<AssumptionCache &()> LookupAssumptionCache;
45  std::function<DominatorTree &()> LookupDomTree;
46 
47 public:
48  MemCpyOptPass() = default;
49 
51 
52  // Glue for the old PM.
54  TargetLibraryInfo *TLI_,
55  std::function<AliasAnalysis &()> LookupAliasAnalysis_,
56  std::function<AssumptionCache &()> LookupAssumptionCache_,
57  std::function<DominatorTree &()> LookupDomTree_);
58 
59 private:
60  // Helper functions
61  bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
62  bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
63  bool processMemCpy(MemCpyInst *M);
64  bool processMemMove(MemMoveInst *M);
65  bool performCallSlotOptzn(Instruction *cpy, Value *cpyDst, Value *cpySrc,
66  uint64_t cpyLen, unsigned cpyAlign, CallInst *C);
67  bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
68  bool processMemSetMemCpyDependence(MemCpyInst *M, MemSetInst *MDep);
69  bool performMemCpyToMemSetOptzn(MemCpyInst *M, MemSetInst *MDep);
70  bool processByValArgument(CallSite CS, unsigned ArgNo);
71  Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
72  Value *ByteVal);
73 
74  bool iterateOnFunction(Function &F);
75 };
76 
77 } // end namespace llvm
78 
79 #endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
uint64_t CallInst * C
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM&#39;s alias analysis passes.
MemCpyOptPass()=default
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This class represents a function call, abstracting a target machine&#39;s calling convention.
A cache of @llvm.assume calls within a function.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This class wraps the llvm.memset intrinsic.
F(f)
This class wraps the llvm.memmove intrinsic.
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:366
An instruction for storing to memory.
Definition: Instructions.h:321
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:145
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
bool runImpl(Function &F, MemoryDependenceResults *MD_, TargetLibraryInfo *TLI_, std::function< AliasAnalysis &()> LookupAliasAnalysis_, std::function< AssumptionCache &()> LookupAssumptionCache_, std::function< DominatorTree &()> LookupDomTree_)
Provides information about what library functions are available for the current target.
This class wraps the llvm.memcpy intrinsic.
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:90
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM Value Representation.
Definition: Value.h:73
print Print MemDeps of function
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.