forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for restrict
attribute on function parameters
#26
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,77 @@ | ||
/* { dg-do compile { target x86_64-*-* } } */ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
#include "libgccjit.h" | ||
|
||
/* We don't want set_options() in harness.h to set -O3 to see that the cold | ||
attribute affects the optimizations. */ | ||
#define TEST_ESCHEWS_SET_OPTIONS | ||
static void set_options (gcc_jit_context *ctxt, const char *argv0) | ||
{ | ||
// Set "-O3". | ||
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3); | ||
} | ||
|
||
#define TEST_COMPILING_TO_FILE | ||
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER | ||
#define OUTPUT_FILENAME "output-of-test-restrict.c.s" | ||
#include "harness.h" | ||
|
||
void | ||
create_code (gcc_jit_context *ctxt, void *user_data) | ||
{ | ||
/* Let's try to inject the equivalent of: | ||
void t(int *__restrict__ a, int *__restrict__ b, char *__restrict__ c) { | ||
*a += *c; | ||
*b += *c; | ||
} | ||
*/ | ||
gcc_jit_type *int_type = | ||
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); | ||
gcc_jit_type *pint_type = gcc_jit_type_get_pointer(int_type); | ||
gcc_jit_type *pint_restrict_type = gcc_jit_type_get_restrict(pint_type); | ||
|
||
gcc_jit_type *void_type = | ||
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); | ||
|
||
gcc_jit_param *a = | ||
gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "a"); | ||
gcc_jit_param *b = | ||
gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "b"); | ||
gcc_jit_param *c = | ||
gcc_jit_context_new_param (ctxt, NULL, pint_restrict_type, "c"); | ||
gcc_jit_param *params[3] = {a, b, c}; | ||
|
||
gcc_jit_function *func_t = | ||
gcc_jit_context_new_function (ctxt, NULL, | ||
GCC_JIT_FUNCTION_EXPORTED, | ||
void_type, | ||
"t", | ||
3, params, | ||
0); | ||
|
||
gcc_jit_block *block = gcc_jit_function_new_block (func_t, NULL); | ||
|
||
/* *a += *c; */ | ||
gcc_jit_block_add_assignment_op ( | ||
block, NULL, | ||
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (a), NULL), | ||
GCC_JIT_BINARY_OP_PLUS, | ||
gcc_jit_lvalue_as_rvalue ( | ||
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL))); | ||
/* *b += *c; */ | ||
gcc_jit_block_add_assignment_op ( | ||
block, NULL, | ||
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (b), NULL), | ||
GCC_JIT_BINARY_OP_PLUS, | ||
gcc_jit_lvalue_as_rvalue ( | ||
gcc_jit_rvalue_dereference (gcc_jit_param_as_rvalue (c), NULL))); | ||
|
||
gcc_jit_block_end_with_void_return (block, NULL); | ||
} | ||
|
||
/* { dg-final { jit-verify-output-file-was-created "" } } */ | ||
/* { dg-final { jit-verify-assembler-output "addl %eax, (%rdi) | ||
addl %eax, (%rsi)" } } */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how relevant this is to libgccjit, but we got patches "rejected" because of implementations in header files, despite having existing implementations in the same header file. I see that
get_aligned
andget_vector
are declared here, so I assume there's a correspondingjit-playback.cc
file where the implementation could live? just a little nit but it could help get the patch approved on the GCC sideThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the information! I'll give a try like this and if needed, I'll move the function in the source file. But for the time being, for coherency I'll leave it here. :)