#!/bin/bash

llvm_path="<llvm_path>"
clang="$llvm_path/bin/clang"
opt="$llvm_path/bin/opt"
llc="$llvm_path/bin/llc"
llvmlink="$llvm_path/bin/llvm-link"

dumpfeat="$llvm_path/bin/opt"

#benchpath=$1
ir_file=$1
IR_DIR=$(dirname $ir_file)
BENCH_DIR=$(dirname $IR_DIR)
REMARKS_DIR=$BENCH_DIR/remarks
FEAT_DIR=$BENCH_DIR/features

#source $benchpath/configs.sh
pipeline=$2

$dumpfeat -passes=dump-feature $ir_file -disable-output
#$dumpfeat -load-pass-plugin <project_path>/external/lib/lib/libLLVMDumpFeaturePass.so -passes=dump-feature $ir_file -disable-output

mv ./features.csv $FEAT_DIR/origin.csv

$opt -S -passes="$pipeline" $ir_file -o $IR_DIR/o3.ll -pass-remarks='.*' -pass-remarks-missed='.*' -pass-remarks-analysis='.*' -pass-remarks-output="$REMARKS_DIR/o3.remarks.yaml" > /dev/null 2>&1
$opt $ir_file -disable-output -passes=dot-callgraph
#python3 ./scripts/input_schema_gen.py ./test/features
#python3 ./scripts/merge_remarks.py