Skip to content

Commit

Permalink
Merge commit '26095fd01232061de9f79decb3e8222ef7b46191' into HEAD [#29]
Browse files Browse the repository at this point in the history
Incorporate the original commit 26095fd
"Ensure :VAR_MAP and :FUNC_MAP are output in order", and add a test case.
  • Loading branch information
tschwinge committed Sep 4, 2023
2 parents 934cb47 + 26095fd commit 1b5946d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
14 changes: 11 additions & 3 deletions nvptx-as.cc
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,21 @@ static Token *
parse_file (htab_t symbol_table, Token *tok)
{
Stmt *comment = 0;
bool is_decl = false;

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

while (tok->kind == K_comment)
tok++;
{
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;
tok++;
}
comment = alloc_comment (start, tok);
comment->vis |= V_prefix_comment;
}
Expand All @@ -721,7 +729,6 @@ parse_file (htab_t symbol_table, Token *tok)
{
unsigned vis = 0;
symbol *def = 0;
unsigned is_decl = 0;
Token *start, *def_token = 0;

for (start = tok;
Expand All @@ -737,7 +744,8 @@ parse_file (htab_t symbol_table, Token *tok)
else if (is_keyword (tok, "visible"))
vis |= V_global;
else if (is_keyword (tok, "extern"))
is_decl = 1;
/*TODO It's not clear why '.extern' are handled via 'decls' instead of via 'symbol_table'. */
is_decl = true;
else if (is_keyword (tok, "weak"))
vis |= V_weak;
if (tok->kind == '(')
Expand Down
43 changes: 43 additions & 0 deletions test/as/order-1.o.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Based on offloading-compilation artifact 'a.xnvptx-none.mkoffload.s' of <https://gcc.gnu.org/PR100059> "[OpenMP] wrong code with 'declare target link' and a scalar variable".
// BEGIN PREAMBLE
.version 3.1
.target sm_35
.address_size 64
// END PREAMBLE
// BEGIN GLOBAL FUNCTION DECL: update
.visible .func update;
// BEGIN FUNCTION DECL: main$_omp_fn$0$impl
.func main$_omp_fn$0$impl (.param .u64 %in_ar0);
//:FUNC_MAP "main$_omp_fn$0"
//:VAR_MAP "i$linkptr"
// BEGIN GLOBAL VAR DEF: i$linkptr
.visible .global .align 8 .u64 i$linkptr[1];
//:VAR_MAP "b$linkptr"
// BEGIN GLOBAL VAR DEF: b$linkptr
.visible .global .align 8 .u64 b$linkptr[1];
//:VAR_MAP "c$linkptr"
// BEGIN GLOBAL VAR DEF: c$linkptr
.visible .global .align 8 .u64 c$linkptr[1];
//:VAR_MAP "a$linkptr"
// BEGIN GLOBAL VAR DEF: a$linkptr
.visible .global .align 8 .u64 a$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
.extern .shared .u64 __nvptx_stacks[32];
// BEGIN GLOBAL VAR DECL: __nvptx_uni
.extern .shared .u32 __nvptx_uni[32];
// BEGIN GLOBAL FUNCTION DEF: update
.visible .func update
{
// [...]
}
.visible .entry main$_omp_fn$0 (.param .u64 %arg, .param .u64 %stack, .param .u64 %sz)
{
// [...]
}
// BEGIN FUNCTION DEF: main$_omp_fn$0$impl
.func main$_omp_fn$0$impl (.param .u64 %in_ar0)
{
// [...]
}
57 changes: 57 additions & 0 deletions test/as/order-1.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Based on offloading-compilation artifact 'a.xnvptx-none.mkoffload.s' of <https://gcc.gnu.org/PR100059> "[OpenMP] wrong code with 'declare target link' and a scalar variable".

// BEGIN PREAMBLE
.version 3.1
.target sm_35
.address_size 64
// END PREAMBLE


// BEGIN GLOBAL FUNCTION DECL: update
.visible .func update;

// BEGIN GLOBAL FUNCTION DEF: update
.visible .func update
{
// [...]
}
.visible .entry main$_omp_fn$0 (.param.u64 %arg, .param.u64 %stack, .param.u64 %sz)
{
// [...]
}

// BEGIN FUNCTION DECL: main$_omp_fn$0$impl
.func main$_omp_fn$0$impl (.param.u64 %in_ar0);

// BEGIN FUNCTION DEF: main$_omp_fn$0$impl
.func main$_omp_fn$0$impl (.param.u64 %in_ar0)
{
// [...]
}
//:FUNC_MAP "main$_omp_fn$0"
//:VAR_MAP "i$linkptr"


// BEGIN GLOBAL VAR DEF: i$linkptr
.visible .global .align 8 .u64 i$linkptr[1];
//:VAR_MAP "b$linkptr"

// BEGIN GLOBAL VAR DEF: b$linkptr
.visible .global .align 8 .u64 b$linkptr[1];
//:VAR_MAP "c$linkptr"

// BEGIN GLOBAL VAR DEF: c$linkptr
.visible .global .align 8 .u64 c$linkptr[1];
//:VAR_MAP "a$linkptr"

// BEGIN GLOBAL VAR DEF: a$linkptr
.visible .global .align 8 .u64 a$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
.extern .shared .u64 __nvptx_stacks[32];

// BEGIN GLOBAL VAR DECL: __nvptx_uni
.extern .shared .u32 __nvptx_uni[32];
5 changes: 5 additions & 0 deletions test/as/order-1.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<https://github.com/MentorEmbedded/nvptx-tools/pull/29> "Ensure :VAR_MAP and :FUNC_MAP are output in order"
<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.s -o %t
RUN: cmp %S/order-1.o.golden %t

0 comments on commit 1b5946d

Please sign in to comment.