Skip to content

Commit e27f76c

Browse files
JanRehders-AMDtsymalla-AMD
authored andcommitted
Add builder tests
1 parent 7e12cc9 commit e27f76c

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

example/ExampleDialect.td

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def HandleGetOp : ExampleOp<"handle.get", [Memory<[]>, NoUnwind, WillReturn]> {
270270
}
271271

272272
def InstNameConflictOp : Op<ExampleDialect, "try.conflict", [WillReturn]> {
273-
let results = (outs);
273+
let results = (outs I32:$result);
274274
let arguments = (ins value:$instName);
275275

276276
let summary = "demonstrate how name conflict will be avoided";
@@ -282,7 +282,7 @@ def InstNameConflictOp : Op<ExampleDialect, "try.conflict", [WillReturn]> {
282282
}
283283

284284
def InstNameConflictDoubleOp : Op<ExampleDialect, "try.conflict", [WillReturn]> {
285-
let results = (outs);
285+
let results = (outs I32:$result);
286286
let arguments = (ins value:$instName, value:$instName_0);
287287

288288
let summary = "demonstrate how name conflict will be avoided";
@@ -293,7 +293,7 @@ def InstNameConflictDoubleOp : Op<ExampleDialect, "try.conflict", [WillReturn]>
293293
}
294294

295295
def InstNameConflictVarargsOp : Op<ExampleDialect, "try.conflict.type.suffix", [WillReturn]> {
296-
let results = (outs);
296+
let results = (outs I32:$result);
297297
let arguments = (ins varargs:$instName_0);
298298

299299
let summary = "demonstrate how name conflict will be avoided";

example/ExampleMain.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ void createFunctionExample(Module &module, const Twine &name) {
128128

129129
useUnnamedStructTypes(b);
130130

131+
b.create<xd::HandleGetOp>("name.of.llvm.value");
132+
b.create<xd::InstNameConflictOp>(b.getInt32(1));
133+
b.create<xd::InstNameConflictOp>(b.getInt32(1), "name.foo");
134+
b.create<xd::InstNameConflictDoubleOp>(b.getInt32(1), b.getInt32(2));
135+
b.create<xd::InstNameConflictDoubleOp>(b.getInt32(1), b.getInt32(2), "bar");
136+
SmallVector<Value *> moreVarArgs = varArgs;
137+
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs);
138+
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs, "two.varargs");
139+
moreVarArgs.push_back(b.getInt32(3));
140+
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs, "three.varargs");
141+
moreVarArgs.push_back(b.getInt32(4));
142+
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs, "four.varargs");
143+
131144
b.CreateRetVoid();
132145
}
133146

test/example/generated/ExampleDialect.cpp.inc

+39-6
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ index
11961196

11971197
const ::llvm::AttributeList attrs
11981198
= ExampleDialect::get(context).getAttributeList(4);
1199-
auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), true);
1199+
auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 32), true);
12001200

12011201
auto fn = module.getOrInsertFunction(s_name, fnType, attrs);
12021202
::llvm::SmallString<32> newName;
@@ -1238,7 +1238,17 @@ instName_0
12381238
(void)instNameType;
12391239
::llvm::Type * const instName_0Type = getInstName_0()->getType();
12401240
(void)instName_0Type;
1241-
return true;
1241+
::llvm::Type * const resultType = getResult()->getType();
1242+
(void)resultType;
1243+
1244+
if (::llvm::IntegerType::get(context, 32) != resultType) {
1245+
errs << " unexpected value of $result:\n";
1246+
errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n';
1247+
errs << " actual: " << printable(resultType) << '\n';
1248+
1249+
return false;
1250+
}
1251+
return true;
12421252
}
12431253

12441254

@@ -1256,6 +1266,7 @@ instName_0
12561266
void InstNameConflictDoubleOp::setInstName_0(::llvm::Value * instName_0) {
12571267
setArgOperand(1, instName_0);
12581268
}
1269+
::llvm::Value *InstNameConflictDoubleOp::getResult() {return this;}
12591270

12601271

12611272

@@ -1269,7 +1280,7 @@ instName_0
12691280

12701281
const ::llvm::AttributeList attrs
12711282
= ExampleDialect::get(context).getAttributeList(4);
1272-
auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), true);
1283+
auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 32), true);
12731284

