Skip to content

Commit

Permalink
add_timing in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Oct 16, 2024
1 parent 4f4ff15 commit fe255de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion bril-rs/brillvm/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub struct Cli {
/// Arguments for the main function
#[arg(action)]
pub args: Vec<String>,

#[arg(action)]
pub add_timing: bool,
}

pub fn run(args: &Cli) -> String {
Expand All @@ -49,7 +52,7 @@ pub fn run(args: &Cli) -> String {
let runtime_path = args.runtime.as_ref().map_or("rt.bc", |f| f);
// create a module from the runtime library for functions like printing/parsing
let runtime_module = Module::parse_bitcode_from_path(runtime_path, &context).unwrap();
let llvm_prog = create_module_from_program(&context, &prog, runtime_module);
let llvm_prog = create_module_from_program(&context, &prog, runtime_module, args.add_timing);

//println!("{}", prog);
//llvm_prog.print_to_file("tmp.ll").unwrap();
Expand Down
10 changes: 6 additions & 4 deletions bril-rs/brillvm/src/llvm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use inkwell::{
attributes::AttributeLoc,
basic_block::BasicBlock,
builder::Builder,
context::Context,
Expand Down Expand Up @@ -1419,6 +1418,7 @@ pub fn create_module_from_program<'a>(
context: &'a Context,
Program { functions, .. }: &Program,
runtime_module: Module<'a>,
add_timing: bool,
) -> Module<'a> {
let builder = context.create_builder();

Expand Down Expand Up @@ -1501,7 +1501,7 @@ pub fn create_module_from_program<'a>(
builder.position_at_end(block);

// When we are in main, start measuring time
if llvm_func.get_name().to_str().unwrap() == "_main" {
if add_timing && llvm_func.get_name().to_str().unwrap() == "_main" {
let ticks_start_name = fresh.fresh_var();
// get_ticks_start is used on x86 and get_ticks is used on arm
#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -1538,7 +1538,7 @@ pub fn create_module_from_program<'a>(
let mut index = 0;
while index < instrs.len() {
// for main, we expect the last instruction to be a print
if llvm_func.get_name().to_str().unwrap() == "_main"
if add_timing && llvm_func.get_name().to_str().unwrap() == "_main"
&& matches!(
instrs[index],
Code::Instruction(Instruction::Effect {
Expand Down Expand Up @@ -1699,7 +1699,9 @@ pub fn create_module_from_program<'a>(
}
});

assert!(added_timing);
if add_timing {
assert!(added_timing);
}

// Add new main function to act as a entry point to the function.
// Sets up arguments for a _main call
Expand Down

0 comments on commit fe255de

Please sign in to comment.