instruction selection for llvm
play

Instruction Selection for LLVM-- Aslan Askarov aslan@cs.au.dk The - PowerPoint PPT Presentation

Compilation 2016 Instruction Selection for LLVM-- Aslan Askarov aslan@cs.au.dk The x86 assembly language Assembler produces object file that contains segments (address ranges with a purpose) Segments containing runnable


  1. 
 
 Compilation 2016 Instruction Selection for LLVM-- Aslan Askarov aslan@cs.au.dk 


  2. The x86 assembly language • Assembler produces object file that contains segments (address ranges with a purpose) • Segments containing runnable code: .text • Segments containing initialized data: .data • Remember to specify segment to fit purpose • Specifying data: • .ascii .asciz • Metadata: • .func .type .endfunc .size .globl • For examples: check provided *.s

  3. The x86 assembly language • Example instruction: movq %rax, -48(%rbp) • General format: <instr><S> <src>, <dst> • <S> ∈ {b,s,w,l,q,t} specifies size ( q : 64 bit) • $ indicates literal number • % indicates register • o(%r1, %r2, n) means o + %r1 + %r2 * n • Example label: mylabel • gives the “current address” the name ‘mylabel’ • Example directives: • .text .data .globl .ascii .asciz 
 .size .func .type .endfunc

  4. • x86.sml – A friendly module for creating and printing x86 64 assembly programs • System V x86 64 Application Binary Interface (ABI) • https://software.intel.com/sites/default/files/article/ 402129/mpx-linux64-abi.pdf • A document describing (among other things) • Frame organization • Calling conventions • Register purpose

  5. Stack organization – a figure from System V ABI document

  6. Register usage Note argument calling convention we don’t use these registers

  7. Organizing stack for Tiger programs stack grows from high memory addresses to low addresses current frame previous frame 0x1010 0x1018 0x1030 … 0x1080 0x1088 … 0x10A0 0x10A8 0x10B0 … 0x1200 0x1018 0x1200 ret addr alloca %localN %local2 %local1 saved args saved %rbp value result of alloca %rsp %rbp Q: why do we need to save args?

  8. backend.sml – LLVM-- to x86 instruction generation • Simple strategy – compiling all %uids to stack- allocated slots • Each LLVM-- instruction may correspond to several x86 instructions • Strategy: • designate temporary registers for storing intermediate results when translating operands • e.g., %rax, %rcx • Q: callee-save vs caller-save registers?

  9. Functions • Function name: just a label • Function call: • Use assembly callq instruction • Function prologue: • save %rbp on stack; decrement %rsp • do not forget to copy arguments on the stack • Function epilogue: • invoked by LL terminators

  10. Other LL commands • Pick your compilation strategy, as long as you are within the bounds of what x86.sml o ff ers you (there is plenty of space) • Recommend to tackle GEP last • Generate test LL programs from your LL module

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