📄 cdoc4
字号:
.SHDelaying and reordering.PPIntertwined with the code generation routines are two other,interrelated processes.The first, implemented by a routine called.II delay,is based on the observation thatnaive code generation for the expression`a = b++' would produce.DSmov b,r0inc bmov r0,a.DEThe point is that the table for postfix ++ has to preservethe value of.II bbefore incrementing it;the general way to do this is to preserve its value in a register.A cleverer scheme would generate.DSmov b,ainc b.DE.II Delayis called for each expression input to.II rcexpr,and it searches for postfix ++ and \-\-operators.If one is found applied to a variable,the tree is patched to bypass the operatorand compiled as it stands;then the increment or decrement itself is done.The effect is as if `a = b; b++' had been written.In this example, of course, the user himself could have done the same job,but more complicated examples are easily constructed, for example`switch (x++)'.An essential restriction is that the condition codes notbe required.It would be incorrect to compile`if (a++) ...'as.DStst ainc abeq ....DEbecause the `inc' destroys the required setting of the condition codes..PPReordering is a similar sort of optimization.Many cases which it detects are usefulmainly with register variables.If.II ris a register variable,the expression `r = x+y' is best compiledas.DSmov x,radd y,r.DEbut the codes tables would produce.DSmov x,r0add y,r0mov r0,r.DEwhich is in fact preferred if.II ris not a register.(If.II ris not a register,thetwo sequences are the same size, but thesecond is slightly faster.)The scheme is to compile the expression as if it had been written`r = x; r =+ y'.The.II reorderroutineis called with a pointer to each tree that.II rcexpris about to compile;if it has the right characteristics,the `r = x' tree is constructed and passed recursivelyto.II rcexpr;then the original tree is modified to read `r =+ y'and the calling instance of.II rcexprcompiles that instead.Of course the whole business is itself recursiveso that more extended forms of the same phenomenon arehandled, like `r = x + y | z'..PPCare does have to be takento avoid `optimizing' an expression like `r = x + r'into `r = x; r =+ r'.It is required that the right operand of the expression on the rightof the `=' be a ', distinct from the register variable..PPThe second case that.II reorderhandles is expressions of the form `r = X' used as a subexpression.Again, the code out of the tables for`x = r = y'would be.DSmov y,r0mov r0,rmov r0,x.DEwhereas if.II rwere a register it would be better to produce.DSmov y,rmov r,x.DEWhen.II reorderdiscovers thata register variable is being assigned toin a subexpression,it calls.II rcexprrecursively tocompile the subexpression, then fiddles the tree passedto it so that the register variable itself appearsas the operand instead of the whole subexpression.Here care has to be taken to avoid an infinite regress,with.II rcexprand.II reordercalling each other forever to handle assignments to registers..PPA third set of cases treated by.II reordercomes up when any name, not necessarily a register,occurs as a left operand of an assignment operator other than `='or as an operand of prefix `++' or `\-\-'.Unless condition-code tests are involved,when a subexpression like `(a =+ b)' is seen,the assignment is performed and the argument treemodified so that.II ais its operand;effectively`x + (y =+ z)' is compiled as `y =+ z; x + y'.Similarly, prefix increment and decrement are pulled outand performed first, then the remainder of the expression..PPThroughout code generation,the expression optimizer is called whenever.II delayor.II reorderchange the expression tree.This allows some special cases to be found that otherwisewould not be seen.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -