[llvm-commits] [llvm] r43327 - /llvm/trunk/docs/tutorial/LangImpl3.html
Chris Lattner
sabre at nondot.org
Wed Oct 24 21:30:37 PDT 2007
Author: lattner
Date: Wed Oct 24 23:30:35 2007
New Revision: 43327
URL: http://llvm.org/viewvc/llvm-project?rev=43327&view=rev
Log:
Run the verifier on generated code.
Modified:
llvm/trunk/docs/tutorial/LangImpl3.html
Modified: llvm/trunk/docs/tutorial/LangImpl3.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/LangImpl3.html?rev=43327&r1=43326&r2=43327&view=diff
==============================================================================
--- llvm/trunk/docs/tutorial/LangImpl3.html (original)
+++ llvm/trunk/docs/tutorial/LangImpl3.html Wed Oct 24 23:30:35 2007
@@ -400,10 +400,6 @@
Builder.SetInsertPoint(BB);
if (Value *RetVal = Body->Codegen()) {
- // Finish off the function.
- Builder.CreateRet(RetVal);
- return TheFunction;
- }
</pre>
</div>
@@ -417,12 +413,29 @@
Since we don't have any control flow, our functions will only contain one
block so far. We'll fix this in a future installment :).</p>
+<div class="doc_code">
+<pre>
+ if (Value *RetVal = Body->Codegen()) {
+ // Finish off the function.
+ Builder.CreateRet(RetVal);
+
+ // Validate the generated code, checking for consistency.
+ verifyFunction(*TheFunction);
+ return TheFunction;
+ }
+</pre>
+</div>
+
<p>Once the insertion point is set up, we call the <tt>CodeGen()</tt> method for
the root expression of the function. If no error happens, this emits code to
compute the expression into the entry block and returns the value that was
computed. Assuming no error, we then create an LLVM <a
-href="../LangRef.html#i_ret">ret instruction</a>. This completes the function,
-which is then returned.</p>
+href="../LangRef.html#i_ret">ret instruction</a>, which completes the function.
+Once the function is built, we call the <tt>verifyFunction</tt> function, which
+is provided by LLVM. This function does a variety of consistency checks on the
+generated code, to determine if our compiler is doing everything right. Using
+this is important: it can catch a lot of bugs. Once the function is finished
+and validated, we return it.</p>
<div class="doc_code">
<pre>
@@ -625,6 +638,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
+#include "llvm/Analysis/Verifier.h"
#include "llvm/Support/LLVMBuilder.h"
#include <cstdio>
#include <string>
@@ -1071,6 +1085,9 @@
if (Value *RetVal = Body->Codegen()) {
// Finish off the function.
Builder.CreateRet(RetVal);
+
+ // Validate the generated code, checking for consistency.
+ verifyFunction(*TheFunction);
return TheFunction;
}
More information about the llvm-commits
mailing list