This is an archive of the discontinued LLVM Phabricator instance.

Adding a DIBuilder interface for Fortran's assumed length string
ClosedPublic

Authored by ykhatav on Jan 26 2022, 12:06 PM.

Details

Summary

Currently DIBuilder supports constant length strings only. In this review I have added a new interface called createStringType() which is capable of generating the debug info metadata for an assumed length string.

Diff Detail

Event Timeline

ykhatav created this revision.Jan 26 2022, 12:06 PM
ykhatav requested review of this revision.Jan 26 2022, 12:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2022, 12:06 PM

I just added a new field StringLocationExp to DIStringType in this commit: https://reviews.llvm.org/rG28bfa57a7315c3161124c90b4d52f467616dc92e . Please add an optional argument to these createStringType functions so that the caller can specify this new field if it desires.

llvm/include/llvm/IR/DIBuilder.h
228

stringLength can be typed as DIVariable *.

Side note: LLVM coding convention calls for capital first letter of a variable name; so stringLength -> StringLength.

ykhatav updated this revision to Diff 403734.Jan 27 2022, 11:23 AM

Added StringLocationExp to the new apis

cchen15 added inline comments.Jan 28 2022, 7:42 AM
llvm/include/llvm/IR/DIBuilder.h
222–240

Use DIVariable * for StringLength.

223

Use DIExpression * for StrLocationExp.

223

Ditto.

llvm/unittests/IR/DebugInfoTest.cpp
249–289

Using nullptr for the length argument seems too generic. Could you mock up a DIVairbale/DIExpression for length and a DIExpression for location for both new functions?

ykhatav updated this revision to Diff 404556.Jan 31 2022, 8:50 AM
ykhatav updated this revision to Diff 404925.Feb 1 2022, 7:10 AM

Updated the test to include the proper string functions

cchen15 added inline comments.Feb 1 2022, 7:22 AM
llvm/include/llvm/IR/DIBuilder.h
223–241

Now the types of the two new functions and the original are all different, you can overload the name createStringType here.

ykhatav updated this revision to Diff 405068.Feb 1 2022, 12:47 PM

Worked on review comments

cchen15 added inline comments.Feb 1 2022, 1:33 PM
llvm/include/llvm/IR/DIBuilder.h
223–241

One last suggestion: We can combine the two new functions into one by typing the length argument PointerUnion<DIVariable*, DIExpression*>. Please see DIBuilder::createArrayType for a precedent.

bwyma added inline comments.Feb 2 2022, 6:04 AM
llvm/include/llvm/IR/DIBuilder.h
223–241

In the createArrayType() instance, the expression and variable arguments are interchangeable metadata to the same composite type parameter. In DIStringType, at least currently, the variable string length and string length expression are independent parameters. To reflect this in the DIBuilder interface I would prefer to have independent createStringType() calls.

cchen15 added inline comments.Feb 2 2022, 6:47 AM
llvm/include/llvm/IR/DIBuilder.h
223–241

DIStringType should have only one field to represent the string length. I think this boils down to if the DIBuilder interface needs to reflect the current state of the underlying implementation. My take is that we can go ahead with what the user should see with this patch, and then change the implementation at a later time if necessary to avoid an additional API change down the road.

bwyma added inline comments.Feb 2 2022, 8:45 AM
llvm/include/llvm/IR/DIBuilder.h
223–241

Even if this change was made, there will still be a second interface routine for creating constant string length types. I don't see value in upcasting the arguments and performing isa comparisons on them just to downcast them into separate arguments again. The string type does not yet have the complexity of the array type interface. The proposed implementation here is cleaner and functionally equivalent.

cchen15 added inline comments.Feb 2 2022, 8:56 AM
llvm/include/llvm/IR/DIBuilder.h
223–241

I don't fully agree but I will commit.

Please wait for the final approval from @aprantl.

ykhatav updated this revision to Diff 405398.Feb 2 2022, 12:51 PM

Updated my local branch with the latest changes

ykhatav updated this revision to Diff 405604.Feb 3 2022, 5:49 AM

Can you add documentation for how these String types are supposed to be used to SourceLevelDebugging.rst?
What's an example for a memory location expression that flang would produce?

ykhatav updated this revision to Diff 406449.Feb 7 2022, 7:06 AM

Modified SourceLevelDebugging.rst to include information about memory location exp.

aprantl accepted this revision.Feb 7 2022, 8:18 AM
aprantl added inline comments.
llvm/docs/SourceLevelDebugging.rst
1092

Thanks. It was unclear to me what to expect in the expression. If it's using DW_OP_push_object_address that makes sense.

This revision is now accepted and ready to land.Feb 7 2022, 8:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 7:56 AM