This is an archive of the discontinued LLVM Phabricator instance.

[MC][CodeGen] Emit constant pools earlier
ClosedPublic

Authored by aeubanks on Aug 2 2021, 3:38 PM.

Details

Summary

Previously we would emit constant pool entries for ldr inline asm at the
very end of AsmPrinter::doFinalization(). However, if we're emitting
dwarf aranges, that would end all sections with aranges. Then if we have
constant pool entries to be emitted in those same sections, we'd hit an
assert that the section has already been ended.

We want to emit constant pool entries before emitting dwarf aranges.
This patch splits out arm32/64's constant pool entry emission into its
own MCTargetStreamer virtual method.

Fixes PR51208

Diff Detail

Event Timeline

aeubanks created this revision.Aug 2 2021, 3:38 PM
aeubanks requested review of this revision.Aug 2 2021, 3:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2021, 3:39 PM

suggestions welcome, I'm not familiar with the MC layer

LG. Calling MCStreamer::endSection early may look weird, but otherwise we need to call it elsewhere. Keeping MCStreamer::endSection in DwarfDebug.cpp as is looks fine for now.

llvm/test/MC/ARM/arange-ldr.ll
1 ↗(On Diff #363591)

How about test/DebugInfo/ARM/

Add a file-level comment about the purpose of the test

6 ↗(On Diff #363591)
CHECK:       ldr r7, .Ltmp[[#TMP:]]

CHECK:      .tmp[[#TMP]]:
CHECK-NEXT: .long  83040
8 ↗(On Diff #363591)

Have some basic checking for .debug_aranges

MaskRay added inline comments.Aug 2 2021, 11:00 PM
llvm/include/llvm/MC/MCStreamer.h
130

I may place this above, grouping with a few other emit*.

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
1818

Perhaps a comment that this needs to be before debug information.

probinson added inline comments.Aug 3 2021, 7:58 AM
llvm/test/MC/ARM/arange-ldr.ll
1 ↗(On Diff #363591)

I disagree about moving the test, test/DebugInfo is for tests of reading debug info, not producing it. This patch is about producing constants and debug info correctly.

aeubanks updated this revision to Diff 363795.Aug 3 2021, 10:11 AM

address comments

MaskRay added inline comments.Aug 3 2021, 1:10 PM
llvm/test/MC/ARM/arange-ldr.ll
1 ↗(On Diff #363591)

test/DebugInfo/ has many .ll and .mir tests (producer).

test/CodeGen/ has a lot as well.

test/MC/ is uncommon for .ll tests.

MaskRay accepted this revision.Aug 3 2021, 1:12 PM

LGTM, with a comment that the test does not belong to test/MC/ (which is mainly for .s tests)

This revision is now accepted and ready to land.Aug 3 2021, 1:12 PM
MaskRay added inline comments.
llvm/test/MC/ARM/arange-ldr.ll
4 ↗(On Diff #363795)

Add a period to the end of a complete sentence.

LGTM, with a comment that the test does not belong to test/MC/ (which is mainly for .s tests)

Hmmm okay. test/CodeGen seems like the most appropriate place for this one.

aeubanks updated this revision to Diff 363885.Aug 3 2021, 2:54 PM

move test
add periods

MaskRay added inline comments.Aug 3 2021, 8:31 PM
llvm/test/MC/ARM/arange-ldr.ll
1 ↗(On Diff #363591)

Even though the test location has settled for this patch, I'd like the test/DebugInfo story be clarified.

test/DebugInfo/ has plenty of .ll tests, so I don't think it is consumer only.

This revision was automatically updated to reflect the committed changes.

Even though the test location has settled for this patch, I'd like the test/DebugInfo story be clarified.
test/DebugInfo/ has plenty of .ll tests, so I don't think it is consumer only.

You can start an llvm-dev thread to debate that point.

I think for this particular patch, the fix is not so much about debug info, as about getting the compiler to emit object-file sections in a way that conforms to its own internal checks; in that sense it is really a CodeGen responsibility, even if one of the sections in question happens to be a debug-info section.