Skip to content

Commit

Permalink
Add new class analysis for development
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Mar 25, 2024
1 parent 9fc5978 commit a3e6625
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 18 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ project(meevax

include(GNUInstallDirs)

string(JOIN " " AGGRESSIVE_OPTIMIZATION_OPTIONS
# "-flto" # This optimization causes a SEGV when compiling with Clang 10.
string(JOIN " " ${PROJECT_NAME}_RELEASE_PLUS
# "-fmerge-all-constants" # This optimization is very effective in reducing binary size, but non-standard to the C++ standard.
# "-march=native" # This optimization causes "Illegal instruction" error (is Valgrind's bug) on CI.
# "-mtune=native"
Expand All @@ -22,7 +21,7 @@ string(JOIN " " AGGRESSIVE_OPTIMIZATION_OPTIONS
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS_DEBUG "-Og -gdwarf-4") # NOTE: The `-gdwarf-4` option is set due to the following issues with Clang 14 and Valgrind versions below 3.20: https://bugzilla.mozilla.org/show_bug.cgi?id=1758782
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG ${AGGRESSIVE_OPTIMIZATION_OPTIONS}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -DNDEBUG ${${PROJECT_NAME}_RELEASE_PLUS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-4")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -pipe")
set(CMAKE_CXX_STANDARD 17)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.157_amd64.deb
sudo apt install build/meevax_0.5.158_amd64.deb
```

or
Expand Down Expand Up @@ -123,9 +123,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.157.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.158.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.157_amd64.deb`
| `package` | Generate debian package `meevax_0.5.158_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.157
0.5.158
7 changes: 3 additions & 4 deletions include/meevax/kernel/procedure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ inline namespace kernel
{
std::enable_if_t<std::is_invocable_v<F> or std::is_invocable_v<F, object &>, F> invocable;

template <typename T, typename U>
explicit generic_procedure(T && x, U && y)
: primitive_procedure { std::forward<decltype(x)>(x) }
, invocable { std::forward<decltype(y)>(y) }
explicit generic_procedure(std::string const& name, F invocable)
: primitive_procedure { name }
, invocable { invocable }
{}

auto operator ()(object & xs) const -> object override
Expand Down
14 changes: 7 additions & 7 deletions script/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ quotient()

tsv()
{
printf "script\tMeevax\tChibi-Scheme\tGauche\n"
printf "\tMeevax\tChibi-Scheme\tGauche\n"

for each in $(scripts)
for script in $(scripts)
do
t0=$(real meevax "$root/benchmark/$each.ss")
t1=$(real chibi-scheme "$root/benchmark/$each.ss")
t2=$(real gosh "$root/benchmark/$each.ss")
t0=$(real meevax "$root/benchmark/$script.ss")
t1=$(real chibi-scheme "$root/benchmark/$script.ss")
t2=$(real gosh "$root/benchmark/$script.ss")

printf "%s\t%s\t%s\t%s\n" \
"$each" \
"$script" \
"$t0" \
"$t1 (x$(quotient "$t0" "$t1"))" \
"$t2 (x$(quotient "$t0" "$t2"))"
done
}

tsv | column -t -s"$(printf '\t')"
tsv | column --table --separator "$(printf '\t')"
106 changes: 106 additions & 0 deletions src/kernel/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,107 @@ namespace meevax
{
inline namespace kernel
{
struct analysis
{
static constexpr auto n = 23;

std::size_t adjacencies[n][n] = {};

~analysis()
{
constexpr std::size_t width = 18;

std::cerr << std::string(width, ' ');

for (auto i = 0; i < n; ++i)
{
std::cerr << std::setw(width) << std::right << static_cast<instruction>(i);
}

std::cerr << std::endl;

for (auto i = 0; i < n; ++i)
{
std::cerr << std::setw(width) << std::right << static_cast<instruction>(i);

for (auto j = 0; j < n; ++j)
{
std::cerr << std::setw(width) << std::right << adjacencies[i][j];
}

std::cerr << std::endl;
}
}

auto adjacency(object const& i, object const& j) -> decltype(auto)
{
return adjacencies[static_cast<std::underlying_type_t<instruction>>(i.as<instruction>())]
[static_cast<std::underlying_type_t<instruction>>(j.as<instruction>())];
}
};

auto analyze(object const& c) -> void
{
assert(c.is<pair>());

assert(car(c).is<instruction>());

static auto a = analysis();

switch (car(c).as<instruction>())
{
case instruction::join:
case instruction::tail_call:
case instruction::tail_letrec:
case instruction::return_:
case instruction::stop:
assert(cdr(c).is<null>());
break;

case instruction::call:
case instruction::cons:
case instruction::drop:
case instruction::dummy:
case instruction::letrec:
analyze(cdr(c));
a.adjacency(car(c), cadr(c))++;
break;

case instruction::current:
case instruction::install:
case instruction::load_absolute:
case instruction::load_constant:
case instruction::load_relative:
case instruction::load_variadic:
case instruction::store_absolute:
case instruction::store_relative:
case instruction::store_variadic:
analyze(cddr(c));
a.adjacency(car(c), caddr(c))++;
break;

case instruction::load_closure:
case instruction::load_continuation:
analyze(cadr(c));
analyze(cddr(c));
a.adjacency(car(c), caddr(c))++;
break;

case instruction::select:
analyze(cadr(c));
analyze(caddr(c));
analyze(cdddr(c));
a.adjacency(car(c), cadddr(c))++;
break;

case instruction::tail_select:
assert(cdddr(c).is<null>());
analyze(cadr(c));
analyze(caddr(c));
break;
}
}

auto merge_constants(object & c) -> void
{
assert(c.is<pair>());
Expand Down Expand Up @@ -106,6 +207,11 @@ inline namespace kernel
{
merge_constants(code);

if constexpr (false)
{
analyze(code);
}

return code;
}
} // namespace kernel
Expand Down

0 comments on commit a3e6625

Please sign in to comment.