LLVM  9.0.0svn
MemCpyOptimizer.h
Go to the documentation of this file.
1 //===- MemCpyOptimizer.h - memcpy optimization ------------------*- C++ -*-===//
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 // This pass performs various transformations related to eliminating memcpy
10 // calls, or transforming sets of stores into memset's.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
15 #define LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
16 
18 #include "llvm/IR/BasicBlock.h"
19 #include "llvm/IR/CallSite.h"
20 #include "llvm/IR/PassManager.h"
21 #include <cstdint>
22 #include <functional>
23 
24 namespace llvm {
25 
26 class AssumptionCache;
27 class CallInst;
28 class DominatorTree;
29 class Function;
30 class Instruction;
31 class MemCpyInst;
32 class MemMoveInst;
33 class MemoryDependenceResults;
34 class MemSetInst;
35 class StoreInst;
36 class TargetLibraryInfo;
37 class Value;
38 
39 class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
40  MemoryDependenceResults *MD = nullptr;
41  TargetLibraryInfo *TLI = nullptr;
42  std::function<AliasAnalysis &()> LookupAliasAnalysis;
43  std::function<AssumptionCache &()> LookupAssumptionCache;
44  std::function<DominatorTree &()> LookupDomTree;
45 
46 public:
47  MemCpyOptPass() = default;
48 
50 
51  // Glue for the old PM.
53  TargetLibraryInfo *TLI_,
54  std::function<AliasAnalysis &()> LookupAliasAnalysis_,
55  std::function<AssumptionCache &()> LookupAssumptionCache_,
56  std::function<DominatorTree &()> LookupDomTree_);
57 
58 private:
59  // Helper functions
60  bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
61  bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
62  bool processMemCpy(MemCpyInst *M);
63  bool processMemMove(MemMoveInst *M);
64  bool performCallSlotOptzn(Instruction *cpy, Value *cpyDst, Value *cpySrc,
65  uint64_t cpyLen, unsigned cpyAlign, CallInst *C);
66  bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
67  bool processMemSetMemCpyDependence(MemCpyInst *M, MemSetInst *MDep);
68  bool performMemCpyToMemSetOptzn(MemCpyInst *M, MemSetInst *MDep);
69  bool processByValArgument(CallSite CS, unsigned ArgNo);
70  Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
71  Value *ByteVal);
72 
73  bool iterateOnFunction(Function &F);
74 };
75 
76 } // end namespace llvm
77 
78 #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:23
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:372
An instruction for storing to memory.
Definition: Instructions.h:320
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
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_)
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:89
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM Value Representation.
Definition: Value.h:72
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.