-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe2df4e
commit 552a711
Showing
6 changed files
with
582 additions
and
1 deletion.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
experimental/iterators/lib/Conversion/IteratorsToLLVM/ArrowUtils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
//===-- IteratorsToLLVM.h - Conversion from Iterators to LLVM ---*- C++ -*-===// | ||
// | ||
// Licensed 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 "ArrowUtils.h" | ||
|
||
#include "iterators/Dialect/Iterators/IR/ArrowUtils.h" | ||
#include "iterators/Utils/MLIRSupport.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/IR/BuiltinOps.h" | ||
|
||
using namespace mlir; | ||
using namespace mlir::iterators; | ||
using namespace mlir::LLVM; | ||
|
||
namespace mlir { | ||
namespace iterators { | ||
|
||
LLVMFuncOp lookupOrInsertArrowArrayGetSize(ModuleOp module) { | ||
MLIRContext *context = module.getContext(); | ||
Type i64 = IntegerType::get(context, 64); | ||
Type array = getArrowArrayType(context); | ||
Type arrayPtr = LLVMPointerType::get(array); | ||
return lookupOrCreateFn(module, "mlirIteratorsArrowArrayGetSize", {arrayPtr}, | ||
i64); | ||
} | ||
|
||
LLVMFuncOp lookupOrInsertArrowArrayGetColumn(ModuleOp module, | ||
Type elementType) { | ||
assert(elementType.isIntOrFloat() && | ||
"only int or float types supported currently"); | ||
MLIRContext *context = module.getContext(); | ||
|
||
// Assemble types for signature. | ||
Type elementPtr = LLVMPointerType::get(elementType); | ||
Type i64 = IntegerType::get(context, 64); | ||
Type array = getArrowArrayType(context); | ||
Type arrayPtr = LLVMPointerType::get(array); | ||
Type schema = getArrowSchemaType(context); | ||
Type schemaPtr = LLVMPointerType::get(schema); | ||
|
||
// Assemble function name. | ||
StringRef typeNameBase; | ||
if (elementType.isSignedInteger() || elementType.isSignlessInteger()) | ||
typeNameBase = "Int"; | ||
else if (elementType.isUnsignedInteger()) | ||
typeNameBase = "UInt"; | ||
else { | ||
assert(elementType.isF16() || elementType.isF32() || elementType.isF64()); | ||
typeNameBase = "Float"; | ||
} | ||
std::string typeWidth = std::to_string(elementType.getIntOrFloatBitWidth()); | ||
std::string funcName = | ||
("mlirIteratorsArrowArrayGet" + typeNameBase + typeWidth + "Column") | ||
.str(); | ||
|
||
// Lookup or insert function. | ||
return lookupOrCreateFn(module, funcName, {arrayPtr, schemaPtr, i64}, | ||
elementPtr); | ||
} | ||
|
||
LLVMFuncOp lookupOrInsertArrowArrayRelease(ModuleOp module) { | ||
MLIRContext *context = module.getContext(); | ||
Type array = getArrowArrayType(context); | ||
Type arrayPtr = LLVMPointerType::get(array); | ||
Type voidType = LLVMVoidType::get(context); | ||
return lookupOrCreateFn(module, "mlirIteratorsArrowArrayRelease", {arrayPtr}, | ||
voidType); | ||
} | ||
|
||
LLVMFuncOp lookupOrInsertArrowSchemaRelease(ModuleOp module) { | ||
MLIRContext *context = module.getContext(); | ||
Type schema = getArrowSchemaType(context); | ||
Type schemaPtr = LLVMPointerType::get(schema); | ||
Type voidType = LLVMVoidType::get(context); | ||
return lookupOrCreateFn(module, "mlirIteratorsArrowSchemaRelease", | ||
{schemaPtr}, voidType); | ||
} | ||
|
||
LLVMFuncOp lookupOrInsertArrowArrayStreamGetSchema(ModuleOp module) { | ||
MLIRContext *context = module.getContext(); | ||
Type arrayStream = getArrowArrayStreamType(context); | ||
Type arrayStreamPtr = LLVMPointerType::get(arrayStream); | ||
Type schema = getArrowSchemaType(context); | ||
Type schemaPtr = LLVMPointerType::get(schema); | ||
Type voidType = LLVMVoidType::get(context); | ||
return lookupOrCreateFn(module, "mlirIteratorsArrowArrayStreamGetSchema", | ||
{arrayStreamPtr, schemaPtr}, voidType); | ||
} | ||
|
||
LLVMFuncOp lookupOrInsertArrowArrayStreamGetNext(ModuleOp module) { | ||
MLIRContext *context = module.getContext(); | ||
Type i1 = IntegerType::get(context, 1); | ||
Type stream = getArrowArrayStreamType(context); | ||
Type streamPtr = LLVMPointerType::get(stream); | ||
Type array = getArrowArrayType(context); | ||
Type arrayPtr = LLVMPointerType::get(array); | ||
return lookupOrCreateFn(module, "mlirIteratorsArrowArrayStreamGetNext", | ||
{streamPtr, arrayPtr}, i1); | ||
} | ||
|
||
LLVMFuncOp lookupOrInsertArrowArrayStreamRelease(ModuleOp module) { | ||
MLIRContext *context = module.getContext(); | ||
Type arrayStream = getArrowArrayStreamType(context); | ||
Type arrayStreamPtr = LLVMPointerType::get(arrayStream); | ||
Type voidType = LLVMVoidType::get(context); | ||
return lookupOrCreateFn(module, "mlirIteratorsArrowArrayStreamRelease", | ||
{arrayStreamPtr}, voidType); | ||
} | ||
|
||
} // namespace iterators | ||
} // namespace mlir |
60 changes: 60 additions & 0 deletions
60
experimental/iterators/lib/Conversion/IteratorsToLLVM/ArrowUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//===-- IteratorsToLLVM.h - Conversion from Iterators to LLVM ---*- C++ -*-===// | ||
// | ||
// Licensed 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 LIB_CONVERSION_ITERATORSTOLLVM_ARROWUTILS_H | ||
#define LIB_CONVERSION_ITERATORSTOLLVM_ARROWUTILS_H | ||
|
||
namespace mlir { | ||
class ModuleOp; | ||
class Type; | ||
namespace LLVM { | ||
class LLVMFuncOp; | ||
} // namespace LLVM | ||
} // namespace mlir | ||
|
||
namespace mlir { | ||
namespace iterators { | ||
|
||
/// Ensures that the runtime function `mlirIteratorsArrowArrayGetSize` is | ||
/// present in the current module and returns the corresponding LLVM func op. | ||
mlir::LLVM::LLVMFuncOp lookupOrInsertArrowArrayGetSize(mlir::ModuleOp module); | ||
|
||
/// Ensures that the runtime function `mlirIteratorsArrowArrayGet*Column` | ||
/// corresponding to the given type is present in the current module and returns | ||
/// the corresponding LLVM func op. | ||
mlir::LLVM::LLVMFuncOp | ||
lookupOrInsertArrowArrayGetColumn(mlir::ModuleOp module, | ||
mlir::Type elementType); | ||
|
||
/// Ensures that the runtime function `mlirIteratorsArrowArrayRelease` is | ||
/// present in the current module and returns the corresponding LLVM func op. | ||
mlir::LLVM::LLVMFuncOp lookupOrInsertArrowArrayRelease(mlir::ModuleOp module); | ||
|
||
/// Ensures that the runtime function `mlirIteratorsArrowSchemaRelease` is | ||
/// present in the current module and returns the corresponding LLVM func op. | ||
mlir::LLVM::LLVMFuncOp lookupOrInsertArrowSchemaRelease(mlir::ModuleOp module); | ||
|
||
/// Ensures that the runtime function `mlirIteratorsArrowArrayStreamGetSchema` | ||
/// is present in the current module and returns the corresponding LLVM func op. | ||
mlir::LLVM::LLVMFuncOp | ||
lookupOrInsertArrowArrayStreamGetSchema(mlir::ModuleOp module); | ||
|
||
/// Ensures that the runtime function `mlirIteratorsArrowArrayStreamGetNext` is | ||
/// present in the current module and returns the corresponding LLVM func op. | ||
mlir::LLVM::LLVMFuncOp | ||
lookupOrInsertArrowArrayStreamGetNext(mlir::ModuleOp module); | ||
|
||
/// Ensures that the runtime function `mlirIteratorsArrowArrayStreamRelease` is | ||
/// present in the current module and returns the corresponding LLVM func op. | ||
mlir::LLVM::LLVMFuncOp | ||
lookupOrInsertArrowArrayStreamRelease(mlir::ModuleOp module); | ||
|
||
} // namespace iterators | ||
} // namespace mlir | ||
|
||
#endif // LIB_CONVERSION_ITERATORSTOLLVM_ARROWUTILS_H |
1 change: 1 addition & 0 deletions
1
experimental/iterators/lib/Conversion/IteratorsToLLVM/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_mlir_conversion_library(MLIRIteratorsToLLVM | ||
ArrowUtils.cpp | ||
IteratorsToLLVM.cpp | ||
IteratorAnalysis.cpp | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.