llvm.org GIT mirror llvm / e3427a5
Add new API lto_codegen_compile_parallel(). This API is proposed by Nick Kledzik. The semantic is: -------------------------------------------------------------------------- Generate code for merged module into an array of native object files. On success returns a pointer to an array of NativeObjectFile. The count parameter returns the number of elements in the array. Each element is a pointer/length for a generated mach-o/ELF buffer. The buffer is owned by the lto_code_gen_t and will be freed when lto_codegen_dispose() is called, or lto_codegen_compile() is called again. On failure, returns NULL (check lto_get_error_message() for details). extern const struct NativeObjectFile* lto_codegen_compile_parallel(lto_code_gen_t cg, size_t *count); --------------------------------------------------------------------------- This API is currently only called on OSX platform. Linux or other Unixes using GNU gold are not supposed to call this function, because on these systems, object files are fed back to linker via disk file instead of memory buffer. In this commit, lto_codegen_compile_parallel() simply calls lto_codegen_compile() to return a single object file. In the near future, this function is the entry point for compilation with partition. Linker can blindly call this function even if partition is turned off; in this case, compiler will return only one object file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189297 91177308-0d34-0410-b5e6-96231b3b80d8 Shuxin Yang 7 years ago
5 changed file(s) with 54 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2626 * @{
2727 */
2828
29 #define LTO_API_VERSION 4
29 #define LTO_API_VERSION 5
3030
3131 typedef enum {
3232 LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
283283 extern bool
284284 lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
285285
286 struct NativeObjectFile {
287 const void *content;
288 size_t length;
289 };
290
291 /**
292 * Generates code for merged module into an array of native object files.
293 * On success returns a pointer to an array of NativeObjectFile. The
294 * count parameter returns the number of elements in the array. Each
295 * element is a pointer/length for a generated mach-o/ELF buffer. The
296 * buffer is owned by the lto_code_gen_t and will be freed when
297 * lto_codegen_dispose() is called, or lto_codegen_compile() is called again.
298 * On failure, returns NULL (check lto_get_error_message() for details).
299 */
300 extern const struct NativeObjectFile*
301 lto_codegen_compile_parallel(lto_code_gen_t cg, size_t *count);
286302
287303 /**
288304 * Sets options to help debug codegen bugs.
7373 _linker(new Module("ld-temp.o", _context)), _target(NULL),
7474 _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
7575 _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
76 _nativeObjectFile(NULL) {
76 _nativeObjectFile(NULL), ObjBufVect(0) {
7777 InitializeAllTargets();
7878 InitializeAllTargetMCs();
7979 InitializeAllAsmPrinters();
8484 delete _target;
8585 delete _nativeObjectFile;
8686 delete _linker.getModule();
87 delete[] ObjBufVect;
8788
8889 for (std::vector::iterator I = _codegenOptions.begin(),
8990 E = _codegenOptions.end(); I != E; ++I)
245246 return _nativeObjectFile->getBufferStart();
246247 }
247248
249 // Currently compile() and compile_parallel() have no difference.
250 NativeObjectFile *LTOCodeGenerator::compile_parallel(size_t *count,
251 std::string &ErrMsg) {
252 assert(ObjBufVect == 0 && "Should be NULL");
253
254 size_t Len;
255 const void *Buf = compile(&Len, ErrMsg);
256 if (!Buf)
257 return 0;
258
259 *count = 1;
260 ObjBufVect = new NativeObjectFile[1];
261 ObjBufVect[0].content = Buf;
262 ObjBufVect[0].length = Len;
263 return ObjBufVect;
264 }
265
248266 bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
249267 if (_target != NULL)
250268 return true;
101101 //
102102 const void *compile(size_t *length, std::string &errMsg);
103103
104 // Corresponding to lto_codegen_compile_parallel() API.
105 // Generates code for merged module into an array of native object files.
106 // On success returns a pointer to an array of NativeObjectFile. The count
107 // parameter returns the number of elements in the array. Each element is
108 // a pointer/length for a generated mach-o/ELF buffer. The buffer is owned
109 // by the lto_code_gen_t and will be freed when lto_codegen_dispose() is
110 // called, or lto_codegen_compile() is called again. On failure, returns
111 // NULL (check lto_get_error_message() for details).
112 //
113 NativeObjectFile *compile_parallel(size_t *count, std::string &ErrMsg);
114
104115 private:
105116 void initializeLTOPasses();
106117
126137 std::vector _codegenOptions;
127138 std::string _mCpu;
128139 std::string _nativeObjectPath;
140 NativeObjectFile *ObjBufVect;
129141 };
130142
131143 #endif // LTO_CODE_GENERATOR_H
206206 return !cg->compile_to_file(name, sLastErrorString);
207207 }
208208
209 extern const struct NativeObjectFile *
210 lto_codegen_compile_parallel(lto_code_gen_t cg, size_t *count) {
211 return cg->compile_parallel(count, sLastErrorString);
212 }
213
209214 /// lto_codegen_debug_options - Used to pass extra options to the code
210215 /// generator.
211216 void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {
2727 lto_codegen_set_assembler_path
2828 lto_codegen_set_cpu
2929 lto_codegen_compile_to_file
30 lto_codegen_compile_parallel
3031 LLVMCreateDisasm
3132 LLVMCreateDisasmCPU
3233 LLVMDisasmDispose