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); }
bool ContractManager::runOnModule(llvm::Module& M) { const llvm::DataLayout* DL = M.getDataLayout(); FN = FactoryNest(DL, nullptr); VariableInfoTracker* VI = &GetAnalysis<VariableInfoTracker>::doit(this); FN.Type->initialize(*VI); if (not contracts) { contracts = ContractContainer::Ptr{new ContractContainer()}; } return false; }
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 }
Runtime::Runtime(llvm::LLVMContext& context, llvm::Module& target, llvm::IRBuilder<>& builder) : target_(target) , builder_(builder) , layout_(target.getDataLayout()) { llvm::SMDiagnostic diag; auto mem_buf = llvm::MemoryBuffer::getMemBuffer(runtime_definitions); runtime_ = llvm::parseIR(*mem_buf.get(), diag, context); if (runtime_ == nullptr) throw std::logic_error("runtime could not be loaded"); }
bool TargetInfo::doInitialization(llvm::Module &m) { dl = &m.getDataLayout(); return ImmutablePass::doInitialization(m); }
void SmackModuleGenerator::generateProgram(llvm::Module& M) { Naming naming; SmackRep rep(M.getDataLayout(), naming, program, getAnalysis<Regions>()); std::list<Decl*>& decls = program.getDeclarations(); DEBUG(errs() << "Analyzing globals...\n"); for (auto& G : M.globals()) { auto ds = rep.globalDecl(&G); decls.insert(decls.end(), ds.begin(), ds.end()); } DEBUG(errs() << "Analyzing functions...\n"); for (auto& F : M) { // Reset the counters for per-function names naming.reset(); DEBUG(errs() << "Analyzing function: " << naming.get(F) << "\n"); auto ds = rep.globalDecl(&F); decls.insert(decls.end(), ds.begin(), ds.end()); auto procs = rep.procedure(&F); assert(procs.size() > 0); if (naming.get(F) != Naming::DECLARATIONS_PROC) decls.insert(decls.end(), procs.begin(), procs.end()); if (F.isDeclaration()) continue; if (!F.empty() && !F.getEntryBlock().empty()) { DEBUG(errs() << "Analyzing function body: " << naming.get(F) << "\n"); for (auto P : procs) { SmackInstGenerator igen(getAnalysis<LoopInfo>(F), rep, *P, naming); DEBUG(errs() << "Generating body for " << naming.get(F) << "\n"); igen.visit(F); DEBUG(errs() << "\n"); // First execute static initializers, in the main procedure. if (F.hasName() && SmackOptions::isEntryPoint(F.getName())) { P->insert(Stmt::call(Naming::INITIALIZE_PROC)); } else if (naming.get(F).find(Naming::INIT_FUNC_PREFIX) == 0) rep.addInitFunc(&F); } DEBUG(errs() << "Finished analyzing function: " << naming.get(F) << "\n\n"); } // MODIFIES // ... to do below, after memory splitting is determined. } auto ds = rep.auxiliaryDeclarations(); decls.insert(decls.end(), ds.begin(), ds.end()); decls.insert(decls.end(), rep.getInitFuncs()); // NOTE we must do this after instruction generation, since we would not // otherwise know how many regions to declare. program.appendPrelude(rep.getPrelude()); std::list<Decl*> kill_list; for (auto D : program) { if (auto P = dyn_cast<ProcDecl>(D)) { if (D->getName().find(Naming::CONTRACT_EXPR) != std::string::npos) { decls.insert(decls.end(), Decl::code(P)); kill_list.push_back(P); } } } for (auto D : kill_list) decls.erase(std::remove(decls.begin(), decls.end(), D), decls.end()); }