OpBuilder<(ins "Value":$v1, "Value":$v2, "ArrayAttr":$mask,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>];
let verifier = [{
- auto type1 = v1().getType();
- auto type2 = v2().getType();
+ auto type1 = getV1().getType();
+ auto type2 = getV2().getType();
if (::mlir::LLVM::getVectorElementType(type1) !=
::mlir::LLVM::getVectorElementType(type2))
return emitOpError("expected matching LLVM IR Dialect element types");
let arguments = (ins LLVM_Type:$value);
string llvmBuilder = [{ builder.CreateResume($value); }];
let verifier = [{
- if (!isa_and_nonnull<LandingpadOp>(value().getDefiningOp()))
+ if (!isa_and_nonnull<LandingpadOp>(getValue().getDefiningOp()))
return emitOpError("expects landingpad value as operand");
// No check for personality of function - landingpad op verifies it.
return success();
let extraClassDeclaration = [{
/// Return the operands for the case destination block at the given index.
OperandRange getCaseOperands(unsigned index) {
- return caseOperands()[index];
+ return getCaseOperands()[index];
}
/// Return a mutable range of operands for the case destination block at the
/// given index.
MutableOperandRange getCaseOperandsMutable(unsigned index) {
- return caseOperandsMutable()[index];
+ return getCaseOperandsMutable()[index];
}
}];
}
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs),
[{
build($_builder, $_state,
- LLVM::LLVMPointerType::get(global.getType(), global.addr_space()),
- global.sym_name());
+ LLVM::LLVMPointerType::get(global.getType(), global.getAddrSpace()),
+ global.getSymName());
$_state.addAttributes(attrs);
}]>,
OpBuilder<(ins "LLVMFuncOp":$func,
}
/// Return the initializer attribute if it exists, or a null attribute.
Attribute getValueOrNull() {
- return value().getValueOr(Attribute());
+ return getValue().getValueOr(Attribute());
}
/// Return the initializer region. This may be empty, but if it is not it
/// terminates in an `llvm.return` op with the initializer value.
let methods = [
InterfaceMethod<"Get fastmath flags", "::mlir::LLVM::FastmathFlags",
- "fastmathFlags">,
+ "getFastmathFlags">,
];
}
let extraClassDeclaration = [{
MemRefType getMemRefType() {
- return memref().getType().cast<MemRefType>();
+ return getMemref().getType().cast<MemRefType>();
}
}];
}
return getRegion().getArgument(0);
}
MemRefType getMemRefType() {
- return memref().getType().cast<MemRefType>();
+ return getMemref().getType().cast<MemRefType>();
}
}];
}
/// Erase the operand at 'index' from the true operand list.
void eraseTrueOperand(unsigned index) {
- trueDestOperandsMutable().erase(index);
+ getTrueDestOperandsMutable().erase(index);
}
// Accessors for operands to the 'false' destination.
/// Erase the operand at 'index' from the false operand list.
void eraseFalseOperand(unsigned index) {
- falseDestOperandsMutable().erase(index);
+ getFalseDestOperandsMutable().erase(index);
}
private:
let extraClassDeclaration = [{
/// Return the operands for the case destination block at the given index.
OperandRange getCaseOperands(unsigned index) {
- return caseOperands()[index];
+ return getCaseOperands()[index];
}
/// Return a mutable range of operands for the case destination block at the
/// given index.
MutableOperandRange getCaseOperandsMutable(unsigned index) {
- return caseOperandsMutable()[index];
+ return getCaseOperandsMutable()[index];
}
}];
#define DISPATCH(cmpPredicate, spirvOp) \
case cmpPredicate: \
rewriter.replaceOpWithNewOp<spirvOp>(op, op.getResult().getType(), \
- adaptor.lhs(), adaptor.rhs()); \
+ adaptor.getLhs(), adaptor.getRhs()); \
return success();
DISPATCH(arith::CmpIPredicate::eq, spirv::LogicalEqualOp);
"bitwidth emulation is not implemented yet on unsigned op"); \
} \
rewriter.replaceOpWithNewOp<spirvOp>(op, op.getResult().getType(), \
- adaptor.lhs(), adaptor.rhs()); \
+ adaptor.getLhs(), adaptor.getRhs()); \
return success();
DISPATCH(arith::CmpIPredicate::eq, spirv::IEqualOp);
#define DISPATCH(cmpPredicate, spirvOp) \
case cmpPredicate: \
rewriter.replaceOpWithNewOp<spirvOp>(op, op.getResult().getType(), \
- adaptor.lhs(), adaptor.rhs()); \
+ adaptor.getLhs(), adaptor.getRhs()); \
return success();
// Ordered.
LogicalResult
matchAndRewrite(math::ExpM1Op op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
- auto operandType = adaptor.operand().getType();
+ auto operandType = adaptor.getOperand().getType();
if (!operandType || !LLVM::isCompatibleType(operandType))
return failure();
} else {
one = rewriter.create<LLVM::ConstantOp>(loc, operandType, floatOne);
}
- auto exp = rewriter.create<LLVM::ExpOp>(loc, adaptor.operand());
+ auto exp = rewriter.create<LLVM::ExpOp>(loc, adaptor.getOperand());
rewriter.replaceOpWithNewOp<LLVM::FSubOp>(op, operandType, exp, one);
return success();
}
LogicalResult
matchAndRewrite(math::Log1pOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
- auto operandType = adaptor.operand().getType();
+ auto operandType = adaptor.getOperand().getType();
if (!operandType || !LLVM::isCompatibleType(operandType))
return rewriter.notifyMatchFailure(op, "unsupported operand type");
: rewriter.create<LLVM::ConstantOp>(loc, operandType, floatOne);
auto add = rewriter.create<LLVM::FAddOp>(loc, operandType, one,
- adaptor.operand());
+ adaptor.getOperand());
rewriter.replaceOpWithNewOp<LLVM::LogOp>(op, operandType, add);
return success();
}
LogicalResult
matchAndRewrite(math::RsqrtOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
- auto operandType = adaptor.operand().getType();
+ auto operandType = adaptor.getOperand().getType();
if (!operandType || !LLVM::isCompatibleType(operandType))
return failure();
} else {
one = rewriter.create<LLVM::ConstantOp>(loc, operandType, floatOne);
}
- auto sqrt = rewriter.create<LLVM::SqrtOp>(loc, adaptor.operand());
+ auto sqrt = rewriter.create<LLVM::SqrtOp>(loc, adaptor.getOperand());
rewriter.replaceOpWithNewOp<LLVM::FDivOp>(op, operandType, one, sqrt);
return success();
}
assert(adaptor.getOperands().size() == 1);
Location loc = operation.getLoc();
auto type =
- this->getTypeConverter()->convertType(operation.operand().getType());
+ this->getTypeConverter()->convertType(operation.getOperand().getType());
auto one = spirv::ConstantOp::getOne(type, operation.getLoc(), rewriter);
auto onePlus =
rewriter.create<spirv::FAddOp>(loc, one, adaptor.getOperands()[0]);
/// scf.reduce.return %1
template <
typename CompareOpTy, typename SelectOpTy,
- typename Predicate = decltype(std::declval<CompareOpTy>().predicate())>
+ typename Predicate = decltype(std::declval<CompareOpTy>().getPredicate())>
static bool
matchSelectReduction(Block &block, ArrayRef<Predicate> lessThanPredicates,
ArrayRef<Predicate> greaterThanPredicates, bool &isMin) {
LogicalResult matchAndRewrite(arith::CeilDivUIOp op,
PatternRewriter &rewriter) const final {
Location loc = op.getLoc();
- Value a = op.lhs();
- Value b = op.rhs();
+ Value a = op.getLhs();
+ Value b = op.getRhs();
Value zero = rewriter.create<arith::ConstantOp>(
loc, rewriter.getIntegerAttr(a.getType(), 0));
Value compare =
LogicalResult
GlobalCtorsOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
- for (Attribute ctor : ctors()) {
+ for (Attribute ctor : getCtors()) {
if (failed(verifySymbolAttrUse(ctor.cast<FlatSymbolRefAttr>(), *this,
symbolTable)))
return failure();
}
static LogicalResult verify(GlobalCtorsOp op) {
- if (op.ctors().size() != op.priorities().size())
+ if (op.getCtors().size() != op.getPriorities().size())
return op.emitError(
"mismatch between the number of ctors and the number of priorities");
return success();
LogicalResult
GlobalDtorsOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
- for (Attribute dtor : dtors()) {
+ for (Attribute dtor : getDtors()) {
if (failed(verifySymbolAttrUse(dtor.cast<FlatSymbolRefAttr>(), *this,
symbolTable)))
return failure();
}
static LogicalResult verify(GlobalDtorsOp op) {
- if (op.dtors().size() != op.priorities().size())
+ if (op.getDtors().size() != op.getPriorities().size())
return op.emitError(
"mismatch between the number of dtors and the number of priorities");
return success();
PowFStrengthReduction::matchAndRewrite(math::PowFOp op,
PatternRewriter &rewriter) const {
Location loc = op.getLoc();
- Value x = op.lhs();
+ Value x = op.getLhs();
FloatAttr scalarExponent;
DenseFPElementsAttr vectorExponent;
- bool isScalar = matchPattern(op.rhs(), m_Constant(&scalarExponent));
- bool isVector = matchPattern(op.rhs(), m_Constant(&vectorExponent));
+ bool isScalar = matchPattern(op.getRhs(), m_Constant(&scalarExponent));
+ bool isVector = matchPattern(op.getRhs(), m_Constant(&vectorExponent));
// Returns true if exponent is a constant equal to `value`.
auto isExponentValue = [&](double value) -> bool {
/// 1) 1-exp^{-2x} / 1+exp^{-2x}, if x => 0
/// 2) exp^{2x}-1 / exp^{2x}+1 , if x < 0
static LogicalResult convertTanhOp(math::TanhOp op, PatternRewriter &rewriter) {
- auto floatType = op.operand().getType();
+ auto floatType = op.getOperand().getType();
Location loc = op.getLoc();
auto floatOne = rewriter.getFloatAttr(floatType, 1.0);
auto floatTwo = rewriter.getFloatAttr(floatType, 2.0);
Value one = rewriter.create<arith::ConstantOp>(loc, floatOne);
Value two = rewriter.create<arith::ConstantOp>(loc, floatTwo);
- Value doubledX = rewriter.create<arith::MulFOp>(loc, op.operand(), two);
+ Value doubledX = rewriter.create<arith::MulFOp>(loc, op.getOperand(), two);
// Case 1: tanh(x) = 1-exp^{-2x} / 1+exp^{-2x}
Value negDoubledX = rewriter.create<arith::NegFOp>(loc, doubledX);
auto floatZero = rewriter.getFloatAttr(floatType, 0.0);
Value zero = rewriter.create<arith::ConstantOp>(loc, floatZero);
Value cmpRes = rewriter.create<arith::CmpFOp>(loc, arith::CmpFPredicate::OGE,
- op.operand(), zero);
+ op.getOperand(), zero);
rewriter.replaceOpWithNewOp<SelectOp>(op, cmpRes, positiveRes, negativeRes);
return success();
}
LogicalResult
TanhApproximation::matchAndRewrite(math::TanhOp op,
PatternRewriter &rewriter) const {
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
auto bcast = [&](Value value) -> Value {
// Clamp operand into [plusClamp, minusClamp] range.
Value minusClamp = bcast(f32Cst(builder, -7.99881172180175781f));
Value plusClamp = bcast(f32Cst(builder, 7.99881172180175781f));
- Value x = clamp(builder, op.operand(), minusClamp, plusClamp);
+ Value x = clamp(builder, op.getOperand(), minusClamp, plusClamp);
// Mask for tiny values that are approximated with `operand`.
Value tiny = bcast(f32Cst(builder, 0.0004f));
Value tinyMask = builder.create<arith::CmpFOp>(
- arith::CmpFPredicate::OLT, builder.create<math::AbsOp>(op.operand()),
+ arith::CmpFPredicate::OLT, builder.create<math::AbsOp>(op.getOperand()),
tiny);
// The monomial coefficients of the numerator polynomial (odd).
LogicalResult
LogApproximationBase<Op>::logMatchAndRewrite(Op op, PatternRewriter &rewriter,
bool base2) const {
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
auto bcast = [&](Value value) -> Value {
Value cstCephesLogP7 = bcast(f32Cst(builder, -2.4999993993E-1f));
Value cstCephesLogP8 = bcast(f32Cst(builder, +3.3333331174E-1f));
- Value x = op.operand();
+ Value x = op.getOperand();
// Truncate input values to the minimum positive normal.
x = max(builder, x, cstMinNormPos);
}
Value invalidMask = builder.create<arith::CmpFOp>(arith::CmpFPredicate::ULT,
- op.operand(), cstZero);
+ op.getOperand(), cstZero);
Value zeroMask = builder.create<arith::CmpFOp>(arith::CmpFPredicate::OEQ,
- op.operand(), cstZero);
+ op.getOperand(), cstZero);
Value posInfMask = builder.create<arith::CmpFOp>(arith::CmpFPredicate::OEQ,
- op.operand(), cstPosInf);
+ op.getOperand(), cstPosInf);
// Filter out invalid values:
// • x == 0 -> -INF
LogicalResult
Log1pApproximation::matchAndRewrite(math::Log1pOp op,
PatternRewriter &rewriter) const {
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
auto bcast = [&](Value value) -> Value {
// ^^^^^^^^^^^^^^^^^^^^^^
// "logLarge" below.
Value cstOne = bcast(f32Cst(builder, 1.0f));
- Value x = op.operand();
+ Value x = op.getOperand();
Value u = builder.create<arith::AddFOp>(x, cstOne);
Value uSmall =
builder.create<arith::CmpFOp>(arith::CmpFPredicate::OEQ, u, cstOne);
LogicalResult
ErfPolynomialApproximation::matchAndRewrite(math::ErfOp op,
PatternRewriter &rewriter) const {
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
auto bcast = [&](Value value) -> Value {
bounds[2] = bcast(f32Cst(builder, 3.75f));
Value isNegativeArg = builder.create<arith::CmpFOp>(arith::CmpFPredicate::OLT,
- op.operand(), zero);
- Value negArg = builder.create<arith::NegFOp>(op.operand());
- Value x = builder.create<SelectOp>(isNegativeArg, negArg, op.operand());
+ op.getOperand(), zero);
+ Value negArg = builder.create<arith::NegFOp>(op.getOperand());
+ Value x = builder.create<SelectOp>(isNegativeArg, negArg, op.getOperand());
Value offset = offsets[0];
Value p[polyDegree + 1];
LogicalResult
ExpApproximation::matchAndRewrite(math::ExpOp op,
PatternRewriter &rewriter) const {
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
Value cstCephesExpP4 = bcast(f32Cst(builder, 0.03668965196652099192f));
Value cstCephesExpP5 = bcast(f32Cst(builder, 0.01314350012789660196f));
- Value x = op.operand();
+ Value x = op.getOperand();
// Reduced y = x - floor(x / ln(2)) * ln(2) = x - k * ln(2)
Value xL2Inv = mul(x, cstLog2E);
LogicalResult
ExpM1Approximation::matchAndRewrite(math::ExpM1Op op,
PatternRewriter &rewriter) const {
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
auto bcast = [&](Value value) -> Value {
// and when the input is ~= -inf, i.e. u - 1 ~= -1.
Value cstOne = bcast(f32Cst(builder, 1.0f));
Value cstNegOne = bcast(f32Cst(builder, -1.0f));
- Value x = op.operand();
+ Value x = op.getOperand();
Value u = builder.create<math::ExpOp>(x);
Value uEqOne =
builder.create<arith::CmpFOp>(arith::CmpFPredicate::OEQ, u, cstOne);
llvm::is_one_of<OpTy, math::SinOp, math::CosOp>::value,
"SinAndCosApproximation pattern expects math::SinOp or math::CosOp");
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
auto bcast = [&](Value value) -> Value {
Value twoOverPi = bcast(f32Cst(builder, TWO_OVER_PI));
Value piOverTwo = bcast(f32Cst(builder, PI_OVER_2));
- Value x = op.operand();
+ Value x = op.getOperand();
Value k = floor(mul(x, twoOverPi));
LogicalResult
RsqrtApproximation::matchAndRewrite(math::RsqrtOp op,
PatternRewriter &rewriter) const {
- if (!getElementTypeOrSelf(op.operand()).isF32())
+ if (!getElementTypeOrSelf(op.getOperand()).isF32())
return rewriter.notifyMatchFailure(op, "unsupported operand type");
- ArrayRef<int64_t> shape = vectorShape(op.operand());
+ ArrayRef<int64_t> shape = vectorShape(op.getOperand());
// Only support already-vectorized rsqrt's.
if (shape.empty() || shape.back() % 8 != 0)
Value cstNegHalf = bcast(f32Cst(builder, -0.5f));
Value cstMinNormPos = bcast(f32FromBits(builder, 0x00800000u));
- Value negHalf = builder.create<arith::MulFOp>(op.operand(), cstNegHalf);
+ Value negHalf = builder.create<arith::MulFOp>(op.getOperand(), cstNegHalf);
// Select only the inverse sqrt of positive normals (denormals are
// flushed to zero).
- Value ltMinMask = builder.create<arith::CmpFOp>(arith::CmpFPredicate::OLT,
- op.operand(), cstMinNormPos);
+ Value ltMinMask = builder.create<arith::CmpFOp>(
+ arith::CmpFPredicate::OLT, op.getOperand(), cstMinNormPos);
Value infMask = builder.create<arith::CmpFOp>(arith::CmpFPredicate::OEQ,
- op.operand(), cstPosInf);
+ op.getOperand(), cstPosInf);
Value notNormalFiniteMask = builder.create<arith::OrIOp>(ltMinMask, infMask);
// Compute an approximate result.
// clang-format on
};
llvm::FastMathFlags ret;
- auto fmf = op.fastmathFlags();
+ auto fmf = op.getFastmathFlags();
for (auto it : handlers)
if (bitEnumContains(fmf, it.first))
(ret.*(it.second))(true);
auto dtorOp = dyn_cast<GlobalDtorsOp>(op);
if (!ctorOp && !dtorOp)
continue;
- auto range = ctorOp ? llvm::zip(ctorOp.ctors(), ctorOp.priorities())
- : llvm::zip(dtorOp.dtors(), dtorOp.priorities());
+ auto range = ctorOp ? llvm::zip(ctorOp.getCtors(), ctorOp.getPriorities())
+ : llvm::zip(dtorOp.getDtors(), dtorOp.getPriorities());
auto appendGlobalFn =
ctorOp ? llvm::appendToGlobalCtors : llvm::appendToGlobalDtors;
for (auto symbolAndPriority : range) {
llvm::raw_string_ostream bs(builder);
while (auto loc = findNextVariable(builderStrRef)) {
auto name = loc.in(builderStrRef).drop_front();
+ auto getterName = op.getGetterName(name);
// First, insert the non-matched part as is.
bs << builderStrRef.substr(0, loc.pos);
// Then, rewrite the name based on its kind.
if (isOperandName(op, name)) {
auto result =
isVariadicOperand
- ? formatv("moduleTranslation.lookupValues(op.{0}())", name)
- : formatv("moduleTranslation.lookupValue(op.{0}())", name);
+ ? formatv("moduleTranslation.lookupValues(op.{0}())", getterName)
+ : formatv("moduleTranslation.lookupValue(op.{0}())", getterName);
bs << result;
} else if (isAttributeName(op, name)) {
- bs << formatv("op.{0}()", name);
+ bs << formatv("op.{0}()", getterName);
} else if (isResultName(op, name)) {
- bs << formatv("moduleTranslation.mapValue(op.{0}())", name);
+ bs << formatv("moduleTranslation.mapValue(op.{0}())", getterName);
} else if (name == "_resultType") {
bs << "moduleTranslation.convertType(op.getResult().getType())";
} else if (name == "_hasResult") {