⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtl.texi

📁 早期freebsd实现
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@c Copyright (C) 1988, 1989, 1992 Free Software Foundation, Inc.@c This is part of the GCC manual.@c For copying conditions, see the file gcc.texi.@ifset INTERNALS@node RTL@chapter RTL Representation@cindex RTL representation@cindex representation of RTL@cindex Register Transfer Language (RTL)Most of the work of the compiler is done on an intermediate representationcalled register transfer language.  In this language, the instructions to beoutput are described, pretty much one by one, in an algebraic form thatdescribes what the instruction does.RTL is inspired by Lisp lists.  It has both an internal form, made up ofstructures that point at other structures, and a textual form that is usedin the machine description and in printed debugging dumps.  The textualform uses nested parentheses to indicate the pointers in the internal form.@menu* RTL Objects::       Expressions vs vectors vs strings vs integers.* Accessors::         Macros to access expression operands or vector elts.* Flags::             Other flags in an RTL expression.* Machine Modes::     Describing the size and format of a datum.* Constants::         Expressions with constant values.* Regs and Memory::   Expressions representing register contents or memory.* Arithmetic::        Expressions representing arithmetic on other expressions.* Comparisons::       Expressions representing comparison of expressions.* Bit Fields::        Expressions representing bit-fields in memory or reg.* Conversions::       Extending, truncating, floating or fixing.* RTL Declarations::  Declaring volatility, constancy, etc.* Side Effects::      Expressions for storing in registers, etc.* Incdec::            Embedded side-effects for autoincrement addressing.* Assembler::         Representing @code{asm} with operands.* Insns::             Expression types for entire insns.* Calls::             RTL representation of function call insns.* Sharing::           Some expressions are unique; others *must* be copied.@end menu@node RTL Objects, Accessors, RTL, RTL@section RTL Object Types@cindex RTL object types@cindex RTL integers@cindex RTL strings@cindex RTL vectors@cindex RTL expression@cindex RTX (See RTL)RTL uses five kinds of objects: expressions, integers, wide integers,strings and vectors.  Expressions are the most important ones.  An RTLexpression (``RTX'', for short) is a C structure, but it is usuallyreferred to with a pointer; a type that is given the typedef name@code{rtx}.An integer is simply an @code{int}; their written form uses decimal digits.A wide integer is an integral object whose type is @code{HOST_WIDE_INT}(@pxref{Config}); their written form used decimal digits.A string is a sequence of characters.  In core it is represented as a@code{char *} in usual C fashion, and it is written in C syntax as well.However, strings in RTL may never be null.  If you write an empty string ina machine description, it is represented in core as a null pointer ratherthan as a pointer to a null character.  In certain contexts, these nullpointers instead of strings are valid.  Within RTL code, strings are mostcommonly found inside @code{symbol_ref} expressions, but they appear inother contexts in the RTL expressions that make up machine descriptions.  A vector contains an arbitrary number of pointers to expressions.  Thenumber of elements in the vector is explicitly present in the vector.The written form of a vector consists of square brackets(@samp{[@dots{}]}) surrounding the elements, in sequence and withwhitespace separating them.  Vectors of length zero are not created;null pointers are used instead.@cindex expression codes@cindex codes, RTL expression@findex GET_CODE@findex PUT_CODEExpressions are classified by @dfn{expression codes} (also called RTXcodes).  The expression code is a name defined in @file{rtl.def}, which isalso (in upper case) a C enumeration constant.  The possible expressioncodes and their meanings are machine-independent.  The code of an RTX canbe extracted with the macro @code{GET_CODE (@var{x})} and altered with@code{PUT_CODE (@var{x}, @var{newcode})}.The expression code determines how many operands the expression contains,and what kinds of objects they are.  In RTL, unlike Lisp, you cannot tellby looking at an operand what kind of object it is.  Instead, you must knowfrom its context---from the expression code of the containing expression.For example, in an expression of code @code{subreg}, the first operand isto be regarded as an expression and the second operand as an integer.  Inan expression of code @code{plus}, there are two operands, both of whichare to be regarded as expressions.  In a @code{symbol_ref} expression,there is one operand, which is to be regarded as a string.Expressions are written as parentheses containing the name of theexpression type, its flags and machine mode if any, and then the operandsof the expression (separated by spaces).Expression code names in the @samp{md} file are written in lower case,but when they appear in C code they are written in upper case.  In thismanual, they are shown as follows: @code{const_int}.@cindex (nil)@cindex nilIn a few contexts a null pointer is valid where an expression is normallywanted.  The written form of this is @code{(nil)}.@node Accessors, Flags, RTL Objects, RTL@section Access to Operands@cindex accessors@cindex access to operands@cindex operand access@cindex RTL formatFor each expression type @file{rtl.def} specifies the number ofcontained objects and their kinds, with four possibilities: @samp{e} forexpression (actually a pointer to an expression), @samp{i} for integer,@samp{w} for wide integer, @samp{s} for string, and @samp{E} for vectorof expressions.  The sequence of letters for an expression code iscalled its @dfn{format}.  Thus, the format of @code{subreg} is@samp{ei}.@refill@cindex RTL format charactersA few other format characters are used occasionally:@table @code@item u@samp{u} is equivalent to @samp{e} except that it is printed differentlyin debugging dumps.  It is used for pointers to insns.@item n@samp{n} is equivalent to @samp{i} except that it is printed differentlyin debugging dumps.  It is used for the line number or code number of a@code{note} insn.@item S@samp{S} indicates a string which is optional.  In the RTL objects incore, @samp{S} is equivalent to @samp{s}, but when the object is read,from an @samp{md} file, the string value of this operand may be omitted.An omitted string is taken to be the null string.@item V@samp{V} indicates a vector which is optional.  In the RTL objects incore, @samp{V} is equivalent to @samp{E}, but when the object is readfrom an @samp{md} file, the vector value of this operand may be omitted.An omitted vector is effectively the same as a vector of no elements.@item 0@samp{0} means a slot whose contents do not fit any normal category.@samp{0} slots are not printed at all in dumps, and are often used inspecial ways by small parts of the compiler.@end tableThere are macros to get the number of operands, the format, and theclass of an expression code:@table @code@findex GET_RTX_LENGTH@item GET_RTX_LENGTH (@var{code})Number of operands of an RTX of code @var{code}.@findex GET_RTX_FORMAT@item GET_RTX_FORMAT (@var{code})The format of an RTX of code @var{code}, as a C string.@findex GET_RTX_CLASS@cindex classes of RTX codes@item GET_RTX_CLASS (@var{code})A single character representing the type of RTX operation that code@var{code} performs.The following classes are defined:@table @code@item oAn RTX code that represents an actual object, such as @code{reg} or@code{mem}.  @code{subreg} is not in this class.@item <An RTX code for a comparison.  The codes in this class are@code{NE}, @code{EQ}, @code{LE}, @code{LT}, @code{GE}, @code{GT},@code{LEU}, @code{LTU}, @code{GEU}, @code{GTU}.@refill@item 1An RTX code for a unary arithmetic operation, such as @code{neg}.@item cAn RTX code for a commutative binary operation, other than @code{NE}and @code{EQ} (which have class @samp{<}).@item 2An RTX code for a noncommutative binary operation, such as @code{MINUS}.@item bAn RTX code for a bitfield operation (@code{ZERO_EXTRACT} and@code{SIGN_EXTRACT}).@item 3An RTX code for other three input operations, such as @code{IF_THEN_ELSE}.@item iAn RTX code for a machine insn (@code{INSN}, @code{JUMP_INSN}, and@code{CALL_INSN}).@refill@item mAn RTX code for something that matches in insns, such as @code{MATCH_DUP}.@item xAll other RTX codes.@end table@end table@findex XEXP@findex XINT@findex XWINT@findex XSTROperands of expressions are accessed using the macros @code{XEXP},@code{XINT}, @code{XWINT} and @code{XSTR}.  Each of these macros takestwo arguments: an expression-pointer (RTX) and an operand number(counting from zero).  Thus,@refill@exampleXEXP (@var{x}, 2)@end example@noindentaccesses operand 2 of expression @var{x}, as an expression.@exampleXINT (@var{x}, 2)@end example@noindentaccesses the same operand as an integer.  @code{XSTR}, used in the samefashion, would access it as a string.Any operand can be accessed as an integer, as an expression or as a string.You must choose the correct method of access for the kind of value actuallystored in the operand.  You would do this based on the expression code ofthe containing expression.  That is also how you would know how manyoperands there are.For example, if @var{x} is a @code{subreg} expression, you know that it hastwo operands which can be correctly accessed as @code{XEXP (@var{x}, 0)}and @code{XINT (@var{x}, 1)}.  If you did @code{XINT (@var{x}, 0)}, youwould get the address of the expression operand but cast as an integer;that might occasionally be useful, but it would be cleaner to write@code{(int) XEXP (@var{x}, 0)}.  @code{XEXP (@var{x}, 1)} would alsocompile without error, and would return the second, integer operand cast asan expression pointer, which would probably result in a crash whenaccessed.  Nothing stops you from writing @code{XEXP (@var{x}, 28)} either,but this will access memory past the end of the expression withunpredictable results.@refillAccess to operands which are vectors is more complicated.  You can use themacro @code{XVEC} to get the vector-pointer itself, or the macros@code{XVECEXP} and @code{XVECLEN} to access the elements and length of avector.@table @code@findex XVEC@item XVEC (@var{exp}, @var{idx})Access the vector-pointer which is operand number @var{idx} in @var{exp}.@findex XVECLEN@item XVECLEN (@var{exp}, @var{idx})Access the length (number of elements) in the vector which isin operand number @var{idx} in @var{exp}.  This value is an @code{int}.@findex XVECEXP@item XVECEXP (@var{exp}, @var{idx}, @var{eltnum})Access element number @var{eltnum} in the vector which isin operand number @var{idx} in @var{exp}.  This value is an RTX.It is up to you to make sure that @var{eltnum} is not negativeand is less than @code{XVECLEN (@var{exp}, @var{idx})}.@end tableAll the macros defined in this section expand into lvalues and thereforecan be used to assign the operands, lengths and vector elements as well asto access them.@node Flags, Machine Modes, Accessors, RTL@section Flags in an RTL Expression@cindex flags in RTL expressionRTL expressions contain several flags (one-bit bit-fields) that are usedin certain types of expression.  Most often they are accessed with thefollowing macros:@table @code@findex MEM_VOLATILE_P@cindex @code{mem} and @samp{/v}@cindex @code{volatil}, in @code{mem}@cindex @samp{/v} in RTL dump@item MEM_VOLATILE_P (@var{x})In @code{mem} expressions, nonzero for volatile memory references.Stored in the @code{volatil} field and printed as @samp{/v}.@findex MEM_IN_STRUCT_P@cindex @code{mem} and @samp{/s}@cindex @code{in_struct}, in @code{mem}@cindex @samp{/s} in RTL dump@item MEM_IN_STRUCT_P (@var{x})In @code{mem} expressions, nonzero for reference to an entirestructure, union or array, or to a component of one.  Zero forreferences to a scalar variable or through a pointer to a scalar.Stored in the @code{in_struct} field and printed as @samp{/s}.@findex REG_LOOP_TEST_P@cindex @code{reg} and @samp{/s}@cindex @code{in_struct}, in @code{reg}@item REG_LOOP_TEST_PIn @code{reg} expressions, nonzero if this register's entire life iscontained in the exit test code for some loop.  Stored in the@code{in_struct} field and printed as @samp{/s}.@findex REG_USERVAR_P @cindex @code{reg} and @samp{/v}@cindex @code{volatil}, in @code{reg}@item REG_USERVAR_P (@var{x})In a @code{reg}, nonzero if it corresponds to a variable present inthe user's source code.  Zero for temporaries generated internally bythe compiler.  Stored in the @code{volatil} field and printed as@samp{/v}.@cindex @samp{/i} in RTL dump@findex REG_FUNCTION_VALUE_P @cindex @code{reg} and @samp{/i}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -