-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[MLIR][VCIX] Support VCIX intrinsics in LLVMIR dialect #75875
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1826a14
[MLIR][VCIX] Support VCIX intrinsics in LLVMIR dialect
nikolaypanchenko 12add9b
Fixed typos in cmake file and added more tests
nikolaypanchenko 8b5ea95
removed `rd` argument from `vcix.v.iv` operation + rebase
nikolaypanchenko ca68194
comment changes + conversion test from math -> vcix
nikolaypanchenko 8a6c546
Addressed comments
nikolaypanchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===- VCIXDialect.h - MLIR VCIX IR dialect -------------------*- C++ ---*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The file defines the basic operations for the VCIX dialect. | ||
// | ||
// The SiFive Vector Coprocessor Interface (VCIX) provides a flexible mechanism | ||
// to extend application processors with custom coprocessors and | ||
// variable-latency arithmetic units. The interface offers throughput comparable | ||
// to that of standard RISC-V vector instructions. To accelerate performance, | ||
// system designers may use VCIX as a low-latency, high-throughput interface to | ||
// a coprocessor | ||
// | ||
// https://www.sifive.com/document-file/sifive-vector-coprocessor-interface-vcix-software | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_LLVMIR_VCIXDIALECT_H_ | ||
#define MLIR_DIALECT_LLVMIR_VCIXDIALECT_H_ | ||
|
||
#include "mlir/Bytecode/BytecodeOpInterface.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/IR/Dialect.h" | ||
#include "mlir/IR/OpDefinition.h" | ||
#include "mlir/Interfaces/SideEffectInterfaces.h" | ||
|
||
///// Ops ///// | ||
#define GET_ATTRDEF_CLASSES | ||
#include "mlir/Dialect/LLVMIR/VCIXOpsAttributes.h.inc" | ||
|
||
#define GET_OP_CLASSES | ||
#include "mlir/Dialect/LLVMIR/VCIXOps.h.inc" | ||
|
||
#include "mlir/Dialect/LLVMIR/VCIXOpsDialect.h.inc" | ||
|
||
#endif /* MLIR_DIALECT_LLVMIR_VCIXDIALECT_H_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
//===-- VCIX.td - VCIX dialect operation definitions *- tablegen -*--------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// The file defines the basic operations for the VCIX dialect. | ||
// | ||
// The SiFive Vector Coprocessor Interface (VCIX) provides a flexible mechanism | ||
// to extend application processors with custom coprocessors and | ||
// variable-latency arithmetic units. The interface offers throughput comparable | ||
// to that of standard RISC-V vector instructions. To accelerate performance, | ||
// system designers may use VCIX as a low-latency, high-throughput interface to | ||
// a coprocessor | ||
// | ||
// https://www.sifive.com/document-file/sifive-vector-coprocessor-interface-vcix-software | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef VCIXIR_OPS | ||
|
||
include "mlir/IR/OpBase.td" | ||
include "mlir/Dialect/LLVMIR/LLVMOpBase.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// VCIX dialect definition. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def VCIX_Dialect : Dialect { | ||
let name = "vcix"; | ||
let cppNamespace = "::mlir::vcix"; | ||
let dependentDialects = ["LLVM::LLVMDialect"]; | ||
let description = [{ | ||
The SiFive Vector Coprocessor Interface (VCIX) provides a flexible mechanism | ||
to extend application processors with custom coprocessors and | ||
variable-latency arithmetic units. The interface offers throughput comparable | ||
to that of standard RISC-V vector instructions. To accelerate performance, | ||
system designers may use VCIX as a low-latency, high-throughput interface to | ||
a coprocessor | ||
|
||
https://www.sifive.com/document-file/sifive-vector-coprocessor-interface-vcix-software | ||
}]; | ||
} | ||
|
||
// Special version for intrinsic version where int attr is zext to i32 or i64 | ||
// depending on xlen of the target. | ||
def VCIX_VectorOrScalar | ||
: AnyTypeOf<[LLVM_AnyVector, I<64>, I<32>, F<16>, F<32>, F<64>]>; | ||
def VCIX_OpcodeAttr : AnyAttrOf<[I32Attr, I64Attr]>; | ||
def VCIX_Register : AnyTypeOf<[I32, I64]>; | ||
def VCIX_ImmAttr : AnyAttrOf<[I32Attr, I64Attr]>; | ||
def VCIX_VL : AnyTypeOf<[I<64>, I<32>]>; | ||
|
||
class VCIX_Op<string mnemonic, list<Trait> traits = []> | ||
: LLVM_OpBase<VCIX_Dialect, mnemonic, traits> { | ||
} | ||
|
||
def VCIX_BinaryImmOp : VCIX_Op<"v.iv">, | ||
Results<(outs LLVM_AnyVector: $res)>, | ||
Arguments<(ins VCIX_OpcodeAttr: $opcode, | ||
nikolaypanchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LLVM_AnyVector: $vs2, | ||
VCIX_ImmAttr: $imm, | ||
Optional<VCIX_VL>: $vl)> { | ||
let summary = "Binary VCIX operation with an immediate second operand"; | ||
let description = [{ | ||
Binary VCIX operation with an immediate second operand. | ||
|
||
Correponds to: | ||
|Mnemonic|funct6|vm|rs2|rs1|funct3|rd|Destination|Sources| | ||
|--|--|--|--|--|--|--|--|--| | ||
|sf.vc.v.iv|0010--|0|vs2|simm|011|vd|vector vd| simm[4:0] vector vs2| | ||
}]; | ||
|
||
string llvmBuilder = [{ | ||
llvm::Type *xlen =getXlenType($opcode, moduleTranslation); | ||
llvm::Value *opcodeConst = mlir::LLVM::detail::getLLVMConstant( | ||
xlen, $opcode, $_location, moduleTranslation); | ||
llvm::Value *immConst = mlir::LLVM::detail::getLLVMConstant( | ||
xlen, $imm, $_location, moduleTranslation); | ||
VectorType vt = op.getResult().getType().cast<VectorType>(); | ||
llvm::Value *vl = | ||
createVL(builder, $vl, vt, xlen, $_location, moduleTranslation); | ||
$res = createIntrinsicCall( | ||
builder, llvm::Intrinsic::riscv_sf_vc_v_iv_se, | ||
{opcodeConst, $vs2, immConst, vl}, | ||
{$_resultType, xlen, $vs2->getType(), xlen, xlen}); | ||
}]; | ||
} | ||
|
||
def VCIX_BinaryOp : VCIX_Op<"v.sv">, | ||
Results<(outs LLVM_AnyVector: $res)>, | ||
Arguments<(ins VCIX_OpcodeAttr: $opcode, | ||
LLVM_AnyVector: $vs2, | ||
VCIX_VectorOrScalar: $op, | ||
Optional<VCIX_VL>: $vl)> { | ||
let summary = "Binary VCIX operation"; | ||
let description = [{ | ||
Binary VCIX operation with an integer scalar, or floating pointer scalar or | ||
vector second operand. | ||
|
||
Correponds to: | ||
|Mnemonic|funct6|vm|rs2|rs1|funct3|rd|Destination| Sources| | ||
|--|--|--|--|--|--|--|--|--|--| | ||
|sf.vc.v.vv|0010--|0|vs2|vs1|000|vd|vector vd|vector vs1, vector vs| | ||
|sf.vc.v.xv|0010--|0|vs2|xs1|100|vd|vector vd|scalar xs1, vector vs2| | ||
|sf.vc.v.fv|0010--|0|vs2|fs1|101|vd|vector vd|scalar fs1, vector vs2| | ||
}]; | ||
|
||
string llvmBuilder = [{ | ||
llvm::Type *xlen = getXlenType($opcode, moduleTranslation); | ||
llvm::Value *opcodeConst = mlir::LLVM::detail::getLLVMConstant( | ||
xlen, $opcode, $_location, moduleTranslation); | ||
llvm::Intrinsic::ID id; | ||
llvm::Type *opType = $op->getType(); | ||
if (opType->isVectorTy()) { | ||
id = llvm::Intrinsic::riscv_sf_vc_v_vv_se; | ||
} else if (opType->isIntegerTy()) { | ||
id = llvm::Intrinsic::riscv_sf_vc_v_xv_se; | ||
} else { | ||
id = llvm::Intrinsic::riscv_sf_vc_v_fv_se; | ||
} | ||
VectorType vt = op.getResult().getType().cast<VectorType>(); | ||
llvm::Value *vl = | ||
createVL(builder, $vl, vt, xlen, $_location, moduleTranslation); | ||
$res = createIntrinsicCall( | ||
builder, id, {opcodeConst, $vs2, $op, vl}, | ||
{$_resultType, xlen, $vs2->getType(), $op->getType(), xlen}); | ||
}]; | ||
} | ||
|
||
#endif // VCIXIR_OPS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
mlir/include/mlir/Target/LLVMIR/Dialect/VCIX/VCIXToLLVMIRTranslation.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===- VCIXToLLVMIRTranslation.h - VCIX to LLVM IR ------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This provides registration calls for VCIX dialect to LLVM IR translation. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_TARGET_LLVMIR_DIALECT_VCIX_VCIXTOLLVMIRTRANSLATION_H | ||
#define MLIR_TARGET_LLVMIR_DIALECT_VCIX_VCIXTOLLVMIRTRANSLATION_H | ||
|
||
namespace mlir { | ||
|
||
class DialectRegistry; | ||
class MLIRContext; | ||
|
||
/// Register the VCIX dialect and the translation from it to the LLVM IR in the | ||
/// given registry. | ||
void registerVCIXDialectTranslation(DialectRegistry ®istry); | ||
|
||
/// Register the VCIX dialect and the translation from it in the registry | ||
/// associated with the given context. | ||
void registerVCIXDialectTranslation(MLIRContext &context); | ||
|
||
} // namespace mlir | ||
|
||
#endif // MLIR_TARGET_LLVMIR_DIALECT_VCIX_VCIXTOLLVMIRTRANSLATION_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===- VCIXDialect.cpp - MLIR VCIX ops implementation ---------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the VCIX dialect and its operations. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/Dialect/LLVMIR/VCIXDialect.h" | ||
|
||
#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/IR/Builders.h" | ||
#include "mlir/IR/BuiltinTypes.h" | ||
#include "mlir/IR/DialectImplementation.h" | ||
#include "mlir/IR/MLIRContext.h" | ||
#include "mlir/IR/Operation.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
#include "llvm/AsmParser/Parser.h" | ||
#include "llvm/IR/Attributes.h" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/Type.h" | ||
#include "llvm/Support/SourceMgr.h" | ||
|
||
using namespace mlir; | ||
using namespace vcix; | ||
|
||
#include "mlir/Dialect/LLVMIR/VCIXOpsDialect.cpp.inc" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// VCIXDialect initialization, type parsing, and registration. | ||
//===----------------------------------------------------------------------===// | ||
|
||
void VCIXDialect::initialize() { | ||
addOperations< | ||
#define GET_OP_LIST | ||
#include "mlir/Dialect/LLVMIR/VCIXOps.cpp.inc" | ||
>(); | ||
|
||
addAttributes< | ||
#define GET_ATTRDEF_LIST | ||
#include "mlir/Dialect/LLVMIR/VCIXOpsAttributes.cpp.inc" | ||
>(); | ||
} | ||
|
||
#define GET_OP_CLASSES | ||
#include "mlir/Dialect/LLVMIR/VCIXOps.cpp.inc" | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "mlir/Dialect/LLVMIR/VCIXOpsAttributes.cpp.inc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
add_mlir_translation_library(MLIRVCIXToLLVMIRTranslation | ||
VCIXToLLVMIRTranslation.cpp | ||
|
||
DEPENDS | ||
MLIRVCIXConversionsIncGen | ||
|
||
LINK_COMPONENTS | ||
Core | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRIR | ||
MLIRLLVMDialect | ||
MLIRVCIXDialect | ||
MLIRSupport | ||
MLIRTargetLLVMIRExport | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any official RISC-V ratification that we should mention/point to here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VCIX is a custom extension. The official link is given at the line 18