@@ -25,47 +25,6 @@ namespace mlir {
2525using namespace mlir ;
2626using namespace mlir ::func;
2727
28- static FuncOp createFnDecl (OpBuilder &b, SymbolOpInterface symTable,
29- StringRef name, FunctionType funcT, bool setPrivate,
30- SymbolTableCollection *symbolTables = nullptr ) {
31- OpBuilder::InsertionGuard g (b);
32- assert (!symTable->getRegion (0 ).empty () && " expected non-empty region" );
33- b.setInsertionPointToStart (&symTable->getRegion (0 ).front ());
34- FuncOp funcOp = FuncOp::create (b, symTable->getLoc (), name, funcT);
35- if (setPrivate)
36- funcOp.setPrivate ();
37- if (symbolTables) {
38- SymbolTable &symbolTable = symbolTables->getSymbolTable (symTable);
39- symbolTable.insert (funcOp, symTable->getRegion (0 ).front ().begin ());
40- }
41- return funcOp;
42- }
43-
44- // / Helper function to look up or create the symbol for a runtime library
45- // / function with the given parameter types. Returns an int64_t, unless a
46- // / different result type is specified.
47- static FailureOr<FuncOp>
48- lookupOrCreateApFloatFn (OpBuilder &b, SymbolOpInterface symTable,
49- StringRef name, TypeRange paramTypes,
50- SymbolTableCollection *symbolTables = nullptr ,
51- Type resultType = {}) {
52- if (!resultType)
53- resultType = IntegerType::get (symTable->getContext (), 64 );
54- std::string funcName = (llvm::Twine (" _mlir_apfloat_" ) + name).str ();
55- auto funcT = FunctionType::get (b.getContext (), paramTypes, {resultType});
56- FailureOr<FuncOp> func =
57- lookupFnDecl (symTable, funcName, funcT, symbolTables);
58- // Failed due to type mismatch.
59- if (failed (func))
60- return func;
61- // Successfully matched existing decl.
62- if (*func)
63- return *func;
64-
65- return createFnDecl (b, symTable, funcName, funcT,
66- /* setPrivate=*/ true , symbolTables);
67- }
68-
6928// / Helper function to look up or create the symbol for a runtime library
7029// / function for a binary arithmetic operation.
7130// /
@@ -81,8 +40,9 @@ lookupOrCreateBinaryFn(OpBuilder &b, SymbolOpInterface symTable, StringRef name,
8140 SymbolTableCollection *symbolTables = nullptr ) {
8241 auto i32Type = IntegerType::get (symTable->getContext (), 32 );
8342 auto i64Type = IntegerType::get (symTable->getContext (), 64 );
84- return lookupOrCreateApFloatFn (b, symTable, name, {i32Type, i64Type, i64Type},
85- symbolTables);
43+ std::string funcName = (llvm::Twine (" _mlir_apfloat_" ) + name).str ();
44+ return lookupOrCreateFn (b, symTable, funcName, {i32Type, i64Type, i64Type},
45+ symbolTables);
8646}
8747
8848static Value getSemanticsValue (OpBuilder &b, Location loc, FloatType floatTy) {
@@ -231,8 +191,9 @@ struct FpToFpConversion final : OpRewritePattern<OpTy> {
231191 // Get APFloat function from runtime library.
232192 auto i32Type = IntegerType::get (symTable->getContext (), 32 );
233193 auto i64Type = IntegerType::get (symTable->getContext (), 64 );
234- FailureOr<FuncOp> fn = lookupOrCreateApFloatFn (
235- rewriter, symTable, " convert" , {i32Type, i32Type, i64Type});
194+ FailureOr<FuncOp> fn =
195+ lookupOrCreateFn (rewriter, symTable, " _mlir_apfloat_convert" ,
196+ {i32Type, i32Type, i64Type});
236197 if (failed (fn))
237198 return fn;
238199
@@ -289,8 +250,8 @@ struct FpToIntConversion final : OpRewritePattern<OpTy> {
289250 auto i32Type = IntegerType::get (symTable->getContext (), 32 );
290251 auto i64Type = IntegerType::get (symTable->getContext (), 64 );
291252 FailureOr<FuncOp> fn =
292- lookupOrCreateApFloatFn (rewriter, symTable, " convert_to_int " ,
293- {i32Type, i32Type, i1Type, i64Type});
253+ lookupOrCreateFn (rewriter, symTable, " _mlir_apfloat_convert_to_int " ,
254+ {i32Type, i32Type, i1Type, i64Type});
294255 if (failed (fn))
295256 return fn;
296257
@@ -351,8 +312,8 @@ struct IntToFpConversion final : OpRewritePattern<OpTy> {
351312 auto i32Type = IntegerType::get (symTable->getContext (), 32 );
352313 auto i64Type = IntegerType::get (symTable->getContext (), 64 );
353314 FailureOr<FuncOp> fn =
354- lookupOrCreateApFloatFn (rewriter, symTable, " convert_from_int " ,
355- {i32Type, i32Type, i1Type, i64Type});
315+ lookupOrCreateFn (rewriter, symTable, " _mlir_apfloat_convert_from_int " ,
316+ {i32Type, i32Type, i1Type, i64Type});
356317 if (failed (fn))
357318 return fn;
358319
@@ -421,8 +382,8 @@ struct CmpFOpToAPFloatConversion final : OpRewritePattern<arith::CmpFOp> {
421382 auto i32Type = IntegerType::get (symTable->getContext (), 32 );
422383 auto i64Type = IntegerType::get (symTable->getContext (), 64 );
423384 FailureOr<FuncOp> fn =
424- lookupOrCreateApFloatFn (rewriter, symTable, " compare " ,
425- {i32Type, i64Type, i64Type}, nullptr , i8Type);
385+ lookupOrCreateFn (rewriter, symTable, " _mlir_apfloat_compare " ,
386+ {i32Type, i64Type, i64Type}, nullptr , i8Type);
426387 if (failed (fn))
427388 return fn;
428389
@@ -569,8 +530,8 @@ struct NegFOpToAPFloatConversion final : OpRewritePattern<arith::NegFOp> {
569530 // Get APFloat function from runtime library.
570531 auto i32Type = IntegerType::get (symTable->getContext (), 32 );
571532 auto i64Type = IntegerType::get (symTable->getContext (), 64 );
572- FailureOr<FuncOp> fn =
573- lookupOrCreateApFloatFn ( rewriter, symTable, " neg " , {i32Type, i64Type});
533+ FailureOr<FuncOp> fn = lookupOrCreateFn (
534+ rewriter, symTable, " _mlir_apfloat_neg " , {i32Type, i64Type});
574535 if (failed (fn))
575536 return fn;
576537
0 commit comments