[PATCH] XCore target exception handling
robert lytton
robert at xmos.com
Fri Jan 17 09:14:12 PST 2014
Hi echristo, rafael.espindola,
XCore target has -fno-exception as the default option
Implement __builtin_eh_return_data_regno()
Pass on "-fexceptions" flag to xcc (linker)
http://llvm-reviews.chandlerc.com/D2570
Files:
lib/Basic/Targets.cpp
lib/Driver/Tools.cpp
test/CodeGen/xcore-abi.c
test/Driver/xcore-opts.c
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -5504,6 +5504,10 @@
TargetInfo::ConstraintInfo &Info) const {
return false;
}
+ virtual int getEHDataRegisterNumber(unsigned RegNo) const {
+ // R0=ExceptionPointerRegister R1=ExceptionSelectorRegister
+ return (RegNo < 2)? RegNo : -1;
+ }
};
const Builtin::Info XCoreTargetInfo::BuiltinInfo[] = {
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1534,7 +1534,7 @@
}
// Exceptions are enabled by default.
- bool ExceptionsEnabled = true;
+ bool ExceptionsEnabled = (Triple.getArch() != llvm::Triple::xcore);
// This keeps track of whether exceptions were explicitly turned on or off.
bool DidHaveExplicitExceptionFlag = false;
@@ -7097,6 +7097,12 @@
assert(Output.isNothing() && "Invalid output.");
}
+ if (Args.hasFlag(options::OPT_fexceptions,
+ options::OPT_fno_exceptions, false)
+ || Args.hasFlag(options::OPT_fcxx_exceptions,
+ options::OPT_fno_cxx_exceptions, false))
+ CmdArgs.push_back("-fexceptions");
+
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
const char *Exec =
Index: test/CodeGen/xcore-abi.c
===================================================================
--- test/CodeGen/xcore-abi.c
+++ test/CodeGen/xcore-abi.c
@@ -1,3 +1,4 @@
+// REQUIRES: xcore-registered-target
// RUN: %clang_cc1 -triple xcore -verify %s
_Static_assert(sizeof(long long) == 8, "sizeof long long is wrong");
_Static_assert(_Alignof(long long) == 4, "alignof long long is wrong");
@@ -112,10 +113,18 @@
// CHECK: call i32 @llvm.xcore.getps(i32 {{%[a-z0-9]+}})
// CHECK: call i32 @llvm.xcore.bitrev(i32 {{%[a-z0-9]+}})
// CHECK: call void @llvm.xcore.setps(i32 {{%[a-z0-9]+}}, i32 {{%[a-z0-9]+}})
- int i = __builtin_getid();
- unsigned int ui = __builtin_getps(i);
+ volatile int i = __builtin_getid();
+ volatile unsigned int ui = __builtin_getps(i);
ui = __builtin_bitrev(ui);
__builtin_setps(i,ui);
+
+ // CHECK: store volatile i32 0, i32* {{%[a-z0-9]+}}, align 4
+ // CHECK: store volatile i32 1, i32* {{%[a-z0-9]+}}, align 4
+ // CHECK: store volatile i32 -1, i32* {{%[a-z0-9]+}}, align 4
+ volatile int res;
+ res = __builtin_eh_return_data_regno(0);
+ res = __builtin_eh_return_data_regno(1);
+ res = __builtin_eh_return_data_regno(2);
}
// CHECK-LABEL: define zeroext i8 @testchar()
Index: test/Driver/xcore-opts.c
===================================================================
--- test/Driver/xcore-opts.c
+++ test/Driver/xcore-opts.c
@@ -1,13 +1,28 @@
// RUN: %clang -target xcore %s -g -Wl,L1Arg,L2Arg -Wa,A1Arg,A2Arg -fverbose-asm -### -o %t.o 2>&1 | FileCheck %s
+// RUN: %clang -target xcore -x c++ %s -g -Wl,L1Arg,L2Arg -Wa,A1Arg,A2Arg -fverbose-asm -### -o %t.o 2>&1 | FileCheck %s
+// RUN: %clang -target xcore -x c++ %s -fexceptions -### -o %t.o 2>&1 | FileCheck -check-prefix CHECK-EXCEP %s
// CHECK: "-nostdsysteminc"
// CHECK: "-momit-leaf-frame-pointer"
// CHECK-NOT: "-mdisable-fp-elim"
// CHECK: "-fno-signed-char"
// CHECK: "-fno-use-cxa-atexit"
+// CHECK-NOT: "-fcxx-exceptions"
+// CHECK-NOT: "-fexceptions"
// CHECK: "-fno-common"
// CHECH: xcc" "-o"
+// CHECK-EXCEP-NOT: "-fexceptions"
// CHECK: "-c" "-g" "-fverbose-asm" "A1Arg" "A2Arg"
// CHECK: xcc" "-o"
+// CHECK-EXCEP-NOT: "-fexceptions"
// CHECK: "L1Arg" "L2Arg"
+// CHECK-EXCEP: "-fno-use-cxa-atexit"
+// CHECK-EXCEP: "-fcxx-exceptions"
+// CHECK-EXCEP: "-fexceptions"
+// CHECK-EXCEP: "-fno-common"
+// CHECH-EXCEP: xcc" "-o"
+// CHECK-EXCEP-NOT: "-fexceptions"
+// CHECK-EXCEP: xcc" "-o"
+// CHECK-EXCEP: "-fexceptions"
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2570.1.patch
Type: text/x-patch
Size: 3864 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140117/8fce13b1/attachment.bin>
More information about the cfe-commits
mailing list