This is an archive of the discontinued LLVM Phabricator instance.

Cloning: Reduce complexity of debug info cloning and fix correctness issue.
ClosedPublic

Authored by pcc on Mar 29 2016, 4:09 PM.

Details

Summary

Commit r260791 contained an error in that it would introduce a cross-module
reference in the old module. It also introduced O(N^2) complexity in the
module cloner by requiring the entire module to be visited for each function.
Fix both of these problems by avoiding use of the CloneDebugInfoMetadata
function (which is only designed to do intra-module cloning) and cloning
function-attached metadata in the same way that we clone all other metadata.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 52001.Mar 29 2016, 4:09 PM
pcc retitled this revision from to Cloning: Reduce complexity of debug info cloning and fix correctness issue..
pcc updated this object.
pcc added reviewers: dexonsmith, aprantl.
pcc added subscribers: llvm-commits, loladiro, tejohnson and 2 others.
dexonsmith edited edge metadata.Mar 29 2016, 4:51 PM
dexonsmith added a subscriber: dexonsmith.

If you add a test this LGTM. I suggest adding something to
unittests/Transforms/Utils/.

pcc added a comment.Mar 29 2016, 4:53 PM

This is already covered by the test CloneModule, Subprogram that was added by r260791. But I suppose I could add another test for another attribute since that is new functionality.

That test passes without this patch...

Can you test specifically for the bug you're fixing?

pcc added a comment.Mar 29 2016, 5:08 PM

Most likely, let me see if I can reproduce the issue that Teresa found (I was mostly looking at the complexity issue).

LGTM, but would be good for Adrian or Duncan to take a look.

lib/Transforms/Utils/CloneFunction.cpp
194 ↗(On Diff #52001)

Maybe add a comment about this applying only to cloning within a single module?

pcc added a comment.Mar 29 2016, 5:31 PM

Sorry, looks like I'll have to go back to the drawing board with this one, it causes test failures in check-clang.

pcc updated this revision to Diff 52124.Mar 30 2016, 2:23 PM
pcc edited edge metadata.
  • Pass ModuleLevelChanges through to MapMetadata, and add test

The problems were related to the calls to CloneFunction in lib/CodeGen/CGVTables.cpp` and in lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp. In both cases we were wrongly cloning distinct debug info, which confused later codegen/verifier passes. This update fixes the inconsistency. Please take another look.

@tstellarAMD it's a little surprising that the only test coverage for the always inline pass in the case where there's debug info is in Clang (specifically in test/CodeGen/backend-unsupported-error.ll, which seems to test something else). Might be something worth adding coverage for in LLVM?

pcc added inline comments.Mar 30 2016, 2:35 PM
lib/Transforms/Utils/CloneFunction.cpp
198–199 ↗(On Diff #52124)

I have a followup patch which will completely remove this function.

This revision was automatically updated to reflect the committed changes.