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