public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Hack to investigate work required for Hybrid capabilities
@ 2022-05-05 12:04 Matthew Malcomson
0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-05 12:04 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f67875053959be76f8437b453f4674faecd0409c
commit f67875053959be76f8437b453f4674faecd0409c
Author: Matthew Malcomson <matthew.malcomson@arm.com>
Date: Thu Mar 17 15:46:40 2022 +0000
Hack to investigate work required for Hybrid capabilities
This patch introduces a `-ffake-hybrid` flag. That flag randomly turns
non-capability pionters into __capability pointers. This enables
simulating Hybrid Morello code using C code not written for that target.
Having that hack enables testing Hybrid functionality on our GCC
testsuite. This can be done for both Hybrid Morello *and* for hybrid
fake-capability. Having both means we can still use stock AArch64
machines for faster turnaround, and can use Morello environments to
double-check our codegen.
Diff:
---
gcc/c-family/c-common.c | 20 ++++++++++++++++++++
gcc/c-family/c-common.h | 1 +
gcc/c/c-convert.c | 3 +++
gcc/c/c-decl.c | 9 +++++++++
gcc/common.opt | 9 +++++++++
gcc/config/aarch64/aarch64.c | 3 +++
6 files changed, 45 insertions(+)
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 11195e16576..6bba7c392d1 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -2679,6 +2679,26 @@ c_common_cap_from_noncap (tree type, tree expr)
return ret;
}
+/* Generate a cast from a non-capability pointer to a capability pointer.
+ As above, this cast will necessarily create a pointer that does not have
+ valid metadata. */
+tree
+c_common_cap_from_ptr (tree type, tree ptr_expr)
+{
+ gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr_expr))
+ && capability_type_p (type));
+ /* MORELLO TODO address spaces.
+ * Need to do special handling for capabilities, but also need to do special
+ * handling for address spaces, capability handling is usually done in
+ * frontend while address space handling is usually done in generic code
+ * `convert_to_pointer_1`. */
+ gcc_assert (TYPE_ADDR_SPACE (TREE_TYPE (type))
+ == TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (ptr_expr))));
+ tree int_expr = convert (noncapability_type (type), ptr_expr);
+ return c_common_cap_from_noncap (type, int_expr);
+}
+
+
/* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
tree
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 363f8d5bc77..88535e28feb 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -861,6 +861,7 @@ extern tree c_common_unsigned_type (tree);
extern tree c_common_signed_type (tree);
extern tree c_common_signed_or_unsigned_type (int, tree);
extern tree c_common_cap_from_noncap (tree, tree);
+extern tree c_common_cap_from_ptr (tree, tree);
extern void c_common_init_ts (void);
extern tree c_build_bitfield_integer_type (unsigned HOST_WIDE_INT, int);
extern enum conversion_safety unsafe_conversion_p (tree, tree, tree, bool);
diff --git a/gcc/c/c-convert.c b/gcc/c/c-convert.c
index 3edd7ebe73a..3f763e8aaed 100644
--- a/gcc/c/c-convert.c
+++ b/gcc/c/c-convert.c
@@ -145,6 +145,9 @@ convert (tree type, tree expr)
case REFERENCE_TYPE:
if (capability_type_p (type) && TREE_CODE (TREE_TYPE (e)) == INTEGER_TYPE)
ret = c_common_cap_from_noncap (type, e);
+ else if (capability_type_p (type) && !capability_type_p (TREE_TYPE (e))
+ && POINTER_TYPE_P (TREE_TYPE (e)))
+ ret = c_common_cap_from_ptr (type, e);
else
ret = convert_to_pointer (type, e);
goto maybe_fold;
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index e45f7c054f2..83a720c34dd 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -6984,6 +6984,15 @@ grokdeclarator (const struct c_declarator *declarator,
type_quals = declarator->u.pointer_quals;
declarator = declarator->declarator;
+ if (flag_fake_hybrid
+ && (rand() % flag_fake_hybrid) == 0)
+ {
+ capability_levels_in_declarator++;
+ tree attr_name = get_identifier ("cheri_capability");
+ // tree attr_args = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
+ tree new_attrs = tree_cons (attr_name, NULL_TREE, returned_attrs);
+ returned_attrs = decl_attributes (&type, new_attrs, ATTR_FLAG_CHERI_INNER_APPLY);
+ }
break;
}
default:
diff --git a/gcc/common.opt b/gcc/common.opt
index 4e254f25100..a874b24842a 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -172,6 +172,9 @@ int rtl_dump_and_exit
Variable
int flag_print_asm_name
+Variable
+int flag_fake_hybrid
+
; Name of top-level original source file (what was input to cpp).
; This comes from the #-command at the beginning of the actual input.
; If there isn't any there, then this is the cc1 input file name.
@@ -1218,6 +1221,12 @@ fdbg-cnt=
Common RejectNegative Joined Var(common_deferred_options) Defer
-fdbg-cnt=<counter>[:<lower_limit1>-]<upper_limit1>[:<lower_limit2>-<upper_limit2>:...][,<counter>:...] Set the debug counter limit.
+ffake-hybrid=
+Common Joined RejectNegative UInteger Var(flag_fake_hybrid) Init(0)
+Choose to do some fake hybrid capability stuff.
+This is largely in order to explore whether using hybrid capabilities will
+cause a lot of problems or not.
+
fdebug-prefix-map=
Common Joined RejectNegative Var(common_deferred_options) Defer
-fdebug-prefix-map=<old>=<new> Map one directory name to another in debug information.
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 89840e54990..05b78dac74c 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -74,6 +74,7 @@
#include "intl.h"
#include "expmed.h"
#include "function-abi.h"
+#include "toplev.h"
/* This file should be included last. */
#include "target-def.h"
@@ -15155,6 +15156,8 @@ aarch64_override_options_internal (struct gcc_options *opts)
error ("MORELLO TODO OpenACC has not been implemented for Morello");
if (!flag_inline_atomics && TARGET_CAPABILITY_ANY)
error ("MORELLO TODO -fno-inline-atomics has not been implemented for Morello");
+ if (flag_fake_hybrid)
+ srand(get_random_seed(false));
if (TARGET_CAPABILITY_ANY && TARGET_SVE)
error ("SVE is not supported with capabilities");
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-05 12:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 12:04 [gcc(refs/vendors/ARM/heads/morello)] Hack to investigate work required for Hybrid capabilities Matthew Malcomson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).