[Mlir-commits] [mlir] 1ebf7ce - [mlir] Use interfaces in MathToLibm

Tres Popp llvmlistbot at llvm.org
Tue Jun 1 04:56:51 PDT 2021


Author: Tres Popp
Date: 2021-06-01T13:56:32+02:00
New Revision: 1ebf7ce950bb72599055d2f2789fd604a02b6d15

URL: https://github.com/llvm/llvm-project/commit/1ebf7ce950bb72599055d2f2789fd604a02b6d15
DIFF: https://github.com/llvm/llvm-project/commit/1ebf7ce950bb72599055d2f2789fd604a02b6d15.diff

LOG: [mlir] Use interfaces in MathToLibm

Previously, this assumed use of ModuleOp and FuncOp. There is no need to
restrict this, and using interfaces allows these patterns to be used
during dialect conversion to LLVM.

Some assertions were removed due to inconsistent implementation of
FunctionLikeOps.

Differential Revision: https://reviews.llvm.org/D103447

Added: 
    

Modified: 
    mlir/lib/Conversion/MathToLibm/MathToLibm.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp b/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
index 8512432681c24..7b71386a52942 100644
--- a/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
+++ b/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
@@ -81,30 +81,30 @@ template <typename Op>
 LogicalResult
 ScalarOpToLibmCall<Op>::matchAndRewrite(Op op,
                                         PatternRewriter &rewriter) const {
-  auto module = op->template getParentOfType<ModuleOp>();
+  auto module = SymbolTable::getNearestSymbolTable(op);
   auto type = op.getType();
   // TODO: Support Float16 by upcasting to Float32
   if (!type.template isa<Float32Type, Float64Type>())
     return failure();
 
   auto name = type.getIntOrFloatBitWidth() == 64 ? doubleFunc : floatFunc;
-  auto opFunc = module.template lookupSymbol<FuncOp>(name);
+  auto opFunc = dyn_cast_or_null<SymbolOpInterface>(
+      SymbolTable::lookupSymbolIn(module, name));
   // Forward declare function if it hasn't already been
   if (!opFunc) {
     OpBuilder::InsertionGuard guard(rewriter);
-    rewriter.setInsertionPointToStart(module.getBody());
+    rewriter.setInsertionPointToStart(&module->getRegion(0).front());
     auto opFunctionTy = FunctionType::get(
         rewriter.getContext(), op->getOperandTypes(), op->getResultTypes());
     opFunc =
         rewriter.create<FuncOp>(rewriter.getUnknownLoc(), name, opFunctionTy);
     opFunc.setPrivate();
   }
-  assert(opFunc.getType().template cast<FunctionType>().getResults() ==
-         op->getResultTypes());
-  assert(opFunc.getType().template cast<FunctionType>().getInputs() ==
-         op->getOperandTypes());
+  assert(SymbolTable::lookupSymbolIn(module, name)
+             ->template hasTrait<mlir::OpTrait::FunctionLike>());
 
-  rewriter.replaceOpWithNewOp<CallOp>(op, opFunc, op->getOperands());
+  rewriter.replaceOpWithNewOp<CallOp>(op, name, op.getType(),
+                                      op->getOperands());
 
   return success();
 }


        


More information about the Mlir-commits mailing list