12741285
auto fn = module.getOrInsertFunction(s_name, fnType, attrs);
12751286
::llvm::SmallString<32> newName;
@@ -1308,7 +1319,17 @@ instName
13081319
}
13091320
::llvm::Type * const instNameType = getInstName()->getType();
13101321
(void)instNameType;
1311-
return true;
1322+
::llvm::Type * const resultType = getResult()->getType();
1323+
(void)resultType;
1324+
1325+
if (::llvm::IntegerType::get(context, 32) != resultType) {
1326+
errs << " unexpected value of $result:\n";
1327+
errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n';
1328+
errs << " actual: " << printable(resultType) << '\n';
1329+
1330+
return false;
1331+
}
1332+
return true;
13121333
}
13131334

13141335

@@ -1319,6 +1340,7 @@ instName
13191340
void InstNameConflictOp::setInstName(::llvm::Value * instName) {
13201341
setArgOperand(0, instName);
13211342
}
1343+
::llvm::Value *InstNameConflictOp::getResult() {return this;}
13221344

13231345

13241346

@@ -1332,7 +1354,7 @@ instName
13321354

13331355
const ::llvm::AttributeList attrs
13341356
= ExampleDialect::get(context).getAttributeList(4);
1335-
auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), true);
1357+
auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 32), true);
13361358

13371359
auto fn = module.getOrInsertFunction(s_name, fnType, attrs);
13381360
::llvm::SmallString<32> newName;
@@ -1371,7 +1393,17 @@ instName
13711393
<< ", expected at least 0\n";
13721394
return false;
13731395
}
1374-
return true;
1396+
::llvm::Type * const resultType = getResult()->getType();
1397+
(void)resultType;
1398+
1399+
if (::llvm::IntegerType::get(context, 32) != resultType) {
1400+
errs << " unexpected value of $result:\n";
1401+
errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n';
1402+
errs << " actual: " << printable(resultType) << '\n';
1403+
1404+
return false;
1405+
}
1406+
return true;
13751407
}
13761408

13771409

@@ -1380,6 +1412,7 @@ instName
13801412
value_op_iterator(arg_begin() + 0),
13811413
value_op_iterator(arg_end()));
13821414
}
1415+
::llvm::Value *InstNameConflictVarargsOp::getResult() {return this;}
13831416

13841417

13851418

test/example/generated/ExampleDialect.h.inc

+3
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ bool verifier(::llvm::raw_ostream &errs);
318318
::llvm::Value * getInstName_0();
319319
void setInstName_0(::llvm::Value * instName_0);
320320

321+
::llvm::Value * getResult();
321322

322323

323324
};
@@ -340,6 +341,7 @@ bool verifier(::llvm::raw_ostream &errs);
340341
::llvm::Value * getInstName();
341342
void setInstName(::llvm::Value * instName);
342343

344+
::llvm::Value * getResult();
343345

344346

345347
};
@@ -360,6 +362,7 @@ bool verifier(::llvm::raw_ostream &errs);
360362
bool verifier(::llvm::raw_ostream &errs);
361363

362364
::llvm::iterator_range<::llvm::User::value_op_iterator> getInstName_0();
365+
::llvm::Value * getResult();
363366

364367

365368
};

test/example/test-builder.test

+9
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,14 @@
3333
; CHECK-NEXT: call void (...) @xd.write([[TMP0]] [[TMP16]])
3434
; CHECK-NEXT: call void (...) @xd.write([[TMP1]] [[TMP17]])
3535
; CHECK-NEXT: call void (...) @xd.write([[TMP2]] [[TMP18]])
36+
; CHECK-NEXT: [[NAME_OF_LLVM_VALUE:%.*]] = call target("xd.handle") @xd.handle.get()
37+
; CHECK-NEXT: [[TMP19:%.*]] = call i32 (...) @xd.try.conflict(i32 1)
38+
; CHECK-NEXT: [[NAME_FOO:%.*]] = call i32 (...) @xd.try.conflict(i32 1)
39+
; CHECK-NEXT: [[TMP20:%.*]] = call i32 (...) @xd.try.conflict(i32 1, i32 2)
40+
; CHECK-NEXT: [[BAR:%.*]] = call i32 (...) @xd.try.conflict(i32 1, i32 2)
41+
; CHECK-NEXT: [[TMP21:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]])
42+
; CHECK-NEXT: [[TWO_VARARGS:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]])
43+
; CHECK-NEXT: [[THREE_VARARGS:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]], i32 3)
44+
; CHECK-NEXT: [[FOUR_VARARGS:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]], i32 3, i32 4)
3645
; CHECK-NEXT: ret void
3746
;

0 commit comments

Comments
 (0)