|
LLVM
5.0.0
|
#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>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, 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, DominatorTree &DT, AssumptionCache *AC) |
| Many allocas are only used within a single basic block. More... | |
| #define DEBUG_TYPE "mem2reg" |
Definition at line 45 of file PromoteMemoryToRegister.cpp.
|
static |
Given a LoadInst LI this adds assume(LI != null) after it.
Definition at line 304 of file PromoteMemoryToRegister.cpp.
References 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(), and rewriteSingleStoreAlloca().
|
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 450 of file PromoteMemoryToRegister.cpp.
References addAssumeNonNull(), llvm::ConvertDebugDeclareToDebugValue(), llvm::dyn_cast(), E, llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::Instruction::getMetadata(), llvm::Instruction::getModule(), llvm::Value::getType(), llvm::isKnownNonNullAt(), llvm::LLVMContext::MD_nonnull, llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::Value::replaceAllUsesWith(), SI, llvm::parallel::sort(), llvm::Value::use_empty(), llvm::Instruction::user_back(), llvm::Value::user_begin(), llvm::Value::user_end(), and llvm::Value::users().
|
static |
Definition at line 315 of file PromoteMemoryToRegister.cpp.
References llvm::Instruction::eraseFromParent(), llvm::Value::getType(), I, llvm::Type::isVoidTy(), llvm::Value::user_begin(), and llvm::Value::user_end().
|
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 347 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::isKnownNonNullAt(), llvm::LLVMContext::MD_nonnull, llvm::Value::replaceAllUsesWith(), llvm::Value::user_begin(), and llvm::Value::user_end().
| 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" | |||
| ) |
1.8.6