Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Dialect/Arithmetic/Utils/Utils.cpp
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | return llvm::to_vector<4>( | ||||
return getValueOrCreateConstantIndexOp(b, loc, value); | return getValueOrCreateConstantIndexOp(b, loc, value); | ||||
})); | })); | ||||
} | } | ||||
Value ArithBuilder::_and(Value lhs, Value rhs) { | Value ArithBuilder::_and(Value lhs, Value rhs) { | ||||
return b.create<arith::AndIOp>(loc, lhs, rhs); | return b.create<arith::AndIOp>(loc, lhs, rhs); | ||||
} | } | ||||
Value ArithBuilder::add(Value lhs, Value rhs) { | Value ArithBuilder::add(Value lhs, Value rhs) { | ||||
if (lhs.getType().isa<IntegerType>()) | if (lhs.getType().isa<FloatType>()) | ||||
return b.create<arith::AddIOp>(loc, lhs, rhs); | |||||
return b.create<arith::AddFOp>(loc, lhs, rhs); | return b.create<arith::AddFOp>(loc, lhs, rhs); | ||||
return b.create<arith::AddIOp>(loc, lhs, rhs); | |||||
} | |||||
Value ArithBuilder::sub(Value lhs, Value rhs) { | |||||
if (lhs.getType().isa<FloatType>()) | |||||
return b.create<arith::SubFOp>(loc, lhs, rhs); | |||||
return b.create<arith::SubIOp>(loc, lhs, rhs); | |||||
} | } | ||||
Value ArithBuilder::mul(Value lhs, Value rhs) { | Value ArithBuilder::mul(Value lhs, Value rhs) { | ||||
if (lhs.getType().isa<IntegerType>()) | if (lhs.getType().isa<FloatType>()) | ||||
return b.create<arith::MulIOp>(loc, lhs, rhs); | |||||
return b.create<arith::MulFOp>(loc, lhs, rhs); | return b.create<arith::MulFOp>(loc, lhs, rhs); | ||||
return b.create<arith::MulIOp>(loc, lhs, rhs); | |||||
} | } | ||||
Value ArithBuilder::sgt(Value lhs, Value rhs) { | Value ArithBuilder::sgt(Value lhs, Value rhs) { | ||||
if (lhs.getType().isa<IndexType, IntegerType>()) | if (lhs.getType().isa<FloatType>()) | ||||
return b.create<arith::CmpIOp>(loc, arith::CmpIPredicate::sgt, lhs, rhs); | |||||
return b.create<arith::CmpFOp>(loc, arith::CmpFPredicate::OGT, lhs, rhs); | return b.create<arith::CmpFOp>(loc, arith::CmpFPredicate::OGT, lhs, rhs); | ||||
return b.create<arith::CmpIOp>(loc, arith::CmpIPredicate::sgt, lhs, rhs); | |||||
} | } | ||||
Value ArithBuilder::slt(Value lhs, Value rhs) { | Value ArithBuilder::slt(Value lhs, Value rhs) { | ||||
if (lhs.getType().isa<IndexType, IntegerType>()) | if (lhs.getType().isa<FloatType>()) | ||||
return b.create<arith::CmpIOp>(loc, arith::CmpIPredicate::slt, lhs, rhs); | |||||
return b.create<arith::CmpFOp>(loc, arith::CmpFPredicate::OLT, lhs, rhs); | return b.create<arith::CmpFOp>(loc, arith::CmpFPredicate::OLT, lhs, rhs); | ||||
return b.create<arith::CmpIOp>(loc, arith::CmpIPredicate::slt, lhs, rhs); | |||||
} | } | ||||
Value ArithBuilder::select(Value cmp, Value lhs, Value rhs) { | Value ArithBuilder::select(Value cmp, Value lhs, Value rhs) { | ||||
return b.create<arith::SelectOp>(loc, cmp, lhs, rhs); | return b.create<arith::SelectOp>(loc, cmp, lhs, rhs); | ||||
} | } |