[LLVMdev] where can I find out the documents of how to write a llvm regression test case?
陳韋任 (Wei-Ren Chen)
chenwj at iis.sinica.edu.tw
Mon Aug 27 00:36:11 PDT 2012
Hi Changcheng,
Below is an example took from test/CodeGen/X86/add.ll:
define i32 @test1(i32 inreg %a) nounwind {
%b = add i32 %a, 128
ret i32 %b
; X32: subl $-128, %eax
; X64: subl $-128,
}
1. The first step, you write a function by using LLVM IR.
define i32 @test1(i32 inreg %a) nounwind {
%b = add i32 %a, 128
ret i32 %b
}
This will be left to LLVM toolchain to generate binary code.
2. Then in the test case above, you add comment like,
; X32: subl $-128, %eax
; X64: subl $-128,
so that FileCheck can check the output of LLVM toolchain and what you
expect from it (; comment). O.K., let's go back to your questions,
> 1.FileCheck verify the file that llvm-dis output and %s? if i just
> want to verify if the file that llvm-dis output contain a string(such
> as "abc“),what should i do?
%s means the *current* file, so you leave this file (*ll, human
readable LLVM IR) to llvm-as to generate *bc (bitcode, non-reabable
by human), use llvm-dis to get back *ll, then use Filecheck [1] to
compare its stdin (output of llvm-dis) with "; CHECK" line in %s
(i.e., this file). Usually you write what you expect in the test
case file, then let FileCheck to the work. The old way is using
`grep`, but it's not recommanded.
> 2."; CHECK: %z = add nuw i64 %x, %y" and "%z = add nuw i64 %x, %y" has
> the same sentence, why?
Usually you add "; CHECK" in usual case before what you expect from
LLVM toolchain, or as the above example shows it adds "; X32:". This is
one feature of FileCheck, you can specify what line you want to compare
with. Above test/CodeGen/X86/add.ll, you will see:
; RUN: llc < %s -mcpu=generic -march=x86 | FileCheck %s -check-prefix=X32
which means FileCheck now will compare LLVM toolchain's result with lines
with"; X32:" prefix. But in your example, note below commond:
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
It basically assemble LLVM IR first, pipe to llvm-dis to disassemble,
then use FileCheck to check if the content before llvm-as and after
llvm-dis is the same or not (should be the same), That's why you see
; CHECK: %z = add nuw i64 %x, %y
%z = add nuw i64 %x, %y
Regards,
chenwj
[1] http://llvm.org/docs/TestingGuide.html#FileCheck
--
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj
More information about the llvm-dev
mailing list