#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h"
#include <algorithm>
return false; // Don't allow a store OF the AI, only INTO the AI.
if (SI->isVolatile())
return false;
+ } else if (const BitCastInst *BC = dyn_cast<BitCastInst>(*UI)) {
+ // Uses by dbg info shouldn't inhibit promotion.
+ if (!BC->hasOneUse() || !isa<DbgInfoIntrinsic>(*BC->use_begin()))
+ return false;
} else {
- return false; // Not a load or store.
+ return false;
}
return true;
/// ivars.
void AnalyzeAlloca(AllocaInst *AI) {
clear();
-
+
// As we scan the uses of the alloca instruction, keep track of stores,
// and decide whether all of the loads and stores to the alloca are within
// the same basic block.
for (Value::use_iterator U = AI->use_begin(), E = AI->use_end();
- U != E; ++U) {
+ U != E;) {
Instruction *User = cast<Instruction>(*U);
- if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
+ ++U;
+ if (BitCastInst *BC = dyn_cast<BitCastInst>(User)) {
+ // Remove any uses of this alloca in DbgInfoInstrinsics.
+ assert(BC->hasOneUse() && "Unexpected alloca uses!");
+ DbgInfoIntrinsic *DI = cast<DbgInfoIntrinsic>(*BC->use_begin());
+ DI->eraseFromParent();
+ BC->eraseFromParent();
+ continue;
+ }
+ else if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
// Remember the basic blocks which define new values for the alloca
DefiningBlocks.push_back(SI->getParent());
AllocaPointerVal = SI->getOperand(0);