1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
Commit Graph

580 Commits

Author SHA1 Message Date
Manuel Jacob
e6438acb66 GlobalValue: use getValueType() instead of getType()->getPointerElementType().
Reviewers: mjacob

Subscribers: jholewinski, arsenm, dsanders, dblaikie

Patch by Eduard Burtescu.

Differential Revision: http://reviews.llvm.org/D16260

llvm-svn: 257999
2016-01-16 20:30:46 +00:00
Teresa Johnson
d8e00ee37a [IRMover] Don't copy personality, etc unless creating def
Function::copyAttributesFrom will copy the personality function, prefix
data and prolog data from the source function to the new function, and
is invoked when the IRMover copies the function prototype. This puts a
reference to a constant in the source module on a function in the dest
module, which causes an error when deleting the source module after
importing, since the personality function in the source module still has
uses (this would presumably also be an issue for the prologue and prefix
data). Remove the copies added to the dest copy when creating the new
prototype, as they are mapped properly when/if we link the function body.

llvm-svn: 257420
2016-01-12 00:24:24 +00:00
Teresa Johnson
675bf59b32 [ThinLTO] Use new in-place symbol changes for exporting module
Due to the new in-place ThinLTO symbol handling support added in
r257174, we now invoke renameModuleForThinLTO on the current
module from within the FunctionImport pass.

Additionally, renameModuleForThinLTO no longer needs to return the
Module as it is performing the renaming in place on the one provided.

This commit will be immediately preceeded by a companion clang patch to
remove its invocation of renameModuleForThinLTO.

llvm-svn: 257181
2016-01-08 17:06:29 +00:00
Teresa Johnson
5e0ce11a8d [ThinLTO] Enable in-place symbol changes for exporting module
Summary:
Move ThinLTO global value processing functions out of ModuleLinker and
into a new ThinLTOGlobalProcessor class, which performs any necessary
linkage and naming changes on the given module in place.

As a result, renameModuleForThinLTO no longer needs to create a new
Module when performing any necessary local to global promotion on a
module that we are possibly exporting from during a ThinLTO backend
compilation.

During function importing the ThinLTO processing is still invoked from
the ModuleLinker (via the new class), as it needs to perform renaming and
linkage changes on the source module, e.g. in order to get the correct
renaming during local to global promotion.

Reviewers: joker.eph

Subscribers: davidxl, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D15696

llvm-svn: 257174
2016-01-08 15:00:00 +00:00
Ahmed Bougacha
3c06bcb519 [Linker] Also treat a DIImportedEntity scope DISubprogram as needed.
Follow-up to r257000: DIImportedEntity can reach a DISubprogram via
its entity, but also via its scope. Handle the latter case as well.

PR26037.

llvm-svn: 257019
2016-01-07 03:14:59 +00:00
Teresa Johnson
018d695dd9 Always treat DISubprogram reached by DIImportedEntity as needed.
It is illegal to have a null entity in a DIImportedEntity, so
we must link in a DISubprogram metadata node referenced by one,
even if the associated function is not linked in or inlined anywhere.

Fixes PR26037.

llvm-svn: 257000
2016-01-07 00:06:27 +00:00
Teresa Johnson
5323e0a960 [ThinLTO] Rename variables used in metadata linking (NFC)
As suggested in review for r255909, rename MDMaterialized to AllowTemps,
and identify the name of the boolean flag being set in calls to
saveMetadataList.

llvm-svn: 256653
2015-12-30 21:13:55 +00:00
Teresa Johnson
a61068c0bc Ensure MDNode used as key in metadata linking map cannot be RAUWed
As suggested in review for r255909, add a way to ensure that temporary
MD used as keys in the MetadataToID map during ThinLTO importing are not
RAUWed.

Add support for marking an MDNode as not replaceable. Clear the new
CanReplace flag when adding a temporary MD node to the MetadataToID map
and clear it when destroying the map.

llvm-svn: 256648
2015-12-30 19:32:24 +00:00
Teresa Johnson
b23b3067db Rename MDValue* to Metadata* (NFC)
Renamed MDValue* to Metadata*, and MDValueToValIDMap to MetadataToIDs,
as per review for r255909.

