Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 5047386
  • /
  • gen-freq-estimate.sh
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:c0796d414dc2dab47b8d18a52fd9448becb8c55b
directory badge
swh:1:dir:50473866082fc18b42173bdb06907d59a8383528

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
gen-freq-estimate.sh
#!/bin/bash

DIR=$(dirname $0)
ROOT=$DIR/..
BIN=$ROOT/build/Release+Asserts/bin
LIB=$ROOT/build/Release+Asserts/lib
SCAF=$LIB/Scaffold.so
OPT=$BIN/opt
CLANG=$BIN/clang
LLVM_LINK=$BIN/llvm-link
LLI=$BIN/lli
I_FLAGS="-I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include"

for f in $*; do
  b=$(basename $f .scaffold)  
  b_dir=$(dirname "$(readlink -f $f)")
  echo "[gen-freq-estimate.sh] $b: Creating output directory"
  mkdir -p "$b"

  echo "[gen-freq-estimate.sh] Compiling frequency-estimation-hybrid.c" >&2
  $CLANG -c -O1 -emit-llvm frequency-estimation-hybrid.c -o frequency-estimation-hybrid.bc

  # if: file is compiled before (possibly flattened/unrolled/cloned also), use that compiled .ll file.
  # else: do simple compilation to get .ll file (without any flattening/unrolling/cloning)    
  if [ -e ${b}/${b}.ll ]; then
    echo "[gen-freq-estimate.sh] Using previously compiled ${b}/${b}.ll as ${b}/${b}_dynamic.ll"
    cp ${b}/${b}.ll ${b}/${b}_dynamic.ll
  else
    echo "[gen-freq-estimate.sh] Simple compiling of ${f} into ${b}/${b}_dynamic.ll" >&2
    $CLANG -c -emit-llvm $I_FLAGS -I$b_dir ${f} -o ${b}/${b}.ll
    cp ${b}/${b}.ll ${b}/${b}_dynamic.ll    
  fi
  
  echo "[gen-freq-estimate.sh] Decomposing Toffolis" >&2
  $OPT -S -load $SCAF -ToffoliReplace ${b}/${b}_dynamic.ll -o ${b}/${b}_dynamic.ll

  echo "[gen-freq-estimate.sh] Identifying Loops to retain..." >&2
  $OPT -S -mem2reg -instcombine -loop-simplify -loop-rotate -indvars ${b}/${b}_dynamic.ll -o ${b}/${b}_marked.ll

  echo "[gen-freq-estimate.sh] Rolling up Loops" >&2
  $OPT -S -load $SCAF -dyn-rollup-loops ${b}/${b}_marked.ll -o ${b}/${b}_rolled.ll

  echo "[gen-freq-estimate.sh] Linking frequency-estimation-hybrid.bc and ${b}/${b}_rolled.ll" >&2
  $LLVM_LINK frequency-estimation-hybrid.bc ${b}/${b}_rolled.ll -S -o=${b}/${b}_linked.ll

  echo "[gen-freq-estimate.sh] Instrumenting ${b}/${b}_linked.ll" >&2
  $OPT -S -load $SCAF -runtime-frequency-estimation-hybrid ${b}/${b}_linked.ll -o ${b}/${b}_instr.ll

  $OPT -S -dce -dse -dce ${b}/${b}_instr.ll -o ${b}/${b}_instr2.ll

  $OPT -S -O1 ${b}/${b}_instr2.ll -o ${b}/${b}_instr.ll

  echo "[gen-freq-estimate.sh] Executing ${b}/${b}_instr.ll with lli" >&2
  $LLI ${b}/${b}_instr.ll > ${b}/${b}.freq

  echo "[gen-freq-estimate.sh] Frequency estimates written to ${b}.freq"
  rm frequency-estimation-hybrid.bc ${b}/${b}_dynamic.ll ${b}/${b}_marked.ll ${b}/${b}_rolled.ll ${b}/${b}_linked.ll ${b}/${b}_instr.ll ${b}/${b}_instr2.ll
done

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API