Cooper_Engineering_a_Compiler(Second Edition) (Rice), страница 96

PDF-файл Cooper_Engineering_a_Compiler(Second Edition) (Rice), страница 96 Конструирование компиляторов (52981): Другое - 7 семестрCooper_Engineering_a_Compiler(Second Edition) (Rice) - PDF, страница 96 (52981) - СтудИзба2019-09-18СтудИзба
Rice1874

Описание файла

Файл "Cooper_Engineering_a_Compiler(Second Edition)" внутри архива находится в следующих папках: Rice, Купер и Торчсон - перевод. PDF-файл из архива "Rice", который расположен в категории "". Всё это находится в предмете "конструирование компиляторов" из 7 семестр, которые можно найти в файловом архиве МГУ им. Ломоносова. Не смотря на прямую связь этого архива с МГУ им. Ломоносова, его также можно найти и в других разделах. .

Просмотр PDF-файла онлайн

Текст 96 страницы из PDF

Finally, it eitherbranches to the corresponding label or to the default case.Figure 7.18a shows our example case statement, rewritten with a differentset of labels. For the figure, we will assume case labels of 0, 15, 23, 37, 41,50, 68, 72, 83, and 99, as well as a default case. The labels could, of course,cover a much larger range. For such a case statement, the compiler mightbuild a search table such as the one shown in Figure 7.18b, and generate abinary search, as in Figure 7.18c, to locate the desired case.

If fall-throughbehavior is allowed, as in c, the compiler must ensure that the blocks appearin memory in their original order.In a binary search or direct address computation, the compiler writer shouldensure that the set of potential targets of the jump are visible in the ir, usinga construct such as the iloc tbl pseudo-operation (see Appendix A.4.2).Such hints both simplify later analysis and make its results more precise.SECTION REVIEWProgramming languages include a variety of features to implementcontrol flow. The compiler needs a schema for each control-flowconstruct in the source languages that it accepts. In some cases, such as aloop, one approach serves for a variety of different constructs.

In others,such as a case statement, the compiler should choose an implementationstrategy based on the specific properties of the code at hand.The exact form of the search loop might vary.For example, the code in the figure does notshort circuit the case when it finds the label early.Empirical testing of several variants written inthe target machine’s assembly code is needed tofind the best choices.392 CHAPTER 7 Code ShapeReview Questionsdo 10 i = 1, 100loop body10i = i + 2continue1. Write the ILOC code for the FORTRAN loop shown in the margin.

Recallthat the loop body must execute 100 iterations, even though the loopmodifies the value of i.2. Consider the tradeoff between implementing a C switch statementwith a direct address computation and with a binary search. At whatpoint should the compiler switch from direct address computation toa binary search? What properties of the actual code should play a rolein that determination?7.9 PROCEDURE CALLSThe implementation of procedure calls is, for the most part, straightforward.As shown in Figure 7.19, a procedure call consists of a precall sequenceand a postreturn sequence in the caller, and a prologue and an epiloguein the callee.

A single procedure can contain multiple call sites, each withits own precall and postreturn sequences. In most languages, a procedurehas one entry point, so it has one prologue sequence and one epiloguesequence. (Some languages allow multiple entry points, each of which hasits own prologue sequence.) Many of the details involved in these sequencesare described in Section 6.5. This section focuses on issues that affect thecompiler’s ability to generate efficient, compact, and consistent code forprocedure calls.Procedure pPrologueProcedure qPrecallllCaPostreturnReEpiloguen FIGURE 7.19 A Standard Procedure Linkage.turnPrologueEpilogue7.9 Procedure Calls 393As a general rule, moving operations from the precall and postreturnsequences into the prologue and epilogue sequences should reduce theoverall size of the final code. If the call from p to q shown in Figure 7.19 isthe only call to q in the entire program, then moving an operation from theprecall sequence in p to the prologue in q (or from the postreturn sequencein p to the epilogue in q) has no impact on code size.

If, however, other callsites invoke q and the compiler moves an operation from the caller to thecallee (at all the call sites), it should reduce the overall code size by replacing multiple copies of an operation with a single one. As the number of callsites that invoke a given procedure rises, the savings grow.

We assume thatmost procedures are called from several locations; if not, both the programmer and the compiler should consider including the procedure inline at thepoint of its only invocation.From the code-shape perspective, procedure calls are similar in Algol-likelanguages and object-oriented languages. The major difference betweenthem lies in the technique used to name the callee (see Section 6.3.4). Inaddition, a call in an object-oriented language typically adds an implicitactual parameter, that is, the receiver’s object record.7.9.1 Evaluating Actual ParametersWhen it builds the precall sequence, the compiler must emit code to evaluatethe actual parameters to the call.

