Skip to content

Commit

Permalink
Add comments about arguments to op declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Symalla committed Feb 20, 2025
1 parent 50260f8 commit 95e5b4d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/TableGen/GenDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ class Builder;
if (!op.description.empty())
description += createCommentFromString(op.description);

if (op.getNumFullArguments() > 0) {
description += "/// Arguments\n";
for (const auto &[idx, arg] : llvm::enumerate(op.getFullArguments()))
description += "/// " + arg.type->getBuilderCppType().str() + " " +
arg.name + "\n";
}

out << tgfmt(R"(
$2
class $_op : public $0 {
Expand Down
50 changes: 50 additions & 0 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ Initial = 2,
/// For those times when you want a little extra, this operation adds two
/// numbers and puts a constant on top.
///
/// Arguments
/// ::llvm::Value * lhs
/// ::llvm::Value * rhs
/// uint32_t extra

class Add32Op : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.add32"};
Expand Down Expand Up @@ -154,6 +158,9 @@ Extra = 2,
///
/// Longer description of... well, you know by now how this goes.
///
/// Arguments
/// ::llvm::Value * lhs
/// ::llvm::Value * rhs

class CombineOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.combine"};
Expand Down Expand Up @@ -188,6 +195,9 @@ Rhs = 1,
///
/// Return the element of `vector` with the given `index`.
///
/// Arguments
/// ::llvm::Value * vector
/// ::llvm::Value * index

class ExtractElementOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.extractelement"};
Expand Down Expand Up @@ -222,6 +232,8 @@ Index = 1,
///
/// Demonstrate a more complex unification case.
///
/// Arguments
/// ::llvm::Value * source

class FromFixedVectorOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.fromfixedvector"};
Expand Down Expand Up @@ -281,6 +293,8 @@ bool verifier(::llvm::raw_ostream &errs);
/// Demonstrates the use of the same unevaluatable `le` predicate in a valued
/// position.
///
/// Arguments
/// ::llvm::Value * source

class IExtOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.iext"};
Expand Down Expand Up @@ -312,6 +326,8 @@ Source = 0,
///
/// Demonstrates the use of a predicate in an unvalued position.
///
/// Arguments
/// ::llvm::Value * source

class ITruncOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.itrunc"};
Expand Down Expand Up @@ -343,6 +359,8 @@ Source = 0,
///
/// Make an argument immutable
///
/// Arguments
/// bool val

class ImmutableOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.immutable.op"};
Expand Down Expand Up @@ -372,6 +390,10 @@ Val = 0,
/// Insert the given `value` into the given `vector` at the given `index` and
/// returns the result.
///
/// Arguments
/// ::llvm::Value * vector
/// ::llvm::Value * value
/// ::llvm::Value * index

class InsertElementOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.insertelement"};
Expand Down Expand Up @@ -410,6 +432,9 @@ Index = 2,
/// Like InstNameConflictOp but this has a second parameter named like the
/// dialect compiler's first choice
///
/// Arguments
/// ::llvm::Value * instName
/// ::llvm::Value * instName_0

class InstNameConflictDoubleOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.inst.name.conflict.double"};
Expand Down Expand Up @@ -446,6 +471,8 @@ InstName_0 = 1,
/// value like IRBuilder methods. This op produces a conflict so the parameter
/// will be renamed.
///
/// Arguments
/// ::llvm::Value * instName

class InstNameConflictOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.inst.name.conflict"};
Expand Down Expand Up @@ -612,6 +639,8 @@ bool verifier(::llvm::raw_ostream &errs);
///
/// Longer description of how this operation writes pieces of data.
///
/// Arguments
/// ::llvm::Value * data

class SetWriteOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.set.write"};
Expand Down Expand Up @@ -642,6 +671,8 @@ Data = 0,
///
/// Returns the store size of the given type in bytes.
///
/// Arguments
/// ::llvm::Type * sizeof_type

class SizeOfOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.sizeof"};
Expand Down Expand Up @@ -673,6 +704,10 @@ SizeofType = 0,
///
/// Illustrate the use of the OpClass feature.
///
/// Arguments
/// ::llvm::Value * ptr
/// ::llvm::Value * count
/// ::llvm::Value * initial

class StreamAddOp : public StreamReduceOp {
static const ::llvm::StringLiteral s_name; //{"xd.ir.stream.add"};
Expand Down Expand Up @@ -700,6 +735,10 @@ bool verifier(::llvm::raw_ostream &errs);
///
/// Illustrate the use of the OpClass feature.
///
/// Arguments
/// ::llvm::Value * ptr
/// ::llvm::Value * count
/// ::llvm::Value * initial

class StreamMaxOp : public StreamReduceOp {
static const ::llvm::StringLiteral s_name; //{"xd.ir.stream.max"};
Expand Down Expand Up @@ -727,6 +766,10 @@ bool verifier(::llvm::raw_ostream &errs);
///
/// Illustrate the use of the OpClass feature.
///
/// Arguments
/// ::llvm::Value * ptr
/// ::llvm::Value * count
/// ::llvm::Value * initial

class StreamMinOp : public StreamReduceOp {
static const ::llvm::StringLiteral s_name; //{"xd.ir.stream.min"};
Expand Down Expand Up @@ -754,6 +797,8 @@ bool verifier(::llvm::raw_ostream &errs);
///
/// The argument should not have a setter method
///
/// Arguments
/// ::llvm::StringRef val

class StringAttrOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.string.attr.op"};
Expand Down Expand Up @@ -782,6 +827,8 @@ Val = 0,
///
/// Longer description of how this operation writes a piece of data.
///
/// Arguments
/// ::llvm::Value * data

class WriteOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.write"};
Expand Down Expand Up @@ -812,6 +859,9 @@ Data = 0,
///
/// Longer description of how this operation writes pieces of data.
///
/// Arguments
/// ::llvm::Value * data
/// ::llvm::ArrayRef<::llvm::Value *> args

class WriteVarArgOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.write.vararg"};
Expand Down

0 comments on commit 95e5b4d

Please sign in to comment.