Skip to content

Commit

Permalink
rebased
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
mgehre-amd committed Feb 28, 2024
2 parents b57a4de + eaab317 commit 0a5f662
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 72 deletions.
92 changes: 46 additions & 46 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,6 @@ class EmitC_Type<string name, string typeMnemonic, list<Trait> traits = []>
let mnemonic = typeMnemonic;
}

def EmitC_OpaqueType : EmitC_Type<"Opaque", "opaque"> {
let summary = "EmitC opaque type";

let description = [{
An opaque data type of which the value gets emitted as is.

Example:

```mlir
!emitc.opaque<"int">
!emitc.opaque<"mytype">
!emitc.opaque<"std::vector<std::string>">
```
}];

let parameters = (ins StringRefParameter<"the opaque value">:$value);
let hasCustomAssemblyFormat = 1;
}

def EmitC_PointerType : EmitC_Type<"Pointer", "ptr"> {
let summary = "EmitC pointer type";

let description = [{
A pointer data type.

Example:

```mlir
// Pointer emitted as `int32_t*`
!emitc.ptr<i32>
// Pointer emitted as `float*`
!emitc.ptr<f32>
// Pointer emitted as `int*`
!emitc.ptr<!emitc.opaque<"int">>
```
}];

let parameters = (ins "Type":$pointee);
let builders = [
TypeBuilderWithInferredContext<(ins "Type":$pointee), [{
return $_get(pointee.getContext(), pointee);
}]>
];
let assemblyFormat = "`<` qualified($pointee) `>`";
}

def EmitC_ArrayType : EmitC_Type<"Array", "array", [ShapedTypeInterface]> {
let summary = "EmitC array type";

Expand Down Expand Up @@ -120,4 +74,50 @@ def EmitC_ArrayType : EmitC_Type<"Array", "array", [ShapedTypeInterface]> {
let hasCustomAssemblyFormat = 1;
}

def EmitC_OpaqueType : EmitC_Type<"Opaque", "opaque"> {
let summary = "EmitC opaque type";

let description = [{
An opaque data type of which the value gets emitted as is.

Example:

```mlir
!emitc.opaque<"int">
!emitc.opaque<"mytype">
!emitc.opaque<"std::vector<std::string>">
```
}];

let parameters = (ins StringRefParameter<"the opaque value">:$value);
let hasCustomAssemblyFormat = 1;
}

def EmitC_PointerType : EmitC_Type<"Pointer", "ptr"> {
let summary = "EmitC pointer type";

let description = [{
A pointer data type.

Example:

```mlir
// Pointer emitted as `int32_t*`
!emitc.ptr<i32>
// Pointer emitted as `float*`
!emitc.ptr<f32>
// Pointer emitted as `int*`
!emitc.ptr<!emitc.opaque<"int">>
```
}];

let parameters = (ins "Type":$pointee);
let builders = [
TypeBuilderWithInferredContext<(ins "Type":$pointee), [{
return $_get(pointee.getContext(), pointee);
}]>
];
let assemblyFormat = "`<` qualified($pointee) `>`";
}

#endif // MLIR_DIALECT_EMITC_IR_EMITCTYPES
56 changes: 30 additions & 26 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,34 +579,9 @@ void emitc::OpaqueAttr::print(AsmPrinter &printer) const {
#include "mlir/Dialect/EmitC/IR/EmitCTypes.cpp.inc"

//===----------------------------------------------------------------------===//
// OpaqueType
// ArrayType
//===----------------------------------------------------------------------===//

Type emitc::OpaqueType::parse(AsmParser &parser) {
if (parser.parseLess())
return Type();
std::string value;
SMLoc loc = parser.getCurrentLocation();
if (parser.parseOptionalString(&value) || value.empty()) {
parser.emitError(loc) << "expected non empty string in !emitc.opaque type";
return Type();
}
if (value.back() == '*') {
parser.emitError(loc) << "pointer not allowed as outer type with "
"!emitc.opaque, use !emitc.ptr instead";
return Type();
}
if (parser.parseGreater())
return Type();
return get(parser.getContext(), value);
}

void emitc::OpaqueType::print(AsmPrinter &printer) const {
printer << "<\"";
llvm::printEscapedString(getValue(), printer.getStream());
printer << "\">";
}

Type emitc::ArrayType::parse(AsmParser &parser) {
if (parser.parseLess())
return Type();
Expand Down Expand Up @@ -665,3 +640,32 @@ emitc::ArrayType::cloneWith(std::optional<ArrayRef<int64_t>> shape,
return emitc::ArrayType::get(getShape(), elementType);
return emitc::ArrayType::get(*shape, elementType);
}

//===----------------------------------------------------------------------===//
// OpaqueType
//===----------------------------------------------------------------------===//

Type emitc::OpaqueType::parse(AsmParser &parser) {
if (parser.parseLess())
return Type();
std::string value;
SMLoc loc = parser.getCurrentLocation();
if (parser.parseOptionalString(&value) || value.empty()) {
parser.emitError(loc) << "expected non empty string in !emitc.opaque type";
return Type();
}
if (value.back() == '*') {
parser.emitError(loc) << "pointer not allowed as outer type with "
"!emitc.opaque, use !emitc.ptr instead";
return Type();
}
if (parser.parseGreater())
return Type();
return get(parser.getContext(), value);
}

void emitc::OpaqueType::print(AsmPrinter &printer) const {
printer << "<\"";
llvm::printEscapedString(getValue(), printer.getStream());
printer << "\">";
}

0 comments on commit 0a5f662

Please sign in to comment.