Skip to content

Commit ae4b14b

Browse files
committed
update pr
1 parent b17c7b7 commit ae4b14b

File tree

25 files changed

+567
-41
lines changed

25 files changed

+567
-41
lines changed

mlir/include/mlir/Dialect/DLTI/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_subdirectory(TransformOps)
2+
add_subdirectory(Transforms)
23

34
add_mlir_dialect(DLTI dlti)
45
add_mlir_doc(DLTIAttrs DLTIDialect Dialects/ -gen-dialect-doc)

mlir/include/mlir/Dialect/DLTI/DLTIBase.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def DLTI_Dialect : Dialect {
3939
constexpr const static ::llvm::StringLiteral
4040
kTargetDeviceDescAttrName = "dlti.target_device_spec";
4141

42+
// Top-level attribute name for target information.
43+
constexpr const static ::llvm::StringLiteral
44+
kTargetDescAttrName = "dlti.target";
45+
4246
// Constants used in entries.
4347
constexpr const static ::llvm::StringLiteral
4448
kDataLayoutEndiannessKey = "dlti.endianness";

mlir/include/mlir/Dialect/DLTI/Traits.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace impl {
1919
LogicalResult verifyHasDefaultDLTIDataLayoutTrait(Operation *op);
2020
DataLayoutSpecInterface getDataLayoutSpec(Operation *op);
2121
TargetSystemSpecInterface getTargetSystemSpec(Operation *op);
22+
TargetAttrInterface getTargetAttr(Operation *op);
23+
void setDataLayoutSpec(Operation *op, DataLayoutSpecInterface spec);
24+
void setTargetSystemSpec(Operation *op, TargetSystemSpecInterface spec);
25+
void setTargetAttr(Operation *op, TargetAttrInterface target);
2226
} // namespace impl
2327

2428
/// Trait to be used by operations willing to use the implementation of the
@@ -39,11 +43,27 @@ class HasDefaultDLTIDataLayout
3943
return impl::getDataLayoutSpec(this->getOperation());
4044
}
4145

46+
/// Sets the data layout specification.
47+
void setDataLayoutSpec(DataLayoutSpecInterface spec) {
48+
impl::setDataLayoutSpec(this->getOperation(), spec);
49+
}
4250
/// Returns the target system description specification as provided by DLTI
4351
/// dialect
4452
TargetSystemSpecInterface getTargetSystemSpec() {
4553
return impl::getTargetSystemSpec(this->getOperation());
4654
}
55+
/// Sets the target system description specification.
56+
void setTargetSystemSpec(TargetSystemSpecInterface spec) {
57+
impl::setTargetSystemSpec(this->getOperation(), spec);
58+
}
59+
/// Returns the target information as provided by DLTI dialect.
60+
TargetAttrInterface getTargetAttr() {
61+
return impl::getTargetAttr(this->getOperation());
62+
}
63+
/// Sets the target information.
64+
void setTargetAttr(TargetAttrInterface target) {
65+
impl::setTargetAttr(this->getOperation(), target);
66+
}
4767
};
4868
} // namespace mlir
4969

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(LLVM_TARGET_DEFINITIONS Passes.td)
2+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name DLTI)
3+
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix DLTI)
4+
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix DLTI)
5+
add_public_tablegen_target(MLIRDLTIPassIncGen)
6+
7+
add_mlir_doc(Passes DLTIPasses ./ -gen-pass-doc)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- Passes.h - Pass Entrypoints ------------------------------*- C++ -*-===//
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+
// This header file defines prototypes that expose pass constructors.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_DLTI_TRANSFORMS_PASSES_H
14+
#define MLIR_DIALECT_DLTI_TRANSFORMS_PASSES_H
15+
16+
#include "mlir/Pass/Pass.h"
17+
18+
namespace mlir {
19+
#define GEN_PASS_DECL
20+
#include "mlir/Dialect/DLTI/Transforms/Passes.h.inc"
21+
22+
/// Generate the code for registering passes.
23+
#define GEN_PASS_REGISTRATION
24+
#include "mlir/Dialect/DLTI/Transforms/Passes.h.inc"
25+
26+
/// Sets the target specs using the target attached to the module.
27+
LogicalResult setTargetSpecsFromTarget(Operation *op);
28+
} // namespace mlir
29+
30+
#endif // MLIR_DIALECT_DLTI_TRANSFORMS_PASSES_H
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- Passes.td - DLTI pass 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 MLIR_DIALECT_DLTI_PASSES
10+
#define MLIR_DIALECT_DLTI_PASSES
11+
12+
include "mlir/Pass/PassBase.td"
13+
14+
def DltiSetTargetSpecsFromTarget: Pass<"dlti-set-target-specs", ""> {
15+
let summary = "Sets DLTI target specs using a target.";
16+
let description = [{
17+
This pass potentially sets the following DLTI target specs in the current
18+
operation:
19+
- The data layout.
20+
- The target system spec.
21+
22+
Example:
23+
24+
```mlir
25+
// Given the following input:
26+
builtin.module @module_1 attributes {dlti.target = #my.target} {...}
27+
// After applying the pass:
28+
builtin.module @module_1 attributes {
29+
dlti.target = #my.target,
30+
dlti.target_system_spec = #my.system_spec,
31+
dlti.dl_spec = #my.dl_spec
32+
} {...}
33+
```
34+
}];
35+
let dependentDialects = [
36+
"::mlir::DLTIDialect"
37+
];
38+
}
39+
40+
#endif // MLIR_DIALECT_DLTI_PASSES

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,8 @@ def GPU_BarrierOp : GPU_Op<"barrier"> {
13881388
}
13891389

