This is an archive of the discontinued LLVM Phabricator instance.

[llvm-exegesis] Provide a way to handle memory instructions.
ClosedPublic

Authored by courbet on Jul 4 2018, 6:39 AM.

Diff Detail

Event Timeline

courbet created this revision.Jul 4 2018, 6:39 AM
RKSimon added inline comments.Jul 4 2018, 7:06 AM
unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
50

How should these numbers relate to the ScratchSpace values?

courbet updated this revision to Diff 154110.Jul 4 2018, 7:39 AM

Use ScratchSpace instead of alinged_storage.

courbet added inline comments.Jul 4 2018, 7:39 AM
unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
50

This was a leftover from a previous implementation. Fixed.

filcab added a subscriber: filcab.Jul 4 2018, 9:40 AM
filcab added inline comments.
tools/llvm-exegesis/lib/Assembler.h
42

s/void*/char*/

tools/llvm-exegesis/lib/BenchmarkRunner.h
85

unique_ptr here. AlignedPtr is ok, though.

94

Can you split the formatting changes to another diff?

tools/llvm-exegesis/lib/Target.cpp
33

Why is the assert being removed? It seemed to be asserting that we don't call this function twice. Are we now possibly calling it twice, or would it still be a programmer problem (as in: we should try to guarantee that the function is only called once).

courbet updated this revision to Diff 154208.Jul 5 2018, 5:32 AM
courbet marked 3 inline comments as done.

address review comments

Thanks for the comments !

tools/llvm-exegesis/lib/Target.cpp
33

Unit tests are actually calling it twice unfortunately. It allows having a single binary for all tests rathen than one binary per test and reduces link time quite importantly.

gchatelet added inline comments.Jul 11 2018, 2:34 AM
tools/llvm-exegesis/lib/Assembler.cpp
92

Remove parenthesis.

171

Remove parenthesis.

tools/llvm-exegesis/lib/BenchmarkRunner.cpp
141

Remove parenthesis.

tools/llvm-exegesis/lib/BenchmarkRunner.h
78

Why not aligned_alloc ?

tools/llvm-exegesis/lib/MCInstrDescView.h
130

"the pointer to" this memory is passed

tools/llvm-exegesis/lib/Target.h
59

I don't understand the comment :-/

How about this :

// Returns the maximum number of bytes a load/store instruction can access at once.
// This is typically the size of the largest register available on the processor.
virtual unsigned getLoadStoreMaxSize() const;

Also I think there's mismatch between the documentation and the implementation since you say return a value that is *larger* than ... but the implementation returns 64.

tools/llvm-exegesis/lib/Uops.cpp
182

This is not ideal because if (HasMemOperands) instantiateMemoryOperands(...) is repeated before each return.
How about a PrototypeBuilder struct that encapsulate the memory logic ?

206

?

tools/llvm-exegesis/lib/Uops.h
45

Not sure to understand what you mean by

// If there are less
// than kMinNumDifferentAddresses in the original snippet, we duplicate
// instructions until there are this number of instructions.
unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
75

Can you introduce a variable for readability?

unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
242

Do you need the (bool) cast?

courbet updated this revision to Diff 155352.Jul 13 2018, 5:03 AM
courbet marked 7 inline comments as done.

address review comments

Thanks, PTAL.

tools/llvm-exegesis/lib/BenchmarkRunner.h
78

the alignment of aligned_alloc has to be an alignment for a valid object. Some X86 instructions require 512 byte alignment, wich is not the alignment of any valid object.

tools/llvm-exegesis/lib/Uops.cpp
182

I originally had a lambda called MaybeInstanciateMemoryOperands, but TBH I think the repeated if makes it clearer.

unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
75

For the {} ? I've added a comment.

unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
242

Yes, because the macro tries to capture Error as an llvm::Error and barfs.

gchatelet added inline comments.Jul 16 2018, 1:17 AM
tools/llvm-exegesis/lib/Uops.cpp
182

I originally had a lambda called MaybeInstanciateMemoryOperands, but TBH I think the repeated if makes it clearer.

The if statement might be clearer than the Lambda but it is as error prone (you can omit the lambda and it compiles but it's broken).
My point was, if you use a Builder it is correct by design (and it removes visual clutter), true that it adds a struct to the file though.

tools/llvm-exegesis/lib/Uops.h
45

"assuming kMinNumDifferentAddresses=5 and getMaxMemoryAccessSize()=64"

courbet updated this revision to Diff 156261.Jul 19 2018, 6:52 AM
courbet marked an inline comment as done.

remove the HasMemOperands bool and ifs.

courbet added inline comments.Jul 19 2018, 6:53 AM
tools/llvm-exegesis/lib/Uops.cpp
182

Here's a proposal with no lambda and no builder, tell me what you think.

gchatelet accepted this revision.Jul 25 2018, 5:49 AM
gchatelet added inline comments.
tools/llvm-exegesis/lib/BenchmarkRunner.h
78

I don't understand why you can't use aligned_alloc(1024, 1<<20);?

This revision is now accepted and ready to land.Jul 25 2018, 5:49 AM

Thanks.

tools/llvm-exegesis/lib/BenchmarkRunner.h
78

aligned_alloc is c++17...

gchatelet added inline comments.Jul 30 2018, 12:01 AM
tools/llvm-exegesis/lib/BenchmarkRunner.h
78

I read C++11 on the link I provided.
https://en.cppreference.com/w/c/memory/aligned_alloc

lebedev.ri added inline comments.Jul 30 2018, 12:02 AM
tools/llvm-exegesis/lib/BenchmarkRunner.h
78

C11, not C++11.

gchatelet added inline comments.Jul 30 2018, 12:11 AM
tools/llvm-exegesis/lib/BenchmarkRunner.h
78

I misread then :) Thx for correcting me.

FYI I'll submit this patch for Clement.

This revision was automatically updated to reflect the committed changes.