void emit_file(llvm::Module &module, Internal::LLVMOStream& out, llvm::TargetMachine::CodeGenFileType file_type) { Internal::debug(1) << "emit_file.Compiling to native code...\n"; Internal::debug(2) << "Target triple: " << module.getTargetTriple() << "\n"; // Get the target specific parser. auto target_machine = Internal::make_target_machine(module); internal_assert(target_machine.get()) << "Could not allocate target machine!\n"; #if LLVM_VERSION == 37 llvm::DataLayout target_data_layout(*(target_machine->getDataLayout())); #else llvm::DataLayout target_data_layout(target_machine->createDataLayout()); #endif if (!(target_data_layout == module.getDataLayout())) { internal_error << "Warning: module's data layout does not match target machine's\n" << target_data_layout.getStringRepresentation() << "\n" << module.getDataLayout().getStringRepresentation() << "\n"; } // Build up all of the passes that we want to do to the module. llvm::legacy::PassManager pass_manager; pass_manager.add(new llvm::TargetLibraryInfoWrapperPass(llvm::Triple(module.getTargetTriple()))); // Make sure things marked as always-inline get inlined #if LLVM_VERSION < 40 pass_manager.add(llvm::createAlwaysInlinerPass()); #else pass_manager.add(llvm::createAlwaysInlinerLegacyPass()); #endif // Enable symbol rewriting. This allows code outside libHalide to // use symbol rewriting when compiling Halide code (for example, by // using cl::ParseCommandLineOption and then passing the appropriate // rewrite options via -mllvm flags). pass_manager.add(llvm::createRewriteSymbolsPass()); // Override default to generate verbose assembly. target_machine->Options.MCOptions.AsmVerbose = true; // Ask the target to add backend passes as necessary. target_machine->addPassesToEmitFile(pass_manager, out, file_type); pass_manager.run(module); }
void emit_file(llvm::Module &module, Internal::LLVMOStream& out, llvm::TargetMachine::CodeGenFileType file_type) { #if LLVM_VERSION < 37 emit_file_legacy(module, out, file_type); #else Internal::debug(1) << "emit_file.Compiling to native code...\n"; Internal::debug(2) << "Target triple: " << module.getTargetTriple() << "\n"; // Get the target specific parser. auto target_machine = Internal::make_target_machine(module); internal_assert(target_machine.get()) << "Could not allocate target machine!\n"; #if LLVM_VERSION == 37 llvm::DataLayout target_data_layout(*(target_machine->getDataLayout())); #else llvm::DataLayout target_data_layout(target_machine->createDataLayout()); #endif if (!(target_data_layout == module.getDataLayout())) { internal_error << "Warning: module's data layout does not match target machine's\n" << target_data_layout.getStringRepresentation() << "\n" << module.getDataLayout().getStringRepresentation() << "\n"; } // Build up all of the passes that we want to do to the module. llvm::legacy::PassManager pass_manager; pass_manager.add(new llvm::TargetLibraryInfoWrapperPass(llvm::Triple(module.getTargetTriple()))); // Make sure things marked as always-inline get inlined pass_manager.add(llvm::createAlwaysInlinerPass()); // Override default to generate verbose assembly. target_machine->Options.MCOptions.AsmVerbose = true; // Ask the target to add backend passes as necessary. target_machine->addPassesToEmitFile(pass_manager, out, file_type); pass_manager.run(module); #endif }