question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to execute the generated bitcode?

See original GitHub issue

❓ Questions and Help

I was wondering if there was a standard api in compiler gym to run executed bitcode?

For example if I have the following environment

env = gym.make("llvm-autophase-ic-v0") env.require_datasets(['cBench-v0'])

And go to the directory containing the datasets bitcode files, try to run one with

lli bitcount.bc

which seg faults - I tried a few other programs and got undefined reference to main. My question is if there is a common way to run these packaged dataset programs pre and post compiler transformations to be able to compute rewards from speedup.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
phesse001commented, Mar 30, 2021

Hello again!

I have been busy recently but have slowly been working on using ck to create datasets to use within compiler gym and thought I’d give an update as well as a follow up question related to creating datasets in compiler gym.

So with ck, each program has its own meta.json file essentially describing all of the dependencies to compile and run the program, as well as compile and run options and tags like ‘cbench,program,benchmark’ that can be used to find groups of programs with the same tags.

I went with using this functionality to create a list of benchmarks to be used by passing a tag. For example ck run cg-program:dqn --dataset_tags=cbench will run the compiler gym dqn I already had but will use ck programs with tags ‘cbench’ as the benchmarks it learns from.

This leaves me to my question about the benchmarks - Right now I find all the programs in ck with the specified tags, compile them to make sure they compile with the ck api, and then for each ck program (which may consist of a list of bc files), I call env.make_benchmark(). I store each of these benchmarks in a list but cannot set env.benchmarks to this list so instead I just randomly select a benchmark and pass that benchmark into env.reset().

I was wondering if this env.benchmark is stored in the same location as the original bitcode file and if the env.step() would then apply whichever action that was selected to all of the bitcode files that are part of the current benchmark.

Thanks and I can give you a link to the code if that helps!

0reactions
ChrisCumminscommented, Mar 30, 2021

Hi @phesse001, thanks for the update! This sounds like great progress.

Right now I find all the programs in ck with the specified tags, compile them to make sure they compile with the ck api, and then for each ck program (which may consist of a list of bc files), I call env.make_benchmark().

Is the goal to have one benchmark per cBench program? If so, you can pass all of the bitcodes that comprise that program into env.make_benchmark() to produce a single benchmark:

benchmark = env.make_benchmark(['myapp.c', 'a-bitcode.bc', 'somelib.bc'])
env.reset(benchmark=benchmark)

Under the covers, this is equivalent to using llvm-link to join the bitcodes:

clang -emit-llvm -c *.c
llvm-link *.bc -o benchmark.bc

This resulting benchmark can be linked to an executable as-per the described flags in cBench meta.json.

I was wondering if this env.benchmark is stored in the same location as the original bitcode file

No, the object created by env.make_benchmark() is independent of the filesystem. If you printed one of the return values you can see that it is an in-memory store of the bitcode as a string.

Hope that helps. Please feel free to ping me at chrisc.101@gmail.com if you want to set up a quick video chat, always nice to connect with fellow compiler researchers 😃

Cheers, Chris

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bitcode and Assembly? | Apple Developer Forums
When using Xcode, bitcode is only produced during archive build, ... Assembly source files should work in the sense that you can build...
Read more >
Understanding Bitcode for iOS Applications - InfoQ
These can be passed to the Swift compiler with -embed-bitcode or by using clang with -fembed-bitcode .
Read more >
How to run LLVM bitcode generated from Haskell source code
I'm trying to run LLVM bitcode generated from Haskell source code instead of compiling the code to a native binary on macOS.
Read more >
Xcode Build Settings
Run Script build phases can use the value of this build setting as a ... For Archive builds, bitcode will be generated in...
Read more >
iOS Symbolication - Visual Studio App Center | Microsoft Learn
The body of the first API call should set symbol_type to Apple . ... If Bitcode is enabled, the symbols generated for your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found