LLVM
8.0.1
|
#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/ADT/TinyPtrVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/IteratedDominanceFrontier.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.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/Type.h"
#include "llvm/IR/User.h"
#include "llvm/Support/Casting.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <utility>
#include <vector>
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... | |
static void | updateForIncomingValueLocation (PHINode *PN, DebugLoc DL, bool ApplyMergedLoc) |
Update the debug location of a phi. More... | |
#define DEBUG_TYPE "mem2reg" |
Definition at line 58 of file PromoteMemoryToRegister.cpp.
|
static |
Given a LoadInst LI this adds assume(LI != null) after it.
Definition at line 314 of file PromoteMemoryToRegister.cpp.
References llvm::Intrinsic::assume, llvm::CallInst::Create(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getModule(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::CmpInst::ICMP_NE, llvm::Instruction::insertAfter(), and llvm::AssumptionCache::registerAssumption().
Referenced by promoteSingleBlockAlloca(), rewriteSingleStoreAlloca(), and updateForIncomingValueLocation().
|
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 459 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(), ComputeLiveInBlocks(), llvm::ConvertDebugDeclareToDebugValue(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::PHINode::Create(), llvm::coverage::CurrentVersion, llvm::dyn_cast(), E, llvm::SmallVectorTemplateCommon< T >::end(), llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), llvm::SmallVectorImpl< T >::erase(), llvm::Instruction::eraseFromParent(), F, llvm::BasicBlock::front(), llvm::Function::front(), llvm::UndefValue::get(), llvm::PHINode::getIncomingBlock(), llvm::Instruction::getMetadata(), llvm::Instruction::getModule(), getName(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::Value::getType(), I, Info, 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, bool >::push_back(), removeLifetimeIntrinsicUsers(), llvm::Value::replaceAllUsesWith(), rewriteSingleStoreAlloca(), llvm::IDFCalculator< NodeTy, IsPostDom >::setDefiningBlocks(), llvm::IDFCalculator< NodeTy, IsPostDom >::setLiveInBlocks(), SI, llvm::SimplifyInstruction(), llvm::SmallVectorBase::size(), llvm::sort(), llvm::Value::use_empty(), llvm::Instruction::user_back(), llvm::Value::user_begin(), llvm::Value::user_end(), llvm::Value::users(), and llvm::IndexedInstrProf::Version.
|
static |
Definition at line 325 of file PromoteMemoryToRegister.cpp.
References llvm::Instruction::eraseFromParent(), llvm::Value::getType(), I, llvm::Type::isVoidTy(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by promoteSingleBlockAlloca().
|
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 357 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 | ( | 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 |
Update the debug location of a phi.
ApplyMergedLoc
indicates whether to create a merged location incorporating DL
, or to set DL
directly.
Definition at line 887 of file PromoteMemoryToRegister.cpp.
References addAssumeNonNull(), llvm::Instruction::applyMergedLocation(), assert(), llvm::BasicBlock::begin(), llvm::ConvertDebugDeclareToDebugValue(), llvm::count(), llvm::dyn_cast(), E, llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::Instruction::getDebugLoc(), llvm::BasicBlock::getInstList(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isKnownNonZero(), llvm::LLVMContext::MD_nonnull, llvm::Instruction::setDebugLoc(), SI, llvm::succ_begin(), and llvm::succ_end().