Skip to content

Commit

Permalink
Remove llvm:: prefix from argument comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tsymalla committed Feb 28, 2025
1 parent 95e5b4d commit a638574
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
6 changes: 6 additions & 0 deletions include/llvm-dialects/TableGen/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ void emitHeader(llvm::raw_ostream& out);

bool shouldEmitComments();

/// Replace all occurrences of needle in haystack with replacement and return
/// the new string.
std::string replaceSubstring(const std::string &haystack,
const std::string &needle,
const std::string &replacement = "");

/// Prefix an incoming multi-line string with a single-line comment string line
/// by line.
std::string createCommentFromString(const std::string &input);
Expand Down
11 changes: 10 additions & 1 deletion lib/TableGen/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "llvm/Support/CommandLine.h"

#include <regex>
#include <string>

using namespace llvm_dialects;
using namespace llvm;

Expand All @@ -36,8 +39,14 @@ void llvm_dialects::emitHeader(raw_ostream& out) {

bool llvm_dialects::shouldEmitComments() { return g_emitComments; }

std::string llvm_dialects::replaceSubstring(const std::string &haystack,
const std::string &needle,
const std::string &replacement) {
return std::regex_replace(haystack, std::regex(needle), replacement);
}

std::string llvm_dialects::createCommentFromString(const std::string &input) {
StringRef inRef{input};
const StringRef inRef{input};
if (inRef.trim().empty())
return input;

Expand Down
9 changes: 6 additions & 3 deletions lib/TableGen/GenDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm-dialects/TableGen/SymbolTable.h"
#include "llvm-dialects/TableGen/Traits.h"

#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormatVariadic.h"
Expand Down Expand Up @@ -182,9 +183,11 @@ class Builder;

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

out << tgfmt(R"(
Expand Down
60 changes: 30 additions & 30 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ Initial = 2,
/// numbers and puts a constant on top.
///
/// Arguments
/// ::llvm::Value * lhs
/// ::llvm::Value * rhs
/// Value * lhs
/// Value * rhs
/// uint32_t extra

class Add32Op : public ::llvm::CallInst {
Expand Down Expand Up @@ -159,8 +159,8 @@ Extra = 2,
/// Longer description of... well, you know by now how this goes.
///
/// Arguments
/// ::llvm::Value * lhs
/// ::llvm::Value * rhs
/// Value * lhs
/// Value * rhs

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

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

class FromFixedVectorOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.fromfixedvector"};
Expand Down Expand Up @@ -294,7 +294,7 @@ bool verifier(::llvm::raw_ostream &errs);
/// position.
///
/// Arguments
/// ::llvm::Value * source
/// Value * source

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

class ITruncOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.itrunc"};
Expand Down Expand Up @@ -391,9 +391,9 @@ Val = 0,
/// returns the result.
///
/// Arguments
/// ::llvm::Value * vector
/// ::llvm::Value * value
/// ::llvm::Value * index
/// Value * vector
/// Value * value
/// Value * index

class InsertElementOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.insertelement"};
Expand Down Expand Up @@ -433,8 +433,8 @@ Index = 2,
/// dialect compiler's first choice
///
/// Arguments
/// ::llvm::Value * instName
/// ::llvm::Value * instName_0
/// Value * instName
/// Value * instName_0

class InstNameConflictDoubleOp : public ::llvm::CallInst {
static const ::llvm::StringLiteral s_name; //{"xd.ir.inst.name.conflict.double"};
Expand Down Expand Up @@ -472,7 +472,7 @@ InstName_0 = 1,
/// will be renamed.
///
/// Arguments
/// ::llvm::Value * instName
/// Value * instName

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

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

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

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

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

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

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

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

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

0 comments on commit a638574

Please sign in to comment.