Skip to content

Commit

Permalink
Revert "Add support for custom allocators"
Browse files Browse the repository at this point in the history
This reverts commit 3d6f36b.
  • Loading branch information
vnmakarov committed Aug 9, 2024
1 parent 2769236 commit 6c23dcb
Show file tree
Hide file tree
Showing 34 changed files with 586 additions and 1,131 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
*.a
/mir-run
/build
/.cache
198 changes: 0 additions & 198 deletions CUSTOM-ALLOCATORS.md

This file was deleted.

5 changes: 2 additions & 3 deletions MIR.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
* MIR API code has an implicit state called by MIR context
* MIR context is represented by data of `MIR_context_t`
* MIR context is created by function `MIR_context_t MIR_init (void)`
* In case you want to use custom allocators, use `MIR_context_t MIR_init2 (MIR_alloc_t, MIR_code_alloc_t)` instead (see [here](CUSTOM-ALLOCATORS.md) for more details)
* Every MIR API function (except for `MIR_init` / `MIR_init2`) requires MIR context passed through the first argument of type `MIR_context_t`
* Every MIR API function (except for `MIR_init`) requires MIR context passed through the first argument of type `MIR_context_t`
* You can use MIR functions in different threads without any synchronization
if they work with different contexts in each thread

## MIR program
* MIR program consists of MIR **modules**
* To start work with MIR program, you should first call API function `MIR_init` / `MIR_init2`
* To start work with MIR program, you should first call API function `MIR_init`
* API function `MIR_finish (MIR_context_t ctx)` should be called last. It frees all internal data used to work with MIR program and all IR (insns, functions, items, and modules) created in this context
* API function `MIR_output (MIR_context_t ctx, FILE *f)` outputs MIR textual representation of the program into given file
* API function `MIR_scan_string (MIR_context_t ctx, const char *str)` reads textual MIR representation given by a string
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
## Disclaimer
* **There is absolutely no warranty that the code will work for any tests except ones given here and on platforms
other than x86_64 Linux/OSX, aarch64 Linux/OSX(Apple M1), and ppc64le/s390x/riscv64 Linux**

