Unverified Commit 126f0374 authored by Gil Rapaport's avatar Gil Rapaport Committed by GitHub
Browse files

Add a structured if operation (#67234)

Add an emitc.if op to the EmitC dialect. A new convert-scf-to-emitc
pass replaces the existing direct translation of scf.if to C; The
translator now handles emitc.if instead.

The emitc.if op doesn't return any value and its then/else regions are
terminated with a new scf.yield op. Values returned by scf.if are
lowered using emitc.variable ops, assigned to in the then/else regions
using a new emitc.assign op.
parent bd675f58
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ translating the following operations:
    *   `func.return`
*   'scf' Dialect
    *   `scf.for`
    *   `scf.if`
    *   `scf.yield`
*   'arith' Dialect
    *   `arith.constant`
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@
#include "mlir/Conversion/PDLToPDLInterp/PDLToPDLInterp.h"
#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
#include "mlir/Conversion/SCFToEmitC/SCFToEmitC.h"
#include "mlir/Conversion/SCFToGPU/SCFToGPUPass.h"
#include "mlir/Conversion/SCFToOpenMP/SCFToOpenMP.h"
#include "mlir/Conversion/SCFToSPIRV/SCFToSPIRVPass.h"
+10 −0
Original line number Diff line number Diff line
@@ -931,6 +931,16 @@ def ConvertParallelLoopToGpu : Pass<"convert-parallel-loops-to-gpu"> {
  let dependentDialects = ["affine::AffineDialect", "gpu::GPUDialect"];
}

//===----------------------------------------------------------------------===//
// SCFToEmitC
//===----------------------------------------------------------------------===//

def SCFToEmitC : Pass<"convert-scf-to-emitc"> {
  let summary = "Convert SCF dialect to EmitC dialect, maintaining structured"
                " control flow";
  let dependentDialects = ["emitc::EmitCDialect"];
}

//===----------------------------------------------------------------------===//
// ShapeToStandard
//===----------------------------------------------------------------------===//
+29 −0
Original line number Diff line number Diff line
//===- SCFToEmitC.h - SCF to EmitC Pass entrypoint --------------*- 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_SCFTOEMITC_SCFTOEMITC_H_
#define MLIR_CONVERSION_SCFTOEMITC_SCFTOEMITC_H_

#include <memory>

namespace mlir {
class Pass;
class RewritePatternSet;

#define GEN_PASS_DECL_SCFTOEMITC
#include "mlir/Conversion/Passes.h.inc"

/// Collect a set of patterns to convert SCF operations to the EmitC dialect.
void populateSCFToEmitCConversionPatterns(RewritePatternSet &patterns);

/// Creates a pass to convert SCF operations to the EmitC dialect.
std::unique_ptr<Pass> createConvertSCFToEmitCPass();

} // namespace mlir

#endif // MLIR_CONVERSION_SCFTOEMITC_SCFTOEMITC_H_
+8 −0
Original line number Diff line number Diff line
@@ -14,15 +14,23 @@
#define MLIR_DIALECT_EMITC_IR_EMITC_H

#include "mlir/Bytecode/BytecodeOpInterface.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/Interfaces/CastInterfaces.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"

#include "mlir/Dialect/EmitC/IR/EmitCDialect.h.inc"
#include "mlir/Dialect/EmitC/IR/EmitCEnums.h.inc"

namespace mlir {
namespace emitc {
void buildTerminatedBody(OpBuilder &builder, Location loc);
} // namespace emitc
} // namespace mlir

#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/EmitC/IR/EmitCAttributes.h.inc"

Loading