| ... | @@ -213,33 +213,33 @@ static SanitizerCoverageOptions getSanCovOptions(ZigLLVMCoverageOptions z) { | ... | @@ -213,33 +213,33 @@ static SanitizerCoverageOptions getSanCovOptions(ZigLLVMCoverageOptions z) { |
| 213 | } | 213 | } |
| 214 | | 214 | |
| 215 | ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, | 215 | ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, |
| 216 | char **error_message, struct ZigLLVMEmitOptions options) | 216 | char **error_message, const struct ZigLLVMEmitOptions *options) |
| 217 | { | 217 | { |
| 218 | TimePassesIsEnabled = options.time_report; | 218 | TimePassesIsEnabled = options->time_report; |
| 219 | | 219 | |
| 220 | raw_fd_ostream *dest_asm_ptr = nullptr; | 220 | raw_fd_ostream *dest_asm_ptr = nullptr; |
| 221 | raw_fd_ostream *dest_bin_ptr = nullptr; | 221 | raw_fd_ostream *dest_bin_ptr = nullptr; |
| 222 | raw_fd_ostream *dest_bitcode_ptr = nullptr; | 222 | raw_fd_ostream *dest_bitcode_ptr = nullptr; |
| 223 | | 223 | |
| 224 | if (options.asm_filename) { | 224 | if (options->asm_filename) { |
| 225 | std::error_code EC; | 225 | std::error_code EC; |
| 226 | dest_asm_ptr = new(std::nothrow) raw_fd_ostream(options.asm_filename, EC, sys::fs::OF_None); | 226 | dest_asm_ptr = new(std::nothrow) raw_fd_ostream(options->asm_filename, EC, sys::fs::OF_None); |
| 227 | if (EC) { | 227 | if (EC) { |
| 228 | *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); | 228 | *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); |
| 229 | return true; | 229 | return true; |
| 230 | } | 230 | } |
| 231 | } | 231 | } |
| 232 | if (options.bin_filename) { | 232 | if (options->bin_filename) { |
| 233 | std::error_code EC; | 233 | std::error_code EC; |
| 234 | dest_bin_ptr = new(std::nothrow) raw_fd_ostream(options.bin_filename, EC, sys::fs::OF_None); | 234 | dest_bin_ptr = new(std::nothrow) raw_fd_ostream(options->bin_filename, EC, sys::fs::OF_None); |
| 235 | if (EC) { | 235 | if (EC) { |
| 236 | *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); | 236 | *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); |
| 237 | return true; | 237 | return true; |
| 238 | } | 238 | } |
| 239 | } | 239 | } |
| 240 | if (options.bitcode_filename) { | 240 | if (options->bitcode_filename) { |
| 241 | std::error_code EC; | 241 | std::error_code EC; |
| 242 | dest_bitcode_ptr = new(std::nothrow) raw_fd_ostream(options.bitcode_filename, EC, sys::fs::OF_None); | 242 | dest_bitcode_ptr = new(std::nothrow) raw_fd_ostream(options->bitcode_filename, EC, sys::fs::OF_None); |
| 243 | if (EC) { | 243 | if (EC) { |
| 244 | *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); | 244 | *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); |
| 245 | return true; | 245 | return true; |
| ... | @@ -255,7 +255,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi | ... | @@ -255,7 +255,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 255 | std::string ProcName = "zig-"; | 255 | std::string ProcName = "zig-"; |
| 256 | ProcName += std::to_string(PID); | 256 | ProcName += std::to_string(PID); |
| 257 | TimeTracerRAII TimeTracer(ProcName, | 257 | TimeTracerRAII TimeTracer(ProcName, |
| 258 | options.bin_filename? options.bin_filename : options.asm_filename); | 258 | options->bin_filename? options->bin_filename : options->asm_filename); |
| 259 | | 259 | |
| 260 | TargetMachine &target_machine = *reinterpret_cast<TargetMachine*>(targ_machine_ref); | 260 | TargetMachine &target_machine = *reinterpret_cast<TargetMachine*>(targ_machine_ref); |
| 261 | target_machine.setO0WantsFastISel(true); | 261 | target_machine.setO0WantsFastISel(true); |
| ... | @@ -264,11 +264,11 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi | ... | @@ -264,11 +264,11 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 264 | | 264 | |
| 265 | // Pipeline configurations | 265 | // Pipeline configurations |
| 266 | PipelineTuningOptions pipeline_opts; | 266 | PipelineTuningOptions pipeline_opts; |
| 267 | pipeline_opts.LoopUnrolling = !options.is_debug; | 267 | pipeline_opts.LoopUnrolling = !options->is_debug; |
| 268 | pipeline_opts.SLPVectorization = !options.is_debug; | 268 | pipeline_opts.SLPVectorization = !options->is_debug; |
| 269 | pipeline_opts.LoopVectorization = !options.is_debug; | 269 | pipeline_opts.LoopVectorization = !options->is_debug; |
| 270 | pipeline_opts.LoopInterleaving = !options.is_debug; | 270 | pipeline_opts.LoopInterleaving = !options->is_debug; |
| 271 | pipeline_opts.MergeFunctions = !options.is_debug; | 271 | pipeline_opts.MergeFunctions = !options->is_debug; |
| 272 | | 272 | |
| 273 | // Instrumentations | 273 | // Instrumentations |
| 274 | PassInstrumentationCallbacks instr_callbacks; | 274 | PassInstrumentationCallbacks instr_callbacks; |
| ... | @@ -306,7 +306,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi | ... | @@ -306,7 +306,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 306 | module_pm.addPass(VerifierPass()); | 306 | module_pm.addPass(VerifierPass()); |
| 307 | } | 307 | } |
| 308 | | 308 | |
| 309 | if (!options.is_debug) { | 309 | if (!options->is_debug) { |
| 310 | module_pm.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); | 310 | module_pm.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); |
| 311 | } | 311 | } |
| 312 | }); | 312 | }); |
| ... | @@ -316,12 +316,12 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi | ... | @@ -316,12 +316,12 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 316 | | 316 | |
| 317 | pass_builder.registerOptimizerLastEPCallback([&](ModulePassManager &module_pm, OptimizationLevel level) { | 317 | pass_builder.registerOptimizerLastEPCallback([&](ModulePassManager &module_pm, OptimizationLevel level) { |
| 318 | // Code coverage instrumentation. | 318 | // Code coverage instrumentation. |
| 319 | if (options.sancov) { | 319 | if (options->sancov) { |
| 320 | module_pm.addPass(SanitizerCoveragePass(getSanCovOptions(options.coverage))); | 320 | module_pm.addPass(SanitizerCoveragePass(getSanCovOptions(options->coverage))); |
| 321 | } | 321 | } |
| 322 | | 322 | |
| 323 | // Thread sanitizer | 323 | // Thread sanitizer |
| 324 | if (options.tsan) { | 324 | if (options->tsan) { |
| 325 | module_pm.addPass(ModuleThreadSanitizerPass()); | 325 | module_pm.addPass(ModuleThreadSanitizerPass()); |
| 326 | module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); | 326 | module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); |
| 327 | } | 327 | } |
| ... | @@ -335,17 +335,17 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi | ... | @@ -335,17 +335,17 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 335 | ModulePassManager module_pm; | 335 | ModulePassManager module_pm; |
| 336 | OptimizationLevel opt_level; | 336 | OptimizationLevel opt_level; |
| 337 | // Setting up the optimization level | 337 | // Setting up the optimization level |
| 338 | if (options.is_debug) | 338 | if (options->is_debug) |
| 339 | opt_level = OptimizationLevel::O0; | 339 | opt_level = OptimizationLevel::O0; |
| 340 | else if (options.is_small) | 340 | else if (options->is_small) |
| 341 | opt_level = OptimizationLevel::Oz; | 341 | opt_level = OptimizationLevel::Oz; |
| 342 | else | 342 | else |
| 343 | opt_level = OptimizationLevel::O3; | 343 | opt_level = OptimizationLevel::O3; |
| 344 | | 344 | |
| 345 | // Initialize the PassManager | 345 | // Initialize the PassManager |
| 346 | if (opt_level == OptimizationLevel::O0) { | 346 | if (opt_level == OptimizationLevel::O0) { |
| 347 | module_pm = pass_builder.buildO0DefaultPipeline(opt_level, options.lto); | 347 | module_pm = pass_builder.buildO0DefaultPipeline(opt_level, options->lto); |
| 348 | } else if (options.lto) { | 348 | } else if (options->lto) { |
| 349 | module_pm = pass_builder.buildLTOPreLinkDefaultPipeline(opt_level); | 349 | module_pm = pass_builder.buildLTOPreLinkDefaultPipeline(opt_level); |
| 350 | } else { | 350 | } else { |
| 351 | module_pm = pass_builder.buildPerModuleDefaultPipeline(opt_level); | 351 | module_pm = pass_builder.buildPerModuleDefaultPipeline(opt_level); |
| ... | @@ -356,7 +356,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi | ... | @@ -356,7 +356,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 356 | codegen_pm.add( | 356 | codegen_pm.add( |
| 357 | createTargetTransformInfoWrapperPass(target_machine.getTargetIRAnalysis())); | 357 | createTargetTransformInfoWrapperPass(target_machine.getTargetIRAnalysis())); |
| 358 | | 358 | |
| 359 | if (dest_bin && !options.lto) { | 359 | if (dest_bin && !options->lto) { |
| 360 | if (target_machine.addPassesToEmitFile(codegen_pm, *dest_bin, nullptr, CodeGenFileType::ObjectFile)) { | 360 | if (target_machine.addPassesToEmitFile(codegen_pm, *dest_bin, nullptr, CodeGenFileType::ObjectFile)) { |
| 361 | *error_message = strdup("TargetMachine can't emit an object file"); | 361 | *error_message = strdup("TargetMachine can't emit an object file"); |
| 362 | return true; | 362 | return true; |
| ... | @@ -375,20 +375,20 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi | ... | @@ -375,20 +375,20 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 375 | // Code generation phase | 375 | // Code generation phase |
| 376 | codegen_pm.run(llvm_module); | 376 | codegen_pm.run(llvm_module); |
| 377 | | 377 | |
| 378 | if (options.llvm_ir_filename) { | 378 | if (options->llvm_ir_filename) { |
| 379 | if (LLVMPrintModuleToFile(module_ref, options.llvm_ir_filename, error_message)) { | 379 | if (LLVMPrintModuleToFile(module_ref, options->llvm_ir_filename, error_message)) { |
| 380 | return true; | 380 | return true; |
| 381 | } | 381 | } |
| 382 | } | 382 | } |
| 383 | | 383 | |
| 384 | if (dest_bin && options.lto) { | 384 | if (dest_bin && options->lto) { |
| 385 | WriteBitcodeToFile(llvm_module, *dest_bin); | 385 | WriteBitcodeToFile(llvm_module, *dest_bin); |
| 386 | } | 386 | } |
| 387 | if (dest_bitcode) { | 387 | if (dest_bitcode) { |
| 388 | WriteBitcodeToFile(llvm_module, *dest_bitcode); | 388 | WriteBitcodeToFile(llvm_module, *dest_bitcode); |
| 389 | } | 389 | } |
| 390 | | 390 | |
| 391 | if (options.time_report) { | 391 | if (options->time_report) { |
| 392 | TimerGroup::printAll(errs()); | 392 | TimerGroup::printAll(errs()); |
| 393 | } | 393 | } |
| 394 | | 394 | |