Generating Serialisation Code with Clang



Similar documents
Digital Infrastructure and Economic Development. An Impact Assessment of Facebook s Data Center in Northern Sweden executive summary

Indian E-Retail Congress 2013

The Data Center of the Future: Creating New Jobs in Europe

DHL Global Energy Conference 2015 Outsourcing logistics Enhancing innovation or increasing risk?

What Makes Cities Successful Randstad on the World Stage

Global Real Estate Outlook

Denied Boarding Eligibility

Goodbye Spokesperson, Hello Steward

ROLE SPECIFICATION INTERNATIONAL FINANCE CORPORATION

Coaching Executives: Building Emotional Intelligence


at the pace of business Leadership development In-house programs available! The Leadership Express Series Ottawa, ON

Denied Boarding Eligibility

seeing the whole picture HAY GROUP JOB EVALUATION MANAGER

Connect the Leading Global Financial Centres by Ultra Low Latency Network

1999 COMMUNICATIONS STUDY LINKING COMMUNICATIONS WITH STRATEGY TO ACHIEVE BUSINESS GOALS

T&E. Where Business Travelers Spend Money

The World s Most Competitive Cities. A Global Investor s Perspective on True City Competitiveness

How CPG manufacturers and retailers can collaborate to create offers that will make a difference. Implications of the Winning with Digital Study

Greater than the Sum of its Parts: Professionalizing the Supervisory Board

Joint General Assembly APLAC-PAC 2014 June 21-28, Guadalaja, Mexico

Opportunities for Action. Achieving Success in Business Process Outsourcing and Offshoring

An introduction to the Rothschild businesses

Freight Forwarders: Thinking Outside the Box

2015 City RepTrak The World s Most Reputable Cities

AT-A-GLANCE DATA CENTER INDUSTRY SEGMENTS

STREAMLINE YOUR TRADING COMMUNITY TRADING COMMUNITY SERVICES

Fact sheet DTZ Fair Value Index TM methodology

The Real Supply Chain Challenge Leadership and Talent Management

Opportunities for Action in Industrial Goods. Winning by Understanding the Full Customer Experience

Alvarez & Marsal Global Forensic and Dispute Services Asia Pacific Regional Meeting (APRM) Tokyo, Japan April 2015

Human Resources Specialty Practice.

P R E S S R E L E A S E

Opportunities for Action. Shared Services in Operations and IT: Additional Complexity or Real Synergies?

Internet of Things, a key lever to reduce CO 2 emissions

CRITICAL THINKING AT THE CRITICAL TIME CONSTRUCTION SOLUTIONS

Real Estate. Expertise of a boutique. Reach of a global firm.

Synopsis: In the first September TripCase product release there will be several big updates.

board solutions litigation support services Executive compensation

Accredited TOGAF 9, ArchiMate 2 and IT4IT Training Course Calendar June 2016 onwards

Financial services regulation in Australia

SEC Staff Addresses Third-Party Endorsements of Investment Advisers on Social Media Websites

The leading adviser in the global education sector

Virtualization in Enterprise Environment. Krisztian Egi

Global Office Thermometer

Be clear about your talent management goals

Opportunities for Action in Information Technology. IT Outsourcing Rediscovered: Getting Your Share This Time Around

Rents continue to recover. Global Office Index Q2 2014

Opportunities for Action in Operations. Working Capital Productivity: The Overlooked Measure of Business Performance Improvement

Aiming for Outsourcing Excellence

Opportunities for Action in Financial Services. Transforming Retail Banking Processes

Opportunities for Action in Industrial Goods. The Price Is Right: Optimizing Industrial Companies Pricing of Services

cybersecurity dinner 2015

Opportunities for Action in Financial Services. Sales Force Effectiveness: Moving Up the Middle and Managing New Prospects

Accredited TOGAF 9 and ArchiMate 2 Training Course Calendar February 2016 onwards

Opportunities for Action in Consumer Markets. To Spend or Not to Spend: A New Approach to Advertising and Promotions

CITY OF CHICAGO BUILDING ENERGY USE BENCHMARKING AND TRANSPARENCY

Ken Favaro Ashish Jain Samuel Bloustein. Small Business Banking Customers An Attractive Segment for Organic Growth

The Global Financial Centres Index 16

Opportunities for Action in Financial Services. Growing Profits Under Pressure: Integrating Corporate and Investment Banking

India. Doorway to opportunities

Cargo Sales & Service Presentation

Seamus McMahon Ashish Jain Kumar Kanagasabai. Redefining the Mission for Banks Call Centers Cut Costs, Grow Sales, or Both

Define your goals, we ll do the rest

GLOBAL FINANCIAL CENTRES 7

Cargo Sales & Service Presentation. Air Logistics UK

Customer Relationship. Opportunities for Action in the Pulp and Paper Industry. Management in the Paper Industry

Launch of Mutual Recognition of Funds Between Mainland China and Hong Kong

São Paulo Office Skyline July 2014

Removal of Credit Ratings References

