Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit cf989e5

Browse files
committed
[PM] Port MemCpyOpt to the new PM.
The need for all these Lookup* functions is just because of calls to getAnalysis inside methods (i.e. not at the top level) of the runOnFunction method. They should be straightforward to clean up when the old PM is gone. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272615 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 364a6f6 commit cf989e5

File tree

8 files changed

+170
-59
lines changed

8 files changed

+170
-59
lines changed

include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void initializeMachineSchedulerPass(PassRegistry&);
219219
void initializeMachineSinkingPass(PassRegistry&);
220220
void initializeMachineTraceMetricsPass(PassRegistry&);
221221
void initializeMachineVerifierPassPass(PassRegistry&);
222-
void initializeMemCpyOptPass(PassRegistry&);
222+
void initializeMemCpyOptLegacyPassPass(PassRegistry&);
223223
void initializeMemDepPrinterPass(PassRegistry&);
224224
void initializeMemDerefPrinterPass(PassRegistry&);
225225
void initializeMemoryDependenceWrapperPassPass(PassRegistry&);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===---- MemCpyOptimizer.h - memcpy optimization ---------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This pass performs various transformations related to eliminating memcpy
11+
// calls, or transforming sets of stores into memset's.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
16+
#define LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H
17+
18+
#include "llvm/ADT/STLExtras.h"
19+
#include "llvm/Analysis/AliasAnalysis.h"
20+
#include "llvm/Analysis/AssumptionCache.h"
21+
#include "llvm/Analysis/GlobalsModRef.h"
22+
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
23+
#include "llvm/Analysis/TargetLibraryInfo.h"
24+
#include "llvm/IR/Dominators.h"
25+
#include "llvm/IR/Function.h"
26+
#include "llvm/IR/Instructions.h"
27+
#include "llvm/IR/IntrinsicInst.h"
28+
#include "llvm/IR/PassManager.h"
29+
30+
namespace llvm {
31+
32+
class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
33+
MemoryDependenceResults *MD = nullptr;
34+
TargetLibraryInfo *TLI = nullptr;
35+
std::function<AliasAnalysis &()> LookupAliasAnalysis;
36+
std::function<AssumptionCache &()> LookupAssumptionCache;
37+
std::function<DominatorTree &()> LookupDomTree;
38+
39+
public:
40+
MemCpyOptPass() {}
41+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
42+
// Glue for the old PM.
43+
bool runImpl(Function &F, MemoryDependenceResults *MD_,
44+
TargetLibraryInfo *TLI_,
45+
std::function<AliasAnalysis &()> LookupAliasAnalysis_,
46+
std::function<AssumptionCache &()> LookupAssumptionCache_,
47+
std::function<DominatorTree &()> LookupDomTree_);
48+
49+
private:
50+
// Helper functions
51+
bool processStore(StoreInst *SI, BasicBlock::iterator &BBI);
52+
bool processMemSet(MemSetInst *SI, BasicBlock::iterator &BBI);
53+
bool processMemCpy(MemCpyInst *M);
54+
bool processMemMove(MemMoveInst *M);
55+
bool performCallSlotOptzn(Instruction *cpy, Value *cpyDst, Value *cpySrc,
56+
uint64_t cpyLen, unsigned cpyAlign, CallInst *C);
57+
bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
58+
bool processMemSetMemCpyDependence(MemCpyInst *M, MemSetInst *MDep);
59+
bool performMemCpyToMemSetOptzn(MemCpyInst *M, MemSetInst *MDep);
60+
bool processByValArgument(CallSite CS, unsigned ArgNo);
61+
Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
62+
Value *ByteVal);
63+
64+
bool iterateOnFunction(Function &F);
65+
};
66+
}
67+
68+
#endif // LLVM_TRANSFORMS_SCALAR_MEMCPYOPTIMIZER_H

lib/LTO/LTOCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void LTOCodeGenerator::initializeLTOPasses() {
127127
initializeLICMPass(R);
128128
initializeMergedLoadStoreMotionLegacyPassPass(R);
129129
initializeGVNLegacyPassPass(R);
130-
initializeMemCpyOptPass(R);
130+
initializeMemCpyOptLegacyPassPass(R);
131131
initializeDCELegacyPassPass(R);
132132
initializeCFGSimplifyPassPass(R);
133133
}

lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
8181
#include "llvm/Transforms/Scalar/LowerAtomic.h"
8282
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
83+
#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
8384
#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
8485
#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
8586
#include "llvm/Transforms/Scalar/Reassociate.h"

lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ FUNCTION_PASS("loweratomic", LowerAtomicPass())
129129
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
130130
FUNCTION_PASS("guard-widening", GuardWideningPass())
131131
FUNCTION_PASS("gvn", GVN())
132+
FUNCTION_PASS("memcpyopt", MemCpyOptPass())
132133
FUNCTION_PASS("mldst-motion", MergedLoadStoreMotionPass())
133134
FUNCTION_PASS("jump-threading", JumpThreadingPass())
134135
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())

0 commit comments

Comments
 (0)