Skip to content

Commit

Permalink
Ensure :VAR_MAP and :FUNC_MAP are output in order, part II [#29]
Browse files Browse the repository at this point in the history
Fix the 'as' issue described in commit 3f67564
"Ensure :VAR_MAP and :FUNC_MAP are output in order: add more test cases [#29]"
by handling '//:VAR_MAP', '//:FUNC_MAP' as stand-alone directives
instead of 'V_comment | V_prefix_comment'.

This also happens to unify the x86_64-linux-gnu, powerpc64le-linux-gnu
'test/as/order-1-{x86_64-linux-gnu,powerpc64le-linux-gnu}.o' as well as
'test/as/order-2-{x86_64-linux-gnu,powerpc64le-linux-gnu}.o' files.
  • Loading branch information
tschwinge committed Sep 6, 2023
1 parent 3f67564 commit aa3404a
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 83 deletions.
29 changes: 22 additions & 7 deletions nvptx-as.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,26 +694,40 @@ static Token *
parse_file (htab_t symbol_table, Token *tok)
{
Stmt *comment = 0;
bool is_decl = false;
bool is_map_directive = false;

if (tok->kind == K_comment)
{
Token *start = tok;

while (tok->kind == K_comment)
{
/* Instead of 'K_comment', a point could be made to have these be
represented as their own 'Kind'. */
if (strncmp (tok->ptr, ":VAR_MAP ", 9) == 0
|| strncmp (tok->ptr, ":FUNC_MAP ", 10) == 0)
/* GCC 'mkoffload's require these to be emitted in order of
appearance; handle via 'decls'. */
is_decl = true;
{
is_map_directive = true;
break;
}
tok++;
}
comment = alloc_stmt (V_comment, start, tok, 0);
comment->vis |= V_prefix_comment;
if (start != tok)
{
comment = alloc_stmt (V_comment, start, tok, 0);
comment->vis |= V_prefix_comment;
}
}

if (tok->kind == K_dotted)
if (is_map_directive)
{
/* GCC 'mkoffload' requires these to be emitted in order of appearance;
handle via 'decls'. */
if (comment)
append_stmt (&decls, comment);
tok = parse_line_nosemi (V_comment, tok, &decls);
}
else if (tok->kind == K_dotted)
{
if (is_keyword (tok, "version")
|| is_keyword (tok, "target")
Expand All @@ -728,6 +742,7 @@ parse_file (htab_t symbol_table, Token *tok)
{
unsigned vis = 0;
symbol *def = 0;
bool is_decl = false;
Token *start, *def_token = 0;

for (start = tok;
Expand Down
43 changes: 0 additions & 43 deletions test/as/order-1-x86_64-linux-gnu.o.golden

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
//:VAR_MAP "b$linkptr"
//:VAR_MAP "c$linkptr"
//:VAR_MAP "a$linkptr"
// BEGIN GLOBAL VAR DEF: i$linkptr
.visible .global .align 8 .u64 i$linkptr[1];
// BEGIN GLOBAL FUNCTION DECL: gomp_nvptx_main
.extern .func gomp_nvptx_main (.param .u64 %in_ar1, .param .u64 %in_ar2);
// BEGIN GLOBAL VAR DECL: __nvptx_stacks
Expand All @@ -23,6 +21,8 @@
.extern .shared .u32 __nvptx_uni[32];
// BEGIN GLOBAL VAR DEF: b$linkptr
.visible .global .align 8 .u64 b$linkptr[1];
// BEGIN GLOBAL VAR DEF: i$linkptr
.visible .global .align 8 .u64 i$linkptr[1];
// BEGIN GLOBAL VAR DEF: c$linkptr
.visible .global .align 8 .u64 c$linkptr[1];
// BEGIN GLOBAL VAR DEF: a$linkptr
Expand Down
12 changes: 8 additions & 4 deletions test/as/order-1.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<https://gcc.gnu.org/PR100059> "[OpenMP] wrong code with 'declare target link' and a scalar variable"

RUN: %target_as_cmd --no-verify %S/order-1-x86_64-linux-gnu.s -o %t
RUN: cmp %S/order-1-x86_64-linux-gnu.o.golden %t
RUN: cmp %S/order-1.o.golden %t

RUN: %target_as_cmd --no-verify %S/order-1-powerpc64le-linux-gnu.s -o %t
RUN: cmp %S/order-1-powerpc64le-linux-gnu.o.golden %t
RUN: cmp %S/order-1.o.golden %t


RUN: %target_as_cmd --no-verify %S/order-2-x86_64-linux-gnu.s -o %t
RUN: cmp %S/order-2-x86_64-linux-gnu.o.golden %t
RUN: cmp %S/order-2.o.golden %t

RUN: %target_as_cmd --no-verify %S/order-2-powerpc64le-linux-gnu.s -o %t
RUN: cmp %S/order-2-powerpc64le-linux-gnu.o.golden %t
RUN: cmp %S/order-2.o.golden %t


RUN: %target_as_cmd --no-verify %S/order-3.s -o %t
RUN: cmp %S/order-3.o.golden %t
27 changes: 0 additions & 27 deletions test/as/order-2-powerpc64le-linux-gnu.o.golden

This file was deleted.

File renamed without changes.
37 changes: 37 additions & 0 deletions test/as/order-3.o.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.version 4.0
.target sm_50
.address_size 64
//:FUNC_MAP "f1.1"
// comment 1
//:FUNC_MAP "f1.2"
//:VAR_MAP "v1"
// comment 2.1
//:FUNC_MAP "f2"
// comment 2.2
//:VAR_MAP "v2"
// The following form is never emitted by GCC, but still happens to be handled here ("by accident"):
//:FUNC_MAP "f3"
// The following form is never emitted by GCC, but still happens to be handled here ("by accident"):
//:FUNC_MAP "f4"
//:VAR_MAP "v4"
.visible .entry e1 ()
{
// [...]
}
.visible .entry e2 ()
{
// [...]
}
.visible .entry e3 ()
{
// [...]
}
.visible .entry e4 ()
{
// [...]
}
//:LABEL_MAP "l5"
.visible .entry e5 ()
{
// [...]
}
42 changes: 42 additions & 0 deletions test/as/order-3.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.version 4.0
.target sm_50
.address_size 64

//:FUNC_MAP "f1.1"
// comment 1
//:FUNC_MAP "f1.2"
//:VAR_MAP "v1"
.visible .entry e1 ()
{
// [...]
}

// comment 2.1
//:FUNC_MAP "f2"
// comment 2.2
//:VAR_MAP "v2"
.visible .entry e2 ()
{
// [...]
}

// The following form is never emitted by GCC, but still happens to be handled here ("by accident"):
/*:FUNC_MAP "f3" */
.visible .entry e3 ()
{
// [...]
}

// The following form is never emitted by GCC, but still happens to be handled here ("by accident"):
/*:FUNC_MAP "f4"
:VAR_MAP "v4" */
.visible .entry e4 ()
{
// [...]
}

//:LABEL_MAP "l5"
.visible .entry e5 ()
{
// [...]
}

0 comments on commit aa3404a

Please sign in to comment.