The architecture of the P416 compiler

Slides:



Advertisements
Similar presentations
P4: specifying data planes
Advertisements

ENGINEERING WORKSHOP Compute Engineering Workshop P4: specifying data planes Mihai Budiu San Jose, March 11, 2015.
Cpeg421-08S/final-review1 Course Review Tom St. John.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
LLVM Developed by University of Illinois at Urbana-Champaign CIS dept Cisc 471 Matthew Warner.
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
COP4020 Programming Languages
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Introduction to Compiling
Customizing OVS using P4 Muhammad Shahbaz with Sean Choi, Ben Pfaff, Chaitanya Kodeboyina, Changhoon Kim, Nick McKeown, Nick Feamster, and Jen Rexford.
Software Testing Mehwish Shafiq. Testing Testing is carried out to validate and verify the piece developed in order to give user a confidence to use reliable.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Credible Compilation With Pointers Martin Rinard and Darko Marinov Laboratory for Computer Science Massachusetts Institute of Technology.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Open Source Compiler Construction (for the JVM)
Principles of Programming & Software Engineering
INTRO. To I.T Razan N. AlShihabi
P4: specifying data planes
Advanced Computer Systems
Software Testing.
Compiler Design (40-414) Main Text Book:
INF230 Basics in C# Programming
PRINCIPLES OF COMPILER DESIGN
Introduction to Compiler Construction
Compiler Construction (CS-636)
Behavioral Design Patterns
Software Engineering Fall 2005
April 28, 2017 SUMIT MAHESHWARI INES UGALDE
Part 3 Design What does design mean in different fields?
Topic: Functions – Part 2
课程名 编译原理 Compiling Techniques
The Client/Server Database Environment
Introduction Enosis Learning.
Compiler Construction
CS416 Compiler Design lec00-outline September 19, 2018
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
Functional Programming with Java
Introduction to Compiler Construction
Introduction Enosis Learning.
Introduction CI612 Compiler Design CI612 Compiler Design.
DC.p4: Programming the forwarding plane of a datacenter switch
Unit# 9: Computer Program Development
Aspect Validation: Connecting Aspects and Formal Methods
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
Component-Level Design
COP4020 Programming Languages
CMPE 152: Compiler Design August 23 Class Meeting
P4FPGA : A Rapid Prototyping Framework for P4
CS416 Compiler Design lec00-outline February 23, 2019
Introduction to Compiler Construction
CMPE 152: Compiler Design January 29 Class Meeting
Intermediate Code Generation
Chapter 10: Compilers and Language Translation
Outline System architecture Current work Experiments Next Steps
Compiler Construction
Chap 1. Getting Started Objectives
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Oriented Design and Abstract Data Type
Digital Designs – What does it take
Introduction to Compiler Construction
Presentation transcript:

The architecture of the P416 compiler May 17, 2017 - P4 workshop, Stanford Mihai Budiu, VMware Research Chris Doss, Barefoot Networks

P416 Newest version of the P4 language (finalized yesterday!) https://github.com/p4lang/p4-spec/tree/master/p4-16/spec This talk is about the (reference implementation) compiler for P416 Compiles both P414 (i.e., P4 v1.0 and P4 v1.1) and P416 programs Apache 2 license, open-source, reference implementation http://github.com/p4lang/p4c

Compiler goals Support current and future versions of P4 Support multiple back-ends Generate code for ASICs, NICs, FPGAs, software switches and other targets Provide support for other tools (debuggers, IDEs, control-plane, etc.) Open-source front-end Extensible architecture (easy to add new passes and optimizations) Use modern compiler techniques (immutable IR*, visitor patterns, strong type checking, etc.) Comprehensive testing *IR = Intermediate Representation

Compiler data flow P414 P416 mid- end ebpf back-end P414 parser C code P414 parser convert v1 IR P414 mid- end BMv2 back-end frontend JSON IR IR P416 parser P416 mid- end your own backend target- specific code

IR with target-specific Compiler structure IR with target-specific extensions Same IR Front-end Mid-end Back-end P4 IR IR Target-independent ~25 distinct passes Target-specific ~25 distinct passes

Structure P4 IR IR Library of pre-built passes Fixed Mix and match Custom Front-end Mid-end Back-end P4 IR IR main() libFrontEnd.a Simplify IR eliminating constructs gradually

Implementation details Common infrastructure for all compiler passes Same IR and visitor base classes Common utilities (error reporting, collections, strings, etc.) C++11, using garbage-collection (-lgc) Clean separation between front-end, mid-end and back-end New mid+back-ends can be added easily IR can be extended (front-end and back-end may have different IRs) IR can be serialized to/from JSON Passes can be added easily

Intermediate Representation (IR) Immutable Can share IR objects safely Even in a multi-threaded environment You cannot corrupt someone else’s state Strongly-typed (hard to build incorrect programs) DAG structure, no parent pointers Manipulated by visitors IR class hierarchy is extensible

IR P4 IR always maintains source-level position Front-end and mid-end maintain invariant that IR is always serializable to a P4 program Simplifies debugging and testing Easy to read the IR: just generate and read P4 Easy to compare generated IR with reference (testing) Compiler can self-validate (re-compile generated code) Dumped P4 can contain IR representation as comments IR always maintains source-level position can emit nice error message anywhere

Visitor pattern https://en.wikipedia.org/wiki/Visitor_pattern “In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures.” “Structure” = IR “Algorithms” = program manipulations

IR rewriting using visitors Input DAG Output DAG visitor Modified DAG New DAG Dead code

IR definition language compiled to C++ interface IDeclaration { … } abstract Expression { … } abstract Statement : StatOrDecl {} class AssignmentStatement : Statement { Expression left; Expression right; print{ out << left << " = " << right; } } Class hierarchy IR fields

Learning the IR by example Front-end and mid-end passes can all dump IR back as P4 source with IR as comments /* <P4Program>(18274) <IndexedVector<Node>>(18275) */ /* <Type_Struct>(15)struct Version */ struct Version { /* <StructField>(10)major/0 <Annotations>(2) <Type_Bits>(9)bit<8> */ bit<8> major; ...

v1model.p4: A P414 switch model A P416 switch architecture that models the fixed switch architecture from the P414 spec Provides backward compatibility for P414 programs Parse verify cksum ingress egress compute cksum deparse

Testing the compiler Dump program at various points and compare with reference Compare expected compiler error messages (on incorrect programs) Recompile P4 generated by compiler Run v1model.p4 programs using BMv2 on packet traces and compare to expected output P4 p4c stderr P4 P4 P4 = = = = P4 P4 P4 errors Expected output P4 p4c P4 p4c P4 p4c expected packet trace json = BMv2 simulator packet trace packet trace

Lessons P416 is a simple language,… but the P4 environment is complicated Supports arbitrary architectures Arbitrary functionality in the architecture Arbitrary extensions (extern blocks) P416 is designed for extensibility Compilers must support extensibility while preserving stability Modularity/extensibility seems to work At least 5 existing back-ends, for software, simulators, FPGAs, ASICs Specification Implementation Great community: thank you all!