This is an archive of the discontinued LLVM Phabricator instance.

[MemoryBuffer] Allow optionally specifying desired buffer alignment
ClosedPublic

Authored by rriddle on Nov 11 2022, 1:56 AM.

Details

Summary

Underlying data may have requirements/expectations/etc. about
the run-time alignment. WritableMemoryBuffer currently uses
a 16 byte alignment, which works for many situations but not all.
Allowing a desired alignment makes it easier to reuse WritableMemoryBuffer
in situations of special alignment, and also removes a problem when
opening files with special alignment constraints. Large files generally
get mmaped, which has ~page alignment, but small files go through
WritableMemoryBuffer which has the much smaller alignment guarantee.

Depends on D137764

Diff Detail

Event Timeline

rriddle created this revision.Nov 11 2022, 1:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 1:56 AM
rriddle requested review of this revision.Nov 11 2022, 1:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 1:56 AM
rriddle added a comment.EditedNov 11 2022, 1:59 AM

@dblaikie Would love thoughts if you think this is the right approach. I hit some interesting situations downstream where a small file with large alignment constraints(in the realm of 64/128/etc bytes) was seemingly miscompiling, but then I learned that MemoryBuffer only mmaps large files. This patch explicitly encodes alignment constraints, which felt safer than just changing the current alignment value hardcoded in WritableMemoryBuffer. The situation I hit was basically the same as the existing TODO in WritableMemoryBuffer::getNewUninitMemBuffer.

dblaikie accepted this revision.Nov 11 2022, 3:51 PM

If you've got a use for it, this seems fine to me.

llvm/unittests/Support/MemoryBufferTest.cpp
232–233

Prefer = over () when both are valid - makes it easier to read because it limits the code to only implicit ctors (so, as a reader, I don't worry that the function is returning a raw pointer & this is taking ownership - and want to go check that the raw pointer is really conferring ownership, etc)

This revision is now accepted and ready to land.Nov 11 2022, 3:51 PM
lattner accepted this revision.Nov 11 2022, 5:06 PM
lattner added a subscriber: lattner.

This LGTM and makes sense. Nice use of the alignment apis.

This revision was automatically updated to reflect the committed changes.
rriddle marked an inline comment as done.