From: Chris Lattner We have a couple common questions about code in the LLVM IR form, lets just
-get these out of the way right now shall we? We have a couple common questions about code in the LLVM IR form - lets just
+get these out of the way right now, shall we?
One nice aspect of LLVM is that it is often capable of preserving language +
One nice aspect of LLVM is that it is often capable of preserving target independence in the IR: you can take the LLVM IR for a Kaleidoscope-compiled program and run it on any target that LLVM supports, even emitting C code and compiling that on targets that LLVM doesn't support natively. You can trivially @@ -215,7 +215,7 @@ the actual source code.
you are willing to fix primitive types to a fixed size (say int = 32-bits, and long = 64-bits), don't care about ABI compatibility with existing binaries, and are willing to give up some other minor features, you can have portable -code. This can even make real sense for specialized domains such as an +code. This can make sense for specialized domains such as an in-kernel language. @@ -227,7 +227,8 @@ in-kernel language.Many of the languages above are also "safe" languages: it is impossible for -a program written in Java to corrupt its address space and crash the process. +a program written in Java to corrupt its address space and crash the process +(assuming the JVM has no bugs). Safety is an interesting property that requires a combination of language design, runtime support, and often operating system support.
@@ -277,13 +278,13 @@ whether an argument is sign or zero extended, information about pointers aliasing, etc. Many of the enhancements are user-driven: people want LLVM to do some specific feature, so they go ahead and extend it to do so. -Third, it is certainly possible to add language-specific +
Third, it is possible and easy to add language-specific optimizations, and you have a number of choices in how to do it. As one trivial -example, it is possible to add language-specific optimization passes that +example, it is easy to add language-specific optimization passes that "know" things about code compiled for a language. In the case of the C family, -there is an optimziation pass that "knows" about the standard C library +there is an optimization pass that "knows" about the standard C library functions. If you call "exit(0)" in main(), it knows that it is safe to -optimize that into "return 0;" for example, because C specifies what the 'exit' +optimize that into "return 0;" because C specifies what the 'exit' function does.
In addition to simple library knowledge, it is possible to embed a variety of