LLVM 23.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"
20
21namespace llvm {
22
23class AAResults;
24class AllocaInst;
25class BatchAAResults;
26class AssumptionCache;
27class CallBase;
28class CallInst;
29class DominatorTree;
31class Function;
32class Instruction;
33class LoadInst;
34class MemCpyInst;
35class MemMoveInst;
36class MemorySSA;
38class MemSetInst;
40class StoreInst;
42class TypeSize;
43class Value;
44
45class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
46 TargetLibraryInfo *TLI = nullptr;
47 AAResults *AA = nullptr;
48 AssumptionCache *AC = nullptr;
49 DominatorTree *DT = nullptr;
50 PostDominatorTree *PDT = nullptr;
51 MemorySSA *MSSA = nullptr;
52 MemorySSAUpdater *MSSAU = nullptr;
53 EarliestEscapeAnalysis *EEA = nullptr;
54
55public:
56 MemCpyOptPass() = default;
57
59
60 // Glue for the old PM.
63 PostDominatorTree *PDT, MemorySSA *MSSA);
64
65private:
66 // Helper functions
67 bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
68 bool processStoreOfLoad(StoreInst *SI, LoadInst *LI, const DataLayout &DL,
70 bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
71 bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
72 bool processMemMove(MemMoveInst *M, BasicBlock::iterator &BBI);
73 bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
74 Value *cpyDst, Value *cpySrc, TypeSize cpyLen,
75 Align cpyAlign, BatchAAResults &BAA,
76 std::function<CallInst *()> GetC);
77 bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep,
78 BatchAAResults &BAA);
79 bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet,
80 BatchAAResults &BAA);
81 bool performMemCpyToMemSetOptzn(MemCpyInst *MemCpy, MemSetInst *MemSet,
82 BatchAAResults &BAA);
83 bool processByValArgument(CallBase &CB, unsigned ArgNo);
84 bool processImmutArgument(CallBase &CB, unsigned ArgNo);
85 Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
86 Value *ByteVal);
87 bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
88 bool performStackMoveOptzn(Instruction *Load, Instruction *Store,
89 Value *DestPtr, Value *SrcPtr, TypeSize Size,
90 BatchAAResults &BAA);
91 bool isMemMoveMemSetDependency(MemMoveInst *M);
92
93 void eraseInstruction(Instruction *I);
94 bool iterateOnFunction(Function &F);
95};
96
97} // end namespace llvm
98
99#endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:213
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
an instruction to allocate memory on the stack
A cache of @llvm.assume calls within a function.
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
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...
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:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:164
Context-sensitive CaptureAnalysis provider, which computes and caches the earliest common dominator c...
An instruction for reading from memory.
This class wraps the llvm.memcpy intrinsic.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI 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:702
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:112
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
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:70