Implementation of a Frontend Compiler for OpenGL ES Shading Language with LLVM Yeoul Na, Seok Joong Hwang, Seon Wook Kim School of Electrical and Computer Engineering, Korea University, Seoul, Korea {rapidsna, nzthing, seon}@korea.ac.kr Abstract Many GPUs have become available in a consumer electronics market due to their performance and power efficiency. However, the internal implementations of GPU compilers are still undisclosed to our community. In this paper, we show implementation of a frontend compiler for OpenGL ES Shading Language on GPUs, which is based on the LLVM compiler. We verified the correctness and conformance of the compiler with WebGL testsuite. 1 Keywords: compiler, GPU, OpenGL, LLVM, Shading Language 1. Introduction Recently, GPUs have become more and more popular in consumer electronic devices due to their power efficient nature for compute-intensive applications. The recent state-of-the-art processors embed GPU on one die as an accelerator [1, 2]. However, despite the popularity, the implementation of their shader compilers is rarely found in research papers. In this paper, we discuss the implementation issues and show the internal implementation of the compiler. Our compiler, an extension of LLVM 2.7 [3] C++ compiler, supports OpenGL ES Shading Language [4] and targets a commercial GPU, VRender 510 [5]. We verified the correctness and conformance of the compiler with WebGL testsuite [6]. The remainder of this paper is organized as follows. Section 2 demonstrates the implementation details of our OpenGL ES Shading Language compiler. Section 3 This work was supported by the IT R&D program of MKE/KEIT. [10041686, Cooperative Control Communication/Security Technology and SoC Development for Autonomous and Safe Driving System] presents the test methodology and verification of our compiler. Finally, Section 4 concludes this paper. 2. OpenGL ES Shading Language Compiler The implementation of an OpenGL ES Shading Language compiler involves two steps: extension of a frontend to support its grammar and adaptation of a backend to a GPU target. In the interest of space, the backend design is not covered, albeit many important design and optimization issues due to the GPUs SIMT nature. Although rudimentarily similar with C++ grammar, OpenGL ES Shading Language has grammatical extensions as listed in Table 1 [4]. Only some major categories are described in the following subsections due to the page limit. Table 1: The required extensions of C++ into OpenGL ES Shading Language compiler. Category Extension Built-in data type Matrix (mat2, mat3, mat4) sampler2D, samplerCube Operation Vector ++,-- operations Matrix operations Precision qualifier highp, mediump, lowp Storage qualifier attribute, uniform, varying Parameter qualifier in, out, inout Special variables gl_Position, gl_FragColor, etc. New statement discard 2.1. Built-in data types The llvm frontend, clang, supports vector type extensions with ext_vector_type attribute [3]. We simply utilized this extension in order to define the built-in vector types, i.e., vec2, ivec3, etc. Each matrix