• Home
  • Raw
  • Download

Lines Matching +full:helper +full:- +full:plugin +full:- +full:utils

1 //===-- gold-plugin.cpp - Plugin to gold for Link Time Optimization  ------===//
8 //===----------------------------------------------------------------------===//
10 // This is a gold plugin for LLVM. It provides an LLVM implementation of the
13 //===----------------------------------------------------------------------===//
22 #include "llvm/Config/config.h" // plugin-api.h requires HAVE_STDINT_H
48 #include "llvm/Transforms/Utils/FunctionImportUtils.h"
49 #include "llvm/Transforms/Utils/GlobalStatus.h"
50 #include "llvm/Transforms/Utils/ValueMapper.h"
52 #include <plugin-api.h>
138 /// single-threaded (i.e. call backs to gold).
181 // When the thinlto plugin option is specified, only read the function
186 // using multiple threads in the gold-plugin, before handing control back to
204 // Note: This array will contain all plugin options which are not claimed
205 // as plugin exclusive to pass to the code generator.
206 // For example, "generate-api-file" and "as"options are for the plugin
216 if (opt == "generate-api-file") { in process_plugin_option()
220 } else if (opt.startswith("extra-library-path=")) { in process_plugin_option()
224 } else if (opt.startswith("obj-path=")) { in process_plugin_option()
225 obj_path = opt.substr(strlen("obj-path=")); in process_plugin_option()
226 } else if (opt == "emit-llvm") { in process_plugin_option()
228 } else if (opt == "save-temps") { in process_plugin_option()
230 } else if (opt == "disable-output") { in process_plugin_option()
234 } else if (opt == "thinlto-index-only") { in process_plugin_option()
236 } else if (opt == "thinlto-emit-imports-files") { in process_plugin_option()
238 } else if (opt.startswith("thinlto-prefix-replace=")) { in process_plugin_option()
239 thinlto_prefix_replace = opt.substr(strlen("thinlto-prefix-replace=")); in process_plugin_option()
241 message(LDPL_FATAL, "thinlto-prefix-replace expects 'old;new' format"); in process_plugin_option()
245 OptLevel = opt[1] - '0'; in process_plugin_option()
249 } else if (opt == "disable-verify") { in process_plugin_option()
285 for (; tv->tv_tag != LDPT_NULL; ++tv) { in onload()
287 // example, LDPT_GET_SYMBOLS_V3 when building against an older plugin-api.h in onload()
289 switch (static_cast<int>(tv->tv_tag)) { in onload()
291 output_name = tv->tv_u.tv_string; in onload()
294 switch (tv->tv_u.tv_val) { in onload()
304 message(LDPL_ERROR, "Unknown output file type %d", tv->tv_u.tv_val); in onload()
309 options::process_plugin_option(tv->tv_u.tv_string); in onload()
313 callback = tv->tv_u.tv_register_claim_file; in onload()
322 callback = tv->tv_u.tv_register_all_symbols_read; in onload()
331 callback = tv->tv_u.tv_register_cleanup; in onload()
337 get_input_file = tv->tv_u.tv_get_input_file; in onload()
340 release_input_file = tv->tv_u.tv_release_input_file; in onload()
343 add_symbols = tv->tv_u.tv_add_symbols; in onload()
348 get_symbols = tv->tv_u.tv_get_symbols; in onload()
351 get_symbols = tv->tv_u.tv_get_symbols; in onload()
354 add_input_file = tv->tv_u.tv_add_input_file; in onload()
357 set_extra_library_path = tv->tv_u.tv_set_extra_library_path; in onload()
360 get_view = tv->tv_u.tv_get_view; in onload()
363 message = tv->tv_u.tv_message; in onload()
396 return GA->getBaseObject(); in getBaseObject()
410 std::error_code EC = BDI->getError(); in diagnosticHandler()
424 message(LDPL_FATAL, "LLVM gold plugin has failed to create LTO module: %s", in diagnosticHandler()
434 message(Level, "LLVM gold plugin: %s", ErrStorage.c_str()); in diagnosticHandler()
454 /// Called by gold to see whether this file is one that our plugin can handle.
464 if (get_view(file->handle, &view) != LDPS_OK) { in claim_file_hook()
465 message(LDPL_ERROR, "Failed to get a view of %s", file->name); in claim_file_hook()
469 MemoryBufferRef(StringRef((const char *)view, file->filesize), ""); in claim_file_hook()
472 // Gold has found what might be IR part-way inside of a file, such as in claim_file_hook()
474 if (file->offset) { in claim_file_hook()
475 offset = file->offset; in claim_file_hook()
478 MemoryBuffer::getOpenFileSlice(file->fd, file->name, file->filesize, in claim_file_hook()
485 BufferRef = Buffer->getMemBufferRef(); in claim_file_hook()
499 message(LDPL_ERROR, "LLVM gold plugin has failed to create LTO module: %s", in claim_file_hook()
508 cf.handle = file->handle; in claim_file_hook()
514 FDToLeaderHandle.insert(std::make_pair(file->fd, file->handle)).first; in claim_file_hook()
515 cf.leader_handle = LeaderHandle->second; in claim_file_hook()
518 cf.filesize = file->filesize; in claim_file_hook()
520 // non-zero offset, which we can append to the file name to obtain a in claim_file_hook()
522 cf.name = file->name; in claim_file_hook()
523 if (file->offset) in claim_file_hook()
524 cf.name += ".llvm." + std::to_string(file->offset) + "." + in claim_file_hook()
525 sys::path::filename(Obj->getModule().getSourceFileName()).str(); in claim_file_hook()
527 for (auto &Sym : Obj->symbols()) { in claim_file_hook()
543 const GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl()); in claim_file_hook()
550 GlobalValue::getMinUnnamedAddr(Res.UnnamedAddr, GV->getUnnamedAddr()); in claim_file_hook()
551 Res.IsLinkonceOdr &= GV->hasLinkOnceLinkage(); in claim_file_hook()
552 Res.Visibility = getMinVisibility(Res.Visibility, GV->getVisibility()); in claim_file_hook()
553 switch (GV->getVisibility()) { in claim_file_hook()
567 if (GV && GV->hasExternalWeakLinkage()) in claim_file_hook()
572 assert(!GV->hasExternalWeakLinkage() && in claim_file_hook()
573 !GV->hasAvailableExternallyLinkage() && "Not a declaration!"); in claim_file_hook()
574 if (GV->hasCommonLinkage()) in claim_file_hook()
576 else if (GV->isWeakForLinker()) in claim_file_hook()
587 const Comdat *C = Base->getComdat(); in claim_file_hook()
589 sym.comdat_key = strdup(C->getName().str().c_str()); in claim_file_hook()
645 /// Helper to get a file's symbols and a view into it via gold callbacks.
715 if (GV && GV->hasAppendingLinkage()) in getModuleForFile()
738 GV->setUnnamedAddr(Res.UnnamedAddr); in getModuleForFile()
739 GV->setVisibility(Res.Visibility); in getModuleForFile()
743 if (GV->hasCommonLinkage()) { in getModuleForFile()
751 const DataLayout &DL = GV->getParent()->getDataLayout(); in getModuleForFile()
752 uint64_t Size = DL.getTypeAllocSize(GV->getType()->getElementType()); in getModuleForFile()
753 unsigned Align = GV->getAlignment(); in getModuleForFile()
761 cast<GlobalVariable>(GV)->setAlignment( in getModuleForFile()
788 if (!GV->isDeclarationForLinker()) in getModuleForFile()
789 assert(GV->hasComdat()); in getModuleForFile()
797 Internalize.insert(GV->getName()); in getModuleForFile()
804 switch (GV->getLinkage()) { in getModuleForFile()
808 GV->setLinkage(GlobalValue::WeakAnyLinkage); in getModuleForFile()
811 GV->setLinkage(GlobalValue::WeakODRLinkage); in getModuleForFile()
819 Internalize.insert(GV->getName()); in getModuleForFile()
849 OS->close(); in cleanup()
873 /// Filename to use as base when save-temps is enabled, used to get
874 /// a unique and identifiable save-temps output file for each ThinLTO backend.
890 : M(std::move(M)), OS(nullptr), TaskID(-1), CombinedIndex(nullptr), in CodeGen()
929 /// Sets up output files necessary to perform optional multi-threaded
960 TripleStr = M->getTargetTriple(); in initTargetMachine()
982 return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine( in createTargetMachine()
988 M->setDataLayout(TM->createDataLayout()); in runLTOPasses()
991 // Apply summary-based LinkOnce/Weak resolution decisions. in runLTOPasses()
994 // Apply summary-based internalization decisions. Skip if there are no in runLTOPasses()
999 if (!DefinedGlobals->empty()) in runLTOPasses()
1004 ModuleLoader Loader(M->getContext(), *ModuleMap); in runLTOPasses()
1012 passes.add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis())); in runLTOPasses()
1015 PMB.LibraryInfo = new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())); in runLTOPasses()
1036 SmallString<128> &NewFilename, int TaskID = -1) { in openOutputFile()
1040 sys::fs::createTemporaryFile("lto-llvm", "o", FD, NewFilename); in openOutputFile()
1059 if (TM->addPassesToEmitFile(CodeGenPasses, *OS, in runCodegenPasses()
1090 MaxThreads > 1 ? I : -1); in runSplitCodeGen()
1122 assert(!SaveTempsFilename.empty() || TaskID == -1); in runAll()
1151 M->setTargetTriple(options::triple.c_str()); in linkInModule()
1152 else if (M->getTargetTriple().empty()) { in linkInModule()
1153 M->setTargetTriple(DefaultTriple); in linkInModule()
1160 L.getModule().setSourceFileName(M->getSourceFileName()); in linkInModule()
1174 cast<GlobalVariable>(Dst)->setAlignment(I.second); in linkInModule()
1248 // non-unique obj_path. in thinLTOBackends()
1249 !options::obj_path.empty() ? TaskCount : -1); in thinLTOBackends()
1304 /// Also, either launch backend threads or (under thinlto-index-only)
1344 // or by a non-IR module). Cross references introduced by importing are in thinLTOLink()
1357 PrevailingCopy[SymGUID] = Index->getGlobalValueSummary(SymGUID); in thinLTOLink()
1365 // Collect for each module the list of function it defines (GUID -> in thinLTOLink()
1379 return Prevailing->second == S; in thinLTOLink()
1388 ExportList->second.count(GUID)) || in thinLTOLink()
1397 // Use global summary-based analysis to identify symbols that can be in thinLTOLink()
1404 "thinlto-emit-imports-files ignored unless thinlto-index-only"); in thinLTOLink()
1407 // If the thinlto-prefix-replace option was specified, parse it and in thinLTOLink()
1480 std::unique_ptr<Module> Combined(new Module("ld-temp.o", Context)); in allSymbolsReadHook()
1495 GlobalValue *GV = Combined->getNamedValue(Name.first()); in allSymbolsReadHook()