LLVM  15.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 
20 namespace llvm {
21 
22 class AAResults;
23 class AssumptionCache;
24 class CallBase;
25 class CallInst;
26 class DominatorTree;
27 class Function;
28 class Instruction;
29 class LoadInst;
30 class MemCpyInst;
31 class MemMoveInst;
32 class MemorySSA;
33 class MemorySSAUpdater;
34 class MemSetInst;
35 class StoreInst;
36 class TargetLibraryInfo;
37 class Value;
38 
39 class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
40  TargetLibraryInfo *TLI = nullptr;
41  AAResults *AA = nullptr;
42  AssumptionCache *AC = nullptr;
43  DominatorTree *DT = nullptr;
44  MemorySSA *MSSA = nullptr;
45  MemorySSAUpdater *MSSAU = nullptr;
46 
47 public:
48  MemCpyOptPass() = default;
49 
51 
52  // Glue for the old PM.
54  AssumptionCache *AC, DominatorTree *DT, MemorySSA *MSSA);
55 
56 private:
57  // Helper functions
58  bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
59  bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
60  bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
61  bool processMemMove(MemMoveInst *M);
62  bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
63  Value *cpyDst, Value *cpySrc, TypeSize cpyLen,
64  Align cpyAlign, std::function<CallInst *()> GetC);
65  bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
66  bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet);
67  bool performMemCpyToMemSetOptzn(MemCpyInst *MemCpy, MemSetInst *MemSet);
68  bool processByValArgument(CallBase &CB, unsigned ArgNo);
69  Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
70  Value *ByteVal);
71  bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
72 
73  void eraseInstruction(Instruction *I);
74  bool iterateOnFunction(Function &F);
75 };
76 
77 } // end namespace llvm
78 
79 #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:152
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
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:87
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:371
llvm::Function
Definition: Function.h:60
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:1054
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
llvm::MemCpyOptPass::runImpl
bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA, AssumptionCache *AC, DominatorTree *DT, MemorySSA *MSSA)
Definition: MemCpyOptimizer.cpp:1662
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::AAResults
Definition: AliasAnalysis.h:511
llvm::Instruction
Definition: Instruction.h:42
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 and llvm.memset.inline intrinsics.
Definition: IntrinsicInst.h:989
BasicBlock.h
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:297
llvm::MemorySSAUpdater
Definition: MemorySSAUpdater.h:54
llvm::MemorySSA
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition: MemorySSA.h:714
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::MemCpyOptPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: MemCpyOptimizer.cpp:1645
SI
StandardInstrumentations SI(Debug, VerifyEach)
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::MemCpyOptPass::MemCpyOptPass
MemCpyOptPass()=default
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:42
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:173
llvm::TypeSize
Definition: TypeSize.h:435
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:222
llvm::MemCpyOptPass
Definition: MemCpyOptimizer.h:39
AA
llvm::MemCpyInst
This class wraps the llvm.memcpy intrinsic.
Definition: IntrinsicInst.h:1041
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1174
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1461
MemorySSA
early cse Early CSE w MemorySSA
Definition: EarlyCSE.cpp:1775
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::codeview::PublicSymFlags::Function
@ Function