13901390
def GPU_GPUModuleOp : GPU_Op<"module", [
1391-
IsolatedFromAbove, DataLayoutOpInterface, HasDefaultDLTIDataLayout,
1391+
IsolatedFromAbove,
1392+
DeclareOpInterfaceMethods<DataLayoutOpInterface, ["getTargetAttr", "setTargetAttr"]>,
13921393
NoRegionArguments, SymbolTable, Symbol] # GraphRegionNoTerminator.traits> {
13931394
let summary = "A top level compilation unit containing code to be run on a GPU.";
13941395
let description = [{

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,9 +3247,7 @@ def NVVM_Tcgen05StOp : NVVM_Op<"tcgen05.st"> {
32473247
// NVVM target attribute.
32483248
//===----------------------------------------------------------------------===//
32493249

3250-
def NVVM_TargettAttr : NVVM_Attr<"NVVMTarget", "target", [
3251-
DeclareAttrInterfaceMethods<TargetInfoAttrInterface>
3252-
]> {
3250+
def NVVM_TargettAttr : NVVM_Attr<"NVVMTarget", "target"> {
32533251
let description = [{
32543252
GPU target attribute for controlling compilation of NVIDIA targets. All
32553253
parameters decay into default values if not present.

mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,7 @@ def ROCDL_CvtSrFp8F32Op :
11171117
// ROCDL target attribute.
11181118
//===----------------------------------------------------------------------===//
11191119

1120-
def ROCDL_TargettAttr : ROCDL_Attr<"ROCDLTarget", "target", [
1121-
DeclareAttrInterfaceMethods<TargetInfoAttrInterface>
1122-
]> {
1120+
def ROCDL_TargettAttr : ROCDL_Attr<"ROCDLTarget", "target"> {
11231121
let description = [{
11241122
ROCDL target attribute for controlling compilation of AMDGPU targets. All
11251123
parameters decay into default values if not present.

mlir/include/mlir/InitAllPasses.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "mlir/Dialect/Async/Passes.h"
2424
#include "mlir/Dialect/Bufferization/Pipelines/Passes.h"
2525
#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
26+
#include "mlir/Dialect/DLTI/Transforms/Passes.h"
2627
#include "mlir/Dialect/EmitC/Transforms/Passes.h"
2728
#include "mlir/Dialect/Func/Transforms/Passes.h"
2829
#include "mlir/Dialect/GPU/Pipelines/Passes.h"
@@ -75,6 +76,7 @@ inline void registerAllPasses() {
7576
bufferization::registerBufferizationPasses();
7677
func::registerFuncPasses();
7778
registerGPUPasses();
79+
registerDLTIPasses();
7880
registerLinalgPasses();
7981
registerNVGPUPasses();
8082
registerSparseTensorPasses();

mlir/include/mlir/Interfaces/DataLayoutInterfaces.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class DataLayout;
2727
class DataLayoutEntryInterface;
2828
class DLTIQueryInterface;
2929
class TargetDeviceSpecInterface;
30+
struct TargetSpec;
3031
class TargetSystemSpecInterface;
3132
using DataLayoutEntryKey = llvm::PointerUnion<Type, StringAttr>;
3233
// Using explicit SmallVector size because we cannot infer the size from the
@@ -305,6 +306,13 @@ class DataLayout {
305306
mutable std::optional<uint64_t> stackAlignment;
306307
};
307308

309+
/// Helper struct for storing a target specification.
310+
struct TargetSpec {
311+
/// Target system spec.
312+
TargetSystemSpecInterface systemSpec;
313+
/// Target data layout.
314+
DataLayoutSpecInterface dataLayout;
315+
};
308316
} // namespace mlir
309317

310318
#endif // MLIR_INTERFACES_DATALAYOUTINTERFACES_H

mlir/include/mlir/Interfaces/DataLayoutInterfaces.td

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,28 @@ def TargetSystemSpecInterface : AttrInterface<"TargetSystemSpecInterface", [DLTI
354354
}];
355355
}
356356

357-
def TargetInfoAttrInterface : AttrInterface<"TargetInfoAttrInterface"> {
357+
def TargetAttrInterface : AttrInterface<"TargetAttrInterface"> {
358358
let cppNamespace = "::mlir";
359359

360360
let description = [{
361361
Attribute interface describing target information.
362362

363-
Target information attributes provide essential information on the
363+
Target information attributes provide essential information on a
364364
compilation target. This information includes the target triple identifier,
365-
the target chip identifier, and a string representation of the target features.
365+
the target chip identifier, a string representation of the target features,
366+
and the target spec data layout.
366367
}];
367368

368369
let methods = [
369370
InterfaceMethod<
370371
/*description=*/"Returns the target triple identifier.",
371-
/*retTy=*/"::mlir::StringRef",
372+
/*retTy=*/"::llvm::StringRef",
372373
/*methodName=*/"getTargetTriple",
373374
/*args=*/(ins)
374375
>,
375376
InterfaceMethod<
376377
/*description=*/"Returns the target chip identifier.",
377-
/*retTy=*/"::mlir::StringRef",
378+
/*retTy=*/"::llvm::StringRef",
378379
/*methodName=*/"getTargetChip",
379380
/*args=*/(ins)
380381
>,
@@ -383,6 +384,12 @@ def TargetInfoAttrInterface : AttrInterface<"TargetInfoAttrInterface"> {
383384
/*retTy=*/"std::string",
384385
/*methodName=*/"getTargetFeatures",
385386
/*args=*/(ins)
387+
>,
388+
InterfaceMethod<
389+
/*description=*/"Sets the target spec. Returns failure if there was a problem.",
390+
/*retTy=*/"::llvm::LogicalResult",
391+
/*methodName=*/"setTargetSpec",
392+
/*args=*/(ins "::mlir::TargetSpec&":$spec)
386393
>
387394
];
388395
}
@@ -420,13 +427,39 @@ def DataLayoutOpInterface : OpInterface<"DataLayoutOpInterface"> {
420427
/*methodName=*/"getDataLayoutSpec",
421428
/*args=*/(ins)
422429
>,
430+
InterfaceMethod<
431+
/*description=*/"Sets the data layout specification for this op.",
432+
/*retTy=*/"void",
433+
/*methodName=*/"setDataLayoutSpec",
434+
/*args=*/(ins "::mlir::DataLayoutSpecInterface":$spec)
435+
>,
423436
InterfaceMethod<
424437
/*description=*/"Returns the target system desc specification for this "
425438
"op, or null if it does not exist.",
426439
/*retTy=*/"::mlir::TargetSystemSpecInterface",
427440
/*methodName=*/"getTargetSystemSpec",
428441
/*args=*/(ins)
429442
>,
443+
InterfaceMethod<
444+
/*description=*/"Sets the target system desc specification for this "
445+
"op.",
446+
/*retTy=*/"void",
447+
/*methodName=*/"setTargetSystemSpec",
448+
/*args=*/(ins "::mlir::TargetSystemSpecInterface":$spec)
449+
>,
450+
InterfaceMethod<
451+
/*description=*/"Returns the target attr for this op, or null if it "
452+
"does not exist.",
453+
/*retTy=*/"::mlir::TargetAttrInterface",
454+
/*methodName=*/"getTargetAttr",
455+
/*args=*/(ins)
456+
>,
457+
InterfaceMethod<
458+
/*description=*/"Sets the target attr for this",
459+
/*retTy=*/"void",
460+
/*methodName=*/"setTargetAttr",
461+
/*args=*/(ins "::mlir::TargetAttrInterface":$target)
462+
>,
430463
StaticInterfaceMethod<
431464
/*description=*/"Returns the size of the given type computed using the "
432465
"relevant entries. The data layout object can be used "
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//===- Target.h - Target information ----------------------------*- C++ -*-===//
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+
// This file declare utilities to interact with LLVM targets by querying an MLIR
10+
// target.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef MLIR_TARGET_LLVM_TARGET_H
15+
#define MLIR_TARGET_LLVM_TARGET_H
16+
17+
#include "mlir/Interfaces/DataLayoutInterfaces.h"
18+
#include "llvm/IR/DataLayout.h"
19+
#include "llvm/TargetParser/Triple.h"
20+
21+
namespace llvm {
22+
class Triple;
23+
class Target;
24+
class TargetMachine;
25+
} // namespace llvm
26+
27+
namespace mlir {
28+
/// Given a target triple. chip and features returns the LLVM data layout.
29+
FailureOr<const llvm::DataLayout>
30+
getLLVMDataLayout(StringRef triple, StringRef chip, StringRef features);
31+
32+
/// Returns the LLVM target triple held by `target`.
33+
llvm::Triple getTargetTriple(TargetAttrInterface target);
34+
35+
/// Returns the LLVM target held by `target`.
36+
FailureOr<const llvm::Target *> getLLVMTarget(TargetAttrInterface target);
37+
38+
/// Helper class for holding LLVM target information. Note: This class requires
39+
/// that the corresponding LLVM target has ben initialized.
40+
class TargetInfo {
41+
public:
42+
TargetInfo(TargetInfo &&) = default;
43+
TargetInfo(const TargetInfo &) = delete;
44+
~TargetInfo();
45+
TargetInfo &operator=(TargetInfo &&) = default;
46+
TargetInfo &operator=(const TargetInfo &) = delete;
47+
/// Constructs the target info from `target`.
48+
static FailureOr<TargetInfo> getTargetInfo(StringRef triple, StringRef chip,
49+
StringRef features);
50+
51+
/// Constructs the target info from `target`.
52+
static FailureOr<TargetInfo> getTargetInfo(TargetAttrInterface target) {
53+
return getTargetInfo(target.getTargetTriple(), target.getTargetChip(),
54+
target.getTargetFeatures());
55+
}
56+
57+
/// Returns the target chip.
58+
StringRef getTargetChip() const;
59+
60+
/// Returns the target features.
61+
StringRef getTargetFeatures() const;
62+
63+
/// Returns the target triple.
64+
const llvm::Triple &getTriple() const;
65+
66+
/// Returns the target.
67+
const llvm::Target &getTarget() const;
68+
69+
/// Returns the target machine.
70+
const llvm::TargetMachine *getTargetMachine() const {
71+
return targetMachine.get();
72+
}
73+
74+
/// Returns the LLVM data layout for the corresponding target.
75+
const llvm::DataLayout getDataLayout() const;
76+
77+
private:
78+
TargetInfo(llvm::TargetMachine *targetMachine);
79+
/// The LLVM target machine.
80+
mutable std::unique_ptr<llvm::TargetMachine> targetMachine;
81+
};
82+
} // namespace mlir
83+
84+
#endif // MLIR_TARGET_LLVM_TARGET_H

mlir/lib/Dialect/DLTI/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_subdirectory(Transforms)
12
add_subdirectory(TransformOps)
23
add_mlir_dialect_library(MLIRDLTIDialect
34
DLTI.cpp

0 commit comments

Comments
 (0)