LLVM API Documentation
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#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/InstructionSimplify.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/Transforms/Utils/Local.h"
#include <algorithm>
#include <queue>
Go to the source code of this file.
Defines | |
#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 | removeLifetimeIntrinsicUsers (AllocaInst *AI) |
static bool | rewriteSingleStoreAlloca (AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI, DominatorTree &DT, AliasSetTracker *AST) |
Rewrite as many loads as possible given a single store. | |
static void | promoteSingleBlockAlloca (AllocaInst *AI, const AllocaInfo &Info, LargeBlockInfo &LBI, AliasSetTracker *AST) |
#define DEBUG_TYPE "mem2reg" |
Definition at line 53 of file PromoteMemoryToRegister.cpp.
static void promoteSingleBlockAlloca | ( | AllocaInst * | AI, |
const AllocaInfo & | Info, | ||
LargeBlockInfo & | LBI, | ||
AliasSetTracker * | AST | ||
) | [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 true. This is necessary in cases where, due to control flow, the alloca is potentially undefined on some control flow paths. e.g. code like this is potentially correct:
for (...) { if (c) { A = undef; undef = B; } }
... so long as A is not used before undef is set.
Definition at line 447 of file PromoteMemoryToRegister.cpp.
References llvm::ConvertDebugDeclareToDebugValue(), llvm::AliasSetTracker::deleteValue(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Value::getType(), llvm::Type::isPointerTy(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::Value::use_empty(), llvm::Instruction::user_back(), llvm::Value::user_begin(), llvm::Value::user_end(), and llvm::Value::users().
static void removeLifetimeIntrinsicUsers | ( | AllocaInst * | AI | ) | [static] |
Definition at line 318 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 bool rewriteSingleStoreAlloca | ( | AllocaInst * | AI, |
AllocaInfo & | Info, | ||
LargeBlockInfo & | LBI, | ||
DominatorTree & | DT, | ||
AliasSetTracker * | AST | ||
) | [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 350 of file PromoteMemoryToRegister.cpp.
References llvm::ConvertDebugDeclareToDebugValue(), llvm::AliasSetTracker::deleteValue(), llvm::DominatorTree::dominates(), llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Value::getType(), llvm::Type::isPointerTy(), 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" | |||
) |