[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 279/437: Implement and document the new jit_indirect cal
From: |
Andy Wingo |
Subject: |
[Guile-commits] 279/437: Implement and document the new jit_indirect call. |
Date: |
Mon, 2 Jul 2018 05:14:36 -0400 (EDT) |
wingo pushed a commit to branch lightning
in repository guile.
commit a9433b5a2c8dd811e812cc42fb7ea8451da3342b
Author: pcpa <address@hidden>
Date: Thu Mar 6 18:20:29 2014 -0300
Implement and document the new jit_indirect call.
* include/lightning.h, lib/lightning.c: Add the new
jit_indirect() call, that returns a special label node,
and tells lightning that the label may be the target of
an indirect jump.
* doc/body.texi: Document the new jit_indirect() call, and
add examples of different ways to create labels and branches.
---
ChangeLog | 10 +++++++++
doc/body.texi | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
include/lightning.h | 2 ++
lib/lightning.c | 16 +++++++++++++-
4 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d5a24a9..1acc32f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-06-03 Paulo Andrade <address@hidden>
+
+ * include/lightning.h, lib/lightning.c: Add the new
+ jit_indirect() call, that returns a special label node,
+ and tells lightning that the label may be the target of
+ an indirect jump.
+
+ * doc/body.texi: Document the new jit_indirect() call, and
+ add examples of different ways to create labels and branches.
+
2014-23-02 Paulo Andrade <address@hidden>
* lib/jit_x86.c: Rewrite previous patch to inline save/restore
diff --git a/doc/body.texi b/doc/body.texi
index 91ce9d7..ab75f75 100644
--- a/doc/body.texi
+++ b/doc/body.texi
@@ -22,7 +22,7 @@ both retargetable and very fast.
@menu
* Overview:: What GNU lightning is
* Installation:: Configuring and installing GNU lightning
-* The instruction set:: The RISC instruction set used i GNU lightning
+* The instruction set:: The RISC instruction set used in GNU lightning
* GNU lightning examples:: GNU lightning's examples
* Reentrancy:: Re-entrant usage of GNU lightning
* Acknowledgements:: Acknowledgements for GNU lightning
@@ -501,6 +501,66 @@ Like branch instruction, @code{jmpi} also returns a value
which is to
be used to compile forward branches. @xref{Fibonacci, , Fibonacci
numbers}.
address@hidden Labels
+There are 3 @lightning{} instructions to create labels:
address@hidden
+label (not specified) @r{simple label}
+forward (not specified) @r{forward label}
+indirect (not specified) @r{special simple label}
address@hidden example
+
address@hidden is normally used as @code{patch_at} argument for backward
+jumps.
+
address@hidden
+ jit_node_t *jump, *label;
+label = jit_label();
+ ...
+ jump = jit_beqr(JIT_R0, JIT_R1);
+ jit_patch_at(jump, label);
address@hidden example
+
address@hidden is used to patch code generation before the actual
+position of the label is known.
+
address@hidden
+ jit_node_t *jump, *label;
+label = jit_forward();
+ jump = jit_beqr(JIT_R0, JIT_R1);
+ jit_patch_at(jump, label);
+ ...
+ jit_link(label);
address@hidden example
+
address@hidden is useful when creating jump tables, and tells
address@hidden to not optimize out a label that is not the target of
+any jump, because an indirect jump may land where it is defined.
+
address@hidden
+ jit_node_t *jump, *label;
+ ...
+ jmpr(JIT_R0); @rem{/* may jump to label */}
+ ...
+label = jit_indirect();
address@hidden example
+
address@hidden is an special case of @code{note} and @code{name}
+because it is a valid argument to @code{address}.
+
+Note that the usual idiom to write the previous example is
address@hidden
+ jit_node_t *addr, *jump;
+addr = jit_movi(JIT_R0, 0); @rem{/* immediate is ignored */}
+ ...
+ jmpr(JIT_R0);
+ ...
+ jit_patch(addr); @rem{/* implicit label added */}
address@hidden example
+
+that automatically binds the implicit label added by @code{patch} with
+the @code{movi}, but on some special conditions it is required to create
+an "unbound" label.
+
@item Function prolog
These macros are used to set up a function prolog. The @code{allocai}
diff --git a/include/lightning.h b/include/lightning.h
index 9fab138..758f760 100644
--- a/include/lightning.h
+++ b/include/lightning.h
@@ -174,6 +174,7 @@ typedef enum {
#define jit_note(u, v) _jit_note(_jit, u, v)
#define jit_label() _jit_label(_jit)
#define jit_forward() _jit_forward(_jit)
+#define jit_indirect() _jit_indirect(_jit)
#define jit_link(u) _jit_link(_jit,u)
jit_code_note, jit_code_label,
@@ -841,6 +842,7 @@ extern jit_node_t *_jit_name(jit_state_t*, char*);
extern jit_node_t *_jit_note(jit_state_t*, char*, int);
extern jit_node_t *_jit_label(jit_state_t*);
extern jit_node_t *_jit_forward(jit_state_t*);
+extern jit_node_t *_jit_indirect(jit_state_t*);
extern void _jit_link(jit_state_t*, jit_node_t*);
extern void _jit_prolog(jit_state_t*);
diff --git a/lib/lightning.c b/lib/lightning.c
index de93e9f..e0adeda 100644
--- a/lib/lightning.c
+++ b/lib/lightning.c
@@ -548,7 +548,10 @@ _jit_address(jit_state_t *_jit, jit_node_t *node)
{
assert(_jitc->done);
assert(node &&
- (node->code == jit_code_note || node->code == jit_code_name));
+ /* If a node type that is documented to be a fixed marker */
+ (node->code == jit_code_note || node->code == jit_code_name ||
+ /* If another special fixed marker, returned by jit_indirect() */
+ (node->code == jit_code_label && (node->flag & jit_flag_use))));
return ((jit_pointer_t)node->u.w);
}
@@ -1083,6 +1086,17 @@ _jit_forward(jit_state_t *_jit)
return (jit_new_node_no_link(jit_code_label));
}
+jit_node_t *
+_jit_indirect(jit_state_t *_jit)
+{
+ jit_node_t *node;
+
+ node = jit_label();
+ node->flag |= jit_flag_use;
+
+ return (node);
+}
+
void
_jit_link(jit_state_t *_jit, jit_node_t *node)
{
- [Guile-commits] 309/437: Do not fail if NULL is passed to init_jit., (continued)
- [Guile-commits] 309/437: Do not fail if NULL is passed to init_jit., Andy Wingo, 2018/07/02
- [Guile-commits] 225/437: Second alpha release 1.99a, Andy Wingo, 2018/07/02
- [Guile-commits] 243/437: IA64: Correct code to save/restore r2 used as lightning JIT_FP., Andy Wingo, 2018/07/02
- [Guile-commits] 348/437: S390: Replace s390x filenames with s390, Andy Wingo, 2018/07/02
- [Guile-commits] 376/437: Correct update of on stack vararg double argument pointer, Andy Wingo, 2018/07/02
- [Guile-commits] 378/437: arm: Add initial jit_va_ calls to arm, Andy Wingo, 2018/07/02
- [Guile-commits] 387/437: alpha: Add initial jit_va_ calls to alpha, Andy Wingo, 2018/07/02
- [Guile-commits] 263/437: ARM: Correct wrong offset for load/store of floats., Andy Wingo, 2018/07/02
- [Guile-commits] 317/437: Add the new "range" test., Andy Wingo, 2018/07/02
- [Guile-commits] 174/437: Correct off by one label/note name and add align argument to jit_data, Andy Wingo, 2018/07/02
- [Guile-commits] 279/437: Implement and document the new jit_indirect call.,
Andy Wingo <=
- [Guile-commits] 143/437: Correct testcases in the mips backend., Andy Wingo, 2018/07/02
- [Guile-commits] 322/437: Add assertion to check for register allocation leaks, Andy Wingo, 2018/07/02
- [Guile-commits] 257/437: Correct misplaced check for already visited blocks, Andy Wingo, 2018/07/02
- [Guile-commits] 301/437: GNU lightning 2.0.5 release, Andy Wingo, 2018/07/02
- [Guile-commits] 206/437: Correct jit implementation to pass several test cases., Andy Wingo, 2018/07/02
- [Guile-commits] 297/437: Do not filter -sz.c files in gitignore, Andy Wingo, 2018/07/02
- [Guile-commits] 255/437: IA64: Force sync of instructions in get-jit-size build mode., Andy Wingo, 2018/07/02
- [Guile-commits] 306/437: x86: Build and pass all tests under cygwin64 (Windows x64), Andy Wingo, 2018/07/02
- [Guile-commits] 352/437: Update documentation, Andy Wingo, 2018/07/02
- [Guile-commits] 357/437: Make more readable always true test, Andy Wingo, 2018/07/02