Instruction scheduling

In computer science, instruction scheduling is a compiler optimization used to improve instruction-level parallelism, which improves performance on machines with instruction pipelines. Put more simply, it tries to do the following without changing the meaning of the code:

  • Avoid pipeline stalls by rearranging the order of instructions.[1]
  • Avoid illegal or semantically ambiguous operations (typically involving subtle instruction pipeline timing issues or non-interlocked resources).

The pipeline stalls can be caused by structural hazards (processor resource limit), data hazards (output of one instruction needed by another instruction) and control hazards (branching).

Data hazards

Instruction scheduling is typically done on a single basic block. In order to determine whether rearranging the block's instructions in a certain way preserves the behavior of that block, we need the concept of a data dependency. There are three types of dependencies, which also happen to be the three data hazards:

  1. Read after Write (RAW or "True"): Instruction 1 writes a value used later by Instruction 2. Instruction 1 must come first, or Instruction 2 will read the old value instead of the new.
  2. Write after Read (WAR or "Anti"): Instruction 1 reads a location that is later overwritten by Instruction 2. Instruction 1 must come first, or it will read the new value instead of the old.
  3. Write after Write (WAW or "Output"): Two instructions both write the same location. They must occur in their original order.

Technically, there is a fourth type, Read after Read (RAR or "Input"): Both instructions read the same location. Input dependence does not constrain the execution order of two statements, but it is useful in scalar replacement of array elements.

To make sure we respect the three types of dependencies, we construct a dependency graph, which is a directed graph where each vertex is an instruction and there is an edge from I1 to I2 if I1 must come before I2 due to a dependency. If loop-carried dependencies are left out, the dependency graph is a directed acyclic graph. Then, any topological sort of this graph is a valid instruction schedule. The edges of the graph are usually labelled with the latency of the dependence. This is the number of clock cycles that needs to elapse before the pipeline can proceed with the target instruction without stalling.

Algorithms

The simplest algorithm to find a topological sort is frequently used and is known as list scheduling. Conceptually, it repeatedly selects a source of the dependency graph, appends it to the current instruction schedule and removes it from the graph. This may cause other vertices to be sources, which will then also be considered for scheduling. The algorithm terminates if the graph is empty.

To arrive at a good schedule, stalls should be prevented. This is determined by the choice of the next instruction to be scheduled. A number of heuristics are in common use:

  • The processor resources used by the already scheduled instructions are recorded. If a candidate uses a resource that is occupied, its priority will drop.
  • If a candidate is scheduled closer to its predecessors than the associated latency, its priority will drop.
  • If a candidate lies on the critical path of the graph, its priority will rise. This heuristic provides some form of look-ahead in an otherwise local decision process.
  • If choosing a candidate will create many new sources, its priority will rise. This heuristic tends to generate more freedom for the scheduler.

Phase order

Instruction scheduling may be done either before or after register allocation or both before and after it. The advantage of doing it before register allocation is that this results in maximum parallelism. The disadvantage of doing it before register allocation is that this can result in the register allocator needing to use a number of registers exceeding those available. This will cause spill/fill code to be introduced, which will reduce the performance of the section of code in question.

If the architecture being scheduled has instruction sequences that have potentially illegal combinations (due to a lack of instruction interlocks), the instructions must be scheduled after register allocation. This second scheduling pass will also improve the placement of the spill/fill code.

If scheduling is only done after register allocation, then there will be false dependencies introduced by the register allocation that will limit the amount of instruction motion possible by the scheduler.

Types

There are several types of instruction scheduling:

  1. Local (basic block) scheduling: instructions can't move across basic block boundaries.
  2. Global scheduling: instructions can move across basic block boundaries.
  3. Modulo scheduling: an algorithm for generating software pipelining, which is a way of increasing instruction level parallelism by interleaving different iterations of an inner loop.
  4. Trace scheduling: the first practical approach for global scheduling, trace scheduling tries to optimize the control flow path that is executed most often.
  5. Superblock scheduling: a simplified form of trace scheduling which does not attempt to merge control flow paths at trace "side entrances". Instead, code can be implemented by more than one schedule, vastly simplifying the code generator.

