LLVM  8.0.0svn
Macros | Functions | Variables
MemCpyOptimizer.cpp File Reference
#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <utility>
Include dependency graph for MemCpyOptimizer.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "memcpyopt"
 

Functions

 STATISTIC (NumMemCpyInstr, "Number of memcpy instructions deleted")
 
 STATISTIC (NumMemSetInfer, "Number of memsets inferred")
 
 STATISTIC (NumMoveToCpy, "Number of memmoves converted to memcpy")
 
 STATISTIC (NumCpyToSet, "Number of memcpys converted to memset")
 
static int64_t GetOffsetFromIndex (const GEPOperator *GEP, unsigned Idx, bool &VariableIdxFound, const DataLayout &DL)
 
static bool IsPointerOffset (Value *Ptr1, Value *Ptr2, int64_t &Offset, const DataLayout &DL)
 Return true if Ptr1 is provably equal to Ptr2 plus a constant offset, and return that constant offset. More...
 
 INITIALIZE_PASS_BEGIN (MemCpyOptLegacyPass, "memcpyopt", "MemCpy Optimization", false, false) INITIALIZE_PASS_END(MemCpyOptLegacyPass
 
static unsigned findStoreAlignment (const DataLayout &DL, const StoreInst *SI)
 
static unsigned findLoadAlignment (const DataLayout &DL, const LoadInst *LI)
 
static unsigned findCommonAlignment (const DataLayout &DL, const StoreInst *SI, const LoadInst *LI)
 
static bool moveUp (AliasAnalysis &AA, StoreInst *SI, Instruction *P, const LoadInst *LI)
 

Variables

 memcpyopt
 
MemCpy Optimization
 
MemCpy false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "memcpyopt"

Definition at line 66 of file MemCpyOptimizer.cpp.

Function Documentation

◆ findCommonAlignment()

static unsigned findCommonAlignment ( const DataLayout DL,
const StoreInst SI,
const LoadInst LI 
)
static

Definition at line 518 of file MemCpyOptimizer.cpp.

References findLoadAlignment(), findStoreAlignment(), and llvm::MinAlign().

Referenced by moveUp().

◆ findLoadAlignment()

static unsigned findLoadAlignment ( const DataLayout DL,
const LoadInst LI 
)
static

◆ findStoreAlignment()

static unsigned findStoreAlignment ( const DataLayout DL,
const StoreInst SI 
)
static

◆ GetOffsetFromIndex()

static int64_t GetOffsetFromIndex ( const GEPOperator GEP,
unsigned  Idx,
bool VariableIdxFound,
const DataLayout DL 
)
static

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( MemCpyOptLegacyPass  ,
"memcpyopt"  ,
"MemCpy Optimization ,
false  ,
false   
)

◆ IsPointerOffset()

static bool IsPointerOffset ( Value Ptr1,
Value Ptr2,
int64_t &  Offset,
const DataLayout DL 
)
static

Return true if Ptr1 is provably equal to Ptr2 plus a constant offset, and return that constant offset.

For example, Ptr1 might be &A[42], and Ptr2 might be &A[40]. In this case offset would be -8.

Definition at line 107 of file MemCpyOptimizer.cpp.

References llvm::dyn_cast(), llvm::User::getNumOperands(), GetOffsetFromIndex(), llvm::User::getOperand(), and llvm::Value::stripPointerCasts().

◆ moveUp()

static bool moveUp ( AliasAnalysis AA,
StoreInst SI,
Instruction P,
const LoadInst LI 
)
static

Definition at line 529 of file MemCpyOptimizer.cpp.

References llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Align, llvm::any_of(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_size(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, assert(), C, llvm::AAResults::callCapturesBefore(), llvm::combineMetadata(), llvm::IRBuilder< T, Inserter >::CreateGEP(), llvm::IRBuilder< T, Inserter >::CreateICmpULE(), llvm::IRBuilderBase::CreateMemCpy(), llvm::IRBuilderBase::CreateMemMove(), llvm::IRBuilderBase::CreateMemSet(), llvm::CastInst::CreatePointerCast(), llvm::IRBuilder< T, Inserter >::CreateSelect(), llvm::IRBuilder< T, Inserter >::CreateSub(), llvm::IRBuilder< T, Inserter >::CreateZExt(), llvm::dbgs(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::doesNotCapture(), llvm::DominatorTree::dominates(), llvm::dyn_cast(), E, llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::erase(), llvm::Instruction::eraseFromParent(), F(), findCommonAlignment(), findLoadAlignment(), findStoreAlignment(), G, llvm::MemoryLocation::get(), llvm::DataLayout::getABITypeAlignment(), llvm::AllocaInst::getAlignment(), llvm::StoreInst::getAlignment(), llvm::AllocaInst::getAllocatedType(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getArgument(), llvm::AllocaInst::getArraySize(), llvm::CallBase< InstTy >::getCalledFunction(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCaller(), llvm::Module::getDataLayout(), llvm::Intrinsic::getDeclaration(), llvm::MemIntrinsicBase< Derived >::getDest(), llvm::MemIntrinsicBase< Derived >::getDestAlignment(), llvm::MemoryLocation::getForDest(), llvm::MemoryLocation::getForSource(), llvm::MemDepResult::getInst(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::Type::getIntegerBitWidth(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::MemIntrinsicBase< Derived >::getLength(), llvm::Instruction::getMetadata(), llvm::AAResults::getModRefInfo(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::CallBase< InstTy >::getNumOperands(), llvm::User::getOperand(), llvm::CallBase< InstTy >::getOperand(), llvm::getOrEnforceKnownAlignment(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getParamAlignment(), llvm::Instruction::getParent(), llvm::GlobalValue::getParent(), llvm::Type::getPointerAddressSpace(), llvm::StoreInst::getPointerOperand(), llvm::MemIntrinsicBase< Derived >::getRawDest(), llvm::MemTransferBase< BaseCL >::getRawSource(), llvm::MemTransferBase< BaseCL >::getSource(), llvm::MemTransferBase< BaseCL >::getSourceAlignment(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeStoreSize(), llvm::ConstantInt::getValue(), llvm::MemSetBase< BaseCL >::getValue(), llvm::ConstantInt::getZExtValue(), llvm::APInt::getZExtValue(), I, llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::insert(), llvm::isBytewiseValue(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::isByValArgument(), llvm::MemDepResult::isClobber(), llvm::MemDepResult::isDef(), llvm::isModOrRefSet(), llvm::isModSet(), llvm::AAResults::isMustAlias(), llvm::AAResults::isNoAlias(), llvm::DominatorTree::isReachableFromEntry(), llvm::StoreInst::isSimple(), llvm::Type::isSized(), llvm::StoreInst::isVolatile(), llvm::MemIntrinsic::isVolatile(), IT, LLVM_DEBUG, llvm::make_range(), llvm::max(), llvm::MayAlias, llvm::Instruction::mayThrow(), llvm::LLVMContext::MD_alias_scope, llvm::LLVMContext::MD_invariant_group, llvm::LLVMContext::MD_noalias, llvm::LLVMContext::MD_nontemporal, llvm::LLVMContext::MD_tbaa, llvm::MinAlign(), llvm::None, P, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::reverse(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setArgument(), llvm::CallBase< InstTy >::setCalledFunction(), SI, Size, llvm::Value::stripPointerCasts(), llvm::Value::user_begin(), llvm::Value::user_end(), and llvm::Value::users().

◆ STATISTIC() [1/4]

STATISTIC ( NumMemCpyInstr  ,
"Number of memcpy instructions deleted"   
)

◆ STATISTIC() [2/4]

STATISTIC ( NumMemSetInfer  ,
"Number of memsets inferred"   
)

◆ STATISTIC() [3/4]

STATISTIC ( NumMoveToCpy  ,
"Number of memmoves converted to memcpy"   
)

◆ STATISTIC() [4/4]

STATISTIC ( NumCpyToSet  ,
"Number of memcpys converted to memset"   
)

Variable Documentation

◆ false

MemCpy false

Definition at line 382 of file MemCpyOptimizer.cpp.

◆ memcpyopt

memcpyopt

Definition at line 382 of file MemCpyOptimizer.cpp.

◆ Optimization

MemCpy Optimization

Definition at line 382 of file MemCpyOptimizer.cpp.