LLVM  13.0.0git
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 
17 #include "llvm/IR/BasicBlock.h"
18 #include "llvm/IR/PassManager.h"
19 #include <cstdint>
20 #include <functional>
21 
22 namespace llvm {
23 
24 class AAResults;
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 MemoryDependenceResults;
35 class MemorySSA;
36 class MemorySSAUpdater;
37 class MemSetInst;
38 class StoreInst;
39 class TargetLibraryInfo;
40 class Value;
41 
42 class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
43  MemoryDependenceResults *MD = nullptr;
44  TargetLibraryInfo *TLI = nullptr;
45  AAResults *AA = nullptr;
46  AssumptionCache *AC = nullptr;
47  DominatorTree *DT = nullptr;
48  MemorySSA *MSSA = nullptr;
49  MemorySSAUpdater *MSSAU = nullptr;
50 
51 public:
52  MemCpyOptPass() = default;
53 
55 
56  // Glue for the old PM.
59  MemorySSA *MSSA);
60 
61 private:
62  // Helper functions
63  bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
64  bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
65  bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
66  bool processMemMove(MemMoveInst *M);
67  bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
68  Value *cpyDst, Value *cpySrc, uint64_t cpyLen,
69  Align cpyAlign, CallInst *C);
70  bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
71  bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet);
72  bool performMemCpyToMemSetOptzn(MemCpyInst *MemCpy, MemSetInst *MemSet);
73  bool processByValArgument(CallBase &CB, unsigned ArgNo);
74  Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
75  Value *ByteVal);
76  bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
77 
78  void eraseInstruction(Instruction *I);
79  bool iterateOnFunction(Function &F);
80 };
81 
82 } // end namespace llvm
83 
84 #endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::BasicBlock::iterator
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:90
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:374
llvm::Function
Definition: Function.h:61
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::MemMoveInst
This class wraps the llvm.memmove intrinsic.
Definition: IntrinsicInst.h:902
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::AAResults
Definition: AliasAnalysis.h:456
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
SI
@ SI
Definition: SIInstrInfo.cpp:7463
llvm::Instruction
Definition: Instruction.h:45
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MemSetInst
This class wraps the llvm.memset intrinsic.
Definition: IntrinsicInst.h:859
BasicBlock.h
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:303
llvm::MemorySSAUpdater
Definition: MemorySSAUpdater.h:56
llvm::MemorySSA
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition: MemorySSA.h:704
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MemCpyOptPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: MemCpyOptimizer.cpp:1710
llvm::MemCpyOptPass::MemCpyOptPass
MemCpyOptPass()=default
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:174
llvm::MemCpyOptPass::runImpl
bool runImpl(Function &F, MemoryDependenceResults *MD, TargetLibraryInfo *TLI, AAResults *AA, AssumptionCache *AC, DominatorTree *DT, MemorySSA *MSSA)
Definition: MemCpyOptimizer.cpp:1735
llvm::MemoryDependenceResults
Provides a lazy, caching interface for making common memory aliasing information queries,...
Definition: MemoryDependenceAnalysis.h:276
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
PassManager.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:207
llvm::MemCpyOptPass
Definition: MemCpyOptimizer.h:42
llvm::MemCpyInst
This class wraps the llvm.memcpy intrinsic.
Definition: IntrinsicInst.h:890
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1164
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1450
MemorySSA
early cse Early CSE w MemorySSA
Definition: EarlyCSE.cpp:1715
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::codeview::PublicSymFlags::Function
@ Function