Skip to content
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

[RTG] Add InstructionOpInterface #7979

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 35 additions & 2 deletions include/circt/Dialect/RTG/IR/RTGISAAssemblyInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,42 @@ def RegisterOpInterface : OpInterface<"RegisterOpInterface"> {
}],
"llvm::APInt", "getClassIndexBinary">,
InterfaceMethod<[{
Returns a suitable string for use in assembly format.
Prints a suitable string for use in the ISA assembly format.
}],
"std::string", "getRegisterAssembly">,
"void", "printRegisterAssembly", (ins "llvm::raw_ostream &":$os)>,
];
}

def InstructionOpInterface : OpInterface<"InstructionOpInterface"> {
let description = [{
This interface should be implemented by operations that represent
ISA instructions.
}];
let cppNamespace = "::circt::rtg";

let methods = [
InterfaceMethod<[{
Returns a binary representation of the instruction compatible with the
ISA specification as an APInt.
}],
"::llvm::APInt", "getInstructionBinary",
(ins "llvm::ArrayRef<llvm::APInt>":$operands)>,
InterfaceMethod<[{
Emits the ISA assembly representation of the instruction to the provided
stream. The format should be the one understood by common assembler
tools.
}],
"void", "printInstructionAssembly",
(ins "llvm::raw_ostream &":$os,
"llvm::ArrayRef<llvm::function_ref<void(llvm::raw_ostream &)>>":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taking arrays of lambdas is general, but low performance. Emiting shouldn't be the bottleneck, but worth keeping in mind.

It seems that since the dialect defines the type of each op's operands, the operand would know how to print it's operands without indirection.

I'd also avoid having a default implementation as there is no sensible default.

$operandPrinters),
/*methodBody=*/[{}],
/*defaultImplementation=*/[{
os << $_op->getName().stripDialect() << " ";
llvm::interleaveComma(operandPrinters, os, [&](auto printer) {
printer(os);
});
}]>,
];
}

Expand Down
Loading