What would be the best way to convert built-in setjmp and longjmp tp library calls? Should it be implemented in clang or in backends? On Tue, Apr 12, 2011 at 2:38 PM, Jim Grosbach <grosbach at apple.com> wrote:> ARM/Darwin implements them. I'm not aware of any others. > > That said, they are designed for internal use by the compiler for exception > handling. Calling them directly like this is very much not recommended. > Using the system library setjmp()/longjmp() functions is preferred. > > -Jim > > On Apr 12, 2011, at 1:56 PM, Akira Hatanaka wrote: > > > Does the X86 backend (or any other backend) correctly implement support > for __builtin_setjmp and __builtin_longjmp? > > I don't get the correct result when I compile and run the following code > with clang. > > > > # clang foo.c -O3; ./a.out > > > > #include <stdio.h> > > void *buf[20]; > > void __attribute__((noinline)) > > foo (void) > > { > > __builtin_longjmp (buf, 1); > > } > > > > int > > main (int argc, char** argv) > > { > > if (__builtin_setjmp (buf)) > > { > > printf("return\n"); > > return 0; > > } > > > > printf("call foo\n"); > > foo (); > > > > return 1; > > } > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110412/af1213be/attachment.html>
If you want an automated method, then using the source code re-writer interfaces in clang is probably a reasonable starting place. Just modifying the source code manually is probably easier, though, to be honest. As a moderate caveat to all of this, there are some bits of code out there that use these builtins that are very tightly coupled to the compiler (the Linux kernel used to do this, I think, and maybe still does). Those sorts of situations are unlikely to be solved satisfactorily by moving to library calls (performance reasons, usually). The appropriate solution there will be very situation specific and will likely involve refactoring the implementations in question to some degree. Regards, Jim On Apr 12, 2011, at 2:54 PM, Akira Hatanaka wrote:> What would be the best way to convert built-in setjmp and longjmp tp library calls? > Should it be implemented in clang or in backends? > > On Tue, Apr 12, 2011 at 2:38 PM, Jim Grosbach <grosbach at apple.com> wrote: > ARM/Darwin implements them. I'm not aware of any others. > > That said, they are designed for internal use by the compiler for exception handling. Calling them directly like this is very much not recommended. Using the system library setjmp()/longjmp() functions is preferred. > > -Jim > > On Apr 12, 2011, at 1:56 PM, Akira Hatanaka wrote: > > > Does the X86 backend (or any other backend) correctly implement support for __builtin_setjmp and __builtin_longjmp? > > I don't get the correct result when I compile and run the following code with clang. > > > > # clang foo.c -O3; ./a.out > > > > #include <stdio.h> > > void *buf[20]; > > void __attribute__((noinline)) > > foo (void) > > { > > __builtin_longjmp (buf, 1); > > } > > > > int > > main (int argc, char** argv) > > { > > if (__builtin_setjmp (buf)) > > { > > printf("return\n"); > > return 0; > > } > > > > printf("call foo\n"); > > foo (); > > > > return 1; > > } > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
On Apr 12, 2011, at 3:15 PM, Jim Grosbach wrote:> If you want an automated method, then using the source code re-writer interfaces in clang is probably a reasonable starting place. Just modifying the source code manually is probably easier, though, to be honest. > > As a moderate caveat to all of this, there are some bits of code out there that use these builtins that are very tightly coupled to the compiler (the Linux kernel used to do this, I think, and maybe still does). Those sorts of situations are unlikely to be solved satisfactorily by moving to library calls (performance reasons, usually). The appropriate solution there will be very situation specific and will likely involve refactoring the implementations in question to some degree.Are these intrinsics really prohibitively difficult to implement? I'm not suggesting that you (or anyone else) particularly needs to do them, but is there more to them than clobbering all registers and then lowering to a quick series of instructions which save/restore the current IP, SP, and (maybe?) FP? Something seems very wrong if rewriting a custom refactoring tool to turn builtin_setjmp/longjmp into library calls could possibly be simpler than just adding support for these intrinsics to one or two more targets. John.