Using LIT in out-of-tree projects
Writing an in-tree LLVM IR regression test is pretty easy: all you need to do is annotate the IR file with testing directives. Look at the following script, for example:
; RUN: opt < %s -instcombine -S -o - | FileCheck %s target triple = "x86_64-unknown-linux" define i32 @foo(i32 %c) { entry: Â Â ; CHECK: [[RET:%.+]] = add nsw i32 %c, 3 Â Â ; CHECK: ret i32 [[RET]] Â Â %add1 = add nsw i32 %c, 1 Â Â %add2 = add nsw i32 %add1, 2 Â Â ret i32 %add2 }
This script checks if InstCombine
(triggered by the -instcombine
command-line option shown in the preceding snippet) simplifies two succeeding arithmetic adds into one. After putting this file into an arbitrary folder under llvm/test
, the script will automatically be picked and run as part of the regression test when you're executing the llvm-lit
command-line tool.
Despite its convenience, this barely helps you use LIT in out-of-tree projects...