llvm-svn: 256593
2015-12-29 23:00:22 +00:00
Teresa Johnson
4fc9fb1957 Handle empty Subprogram list when linking metadata.
Use an iterator that handles an empty subprogram list.

Fixes PR25915.

llvm-svn: 256224
2015-12-22 01:17:19 +00:00
Teresa Johnson
c59bb76cad [ThinLTO] Rename variable to reflect bulk importing change (NFC)
llvm-svn: 256171
2015-12-21 17:33:24 +00:00
Teresa Johnson
d8bcc1cb4d Remove unused functions from ModuleLinker (NFC)
Remove a couple ModuleLinker methods and a related static function that
are no longer used after the linker split.

llvm-svn: 256162
2015-12-21 15:49:59 +00:00
Rafael Espindola
4fe057fd6e Drop support for dematerializing.
It was only used on lib/Linker and the use was "dead" since it was used on a
function the IRMover had just moved.

llvm-svn: 256019
2015-12-18 19:57:26 +00:00
Teresa Johnson
d80a73c588 Rename variables to reflect linker split (NFC)
Renamed variables to be more reflective of whether they are
an instance of Linker, IRLinker or ModuleLinker. Also fix a stale
comment.

llvm-svn: 256011
2015-12-18 19:28:59 +00:00
Teresa Johnson
a03b8bd4f9 [ThinLTO/LTO] Don't link in unneeded metadata
Summary:
Third patch split out from http://reviews.llvm.org/D14752.

Only map in needed DISubroutine metadata (imported or otherwise linked
in functions and other DISubroutine referenced by inlined instructions).
This is supported for ThinLTO, LTO and llvm-link --only-needed, with
associated tests for each one.

Depends on D14838.

Reviewers: dexonsmith, joker.eph

Subscribers: davidxl, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D14843

llvm-svn: 256003
2015-12-18 17:51:37 +00:00
Teresa Johnson
0dce8d436c [ThinLTO] Metadata linking for imported functions
Summary:
Second patch split out from http://reviews.llvm.org/D14752.

Maps metadata as a post-pass from each module when importing complete,
suturing up final metadata to the temporary metadata left on the
imported instructions.

This entails saving the mapping from bitcode value id to temporary
metadata in the importing pass, and from bitcode value id to final
metadata during the metadata linking postpass.

Depends on D14825.

Reviewers: dexonsmith, joker.eph

Subscribers: davidxl, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D14838

llvm-svn: 255909
2015-12-17 17:14:09 +00:00
Teresa Johnson
d06d6a8e96 Mark a couple ModuleLinker member functions as const (NFC)
llvm-svn: 255903
2015-12-17 16:34:53 +00:00
Rafael Espindola
f7a0054c75 Change linkInModule to take a std::unique_ptr.
Passing in a std::unique_ptr should help find errors when the module
is used after being linked into another module.

llvm-svn: 255842
2015-12-16 23:16:33 +00:00
Rafael Espindola
5b397256de Use diagnostic handler in the LLVMContext
This patch converts code that has access to a LLVMContext to not take a
diagnostic handler.

This has a few advantages

* It is easier to use a consistent diagnostic handler in a single program.
* Less clutter since we are not passing a handler around.

It does make it a bit awkward to implement some C APIs that return a
diagnostic string. I will propose new versions of these APIs and
deprecate the current ones.

llvm-svn: 255571
2015-12-14 23:17:03 +00:00
Rafael Espindola
43562b355d Fix another case where the linkage was not set.
llvm-svn: 255272
2015-12-10 18:44:26 +00:00
Rafael Espindola
9a2fc3b415 Avoid undefined behavior when vector is empty.
Found by ubsan.

llvm-svn: 255258
2015-12-10 16:35:06 +00:00
Rafael Espindola
c944447e56 Slit lib/Linker in two.
A linker normally has two stages: symbol resolution and "moving stuff".

