From 8866634b02d4230c723c3c9449341ee749a0e2a4 Mon Sep 17 00:00:00 2001 From: Yang Rong Date: Fri, 31 May 2013 15:19:09 +0800 Subject: [PATCH] Fix a random assert caused by scalarize pass. Revome the dead values in unit.valueMap at each begin of pass to avoid the new value have some address. Also fix a typo Signed-off-by: Yang Rong Reviewed-by: Zhigang Gong --- backend/src/ir/unit.cpp | 10 +++++++++- backend/src/ir/unit.hpp | 2 ++ backend/src/llvm/llvm_gen_backend.cpp | 1 + backend/src/llvm/llvm_scalarize.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/backend/src/ir/unit.cpp b/backend/src/ir/unit.cpp index 1e98afa..44cec3c 100644 --- a/backend/src/ir/unit.cpp +++ b/backend/src/ir/unit.cpp @@ -21,6 +21,7 @@ * \file unit.cpp * \author Benjamin Segovia */ +#include "llvm/Instructions.h" #include "ir/unit.hpp" #include "ir/function.hpp" @@ -53,10 +54,17 @@ namespace ir { constantSet.append(data, name, size, alignment); } + void Unit::removeDeadValues() + { + for(auto &it : valueMap) { + llvm::Instruction* I = llvm::dyn_cast(it.first.first); //fake value + if((I == NULL) || (I->getParent() == NULL)) + valueMap.erase(it.first); + } + } std::ostream &operator<< (std::ostream &out, const Unit &unit) { unit.apply([&out] (const Function &fn) { out << fn << std::endl; }); return out; } } /* namespace ir */ } /* namespace gbe */ - diff --git a/backend/src/ir/unit.hpp b/backend/src/ir/unit.hpp index 3b293f5..f19fd7e 100644 --- a/backend/src/ir/unit.hpp +++ b/backend/src/ir/unit.hpp @@ -88,6 +88,8 @@ namespace ir { GBE_ASSERT(valueMap.find(key) == valueMap.end()); // Do not insert twice valueMap[key] = value; } + /* remove fake values that removed by other pass */ + void removeDeadValues(void); /*! Return the value map */ const map& getValueMap(void) const { return valueMap; } private: diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index db7d714..5189db3 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -1140,6 +1140,7 @@ namespace gbe } ctx.startFunction(F.getName()); + unit.removeDeadValues(); this->regTranslator.clear(); this->regTranslator.initValueMap(unit.getValueMap()); this->labelMap.clear(); diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp index bc66549..c24e575 100644 --- a/backend/src/llvm/llvm_scalarize.cpp +++ b/backend/src/llvm/llvm_scalarize.cpp @@ -182,7 +182,7 @@ namespace gbe { bool IsPerComponentOp(const Value* value); //these function used to add extract and insert instructions when load/store etc. - void extractFromeVector(Value* insn); + void extractFromVector(Value* insn); Value* InsertToVector(Value* insn, Value* vecValue); Type* GetBasicType(Value* value) { @@ -581,7 +581,7 @@ namespace gbe { return true; } - void Scalarize::extractFromeVector(Value* insn) { + void Scalarize::extractFromVector(Value* insn) { VectorValues& vVals = vectorVals[insn]; for (int i = 0; i < GetComponentCount(insn); ++i) { @@ -645,7 +645,7 @@ namespace gbe { case GEN_OCL_GET_IMAGE_WIDTH: case GEN_OCL_GET_IMAGE_HEIGHT: { - extractFromeVector(call); + extractFromVector(call); break; } case GEN_OCL_WRITE_IMAGE10: @@ -673,7 +673,7 @@ namespace gbe { bool Scalarize::scalarizeLoad(LoadInst* ld) { - extractFromeVector(ld); + extractFromVector(ld); return false; } @@ -738,7 +738,7 @@ namespace gbe { Type *type = I->getType(); if(type->isVectorTy()) - extractFromeVector(I); + extractFromVector(I); } return; } @@ -758,9 +758,9 @@ namespace gbe { intTy = IntegerType::get(module->getContext(), 32); floatTy = Type::getFloatTy(module->getContext()); builder = new IRBuilder<>(module->getContext()); + unit.removeDeadValues(); scalarizeArgs(F); - typedef ReversePostOrderTraversal RPOTType; RPOTType rpot(&F); for (RPOTType::rpo_iterator bbI = rpot.begin(), bbE = rpot.end(); bbI != bbE; ++bbI) { -- 2.7.4