This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add function_entry_count to LLVMFuncOp
ClosedPublic

Authored by Dinistro on Jan 4 2023, 9:17 AM.

Details

Summary

This commit introduces the function_entry_count metadata field to the
LLVMFuncOp and adds both the corresponding import and export
funtionalities.
The import of the function metadata uses the same infrastructure as the
instruction metadata, i.e., it dispatches through a dialect interface.

Diff Detail

Event Timeline

Dinistro created this revision.Jan 4 2023, 9:17 AM
Herald added a project: Restricted Project. · View Herald Transcript
Dinistro requested review of this revision.Jan 4 2023, 9:17 AM
gysit added inline comments.Jan 4 2023, 11:33 PM
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
1996

nit: functionEntryCounts -> functionEntryCount

2010

I think there is a getFunctionEntryCountAttrName name? Also should't this be singular without an s?

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

nit: the comment needs an update.

92

Should we use the attribute name here and below?

93–94

nit: "TODO support function entry count metadata with a global identifier field." That way it is clear there is no specific reason why this is not imported.

mlir/lib/Target/LLVMIR/ModuleImport.cpp
1191–1200

Any chance this could be factored out in a helper method assuming instructions and functions are both values?

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
893

nit: auto -> Int64Attr?

Dinistro updated this revision to Diff 486494.Jan 5 2023, 1:20 AM

address review comments

Dinistro marked 3 inline comments as done and 2 inline comments as done.Jan 5 2023, 1:24 AM
Dinistro added inline comments.
mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
92

I do not quite follow. This function does not belong to a specific operation, so one has no access to the attribute name accessors

93–94

I'm not sure if these GUIDs would be preserved when exporting back to LLVM. But I can add it as a TODO and we can later on check if this is indeed the case or not.

mlir/lib/Target/LLVMIR/ModuleImport.cpp
1191–1200

I tired, but unfortunately Value::getAllMetadata is protected and cannot be accessed. Furthermore, llvm::Value has no location, so such a function would take up to 4 arguments.

Dinistro updated this revision to Diff 486520.Jan 5 2023, 3:54 AM

drop unnecessary comment

gysit accepted this revision.Jan 5 2023, 4:01 AM

LGTM

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

Never mind I thought the getFunctionEntryCountAttrName is a static function.

mlir/lib/Target/LLVMIR/ModuleImport.cpp
1191–1200

ok let's keep it then.

This revision is now accepted and ready to land.Jan 5 2023, 4:01 AM
Dinistro marked 5 inline comments as done.Jan 5 2023, 4:20 AM
This revision was automatically updated to reflect the committed changes.