-
Notifications
You must be signed in to change notification settings - Fork 299
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
[LLHD] Add extract field operations #35
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,3 +101,118 @@ def LLHD_DextsOp : LLHD_Op<"dexts", [ | |
unsigned getTargetWidth() { return getLLHDTypeWidth(target().getType()); } | ||
}]; | ||
} | ||
|
||
def LLHD_ExtfOp : LLHD_Op<"extf", [ | ||
NoSideEffect, | ||
PredOpTrait<"'index' has to be smaller than the 'target' size", | ||
CPred<"$index.cast<IntegerAttr>().getInt() < getTargetWidth()">>, | ||
TypesMatchWith<"'result' type has to match type at 'index' of 'target', in " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems awkwardly worded to me. The description doesn't quite seem to match the predicate? |
||
"case 'target' is a singal, consider the underlying types of the 'target'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. singal -> signal |
||
" and 'result' signals", | ||
"target", "result", | ||
"($_self.isa<llhd::SigType>() " | ||
"? llhd::SigType::get(" | ||
"getElementTypeAtIndex($index.cast<IntegerAttr>().getInt())) " | ||
": getElementTypeAtIndex($index.cast<IntegerAttr>().getInt()))"> | ||
]> { | ||
let summary = "Extract an element from a vector or tuple"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or a signal with with vector or tuple type? |
||
let description = [{ | ||
The `llhd.extf` operation allows access to an element of the `$target` | ||
operand. The `$index` attribute defines the index of the element to extract. | ||
If `%target` is a signal, a new subsignal aliasing the field will be | ||
returned. | ||
|
||
Example: | ||
|
||
```mlir | ||
%0 = constant dense<[1,2,3]> : vector<3xi8> | ||
%1 = llhd.extf %0, 0 : vector<3xi8> -> i8 | ||
|
||
%2 = llhd.sig %0 : vector<3xi8> | ||
%3 = llhd.extf %2, 0 : !llhd.sig<vector<3xi8>> -> !llhd.sig<i8> | ||
|
||
%4 = llhd.const 8 : i16 | ||
%5 = llhd.tuple %0, %4 : tuple<vector<3xi8>, i16> | ||
%6 = llhd.extf %5, 1 : tuple<vector<3xi8>, i16> -> i16 | ||
``` | ||
}]; | ||
|
||
let arguments = (ins AnyTypeOf<[ | ||
AnyVector, | ||
AnyTuple, | ||
LLHD_SigType<[AnyVector, AnyTuple]> | ||
]>: $target, | ||
IndexAttr: $index); | ||
|
||
let results = (outs AnyType: $result); | ||
|
||
let assemblyFormat = [{ | ||
$target `,` $index attr-dict `:` type($target) `->` type($result) | ||
}]; | ||
|
||
let extraClassDeclaration = [{ | ||
unsigned getTargetWidth() { return getLLHDTypeWidth(target().getType()); }; | ||
|
||
Type getElementTypeAtIndex(unsigned index) { | ||
Type targetType = target().getType(); | ||
if (auto sig = targetType.dyn_cast<llhd::SigType>()) | ||
targetType = sig.getUnderlyingType(); | ||
if (auto vec = targetType.dyn_cast<VectorType>()) | ||
return vec.getElementType(); | ||
return targetType.dyn_cast<TupleType>().getTypes()[index]; | ||
} | ||
}]; | ||
} | ||
|
||
def LLHD_DextfOp : LLHD_Op<"dextf", [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh no, it's random sequence of letters op! |
||
NoSideEffect, | ||
TypesMatchWith<"'result' must be the element type of the 'target' vector, in " | ||
"case 'target' is a signal of a vector, 'result' also is a signal of the " | ||
"vector element type", | ||
"target", "result", | ||
"($_self.isa<llhd::SigType>() ? llhd::SigType::get(getElementType()) " | ||
": getElementType())"> | ||
]> { | ||
let summary = [{ | ||
Dynamically extract an element from a vector or signal of vector. | ||
}]; | ||
let description = [{ | ||
The `llhd.dextf` operation allows to dynamically access an element of the | ||
`$target` operand. The `$index` operand defines the index of the element to | ||
extract. If `%target` is a signal, a new subsignal aliasing the element will | ||
be returned. | ||
|
||
Example: | ||
|
||
```mlir | ||
%index = llhd.const 1 : i2 | ||
|
||
%0 = constant dense<[1,2,3]> : vector<3xi8> | ||
%1 = llhd.dextf %0, %index : (vector<3xi8>, i2) -> i8 | ||
|
||
%2 = llhd.sig %0 : vector<3xi8> | ||
%3 = llhd.dextf %2, %index : (!llhd.sig<vector<3xi8>>, i2) -> !llhd.sig<i8> | ||
``` | ||
}]; | ||
|
||
let arguments = (ins | ||
AnyTypeOf<[AnyVector, LLHD_SigType<[AnyVector]>]>: $target, | ||
AnySignlessInteger: $index); | ||
|
||
let results = (outs AnyType: $result); | ||
|
||
let assemblyFormat = [{ | ||
$target `,` $index attr-dict `:` functional-type(operands, results) | ||
}]; | ||
|
||
let extraClassDeclaration = [{ | ||
unsigned getTargetWidth() { return getLLHDTypeWidth(target().getType()); } | ||
|
||
Type getElementType() { | ||
Type targetType = target().getType(); | ||
if (auto sig = targetType.dyn_cast<llhd::SigType>()) | ||
targetType = sig.getUnderlyingType(); | ||
return targetType.dyn_cast<VectorType>().getElementType(); | ||
} | ||
}]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer complete words. IS this "Extend Float?" "Extract field?" "External foobar?" "Example Tensorflow?"