Skip to content

Commit 108501e

Browse files
committed
Addressed reviewer comments
1 parent f2ffe70 commit 108501e

File tree

12 files changed

+223
-109
lines changed

12 files changed

+223
-109
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
add_mlir_dialect(PtrOps ptr)
22
add_mlir_doc(PtrOps PtrOps Dialects/ -gen-op-doc)
3+
4+
set(LLVM_TARGET_DEFINITIONS PtrOps.td)
5+
mlir_tablegen(PtrOpsAttrs.h.inc -gen-attrdef-decls -attrdefs-dialect=ptr)
6+
mlir_tablegen(PtrOpsAttrs.cpp.inc -gen-attrdef-defs -attrdefs-dialect=ptr)
7+
add_public_tablegen_target(MLIRPtrOpsAttributesIncGen)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===-- PtrAttrDefs.td - Ptr Attributes definition file ----*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef PTR_ATTRDEFS
10+
#define PTR_ATTRDEFS
11+
12+
include "mlir/Dialect/Ptr/IR/PtrDialect.td"
13+
include "mlir/IR/AttrTypeBase.td"
14+
15+
// All of the attributes will extend this class.
16+
class Ptr_Attr<string name, string attrMnemonic,
17+
list<Trait> traits = [],
18+
string baseCppClass = "::mlir::Attribute">
19+
: AttrDef<Ptr_Dialect, name, traits, baseCppClass> {
20+
let mnemonic = attrMnemonic;
21+
}
22+
23+
//===----------------------------------------------------------------------===//
24+
// SpecAttr
25+
//===----------------------------------------------------------------------===//
26+
27+
def Ptr_SpecAttr : Ptr_Attr<"Spec", "spec"> {
28+
let summary = "ptr data layout spec";
29+
let description = [{
30+
Defines the data layout spec for a pointer type. This attribute has 4
31+
fields:
32+
- [Required] size: size of the pointer in bits.
33+
- [Required] abi: ABI-required alignment for the pointer in bits.
34+
- [Required] preferred: preferred alignment for the pointer in bits.
35+
- [Optional] index: bitwidth that should be used when performing index
36+
computations for the type. Setting the field to `kOptionalSpecValue`, means
37+
the field is optional.
38+
39+
Furthermore, the attribute will verify that all present values are divisible
40+
by 8 (number of bits in a byte), and that `preferred` > `abi`.
41+
42+
Example:
43+
```mlir
44+
// Spec for a 64 bit ptr, with a required alignment of 64 bits, but with
45+
// a preferred alignment of 128 bits and an index bitwidth of 64 bits.
46+
#ptr.spec<size = 64, abi = 64, preferred = 128, index = 64>
47+
```
48+
}];
49+
let parameters = (ins
50+
"uint32_t":$size,
51+
"uint32_t":$abi,
52+
"uint32_t":$preferred,
53+
DefaultValuedParameter<"uint32_t", "kOptionalSpecValue">:$index
54+
);
55+
let skipDefaultBuilders = 1;
56+
let builders = [
57+
AttrBuilder<(ins "uint32_t":$size, "uint32_t":$abi, "uint32_t":$preferred,
58+
CArg<"uint32_t", "kOptionalSpecValue">:$index), [{
59+
return $_get($_ctxt, size, abi, preferred, index);
60+
}]>
61+
];
62+
let assemblyFormat = "`<` struct(params) `>`";
63+
let extraClassDeclaration = [{
64+
/// Constant for specifying a spec entry is optional.
65+
static constexpr uint32_t kOptionalSpecValue = std::numeric_limits<uint32_t>::max();
66+
}];
67+
let genVerifyDecl = 1;
68+
}
69+
70+
#endif // PTR_ATTRDEFS
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===- PtrAttrs.h - Pointer dialect attributes ------------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file declares the Ptr dialect attributes.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_PTR_IR_PTRATTRS_H
14+
#define MLIR_DIALECT_PTR_IR_PTRATTRS_H
15+
16+
#include "mlir/IR/OpImplementation.h"
17+
18+
#define GET_ATTRDEF_CLASSES
19+
#include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.h.inc"
20+
21+
#endif // MLIR_DIALECT_PTR_IR_PTRATTRS_H

mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def Ptr_Dialect : Dialect {
2323
let summary = "Pointer dialect";
2424
let cppNamespace = "::mlir::ptr";
2525
let useDefaultTypePrinterParser = 1;
26-
let useDefaultAttributePrinterParser = 0;
26+
let useDefaultAttributePrinterParser = 1;
2727
}
2828

2929
//===----------------------------------------------------------------------===//
@@ -64,13 +64,6 @@ def Ptr_PtrType : Ptr_Type<"Ptr", "ptr", [
6464
}]>
6565
];
6666
let skipDefaultBuilders = 1;
67-
let extraClassDeclaration = [{
68-
/// Returns the default memory space.
69-
Attribute getDefaultMemorySpace() const;
70-
71-
/// Returns the memory space as an unsigned number.
72-
uint64_t getAddressSpace() const;
73-
}];
7467
}
7568

