Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Unified Diff: lib/Transforms/NaCl/SimplifyAllocas.cpp

Issue 1166253003: SimplifyAllocas: search through more bitcasts to find alloca for llvm.dbg.declare. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: report_fatal_error Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/Transforms/NaCl/simplify-allocas.ll » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Transforms/NaCl/SimplifyAllocas.cpp
diff --git a/lib/Transforms/NaCl/SimplifyAllocas.cpp b/lib/Transforms/NaCl/SimplifyAllocas.cpp
index ba25b5f961ad5ca28254e67de200b003bb2558e8..78dbfd8b98c36ecf5597b69accd25167079e9c3d 100644
--- a/lib/Transforms/NaCl/SimplifyAllocas.cpp
+++ b/lib/Transforms/NaCl/SimplifyAllocas.cpp
@@ -18,7 +18,9 @@
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/Transforms/NaCl.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
+
using namespace llvm;
namespace {
class SimplifyAllocas : public BasicBlockPass {
@@ -50,6 +52,21 @@ private:
return false;
}
+ AllocaInst *findAllocaFromBC(BitCastInst *BCInst) {
+ Value *Op0 = BCInst->getOperand(0);
+ while (!llvm::isa<AllocaInst>(Op0)) {
+ if (auto *NextBC = llvm::dyn_cast<BitCastInst>(Op0)) {
+ Op0 = NextBC->getOperand(0);
+ } else {
+ dbgs() << "findAllocaFromBC encountered a non-bitcast intermediate val "
+ << *Op0 << " starting w/ BCInst " << *BCInst << "\n";
+ report_fatal_error(
+ "findAllocaFromBC encountered a non-bitcast intermediate");
+ }
+ }
+ return llvm::cast<AllocaInst>(Op0);
+ }
+
bool runOnBasicBlock(BasicBlock &BB) override {
bool Changed = false;
for (BasicBlock::iterator I = BB.getFirstInsertionPt(), E = BB.end();
@@ -106,12 +123,11 @@ private:
// Sometimes dbg.declare points to an argument instead of an alloca.
if (auto *VM = dyn_cast<ValueAsMetadata>(MV->getMetadata())) {
if (auto *BCInst = dyn_cast<BitCastInst>(VM->getValue())) {
- Value *CastSrc = BCInst->getOperand(0);
- assert(isa<AllocaInst>(CastSrc));
+ AllocaInst *Alloca = findAllocaFromBC(BCInst);
Call->setArgOperand(
0,
MetadataAsValue::get(Inst->getContext(),
- ValueAsMetadata::get(CastSrc)));
+ ValueAsMetadata::get(Alloca)));
Changed = true;
}
}
« no previous file with comments | « no previous file | test/Transforms/NaCl/simplify-allocas.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698