void emit_file(llvm::Module *module, const std::string &filename, llvm::TargetMachine::CodeGenFileType file_type) { #if LLVM_VERSION < 37 emit_file_legacy(module, filename, 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. llvm::TargetMachine *target_machine = get_target_machine(module); internal_assert(target_machine) << "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())) { // This *might* be indicative on a bug elsewhere, but might // also be fine. It depends on what the differences are // precisely. Notify when in debug mode. Internal::debug(1) << "Warning: module's data layout does not match target machine's\n" << target_data_layout.getStringRepresentation() << "\n" << module->getDataLayout().getStringRepresentation() << "\n"; module->setDataLayout(target_data_layout); } std::unique_ptr<llvm::raw_fd_ostream> out(new_raw_fd_ostream(filename)); // 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); delete target_machine; #endif }
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 }