[LLVMdev] Integrating LLVM in an existing project

Duncan Sands baldrick at free.fr
Fri Apr 6 11:20:44 PDT 2007


Hi Chris,

> The static code generator works for many simple cases, but it is currently 
> disabled.  To enable it, uncomment this line in 
> llvm-gcc/gcc/llvm-convert.cpp:
> 
> //#define ITANIUM_STYLE_EXCEPTIONS
> 
> 
> Based on that, you should be able to compile simple C++ codes that throw 
> and catch exceptions.  The next step would be to make a .bc file, run it 
> through the JIT, see how it explodes :)

the compiler fails to build if you do that :-/
The attached patch helps a bit but it needs more work.
Also, I suppose you might need to uncomment this bit in llvm-backend.cpp
as well:
// Disabled until PR1224 is resolved.
  //if (flag_exceptions)
  //  Args.push_back("--enable-eh");

Some comments on the patch:
(1)
       new UnreachableInst(CurBB);
+    } else {
+      new UnwindInst(UnwindBB);
     }
-#endif
+#else
     new UnwindInst(UnwindBB);
+#endif

This avoid generating an unwind instruction straight after an unreachable
instruction, i.e. two terminators in a row.

(2)

-  FuncCPPPersonality = cast<Function>(
+  FuncCPPPersonality =
     TheModule->getOrInsertFunction("__gxx_personality_v0",
                                    Type::getPrimitiveType(Type::VoidTyID),
-                                   NULL));
-  FuncCPPPersonality->setLinkage(Function::ExternalLinkage);
-  FuncCPPPersonality->setCallingConv(CallingConv::C);
+                                   NULL);
 
-  FuncUnwindResume = cast<Function>(
+  FuncUnwindResume =
     TheModule->getOrInsertFunction("_Unwind_Resume",
                                    Type::getPrimitiveType(Type::VoidTyID),
                                    PointerType::get(Type::Int8Ty),
-                                   NULL));
-  FuncUnwindResume->setLinkage(Function::ExternalLinkage);
-  FuncUnwindResume->setCallingConv(CallingConv::C);
+                                   NULL);
 
When compiling the C++ file in which __gxx_personality_v0 is defined,
getOrInsertFunction returns a bitcast of the real function (a bitcast,
because the prototype of the real function is not "void (void)").  This
is a constant expression, thus cast<Function> asserts.  Also, there seems
to be no need to set the CC and linkage because the values set are the
defaults.  By the way, I like the use of the C++ only __gxx_personality_v0
here!

(3)

+      TypeInfo = BitCastToType(TypeInfo, PointerType::get(Type::Int8Ty));

This argument is, as far as I can see, just a "cookie" and certainly need
not be an i8*, thus the bitcast.  Also, since it is a cookie, shouldn't
the intrinsic be taking an opaque* rather than an i8*?

Ciao,

Duncan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eon.diff
Type: text/x-diff
Size: 2665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070406/7c58cac3/attachment.diff>


More information about the llvm-dev mailing list