ISLE: Common accessors for some insn data fields (#3781)

Add accessors to prelude.isle to access data fields of
`func_addr` and `symbol_value` instructions.

These are based on similar versions I had added to the s390x
back-end, but are a bit more straightforward to use.

- func_ref_data: Extract SigRef, ExternalName, and RelocDistance
  fields given a FuncRef.

- symbol_value_data: Extract ExternalName, RelocDistance, and
  offset fields given a GlobalValue representing a Symbol.

- reloc_distance_near: Test for RelocDistance::Near.

The s390x back-end is changed to use these common versions.

Note that this exposed a bug in common isle code: This extractor:

(extractor (load_sym inst)
  (and inst
       (load _ (def_inst (symbol_value
                           (symbol_value_data _
                             (reloc_distance_near) offset)))
               (i64_from_offset
                 (memarg_symbol_offset_sum <offset _)))))

would raise an assertion in sema.rs due to a supposed cycle in
extractor definitions.  But there was no actual cycle, it was
simply that the extractor tree refers twice to the `insn_data`
extractor (once via the `load` and once via the `symbol_value`
extractor).  Fixed by checking for pre-existing definitions only
along one path in the tree, not across the whole tree.
This commit is contained in:
Ulrich Weigand
2022-02-09 02:57:27 +01:00
committed by GitHub
parent 9c5c872b3b
commit 10198553c7
13 changed files with 960 additions and 883 deletions

View File

@@ -1156,27 +1156,23 @@
;;;; Rules for `func_addr` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load the address of a function, target reachable via PC-relative instruction.
(rule (lower (and (func_addr _)
(call_target_data name (reloc_distance_near))))
(rule (lower (func_addr (func_ref_data _ name (reloc_distance_near))))
(value_reg (load_addr (memarg_symbol name 0 (memflags_trusted)))))
;; Load the address of a function, general case.
(rule (lower (and (func_addr _)
(call_target_data name _)))
(rule (lower (func_addr (func_ref_data _ name _)))
(value_reg (load_ext_name_far name 0)))
;;;; Rules for `symbol_value` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load the address of a symbol, target reachable via PC-relative instruction.
(rule (lower (and (symbol_value _)
(symbol_value_data name (reloc_distance_near)
(memarg_symbol_offset offset))))
(rule (lower (symbol_value (symbol_value_data name (reloc_distance_near)
(memarg_symbol_offset offset))))
(value_reg (load_addr (memarg_symbol name offset (memflags_trusted)))))
;; Load the address of a symbol, general case.
(rule (lower (and (symbol_value _)
(symbol_value_data name _ offset)))
(rule (lower (symbol_value (symbol_value_data name _ offset)))
(value_reg (load_ext_name_far name offset)))