introduction to machine descriptions
play

Introduction to Machine Descriptions Uday Khedker - PowerPoint PPT Presentation

Tutorial on Essential Abstractions in GCC Introduction to Machine Descriptions Uday Khedker (www.cse.iitb.ac.in/grc) GCC Resource Center, Department of Computer Science and Engineering, Indian Institute of Technology, Bombay April 2011


  1. Tutorial on Essential Abstractions in GCC Introduction to Machine Descriptions Uday Khedker (www.cse.iitb.ac.in/grc) GCC Resource Center, Department of Computer Science and Engineering, Indian Institute of Technology, Bombay April 2011

  2. EA-GCC, Chamonix MD Intro: Outline 1/21 Outline • Influences on GCC Machine Descriptions • Organization of GCC Machine Descriptions • Machine description constructs • The essence of retargetability in GCC Uday Khedker GRC, IIT Bombay

  3. EA-GCC, Chamonix MD Intro: Outline 2/21 Examples of Influences on the Machine Descriptions GCC Architecture Source Language • Generation of nop • tree covers for • INT TYPE SIZE instruction selection • Activation Record • define predicate <target>.h <target>.h Machine Description hwint.h Target System � <target>.md • Instruction Set <target>.h Architecture Build System Host System • Assembly and � <target>.h executable other headers formats Uday Khedker GRC, IIT Bombay

  4. Part 1 Organization of GCC MD

  5. EA-GCC, Chamonix MD Intro: Organization of GCC MD 3/21 Contents of GCC MD • Processor instructions useful to GCC • Processor characteristics useful to GCC • Target ASM syntax • Target specific optimizations as IR-RTL → IR-RTL transformations (GCC code performs the transformation computations, MD supplies their target patterns ) ◮ Peephole optimizations ◮ Transformations for enabling scheduling Uday Khedker GRC, IIT Bombay

  6. EA-GCC, Chamonix MD Intro: Organization of GCC MD 4/21 Syntactic Entities in GCC MD • Necessary Specifications ◮ Processor instructions useful to GCC ◮ One GIMPLE → One IR-RTL define insn ◮ One GIMPLE → More than one IR-RTL define expand ◮ Processor characteristics useful to GCC define cpu unit ◮ Target ASM syntax part of define insn ◮ IR-RTL → IR-RTL transformations define split ◮ Target Specific Optimizations define peephole2 • Programming Conveniences (eg. define insn and split , define constants , define cond exec , define automaton ) Uday Khedker GRC, IIT Bombay

  7. EA-GCC, Chamonix MD Intro: Organization of GCC MD 5/21 File Organization of GCC MD The GCC MD comprises of • <target>.h : A set of C macros that describe ◮ HLL properties: e.g. INT TYPE SIZE to h/w bits ◮ Activation record structure ◮ Target Register (sub)sets, and characteristics (lists of read-only regs, dedicated regs, etc.) ◮ System Software details: formats of assembler, executable etc. <target>.md : Target instructions described using MD constructs. • (Our main interest!) • <target>.c : Optional, but usually required. C functions that implement target specific code (e.g. target specific activation layout). Uday Khedker GRC, IIT Bombay

  8. EA-GCC, Chamonix MD Intro: Organization of GCC MD 5/21 File Organization of GCC MD The GCC MD comprises of • <target>.h : A set of C macros that describe ◮ HLL properties: e.g. INT TYPE SIZE to h/w bits ◮ Activation record structure ◮ Target Register (sub)sets, and characteristics (lists of read-only regs, dedicated regs, etc.) ◮ System Software details: formats of assembler, executable etc. <target>.md : Target instructions described using MD constructs. • (Our main interest!) • <target>.c : Optional, but usually required. C functions that implement target specific code (e.g. target specific activation layout). Uday Khedker GRC, IIT Bombay

  9. Part 2 Essential Constructs in Machine Descriptions

  10. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 6/21 The GCC Phase Sequence Target Independent Target Dependent Tree SSA Generate Generate Parse Gimplify Optimize RTL Optimize RTL ASM GIMPLE → RTL RTL → ASM Uday Khedker GRC, IIT Bombay

  11. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 6/21 The GCC Phase Sequence Target Independent Target Dependent Tree SSA Generate Generate Parse Gimplify Optimize RTL Optimize RTL ASM GIMPLE → RTL RTL → ASM MD Info Required Uday Khedker GRC, IIT Bombay

  12. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 7/21 The GCC Phase Sequence Observe that • RTL is a target specific IR • GIMPLE → non strict RTL → strict RTL. • SPN: “(Semantic) Glue” between GIMPLE and RTL ◮ operator match + coarse operand match, and ◮ refine the operand match • Finally: Strict RTL ⇔ Unique target ASM string Consider generating RTL expressions of GIMPLE nodes Two constructs available: define insn and define expand • Uday Khedker GRC, IIT Bombay

  13. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 8/21 Running Example Consider a data move operation • reads data from source location, and • writes it to the destination location. • GIMPLE node: GIMPLE ASSIGN • SPN: “ movsi ” Some possible combinations are: • Reg ← Reg : Register move • Reg ← Mem : Load • Reg ← Const : Load immediate • Mem ← Reg : Store • Mem ← Mem : Illegal instruction Uday Khedker GRC, IIT Bombay

  14. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 9/21 Specifying Target Instruction Semantics (define_insn "movsi" [(set (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "k") )] "" /* C boolean expression, if required */ "li %0, %1" ) Uday Khedker GRC, IIT Bombay

  15. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 9/21 Specifying Target Instruction Semantics Define instruction pattern Standard Pattern Name (define_insn "movsi" [(set (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "k") )] "" /* C boolean expression, if required */ "li %0, %1" ) RTL Expression (RTX): target asm inst. = Concrete syntax for RTX Semantics of target instruction Uday Khedker GRC, IIT Bombay

  16. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 9/21 Specifying Target Instruction Semantics RTL operator MD constructs (define_insn "movsi" [(set (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "k") )] "" /* C boolean expression, if required */ "li %0, %1" ) Mode Predicates Constraints Uday Khedker GRC, IIT Bombay

  17. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 10/21 Instruction Specification and Translation Target Independent Target Dependent Tree SSA Generate Generate Parse Gimplify Optimize RTL Optimize RTL ASM GIMPLE → RTL RTL → ASM (define_insn "movsi" [(set (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "k"))] "" /* C boolean expression, if required */ "mov %0, %1" ) Uday Khedker GRC, IIT Bombay

  18. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 10/21 Instruction Specification and Translation Target Independent Target Dependent Tree SSA Generate Generate Parse Gimplify Optimize RTL Optimize RTL ASM • GIMPLE: target independent GIMPLE → RTL RTL → ASM • RTL: target dependent • Need: associate the semantics ⇒ GCC Solution: Standard Pattern Names (define_insn "movsi" [(set (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "k"))] "" /* C boolean expression, if required */ "mov %0, %1" ) Uday Khedker GRC, IIT Bombay

  19. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 10/21 Instruction Specification and Translation Target Independent Target Dependent Tree SSA Generate Generate Parse Gimplify Optimize RTL Optimize RTL ASM • GIMPLE: target independent GIMPLE → RTL RTL → ASM • RTL: target dependent • Need: associate the semantics RTL Template ASM ⇒ GCC Solution: Standard Pattern Names GIMPLE ASSIGN (define_insn "movsi" [(set (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "k"))] "" /* C boolean expression, if required */ "mov %0, %1" ) Uday Khedker GRC, IIT Bombay

  20. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 11/21 General Move Instruction (define_insn "maybe_spn_like_movsi" [(set (match_operand:SI 0 "general_operand" "") (match_operand:SI 1 "general_operand" ""))] "" "mov %0, %1" ) • This define insn can generate data movement patterns of all combinations • Even Mem → Mem is possible. • We need a mechanism to generate more restricted data movement RTX instances! Uday Khedker GRC, IIT Bombay

  21. EA-GCC, Chamonix MD Intro: Essential Constructs in Machine Descriptions 12/21 The define expand Construct (define_expand "movsi" [(set (match_operand:SI 0 "nonimmediate_operand" "") (match_operand:SI 1 "general_operand" "") )] "" { if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) != REG) if (can_create_pseudo_p()) operands[1] = force_reg (SImode, operands[1]); } ) Uday Khedker GRC, IIT Bombay

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend