aboutsummaryrefslogtreecommitdiff
path: root/gcc/md.texi
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/md.texi')
-rw-r--r--gcc/md.texi54
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/md.texi b/gcc/md.texi
index 3b77c4b..8227159 100644
--- a/gcc/md.texi
+++ b/gcc/md.texi
@@ -39,6 +39,8 @@ See the next chapter for information on the C header file.
* Insn Attributes:: Specifying the value of attributes for generated insns.
* Conditional Execution::Generating @code{define_insn} patterns for
predication.
+* Constant Definitions::Defining symbolic constants that can be used in the
+ md file.
@end menu
@node Patterns
@@ -4690,3 +4692,55 @@ generates a new pattern
"(@var{test2}) && (@var{test1})"
"(%3) add %2,%1,%0")
@end smallexample
+
+@node Constant Definitions
+@section Constant Definitions
+@cindex constant definitions
+@findex define_constants
+
+Using literal constants inside instruction patterns reduces legibility and
+can be a maintenance problem.
+
+To overcome this problem, you may use the @code{define_constants}
+expression. It contains a vector of name-value pairs. From that
+point on, wherever any of the names appears in the MD file, it is as
+if the corresponding value had been written instead. You may use
+@code{define_constants} multiple times; each appearance adds more
+constants to the table. It is an error to redefine a constant with
+a different value.
+
+To come back to the a29k load multiple example, instead of
+
+@smallexample
+(define_insn ""
+ [(match_parallel 0 "load_multiple_operation"
+ [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
+ (match_operand:SI 2 "memory_operand" "m"))
+ (use (reg:SI 179))
+ (clobber (reg:SI 179))])]
+ ""
+ "loadm 0,0,%1,%2")
+@end smallexample
+
+You could write:
+
+@smallexample
+(define_constants [
+ (R_BP 177)
+ (R_FC 178)
+ (R_CR 179)
+ (R_Q 180)
+])
+
+(define_insn ""
+ [(match_parallel 0 "load_multiple_operation"
+ [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
+ (match_operand:SI 2 "memory_operand" "m"))
+ (use (reg:SI R_CR))
+ (clobber (reg:SI R_CR))])]
+ ""
+ "loadm 0,0,%1,%2")
+@end smallexample
+
+The constants that are defined with a define_constant are also output
+in the insn-codes.h header file as #defines.