Skip to content

Commit

Permalink
Add builder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanRehders-AMD authored and tsymalla-AMD committed Feb 2, 2024
1 parent 7e12cc9 commit e27f76c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
6 changes: 3 additions & 3 deletions example/ExampleDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def HandleGetOp : ExampleOp<"handle.get", [Memory<[]>, NoUnwind, WillReturn]> {
}

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

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

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

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

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

let summary = "demonstrate how name conflict will be avoided";
Expand Down
13 changes: 13 additions & 0 deletions example/ExampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ void createFunctionExample(Module &module, const Twine &name) {

useUnnamedStructTypes(b);

b.create<xd::HandleGetOp>("name.of.llvm.value");
b.create<xd::InstNameConflictOp>(b.getInt32(1));
b.create<xd::InstNameConflictOp>(b.getInt32(1), "name.foo");
b.create<xd::InstNameConflictDoubleOp>(b.getInt32(1), b.getInt32(2));
b.create<xd::InstNameConflictDoubleOp>(b.getInt32(1), b.getInt32(2), "bar");
SmallVector<Value *> moreVarArgs = varArgs;
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs);
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs, "two.varargs");
moreVarArgs.push_back(b.getInt32(3));
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs, "three.varargs");
moreVarArgs.push_back(b.getInt32(4));
b.create<xd::InstNameConflictVarargsOp>(moreVarArgs, "four.varargs");

b.CreateRetVoid();
}

Expand Down
45 changes: 39 additions & 6 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ index

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

auto fn = module.getOrInsertFunction(s_name, fnType, attrs);
::llvm::SmallString<32> newName;
Expand Down Expand Up @@ -1238,7 +1238,17 @@ instName_0
(void)instNameType;
::llvm::Type * const instName_0Type = getInstName_0()->getType();
(void)instName_0Type;
return true;
::llvm::Type * const resultType = getResult()->getType();
(void)resultType;

if (::llvm::IntegerType::get(context, 32) != resultType) {
errs << " unexpected value of $result:\n";
errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n';
errs << " actual: " << printable(resultType) << '\n';

return false;
}
return true;
}


Expand All @@ -1256,6 +1266,7 @@ instName_0
void InstNameConflictDoubleOp::setInstName_0(::llvm::Value * instName_0) {
setArgOperand(1, instName_0);
}
::llvm::Value *InstNameConflictDoubleOp::getResult() {return this;}



Expand All @@ -1269,7 +1280,7 @@ instName_0

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

auto fn = module.getOrInsertFunction(s_name, fnType, attrs);
::llvm::SmallString<32> newName;
Expand Down Expand Up @@ -1308,7 +1319,17 @@ instName
}
::llvm::Type * const instNameType = getInstName()->getType();
(void)instNameType;
return true;
::llvm::Type * const resultType = getResult()->getType();
(void)resultType;

if (::llvm::IntegerType::get(context, 32) != resultType) {
errs << " unexpected value of $result:\n";
errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n';
errs << " actual: " << printable(resultType) << '\n';

return false;
}
return true;
}


Expand All @@ -1319,6 +1340,7 @@ instName
void InstNameConflictOp::setInstName(::llvm::Value * instName) {
setArgOperand(0, instName);
}
::llvm::Value *InstNameConflictOp::getResult() {return this;}



Expand All @@ -1332,7 +1354,7 @@ instName

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

auto fn = module.getOrInsertFunction(s_name, fnType, attrs);
::llvm::SmallString<32> newName;
Expand Down Expand Up @@ -1371,7 +1393,17 @@ instName
<< ", expected at least 0\n";
return false;
}
return true;
::llvm::Type * const resultType = getResult()->getType();
(void)resultType;

if (::llvm::IntegerType::get(context, 32) != resultType) {
errs << " unexpected value of $result:\n";
errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n';
errs << " actual: " << printable(resultType) << '\n';

return false;
}
return true;
}


Expand All @@ -1380,6 +1412,7 @@ instName
value_op_iterator(arg_begin() + 0),
value_op_iterator(arg_end()));
}
::llvm::Value *InstNameConflictVarargsOp::getResult() {return this;}



Expand Down
3 changes: 3 additions & 0 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ bool verifier(::llvm::raw_ostream &errs);
::llvm::Value * getInstName_0();
void setInstName_0(::llvm::Value * instName_0);

::llvm::Value * getResult();


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

::llvm::Value * getResult();


};
Expand All @@ -360,6 +362,7 @@ bool verifier(::llvm::raw_ostream &errs);
bool verifier(::llvm::raw_ostream &errs);

::llvm::iterator_range<::llvm::User::value_op_iterator> getInstName_0();
::llvm::Value * getResult();


};
Expand Down
9 changes: 9 additions & 0 deletions test/example/test-builder.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,14 @@
; CHECK-NEXT: call void (...) @xd.write([[TMP0]] [[TMP16]])
; CHECK-NEXT: call void (...) @xd.write([[TMP1]] [[TMP17]])
; CHECK-NEXT: call void (...) @xd.write([[TMP2]] [[TMP18]])
; CHECK-NEXT: [[NAME_OF_LLVM_VALUE:%.*]] = call target("xd.handle") @xd.handle.get()
; CHECK-NEXT: [[TMP19:%.*]] = call i32 (...) @xd.try.conflict(i32 1)
; CHECK-NEXT: [[NAME_FOO:%.*]] = call i32 (...) @xd.try.conflict(i32 1)
; CHECK-NEXT: [[TMP20:%.*]] = call i32 (...) @xd.try.conflict(i32 1, i32 2)
; CHECK-NEXT: [[BAR:%.*]] = call i32 (...) @xd.try.conflict(i32 1, i32 2)
; CHECK-NEXT: [[TMP21:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]])
; CHECK-NEXT: [[TWO_VARARGS:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]])
; CHECK-NEXT: [[THREE_VARARGS:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]], i32 3)
; CHECK-NEXT: [[FOUR_VARARGS:%.*]] = call i32 (...) @xd.try.conflict.type.suffix(ptr [[P1]], i8 [[P2]], i32 3, i32 4)
; CHECK-NEXT: ret void
;

0 comments on commit e27f76c

Please sign in to comment.