diff options
author | Karl Schimpf <kschimpf@google.com> | 2013-07-25 12:23:14 -0700 |
---|---|---|
committer | Karl Schimpf <kschimpf@google.com> | 2013-07-25 12:23:14 -0700 |
commit | d0c3e5a5d23f2d7c91a7091918bd85ca495dae19 (patch) | |
tree | 0e2cda35ba6a4178bd7432e64c277960ecd37beb | |
parent | ea660c168960b06cbcbc4d312a537618a1a8549a (diff) |
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
-rw-r--r-- | include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h | 2 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp | 73 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h | 7 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp | 5 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp | 19 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h | 9 |
6 files changed, 1 insertions, 114 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h index b334842415..53f74f0ef4 100644 --- a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h +++ b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h @@ -162,7 +162,7 @@ namespace naclbitc { CST_CODE_INLINEASM_OLD = 18, // No longer used. CST_CODE_CE_SHUFVEC_EX = 19, // Not used in PNaCl. CST_CODE_CE_INBOUNDS_GEP = 20,// Not used in PNaCl. - CST_CODE_BLOCKADDRESS = 21, // CST_CODE_BLOCKADDRESS [fnty, fnval, bb#] + CST_CODE_BLOCKADDRESS = 21, // Not used in PNaCl. CST_CODE_DATA = 22, // DATA: [n x elements] CST_CODE_INLINEASM = 23 // Not used in PNaCl. }; 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<BasicBlock*>().swap(FunctionBBs); std::vector<Function*>().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<Function>(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<Function*, std::vector<BlockAddrRefTy> >::iterator BAFRI = - BlockAddrFwdRefs.find(F); - if (BAFRI != BlockAddrFwdRefs.end()) { - std::vector<BlockAddrRefTy> &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<BasicBlock*>().swap(FunctionBBs); @@ -1873,16 +1814,6 @@ bool NaClBitcodeReader::isDematerializable(const GlobalValue *GV) const { const Function *F = dyn_cast<Function>(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<Function*>(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; } diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h index fe7b5c1e9e..849ca7e506 100644 --- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h +++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h @@ -155,11 +155,6 @@ class NaClBitcodeReader : public GVMaterializer { /// stream. DenseMap<Function*, uint64_t> DeferredFunctionInfo; - /// BlockAddrFwdRefs - These are blockaddr references to basic blocks. These - /// are resolved lazily when functions are loaded. - typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy; - DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs; - /// UseRelativeIDs - Indicates that we are using a new encoding for /// instruction operands where most operands in the current /// FUNCTION_BLOCK are encoded relative to the instruction number, @@ -193,8 +188,6 @@ public: FreeState(); } - void materializeForwardReferencedFunctions(); - void FreeState(); /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp index afc8d83451..9f3626557b 100644 --- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp @@ -753,11 +753,6 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) Record.push_back(VE.getValueID(C->getOperand(i))); AbbrevToUse = AggregateAbbrev; - } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) { - Code = naclbitc::CST_CODE_BLOCKADDRESS; - Record.push_back(VE.getTypeID(BA->getFunction()->getType())); - Record.push_back(VE.getValueID(BA->getFunction())); - Record.push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock())); } else { #ifndef NDEBUG C->dump(); diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp index 01b4ff8df5..3ad224a04f 100644 --- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp @@ -423,22 +423,3 @@ void NaClValueEnumerator::purgeFunction() { BasicBlocks.clear(); FnForwardTypeRefs.clear(); } - -static void IncorporateFunctionInfoGlobalBBIDs(const Function *F, - DenseMap<const BasicBlock*, unsigned> &IDMap) { - unsigned Counter = 0; - for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) - IDMap[BB] = ++Counter; -} - -/// getGlobalBasicBlockID - This returns the function-specific ID for the -/// specified basic block. This is relatively expensive information, so it -/// should only be used by rare constructs such as address-of-label. -unsigned NaClValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const { - unsigned &Idx = GlobalBasicBlockIDs[BB]; - if (Idx != 0) - return Idx-1; - - IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs); - return getGlobalBasicBlockID(BB); -} diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h index 21bbb2fb76..3e71740f92 100644 --- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h +++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h @@ -55,10 +55,6 @@ private: ValueMapType ValueMap; ValueList Values; - /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by - /// the "getGlobalBasicBlockID" method. - mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs; - typedef DenseMap<const Instruction*, unsigned> InstructionMapType; InstructionMapType InstructionMap; unsigned InstructionCount; @@ -133,11 +129,6 @@ public: return BasicBlocks; } - /// getGlobalBasicBlockID - This returns the function-specific ID for the - /// specified basic block. This is relatively expensive information, so it - /// should only be used by rare constructs such as address-of-label. - unsigned getGlobalBasicBlockID(const BasicBlock *BB) const; - /// incorporateFunction/purgeFunction - If you'd like to deal with a function, /// use these two methods to get its data into the NaClValueEnumerator! /// |