This is an archive of the discontinued LLVM Phabricator instance.

Fix DISubprogram while extracting instructions out of function
Needs ReviewPublic

Authored by hiraditya on Apr 21 2018, 7:23 AM.

Details

Summary

This case triggers when merge-similar-functions tries to extract instructions out of instantiations of a template function.

Diff Detail

Event Timeline

hiraditya created this revision.Apr 21 2018, 7:23 AM

Looks generally good, some nitpicks inside.

include/llvm/Transforms/Utils/Cloning.h
161

Can you add an

enum {
  ExtractingFunctions = true;
  CloningIntoSameModule = false;
};

or something along those lines for better readability?

test/Transforms/MergeSimilarFunc/merge-debug-info-2.ll
59

Is there a reason why this function needs to have more than just a single instruction?

69

please delete all the !tbaa metadata it's just distracting and will make the test harder to update in the future.

86

please delete all non-essential attributes (everything in quotes).

tobiasvk added inline comments.Apr 23 2018, 9:04 AM
lib/Transforms/Utils/CloneFunction.cpp
136

How about changing this to MustCloneSP = !ExtractingFunction && OldFunc->getParent() && OldFunc->getParent() == NewFunc->getParent(). Then you can leave the if block right after unchanged.

hiraditya marked 3 inline comments as done.Apr 23 2018, 3:24 PM
hiraditya added inline comments.
test/Transforms/MergeSimilarFunc/merge-debug-info-2.ll
59

Merge function seem to have some size metric to merge instructions. I think it may be possible to reduce a little bit but how much I'm not sure.

hiraditya updated this revision to Diff 143665.Apr 23 2018, 3:25 PM

Addressed comments

You can use attributes to force inlining or non-inlining to create a
particular scenario.

hiraditya updated this revision to Diff 143675.Apr 23 2018, 6:29 PM
aprantl added inline comments.Apr 24 2018, 7:53 AM
include/llvm/Transforms/Utils/Cloning.h
132

Can you please also add documentation to CloneFunctionInto that explains what the difference between those modes is?

132

/// Used to control \p CloneFunctionInto.

hiraditya updated this revision to Diff 144142.Apr 26 2018, 9:37 AM

Comments for enum

aprantl added inline comments.Apr 26 2018, 9:55 AM
include/llvm/Transforms/Utils/Cloning.h
132
/// Used to control \p CloneFunctionInto.
enum class CloneType {
    InvalidCloneType,
    /// Cloning will result in module level changes.
    ModuleLevelChanges,
    /// What does this mean exactly? Do we even need it?
    NoModuleLevelChanges,
    /// Cloning will be used for extracting functions
    /// by passes like function merging, it does not require module level changes
    /// but debug info needs special treatment like: DISubprogram is not cloned.
    ExtractingFunctions,
};
hiraditya added inline comments.Apr 26 2018, 10:14 AM
include/llvm/Transforms/Utils/Cloning.h
132

What does this mean exactly? Do we even need it?

This is used in cases when we dont want module level changes but it is not used for extracting functions. I did not want to modify the behavior at other places so introduced this for example: calls to CloneFunctionInto in Cloning.cpp. Perhaps we can merge ExtractingFunctions with NoModuleLevelChanges but I'm not very sure.

aprantl added inline comments.Apr 26 2018, 11:02 AM
include/llvm/Transforms/Utils/Cloning.h
137

Could you please comment that explains exactly what scenario this is supposed to be used for? The idea being that If we can't document the use-case precisely, we probably should not have this mode.