Opportunities for Action in Consumer Markets. Fast Is Good, but Smart Is Better

Elements of an Organization That Can Work For the Police

The Global Financial Centres Index 11

SRM How to maximize vendor value and opportunity

SOCIAL MEDIA STRATEGY EXECUTION 10 STEPS DIGITAL SERIES

Global Cities Which global cities are performing best today, which have the best long-term potential, and what makes a smart city?

GOING FOR GOLD IN THE GLOBAL OFFICE MARKET

Global Cities, Present and Future

Occupier Perspective Global Occupancy Costs - Offices 2013 Cost saving opportunities in weak markets

Guide. Axis Webinar. User guide

World City Millionaire Rankings. May 2013

Bring a Big World Closer

How to ace the case interview

WEALTH MANAGEMENT. Strengthen Client Relationships with Cost Effective Data and Technology Solutions

Phoenix Agenda Inside Tomorrow s Retail Bank

DOE Announces Fundamental Shift in LNG Export Authorization Policy

BUILDING A SUCCESSFUL ROADMAP TO THE CLOUD

THINK Global: Risk and return

Eight Best Practices for Conducting a Successful General Counsel Search

Health Care Viewpoint

Competing for Small Business P&C Insurance. Strategy for growth

Transcription:

EURO-LLVM CONFERENCE 12 th April 2012 Wayne Palmer Generating Serialisation Code with Clang 1

INTRODUCTION TO THE QUANTITATIVE ANALYTICS LIBRARY A single C++ library of nearly 10 million lines of code. Delivered 2-3 times a week to each of the trading and risk management desks around the bank. Calculates risk. Calculates how to hedge that risk. Generating Serialisation Code with Clang 2

INTRODUCTION TO THE QUANTITATIVE ANALYTICS LIBRARY Market behaviour generally too complex to model using closed-form methods. Significant amount of calculations in QA use Monte Carlo techniques. Monte Carlo computationally expensive. 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Random Points Quarter Circle Unit Unit Square Generating Serialisation Code with Clang 3

THE NEED FOR SERIALISATION On a single machine, risk calculations would take days or even weeks. The requirement is for risk calculations to take anywhere from milliseconds to overnight. For speed, calculations are distributed to a grid. Currently there are: 55,000 CPU Cores. 25,000 servers and scavenged workstations. 100 million tasks are run each day. 50% CPU core growth each year. To communicate between processes on the grid we need to serialise data structures. Generating Serialisation Code with Clang 4

THE NEED FOR SERIALISATION Hand written serialisation code. Time consuming. Not a scalable solution. Maintenance costs increase as library size increases. Fundamental changes need to be rolled out to every data structure. Prone to human error. Hard to enforce standards. Generating Serialisation Code with Clang 5

A BIT OF HISTORY Automation of serialisation code generation previously used Doxygen. Not designed with the intention of generating code for serialisation. Would only run on directories and not individual translation units. Built up massive data structures in memory. Slow. Not a C++ compiler, but a C++ parser. Implementation not separated from functionality. Difficult to integrate with the build system. Generating Serialisation Code with Clang 6

ENTER CLANG Serialisation with Clang Clang AST easy to use. Fast. Accurate. Can use attributes to identify structures for serialisation. Generate customised errors with respect to serialisation. Runs on translation units. Seamlessly integrated into our Build System. Can easily deliver wholesale changes to serialisation. Easily rollout new output formats, i.e. JSON, XML, Binary. Change existing formats. Generating Serialisation Code with Clang 7

THE POWER OF ATTRIBUTES Clang has great support for finding attributes. Separates functionality from implementation. Can easily add / remove serialisation by adding / removing the attribute. Don t have to alter the class implementation. Hard to mistake the identity of the class. #ifdef clang # define ATTR(...) attribute ((annotate( " " # VA_ARGS ))) #else # define ATTR(...) #endif Generating Serialisation Code with Clang 8

THE POWER OF ATTRIBUTES #ifndef SIMPLE_H #define SIMPLE_H #include "ATTR.h" class ATTR(serialise) Simple { public: Simple() : m_sermember(65) {} int m_sermember; virtual void needamethod(); virtual ~Simple() {} }; #endif // SIMPLE_H Generating Serialisation Code with Clang 9

THE POWER OF ATTRIBUTES #ifndef SIMPLE_H #define SIMPLE_H #include "ATTR.h" class ATTR(serialise) Simple { public: Simple() : m_sermember(65), m_nosermember(65) {} int m_sermember; char ATTR(no_serialise) m_nosermember; virtual void needamethod(); virtual ~Simple() {} }; #endif // SIMPLE_H Generating Serialisation Code with Clang 10

THE POWER OF ATTRIBUTES #ifndef SIMPLE_H #define SIMPLE_H #include "ATTR.h" class ATTR(hand_serialise(HandSer.h)) Simple { public: Simple() : m_sermember(65) {} int m_sermember; virtual void needamethod(); virtual ~Simple() {} }; #endif // SIMPLE_H Generating Serialisation Code with Clang 11

