This is an archive of the discontinued LLVM Phabricator instance.

[mlir][llvm] Add support for loop metadata import
ClosedPublic

Authored by Dinistro on Feb 6 2023, 3:08 AM.

Details

Summary

This commit introduces functionality to import loop metadata. Loop
metadata nodes are transformed into LoopAnnotationAttrs and attached to
the corresponding branch operations.

Diff Detail

Event Timeline

Dinistro created this revision.Feb 6 2023, 3:08 AM
Herald added a project: Restricted Project. · View Herald Transcript
Dinistro requested review of this revision.Feb 6 2023, 3:08 AM
Dinistro updated this revision to Diff 495141.Feb 6 2023, 7:55 AM

Fix windows build with explicit cast to llvm::MDNode

gysit added inline comments.Feb 7 2023, 1:25 AM
mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
153

Shouldn't there be a check if for a failure?

156

maybe iterator based initialization works here (not 100% sure):
SmallVector<Attribute> accessGroupAttrs(accessGroups.begin(), accessGroups.end());

162

nit: Let's also mention that the attribute is attached to the op?
E.g.:

Converts the given loop metadata node to an MLIR loop annotation attribute and attaches it to the imported operation if the translation succeeds. Returns failure otherwise.

mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp
18

ultra nit: that keeps the state

90

Could it happen that the same name appears twice?

144

I would probably rename to something that starts with a verb, e.g. emitValueWarning or just emitWarning.

237

nit: emptyParam -> isEmptyOrNull?

260

nit: let's spell out the types here.

349

I think the * operator is preferred and the types here and on the line below should probably be spelled out.

353

I would use llvm::append_range here since we are appending possibly multiple time.

Additionally the * operator is preferred over .value()

376

ultra nit: no need to change but wouldn't annotationMap be the better fit here?

395

ultra nit: in these cases loopMetadataMapping.find may be the preferred choice since only one search is needed.

mlir/lib/Target/LLVMIR/LoopAnnotationImporter.h
15

nit:
MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONIMPOIRT_H_ ->
MLIR_LIB_TARGET_LLVMIR_LOOPANNOTATIONIMPORTER_H_

mlir/lib/Target/LLVMIR/ModuleImport.cpp
1578

nit: either an access group or even a single access group

mlir/test/Target/LLVMIR/Import/metadata-loop.ll
33

nit: you could use CHECK-LABEL but then all variables matched before need to be prefixed with a dollar:

#[[$ANNOT_ATTR:.*] =
Dinistro updated this revision to Diff 495500.Feb 7 2023, 6:10 AM
Dinistro marked 14 inline comments as done.

address reviewer comments

mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
156

That works :)

mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp
90

Good catch, added a check and a corresponding test.

144

Changed to emitNodeWarning as emitWarning leads to a name clash.

376

Depends on the definition of "annotation" in this context. The whole attribute is called LoopAnnotationAttr, so calling each field of it an annotation might be a term overload.

gysit accepted this revision.Feb 7 2023, 6:59 AM

LGTM modulo the underscore comment.

mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp
90

nit I believe this produces a warning. Usually the way to go is to put a variable name and then to (void)dummy on the next line.

This revision is now accepted and ready to land.Feb 7 2023, 6:59 AM
Dinistro updated this revision to Diff 495542.Feb 7 2023, 7:50 AM
Dinistro marked an inline comment as done.

fix the unused variable warning

Dinistro updated this revision to Diff 495769.Feb 8 2023, 2:22 AM

fix test after rebase

This revision was automatically updated to reflect the committed changes.