forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/fused-ops' into bump_to_…
…5855237
- Loading branch information
Showing
30 changed files
with
905 additions
and
34 deletions.
There are no files selected for viewing
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
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
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,25 @@ | ||
//===- UBToEmitC.h - UB to EmitC dialect conversion -------------*- 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 MLIR_CONVERSION_UBTOEMITC_UBTOEMITC_H | ||
#define MLIR_CONVERSION_UBTOEMITC_UBTOEMITC_H | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Transforms/DialectConversion.h" | ||
|
||
namespace mlir { | ||
#define GEN_PASS_DECL_CONVERTUBTOEMITC | ||
#include "mlir/Conversion/Passes.h.inc" | ||
|
||
namespace ub { | ||
void populateUBToEmitCConversionPatterns(TypeConverter &converter, | ||
RewritePatternSet &patterns); | ||
} // namespace ub | ||
} // namespace mlir | ||
|
||
#endif // MLIR_CONVERSION_UBTOEMITC_UBTOEMITC_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
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
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,43 @@ | ||
//===---------- FunctionOpAssembly.h - Parser for `emitc.func` op ---------===// | ||
// | ||
// 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 MLIR_INCLUDE_MLIR_DIALECT_EMITC_IR_FUNCTIONOPASSEMBLY_H | ||
#define MLIR_INCLUDE_MLIR_DIALECT_EMITC_IR_FUNCTIONOPASSEMBLY_H | ||
|
||
#include "mlir/IR/OperationSupport.h" | ||
#include "mlir/Interfaces/FunctionImplementation.h" | ||
#include "mlir/Support/LogicalResult.h" | ||
|
||
#include "mlir/IR/Builders.h" | ||
|
||
namespace mlir::emitc { | ||
|
||
class FuncOp; | ||
|
||
ParseResult | ||
parseFunctionSignature(OpAsmParser &parser, bool allowVariadic, | ||
SmallVectorImpl<OpAsmParser::Argument> &arguments, | ||
bool &isVariadic, SmallVectorImpl<Type> &resultTypes, | ||
SmallVectorImpl<DictionaryAttr> &resultAttrs); | ||
|
||
ParseResult | ||
parseFunctionOp(OpAsmParser &parser, OperationState &result, bool allowVariadic, | ||
StringAttr typeAttrName, | ||
function_interface_impl::FuncTypeBuilder funcTypeBuilder, | ||
StringAttr argAttrsName, StringAttr resAttrsName); | ||
|
||
void printFunctionSignature(OpAsmPrinter &p, FuncOp op, ArrayRef<Type> argTypes, | ||
bool isVariadic, ArrayRef<Type> resultTypes); | ||
|
||
void printFunctionOp(OpAsmPrinter &p, FuncOp op, bool isVariadic, | ||
StringRef typeAttrName, StringAttr argAttrsName, | ||
StringAttr resAttrsName); | ||
|
||
} // namespace mlir::emitc | ||
|
||
#endif // MLIR_INCLUDE_MLIR_DIALECT_EMITC_IR_FUNCTIONOPASSEMBLY_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
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
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,17 @@ | ||
add_mlir_conversion_library(MLIRUBToEmitC | ||
UBToEmitC.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/UBToEmitC | ||
|
||
DEPENDS | ||
MLIRConversionPassIncGen | ||
|
||
LINK_COMPONENTS | ||
Core | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRLLVMCommonConversion | ||
MLIREmitCDialect | ||
MLIRUBDialect | ||
) |
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,79 @@ | ||
//===- UBToEmitC.cpp - UB to EmitC dialect conversion ---------------------===// | ||
// | ||
// 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 "mlir/Conversion/UBToEmitC/UBToEmitC.h" | ||
|
||
#include "mlir/Dialect/EmitC/IR/EmitC.h" | ||
#include "mlir/Dialect/EmitC/Transforms/TypeConversions.h" | ||
#include "mlir/Dialect/UB/IR/UBOps.h" | ||
#include "mlir/IR/BuiltinAttributes.h" | ||
#include "mlir/IR/BuiltinTypes.h" | ||
#include "mlir/IR/TypeUtilities.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Transforms/DialectConversion.h" | ||
|
||
namespace mlir { | ||
#define GEN_PASS_DEF_CONVERTUBTOEMITC | ||
#include "mlir/Conversion/Passes.h.inc" | ||
} // namespace mlir | ||
|
||
using namespace mlir; | ||
|
||
namespace { | ||
struct PoisonOpLowering : public OpConversionPattern<ub::PoisonOp> { | ||
using OpConversionPattern::OpConversionPattern; | ||
|
||
LogicalResult | ||
matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor, | ||
ConversionPatternRewriter &rewriter) const override { | ||
const TypeConverter *converter = getTypeConverter(); | ||
Type convertedType = converter->convertType(op.getType()); | ||
|
||
if (!convertedType) | ||
return rewriter.notifyMatchFailure(op.getLoc(), "type conversion failed"); | ||
|
||
if (!(emitc::isIntegerIndexOrOpaqueType(convertedType) || | ||
emitc::isSupportedFloatType(convertedType))) { | ||
return rewriter.notifyMatchFailure( | ||
op.getLoc(), "only scalar poison values can be lowered"); | ||
} | ||
|
||
// Any constant will be fine to lower a poison op | ||
rewriter.replaceOpWithNewOp<emitc::VariableOp>( | ||
op, convertedType, emitc::OpaqueAttr::get(op->getContext(), "")); | ||
return success(); | ||
} | ||
}; | ||
} // namespace | ||
|
||
void ub::populateUBToEmitCConversionPatterns(TypeConverter &converter, | ||
RewritePatternSet &patterns) { | ||
MLIRContext *ctx = patterns.getContext(); | ||
patterns.add<PoisonOpLowering>(converter, ctx); | ||
} | ||
|
||
struct ConvertUBToEmitC : public impl::ConvertUBToEmitCBase<ConvertUBToEmitC> { | ||
using Base::Base; | ||
|
||
void runOnOperation() override { | ||
RewritePatternSet patterns(&getContext()); | ||
TypeConverter converter; | ||
converter.addConversion([](Type t) { return t; }); | ||
populateEmitCSizeTTypeConversions(converter); | ||
|
||
ConversionTarget target(getContext()); | ||
target.addLegalDialect<emitc::EmitCDialect>(); | ||
target.addIllegalDialect<ub::UBDialect>(); | ||
|
||
mlir::ub::populateUBToEmitCConversionPatterns(converter, patterns); | ||
|
||
if (failed(applyPartialConversion(getOperation(), target, | ||
std::move(patterns)))) | ||
signalPassFailure(); | ||
} | ||
}; |
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
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.