7669
//===----------------------------------------------------------------------===//

mlir/include/mlir/Dialect/Ptr/IR/PtrOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define MLIR_DIALECT_PTR_IR_PTROPS_H
1515

1616
#include "mlir/Bytecode/BytecodeOpInterface.h"
17+
#include "mlir/Dialect/Ptr/IR/PtrAttrs.h"
1718
#include "mlir/Dialect/Ptr/IR/PtrDialect.h"
1819
#include "mlir/Dialect/Ptr/IR/PtrTypes.h"
1920
#include "mlir/IR/OpDefinition.h"

mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define PTR_OPS
1111

1212
include "mlir/Dialect/Ptr/IR/PtrDialect.td"
13+
include "mlir/Dialect/Ptr/IR/PtrAttrDefs.td"
1314
include "mlir/IR/OpAsmInterface.td"
1415

1516
#endif // PTR_OPS

mlir/include/mlir/Dialect/Ptr/IR/PtrTypes.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@
1616
#include "mlir/IR/Types.h"
1717
#include "mlir/Interfaces/DataLayoutInterfaces.h"
1818

19-
namespace mlir {
20-
namespace ptr {
21-
/// The positions of different values in the data layout entry for pointers.
22-
enum class PtrDLEntryPos { Size = 0, Abi = 1, Preferred = 2, Index = 3 };
23-
24-
/// Returns the value that corresponds to named position `pos` from the
25-
/// data layout entry `attr` assuming it's a dense integer elements attribute.
26-
/// Returns `std::nullopt` if `pos` is not present in the entry.
27-
/// Currently only `PtrDLEntryPos::Index` is optional, and all other positions
28-
/// may be assumed to be present.
29-
std::optional<uint64_t> extractPointerSpecValue(Attribute attr,
30-
PtrDLEntryPos pos);
31-
} // namespace ptr
32-
} // namespace mlir
33-
3419
#define GET_TYPEDEF_CLASSES
3520
#include "mlir/Dialect/Ptr/IR/PtrOpsTypes.h.inc"
3621

mlir/lib/Dialect/Ptr/IR/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
add_mlir_dialect_library(
22
MLIRPtrDialect
3+
PtrAttrs.cpp
34
PtrTypes.cpp
45
PtrDialect.cpp
56
ADDITIONAL_HEADER_DIRS
67
${PROJECT_SOURCE_DIR}/mlir/Dialect/Pointer
78
DEPENDS
9+
MLIRPtrOpsAttributesIncGen
810
MLIRPtrOpsIncGen
911
LINK_LIBS
1012
PUBLIC

mlir/lib/Dialect/Ptr/IR/PtrAttrs.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===- PtrAttrs.cpp - Pointer dialect attributes ----------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the Ptr dialect attributes.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/Dialect/Ptr/IR/PtrAttrs.h"
14+
#include "llvm/ADT/TypeSwitch.h"
15+
16+
using namespace mlir;
17+
using namespace mlir::ptr;
18+
19+
constexpr const static unsigned kBitsInByte = 8;
20+
21+
//===----------------------------------------------------------------------===//
22+
// SpecAttr
23+
//===----------------------------------------------------------------------===//
24+
25+
LogicalResult SpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,
26+
uint32_t size, uint32_t abi, uint32_t preferred,
27+
uint32_t index) {
28+
if (size % kBitsInByte != 0)
29+
return emitError() << "size entry must be divisible by 8";
30+
else if (abi % kBitsInByte != 0)
31+
return emitError() << "abi entry must be divisible by 8";
32+
else if (preferred % kBitsInByte != 0)
33+
return emitError() << "preferred entry must be divisible by 8";
34+
else if (index != kOptionalSpecValue && index % kBitsInByte != 0)
35+
return emitError() << "index entry must be divisible by 8";
36+
if (abi > preferred)
37+
return emitError() << "preferred alignment is expected to be at least "
38+
"as large as ABI alignment";
39+
return success();
40+
}

mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ void PtrDialect::initialize() {
2929
#define GET_OP_LIST
3030
#include "mlir/Dialect/Ptr/IR/PtrOps.cpp.inc"
3131
>();
32+
addAttributes<
33+
#define GET_ATTRDEF_LIST
34+
#include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.cpp.inc"
35+
>();
3236
addTypes<
3337
#define GET_TYPEDEF_LIST
3438
#include "mlir/Dialect/Ptr/IR/PtrOpsTypes.cpp.inc"
@@ -41,6 +45,9 @@ void PtrDialect::initialize() {
4145

4246
#include "mlir/Dialect/Ptr/IR/PtrOpsDialect.cpp.inc"
4347

48+
#define GET_ATTRDEF_CLASSES
49+
#include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.cpp.inc"
50+
4451
#define GET_TYPEDEF_CLASSES
4552
#include "mlir/Dialect/Ptr/IR/PtrOpsTypes.cpp.inc"
4653

0 commit comments

Comments
 (0)