In lib/Linker there is the complication of lazy linking some globals,
but it was still far more mixed than it needed to.

This splits the linker into a lower level IRMover and the linker proper.
The IRMover just takes a list of globals to move and a callback that
lets the user control what is lazy linked.

The main motivation is that now tools/gold (and soon lld) can use their
own symbol resolution to instruct IRMover what to do.

llvm-svn: 255254
2015-12-10 14:19:35 +00:00
Rafael Espindola
88c4494d79 Synchronize the logic for deciding to link a gv.
We were deciding to not link an available_externally gv over a
declaration, but then copying over the body anyway.

llvm-svn: 255169
2015-12-09 22:44:00 +00:00
Rafael Espindola
02e9e50bfb Move all private members together. NFC.
llvm-svn: 255021
2015-12-08 14:54:49 +00:00
Rafael Espindola
735500f8f1 Factor two calls to a common location.
llvm-svn: 254967
2015-12-07 23:32:39 +00:00
Rafael Espindola
b67b3b7c85 Simplify the error handling a bit. NFC.
llvm-svn: 254952
2015-12-07 21:28:22 +00:00
Rafael Espindola
1d4a6cc6f5 Link declaration lazily.
We already linked available_externally and linkonce lazily, this just
adds declarations to the list.

llvm-svn: 254917
2015-12-07 16:31:41 +00:00
Rafael Espindola
f776a4d852 Change how the linker handles the old llvm.global_ctors.
Now instead of changing it to the new format and then linking, it just
handles the old format while copying it over.

The main differences are:

* There is no rauw in the source module.
* An old format input is always upgraded.

The first item helps with having a sane API that passes in a GV list to
the linker.

The second one is a small step in deprecating the old format.

llvm-svn: 254907
2015-12-07 13:24:23 +00:00
Teresa Johnson
f06c8232ba [ThinLTO] Helper for performing renaming/promotion on a module
Creates a module and performs necessary renaming/promotion of locals
that may be exported to another module.

Split out of D15024.

llvm-svn: 254802
2015-12-04 23:40:22 +00:00
Rafael Espindola
2c7e9b8d27 Always pass a diagnostic handler to the linker.
Before this patch the diagnostic handler was optional. If it was not
passed, the one in the LLVMContext was used.

That is probably not a pattern we want to follow. If each area has an
optional callback, there is a sea of callbacks and it is hard to follow
which one is called.

Doing this also found cases where the callback is a nice addition, like
testing that no errors or warnings are reported.

The other option is to always use the diagnostic handler in the
LLVMContext. That has a few problems

* To implement the C API we would have to set the diag handler and then
  set it back to the original value.
* Code that creates the context might be far away from code that wants
  the diagnostics.

I do have a patch that implements the second option and will send that as
an RFC.

llvm-svn: 254777
2015-12-04 22:08:53 +00:00
Teresa Johnson
a3f3dcad2f [ThinLTO] Appending linkage fixes
Summary:
Fix import from module with appending var, which cannot be imported. The
first fix is to remove an overly-aggressive error check.

The second fix is to deal with restructuring introduced to the module
linker yesterday in r254418 (actually, this fix was included already
in r254559, just added some additional cleanup).

Test by Mehdi Amini.

Reviewers: joker.eph, rafael

Subscribers: joker.eph, llvm-commits

Differential Revision: http://reviews.llvm.org/D15156

llvm-svn: 254624
2015-12-03 18:20:05 +00:00
Rafael Espindola
74516b6dba Simplify ValueMap handling.
We now just return values and let ValueMap handle the map.

llvm-svn: 254615
2015-12-03 16:36:16 +00:00
Rafael Espindola
ee432f5070 Don't pass member variables to member functions. NFC.
llvm-svn: 254610
2015-12-03 14:48:20 +00:00
Mehdi Amini
94623d2769 Adapt comment and rename variable in ModuleLinker to describe more accurately the actual use.
Thanks Sean Silva for the suggestion.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 254582
2015-12-03 02:37:30 +00:00
Mehdi Amini
07b85fee55 Remove "ExportingModule" from ThinLTO Index (NFC)
There is no real reason the index has to have the concept of an
exporting Module. We should be able to have one single unique
instance of the Index, and it should be read-only after creation
for the whole ThinLTO processing.
The linker plugin should be able to process multiple modules (in
parallel or in sequence) with the same index.

