Skip to content

Commit a638574

Browse files
committed
Remove llvm:: prefix from argument comments
1 parent 95e5b4d commit a638574

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
lines changed

include/llvm-dialects/TableGen/Common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ void emitHeader(llvm::raw_ostream& out);
3636

3737
bool shouldEmitComments();
3838

39+
/// Replace all occurrences of needle in haystack with replacement and return
40+
/// the new string.
41+
std::string replaceSubstring(const std::string &haystack,
42+
const std::string &needle,
43+
const std::string &replacement = "");
44+
3945
/// Prefix an incoming multi-line string with a single-line comment string line
4046
/// by line.
4147
std::string createCommentFromString(const std::string &input);

lib/TableGen/Common.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include "llvm/Support/CommandLine.h"
2424

25+
#include <regex>
26+
#include <string>
27+
2528
using namespace llvm_dialects;
2629
using namespace llvm;
2730

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

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

42+
std::string llvm_dialects::replaceSubstring(const std::string &haystack,
43+
const std::string &needle,
44+
const std::string &replacement) {
45+
return std::regex_replace(haystack, std::regex(needle), replacement);
46+
}
47+
3948
std::string llvm_dialects::createCommentFromString(const std::string &input) {
40-
StringRef inRef{input};
49+
const StringRef inRef{input};
4150
if (inRef.trim().empty())
4251
return input;
4352

lib/TableGen/GenDialect.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm-dialects/TableGen/SymbolTable.h"
2727
#include "llvm-dialects/TableGen/Traits.h"
2828

29+
#include "llvm/ADT/STLExtras.h"
2930
#include "llvm/ADT/StringExtras.h"
3031
#include "llvm/Support/CommandLine.h"
3132
#include "llvm/Support/FormatVariadic.h"
@@ -182,9 +183,11 @@ class Builder;
182183

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

190193
out << tgfmt(R"(

test/example/generated/ExampleDialect.h.inc

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ Initial = 2,
118118
/// numbers and puts a constant on top.
119119
///
120120
/// Arguments
121-
/// ::llvm::Value * lhs
122-
/// ::llvm::Value * rhs
121+
/// Value * lhs
122+
/// Value * rhs
123123
/// uint32_t extra
124124

125125
class Add32Op : public ::llvm::CallInst {
@@ -159,8 +159,8 @@ Extra = 2,
159159
/// Longer description of... well, you know by now how this goes.
160160
///
161161
/// Arguments
162-
/// ::llvm::Value * lhs
163-
/// ::llvm::Value * rhs
162+
/// Value * lhs
163+
/// Value * rhs
164164

165165
class CombineOp : public ::llvm::CallInst {
166166
static const ::llvm::StringLiteral s_name; //{"xd.ir.combine"};
@@ -196,8 +196,8 @@ Rhs = 1,
196196
/// Return the element of `vector` with the given `index`.
197197
///
198198
/// Arguments
199-
/// ::llvm::Value * vector
200-
/// ::llvm::Value * index
199+
/// Value * vector
200+
/// Value * index
201201

202202
class ExtractElementOp : public ::llvm::CallInst {
203203
static const ::llvm::StringLiteral s_name; //{"xd.ir.extractelement"};
@@ -233,7 +233,7 @@ Index = 1,
233233
/// Demonstrate a more complex unification case.
234234
///
235235
/// Arguments
236-
/// ::llvm::Value * source
236+
/// Value * source
237237

238238
class FromFixedVectorOp : public ::llvm::CallInst {
239239
static const ::llvm::StringLiteral s_name; //{"xd.ir.fromfixedvector"};
@@ -294,7 +294,7 @@ bool verifier(::llvm::raw_ostream &errs);
294294
/// position.
295295
///
296296
/// Arguments
297-
/// ::llvm::Value * source
297+
/// Value * source
298298

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

332332
class ITruncOp : public ::llvm::CallInst {
333333
static const ::llvm::StringLiteral s_name; //{"xd.ir.itrunc"};
@@ -391,9 +391,9 @@ Val = 0,
391391
/// returns the result.
392392
///
393393
/// Arguments
394-
/// ::llvm::Value * vector
395-
/// ::llvm::Value * value
396-
/// ::llvm::Value * index
394+
/// Value * vector
395+
/// Value * value
396+
/// Value * index
397397

398398
class InsertElementOp : public ::llvm::CallInst {
399399
static const ::llvm::StringLiteral s_name; //{"xd.ir.insertelement"};
@@ -433,8 +433,8 @@ Index = 2,
433433
/// dialect compiler's first choice
434434
///
435435
/// Arguments
436-
/// ::llvm::Value * instName
437-
/// ::llvm::Value * instName_0
436+
/// Value * instName
437+
/// Value * instName_0
438438

439439
class InstNameConflictDoubleOp : public ::llvm::CallInst {
440440
static const ::llvm::StringLiteral s_name; //{"xd.ir.inst.name.conflict.double"};
@@ -472,7 +472,7 @@ InstName_0 = 1,
472472
/// will be renamed.
473473
///
474474
/// Arguments
475-
/// ::llvm::Value * instName
475+
/// Value * instName
476476

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

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

677677
class SizeOfOp : public ::llvm::CallInst {
678678
static const ::llvm::StringLiteral s_name; //{"xd.ir.sizeof"};
@@ -705,9 +705,9 @@ SizeofType = 0,
705705
/// Illustrate the use of the OpClass feature.
706706
///
707707
/// Arguments
708-
/// ::llvm::Value * ptr
709-
/// ::llvm::Value * count
710-
/// ::llvm::Value * initial
708+
/// Value * ptr
709+
/// Value * count
710+
/// Value * initial
711711

712712
class StreamAddOp : public StreamReduceOp {
713713
static const ::llvm::StringLiteral s_name; //{"xd.ir.stream.add"};
@@ -736,9 +736,9 @@ bool verifier(::llvm::raw_ostream &errs);
736736
/// Illustrate the use of the OpClass feature.
737737
///
738738
/// Arguments
739-
/// ::llvm::Value * ptr
740-
/// ::llvm::Value * count
741-
/// ::llvm::Value * initial
739+
/// Value * ptr
740+
/// Value * count
741+
/// Value * initial
742742

743743
class StreamMaxOp : public StreamReduceOp {
744744
static const ::llvm::StringLiteral s_name; //{"xd.ir.stream.max"};
@@ -767,9 +767,9 @@ bool verifier(::llvm::raw_ostream &errs);
767767
/// Illustrate the use of the OpClass feature.
768768
///
769769
/// Arguments
770-
/// ::llvm::Value * ptr
771-
/// ::llvm::Value * count
772-
/// ::llvm::Value * initial
770+
/// Value * ptr
771+
/// Value * count
772+
/// Value * initial
773773

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

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

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

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

0 commit comments

Comments
 (0)