Calling a script from a script in a lit test

I’m trying to put together some tests for the optimization bisecting feature I’m working on and I’ve come across a stumbling block trying to accomplish something in a lit test.

I’ve got an IR file with some simple functions, one of which includes a call to another function that will be inlined during optimization. I can use this to manually test my new OptBisect class by invoking the existing utils/bisect file in the following way:

python <llvm_scr_root>/utils/bisect --start=0 --end=200 test.sh %(count)s

with ‘test.sh’ looking like this:

opt -O2 -opt-bisect-limit=%1 -S opt-bisect.ll | FileCheck opt-bisect.ll --check-prefix=CHECK-BISECT-INLINE

and ‘opt-bisect.ll’ looking (more or less) like this:

; CHECK-BISECT-INLINE: call i32 @f1()

define i32 @f1() {

entry:

ret i32 0

}

define i32 @f2() {

entry:

%temp = call i32 @f1()

ret i32 %temp

}

From a command shell that does exactly what I want it to and converges on the inlining optimization. So my question is, how can I accomplish that same thing in the form of a lit test. I feel like it’s really close, but I don’t know (1) how to find utils/bisect properly from the lit test, and (2) how to get the piping at the right level on the run line (or into a secondary script that will work on all platforms.

Can anyone help me out?

Thanks,

Andy

Well… last time I wanted to essentially have two files in one in a lit test, I used grep and sed to split one file, like the following:

; RUN: grep BISECT %s | sed -e ‘s/^.*BISECT: //’ > %t.sh
; RUN: python …/bisect … %t.sh
; BISECT: opt -O2 …
define void @foo() { ret void }

This approach isn’t going to work on Windows, though, because bash isn’t provided by gnuwin32, and so far we’ve avoided depending on it directly.

I’ve come up with something that appears to be working for me on Windows using a python script to do the intermediate piping, but I have serious reservations about trusting python’s subprocess for cross-platform portability. Have they fixed that yet?

I’ve come up with something that appears to be working for me on Windows
using a python script to do the intermediate piping, but I have serious
reservations about trusting python’s subprocess for cross-platform
portability. Have they fixed that yet?

Python's subprocess module is extremely robust in my experience (having
used it across platforms, including windows, recently).

-- Sean Silva

I’m trying to put together some tests for the optimization bisecting
feature I’m working on and I’ve come across a stumbling block trying to
accomplish something in a lit test.

I’ve got an IR file with some simple functions, one of which includes a
call to another function that will be inlined during optimization. I can
use this to manually test my new OptBisect class by invoking the existing
utils/bisect file in the following way:

    python <llvm_scr_root>/utils/bisect --start=0 --end=200 test.sh
%(count)s

with ‘test.sh’ looking like this:

    opt -O2 -opt-bisect-limit=%1 -S opt-bisect.ll | FileCheck
opt-bisect.ll --check-prefix=CHECK-BISECT-INLINE

and ‘opt-bisect.ll’ looking (more or less) like this:

    ; CHECK-BISECT-INLINE: call i32 @f1()

    define i32 @f1() {

    entry:

      ret i32 0

    }

    define i32 @f2() {

    entry:

      %temp = call i32 @f1()

      ret i32 %temp

    }

From a command shell that does exactly what I want it to and converges on
the inlining optimization. So my question is, how can I accomplish that
same thing in the form of a lit test. I feel like it’s really close, but I
don’t know (1) how to find utils/bisect properly from the lit test,

You can probably add a lit substitution %llvm_src_root if we don't have one.
(The generated files build_dir/bin/llvm-lit.py (or build_dir/bin/llvm-lit)
already know it, so that information should be available to lit I think)

and (2) how to get the piping at the right level on the run line (or into
a secondary script that will work on all platforms.

You can always just put files in %S/Inputs/

-- Sean Silva