Skip to content

Commit

Permalink
funcall generates args test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsandler committed Mar 28, 2024
1 parent d089a24 commit 98103aa
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
2 changes: 1 addition & 1 deletion expected_results.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion test_framework/regalloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ class CoalesceTest(NamedTuple):
"fourteen_pseudos_interfere.c": NoSpillTest(),
"track_dbl_arg_registers.c": NoSpillTest(),
"store_pointer_in_register.c": NoSpillTest(),
"funcall_generates_args.c": NoSpillTest(),
"force_spill.c": SpillTest(
max_spilled_instructions=3,
max_spilled_pseudos=1,
Expand Down
5 changes: 3 additions & 2 deletions test_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@
"chapter_20/int_only/no_coalescing/division_uses_ax.c": [
"chapter_20/libraries/util.c"
],
"chapter_20/int_only/with_coalescing/funcall_generates_args.c": [
"chapter_20/libraries/funcall_generates_args_lib.c"
"chapter_20/int_only/no_coalescing/funcall_generates_args.c": [
"chapter_20/libraries/funcall_generates_args_lib.c",
"chapter_20/libraries/util.c"
],
"chapter_20/int_only/no_coalescing/force_spill.c": [
"chapter_20/libraries/util.c"
Expand Down
39 changes: 39 additions & 0 deletions tests/chapter_20/int_only/no_coalescing/funcall_generates_args.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Make sure we recognize that a function uses some parameter-passing registers,
* determined by its declaration. Don't inspect assembly, just validate behavior.
* NOTE: only works as intended after we've implemented register coalescing.
* */

#include "util.h"

// defined in funcall_generates_args_lib,
// exits early with return code -1 if a and b don't have
// the correc values
int f(int a, int b);

int glob = 10;
int x = 0;
int y = 0;
int target(void) {
int a = glob + 1;
int b = glob + 2;
// We'll coalesce a and b with EDI/ESI because they're copied into those
// registers. If we don't recognize that EDI/ESI are live when we call f,
// we'll coalesce the temporaries that hold a * glob and b * glob
// with EDI/ESI too, since we'll generate the following assembly:
// movl %a, %tmp
// imull %glob, %tmp
// movl %tmp, %x
// and similar for y/b
x = a * glob;
y = b * glob;
// validate a and b
f(a, b);
// validate x and y
check_one_int(x, 110);
check_one_int(y, 120);
return 0;
}

int main(void) {
return target();
}
24 changes: 0 additions & 24 deletions tests/chapter_20/int_only/with_coalescing/funcall_generates_args.c

This file was deleted.

18 changes: 17 additions & 1 deletion tests/chapter_20/libraries/funcall_generates_args_lib.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// helper function for funcall_generates_args

#include <stdio.h>
#include <stdlib.h>

// a and b should be 11 and 12
int f(int a, int b) {
return a == 11 && b == 12;
if (a != 11) {
printf("Expected a to be 11 but found %d\n", a);
exit(-1);
}

if (b != 12) {
printf("Expected b to be 12 but found %d\n", b);
exit(-1);
}

return 0;
}

0 comments on commit 98103aa

Please sign in to comment.