summaryrefslogtreecommitdiffstats
path: root/llvm/tools/gold/gold-plugin.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix handling of extern_weak. This was broken by r225983.Rafael Espindola2015-01-141-2/+4
| | | | llvm-svn: 226026
* Handle a symbol being undefined.Rafael Espindola2015-01-141-1/+5
| | | | | | | | | | | | | This can happen if: * It is present in a comdat in one file. * It is not present in the comdat of the file that is kept. * Is is not used. This should fix the LTO boostrap. Thanks to Takumi NAKAMURA for setting up the bot! llvm-svn: 225983
* Use the DiagnosticHandler to print diagnostics when reading bitcode.Rafael Espindola2015-01-101-2/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bitcode reading interface used std::error_code to report an error to the callers and it is the callers job to print diagnostics. This is not ideal for error handling or diagnostic reporting: * For error handling, all that the callers care about is 3 possibilities: * It worked * The bitcode file is corrupted/invalid. * The file is not bitcode at all. * For diagnostic, it is user friendly to include far more information about the invalid case so the user can find out what is wrong with the bitcode file. This comes up, for example, when a developer introduces a bug while extending the format. The compromise we had was to have a lot of error codes. With this patch we use the DiagnosticHandler to communicate with the human and std::error_code to communicate with the caller. This allows us to have far fewer error codes and adds the infrastructure to print better diagnostics. This is so because the diagnostics are printed when he issue is found. The code that detected the problem in alive in the stack and can pass down as much context as needed. As an example the patch updates test/Bitcode/invalid.ll. Using a DiagnosticHandler also moves the fatal/non-fatal error decision to the caller. A simple one like llvm-dis can just use fatal errors. The gold plugin needs a bit more complex treatment because of being passed non-bitcode files. An hypothetical interactive tool would make all bitcode errors non-fatal. llvm-svn: 225562
* Fix a leak found by asan.Rafael Espindola2014-12-231-5/+12
| | | | llvm-svn: 224776
* Simplify the handling of aliases in the gold plugin.Rafael Espindola2014-12-101-49/+33
| | | | | | | | | | | | | | | The complicated situation is when we have to keep an alias but drop a GV that is part of the aliasee. We used to clone the dropped GV and make the clone internal. This is wasteful as we know the original will be dropped. With this patch what is done instead is set the linkage of the original to internal and replace all uses (but the one in the alias) with a new declaration that takes the name of the old GV. This saves us from having to copy the body. llvm-svn: 223863
* Rename createIRObjectFile to just create.Rafael Espindola2014-12-091-2/+2
| | | | | | | It is a static method of IRObjectFile, so having to use IRObjectFile::createIRObjectFile was redundant. llvm-svn: 223822
* Remember the unmangled name in the plugin.Rafael Espindola2014-12-091-3/+3
| | | | | | | | | This allows it to work with non trivial manglings like the one in COFF. Amusingly, this can be tested with gold, as emit-llvm causes the plugin to exit before any COFF is generated. llvm-svn: 223790
* Don't lookup an object symbol name in the module.Rafael Espindola2014-12-091-21/+27
| | | | | | | | | | | Instead, walk the obj symbol list in parallel to find the GV. This shouldn't change anything on ELF where global symbols are not mangled, but it is a step toward supporting other object formats. Gold itself is ELF only, but bfd ld supports COFF and the logic in the gold plugin could be reused on lld. llvm-svn: 223780
* gold plugin: call llvm_shutdown so that -stats works.Rafael Espindola2014-11-251-0/+3
| | | | llvm-svn: 222787
* Add a disable-output option to the gold plugin.Rafael Espindola2014-11-241-9/+20
| | | | | | This corresponds to the opt option and is handy for profiling. llvm-svn: 222687
* gold-plugin: Fix typo in error messageDuncan P. N. Exon Smith2014-11-191-1/+1
| | | | | | Spotted while reading code. llvm-svn: 222395
* Fix the build of the gold plugin.Rafael Espindola2014-11-011-1/+0
| | | | | | I did the previous patch on OS X and didn't noticed the issue. llvm-svn: 221070
* Remove redundant calls to isMaterializable.Rafael Espindola2014-11-011-4/+2
| | | | | | | | | | This removes calls to isMaterializable in the following cases: * It was redundant with a call to isDeclaration now that isDeclaration returns the correct answer for materializable functions. * It was followed by a call to Materialize. Just call Materialize and check EC. llvm-svn: 221050
* Enable the slp vectorizer in the gold plugin.Rafael Espindola2014-10-301-0/+1
| | | | llvm-svn: 220887
* Enable the loop vectorizer in the gold plugin.Rafael Espindola2014-10-301-0/+1
| | | | llvm-svn: 220886
* Replace also-emit-llvm with save-temps.Rafael Espindola2014-10-291-23/+15
| | | | | | | | The also-emit-llvm option only supported getting the IR before optimizations. This patch replaces it with a more generic save-temps option that saves the IR both before and after optimizations. llvm-svn: 220885
* Remove unused variable.Rafael Espindola2014-10-251-1/+1
| | | | llvm-svn: 220610
* Update the error handling of lib/Linker.Rafael Espindola2014-10-251-3/+2
| | | | | | Instead of passing a std::string&, use the new diagnostic infrastructure. llvm-svn: 220608
* Modernize the error handling of the Materialize function.Rafael Espindola2014-10-241-2/+5
| | | | llvm-svn: 220600
* Don't ever call materializeAllPermanently during LTO.Rafael Espindola2014-10-241-18/+5
| | | | | | | | | | To do this, change the representation of lazy loaded functions. The previous representation cannot differentiate between a function whose body has been removed and one whose body hasn't been read from the .bc file. That means that in order to drop a function, the entire body had to be read. llvm-svn: 220580
* Fix a gcc warning.Rafael Espindola2014-10-221-1/+1
| | | | | | Thanks to Filipe Cabecinhas for the report. llvm-svn: 220361
* Fix gcc warning in gold-plugin.cpp.Rafael Espindola2014-10-101-0/+1
| | | | | | Patch by Markus Trippelsdorf! llvm-svn: 219459
* gold plugin: Handle gold selecting a linkonce GV when a weak is present.Rafael Espindola2014-10-071-1/+7
| | | | | | | | | The plugin API doesn't have the notion of linkonce, only weak. It is up to the plugin to figure out if a symbol used only for the symbol table can be dropped. In particular, it has to avoid dropping a linkonce_odr selected by gold if there is also a weak_odr. llvm-svn: 219188
* gold plugin: create internal replacement with original linkage first.Rafael Espindola2014-10-071-3/+4
| | | | | | | | | The call to copyAttributesFrom will copy the visibility, which might assert if it were to produce something invalid like "internal hidden". We avoid it by first creating the replacement with the original linkage and then setting it to internal affter the call to copyAttributesFrom. llvm-svn: 219184
* gold plugin: Remap function arguments when creating a replacement function.Rafael Espindola2014-10-071-0/+14
| | | | | | | | When creating an internal function replacement for use in an alias we were not remapping the argument uses in the instructions to point to the new arguments. llvm-svn: 219177
* LTO: introduce object file-based on-disk module format.Peter Collingbourne2014-09-181-3/+12
| | | | | | | | | | | | | | | | | | This format is simply a regular object file with the bitcode stored in a section named ".llvmbc", plus any number of other (non-allocated) sections. One immediate use case for this is to accommodate compilation processes which expect the object file to contain metadata in non-allocated sections, such as the ".go_export" section used by some Go compilers [1], although I imagine that in the future we could consider compiling parts of the module (such as large non-inlinable functions) directly into the object file to improve LTO efficiency. [1] http://golang.org/doc/install/gccgo#Imports Differential Revision: http://reviews.llvm.org/D4371 llvm-svn: 218078
* Internalize common symbols when we can.Rafael Espindola2014-09-171-1/+3
| | | | | | This fixes pr20974. llvm-svn: 217981
* Add doInitialization/doFinalization to DataLayoutPass.Rafael Espindola2014-09-101-1/+1
| | | | | | | | | | | | | With this a DataLayoutPass can be reused for multiple modules. Once we have doInitialization/doFinalization, it doesn't seem necessary to pass a Module to the constructor. Overall this change seems in line with the idea of making DataLayout a required part of Module. With it the only way of having a DataLayout used is to add it to the Module. llvm-svn: 217548
* Remember to eraseFromParent after replaceAllUsesWith.Rafael Espindola2014-09-101-0/+1
| | | | llvm-svn: 217536
* Handle common linkage correctly in the gold plugin.Rafael Espindola2014-09-091-0/+8
| | | | | | | | | | This is the plugin version of pr20882. This handles the case of every common symbol being in the IR. We will need some support from gold to handle the case where some symbols are in ELF and some in the IR. llvm-svn: 217458
* unique_ptrify IRObjectFile::createIRObjectFileDavid Blaikie2014-09-031-2/+2
| | | | | | | | I took a guess at the changes to the gold plugin, because that doesn't seem to build by default for me. Not sure what dependencies I might be missing for that. llvm-svn: 217056
* Pass a && to getLazyBitcodeModule.Rafael Espindola2014-09-031-1/+1
| | | | | | | | This forces callers to use std::move when calling it. It is somewhat odd to have code with std::move that doesn't always move, but it is also odd to have code without std::move that sometimes moves. llvm-svn: 217049
* Don't create a MemoryBuffer just to get the MemoryBufferRef. NFC.Rafael Espindola2014-08-271-6/+6
| | | | llvm-svn: 216608
* Convert a few more cases of direct intialization of unique_ptrs from ↵David Blaikie2014-08-271-2/+2
| | | | | | | | MemoryBuffer::getMemBuffer to move initialization now that it returns by unique_ptr instead of raw pointer. Cleanup/improvements following r216583. llvm-svn: 216605
* Return a std::unique_ptr when creating a new MemoryBuffer.Rafael Espindola2014-08-271-2/+2
| | | | llvm-svn: 216583
* Pass a std::unique_ptr<MemoryBuffer>& to getLazyBitcodeModule.Rafael Espindola2014-08-261-2/+1
| | | | | | | By taking a reference we can do the ownership transfer in one place instead of expecting every caller to do it. llvm-svn: 216492
* Modernize raw_fd_ostream's constructor a bit.Rafael Espindola2014-08-251-7/+7
| | | | | | | | | | Take a StringRef instead of a "const char *". Take a "std::error_code &" instead of a "std::string &" for error. A create static method would be even better, but this patch is already a bit too big. llvm-svn: 216393
* Add support for comdats to the gold plugin.Rafael Espindola2014-08-221-12/+97
| | | | | | | | | | | | | | | | | | | | | | | There are two parts to this. First, the plugin needs to tell gold the comdat by setting comdat_key. What gets things a bit more complicated is that gold only seems symbols. In particular, if A is an alias to B, it only sees the symbols A and B. It can then ask us to keep symbol A but drop symbol B. What we have to do instead is to create an internal version of B and make A an alias to that. At some point some of this logic should be moved to lib/Linker so that we don't map a Constant to an internal version just to have lib/Linker map that again to the destination module. The reason for implementing this in tools/gold for now is simplicity. With it in place it should be possible to update clang to use comdats for constructors and destructors on ELF without breaking the LTO bootstrap. Once that is done I intend to come back and improve the interface lib/Linker exposes. llvm-svn: 216302
* Rewrite the gold plugin to fix pr19901.Rafael Espindola2014-08-211-145/+392
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a fundamental difference between how the gold API and lib/LTO view the LTO process. The gold API talks about a particular symbol in a particular file. The lib/LTO API talks about a symbol in the merged module. The merged module is then defined in terms of the IR semantics. In particular, a linkonce_odr GV is only copied if it is used, since it is valid to drop unused linkonce_odr GVs. In the testcase in pr19901 both properties collide. What happens is that gold asks us to keep a particular linkonce_odr symbol, but the IR linker doesn't copy it to the merged module and we never have a chance to ask lib/LTO to keep it. This patch fixes it by having a more direct implementation of the gold API. If it asks us to keep a symbol, we change the linkage so it is not linkonce. If it says we can drop a symbol, we do so. All of this before we even send the module to lib/Linker. Since now we don't have to produce LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN, during symbol resolution we can use a temporary LLVMContext and do lazy module loading. This allows us to keep the minimum possible amount of allocated memory around. This should also allow as much parallelism as we want, since there is no shared context. llvm-svn: 216215
* Fix using -plugin-opt=apiflie when also using -plugin-opt=emit-llvm.Rafael Espindola2014-08-111-18/+25
| | | | llvm-svn: 215378
* Remove unused argument.Rafael Espindola2014-07-311-2/+2
| | | | | | Thanks to Justin Bogner for noticing it. llvm-svn: 214426
* Use range loops.Rafael Espindola2014-07-301-21/+17
| | | | llvm-svn: 214280
* Convert a few more function pointer calls to just "f()".Rafael Espindola2014-07-301-3/+3
| | | | llvm-svn: 214276
* Don't duplicate the function name in a comment.Rafael Espindola2014-07-301-4/+3
| | | | llvm-svn: 214272
* Use function pointers with just f(1,2) instead of (*f)(1,2).Rafael Espindola2014-07-301-27/+26
| | | | llvm-svn: 214265
* Use nullptr instead of NULL.Rafael Espindola2014-07-291-8/+8
| | | | llvm-svn: 214229
* Remove unused includes.Rafael Espindola2014-07-291-8/+0
| | | | llvm-svn: 214226
* Delete dead code.Rafael Espindola2014-07-291-7/+0
| | | | | | The gold plugin doesn't call lseek or read directly any more. llvm-svn: 214221
* gold plugin: Fix handling of corrupted bitcode files.Rafael Espindola2014-07-291-2/+3
| | | | | | We should still claim them and tell gold about the error. llvm-svn: 214214
* Small gold plugin simplifications.Rafael Espindola2014-07-291-6/+4
| | | | | | | * Use a range loop. * Store the extra options as "const char *". llvm-svn: 214199
OpenPOWER on IntegriCloud