LLVM 20.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
20namespace llvm {
21
22class AAResults;
23class AllocaInst;
24class BatchAAResults;
25class AssumptionCache;
26class CallBase;
27class CallInst;
28class DominatorTree;
29class EarliestEscapeAnalysis;
30class Function;
31class Instruction;
32class LoadInst;
33class MemCpyInst;
34class MemMoveInst;
35class MemorySSA;
36class MemorySSAUpdater;
37class MemSetInst;
38class PostDominatorTree;
39class StoreInst;
40class TargetLibraryInfo;
41class TypeSize;
42class Value;
43
44class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
45 TargetLibraryInfo *TLI = nullptr;
46 AAResults *AA = nullptr;
47 AssumptionCache *AC = nullptr;
48 DominatorTree *DT = nullptr;
49 PostDominatorTree *PDT = nullptr;
50 MemorySSA *MSSA = nullptr;
51 MemorySSAUpdater *MSSAU = nullptr;
52 EarliestEscapeAnalysis *EEA = nullptr;
53
54public:
55 MemCpyOptPass() = default;
56
58
59 // Glue for the old PM.
62 MemorySSA *MSSA);
63
64private:
65 // Helper functions
66 bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
67 bool processStoreOfLoad(StoreInst *SI, LoadInst *LI, const DataLayout &DL,
69 bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
70 bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
71 bool processMemMove(MemMoveInst *M, BasicBlock::iterator &BBI);
72 bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
73 Value *cpyDst, Value *cpySrc, TypeSize cpyLen,
74 Align cpyAlign, BatchAAResults &BAA,
75 std::function<CallInst *()> GetC);
76 bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep,
77 BatchAAResults &BAA);
78 bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet,
79 BatchAAResults &BAA);
80 bool performMemCpyToMemSetOptzn(MemCpyInst *MemCpy, MemSetInst *MemSet,
81 BatchAAResults &BAA);
82 bool processByValArgument(CallBase &CB, unsigned ArgNo);
83 bool processImmutArgument(CallBase &CB, unsigned ArgNo);
84 Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
85 Value *ByteVal);
86 bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
87 bool performStackMoveOptzn(Instruction *Load, Instruction *Store,
88 AllocaInst *DestAlloca, AllocaInst *SrcAlloca,
90 bool isMemMoveMemSetDependency(MemMoveInst *M);
91
92 void eraseInstruction(Instruction *I);
93 bool iterateOnFunction(Function &F);
94};
95
96} // end namespace llvm
97
98#endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
uint64_t Size
early cse Early CSE w MemorySSA
Definition: EarlyCSE.cpp:1960
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
an instruction to allocate memory on the stack
Definition: Instructions.h:63
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
A cache of @llvm.assume calls within a function.
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:177
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1120
This class represents a function call, abstracting a target machine's calling convention.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
Context-sensitive CaptureAnalysis provider, which computes and caches the earliest common dominator c...
An instruction for reading from memory.
Definition: Instructions.h:176
This class wraps the llvm.memcpy intrinsic.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA, AssumptionCache *AC, DominatorTree *DT, PostDominatorTree *PDT, MemorySSA *MSSA)
MemCpyOptPass()=default
This class wraps the llvm.memmove intrinsic.
This class wraps the llvm.memset and llvm.memset.inline intrinsics.
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition: MemorySSA.h:701
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
An instruction for storing to memory.
Definition: Instructions.h:292
Provides information about what library functions are available for the current target.
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69