The compiler treats each actual parameteras an expression. For a call-by-value parameter, the precall sequence evaluates the expression and stores its value in a location designated for thatparameter—either in a register or in the callee’s ar. For a call-by-referenceparameter, the precall sequence evaluates the parameter to an address andstores the address in a location designated for that parameter. If a call-byreference parameter has no storage location, then the compiler may need toallocate space to hold the parameter’s value so that it has an address to passto the callee.If the source language specifies an order of evaluation for the actual parameters, the compiler must, of course, follow that order. Otherwise, it shoulduse a consistent order—either left to right or right to left. The evaluationorder matters for parameters that might have side effects.

For example, aprogram that used two routines push and pop to manipulate a stack wouldproduce different results for the sequence subtract(pop(), pop()) underleft-to-right and right-to-left evaluation.Procedures typically have several implicit arguments. These include theprocedure’s arp, the caller’s arp, the return address, and any information394 CHAPTER 7 Code Shapeneeded to establish addressability.

Object-oriented languages pass thereceiver as an implicit parameter. Some of these arguments are passed inregisters while others usually reside in memory. Many architectures have anoperation likejsr label1 ⇒ rithat transfers control to label1 and places the address of the operation thatfollows the jsr into ri .Procedures passed as actual parameters may require special treatment.

If pcalls q, passing procedure r as an argument, p must pass to q more information than r’s starting address. In particular, if the compiled code uses accesslinks to find nonlocal variables, the callee needs r’s lexical level so that asubsequent call to r can find the correct access link for r’s level.

The compiler can construct an haddress,leveli pair and pass it (or its address) in placeof the procedure-valued parameter. When the compiler constructs the precallsequence for a procedure-valued parameter, it must insert the extra code tofetch the lexical level and adjust the access link accordingly.7.9.2 Saving and Restoring RegistersUnder any calling convention, one or both of the caller and the callee mustpreserve register values. Often, linkage conventions use a combination ofcaller-saves and callee-saves registers. As both the cost of memory operations and the number of registers have risen, the cost of saving and restoringregisters at call sites has increased, to the point where it merits carefulattention.In choosing a strategy to save and restore registers, the compiler writer mustconsider both efficiency and code size.

Some processor features impact thischoice. Features that spill a portion of the register set can reduce code size.Examples of such features include register windows on the sparc machines,the multiword load and store operations on the Power architectures, and thehigh-level call operation on the vax. Each offers the compiler a compactway to save and restore some portion of the register set.While larger register sets can increase the number of registers that the codesaves and restores, in general, using these additional registers improves thespeed of the resulting code. With fewer registers, the compiler would beforced to generate loads and stores throughout the code; with more registers,7.9 Procedure Calls 395many of these spills occur only at a call site. (The larger register set shouldreduce the total number of spills in the code.) The concentration of savesand restores at call sites presents the compiler with opportunities to handle them in better ways than it might if they were spread across an entireprocedure.nnnUsing multi-register memory operations When saving and restoringadjacent registers, the compiler can use a multiregister memoryoperation.

Many isas support doubleword and quadword load and storeoperations. Using these operations can reduce code size; it may alsoimprove execution speed. Generalized multiregister memory operationscan have the same effect.Using a library routine As the number of registers grows, the precalland postreturn sequences both grow. The compiler writer can replacethe sequence of individual memory operations with a call to acompiler-supplied save or restore routine.

Done across all calls, thisstrategy can produce a significant savings in code size. Since the saveand restore routines are known only to the compiler, they can useminimal call sequence to keep the runtime cost low.The save and restore routines can take an argument that specifies whichregisters must be preserved. It may be worthwhile to generate optimizedversions for common cases, such as preserving all the caller-saves orcallee-saves registers.Combining responsibilities To further reduce overhead, the compilermight combine the work for caller-saves and callee-saves registers.

Свежие статьи
Популярно сейчас
А знаете ли Вы, что из года в год задания практически не меняются? Математика, преподаваемая в учебных заведениях, никак не менялась минимум 30 лет. Найдите нужный учебный материал на СтудИзбе!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Нашёл ошибку?
Или хочешь предложить что-то улучшить на этой странице? Напиши об этом и получи бонус!
Бонус рассчитывается индивидуально в каждом случае и может быть в виде баллов или бесплатной услуги от студизбы.
Предложить исправление
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
5120
Авторов
на СтудИзбе
444
Средний доход
с одного платного файла
Обучение Подробнее