mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-29 15:04:57 +00:00
enhance memcpyopt to obey -fno-builtin and friends. This addresses a
problem reported on cfe-dev. llvm-svn: 130661
This commit is contained in:
parent
d49e7769a7
commit
c04013dd48
@ -23,6 +23,9 @@ namespace llvm {
|
||||
// void *memcpy(void *s1, const void *s2, size_t n);
|
||||
memcpy,
|
||||
|
||||
// void *memmove(void *s1, const void *s2, size_t n);
|
||||
memmove,
|
||||
|
||||
/// void memset_pattern16(void *b, const void *pattern16, size_t len);
|
||||
memset_pattern16,
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "llvm/Support/IRBuilder.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Target/TargetLibraryInfo.h"
|
||||
#include <list>
|
||||
using namespace llvm;
|
||||
|
||||
@ -299,12 +300,15 @@ void MemsetRanges::addRange(int64_t Start, int64_t Size, Value *Ptr,
|
||||
namespace {
|
||||
class MemCpyOpt : public FunctionPass {
|
||||
MemoryDependenceAnalysis *MD;
|
||||
TargetLibraryInfo *TLI;
|
||||
const TargetData *TD;
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
MemCpyOpt() : FunctionPass(ID) {
|
||||
initializeMemCpyOptPass(*PassRegistry::getPassRegistry());
|
||||
MD = 0;
|
||||
TLI = 0;
|
||||
TD = 0;
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F);
|
||||
@ -316,6 +320,7 @@ namespace {
|
||||
AU.addRequired<DominatorTree>();
|
||||
AU.addRequired<MemoryDependenceAnalysis>();
|
||||
AU.addRequired<AliasAnalysis>();
|
||||
AU.addRequired<TargetLibraryInfo>();
|
||||
AU.addPreserved<AliasAnalysis>();
|
||||
AU.addPreserved<MemoryDependenceAnalysis>();
|
||||
}
|
||||
@ -346,6 +351,7 @@ INITIALIZE_PASS_BEGIN(MemCpyOpt, "memcpyopt", "MemCpy Optimization",
|
||||
false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
|
||||
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceAnalysis)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)
|
||||
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
||||
INITIALIZE_PASS_END(MemCpyOpt, "memcpyopt", "MemCpy Optimization",
|
||||
false, false)
|
||||
@ -804,6 +810,9 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
|
||||
bool MemCpyOpt::processMemMove(MemMoveInst *M) {
|
||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||
|
||||
if (!TLI->has(LibFunc::memmove))
|
||||
return false;
|
||||
|
||||
// See if the pointers alias.
|
||||
if (!AA.isNoAlias(AA.getLocationForDest(M), AA.getLocationForSource(M)))
|
||||
return false;
|
||||
@ -935,6 +944,14 @@ bool MemCpyOpt::runOnFunction(Function &F) {
|
||||
bool MadeChange = false;
|
||||
MD = &getAnalysis<MemoryDependenceAnalysis>();
|
||||
TD = getAnalysisIfAvailable<TargetData>();
|
||||
TLI = &getAnalysis<TargetLibraryInfo>();
|
||||
|
||||
// If we don't have at least memset and memcpy, there is little point of doing
|
||||
// anything here. These are required by a freestanding implementation, so if
|
||||
// even they are disabled, there is no point in trying hard.
|
||||
if (!TLI->has(LibFunc::memset) || !TLI->has(LibFunc::memcpy))
|
||||
return false;
|
||||
|
||||
while (1) {
|
||||
if (!iterateOnFunction(F))
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user