LLVM  5.0.0
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 
22 #include "llvm/IR/BasicBlock.h"
23 #include "llvm/IR/Dominators.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/IntrinsicInst.h"
27 #include "llvm/IR/PassManager.h"
28 #include <cstdint>
29 #include <functional>
30 
31 namespace llvm {
32 
33 class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
34  MemoryDependenceResults *MD = nullptr;
35  TargetLibraryInfo *TLI = nullptr;
36  std::function<AliasAnalysis &()> LookupAliasAnalysis;
37  std::function<AssumptionCache &()> LookupAssumptionCache;
38  std::function<DominatorTree &()> LookupDomTree;
39 
40 public:
41  MemCpyOptPass() = default;
42 
44  // Glue for the old PM.
46  TargetLibraryInfo *TLI_,
47  std::function<AliasAnalysis &()> LookupAliasAnalysis_,
48  std::function<AssumptionCache &()> LookupAssumptionCache_,
49  std::function<DominatorTree &()> LookupDomTree_);
50 
51 private:
52  // Helper functions
53  bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
54  bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
55  bool processMemCpy(MemCpyInst *M);
56  bool processMemMove(MemMoveInst *M);
57  bool performCallSlotOptzn(Instruction *cpy, Value *cpyDst, Value *cpySrc,
58  uint64_t cpyLen, unsigned cpyAlign, CallInst *C);
59  bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
60  bool processMemSetMemCpyDependence(MemCpyInst *M, MemSetInst *MDep);
61  bool performMemCpyToMemSetOptzn(MemCpyInst *M, MemSetInst *MDep);
62  bool processByValArgument(CallSite CS, unsigned ArgNo);
63  Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
64  Value *ByteVal);
65 
66  bool iterateOnFunction(Function &F);
67 };
68 
69 } // end namespace llvm
70 
71 #endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
MemCpyOptPass()=default
This class represents a function call, abstracting a target machine's calling convention.
A cache of .assume calls within a function.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This class wraps the llvm.memset intrinsic.
This class wraps the llvm.memmove intrinsic.
#define F(x, y, z)
Definition: MD5.cpp:55
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:365
An instruction for storing to memory.
Definition: Instructions.h:306
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:134
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
bool runImpl(Function &F, MemoryDependenceResults *MD_, TargetLibraryInfo *TLI_, std::function< AliasAnalysis &()> LookupAliasAnalysis_, std::function< AssumptionCache &()> LookupAssumptionCache_, std::function< DominatorTree &()> LookupDomTree_)
Iterator for intrusive lists based on ilist_node.
Provides information about what library functions are available for the current target.
This class wraps the llvm.memcpy intrinsic.
#define C
Definition: LargeTest.cpp:25
#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.