File indexing completed on 2026-05-10 08:44:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
0015 #define LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
0016
0017 #include "llvm/IR/BasicBlock.h"
0018 #include "llvm/IR/PassManager.h"
0019
0020 namespace llvm {
0021
0022 class AAResults;
0023 class AllocaInst;
0024 class BatchAAResults;
0025 class AssumptionCache;
0026 class CallBase;
0027 class CallInst;
0028 class DominatorTree;
0029 class EarliestEscapeAnalysis;
0030 class Function;
0031 class Instruction;
0032 class LoadInst;
0033 class MemCpyInst;
0034 class MemMoveInst;
0035 class MemorySSA;
0036 class MemorySSAUpdater;
0037 class MemSetInst;
0038 class PostDominatorTree;
0039 class StoreInst;
0040 class TargetLibraryInfo;
0041 class TypeSize;
0042 class Value;
0043
0044 class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
0045 TargetLibraryInfo *TLI = nullptr;
0046 AAResults *AA = nullptr;
0047 AssumptionCache *AC = nullptr;
0048 DominatorTree *DT = nullptr;
0049 PostDominatorTree *PDT = nullptr;
0050 MemorySSA *MSSA = nullptr;
0051 MemorySSAUpdater *MSSAU = nullptr;
0052 EarliestEscapeAnalysis *EEA = nullptr;
0053
0054 public:
0055 MemCpyOptPass() = default;
0056
0057 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
0058
0059
0060 bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA,
0061 AssumptionCache *AC, DominatorTree *DT, PostDominatorTree *PDT,
0062 MemorySSA *MSSA);
0063
0064 private:
0065
0066 bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
0067 bool processStoreOfLoad(StoreInst *SI, LoadInst *LI, const DataLayout &DL,
0068 BasicBlock::iterator &BBI);
0069 bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
0070 bool processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI);
0071 bool processMemMove(MemMoveInst *M, BasicBlock::iterator &BBI);
0072 bool performCallSlotOptzn(Instruction *cpyLoad, Instruction *cpyStore,
0073 Value *cpyDst, Value *cpySrc, TypeSize cpyLen,
0074 Align cpyAlign, BatchAAResults &BAA,
0075 std::function<CallInst *()> GetC);
0076 bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep,
0077 BatchAAResults &BAA);
0078 bool processMemSetMemCpyDependence(MemCpyInst *MemCpy, MemSetInst *MemSet,
0079 BatchAAResults &BAA);
0080 bool performMemCpyToMemSetOptzn(MemCpyInst *MemCpy, MemSetInst *MemSet,
0081 BatchAAResults &BAA);
0082 bool processByValArgument(CallBase &CB, unsigned ArgNo);
0083 bool processImmutArgument(CallBase &CB, unsigned ArgNo);
0084 Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
0085 Value *ByteVal);
0086 bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
0087 bool performStackMoveOptzn(Instruction *Load, Instruction *Store,
0088 AllocaInst *DestAlloca, AllocaInst *SrcAlloca,
0089 TypeSize Size, BatchAAResults &BAA);
0090 bool isMemMoveMemSetDependency(MemMoveInst *M);
0091
0092 void eraseInstruction(Instruction *I);
0093 bool iterateOnFunction(Function &F);
0094 };
0095
0096 }
0097
0098 #endif