blob: 3f5e374d3329087b031c6e8a6074eda9e60e0d47 [file] [log] [blame]
Shih-wei Liaocecdab22011-01-10 02:10:29 -08001===============================================================
2libbcc: A Versatile Bitcode Execution Engine for Mobile Devices
3===============================================================
Logan36fafd92011-01-08 22:55:19 +08004
5
6Introduction
7------------
8
Shih-wei Liao7fff2282011-01-09 13:57:01 -08009libbcc is an LLVM bitcode execution engine that compiles the bitcode
Shih-wei Liaocecdab22011-01-10 02:10:29 -080010to an in-memory executable. libbcc is versatile because:
11
12* it implements both AOT (Ahead-of-Time) and JIT (Just-in-Time) compilation.
13
14* Android devices demand fast start-up time, small size and high performance.
Shih-wei Liao7fff2282011-01-09 13:57:01 -080015
16libbcc provides:
17
Shih-wei Liaocecdab22011-01-10 02:10:29 -080018* a *just-in-time bitcode compiler*, which translates the bitcode into
Shih-wei Liao7fff2282011-01-09 13:57:01 -080019 machine code
20
21* a *caching mechanism*, which can:
22
Shih-wei Liaocecdab22011-01-10 02:10:29 -080023 * after each compilation, serialize the in-memory executable into a cache file.
Shih-wei Liao7fff2282011-01-09 13:57:01 -080024 Note that the compilation is triggered by a cache miss.
25 * load from the cache file upon cache-hit.
26
Logan36fafd92011-01-08 22:55:19 +080027Here are some highlights of libbcc:
28
Shih-wei Liao7fff2282011-01-09 13:57:01 -080029* libbcc supports bitcode from various language frontends, such as
Logan36fafd92011-01-08 22:55:19 +080030 RenderScript, GLSL.
31
32* libbcc strives to balance between library size, launch time and
33 steady-state performance:
34
Shih-wei Liao7fff2282011-01-09 13:57:01 -080035 * The size of libbcc is aggressively reduced for mobile devices.
Shih-wei Liaocecdab22011-01-10 02:10:29 -080036 We customize and we don't use the default Execution Engine from upstream.
Logan36fafd92011-01-08 22:55:19 +080037
38 * To reduce launch time, we support caching of binaries.
39
40 * For steady-state performance, we enable VFP3 and aggressive
41 optimizations.
42
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080043* Currently we disable Lazy JITting.
44
Logan36fafd92011-01-08 22:55:19 +080045
46
47API
48---
49
Shih-wei Liao7fff2282011-01-09 13:57:01 -080050**Basic:**
Logan36fafd92011-01-08 22:55:19 +080051
52* **bccCreateScript** - Create new bcc script
53
54* **bccRegisterSymbolCallback** - Register the callback function for external
55 symbol lookup
56
57* **bccReadBC** - Set the source bitcode for compilation
58
59* **bccReadModule** - Set the llvm::Module for compilation
60
61* **bccLinkBC** - Set the library bitcode for linking
62
Shih-wei Liao7fff2282011-01-09 13:57:01 -080063* **bccPrepareExecutable** - Create the in-memory executable by either
Logan36fafd92011-01-08 22:55:19 +080064 just-in-time compilation or cache loading
65
66* **bccDeleteScript** - Destroy bcc script and release the resources
67
68* **bccGetError** - Get the error code
69
Shih-wei Liao7fff2282011-01-09 13:57:01 -080070* **bccGetScriptInfoLog** - *deprecated* - Don't use this
Logan36fafd92011-01-08 22:55:19 +080071
72
Shih-wei Liao7fff2282011-01-09 13:57:01 -080073**Reflection:**
Logan36fafd92011-01-08 22:55:19 +080074
75* **bccGetExportVars** - Get the addresses of exported variables
76
77* **bccGetExportFuncs** - Get the addresses of exported functions
78
79* **bccGetPragmas** - Get the pragmas
80
81
Shih-wei Liao7fff2282011-01-09 13:57:01 -080082**Debug:**
Logan36fafd92011-01-08 22:55:19 +080083
84* **bccGetFunctions** - Get the function name list
85
Shih-wei Liao7fff2282011-01-09 13:57:01 -080086* **bccGetFunctionBinary** - Get the address and the size of a function binary
Logan36fafd92011-01-08 22:55:19 +080087
88
89
90Cache File Format
91-----------------
92
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080093A cache file (denoted as \*.oBCC) for libbcc consists of several sections:
Logan36fafd92011-01-08 22:55:19 +080094header, string pool, dependencies table, relocation table, exported
95variable list, exported function list, pragma list, function information
96table, and bcc context. Every section should be aligned to a word size.
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080097Here is the brief description of each sections:
Logan36fafd92011-01-08 22:55:19 +080098
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080099* **Header** (OBCC_Header) - The header of a cache file. It contains the
Shih-wei Liaocecdab22011-01-10 02:10:29 -0800100 magic word, version, machine integer type information (the endianness,
101 the size of off_t, size_t, and ptr_t), and the size
102 and offset of other sections. The header section is guaranteed
Logan36fafd92011-01-08 22:55:19 +0800103 to be at the beginning of the cache file.
104
Shih-wei Liao0d4984b2011-01-09 04:39:00 -0800105* **String Pool** (OBCC_StringPool) - A collection of serialized variable
Logan36fafd92011-01-08 22:55:19 +0800106 length strings. The strp_index in the other part of the cache file
107 represents the index of such string in this string pool.
108
109* **Dependencies Table** (OBCC_DependencyTable) - The dependencies table.
Shih-wei Liao8538dfa2011-01-09 15:42:28 -0800110 This table stores the resource name (or file path), the resource
Logan36fafd92011-01-08 22:55:19 +0800111 type (rather in APK or on the file system), and the SHA1 checksum.
112
Shih-wei Liao0d4984b2011-01-09 04:39:00 -0800113* **Relocation Table** (OBCC_RelocationTable) - *not enabled*
Logan36fafd92011-01-08 22:55:19 +0800114
115* **Exported Variable List** (OBCC_ExportVarList),
116 **Exported Function List** (OBCC_ExportFuncList) -
117 The list of the addresses of exported variables and exported functions.
118
119* **Pragma List** (OBCC_PragmaList) - The list of pragma key-value pair.
120
121* **Function Information Table** (OBCC_FuncTable) - This is a table of
122 function information, such as function name, function entry address,
123 and function binary size. Besides, the table should be ordered by
124 function name.
125
126* **Context** - The context of the in-memory executable, including
127 the code and the data. The offset of context should aligned to
128 a page size, so that we can mmap the context directly into the memory.
129
130For furthur information, you may read `bcc_cache.h <include/bcc/bcc_cache.h>`_,
131`CacheReader.cpp <lib/bcc/CacheReader.cpp>`_, and
132`CacheWriter.cpp <lib/bcc/CacheWriter.cpp>`_ for details.
133
134
135
136JIT'ed Code Calling Conventions
137-------------------------------
138
1391. Calls from Execution Environment or from/to within script:
140
141 On ARM, the first 4 arguments will go into r0, r1, r2, and r3, in that order.
142 The remaining (if any) will go through stack.
143
144 For ext_vec_types such as float2, a set of registers will be used. In the case
145 of float2, a register pair will be used. Specifically, if float2 is the first
146 argument in the function prototype, float2.x will go into r0, and float2.y,
147 r1.
148
149 Note: stack will be aligned to the coarsest-grained argument. In the case of
150 float2 above as an argument, parameter stack will be aligned to an 8-byte
151 boundary (if the sizes of other arguments are no greater than 8.)
152
1532. Calls from/to a separate compilation unit: (E.g., calls to Execution
154 Environment if those runtime library callees are not compiled using LLVM.)
155
156 On ARM, we use hardfp. Note that double will be placed in a register pair.