Compiler examples

The GNU Compiler Collection is one compiler known to perform instruction scheduling, using the -march (both instruction set and scheduling) or -mtune (only scheduling) flags. It uses descriptions of instruction latencies and what instructions can be run in parallel (or equivalently, which "port" each use) for each microarchitecture to perform the task. This feature is available to almost all architectures that GCC supports.[2]

Until version 12.0.0, the instruction scheduling in LLVM/Clang could only accept a -march (called target-cpu in LLVM parlance) switch for both instruction set and scheduling. Version 12 adds support for -mtune (tune-cpu) for x86 only.[3]

Sources of information on latency and port usage include:

LLVM's llvm-exegesis should be usable on all machines, especially to gather information on non-x86 ones.[6]

See also

References

  1. ^ Su, Ching-Long; Tsui, Chi-Ying; Despain, Alvin M. (1994). Low Power Architecture Design and Compilation Techniques for High-Performance Processors (PDF) (Report). Advanced Computer Architecture Laboratory. ACAL-TR-94-01. (Cold scheduling)
  2. ^ "x86 Options". Using the GNU Compiler Collection (GCC).
  3. ^ "⚙ D85384 [X86] Add basic support for -mtune command line option in clang". reviews.llvm.org.
  4. ^ "Software optimization resources. C++ and assembly. Windows, Linux, BSD, Mac OS X". Agner Fog.
  5. ^ "x86, x64 Instruction Latency, Memory Latency and CPUID dumps". instlatx64.atw.hu. See also the "Comments" link on the page.
  6. ^ "llvm-exegesis - LLVM Machine Instruction Benchmark". LLVM 12 Documentation.

Further reading

Read other articles:

この記事には複数の問題があります。改善やノートページでの議論にご協力ください。 出典が不足しています。存命人物の記事は特に、検証可能性を満たしている必要があります。(2019年9月) 人物の特筆性の基準を満たしていないおそれがあります。(2019年9月) 雑多な内容を羅列した節があります。(2019年9月)出典検索?: ユリサ – ニュース · 書籍...

 

