This is an archive of the discontinued LLVM Phabricator instance.

[Cloning] Copy metadata of global declarations
ClosedPublic

Authored by ruiling on Dec 17 2020, 4:34 AM.

Details

Summary

We have modules with metadata on declarations, and out-of-tree passes
use that metadata, and we need to clone those modules. We really expect
such metadata is kept during the clone operation.

Diff Detail

Event Timeline

ruiling created this revision.Dec 17 2020, 4:34 AM
ruiling requested review of this revision.Dec 17 2020, 4:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 17 2020, 4:34 AM
arsenm requested changes to this revision.Dec 18 2020, 7:04 AM

Needs tests

This revision now requires changes to proceed.Dec 18 2020, 7:04 AM
aprantl added inline comments.Dec 18 2020, 9:11 AM
llvm/unittests/Transforms/Utils/CloningTest.cpp
843 ↗(On Diff #312448)

Nit: LLVM coding style wants full sentences in comments.
i.e.: // Test global variable declarations.

846 ↗(On Diff #312448)

It's not obvious to me what the intended difference between GVD and GV is — is it just the Comdat flag? Could we document that?

ruiling added inline comments.Dec 18 2020, 12:58 PM
llvm/unittests/Transforms/Utils/CloningTest.cpp
843 ↗(On Diff #312448)

Thanks, will fix it.

846 ↗(On Diff #312448)

the GVD is just a global variable declaration, which means have no initializer. will document it to make is obvious.

Needs tests

Do we need more test besides the unit-test?

ruiling updated this revision to Diff 312881.Dec 18 2020, 1:12 PM

refactor some comments

ping, any further comments? @arsenm @aprantl

arsenm added a comment.Jan 5 2021, 7:39 PM

Is a lit test possible?

Now that most features of CloneModule() are tested by the unit-test. Is there any specific reason to prefer lit-test over unit-test?

Now that most features of CloneModule() are tested by the unit-test. Is there any specific reason to prefer lit-test over unit-test?

It's easier to read and update IR tests than unit tests

ruiling updated this revision to Diff 314988.Jan 6 2021, 2:25 PM

change to lit-test. @arsenm please check whether you like this.

arsenm accepted this revision.Jan 7 2021, 7:40 AM
This revision is now accepted and ready to land.Jan 7 2021, 7:40 AM
This revision was landed with ongoing or failed builds.Jan 7 2021, 4:26 PM
This revision was automatically updated to reflect the committed changes.

seems that copying the metadata causing the Cloned module still reference some metadata in source modules. and simplifyExternals(*MergedM); in ThinLTOBitcodeWriter.cpp modifies the metadata in the source module M. which is out-of my expectation. I am not familiar with that part of code, so still need some time to continue investigate. I am not sure @pcc Do you have any idea on this?
Actually it is changing a metadata in module M from:
!32 = !DITemplateValueParameter(type: !33, value: { i64, i64 } { i64 ptrtoint (i32 (%class.i*)* @_ZNK1i5m_fn1Ev to i64), i64 0 })
into
!32 = !DITemplateValueParameter(type: !33, value: { i64, i64 } { i64 ptrtoint (void ()* @_ZNK1i5m_fn1Ev to i64), i64 0 })
I dumped the modules before and after my change, this is the only diff of Module M before writing out.