From d0c3e5a5d23f2d7c91a7091918bd85ca495dae19 Mon Sep 17 00:00:00 2001 From: Karl Schimpf Date: Thu, 25 Jul 2013 12:23:14 -0700 Subject: Remove block address constants form PNaCl bitcode. Removes block address constants because they are not part of the PNaClABI. Suggested in CL https://codereview.chromium.org/20172002 BUG= https://code.google.com/p/nativeclient/issues/detail?id=3590 R=mseaborn@chromium.org Review URL: https://codereview.chromium.org/20402002 --- lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp | 73 --------------------------- 1 file changed, 73 deletions(-) (limited to 'lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp') diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp index f36fc4b17c..b384df7f58 100644 --- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp +++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp @@ -33,13 +33,6 @@ enum { SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex }; -void NaClBitcodeReader::materializeForwardReferencedFunctions() { - while (!BlockAddrFwdRefs.empty()) { - Function *F = BlockAddrFwdRefs.begin()->first; - F->Materialize(); - } -} - void NaClBitcodeReader::FreeState() { if (BufferOwned) delete Buffer; @@ -50,8 +43,6 @@ void NaClBitcodeReader::FreeState() { std::vector().swap(FunctionBBs); std::vector().swap(FunctionsWithBodies); DeferredFunctionInfo.clear(); - - assert(BlockAddrFwdRefs.empty() && "Unresolved blockaddress fwd references"); } //===----------------------------------------------------------------------===// @@ -1014,37 +1005,6 @@ bool NaClBitcodeReader::ParseConstants() { } break; } - - case naclbitc::CST_CODE_BLOCKADDRESS:{ - if (Record.size() < 3) return Error("Invalid CE_BLOCKADDRESS record"); - Type *FnTy = getTypeByID(Record[0]); - if (FnTy == 0) return Error("Invalid CE_BLOCKADDRESS record"); - Function *Fn = - dyn_cast_or_null(ValueList.getConstantFwdRef(Record[1],FnTy)); - if (Fn == 0) return Error("Invalid CE_BLOCKADDRESS record"); - - // If the function is already parsed we can insert the block address right - // away. - if (!Fn->empty()) { - Function::iterator BBI = Fn->begin(), BBE = Fn->end(); - for (size_t I = 0, E = Record[2]; I != E; ++I) { - if (BBI == BBE) - return Error("Invalid blockaddress block #"); - ++BBI; - } - V = BlockAddress::get(Fn, BBI); - } else { - // Otherwise insert a placeholder and remember it so it can be inserted - // when the function is parsed. - GlobalVariable *FwdRef = new GlobalVariable(*Fn->getParent(), - Type::getInt8Ty(Context), - false, GlobalValue::InternalLinkage, - 0, ""); - BlockAddrFwdRefs[Fn].push_back(std::make_pair(Record[2], FwdRef)); - V = FwdRef; - } - break; - } } ValueList.AssignValue(V, NextCstNo); @@ -1782,25 +1742,6 @@ OutOfRecordLoop: } } - // See if anything took the address of blocks in this function. If so, - // resolve them now. - DenseMap >::iterator BAFRI = - BlockAddrFwdRefs.find(F); - if (BAFRI != BlockAddrFwdRefs.end()) { - std::vector &RefList = BAFRI->second; - for (unsigned i = 0, e = RefList.size(); i != e; ++i) { - unsigned BlockIdx = RefList[i].first; - if (BlockIdx >= FunctionBBs.size()) - return Error("Invalid blockaddress block #"); - - GlobalVariable *FwdRef = RefList[i].second; - FwdRef->replaceAllUsesWith(BlockAddress::get(F, FunctionBBs[BlockIdx])); - FwdRef->eraseFromParent(); - } - - BlockAddrFwdRefs.erase(BAFRI); - } - // Trim the value list down to the size it was before we parsed this function. ValueList.shrinkTo(ModuleValueListSize); std::vector().swap(FunctionBBs); @@ -1873,16 +1814,6 @@ bool NaClBitcodeReader::isDematerializable(const GlobalValue *GV) const { const Function *F = dyn_cast(GV); if (!F || F->isDeclaration()) return false; - // @LOCALMOD-START - // Don't dematerialize functions with BBs which have their address taken; - // it will cause any referencing blockAddress constants to also be destroyed, - // but because they are GVs, they need to stay around until PassManager - // finalization. - for (Function::const_iterator BB = F->begin(); BB != F->end(); ++BB) { - if (BB->hasAddressTaken()) - return false; - } - // @LOCALMOD-END return DeferredFunctionInfo.count(const_cast(F)); } @@ -1993,8 +1924,6 @@ Module *llvm::getNaClLazyBitcodeModule(MemoryBuffer *Buffer, // Have the NaClBitcodeReader dtor delete 'Buffer'. R->setBufferOwned(true); - R->materializeForwardReferencedFunctions(); - return M; } @@ -2016,8 +1945,6 @@ Module *llvm::getNaClStreamedBitcodeModule(const std::string &name, } R->setBufferOwned(false); // no buffer to delete - R->materializeForwardReferencedFunctions(); - return M; } -- cgit v1.2.3-70-g09d2