Skip to content

Array const vararg fpneg fpext trunc roundtrip #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
42 changes: 42 additions & 0 deletions jlm/mlir/backend/JlmToMlirConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ JlmToMlirConverter::ConvertSimpleNode(
MlirOp =
Builder_->create<::mlir::arith::ConstantFloatOp>(Builder_->getUnknownLoc(), value, size);
}
else if (auto arrOp = dynamic_cast<const llvm::ConstantDataArray *>(&operation))
{
auto arrayType = ConvertType(*arrOp->result(0));
MlirOp = Builder_->create<::mlir::jlm::ConstantDataArray>(
Builder_->getUnknownLoc(),
arrayType,
inputs);
}
else if (auto zeroOp = dynamic_cast<const llvm::ConstantAggregateZero *>(&operation))
{
auto type = ConvertType(*zeroOp->result(0));
MlirOp = Builder_->create<::mlir::LLVM::ZeroOp>(Builder_->getUnknownLoc(), type);
}
else if (jlm::rvsdg::is<const rvsdg::bitbinary_op>(operation))
{
MlirOp = ConvertBitBinaryNode(operation, inputs);
Expand All @@ -377,6 +390,17 @@ JlmToMlirConverter::ConvertSimpleNode(
{
MlirOp = ConvertFpBinaryNode(*fpBinOp, inputs);
}
else if (rvsdg::is<const jlm::llvm::FNegOperation>(operation))
{
MlirOp = Builder_->create<::mlir::arith::NegFOp>(Builder_->getUnknownLoc(), inputs[0]);
}
else if (auto fpextOp = dynamic_cast<const jlm::llvm::FPExtOperation *>(&operation))
{
MlirOp = Builder_->create<::mlir::arith::ExtFOp>(
Builder_->getUnknownLoc(),
ConvertType(*fpextOp->result(0)),
inputs[0]);
}

else if (jlm::rvsdg::is<const rvsdg::bitcompare_op>(operation))
{
Expand All @@ -403,6 +427,13 @@ JlmToMlirConverter::ConvertSimpleNode(
ConvertType(*sitofpOp->result(0)),
inputs[0]);
}
else if (auto truncOp = dynamic_cast<const jlm::llvm::TruncOperation *>(&operation))
{
MlirOp = Builder_->create<::mlir::arith::TruncIOp>(
Builder_->getUnknownLoc(),
ConvertType(*truncOp->result(0)),
inputs[0]);
}
// ** region structural nodes **
else if (auto ctlOp = dynamic_cast<const rvsdg::ctlconstant_op *>(&operation))
{
Expand All @@ -411,6 +442,13 @@ JlmToMlirConverter::ConvertSimpleNode(
ConvertType(node.output(0)->type()), // Control, ouput type
ctlOp->value().alternative());
}
else if (auto vaOp = dynamic_cast<const llvm::valist_op *>(&operation))
{
MlirOp = Builder_->create<::mlir::jlm::CreateVarArgList>(
Builder_->getUnknownLoc(),
ConvertType(*vaOp->result(0)),
inputs);
}
else if (auto undefOp = dynamic_cast<const llvm::UndefValueOperation *>(&operation))
{
MlirOp = Builder_->create<::mlir::jlm::Undef>(
Expand Down Expand Up @@ -731,6 +769,10 @@ JlmToMlirConverter::ConvertType(const rvsdg::Type & type)
ConvertType(arrayType->element_type()),
arrayType->nelements());
}
else if (rvsdg::is<const llvm::VariableArgumentType>(type))
{
return Builder_->getType<::mlir::jlm::VarargListType>();
}
else
{
auto message = util::strfmt("Type conversion not implemented: ", type.debug_string());
Expand Down
55 changes: 55 additions & 0 deletions jlm/mlir/frontend/MlirToJlmConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,38 @@ MlirToJlmConverter::ConvertOperation(
return &output;
}

else if (auto negOp = ::mlir::dyn_cast<::mlir::arith::NegFOp>(&mlirOperation))
{
auto type = negOp.getResult().getType();
auto floatType = ::mlir::cast<::mlir::FloatType>(type);

llvm::fpsize size = ConvertFPSize(floatType.getWidth());
auto & output =
rvsdg::SimpleNode::Create(rvsdgRegion, jlm::llvm::FNegOperation(size), { inputs[0] });
return &output;
}

else if (auto extOp = ::mlir::dyn_cast<::mlir::arith::ExtFOp>(&mlirOperation))
{
auto type = extOp.getResult().getType();
auto floatType = ::mlir::cast<::mlir::FloatType>(type);

llvm::fpsize size = ConvertFPSize(floatType.getWidth());
auto & output = rvsdg::SimpleNode::Create(
rvsdgRegion,
jlm::llvm::FPExtOperation(inputs[0]->Type(), llvm::FloatingPointType::Create(size)),
{ inputs[0] });
return &output;
}

else if (auto truncOp = ::mlir::dyn_cast<::mlir::arith::TruncIOp>(&mlirOperation))
{
auto type = truncOp.getResult().getType();
auto intType = ::mlir::cast<::mlir::IntegerType>(type);
return rvsdg::output::GetNode(
*jlm::llvm::TruncOperation::create(intType.getIntOrFloatBitWidth(), inputs[0]));
}

// Binary Integer Comparision operations
else if (auto ComOp = ::mlir::dyn_cast<::mlir::arith::CmpIOp>(&mlirOperation))
{
Expand All @@ -437,6 +469,25 @@ MlirToJlmConverter::ConvertOperation(
return rvsdg::output::GetNode(*jlmUndefOutput);
}

else if (auto ArrayOp = ::mlir::dyn_cast<::mlir::jlm::ConstantDataArray>(&mlirOperation))
{
return rvsdg::output::GetNode(
*llvm::ConstantDataArray::Create(std::vector(inputs.begin(), inputs.end())));
}

else if (auto ZeroOp = ::mlir::dyn_cast<::mlir::LLVM::ZeroOp>(&mlirOperation))
{
auto type = ZeroOp.getType();
return rvsdg::output::GetNode(
*llvm::ConstantAggregateZero::Create(rvsdgRegion, ConvertType(type)));
}

else if (auto VarArgOp = ::mlir::dyn_cast<::mlir::jlm::CreateVarArgList>(&mlirOperation))
{
return rvsdg::output::GetNode(
*llvm::valist_op::Create(rvsdgRegion, std::vector(inputs.begin(), inputs.end())));
}

// Memory operations

else if (auto AllocaOp = ::mlir::dyn_cast<::mlir::jlm::Alloca>(&mlirOperation))
Expand Down Expand Up @@ -765,6 +816,10 @@ MlirToJlmConverter::ConvertType(::mlir::Type & type)
{
return std::make_unique<llvm::PointerType>();
}
else if (::mlir::isa<::mlir::jlm::VarargListType>(type))
{
return std::make_unique<llvm::VariableArgumentType>();
}
else if (auto arrayType = ::mlir::dyn_cast<::mlir::LLVM::LLVMArrayType>(type))
{
auto mlirElementType = arrayType.getElementType();
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-mlir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

GIT_REPOSITORY=https://github.com/EECS-NTNU/mlir_rvsdg.git
GIT_COMMIT=9845608c59520771e0b3e4a8507094f84a00bc6a
GIT_COMMIT=e01d4ef44766b2da278e5a4e48d80d877c8017ce

# Get the absolute path to this script and set default build and install paths
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
Expand Down
Loading
Loading