aboutsummaryrefslogtreecommitdiff
path: root/lib/Target
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-09-08 18:54:55 +0000
committerChris Lattner <sabre@nondot.org>2003-09-08 18:54:55 +0000
commit36143fc4440ac1fc2a0fc95a4999bcadc3ec207d (patch)
tree8e8d7c349a476eb4d2997258e6e3405fa0e2a994 /lib/Target
parenta6ce898dad724380b1444f664f8e422ba1e746d0 (diff)
Add support for the unwind instruction
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8408 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/CBackend/CBackend.cpp14
-rw-r--r--lib/Target/CBackend/Writer.cpp14
-rw-r--r--lib/Target/X86/InstSelectSimple.cpp5
-rw-r--r--lib/Target/X86/X86ISelSimple.cpp5
4 files changed, 38 insertions, 0 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 721ead091c..073ce19189 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -117,6 +117,7 @@ namespace {
void visitBranchInst(BranchInst &I);
void visitSwitchInst(SwitchInst &I);
void visitInvokeInst(InvokeInst &I);
+ void visitUnwindInst(UnwindInst &I);
void visitPHINode(PHINode &I);
void visitBinaryOperator(Instruction &I);
@@ -980,6 +981,19 @@ void CWriter::visitInvokeInst(InvokeInst &II) {
}
+void CWriter::visitUnwindInst(UnwindInst &I) {
+ // The unwind instructions causes a control flow transfer out of the current
+ // function, unwinding the stack until a caller who used the invoke
+ // instruction is found. In this context, we code generated the invoke
+ // instruction to add an entry to the top of the jmpbuf_list. Thus, here we
+ // just have to longjmp to the specified handler.
+ Out << " if (__llvm_jmpbuf_list == 0) { /* llvm.unwind */\n"
+ << " printf(\"throw found with no handler!\\n\"); abort();\n"
+ << " }\n"
+ << " longjmp(__llvm_jmpbuf_list->buf, 1);\n";
+ emittedInvoke = true;
+}
+
static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 721ead091c..073ce19189 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -117,6 +117,7 @@ namespace {
void visitBranchInst(BranchInst &I);
void visitSwitchInst(SwitchInst &I);
void visitInvokeInst(InvokeInst &I);
+ void visitUnwindInst(UnwindInst &I);
void visitPHINode(PHINode &I);
void visitBinaryOperator(Instruction &I);
@@ -980,6 +981,19 @@ void CWriter::visitInvokeInst(InvokeInst &II) {
}
+void CWriter::visitUnwindInst(UnwindInst &I) {
+ // The unwind instructions causes a control flow transfer out of the current
+ // function, unwinding the stack until a caller who used the invoke
+ // instruction is found. In this context, we code generated the invoke
+ // instruction to add an entry to the top of the jmpbuf_list. Thus, here we
+ // just have to longjmp to the specified handler.
+ Out << " if (__llvm_jmpbuf_list == 0) { /* llvm.unwind */\n"
+ << " printf(\"throw found with no handler!\\n\"); abort();\n"
+ << " }\n"
+ << " longjmp(__llvm_jmpbuf_list->buf, 1);\n";
+ emittedInvoke = true;
+}
+
static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp
index f754d11066..6712d94f32 100644
--- a/lib/Target/X86/InstSelectSimple.cpp
+++ b/lib/Target/X86/InstSelectSimple.cpp
@@ -132,6 +132,7 @@ namespace {
const std::vector<ValueRecord> &Args);
void visitCallInst(CallInst &I);
void visitInvokeInst(InvokeInst &II);
+ void visitUnwindInst(UnwindInst &UI);
void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
// Arithmetic operators
@@ -1020,6 +1021,10 @@ void ISel::visitInvokeInst(InvokeInst &II) {
BuildMI(BB, X86::JMP, 1).addPCDisp(II.getNormalDest());
}
+void ISel::visitUnwindInst(UnwindInst &UI) {
+ // unwind is not supported yet! Just abort when the unwind inst is executed!
+ BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
+}
void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
unsigned TmpReg1, TmpReg2;
diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp
index f754d11066..6712d94f32 100644
--- a/lib/Target/X86/X86ISelSimple.cpp
+++ b/lib/Target/X86/X86ISelSimple.cpp
@@ -132,6 +132,7 @@ namespace {
const std::vector<ValueRecord> &Args);
void visitCallInst(CallInst &I);
void visitInvokeInst(InvokeInst &II);
+ void visitUnwindInst(UnwindInst &UI);
void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
// Arithmetic operators
@@ -1020,6 +1021,10 @@ void ISel::visitInvokeInst(InvokeInst &II) {
BuildMI(BB, X86::JMP, 1).addPCDisp(II.getNormalDest());
}
+void ISel::visitUnwindInst(UnwindInst &UI) {
+ // unwind is not supported yet! Just abort when the unwind inst is executed!
+ BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
+}
void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
unsigned TmpReg1, TmpReg2;