⚙ D110797 [MLIR] Replace std ops with arith dialect ops is about to land/just landed, which moved the following ops from the Standard Dialect:
MLIR asm | C++ |
---|---|
addi → arith.addi
|
AddIOp → arith::AddIOp
|
subi → arith.subi
|
SubIOp → arith::SubIOp
|
muli → arith.muli
|
MulIOp → arith::MulIOp
|
divi_unsigned → arith.divui
|
UnsignedDivIOp → arith::DivUIOp
|
divi_signed → arith.divsi
|
SignedDivIOp → arith::DivSIOp
|
ceildivi_signed → arith.ceildivsi
|
SignedCeilDivIOp → arith::CeilDivSIOp
|
floordivi_signed → arith.floordivsi
|
SignedFloorDivIOp → arith::FloorDivSIOp
|
remi_unsigned → arith.remui
|
UnsignedRemIOp → arith::RemUIOp
|
remi_signed → arith.remsi
|
SignedRemIOp → arith::RemSIOp
|
and → arith.andi
|
AndOp → arith::AndIOp
|
or → arith.ori
|
OrOp → arith::OrIOp
|
xor → arith.xori
|
XOrOp → arith::XOrIOp
|
shift_left → arith.shli
|
ShiftLeftOp → arith::ShLIOp
|
shift_right_unsigned → arith.shrui
|
UnsignedShiftRightOp → arith::ShRUIOp
|
shift_right_signed → arith.shrsi
|
SignedShiftRightOp → arith::ShRSIOp
|
negf → arith.negf
|
NegFOp → arith::NegFOp
|
addf → arith.addf
|
AddFOp → arith::AddFOp
|
subf → arith.subf
|
SubFOp → arith::SubFOp
|
mulf → arith.mulf
|
MulFOp → arith::MulFOp
|
divf → arith.divf
|
DivFOp → arith::DivFOp
|
remf → arith.remf
|
RemFOp → arith::RemFOp
|
zexti → arith.extui
|
ZeroExtendIOp → arith::ExtUIOp
|
sexti → arith.extsi
|
SignExtendIOp → arith::ExtSIOp
|
fpext → arith.extf
|
FPExtOp → arith::ExtFOp
|
trunci → arith.trunci
|
TruncateIOp → arith::TruncIOp
|
fptrunc → arith.truncf
|
FPTruncOp → arith::TruncFOp
|
uitofp → arith.uitofp
|
UIToFPOp → arith::UIToFPOp
|
sitofp → arith.sitofp
|
SIToFPOp → arith::SIToFPOp
|
fptoui → arith.fptoui
|
FPToUIOp → arith::FPToUIOp
|
fptosi → arith.fptosi
|
FPToSIOp → arith::FPToSIOp
|
index_cast → arith.index_cast
|
IndexCastOp → arith::IndexCastOp
|
bitcast → arith.bitcast
|
BitcastOp → arith::BitcastOp
|
cmpi → arith.cmpi
|
CmpIOp → arith::CmpIOp
|
cmpf → arith.cmpf
|
CmpFOp → arith::CmpFOp
|
absf → math.abs
|
AbsFOp → math::AbsOp
|
ceilf → math.ceil
|
CeilFOp → math::CeilOp
|
floorf → math.floor
|
FloorFOp → math::FloorOp
|
copysign → math.copysign
|
CopySignOp → math::CopySignOp
|
fmaf → math.fma
|
FmaFOp → math::FmaOp
|
ConstantOp
remains in Standard. However, it can no longer be used to create integers, floats, vectors, or tensors. These are now created using arith::ConstantOp
or arith.constant
. std.constant
will continue to be used to create complex constants, function references, etc. ConstantIntOp
, ConstantFloatOp
, and ConstantIndexOp
are also under arith::
namespace.
Dependencies
Any users of MLIRStandardTo*
will also need to depend on MLIRArithmeticTo*
and call populateArithmeticTo*
to include the moved patterns. Users of StandardOpsDialect
will most likely need to depend on ArithmeticDialect
if they use the moved ops.
Script
I used the following script to help with renaming:
declare -A ops_cpp=(
[arith::ConstantIndexOp]=ConstantIndexOp
[arith::ConstantIntOp]=ConstantIntOp
[arith::ConstantFloatOp]=ConstantFloatOp
[arith::AddIOp]=AddIOp
[arith::SubIOp]=SubIOp
[arith::MulIOp]=MulIOp
[arith::DivUIOp]=UnsignedDivIOp
[arith::DivSIOp]=SignedDivIOp
[arith::CeilDivSIOp]=SignedCeilDivIOp
[arith::FloorDivSIOp]=SignedFloorDivIOp
[arith::RemUIOp]=UnsignedRemIOp
[arith::RemSIOp]=SignedRemIOp
[arith::AndIOp]=AndOp
[arith::OrIOp]=OrOp
[arith::XOrIOp]=XOrOp
[arith::ShLIOp]=ShiftLeftOp
[arith::ShRUIOp]=UnsignedShiftRightOp
[arith::ShRSIOp]=SignedShiftRightOp
[arith::NegFOp]=NegFOp
[arith::AddFOp]=AddFOp
[arith::SubFOp]=SubFOp
[arith::MulFOp]=MulFOp
[arith::DivFOp]=DivFOp
[arith::RemFOp]=RemFOp
[arith::ExtUIOp]=ZeroExtendIOp
[arith::ExtSIOp]=SignExtendIOp
[arith::ExtFOp]=FPExtOp
[arith::TruncIOp]=TruncateIOp
[arith::TruncFOp]=FPTruncOp
[arith::UIToFPOp]=UIToFPOp
[arith::SIToFPOp]=SIToFPOp
[arith::FPToUIOp]=FPToUIOp
[arith::FPToSIOp]=FPToSIOp
[arith::IndexCastOp]=IndexCastOp
[arith::BitcastOp]=BitcastOp
[arith::CmpIOp]=CmpIOp
[arith::CmpFOp]=CmpFOp
[math::AbsOp]=AbsFOp
[math::CeilOp]=CeilFOp
[math::FloorOp]=FloorFOp
[math::CopySignOp]=CopySignOp
[math::FmaOp]=FmaFOp
[arith::CmpIPredicate]=CmpIPredicate
[arith::CmpFPredicate]=CmpFPredicate
)
declare -A ops_mlir=(
[arith.addi]=addi
[arith.subi]=subi
[arith.muli]=muli
[arith.divui]=divi_unsigned
[arith.divsi]=divi_signed
[arith.ceildivsi]=ceildivi_signed
[arith.floordivsi]=floordivi_signed
[arith.remui]=remi_unsigned
[arith.remsi]=remi_signed
[arith.andi]=and
[arith.ori]=or
[arith.xori]=xor
[arith.shli]=shift_left
[arith.shrui]=shift_right_unsigned
[arith.shrsi]=shift_right_signed
[arith.negf]=negf
[arith.addf]=addf
[arith.subf]=subf
[arith.mulf]=mulf
[arith.divf]=divf
[arith.remf]=remf
[arith.extui]=zexti
[arith.extsi]=sexti
[arith.extf]=fpext
[arith.trunci]=trunci
[arith.truncf]=fptrunc
[arith.uitofp]=uitofp
[arith.sitofp]=sitofp
[arith.fptoui]=fptoui
[arith.fptosi]=fptosi
[arith.index_cast]=index_cast
[arith.bitcast]=bitcast
[arith.cmpi]=cmpi
[arith.cmpf]=cmpf
[math.abs]=absf
[math.ceil]=ceilf
[math.floor]=floorf
[math.copysign]=copysign
[math.fma]=fmaf
)
replace_all_cpp() {
for i in "${!ops_cpp@]}"; do
j=${ops_cpp[$i]}
lookup="(?<!::)\b$j\b"
grep -P "$lookup" -r $1 | xargs -n 4 -P 4 perl -i -pe "s/$lookup/$i/g"
lookup="(?<!::)\b$jAdaptor\b"
grep -P "$lookup" -r $1 | xargs -n 4 -P 4 perl -i -pe "s/$lookup/$iAdaptor/g"
lookup="mlir::\b$j\b"
grep -P "$lookup" -r $1 | xargs -n 4 -P 4 perl -i -pe "s/$lookup/mlir::$i/g"
done
}
replace_all_mlir() {
for i in "${!ops_mlir[@]}"; do
j=${ops_mlir[$i]}
lookup=" = \b$j\b "
grep -P "$lookup" -r $1 | xargs -n 4 -P 4 perl -i -pe "s/$lookup/ = $i /g"
lookup=" = \b$j\b$"
grep -P "$lookup" -r $1 | xargs -n 4 -P 4 perl -i -pe "s/$lookup/ = $i/g"
done
grep -P "$lookup" -r $1 | xargs -n 4 -P 4 perl -i -pe 's/ = constant (?!\[\"u@)/ = arith.constant /g'
}