Skip to content

Commit

Permalink
Add DLTI helper
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-smnk committed Jan 16, 2025
1 parent ad31e0f commit 76bcc85
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
30 changes: 30 additions & 0 deletions include/TPP/Transforms/Utils/DLTIUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- DLTIUtils.h -----------------------------------------------*- C++-*-===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef TPP_TRANSFORMS_UTILS_DLTIUTILS_H
#define TPP_TRANSFORMS_UTILS_DLTIUTILS_H

#include "mlir/Dialect/DLTI/DLTI.h"

namespace llvm {
class StringRef;
} // namespace llvm

namespace mlir {
namespace dlti {
namespace utils {

// Perform a DLTI-query using string keys.
FailureOr<Attribute> query(Operation *op, ArrayRef<StringRef> keys,
bool emitError = false);

} // namespace utils
} // namespace dlti
} // namespace mlir

#endif // TPP_TRANSFORMS_UTILS_DLTIUTILS_H
1 change: 1 addition & 0 deletions lib/TPP/Transforms/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_mlir_library(TPPTransformsUtils
BuilderUtils.cpp
DLTIUtils.cpp
TensorInit.cpp
TensorInitFloat.cpp
TensorInitInt.cpp
Expand Down
32 changes: 32 additions & 0 deletions lib/TPP/Transforms/Utils/DLTIUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===- DLTIUtils.cpp ---------------------------------------------*- C++-*-===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "TPP/Transforms/Utils/DLTIUtils.h"

namespace mlir {
namespace dlti {
namespace utils {

FailureOr<Attribute> query(Operation *op, ArrayRef<StringRef> keys,
bool emitError) {
if (!op)
return failure();

auto ctx = op->getContext();
SmallVector<DataLayoutEntryKey> entryKeys;
for (auto &key : keys) {
auto entry = StringAttr::get(ctx, key);
entryKeys.push_back(entry);
}

return dlti::query(op, entryKeys, emitError);
}

} // namespace utils
} // namespace dlti
} // namespace mlir

0 comments on commit 76bcc85

Please sign in to comment.