## MIR
* MIR is strongly typed IR
* MIR can represent machine 32-bit and 64-bit insns of different architectures
Expand Down Expand Up @@ -178,7 +178,7 @@ ex100: func v, 0
* Running code from the above example could look like the following (here `m1` and `m2` are modules
`m_sieve` and `m_e100`, `func` is function `ex100`, `sieve` is function `sieve`):
```c
/* ctx is a context created by MIR_init / MIR_init2 */
/* ctx is a context created by MIR_init */
MIR_load_module (ctx, m1); MIR_load_module (ctx, m2);
MIR_load_external (ctx, "printf", printf);
MIR_link (ctx, MIR_set_interp_interface, import_resolver);
Expand Down Expand Up @@ -316,8 +316,8 @@ The executable is "configurable" with environment variables:
* Files `mir-gen-x86_64.c`, `mir-gen-aarch64.c`, `mir-gen-ppc64.c`, `mir-gen-s390x.c`,
and `mir-gen-riscv64.c` is machine dependent code of JIT compiler
* Files `mir-<target>.c` contain simple machine dependent code common for interpreter and
JIT compiler
* Files `mir-<target>.h` contain declarations common for interpreter and JIT compiler
JIT compiler
* Files `mir-<target>.h` contain declarations common for interpreter and JIT compiler
* Files `mir2c/mir2c.h` and `mir2c/mir2c.c` contain code for MIR to C compiler. The generated code might be not portable
* Files `c2mir/c2mir.h`, `c2mir/c2mir.c`, `c2mir/c2mir-driver.c`, and `c2mir/mirc.h` contain code for
C to MIR compiler. Files in directories `c2mir/x86_64` and `c2mir/aarch64`, `c2mir/ppc64`, `c2mir/s390x`,
Expand Down Expand Up @@ -346,7 +346,7 @@ The executable is "configurable" with environment variables:
[1] is based on wall time of compilation of C sieve code (w/o any include file and with
using memory file system for GCC) and the corresponding MIR sieve code by MIR-interpreter
and MIR-generator with optimization level 2

[2] is based on the best wall time of 10 runs with used MIR-generator optimization level 2

[3] is based on stripped sizes of cc1 for GCC and MIR core and interpreter or generator for MIR
Expand Down Expand Up @@ -388,7 +388,7 @@ The executable is "configurable" with environment variables:
* wasi LLVM is a C to webassember clang compiler (11.0.0) with wasmer (1.0.2) based on LLVM backend
* wasi singlepass is a C to webassember clang compiler (11.0.0) with wasmer (1.0.2) based on singlepass backend
* wasi wasmtime is a C to webassember clang compiler (11.0.0) with wasmtime (0.26.0) runtime based on cranelift backend

| | Average | Geomean |
|--------------------------------------------------|-----------|-----------|
| gcc -O2 | 1.00 | 1.00 |
Expand Down
12 changes: 4 additions & 8 deletions adt-tests/mir-bitmap-test.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#include "mir-bitmap.h"
#include "mir-alloc.h"

#include "mir-alloc-default.c"

int main (void) {
MIR_alloc_t alloc = &default_alloc;
int status;
bitmap_t b1, b2, b3, b4;

b1 = bitmap_create (alloc);
b2 = bitmap_create (alloc);
b3 = bitmap_create (alloc);
b4 = bitmap_create (alloc);
b1 = bitmap_create ();
b2 = bitmap_create ();
b3 = bitmap_create ();
b4 = bitmap_create ();
status = bitmap_empty_p (b1);
status &= bitmap_bit_count (b1) == 0;

Expand Down
8 changes: 1 addition & 7 deletions adt-tests/mir-htab-test.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include "mir-htab.h"
#include "mir-alloc.h"

#include "mir-alloc-default.c"

static int status = 1;

Expand All @@ -27,14 +24,11 @@ static void add (int i, void *arg) {
(*sum) += i;
}



int main (void) {
MIR_alloc_t alloc = &default_alloc;
int i, collisions, iter, tab_el;
HTAB (int) * htab;

HTAB_CREATE_WITH_FREE_FUNC (int, htab, alloc, 4, hash, eq, f, ARG);
HTAB_CREATE_WITH_FREE_FUNC (int, htab, 4, hash, eq, f, ARG);
status &= HTAB_ELS_NUM (int, htab) == 0;
for (iter = 0; iter < 10; iter++) {
for (i = 0; i < 100; i++) {
Expand Down
14 changes: 5 additions & 9 deletions adt-tests/mir-reduce-test.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include <stdio.h>
#include "mir-alloc.h"
#include "mir-reduce.h"
#include "mir-varr.h"
#include "real-time.h"

#include "mir-alloc-default.c"

DEF_VARR (uint8_t);
static VARR (uint8_t) * orig, *buf1, *buf2;

Expand Down Expand Up @@ -46,26 +43,25 @@ static size_t writer2 (const void *start, size_t len, void *aux_data) {
}

int main (int argc, const char *argv[]) {
MIR_alloc_t alloc = &default_alloc;
size_t i, n;
double start = real_usec_time ();

if (argc != 2 || (input_file = fopen (argv[1], "rb")) == NULL) {
fprintf (stderr, "usage: %s <inputfile>\n", argv[0]);
return 1;
}
VARR_CREATE (uint8_t, orig, alloc, 0);
VARR_CREATE (uint8_t, buf1, alloc, 0);
if (!reduce_encode (alloc, reader1, writer1, NULL)) {
VARR_CREATE (uint8_t, orig, 0);
VARR_CREATE (uint8_t, buf1, 0);
if (!reduce_encode (reader1, writer1, NULL)) {
fprintf (stderr, "Error in reducing input file!\n");
return 1;
}
fprintf (stderr, "Compression: original len = %llu, result = %llu, ration=%.2f, time=%.2fms\n",
(unsigned long long) input_length1, (unsigned long long) output_length1,
(input_length1 + 0.0) / output_length1, (real_usec_time () - start) / 1000.0);
VARR_CREATE (uint8_t, buf2, alloc, 0);
VARR_CREATE (uint8_t, buf2, 0);
start = real_usec_time ();
if (!reduce_decode (alloc, reader2, writer2, NULL)) {
if (!reduce_decode (reader2, writer2, NULL)) {
fprintf (stderr, "Corrupted input file!\n");
return 1;
}
Expand Down
6 changes: 1 addition & 5 deletions adt-tests/mir-varr-test.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#include "mir-alloc.h"
#include "mir-varr.h"

#include "mir-alloc-default.c"

DEF_VARR (int);
int main (void) {
MIR_alloc_t alloc = &default_alloc;
int status, elem;
VARR (int) * test;
size_t ind;
int arr[] = {1, 2, 3};

VARR_CREATE (int, test, alloc, 0);
VARR_CREATE (int, test, 0);
status = VARR_LENGTH (int, test) == 0;
VARR_PUSH (int, test, 42);
status &= VARR_LAST (int, test) == 42;
Expand Down
Loading

0 comments on commit 6c23dcb

Please sign in to comment.