ONCE AND ONLY ONCE How do we identify the data structures for which we want to generate serialisation code? How do we ensure each data structure has serialisation code generated? How do we ensure this is all done seamlessly within the build system? Generating Serialisation Code with Clang 12

ONCE AND ONLY ONCE Translation units can include many declarations of classes that require serialisation. Generating Serialisation Code with Clang 13

ONCE AND ONLY ONCE Class declarations that require serialisation can be included in more than one translation unit. Generating Serialisation Code with Clang 14

FINDING THE KEY FUNCTION Must find a key function. A method that makes this class unique to this translation unit. Same as Clang key function for finding where to place a v-table. However, don t care if it is virtual or non-virtual. Generating Serialisation Code with Clang 15

FINDING THE KEY FUNCTION Visit each method of the Clang AST (CXXMethodDecl). void Action::VisitCXXMethodDecl( CXXMethodDeclIter iter ) { } Generating Serialisation Code with Clang 16

FINDING THE KEY FUNCTION Throw away methods that have no declaration context (global scope). clang::declcontext const * declctxt(iter->getdeclcontext()); if (!declctxt) return; Generating Serialisation Code with Clang 17

FINDING THE KEY FUNCTION If the declaration context is a class or struct (CXXRecordDecl) then take a closer look at this class. Traverse each method of this CXXRecordDecl looking for a key method. if (clang::cxxrecorddecl const * cxxrecdecl = dyn_cast<clang::cxxrecorddecl>(declctxt)) Generating Serialisation Code with Clang 18

FINDING THE KEY FUNCTION Key function won t be unique if it is in the header file, i.e.: Implicitly generated by the compiler (i.e. constructors). Inline specified or have an inline body. Pure virtual function most probably has no implementation. If the function is none of these things, it is the key function. if (methoddecl->ispure()) continue; if (methoddecl->isimplicit()) continue; if (methoddecl->isinlinespecified()) continue; if (methoddecl->hasinlinebody()) continue; founddecl = methoddecl; break; Generating Serialisation Code with Clang 19

CAN T FIND A KEY FUNCTION What if a class that requires serialisation has no key function? Manually add a key method. size_t = sizeof(t) ensures that T is a complete type. struct Reflection { template<typename T> static void owner(const T &, const size_t = sizeof(t)); }; #define OWN_THE_SERIALISATION_FOR(TYPE) \ template<> void Reflection::owner(const TYPE &, const size_t); OWN_THE_SERIALISATION_FOR(A) Generating Serialisation Code with Clang 20

GENERATING FOR A SIMPLE CLASS Now that we have found a unique identifier for struct A (the key method of A), check that it has attribute serialise. If so, Clang can easily generate code capable of serialising the object in the file A.ser.cpp. Generating Serialisation Code with Clang 21

COMPILING FOR A SIMPLE CLASS The build system then force includes the file A.ser.cpp into A.cpp. Seamlessly, the developer s struct A is now capable of being serialised / deserialised. Generating Serialisation Code with Clang 22

WHAT CLANG GENERATES ONE CLASS Code generation for a simple struct (or class) A. Generate the declaration for the serialise function. Generate the definition for the serialise function. Generating Serialisation Code with Clang 23

WHAT CLANG GENERATES INHERITANCE When struct A derives from B: Since we want our build system to compile this file straight away, the declaration for serialising B ( serialise<b>() ) must be generated now in the file A.ser.cpp. Without this, gates in the build system would have to be introduced. All classes that inherit from B will generate this declaration. Clang will generate the definition for serialise<b>() when processing B. Generating Serialisation Code with Clang 24

WHAT CLANG GENERATES IMPLICIT TEMPLATES For templated types we chose to generate templates rather than specialisations less code generation required. The declaration and definition for templated types must be generated by Clang. Generating Serialisation Code with Clang 25

OTHER USES OF CLANG WITHIN BARCLAYS Automatic generation of the Quantitative Analytics library interface. Keyhole interface similar to COM. Must maintain backwards compatibility. Generates C++, COM, SWIG (Java),.NET (C++/CLR) interfaces automatically. Enforcing standards on the use of framework classes. Thread safety mark-up. Generating Serialisation Code with Clang 26

QUESTIONS EMEA Amsterdam Birmingham Doha Dubai Dublin Frankfurt Geneva Glasgow Johannesburg Kiev Lisbon London Lugano Luxembourg Madrid Manchester Milan Moscow Paris Prague Rome Tel Aviv Zurich AMERICAS Atlanta Boston Buenos Aires Calgary Chicago Dallas Houston Los Angeles Menlo Park Mexico City Miami New York Portland Puerto Rico San Diego San Francisco Santa Monica Sao Paulo Seattle Toronto Washington, DC ASIA Beijing Hong Kong Jakarta Kuala Lumpur Labuan Manila Mumbai Seoul Shanghai Singapore Sydney Taipei Tokyo Generating Serialisation Code with Clang 27