[llvm-commits] [llvm] r50703 - in /llvm/branches/non-call-eh: include/llvm/BasicBlock.h include/llvm/Bitcode/LLVMBitCodes.h lib/AsmParser/llvmAsmParser.y lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp lib/VMCore/AsmWriter.cpp lib/VMCore/BasicBlock.cpp test/Feature/unwindto.ll
Nick Lewycky
nicholas at mxc.ca
Mon May 5 20:57:57 PDT 2008
Author: nicholas
Date: Mon May 5 22:57:57 2008
New Revision: 50703
URL: http://llvm.org/viewvc/llvm-project?rev=50703&view=rev
Log:
Add an optional 'nounwind' marker to basic blocks.
Modified:
llvm/branches/non-call-eh/include/llvm/BasicBlock.h
llvm/branches/non-call-eh/include/llvm/Bitcode/LLVMBitCodes.h
llvm/branches/non-call-eh/lib/AsmParser/llvmAsmParser.y
llvm/branches/non-call-eh/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/branches/non-call-eh/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/branches/non-call-eh/lib/VMCore/AsmWriter.cpp
llvm/branches/non-call-eh/lib/VMCore/BasicBlock.cpp
llvm/branches/non-call-eh/test/Feature/unwindto.ll
Modified: llvm/branches/non-call-eh/include/llvm/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/include/llvm/BasicBlock.h?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/include/llvm/BasicBlock.h (original)
+++ llvm/branches/non-call-eh/include/llvm/BasicBlock.h Mon May 5 22:57:57 2008
@@ -86,15 +86,26 @@
/// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind
/// instruction occurs in this block. May be null, in which case unwinding
- /// is undefined in this block.
+ /// exits the function.
+ ///
const BasicBlock *getUnwindDest() const;
BasicBlock *getUnwindDest();
/// setUnwindDest - Set which BasicBlock flow will enter if an unwind is
- /// executed within this block. It may be set to null if unwinding is not
- /// permitted in this block.
+ /// executed within this block. It may be set to null to indicate that
+ /// unwinding will exit the function.
+ ///
void setUnwindDest(BasicBlock *unwindDest);
+ /// doesNotThrow - Determine whether the block may not unwind.
+ ///
+ bool doesNotThrow() const;
+
+ /// setDoesNotThrow - Set whether unwinding is permissible in this
+ /// BasicBlock. Setting it to true will also clear the unwind dest.
+ ///
+ void setDoesNotThrow(bool doesNotThrow = true);
+
/// getParent - Return the enclosing method, or null if none
///
const Function *getParent() const { return Parent; }
Modified: llvm/branches/non-call-eh/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/include/llvm/Bitcode/LLVMBitCodes.h?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/branches/non-call-eh/include/llvm/Bitcode/LLVMBitCodes.h Mon May 5 22:57:57 2008
@@ -204,7 +204,8 @@
FUNC_CODE_INST_STORE2 = 24, // STORE: [ptrty,ptr,val, align, vol]
FUNC_CODE_INST_GETRESULT = 25, // GETRESULT: [ty, opval, n]
- FUNC_CODE_INST_BB_UNWINDDEST = 26 // BB_UNWINDDEST: [bb#]
+ FUNC_CODE_INST_BB_UNWINDDEST = 26, // BB_UNWINDDEST: [bb#]
+ FUNC_CODE_INST_BB_NOUNWIND = 27 // BB_NOUNWIND
};
} // End bitc namespace
} // End llvm namespace
Modified: llvm/branches/non-call-eh/lib/AsmParser/llvmAsmParser.y
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/lib/AsmParser/llvmAsmParser.y?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/lib/AsmParser/llvmAsmParser.y (original)
+++ llvm/branches/non-call-eh/lib/AsmParser/llvmAsmParser.y Mon May 5 22:57:57 2008
@@ -2561,10 +2561,21 @@
$$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), 0);
CHECK_FOR_ERROR
}
- | UNWINDS TO ValueRef { // Only the unwind to block
+ | UNWINDS TO ValueRef { // Only the unwind to block
$$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), getBBVal($3));
CHECK_FOR_ERROR
}
+ | NOUNWIND { // Only the nounwind label
+ $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), 0);
+ $$->setDoesNotThrow();
+ CHECK_FOR_ERROR
+ }
+ | NOUNWIND UNWINDS TO ValueRef { // Only the nounwind and unwind to block
+ $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), getBBVal($4));
+ $$->setDoesNotThrow();
+ CHECK_FOR_ERROR
+ }
+
| LABELSTR { // Labelled (named) basic block
$$ = defineBBVal(ValID::createLocalName(*$1), 0);
delete $1;
@@ -2575,6 +2586,18 @@
delete $1;
CHECK_FOR_ERROR
};
+ | LABELSTR NOUNWIND {
+ $$ = defineBBVal(ValID::createLocalName(*$1), 0);
+ $$->setDoesNotThrow();
+ delete $1;
+ CHECK_FOR_ERROR
+ };
+ | LABELSTR NOUNWIND UNWINDS TO ValueRef {
+ $$ = defineBBVal(ValID::createLocalName(*$1), getBBVal($5));
+ $$->setDoesNotThrow();
+ delete $1;
+ CHECK_FOR_ERROR
+ };
BBTerminatorInst :
RET ReturnedVal { // Return with a result...
Modified: llvm/branches/non-call-eh/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/lib/Bitcode/Reader/BitcodeReader.cpp?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/branches/non-call-eh/lib/Bitcode/Reader/BitcodeReader.cpp Mon May 5 22:57:57 2008
@@ -1233,6 +1233,10 @@
CurBB->setUnwindDest(getBasicBlock(Record[0]));
continue;
+ case bitc::FUNC_CODE_INST_BB_NOUNWIND: // BB_NOUNWIND
+ CurBB->setDoesNotThrow();
+ continue;
+
case bitc::FUNC_CODE_INST_BINOP: { // BINOP: [opval, ty, opval, opcode]
unsigned OpNum = 0;
Value *LHS, *RHS;
Modified: llvm/branches/non-call-eh/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/branches/non-call-eh/lib/Bitcode/Writer/BitcodeWriter.cpp Mon May 5 22:57:57 2008
@@ -975,7 +975,11 @@
Vals.push_back(VE.getValueID(unwindDest));
Stream.EmitRecord(bitc::FUNC_CODE_INST_BB_UNWINDDEST, Vals);
Vals.clear();
- }
+ }
+ if (BB->doesNotThrow()) {
+ Stream.EmitRecord(bitc::FUNC_CODE_INST_BB_NOUNWIND, Vals);
+ Vals.clear();
+ }
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
I != E; ++I) {
Modified: llvm/branches/non-call-eh/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/lib/VMCore/AsmWriter.cpp?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/branches/non-call-eh/lib/VMCore/AsmWriter.cpp Mon May 5 22:57:57 2008
@@ -1164,15 +1164,15 @@
///
void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
if (BB->hasName()) // Print out the label if it exists...
- Out << getLLVMName(BB->getName(), LabelPrefix) << ':';
+ Out << getLLVMName(BB->getName(), LabelPrefix) << ": ";
- if (const BasicBlock* unwindDest = BB->getUnwindDest()) {
- if (BB->hasName())
- Out << ' ';
+ if (BB->doesNotThrow())
+ Out << "nounwind ";
+ if (const BasicBlock* unwindDest = BB->getUnwindDest()) {
Out << "unwinds to";
writeOperand(unwindDest, false);
- }
+ }
if (!BB->hasName() && !BB->use_empty()) { // Don't print block # of no uses...
Out << "; <label>:";
Modified: llvm/branches/non-call-eh/lib/VMCore/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/lib/VMCore/BasicBlock.cpp?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/lib/VMCore/BasicBlock.cpp (original)
+++ llvm/branches/non-call-eh/lib/VMCore/BasicBlock.cpp Mon May 5 22:57:57 2008
@@ -80,6 +80,8 @@
// Make sure that we get added to a function
LeakDetector::addGarbageObject(this);
+ SubclassData = 0;
+
if (InsertBefore) {
assert(NewParent &&
"Cannot insert block before another block with no function!");
@@ -123,15 +125,35 @@
return cast_or_null<const BasicBlock>(unwindDest.get());
}
+/// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind
+/// instruction occurs in this block. May be null, in which case unwinding
+/// exits the function.
BasicBlock *BasicBlock::getUnwindDest() {
return cast_or_null<BasicBlock>(unwindDest.get());
}
+/// setUnwindDest - Set which BasicBlock flow will enter if an unwind is
+/// executed within this block. It may be set to null to indicate that
+/// unwinding will exit the function.
void BasicBlock::setUnwindDest(BasicBlock *dest) {
NumOperands = unwindDest ? 1 : 0;
unwindDest.set(dest);
}
+/// doesNotThrow - Determine whether the block may not unwind.
+bool BasicBlock::doesNotThrow() const {
+ return SubclassData & 1;
+}
+
+/// setDoesNotThrow - Set whether unwinding is permissible in this
+/// BasicBlock. Setting it to true will also clear the unwind dest.
+void BasicBlock::setDoesNotThrow(bool doesNotThrow) {
+ if (doesNotThrow)
+ SubclassData |= 1;
+ else
+ SubclassData &= ~1;
+}
+
/// moveBefore - Unlink this basic block from its current function and
/// insert it into the function that MovePos lives in, right before MovePos.
void BasicBlock::moveBefore(BasicBlock *MovePos) {
Modified: llvm/branches/non-call-eh/test/Feature/unwindto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/non-call-eh/test/Feature/unwindto.ll?rev=50703&r1=50702&r2=50703&view=diff
==============================================================================
--- llvm/branches/non-call-eh/test/Feature/unwindto.ll (original)
+++ llvm/branches/non-call-eh/test/Feature/unwindto.ll Mon May 5 22:57:57 2008
@@ -48,7 +48,7 @@
define void @test6() {
entry:
- br label %unwind
+ br label %unwind
unwind: unwinds to %unwind
unwind
}
@@ -65,3 +65,28 @@
[2, %cond_false], [2, %cond_false]
ret i8 %x
}
+
+define i1 @test8(i8 %i, i8 %j) {
+entry: unwinds to %target
+ %tmp = sub i8 %i, %j ; <i8> [#uses=1]
+ %b = icmp eq i8 %tmp, 0 ; <i1> [#uses=1]
+ ret i1 %b
+target: nounwind
+ ret i1 false
+}
+
+define i1 @test9(i8 %i, i8 %j) {
+entry: nounwind unwinds to %0
+ %tmp = sub i8 %i, %j ; <i8> [#uses=1]
+ %b = icmp eq i8 %tmp, 0 ; <i1> [#uses=1]
+ ret i1 %b
+nounwind unwinds to %0
+ ret i1 false
+}
+
+define void @test10() {
+entry:
+ br label %unwind
+unwind: nounwind unwinds to %unwind
+ unwind
+}
More information about the llvm-commits
mailing list