2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. _instruction-output:
8 Output of Assembler Instructions
9 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 .. prevent bad page break with this line
13 This describes assembler instruction output.
15 .. c:macro:: REGISTER_NAMES
17 A C initializer containing the assembler's names for the machine
18 registers, each one as a C string constant. This is what translates
19 register numbers in the compiler into assembler language.
21 .. c:macro:: ADDITIONAL_REGISTER_NAMES
23 If defined, a C initializer for an array of structures containing a name
24 and a register number. This macro defines additional names for hard
25 registers, thus allowing the ``asm`` option in declarations to refer
26 to registers using alternate names.
28 .. c:macro:: OVERLAPPING_REGISTER_NAMES
30 If defined, a C initializer for an array of structures containing a
31 name, a register number and a count of the number of consecutive
32 machine registers the name overlaps. This macro defines additional
33 names for hard registers, thus allowing the ``asm`` option in
34 declarations to refer to registers using alternate names. Unlike
35 ``ADDITIONAL_REGISTER_NAMES``, this macro should be used when the
36 register name implies multiple underlying registers.
38 This macro should be used when it is important that a clobber in an
39 ``asm`` statement clobbers all the underlying values implied by the
40 register name. For example, on ARM, clobbering the double-precision
41 VFP register 'd0' implies clobbering both single-precision registers
44 .. c:macro:: ASM_OUTPUT_OPCODE (stream, ptr)
46 Define this macro if you are using an unusual assembler that
47 requires different names for the machine instructions.
49 The definition is a C statement or statements which output an
50 assembler instruction opcode to the stdio stream :samp:`{stream}`. The
51 macro-operand :samp:`{ptr}` is a variable of type ``char *`` which
52 points to the opcode name in its 'internal' form---the form that is
53 written in the machine description. The definition should output the
54 opcode name to :samp:`{stream}`, performing any translation you desire, and
55 increment the variable :samp:`{ptr}` to point at the end of the opcode
56 so that it will not be output twice.
58 In fact, your macro definition may process less than the entire opcode
59 name, or more than the opcode name; but if you want to process text
60 that includes :samp:`%`-sequences to substitute operands, you must take
61 care of the substitution yourself. Just be sure to increment
62 :samp:`{ptr}` over whatever text should not be output normally.
64 .. index:: recog_data.operand
66 If you need to look at the operand values, they can be found as the
67 elements of ``recog_data.operand``.
69 If the macro definition does nothing, the instruction is output
72 .. c:macro:: FINAL_PRESCAN_INSN (insn, opvec, noperands)
74 If defined, a C statement to be executed just prior to the output of
75 assembler code for :samp:`{insn}`, to modify the extracted operands so
76 they will be output differently.
78 Here the argument :samp:`{opvec}` is the vector containing the operands
79 extracted from :samp:`{insn}`, and :samp:`{noperands}` is the number of
80 elements of the vector which contain meaningful data for this insn.
81 The contents of this vector are what will be used to convert the insn
82 template into assembler code, so you can change the assembler output
83 by changing the contents of the vector.
85 This macro is useful when various assembler syntaxes share a single
86 file of instruction patterns; by defining this macro differently, you
87 can cause a large class of instructions to be output differently (such
88 as with rearranged operands). Naturally, variations in assembler
89 syntax affecting individual insn patterns ought to be handled by
90 writing conditional output routines in those patterns.
92 If this macro is not defined, it is equivalent to a null statement.
94 .. include:: ../tm.rst.in
95 :start-after: [TARGET_ASM_FINAL_POSTSCAN_INSN]
96 :end-before: [TARGET_ASM_FINAL_POSTSCAN_INSN]
99 .. c:macro:: PRINT_OPERAND (stream, x, code)
101 A C compound statement to output to stdio stream :samp:`{stream}` the
102 assembler syntax for an instruction operand :samp:`{x}`. :samp:`{x}` is an
105 :samp:`{code}` is a value that can be used to specify one of several ways
106 of printing the operand. It is used when identical operands must be
107 printed differently depending on the context. :samp:`{code}` comes from
108 the :samp:`%` specification that was used to request printing of the
109 operand. If the specification was just :samp:`%{digit}` then
110 :samp:`{code}` is 0; if the specification was :samp:`%{ltr}{digit}` then :samp:`{code}` is the ASCII code for :samp:`{ltr}`.
114 If :samp:`{x}` is a register, this macro should print the register's name.
115 The names can be found in an array ``reg_names`` whose type is
116 ``char *[]``. ``reg_names`` is initialized from
119 When the machine description has a specification :samp:`%{punct}`
120 (a :samp:`%` followed by a punctuation character), this macro is called
121 with a null pointer for :samp:`{x}` and the punctuation character for
124 .. c:macro:: PRINT_OPERAND_PUNCT_VALID_P (code)
126 A C expression which evaluates to true if :samp:`{code}` is a valid
127 punctuation character for use in the ``PRINT_OPERAND`` macro. If
128 ``PRINT_OPERAND_PUNCT_VALID_P`` is not defined, it means that no
129 punctuation characters (except for the standard one, :samp:`%`) are used
132 .. c:macro:: PRINT_OPERAND_ADDRESS (stream, x)
134 A C compound statement to output to stdio stream :samp:`{stream}` the
135 assembler syntax for an instruction operand that is a memory reference
136 whose address is :samp:`{x}`. :samp:`{x}` is an RTL expression.
138 .. index:: TARGET_ENCODE_SECTION_INFO usage
140 On some machines, the syntax for a symbolic address depends on the
141 section that the address refers to. On these machines, define the hook
142 ``TARGET_ENCODE_SECTION_INFO`` to store the information into the
143 ``symbol_ref``, and then check for it here. See :ref:`assembler-format`.
145 .. index:: dbr_sequence_length
147 .. c:macro:: DBR_OUTPUT_SEQEND (file)
149 A C statement, to be executed after all slot-filler instructions have
150 been output. If necessary, call ``dbr_sequence_length`` to
151 determine the number of slots filled in a sequence (zero if not
152 currently outputting a sequence), to decide how many no-ops to output,
155 Don't define this macro if it has nothing to do, but it is helpful in
156 reading assembly output if the extent of the delay sequence is made
157 explicit (e.g. with white space).
159 .. index:: final_sequence
161 Note that output routines for instructions with delay slots must be
162 prepared to deal with not being output as part of a sequence
163 (i.e. when the scheduling pass is not run, or when no slot fillers could be
164 found.) The variable ``final_sequence`` is null when not
165 processing a sequence, otherwise it contains the ``sequence`` rtx
168 .. index:: asm_fprintf
170 .. c:macro:: REGISTER_PREFIX
175 If defined, C string expressions to be used for the :samp:`%R`, :samp:`%L`,
176 :samp:`%U`, and :samp:`%I` options of ``asm_fprintf`` (see
177 :samp:`final.cc`). These are useful when a single :samp:`md` file must
178 support multiple assembler formats. In that case, the various :samp:`tm.h`
179 files can define these macros differently.
181 .. c:macro:: ASM_FPRINTF_EXTENSIONS (file, argptr, format)
183 If defined this macro should expand to a series of ``case``
184 statements which will be parsed inside the ``switch`` statement of
185 the ``asm_fprintf`` function. This allows targets to define extra
186 printf formats which may useful when generating their assembler
187 statements. Note that uppercase letters are reserved for future
188 generic extensions to asm_fprintf, and so are not available to target
189 specific code. The output file is given by the parameter :samp:`{file}`.
190 The varargs input pointer is :samp:`{argptr}` and the rest of the format
191 string, starting the character after the one that is being switched
192 upon, is pointed to by :samp:`{format}`.
194 .. c:macro:: ASSEMBLER_DIALECT
196 If your target supports multiple dialects of assembler language (such as
197 different opcodes), define this macro as a C expression that gives the
198 numeric index of the assembler language dialect to use, with zero as the
201 If this macro is defined, you may use constructs of the form
205 {option0|option1|option2...}
207 in the output templates of patterns (see :ref:`output-template`) or in the
208 first argument of ``asm_fprintf``. This construct outputs
209 :samp:`option0`, :samp:`option1`, :samp:`option2`, etc., if the value of
210 ``ASSEMBLER_DIALECT`` is zero, one, two, etc. Any special characters
211 within these strings retain their usual meaning. If there are fewer
212 alternatives within the braces than the value of
213 ``ASSEMBLER_DIALECT``, the construct outputs nothing. If it's needed
214 to print curly braces or :samp:`|` character in assembler output directly,
215 :samp:`%{`, :samp:`%}` and :samp:`%|` can be used.
217 If you do not define this macro, the characters :samp:`{`, :samp:`|` and
218 :samp:`}` do not have any special meaning when used in templates or
219 operands to ``asm_fprintf``.
221 Define the macros ``REGISTER_PREFIX``, ``LOCAL_LABEL_PREFIX``,
222 ``USER_LABEL_PREFIX`` and ``IMMEDIATE_PREFIX`` if you can express
223 the variations in assembler language syntax with that mechanism. Define
224 ``ASSEMBLER_DIALECT`` and use the :samp:`{option0|option1}` syntax
225 if the syntax variant are larger and involve such things as different
226 opcodes or operand order.
228 .. c:macro:: ASM_OUTPUT_REG_PUSH (stream, regno)
230 A C expression to output to :samp:`{stream}` some assembler code
231 which will push hard register number :samp:`{regno}` onto the stack.
232 The code need not be optimal, since this macro is used only when
235 .. c:macro:: ASM_OUTPUT_REG_POP (stream, regno)
237 A C expression to output to :samp:`{stream}` some assembler code
238 which will pop hard register number :samp:`{regno}` off of the stack.
239 The code need not be optimal, since this macro is used only when