diff options
author | Chris Lattner <sabre@nondot.org> | 2009-10-31 20:08:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-10-31 20:08:37 +0000 |
commit | b2c0e243c54574485a146a0eb96bb38883a6dc27 (patch) | |
tree | 56d41454d4e0adc0e2b304b60200b8e1fb33f1d4 /llvm/lib/Bitcode | |
parent | 75ce573815262082666cc90bd87575557d588c01 (diff) | |
download | llvm-b2c0e243c54574485a146a0eb96bb38883a6dc27.zip llvm-b2c0e243c54574485a146a0eb96bb38883a6dc27.tar.gz llvm-b2c0e243c54574485a146a0eb96bb38883a6dc27.tar.bz2 |
Make blockaddress(@func, null) be valid, and make 'deleting a basic
block with a blockaddress still referring to it' replace the invalid
blockaddress with a new blockaddress(@func, null) instead of a
inttoptr(1).
This changes the bitcode encoding format, and still needs codegen
support (this should produce a non-zero value, referring to the entry
block of the function would also be quite reasonable).
llvm-svn: 85678
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 8 |
3 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 68527e3..749f16f 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2274,11 +2274,12 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { 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()) + if (BlockIdx > FunctionBBs.size()) return Error("Invalid blockaddress block #"); GlobalVariable *FwdRef = RefList[i].second; - FwdRef->replaceAllUsesWith(BlockAddress::get(F, FunctionBBs[BlockIdx])); + BasicBlock *BB = BlockIdx == 0 ? 0 : FunctionBBs[BlockIdx-1]; + FwdRef->replaceAllUsesWith(BlockAddress::get(F, BB)); FwdRef->eraseFromParent(); } diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index af0b8ac..e32977d 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -854,7 +854,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, break; } } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) { - assert(BA->getFunction() == BA->getBasicBlock()->getParent() && + assert((!BA->getBasicBlock() || + BA->getFunction() == BA->getBasicBlock()->getParent()) && "Malformed blockaddress"); Code = bitc::CST_CODE_BLOCKADDRESS; Record.push_back(VE.getTypeID(BA->getFunction()->getType())); diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index d840d4a..92a9bab 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -265,6 +265,8 @@ void ValueEnumerator::EnumerateValue(const Value *V) { // Do not enumerate the initializers for an array of simple characters. // The initializers just polute the value table, and we emit the strings // specially. + } else if (isa<BlockAddress>(C)) { + // Don't enumerate function or block. } else if (C->getNumOperands()) { // If a constant has operands, enumerate them. This makes sure that if a // constant has uses (for example an array of const ints), that they are @@ -276,8 +278,7 @@ void ValueEnumerator::EnumerateValue(const Value *V) { // graph that don't go through a global variable. for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I) - if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress. - EnumerateValue(*I); + EnumerateValue(*I); // Finally, add the value. Doing this could make the ValueID reference be // dangling, don't reuse it. @@ -417,9 +418,10 @@ static void IncorporateFunctionInfoGlobalBBIDs(const Function *F, /// specified basic block. This is relatively expensive information, so it /// should only be used by rare constructs such as address-of-label. unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const { + if (BB == 0) return 0; unsigned &Idx = GlobalBasicBlockIDs[BB]; if (Idx != 0) - return Idx-1; + return Idx; IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs); return getGlobalBasicBlockID(BB); |