MLIR
17.0.0git
|
#include "mlir/Conversion/MathToFuncs/MathToFuncs.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/Math/IR/Math.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Dialect/Vector/Utils/VectorUtils.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/TypeSwitch.h"
#include "mlir/Conversion/Passes.h.inc"
Go to the source code of this file.
Namespaces | |
mlir | |
This header declares functions that assit transformations in the MemRef dialect. | |
Macros | |
#define | GEN_PASS_DEF_CONVERTMATHTOFUNCS |
Functions | |
static FunctionType | getElementalFuncTypeForOp (Operation *op) |
static func::FuncOp | createElementIPowIFunc (ModuleOp *module, Type elementType) |
Create linkonce_odr function to implement the power function with the given elementType type inside module . More... | |
static func::FuncOp | createElementFPowIFunc (ModuleOp *module, FunctionType funcType) |
Create linkonce_odr function to implement the power function with the given funcType type inside module . More... | |
#define GEN_PASS_DEF_CONVERTMATHTOFUNCS |
Definition at line 27 of file MathToFuncs.cpp.
|
static |
Create linkonce_odr function to implement the power function with the given funcType
type inside module
.
The funcType
must be 'FloatType (*)(FloatType, IntegerType)' function type.
template <typename T> Tb __mlir_math_fpowi_*(Tb b, Tp p) { if (p == Tp{0}) return Tb{1}; bool isNegativePower{p < Tp{0}} bool isMin{p == std::numeric_limits<Tp>::min()}; if (isMin) { p = std::numeric_limits<Tp>::max(); } else if (isNegativePower) { p = -p; } Tb result = Tb{1}; Tb origBase = Tb{b}; while (true) { if (p & Tp{1}) result *= b; p >>= Tp{1}; if (p == Tp{0}) break; b *= b; } if (isMin) { result *= origBase; } if (isNegativePower) { result = Tb{1} / result; } return result; }
if (isNegativePower) { result = Tb{1} / result; }
Definition at line 390 of file MathToFuncs.cpp.
References mlir::ImplicitLocOpBuilder::atBlockEnd(), mlir::Type::cast(), mlir::Region::end(), mlir::Block::getArgument(), mlir::Block::getParent(), and mlir::FloatType::getWidth().
|
static |
Create linkonce_odr function to implement the power function with the given elementType
type inside module
.
The elementType
must be IntegerType, an the created function has 'IntegerType (*)(IntegerType, IntegerType)' function type.
template <typename T> T __mlir_math_ipowi_*(T b, T p) { if (p == T(0)) return T(1); if (p < T(0)) { if (b == T(0)) return T(1) / T(0); // trigger div-by-zero if (b == T(1)) return T(1); if (b == T(-1)) { if (p & T(1)) return T(-1); return T(1); } return T(0); } T result = T(1); while (true) { if (p & T(1)) result *= b; p >>= T(1); if (p == T(0)) return result; b *= b; } }
Definition at line 163 of file MathToFuncs.cpp.
References mlir::ImplicitLocOpBuilder::atBlockEnd(), mlir::ImplicitLocOpBuilder::create(), mlir::OpBuilder::createBlock(), mlir::Region::end(), mlir::Builder::getContext(), mlir::Builder::getIntegerAttr(), mlir::Type::getIntOrFloatBitWidth(), mlir::ImplicitLocOpBuilder::getLoc(), mlir::Block::getParent(), mlir::Type::isa(), and mlir::OpBuilder::setInsertionPointToEnd().
|
static |
Definition at line 120 of file MathToFuncs.cpp.
References mlir::Operation::getContext(), mlir::Operation::getNumOperands(), mlir::Operation::getNumResults(), mlir::Operation::operand_type_begin(), mlir::Operation::operand_type_end(), mlir::Operation::result_type_begin(), and mlir::Operation::result_type_end().