Defunct Swedish state-owned telephone company The Rikstelefon brandmark of Televerket telephones Televerket was a Swedish State authority acting as a state-owned corporation (public enterprise), responsible for telecommunications in Sweden from 1853 until 1993. Originally it was named Kongl. Elektriska Telegraf-Werket (literally: Royal Electric Telegraph Agency), which was founded in 1853. Its name changed to Kongl. Telegrafverket in 1871, Kungl. Telegrafverket in 1903, the prefix Kungl. (an ...

 

اختصاراتوب:موط مشروع ويكي طب أهلاً بك في مشروع ويكي طب! هُنا يلتقي الويكيبيديون المُهتمون بالمحتوى الطِبّي والصحّي سواءً كانوا أطباء أو طلبة طب أو هواة. هُنا نتعلم ونتناقش ونُحدّد المهام. الصفحة الرئيسيةنقاش المشروعدليل التقديراتبوابة الطبالمقالات المقترحة  عن المشروع ...

2018 American filmBad ReputationDirected byKevin KerslakeWritten byJoel MarcusProduced byPeter Afterman Carianne BrinkmanStarringJoan Jett Kenny LagunaCinematographyKevin Kerslake Greg OlliverEdited byJoel MarcusMusic byThe Runaways Joan Jett & the BlackheartsProductioncompanies BMG Blackheart Films Inaudible Films Submarine[2] Distributed byMagnolia Pictures[3]Release date 28 September 2018 (2018-09-28) [1]Running time93 minutesCountryUnited StatesL...

 

Este artículo o sección necesita referencias que aparezcan en una publicación acreditada.Este aviso fue puesto el 12 de diciembre de 2008. Príncipe Valiente Prince Valiant Emblema de la serie.Idioma inglésEditorial King Features SyndicateContenidoTradición EstadounidenseGénero HistóricoPersonajes principales Prince ValiantDirección artísticaCreador(es) Harold Foster[editar datos en Wikidata] Príncipe Valiente, cuyo nombre original completo es Prince Valiant in the Days of...

 

Supposed sexual right of medieval lords Part of a series onViolence against women Killing Bride burning Dowry death Honor killing Femicide Infanticide Matricide Pregnant women Sati Sororicide Uxoricide Sexual assault and rape Child sexual initiation Forced prostitution Sexual slavery Fetish slaves Human trafficking Violence against prostitutes Rape and pregnancy laws Sexual assault Campus sexual assault Cybersex trafficking Mass sexual assault Sexual violence Types of rape by deception correc...

Gereja kembar Santa Maria in Montesanto (kiri) dan Santa Maria dei Miracoli (kanan), dilihat dari Piazza del Popolo. Antara dua gereja Via del Corso dimulai. Meskipun sangat mirip, perbedaan dapat dilihat pada gambar ini pada dua menara tempat lonceng bergantung kecil dan pada dua kubah (terlihat dari jumlah jendela di tympanum masing-masing gereja). Santa Maria dei Miracoli dan Santa Maria di Montesanto adalah dua gereja Katolik terkenal di Roma. Mereka terletak di Piazza del Popolo, menghad...

 

American businessman David RisherBorn (1965-07-15) July 15, 1965 (age 58)Washington, DCEducationPrinceton University (BA)Harvard University (MBA)OccupationCEO of LyftParentsJohn R. Risher Jr. (father)Sarah Walker Risher (mother) John David Risher (born July 15, 1965) is an American businessman and philanthropist. He is the CEO and co-founder of Worldreader, a non-profit organization that aims to get children reading so they can reach their potential,[1] and the co-founder of #Hal...

 

Radio station in Tamaqua, PennsylvaniaWMGH-FMTamaqua, PennsylvaniaFrequency105.5 MHzBrandingMagic 105.5ProgrammingLanguage(s)EnglishFormatAlbum Oriented RockAffiliationsAdlarge, Westwood One, United Stations Radio NetworkOwnershipOwnerCC Broadcasting, LLC.Sister stationsWGPA, WLSHHistoryFirst air dateJune 14, 1965 (as WSVB)Former call signsWSVB (1965-1972)WZTA (1972-1987)WCRN (1987)Call sign meaningMagicTechnical informationFacility ID18231ClassAERP1,400 wattsHAAT148 meters (486 ft)Trans...

Dutch footballer (born 1989) Bas Dost Dost playing for VfL Wolfsburg in 2015Personal informationDate of birth (1989-05-31) 31 May 1989 (age 34)Place of birth Deventer, NetherlandsHeight 1.96 m (6 ft 5 in)Position(s) ForwardTeam informationCurrent team NECNumber 12Youth career1995–2001 CVV Germanicus2001–2007 EmmenSenior career*Years Team Apps (Gls)2007–2008 Emmen 23 (6)2008–2010 Heracles Almelo 61 (17)2010–2012 Heerenveen 66 (45)2012–2016 VfL Wolfsburg 85 (36)2...

 

Pendaratan di NadzabBagian dari Perang Dunia II, Perang Pasifik5 September 1943.Tanggal5 September 1943Lokasi6°33′S 146°42′E / 6.550°S 146.700°E / -6.550; 146.700 Nadzab, Provinsi Morobe, Teritorial NuginiHasil Kemenangan SekutuPihak terlibat  Amerika Serikat  Australia  JepangTokoh dan pemimpin Douglas MacArthur Thomas Blamey George Kenney Edmund Herring George Alan Vasey Hitoshi Imamura Hatazō Adachi Kumaichi Teramoto Hidemitsu NakanoKekuatan ...

 

Part of a series onLiving spaces MainHouse (detached) • Apartment • Housing projects • Human outpost • Tenement • Condominium • Mixed-use development (live-work) • Hotel • Hostel (travellers' hotel) • Castles • Public housing • Squat • Flophouse • Green home • Shack • Slum • Shanty town IssuesAffordability • Executive housing • Environmental planning • Eviction • Fair housing • Healthiness • Homelessness • Housing discrimination • Housing inequa...

Overview of the legality and practice of prostitution in Laos   Decriminalization – No criminal penalties for prostitution   Legalization – prostitution legal and regulated   Abolitionism – prostitution is legal, but organized activities such as brothels and pimping are illegal; prostitution is not regulated   Neo-abolitionism illegal to buy sex and for 3rd party involvement, legal to sell sex   Prohibitionism – prostitution illegal &#...

 

Sebastián Coates Informasi pribadiNama lengkap Sebastián Coates NionTanggal lahir 7 Oktober 1990 (umur 33)Tempat lahir Montevideo, UruguayTinggi 200 cm (6 ft 6+1⁄2 in)Posisi bermain BekInformasi klubKlub saat ini SportingNomor 13Karier junior2001–2009 NacionalKarier senior*Tahun Tim Tampil (Gol)2009–2011 Nacional 60 (8)2011–2014 Liverpool 12 (1)2014–2017 Sunderland 46 (0)2016–2017 → Sporting (pinjaman) 46 (3)2017– Sporting 80 (9)Tim nasional2009 Urugu...

 

Distrik Vallée du Bandama District de la Vallée du BandamaDistrikNegara Pantai GadingDibentuk2011Ibu kotaBouakéLuas[1] • Total28.518 km2 (11,011 sq mi)Populasi (2021)[2] • Total1.964.929 • Kepadatan69/km2 (180/sq mi) Distrik Vallée du Bandama (Prancis: District de la Vallée du Bandama) adalah salah satu dari empat belas distrik administratif di Pantai Gading. Distrik ini terletak di bagian utara-tengah ...

Украи́нцы в Ростовской области Язык украинский, русский Религия в большинстве случаев — христиане: греко-католики православные Украи́нцы в Ростовской области (укр. Українці Ростовської області) — одна из крупнейших национальных общин, которая сформировалась историче...

 

2012 single by the Ready SetGive Me Your Hand (Best Song Ever)Single by the Ready Setfrom the album The Bad & the Better ReleasedMay 18, 2012Recorded2011Genre Dance-pop pop[1] Length3:48LabelWarner Bros.Songwriter(s) Jordan Witzigreuter Simon Wilcox Andrew Goldstein Producer(s)GoldsteinThe Ready Set singles chronology Killer (2011) Give Me Your Hand (Best Song Ever) (2012) Higher (2014) Music videoGive Me Your Hand (Best Song Ever) on YouTube Give Me Your Hand (Best Song Ever) is ...

 

Street in Manhattan, New York Dr. Hutton's Church on University Place (c. 1856–1879). More details A Dr. Hutton led a Dutch Reformed congregation on Washington Square.[1] This church was built in 1837,[2] and Dr. Mancius S. Hutton retired from it c. 1879.[3] The New York Public Library marks the images as from a collection that covers 1858–1925, so the image is from 1858–1879.[4] University Place is a short north-south thoroughfare in the Greenwich V...

Artikel ini membutuhkan rujukan tambahan agar kualitasnya dapat dipastikan. Mohon bantu kami mengembangkan artikel ini dengan cara menambahkan rujukan ke sumber tepercaya. Pernyataan tak bersumber bisa saja dipertentangkan dan dihapus.Cari sumber: Lembaga Dakwah Kampus – berita · surat kabar · buku · cendekiawan · JSTOR Lembaga Dakwah Kampus (sering disingkat LDK) adalah istilah kolektif untuk organisasi kemahasiswaan intra kampus di Indonesia yang dit...

 

2004 film directed by Yash Chopra Veer-ZaaraTheatrical-release posterDirected byYash ChopraWritten byAditya ChopraProduced byYash ChopraAditya ChopraStarringShah Rukh KhanPreity ZintaRani MukerjiNarrated byYash ChopraCinematographyAnil MehtaEdited byRitesh SoniMusic byOriginal Songs:Madan MohanBackground Score:R. S. ManiRevision:Sanjeev KohliProductioncompanyYash Raj FilmsDistributed byYash Raj FilmsRelease date 12 November 2004 (2004-11-12) Running time192 minutes[1]Co...

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!