LLVM  6.0.0svn
Macros | Functions
PromoteMemoryToRegister.cpp File Reference
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/IteratedDominanceFrontier.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include <algorithm>
Include dependency graph for PromoteMemoryToRegister.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "mem2reg"
 

Functions

 STATISTIC (NumLocalPromoted, "Number of alloca's promoted within one block")
 
 STATISTIC (NumSingleStore, "Number of alloca's promoted with a single store")
 
 STATISTIC (NumDeadAlloca, "Number of dead alloca's removed")
 
 STATISTIC (NumPHIInsert, "Number of PHI nodes inserted")
 
static void addAssumeNonNull (AssumptionCache *AC, LoadInst *LI)
 Given a LoadInst LI this adds assume(LI != null) after it. More...
 
static void removeLifetimeIntrinsicUsers (AllocaInst *AI)
 
static bool rewriteSingleStoreAlloca (AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI, const DataLayout &DL, DominatorTree &DT, AssumptionCache *AC)
 Rewrite as many loads as possible given a single store. More...
 
static bool promoteSingleBlockAlloca (AllocaInst *AI, const AllocaInfo &Info, LargeBlockInfo &LBI, const DataLayout &DL, DominatorTree &DT, AssumptionCache *AC)
 Many allocas are only used within a single basic block. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "mem2reg"

Definition at line 45 of file PromoteMemoryToRegister.cpp.

Function Documentation

◆ addAssumeNonNull()

static void addAssumeNonNull ( AssumptionCache AC,
LoadInst LI 
)
static

◆ promoteSingleBlockAlloca()

static bool promoteSingleBlockAlloca ( AllocaInst AI,
const AllocaInfo &  Info,
LargeBlockInfo &  LBI,
const DataLayout DL,
DominatorTree DT,
AssumptionCache AC 
)
static

Many allocas are only used within a single basic block.

If this is the case, avoid traversing the CFG and inserting a lot of potentially useless PHI nodes by just performing a single linear pass over the basic block using the Alloca.

If we cannot promote this alloca (because it is read before it is written), return false. This is necessary in cases where, due to control flow, the alloca is undefined only on some control flow paths. e.g. code like this is correct in LLVM IR: // A is an alloca with no stores so far for (...) { int t = *A; if (!first_iteration) use(t); *A = 42; }

Definition at line 443 of file PromoteMemoryToRegister.cpp.

References addAssumeNonNull(), llvm::PHINode::addIncoming(), assert(), B, llvm::BasicBlock::back(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::BasicBlock::begin(), llvm::IDFCalculator< NodeTy, IsPostDom >::calculate(), llvm::ConvertDebugDeclareToDebugValue(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::count(), llvm::PHINode::Create(), llvm::coverage::CurrentVersion, llvm::dyn_cast(), E, llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), llvm::SmallVectorImpl< T >::erase(), llvm::Instruction::eraseFromParent(), F, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::BasicBlock::front(), llvm::Function::front(), llvm::UndefValue::get(), llvm::PHINode::getIncomingBlock(), llvm::BasicBlock::getInstList(), llvm::Instruction::getMetadata(), llvm::Instruction::getModule(), getName(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::Value::getType(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isAllocaPromotable(), llvm::isKnownNonZero(), llvm::lower_bound(), llvm::LLVMContext::MD_nonnull, P, llvm::pred_begin(), llvm::pred_end(), llvm::predecessors(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), removeLifetimeIntrinsicUsers(), llvm::Value::replaceAllUsesWith(), rewriteSingleStoreAlloca(), llvm::IDFCalculator< NodeTy, IsPostDom >::setDefiningBlocks(), llvm::IDFCalculator< NodeTy, IsPostDom >::setLiveInBlocks(), SI, llvm::SimplifyInstruction(), llvm::SmallVectorTemplateCommon< T >::size(), llvm::parallel::sort(), llvm::succ_begin(), llvm::succ_end(), llvm::Value::use_empty(), llvm::Instruction::user_back(), llvm::Value::user_begin(), llvm::Value::user_end(), llvm::Value::users(), and llvm::IndexedInstrProf::Version.

◆ removeLifetimeIntrinsicUsers()

static void removeLifetimeIntrinsicUsers ( AllocaInst AI)
static

◆ rewriteSingleStoreAlloca()

static bool rewriteSingleStoreAlloca ( AllocaInst AI,
AllocaInfo &  Info,
LargeBlockInfo &  LBI,
const DataLayout DL,
DominatorTree DT,
AssumptionCache AC 
)
static

Rewrite as many loads as possible given a single store.

When there is only a single store, we can use the domtree to trivially replace all of the dominated loads with the stored value. Do so, and return true if this has successfully promoted the alloca entirely. If this returns false there were some loads which were not dominated by the single store and thus must be phi-ed with undef. We fall back to the standard alloca promotion algorithm in that case.

Definition at line 340 of file PromoteMemoryToRegister.cpp.

References addAssumeNonNull(), assert(), llvm::ConvertDebugDeclareToDebugValue(), llvm::DominatorTree::dominates(), E, llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::Instruction::getMetadata(), llvm::Instruction::getModule(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::isKnownNonZero(), llvm::LLVMContext::MD_nonnull, llvm::Value::replaceAllUsesWith(), llvm::Value::user_begin(), and llvm::Value::user_end().

Referenced by promoteSingleBlockAlloca().

◆ STATISTIC() [1/4]

STATISTIC ( NumLocalPromoted  ,
"Number of alloca's promoted within one block"   
)

◆ STATISTIC() [2/4]

STATISTIC ( NumSingleStore  ,
"Number of alloca's promoted with a single store"   
)

◆ STATISTIC() [3/4]

STATISTIC ( NumDeadAlloca  ,
"Number of dead alloca's removed"   
)

◆ STATISTIC() [4/4]

STATISTIC ( NumPHIInsert  ,
"Number of PHI nodes inserted"   
)