summaryrefslogtreecommitdiff
path: root/yjit_core.h
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2021-04-08 16:40:08 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:33 -0400
commitf6e3f75c2b7503eb89f517c57ac4ea97dc2752b4 (patch)
tree2f93077875cb816937a24568a2ff18e5db3696e5 /yjit_core.h
parent40b329096660c55f9f30069a1b72aec026ee19b1 (diff)
Introduce concept of YJIT instruction operands
Diffstat (limited to 'yjit_core.h')
-rw-r--r--yjit_core.h66
1 files changed, 39 insertions, 27 deletions
diff --git a/yjit_core.h b/yjit_core.h
index e264d89ffa..3830146f7e 100644
--- a/yjit_core.h
+++ b/yjit_core.h
@@ -26,23 +26,20 @@
// Default versioning context (no type information)
#define DEFAULT_CTX ( (ctx_t){ 0 } )
-typedef enum yjit_type_enum
-{
- ETYPE_UNKNOWN = 0,
- ETYPE_NIL,
- ETYPE_FIXNUM,
- ETYPE_ARRAY,
- ETYPE_HASH
- //ETYPE_SYMBOL
- //ETYPE_STRING
-
-} type_enum_t;
-
-/**
-Represent the type of a value (local/stack/self) in YJIT
-*/
+// Represent the type of a value (local/stack/self) in YJIT
typedef struct yjit_type_struct
{
+ enum
+ {
+ ETYPE_UNKNOWN = 0,
+ ETYPE_NIL,
+ ETYPE_FIXNUM,
+ ETYPE_ARRAY,
+ ETYPE_HASH
+ //ETYPE_SYMBOL
+ //ETYPE_STRING
+ };
+
// Value is definitely a heap object
uint8_t is_heap : 1;
@@ -69,18 +66,19 @@ STATIC_ASSERT(val_type_size, sizeof(val_type_t) == 1);
#define TYPE_ARRAY ( (val_type_t){ .is_heap = 1, .type = ETYPE_ARRAY } )
#define TYPE_HASH ( (val_type_t){ .is_heap = 1, .type = ETYPE_HASH } )
-typedef enum yjit_temp_loc
-{
- TEMP_STACK = 0,
- TEMP_SELF,
- TEMP_LOCAL, // Local with index
- //TEMP_CONST, // Small constant (0, 1, 2, Qnil, Qfalse, Qtrue)
-
-} temp_loc_t;
-
+// Potential mapping of a value on the temporary stack to
+// self, a local variable or constant so that we can track its type
typedef struct yjit_temp_mapping
{
- // Where/how is the local stored?
+ enum
+ {
+ TEMP_STACK = 0,
+ TEMP_SELF,
+ TEMP_LOCAL, // Local with index
+ //TEMP_CONST, // Small constant (0, 1, 2, Qnil, Qfalse, Qtrue)
+ };
+
+ // Where/how is the value stored?
uint8_t kind: 2;
// Index of the local variale,
@@ -96,6 +94,20 @@ STATIC_ASSERT(temp_mapping_size, sizeof(temp_mapping_t) == 1);
// Temp value is actually self
#define MAP_SELF ( (temp_mapping_t) { .kind = TEMP_SELF } )
+// Operand to a bytecode instruction
+typedef struct yjit_insn_opnd
+{
+ // Indicates if the value is self
+ bool is_self;
+
+ // Index on the temporary stack (for stack operands only)
+ uint16_t idx;
+
+} insn_opnd_t;
+
+#define OPND_SELF ( (insn_opnd_t){ .is_self = true } )
+#define OPND_STACK(stack_idx) ( (insn_opnd_t){ .is_self = false, .idx = stack_idx } )
+
/**
Code generation context
Contains information we can use to optimize code
@@ -225,8 +237,8 @@ x86opnd_t ctx_stack_push_self(ctx_t* ctx);
x86opnd_t ctx_stack_push_local(ctx_t* ctx, size_t local_idx);
x86opnd_t ctx_stack_pop(ctx_t* ctx, size_t n);
x86opnd_t ctx_stack_opnd(ctx_t* ctx, int32_t idx);
-val_type_t ctx_get_temp_type(const ctx_t* ctx, size_t idx);
-void ctx_set_temp_type(ctx_t* ctx, size_t idx, val_type_t type);
+val_type_t ctx_get_opnd_type(const ctx_t* ctx, insn_opnd_t opnd);
+void ctx_set_opnd_type(ctx_t* ctx, insn_opnd_t opnd, val_type_t type);
void ctx_set_local_type(ctx_t* ctx, size_t idx, val_type_t type);
int ctx_diff(const ctx_t* src, const ctx_t* dst);