-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLIR][LLVM] Add bytecode support for several attributes #162577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bcardosolopes
wants to merge
4
commits into
llvm:main
Choose a base branch
from
bcardosolopes:mlir-llvm-bytecode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+639
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bce0803
[MLIR][LLVM] Add bytecode support for several attributes
bcardosolopes eff046f
Update order of elements to match upstream
bcardosolopes dd8aa3d
Address review feedback
bcardosolopes 753f296
Address more comments and use -verify-roundtrip
bcardosolopes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
364 changes: 364 additions & 0 deletions
364
mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,364 @@ | ||
//===-- LLVMDialectBytecode.td - LLVM bytecode defs --------*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is the LLVM bytecode reader/writer definition file. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_DIALECT_BYTECODE | ||
#define LLVM_DIALECT_BYTECODE | ||
|
||
include "mlir/IR/BytecodeBase.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Bytecode classes for attributes and types. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def String : | ||
WithParser <"succeeded($_reader.readString($_var))", | ||
WithBuilder<"$_args", | ||
WithPrinter<"$_writer.writeOwnedString($_getter)", | ||
WithType <"StringRef">>>>; | ||
|
||
class Attr<string type> : WithType<type, Attribute>; | ||
|
||
class OptionalAttribute<string type> : | ||
WithParser <"succeeded($_reader.readOptionalAttribute($_var))", | ||
WithPrinter<"$_writer.writeOptionalAttribute($_getter)", | ||
WithType<type, Attribute>>>; | ||
|
||
class OptionalInt<string type> : | ||
WithParser <"succeeded(readOptionalInt($_reader, $_var))", | ||
WithPrinter<"writeOptionalInt($_writer, $_getter)", | ||
WithType<"std::optional<" # type # ">", VarInt>>>; | ||
|
||
class OptionalArrayRef<string eltType> : | ||
WithParser <"succeeded(readOptionalArrayRef<" | ||
# eltType # ">($_reader, $_var))", | ||
WithPrinter<"writeOptionalArrayRef<" | ||
# eltType # ">($_writer, $_getter)", | ||
WithType<"SmallVector<" | ||
# eltType # ">", Attribute>>>; | ||
|
||
class EnumClassFlag<string flag, string getter> : | ||
WithParser<"succeeded($_reader.readVarInt($_var))", | ||
WithBuilder<"(" # flag # ")$_args", | ||
WithPrinter<"$_writer.writeVarInt((uint64_t)$_name." # getter # ")", | ||
WithType<"uint64_t", VarInt>>>>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// General notes | ||
// - For each attribute or type entry, the argument names should match | ||
// LLVMAttrDefs.td | ||
// - The mnemonics are either LLVM or builtin MLIR attributes and types, but | ||
// regular C++ types are also allowed to match builders and parsers. | ||
// - DIScopeAttr and DINodeAttr are empty base classes, custom encoding not | ||
// needed. | ||
//===----------------------------------------------------------------------===// | ||
|
||
//===----------------------------------------------------------------------===// | ||
// AliasScopeAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def AliasScopeAttr : DialectAttribute<(attr | ||
Attr<"Attribute">:$id, | ||
Attr<"AliasScopeDomainAttr">:$domain, | ||
OptionalAttribute<"StringAttr">:$description | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DIBasicTypeAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DIBasicTypeAttr : DialectAttribute<(attr | ||
VarInt:$tag, | ||
String:$name, | ||
VarInt:$sizeInBits, | ||
VarInt:$encoding | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DIExpressionAttr, DIExpressionElemAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DIExpressionElemAttr : DialectAttribute<(attr | ||
VarInt:$opcode, | ||
OptionalArrayRef<"uint64_t">:$arguments | ||
)>; | ||
|
||
def DIExpressionAttr : DialectAttribute<(attr | ||
OptionalArrayRef<"DIExpressionElemAttr">:$operations | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DIFileAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DIFileAttr : DialectAttribute<(attr | ||
String:$name, | ||
String:$directory | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DILocalVariableAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DILocalVariableAttr : DialectAttribute<(attr | ||
Attr<"DIScopeAttr">:$scope, | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalAttribute<"DIFileAttr">:$file, | ||
VarInt:$line, | ||
VarInt:$arg, | ||
VarInt:$alignInBits, | ||
OptionalAttribute<"DITypeAttr">:$type, | ||
EnumClassFlag<"DIFlags", "getFlags()">:$_rawflags, | ||
LocalVar<"DIFlags", "(DIFlags)_rawflags">:$flags | ||
)> { | ||
// DILocalVariableAttr direct getter uses a `StringRef` for `name`. Since the | ||
// more direct getter is prefered during bytecode reading, force the base one | ||
// and prevent crashes for empty `StringAttr`. | ||
let cBuilder = "$_resultType::get(context, $_args)"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DISubroutineTypeAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DISubroutineTypeAttr : DialectAttribute<(attr | ||
VarInt:$callingConvention, | ||
OptionalArrayRef<"DITypeAttr">:$types | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DICompileUnitAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DICompileUnitAttr : DialectAttribute<(attr | ||
Attr<"DistinctAttr">:$id, | ||
VarInt:$sourceLanguage, | ||
Attr<"DIFileAttr">:$file, | ||
OptionalAttribute<"StringAttr">:$producer, | ||
Bool:$isOptimized, | ||
EnumClassFlag<"DIEmissionKind", "getEmissionKind()">:$_rawEmissionKind, | ||
LocalVar<"DIEmissionKind", "(DIEmissionKind)_rawEmissionKind">:$emissionKind, | ||
EnumClassFlag<"DINameTableKind", "getNameTableKind()">:$_rawNameTableKind, | ||
LocalVar<"DINameTableKind", | ||
"(DINameTableKind)_rawNameTableKind">:$nameTableKind | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DISubprogramAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DISubprogramAttr : DialectAttribute<(attr | ||
OptionalAttribute<"DistinctAttr">:$recId, | ||
Bool:$isRecSelf, | ||
OptionalAttribute<"DistinctAttr">:$id, | ||
OptionalAttribute<"DICompileUnitAttr">:$compileUnit, | ||
OptionalAttribute<"DIScopeAttr">:$scope, | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalAttribute<"StringAttr">:$linkageName, | ||
OptionalAttribute<"DIFileAttr">:$file, | ||
VarInt:$line, | ||
VarInt:$scopeLine, | ||
EnumClassFlag<"DISubprogramFlags", "getSubprogramFlags()">:$_rawflags, | ||
LocalVar<"DISubprogramFlags", "(DISubprogramFlags)_rawflags">:$subprogramFlags, | ||
OptionalAttribute<"DISubroutineTypeAttr">:$type, | ||
OptionalArrayRef<"DINodeAttr">:$retainedNodes, | ||
OptionalArrayRef<"DINodeAttr">:$annotations | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DICompositeTypeAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DICompositeTypeAttr : DialectAttribute<(attr | ||
OptionalAttribute<"DistinctAttr">:$recId, | ||
Bool:$isRecSelf, | ||
VarInt:$tag, | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalAttribute<"DIFileAttr">:$file, | ||
VarInt:$line, | ||
OptionalAttribute<"DIScopeAttr">:$scope, | ||
OptionalAttribute<"DITypeAttr">:$baseType, | ||
EnumClassFlag<"DIFlags", "getFlags()">:$_rawflags, | ||
LocalVar<"DIFlags", "(DIFlags)_rawflags">:$flags, | ||
VarInt:$sizeInBits, | ||
VarInt:$alignInBits, | ||
OptionalAttribute<"DIExpressionAttr">:$dataLocation, | ||
OptionalAttribute<"DIExpressionAttr">:$rank, | ||
OptionalAttribute<"DIExpressionAttr">:$allocated, | ||
OptionalAttribute<"DIExpressionAttr">:$associated, | ||
OptionalArrayRef<"DINodeAttr">:$elements | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DIDerivedTypeAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DIDerivedTypeAttr : DialectAttribute<(attr | ||
VarInt:$tag, | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalAttribute<"DITypeAttr">:$baseType, | ||
VarInt:$sizeInBits, | ||
VarInt:$alignInBits, | ||
VarInt:$offsetInBits, | ||
OptionalInt<"unsigned">:$dwarfAddressSpace, | ||
OptionalAttribute<"DINodeAttr">:$extraData | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DIImportedEntityAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DIImportedEntityAttr : DialectAttribute<(attr | ||
VarInt:$tag, | ||
Attr<"DIScopeAttr">:$scope, | ||
Attr<"DINodeAttr">:$entity, | ||
OptionalAttribute<"DIFileAttr">:$file, | ||
VarInt:$line, | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalArrayRef<"DINodeAttr">:$elements | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DIGlobalVariableAttr, DIGlobalVariableExpressionAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DIGlobalVariableAttr : DialectAttribute<(attr | ||
OptionalAttribute<"DIScopeAttr">:$scope, | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalAttribute<"StringAttr">:$linkageName, | ||
Attr<"DIFileAttr">:$file, | ||
VarInt:$line, | ||
Attr<"DITypeAttr">:$type, | ||
Bool:$isLocalToUnit, | ||
Bool:$isDefined, | ||
VarInt:$alignInBits | ||
)>; | ||
|
||
def DIGlobalVariableExpressionAttr : DialectAttribute<(attr | ||
Attr<"DIGlobalVariableAttr">:$var, | ||
OptionalAttribute<"DIExpressionAttr">:$expr | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DILabelAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DILabelAttr : DialectAttribute<(attr | ||
Attr<"DIScopeAttr">:$scope, | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalAttribute<"DIFileAttr">:$file, | ||
VarInt:$line | ||
)> { | ||
// DILabelAttr direct getter uses a `StringRef` for `name`. Since the | ||
// more direct getter is prefered during bytecode reading, force the base one | ||
// and prevent crashes for empty `StringAttr`. | ||
let cBuilder = "$_resultType::get(context, $_args)"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DILexicalBlockAttr, DILexicalBlockFileAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DILexicalBlockAttr : DialectAttribute<(attr | ||
Attr<"DIScopeAttr">:$scope, | ||
OptionalAttribute<"DIFileAttr">:$file, | ||
VarInt:$line, | ||
VarInt:$column | ||
)>; | ||
|
||
def DILexicalBlockFileAttr : DialectAttribute<(attr | ||
Attr<"DIScopeAttr">:$scope, | ||
OptionalAttribute<"DIFileAttr">:$file, | ||
VarInt:$discriminator | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DINamespaceAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DINamespaceAttr : DialectAttribute<(attr | ||
OptionalAttribute<"StringAttr">:$name, | ||
OptionalAttribute<"DIScopeAttr">:$scope, | ||
Bool:$exportSymbols | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DISubrangeAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def DISubrangeAttr : DialectAttribute<(attr | ||
OptionalAttribute<"Attribute">:$count, | ||
OptionalAttribute<"Attribute">:$lowerBound, | ||
OptionalAttribute<"Attribute">:$upperBound, | ||
OptionalAttribute<"Attribute">:$stride | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// LoopAnnotationAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def LoopAnnotationAttr : DialectAttribute<(attr | ||
OptionalAttribute<"BoolAttr">:$disableNonforced, | ||
OptionalAttribute<"LoopVectorizeAttr">:$vectorize, | ||
OptionalAttribute<"LoopInterleaveAttr">:$interleave, | ||
OptionalAttribute<"LoopUnrollAttr">:$unroll, | ||
OptionalAttribute<"LoopUnrollAndJamAttr">:$unrollAndJam, | ||
OptionalAttribute<"LoopLICMAttr">:$licm, | ||
OptionalAttribute<"LoopDistributeAttr">:$distribute, | ||
OptionalAttribute<"LoopPipelineAttr">:$pipeline, | ||
OptionalAttribute<"LoopPeeledAttr">:$peeled, | ||
OptionalAttribute<"LoopUnswitchAttr">:$unswitch, | ||
OptionalAttribute<"BoolAttr">:$mustProgress, | ||
OptionalAttribute<"BoolAttr">:$isVectorized, | ||
OptionalAttribute<"FusedLoc">:$startLoc, | ||
OptionalAttribute<"FusedLoc">:$endLoc, | ||
OptionalArrayRef<"AccessGroupAttr">:$parallelAccesses | ||
)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Attributes & Types with custom bytecode handling. | ||
//===----------------------------------------------------------------------===// | ||
|
||
// All the attributes with custom bytecode handling. | ||
def LLVMDialectAttributes : DialectAttributes<"LLVM"> { | ||
let elems = [ | ||
AliasScopeAttr, | ||
DIBasicTypeAttr, | ||
DICompileUnitAttr, | ||
DICompositeTypeAttr, | ||
DIDerivedTypeAttr, | ||
DIExpressionElemAttr, | ||
DIExpressionAttr, | ||
DIFileAttr, | ||
DIGlobalVariableAttr, | ||
DIGlobalVariableExpressionAttr, | ||
DIImportedEntityAttr, | ||
DILabelAttr, | ||
DILexicalBlockAttr, | ||
DILexicalBlockFileAttr, | ||
DILocalVariableAttr, | ||
DINamespaceAttr, | ||
DISubprogramAttr, | ||
DISubrangeAttr, | ||
DISubroutineTypeAttr, | ||
LoopAnnotationAttr | ||
// Referenced attributes currently missing support: | ||
// AccessGroupAttr, LoopVectorizeAttr, LoopInterleaveAttr, LoopUnrollAttr, | ||
// LoopUnrollAndJamAttr, LoopLICMAttr, LoopDistributeAttr, LoopPipelineAttr, | ||
// LoopPeeledAttr, LoopUnswitchAttr | ||
]; | ||
} | ||
|
||
def LLVMDialectTypes : DialectTypes<"LLVM"> { | ||
let elems = []; | ||
} | ||
|
||
#endif // LLVM_DIALECT_BYTECODE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.