Lld The LLVM Linker Friday, April 13, 2012 2012 LLVM Euro - Michael Spencer.
A SURVEY OF PACE AND LLVM - capsl.udel.edu
Transcript of A SURVEY OF PACE AND LLVM - capsl.udel.edu
![Page 1: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/1.jpg)
A SURVEY OF PACE AND LLVMCPEG 621
Kirk Kelsey — ET InternationalOctober 27th 2010
![Page 2: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/2.jpg)
Open64 Compiler(PathScale, OBC, Osprey)SGI Pro Compiler
LLVM
10/20/10 Open64 Tutorial - An Introduction 5
A MAP OF MODERN COMPILER PLATFORMS
1980 1985 1990 1995 2000 2005 2010
RISC VLIW/SuperScalar EPIC/MP CMP/MT
Cydra VLIW Compiler
GNU Compilers
IMPACT Compiler
HP Research Compiler
Trimaran Compiler
Multiflow VLIW
Compiler
Ucode CompilerChow/Hennessy SUIF Compiler
![Page 3: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/3.jpg)
PACE
Open64 Compiler(PathScale, OBC, Osprey)SGI Pro Compiler
LLVM
10/20/10 Open64 Tutorial - An Introduction 5
A MAP OF MODERN COMPILER PLATFORMS
1980 1985 1990 1995 2000 2005 2010
RISC VLIW/SuperScalar EPIC/MP CMP/MT
Cydra VLIW Compiler
GNU Compilers
IMPACT Compiler
HP Research Compiler
Trimaran Compiler
Multiflow VLIW
Compiler
Ucode CompilerChow/Hennessy SUIF Compiler
![Page 4: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/4.jpg)
OUTLINE
• Open 64
• National Compiler Infrastructure Project
• Architecture-Aware Compiler Environment
• Low-Level Virtual Machine
3
![Page 5: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/5.jpg)
OPEN 64Xiaomi An
![Page 6: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/6.jpg)
PACE
Open64 Compiler(PathScale, OBC, Osprey)SGI Pro Compiler
LLVM
10/20/10 Open64 Tutorial - An Introduction 5
A MAP OF MODERN COMPILER PLATFORMS
1980 1985 1990 1995 2000 2005 2010
RISC VLIW/SuperScalar EPIC/MP CMP/MT
Cydra VLIW Compiler
GNU Compilers
IMPACT Compiler
HP Research Compiler
Trimaran Compiler
Multiflow VLIW
Compiler
Ucode CompilerChow/Hennessy SUIF Compiler
![Page 7: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/7.jpg)
NATIONAL COMPILER INFRASTRUCTURE PROJECT
SUIF
• Stanford University Intermediate Format• also: Harvard, Rice, MIT, and the Portland Group
• Funded by DARPA and NSF
• Leveraged GCC and EDG
6
![Page 8: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/8.jpg)
AACE
• Architecture Aware Compilation Environment
• Motivation:
• processor design complexity continues to grow
• performance tuning an application is directly related
• compilers are the gatekeepers and bottlenecks
http://www.darpa.mil/tcto_aace.html
7
![Page 9: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/9.jpg)
THE PACE PROJECT
• $16 million DARPA award
• Headed by researchers at Rice UniversityThe Ohio State University, Stanford University, Texas Instruments
• Focused on reducing compiler development timetakes ~5 years to develop a compiler for a new architecture
http://pace.rice.edu/
8
![Page 10: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/10.jpg)
PACE
OBJECTIVES
• Understand the compilation• the capabilities of the compiler• how the application is used• the attributes of the hardware
• Support multiple levels of transformationeach based on different characteristics
• Use feedback from past compilation
9
![Page 11: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/11.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
10
![Page 12: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/12.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Platform Aware Optimizer
Target Aware Optimizer
X86 Backend
Application AwarePartitioner
Source Code
10
![Page 13: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/13.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
X86 Backend
Application AwarePartitioner
Source Code
10
![Page 14: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/14.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
10
![Page 15: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/15.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
10
![Page 16: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/16.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
10
![Page 17: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/17.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
10
![Page 18: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/18.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
Compiler Characterization
10
![Page 19: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/19.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
Compiler Characterization
micro-benchmarks
10
![Page 20: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/20.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
Compiler Characterization
micro-benchmarks
Generic Backend
10
![Page 21: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/21.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
Compiler Characterization
micro-benchmarks
Runtime System
Generic Backend
10
![Page 22: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/22.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
Compiler Characterization
Knowledge Base
Learning Engine
micro-benchmarks
Runtime System
Generic Backend
10
![Page 23: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/23.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
Compiler Characterization
Knowledge Base
Learning Engine
micro-benchmarks
Runtime System
Generic Backend
10
![Page 24: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/24.jpg)
PACE COMPILER
HIGH LEVEL DESIGN
Translator
Platform Aware Optimizer
Target Aware Optimizer
Native CompilerX86 Backend
Application AwarePartitioner
Source Code
Application Profile
System Characterization
Compiler Characterization
Knowledge Base
Learning Engine
micro-benchmarks
Runtime System
Generic Backend
10
![Page 25: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/25.jpg)
AAP: INPUT & OUTPUT• Input• program source code• application characterization — execution profiles• native compiler characterization
•Output•Refactored Program Units (RPUs)
Application Aware Partitioner
Application Characterization
RPU
RPU
RPU
RPU
RPU
RPU
Source Code
1. Parse Profile
2. Partition Graph
3. Restructure Code
11
![Page 26: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/26.jpg)
PLATFORM AWARE OPTIMIZER
• Understands the target system attributes• relies on micro-benchmarks that extract the information
• Performs AST based transformations• data flow analysis, abstract interpretation, symbolic execution• value-based specialization
based on program data values and addresses• polyhedral and non-polyhedral loop transformations• data transformations:
privatization, scalar replacement, alignment, padding, array and struct redistribution
12
![Page 27: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/27.jpg)
TARGET AWARE OPTIMIZER•low-level optimization tailor the code to specific target
•measured capacities (e.g., Maxlive, # issue slots)•optimizations native compiler lacks (e.g. software pipelining)
•provides feedback to PAO on effectiveness of transformations• scheduler sees too little ILP ask PAO to generate more• register pressure high in a loop ask PAO to tone it down•decides to pipeline loop ask PAO to remove control flow
•generates assembly code for various strains of IA32• IA32 is sufficiently popular to merit the attention•chance to experiment with static and runtime optimizations•proof of concept for characteristic-driven optimization
13
![Page 28: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/28.jpg)
PAO TO TAO
QUERY INTERFACE• PAO queries TAO for expected performance
• Encapsulates code in a synthetic function with a query object
• TAO applies standard scalar compiler optimizations• Driven by processor characteristics• Uses a pseudo-backend based on the Resource Characteristics• Records static metrics for low-level code in the query
• PAO interprets query results and chooses transformation parameters based on TAO feedback
• E.g., choosing unroll factors for each loop in a loop nest14
![Page 29: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/29.jpg)
PAO-TAO INTERFACES
1. IR Translation PAOTAO
2. Profile Info PAO TAO
3. Code fragments PAOTAO
4. Cost Analysis TAOPAO
5. Rate-limiting resource for code regions, TAO PAO
6. Alias/Dep Info
7. Per-region control options/directives/annotations
8. IR Translation PAOTAO
15
![Page 30: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/30.jpg)
PACE
GENERIC BACKEND
• Generalizes some target attributes• Register availability & aliasing• Instruction latency• Functional unit availability
• Supports the query answering mechanism
• Used for synthetic code generation(not actual compilation)
16
![Page 31: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/31.jpg)
LLVM
![Page 32: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/32.jpg)
LLVM
ORIGINS & OVERVIEW
• LLVM is:
• not a virtual machine
• a generic, low-level intermediate representation
• a complete compiler tool-chain
• Developed at UIUC
18
![Page 33: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/33.jpg)
LLVM STRUCTURE
BitcodeLLVMAssembly
Source Code
Front End
JIT Machine Assembly
Optimizer
Compiler
Linker
19
![Page 34: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/34.jpg)
LLVM
FRONT END
• Generates LLVM IR
• There are three available:
• LLVM-gcc Modified version of GCC 4.2.1
• Clang C Language Front End (and Obj-C, C++)
• Dragon Egg plugin to GCC versions 4.5 and later
20
![Page 35: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/35.jpg)
LLVM
CLANG
• Supports development of multiple client types
• static analyzers, rewriters, code generation
• Compatible with GCC
• Detailed and intuitive diagnostic messages
• Better IDE support
21
![Page 36: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/36.jpg)
LLVM
INTERMEDIATE REPRESENTATION
• Used in three forms • (in memory, on disk, human readable)
• SSA Based, low-level representation
• Typed and extensible
• Expressive• Multiple linkage types (visibility)• Multiple calling conventions
22
![Page 37: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/37.jpg)
LLVM
PHI EXAMPLE
Syntax:
<result> = phi <ty> [ <val0>, <label0>], ...
; Infinite loop that counts from 0 on up...Loop: %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] %nextindvar = add i32 %indvar, 1 br label %Loop
23
![Page 38: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/38.jpg)
LLVM
HELLO WORLD; Declare the string constant as a global [email protected] = internalconstant[13 x i8] c"hello world\0A\00"
; External declaration of the puts functiondeclare i32 @puts(i8*)
; Definition of main functiondefine i32 @main() { ; i32()* ; Convert [13 x i8]* to i8 *... %cast210 = getelementptr [13 x i8]* @.LC0, i64 0, i64 0
; Call puts function to write out the string to stdout. call i32 @puts(i8* %cast210) ; i32 ret i32 0 }; Named metadata!1 = metadata !{i32 41}!foo = !{!1, null}
24
![Page 39: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/39.jpg)
LLVMMIDDLE END
![Page 40: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/40.jpg)
OPT
• Supports dynamically loaded passes
• All passes are automatically scheduled
• Provides analysis to later passes(alias, dependence, pointer bounds)
• Provides transformation passes(dead code, loop {invariant motion, unrolling, switching})
• Results in a new bitcode file26
![Page 41: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/41.jpg)
WRITING AN OPT PASS#include "llvm/Pass.h"#include "llvm/Function.h"#include "llvm/Support/raw_ostream.h"using namespace llvm;struct Hello : public FunctionPass {
static char ID;Hello() : FunctionPass(&ID) {}
virtual bool runOnFunction(Function &F) {errs() << "Hello: " << F.getName() << "\n";return false;
}};char Hello::ID = 0;INITIALIZE_PASS(Hello, "Hello", "Hello World Pass", false, false);
27
![Page 42: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/42.jpg)
BACKEND
![Page 43: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/43.jpg)
LLVM TARGET INDEPENDENT
CODE GENERATOR
• Abstract target description
• Classes to represent the code being generated
• Representation of assembly level constructs
(labels, sections, and instructions)
• Target-independent algorithms
• Target description interfaces for particular targets
• The target-independent JIT components
29
![Page 44: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/44.jpg)
CODE GENERATION
STAGES• Instruction Selection
• Scheduling and Formation.
• SSA-based Machine Code Optimizations
• Register Allocation
• Prolog/Epilog Code Insertion
• Late Machine Code Optimizations
• Code Emission30
![Page 45: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/45.jpg)
CODE GENERATION
STAGES• Instruction Selection
• Scheduling and Formation.
• SSA-based Machine Code Optimizations
• Register Allocation
• Prolog/Epilog Code Insertion
• Late Machine Code Optimizations
• Code Emission30
![Page 46: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/46.jpg)
TARGET DESCRIPTION
• TargetMachine – provides access to:
• TargetData – endian-ness, alignments, pointer size
• TargetLowering – LLVM IR to Selection DAG information
• TargetRegisterInfo – number, class, aliases
• TargetInstructionInfo – mnemonic, operands, implicit registers
• TargetFrameInfo – stack direction, alignment, offset
• TargetSubtarget – supported instructions, their latencies, etc
• TargetJITInfo – [optional]31
![Page 47: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/47.jpg)
SELECTION DAG
• Graph representation of code
• Each node represents one instruction
• Each edges represents a dependency
• Used for instruction selection and scheduling
32
![Page 48: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/48.jpg)
SELECTION DAG
EXAMPLE
33
%T1 = fadd float %W, %X%T2 = fmul float %T1, %Y%T3 = fadd float %T2, %Z
![Page 49: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/49.jpg)
SELECTION DAG
EXAMPLE
33
%T1 = fadd float %W, %X%T2 = fmul float %T1, %Y%T3 = fadd float %T2, %Z
fadd:f32 W, X fmul:f32 [?], Y fmul:f32 [?], Z
![Page 50: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/50.jpg)
SELECTION DAG
EXAMPLE
33
%T1 = fadd float %W, %X%T2 = fmul float %T1, %Y%T3 = fadd float %T2, %Z
(fadd:f32 (fmul:f32 (fadd:f32 W, X), Y), Z)
fadd:f32 W, X fmul:f32 [?], Y fmul:f32 [?], Z
![Page 51: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/51.jpg)
SELECTION DAG
EXAMPLE
34
(fadd:f32 (fmul:f32 (fadd:f32 W, X), Y), Z)
(FADDS (FMULS (FADDS W, X), Y), Z)
![Page 52: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/52.jpg)
SELECTION DAG
EXAMPLE
34
(fadd:f32 (fmul:f32 (fadd:f32 W, X), Y), Z)
(FADDS (FMULS (FADDS W, X), Y), Z)
(FMADDS (FADDS W, X), Y, Z)
![Page 53: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/53.jpg)
SELECTION DAG
EXAMPLE• def FMADDS : AForm_1<59, 29,(ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB), "fmadds $FRT, $FRA, $FRC, $FRB", [(set F4RC:$FRT,(fadd (fmul F4RC:$FRA, F4RC:$FRC), F4RC:$FRB))]>;
• def FADDS : AForm_2<59, 21, (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB), "fadds $FRT, $FRA, $FRB", [(set F4RC:$FRT, (fadd F4RC:$FRA, F4RC:$FRB))]>;
35
![Page 54: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/54.jpg)
INSTRUCTION SCHEDULING
• Several schedulers provided:
• Standard list based scheduling (top-down)
• Fast list based scheduling (bottom-up)
• Register reducing list scheduler (top-down or bottom-up)
• Plus hybrids to balance ILP/register pressure/latency
• Each target specifies its own default36
![Page 55: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/55.jpg)
REGISTER ALLOCATION
• LLVM IR uses “infinite” virtual registers
• Each target specifies:• available registers• super/sub registers• allocation order (per class)
• LLVM provides three allocators• fast• linear scan• PBQP
Partitioned Boolean Quadratic Programming
37
![Page 56: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/56.jpg)
LLC PLUGINS
• Each LLC pass is a distinct library
• Passes can be dynamically loaded(e.g. register allocator, instruction scheduler, GC Support)
• Target information must be defined statically
38
![Page 57: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/57.jpg)
LLVM
SUPPORTED TARGETS• X86
• PowerPC
• ARM
• Sparc
• Alpha
• MSP430
• Mips
• SystemZ
• XCore
• Blackfin
• CellSPU
• MBlaze
• PTX
http://llvm.org/docs/CodeGenerator.html#targetfeatures39
![Page 58: A SURVEY OF PACE AND LLVM - capsl.udel.edu](https://reader034.fdocuments.us/reader034/viewer/2022043020/626bdc7817a41e00a01a4f1a/html5/thumbnails/58.jpg)
OTHER TOOLS
• llvm: wrapper program (much like gcc)
• llvm-link: ‘links’ together several bitcode files
• llvm-ar : creates and ‘archive‘ of bitcode files (like ar)
• llvm-nm: lists symbol names (like nm)
• llvm-as: converts LLVM assembly to LLVM bitcode
• llvm-prof: profiles an LLVM execution40