-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OpenMP] Do not always emit unused extern variables
Currently, the precense of the OpenMP target declare metadata requires that we always codegen a global declaration. This is undesirable in the case that we could defer or omit this declaration as is common with unused extern variables. This is important as it allows us, in the runtime, to rely on static linking semantics to omit unused symbols so they are not included when the user links it in. This patch changes the check for always emitting these variables. Because of this we also need to extend this logic to the generation of the offloading entries. This has the result of derring the offload entry generation to the canonical definitoin. So we are effectively assuming whoever owns the storage for this variable will perform that operation. This makes an exception for `link` attributes as those require their own special handling. Let me know if this is sound in the implementation, I do not have the largest view of the standards here. Fixes: #64133 Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D156368
- Loading branch information
Showing
4 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %libomptarget-compile-generic -DVAR -c -o %t.o | ||
// RUN: %libomptarget-compile-generic %t.o && %libomptarget-run-generic | %fcheck-generic | ||
|
||
#ifdef VAR | ||
int x = 1; | ||
#else | ||
#include <stdio.h> | ||
#include <assert.h> | ||
extern int x; | ||
|
||
int main() { | ||
int value = 0; | ||
#pragma omp target map(from : value) | ||
value = x; | ||
assert(value == 1); | ||
|
||
x = 999; | ||
#pragma omp target update to(x) | ||
|
||
#pragma omp target map(from : value) | ||
value = x; | ||
assert(value == 999); | ||
|
||
// CHECK: PASS | ||
printf ("PASS\n"); | ||
} | ||
#endif |