Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libsolidity/codegen/mlir/Sol/SolOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def Sol_DivOp : Sol_UncheckedIntArithOp<"div"> {
def Sol_ModOp : Sol_UncheckedIntArithOp<"mod"> {
// TODO: folder, canonicalizer
}
def Sol_ExpOp : Sol_UncheckedIntArithOp<"exp"> {
// TODO: folder, canonicalizer
}

def Sol_CmpOp : Sol_Op<"cmp", [Pure, SameTypeOperands]> {
let arguments = (ins Sol_CmpPredicateAttr:$predicate, Sol_Int:$lhs,
Expand Down
1 change: 1 addition & 0 deletions libsolidity/codegen/mlir/SolToStandardPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct ConvertSolToStandard
sol::CSubOp,
sol::CMulOp,
sol::CDivOp,
sol::ExpOp,
sol::AllocaOp,
sol::MallocOp,
sol::ArrayLitOp,
Expand Down
4 changes: 4 additions & 0 deletions libsolidity/codegen/mlir/SolidityToMLIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ mlir::Value SolidityToMLIRPass::genBinExpr(Token op, mlir::Value lhs,
return b.create<mlir::sol::CDivOp>(loc, lhs, rhs);
case Token::Mod:
return b.create<mlir::sol::ModOp>(loc, lhs, rhs);
case Token::Exp:
if (inUnchecked)
return b.create<mlir::sol::ExpOp>(loc, lhs, rhs);
break;
case Token::Equal:
return b.create<mlir::sol::CmpOp>(loc, mlir::sol::CmpPredicate::eq, lhs,
rhs);
Expand Down
5 changes: 3 additions & 2 deletions libsolidity/codegen/mlir/Target/EVM/SolToYul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ struct BytesCastOpLowering : public OpConversionPattern<sol::BytesCastOp> {
}
};

/// A templatized version of a conversion pattern for lowering add, sub and mul
/// ops.
/// A templatized version of a conversion pattern for lowering add, sub, mul
/// and exp ops.
template <typename SrcOpT, typename DstOpT>
struct ArithBinOpLowering : public OpConversionPattern<SrcOpT> {
using OpConversionPattern<SrcOpT>::OpConversionPattern;
Expand Down Expand Up @@ -2213,6 +2213,7 @@ void evm::populateArithPats(RewritePatternSet &pats, TypeConverter &tyConv) {
ArithBinOpLowering<sol::AddOp, arith::AddIOp>,
ArithBinOpLowering<sol::SubOp, arith::SubIOp>,
ArithBinOpLowering<sol::MulOp, arith::MulIOp>,
ArithBinOpLowering<sol::ExpOp, yul::ExpOp>,
DivOrModOpLowering<sol::DivOp, arith::DivSIOp, arith::DivUIOp>,
DivOrModOpLowering<sol::ModOp, arith::RemSIOp, arith::RemUIOp>,
CmpOpLowering>(tyConv, pats.getContext());
Expand Down
8 changes: 8 additions & 0 deletions libsolidity/codegen/mlir/Target/EVM/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ Value evm::Builder::genStoragePtr(Value addr, std::optional<Location> locArg) {
return b.create<LLVM::IntToPtrOp>(loc, storageAddrSpacePtrTy, addr);
}

Value evm::Builder::genTStoragePtr(Value addr, std::optional<Location> locArg) {
Location loc = locArg ? *locArg : defLoc;

auto tstorageAddrSpacePtrTy = LLVM::LLVMPointerType::get(
b.getContext(), evm::AddrSpace_TransientStorage);
return b.create<LLVM::IntToPtrOp>(loc, tstorageAddrSpacePtrTy, addr);
}

Value evm::Builder::genCodePtr(Value addr, std::optional<Location> locArg) {
Location loc = locArg ? *locArg : defLoc;

Expand Down
5 changes: 5 additions & 0 deletions libsolidity/codegen/mlir/Target/EVM/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ class Builder {
genStoragePtr(mlir::Value addr,
std::optional<mlir::Location> locArg = std::nullopt);

/// Generates a pointer to the address in the transient storage.
mlir::Value
genTStoragePtr(mlir::Value addr,
std::optional<mlir::Location> locArg = std::nullopt);

/// Generates a pointer to the address in the code.
mlir::Value genCodePtr(mlir::Value addr,
std::optional<mlir::Location> locArg = std::nullopt);
Expand Down
Loading
Loading