Introduction to LLVM (II)

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Introduction to Macromedia Director 8.5 – Lingo
Chapter 10- Instruction set architectures
Amazon CloudFront An introductory discussion. What is Amazon CloudFront? 5/31/20122© e-Zest Solutions Ltd. Amazon CloudFront is a web service for content.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Improving Code Generation Honors Compilers April 16 th 2002.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
IE 212: Computational Methods for Industrial Engineering
LLVM Compiler (2 of 3) Jason Dangel. Lectures High-level overview of LLVM (Katie) Walkthrough of LLVM in context of our project (Jason) –Input requirements.
CSC 338: Compiler design and implementation
Cosc 2150: Computer Organization
TIP TOP TIPS A presentation by: John H. Gonzaga. TIP TOP TIPS Displaying File Information Key Matches Link Checkers Monthly Analytics Report.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Website Improvements PNDWC INTERACTIVE GIS PROJECT.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
CSCE 548 Integer Overflows Format String Problem.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Construction Dr. Naveed Ejaz Lecture 4. 2 The Back End Register Allocation:  Have each value in a register when it is used. Instruction selection.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Lecture 14 Miscellaneous Topics II: Enuerations, Pointers to Functions (& Prelim Review)
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
Peyman Dodangeh Sharif University of Technology Fall 2014.
1 2/2/05CS250 Introduction to Computer Science II Pointers.
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Data Exchange Framework
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
LLVM Simone Campanoni
Writing an Assembly-language program MIPS assembly language using MARS: MIPS Assembler and Runtime Simulator CS-2710 Dr. Mark L. Hornick 1.
Automating Fortran - C Interoperability Prepared by: Sisi Liu (Garnet) Mentor: Dan Nagle Co-Mentor: Davide del Vento 1.
Core LIMS Training: Entering Experimental Data – Simple Data Entry.
Memory Management.
C++ Lesson 1.
Simone Campanoni LLVM Simone Campanoni
Advanced Computer Systems
Component 1.6.
Java SWING and Model View Controller (MVC)
Visit for more Learning Resources
Advanced Programming in Java
C++, OBJECT ORIENTED PROGRAMMING
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Variables, Expressions, and IO
Simone Campanoni LLVM Simone Campanoni
Chapter 1: Introduction to Compiling (Cont.)
LLVM Pass and Code Instrumentation
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Bojian Zheng CSCD70 Spring 2018
Optimizing Malloc and Free
Object Oriented Programming COP3330 / CGS5409
Code Generation.
Chapter 11 Introduction to Programming in C
Building Web Applications
Compiler Construction
Classes and Objects.
STL Iterators Separating Container from Data Access.
CISC/CMPE320 - Prof. McLeod
Bojian Zheng CSCD70 Spring 2018
HW2 – Frequent Path Loop Invariant Code Motion
Fundaments of Game Design
Compiler Construction
Compiler Structures 1. Overview Objective
Lecture 2 - Names & Functions
Presentation transcript:

Introduction to LLVM (II) Bojian Zheng CSCD70 Spring 2018 bojian@cs.toronto.edu

Makefile Error: Optimize.mk In the Optimize.mk file provided in the first assignment, you might need to add ./ in front of the optimizer target FunctionInfo.so. Thanks a lot to Chengyu (Tyrone) Xiong for pointing this out.

Review Keywords: Intermediate Representation (IR) Optimization Pass Analysis & Transformation

Review Keywords: Program Structure Iterators Downcasting LLVM Pass Interface

Transformations

Insert/Remove/Move/Replace Instructions Three Options Instruction class methods. Ask parent (BasicBlock) to do this. Make use of BasicBlockUtils.

Attention! Iterator Hazard As you do transformations, iterators might be invalidated. → Demo on std::vector < unsigned > ::iterator Thanks a lot to Qiongsi Wu for bringing this up.

Attention! Reference Updates Original Code Transformed Code %2 = add %1, 0 %3 = mul %2, 2 %2 = add %1, 0 %3 = mul ???, 2

Questions? Keywords: Iterator Hazard References Update (More Later On)

LLVM Instruction: The User-Use-Usee Design Pattern

LLVM Class Hierarchies Value User Instruction

Value (Usee) The Value class is the most important base class in LLVM. It has a type (integer, floating point, …): getType() It might or might not have a name: hasName(), getName() Keeps track of a list of Users that are using this Value.

Instruction (User) An User keeps track of a list of Values that it is using as Operands: User user = … for (auto iter = user.op_begin(); iter != user.op_end(); ++iter) {Value * operand = *iter; …} An Instruction is a User.

But wait, … Is Instruction (User) a Value (Usee)? %2= add %1, 10 DO NOT interpret this statement as “the result of Instruction add %1, 10 is assigned to %2”, instead, think this way – “%2 is the Value Representation of Instruction add %1, 10 ”. Therefore, whenever we use the Value %2, we mean to use the Instruction add %1, 10 .

To Conclude Suppose we have an instruction: Instruction inst = … What is this instruction using? for (auto iter = inst.op_begin(); iter != inst.op_end(); ++iter) {…} What is using this instruction? for (auto iter = inst.user_begin(); iter != inst.user_end(); ++iter)

Questions? Keywords: User-Use-Usee Design Pattern

Optimizer Manager

Optimizer Manager What is this doing? void Analysis::getAnalysisUsage(AnalysisUsage & AU) const { AU.setPreservesAll(); } Very frequently, when writing a pass, we want the followings: What information does this pass require? Will this information still be preserved after this pass?

Questions Keywords: Require Preserve

Code Download Links Visitor Design Pattern https://github.com/ArmageddonKnight/CSCD70-Tutorial-Demo Visitor Design Pattern serves as an alternative to Dynamic Casting. You can find an example on this in the repository.