1 //===- MemCpyOptimizer.h - memcpy optimization ------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This pass performs various transformations related to eliminating memcpy
10 // calls, or transforming sets of stores into memset's.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
15 #define LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/IR/BasicBlock.h"
19 #include "llvm/IR/CallSite.h"
20 #include "llvm/IR/PassManager.h"
26 class AssumptionCache
;
33 class MemoryDependenceResults
;
36 class TargetLibraryInfo
;
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
;
47 MemCpyOptPass() = default;
49 PreservedAnalyses
run(Function
&F
, FunctionAnalysisManager
&AM
);
51 // Glue for the old PM.
52 bool runImpl(Function
&F
, MemoryDependenceResults
*MD_
,
53 TargetLibraryInfo
*TLI_
,
54 std::function
<AliasAnalysis
&()> LookupAliasAnalysis_
,
55 std::function
<AssumptionCache
&()> LookupAssumptionCache_
,
56 std::function
<DominatorTree
&()> LookupDomTree_
);
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
,
73 bool iterateOnFunction(Function
&F
);
76 } // end namespace llvm
78 #endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H