The only reason the ExportingModule was present seems to be to
implement hasExportedFunctions() that is used by the Module linker
to decide what to do with the current Module.
For now I replaced it with a query to the map of Modules path to
see if this module was declared in the Index and consider that if
it is the case then it is probably exporting function.
On the long term the Linker interface needs to evolve and this
call should not be needed anymore.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 254581
2015-12-03 02:37:23 +00:00
Rafael Espindola
f645fe92d8 Switch the linker to having a whitelist of GVs.
This replaces DoNotLinkFromSource with ValuesToLink. It also moves the
computation of ValuesToLink earlier.

It is a bit simpler and an important step in slitting the linker into an
ir mover and a linker proper.

The test change is because we now avoid creating dead declarations.

llvm-svn: 254559
2015-12-02 22:59:04 +00:00
Rafael Espindola
c0e7cab0ab Delete what is now duplicated code.
Having to import an alias as declaration is not thinlto specific.

The test difference are because when we already have a decl and we are
not importing it, we just leave the decl alone.

llvm-svn: 254556
2015-12-02 22:22:24 +00:00
Rafael Espindola
371e07845e Also copy private linkage globals when needed.
This was an omission when handling COFF style comdats with local keys.
Should fix the sanitizer-windows bot.

llvm-svn: 254543
2015-12-02 20:57:33 +00:00
Rafael Espindola
5354070607 Don't copy information from aliasee to alias.
They are independent.

llvm-svn: 254541
2015-12-02 20:03:17 +00:00
Rafael Espindola
e3433ec69d Fix linking when we copy over only a decl.
We were failing to copy the fact that the GV is weak and in the case of
an alias, producing invalid IR.

llvm-svn: 254538
2015-12-02 19:30:52 +00:00
Mehdi Amini
34766825ef Change ModuleLinker to take a set of GlobalValues to import instead of a single one
For efficiency reason, when importing multiple functions for the same Module,
we can avoid reparsing it every time.

Differential Revision: http://reviews.llvm.org/D15102

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 254486
2015-12-02 04:34:28 +00:00
Rafael Espindola
0bc33d1f7e Use default member initializers.
llvm-svn: 254473
2015-12-01 23:06:26 +00:00
Rafael Espindola
5ecdd9cb53 Remove unnecessary getter.
llvm-svn: 254466
2015-12-01 23:01:51 +00:00
Rafael Espindola
43979b3579 Pass down the dst GV to linkGlobalValueBody. NFC.
llvm-svn: 254465
2015-12-01 22:40:40 +00:00
Rafael Espindola
dfd9cfc115 Delete unused includes.
llvm-svn: 254457
2015-12-01 20:23:19 +00:00
Rafael Espindola
e644b56ccd clang-format LinkModules.cpp.
Most of the file has been changed recently and was already clang-format
clean.

llvm-svn: 254454
2015-12-01 20:11:43 +00:00
Rafael Espindola
e3fda2ca99 Use references now that it is natural to do so.
The linker never takes ownership of a module or changes which module it
is refering to, making it natural to use references.

llvm-svn: 254449
2015-12-01 19:50:54 +00:00
Rafael Espindola
8c37192246 Delete dead code.
llvm-svn: 254436
2015-12-01 18:50:35 +00:00
Rafael Espindola
876cd0cb5e Use a forwarding constructor instead of an init method.
llvm-svn: 254435
2015-12-01 18:46:19 +00:00
Rafael Espindola
49b4ffd0b8 Delete the setModule method from the Linker.
It was only used from LTO for a debug feature, and LTO can just create
another linker.

It is pretty odd to have a method to reset the module in the middle of a
link. It would make IdentifiedStructTypes inconsistent with the Module
for example.

llvm-svn: 254434
2015-12-01 18:41:30 +00:00