[tint][ir][ToProgram] Emit builtin calls
Change-Id: I48a21b8f4e1e430adddaf357a9349e07163de383
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/139643
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/ir/to_program.cc b/src/tint/ir/to_program.cc
index 63a8abe..3f87f8b 100644
--- a/src/tint/ir/to_program.cc
+++ b/src/tint/ir/to_program.cc
@@ -23,6 +23,7 @@
#include "src/tint/ir/binary.h"
#include "src/tint/ir/block.h"
#include "src/tint/ir/break_if.h"
+#include "src/tint/ir/builtin_call.h"
#include "src/tint/ir/call.h"
#include "src/tint/ir/constant.h"
#include "src/tint/ir/construct.h"
@@ -465,6 +466,14 @@
}
Bind(c->Result(), expr);
},
+ [&](ir::BuiltinCall* c) {
+ auto* expr = b.Call(c->Func(), std::move(args));
+ if (!call->HasResults() || call->Result()->Usages().IsEmpty()) {
+ Append(b.CallStmt(expr));
+ return;
+ }
+ Bind(c->Result(), expr);
+ },
[&](ir::Construct* c) {
auto ty = Type(c->Result()->Type());
Bind(c->Result(), b.Call(ty, std::move(args)));
diff --git a/src/tint/ir/to_program_roundtrip_test.cc b/src/tint/ir/to_program_roundtrip_test.cc
index c8dde81..66ed84b 100644
--- a/src/tint/ir/to_program_roundtrip_test.cc
+++ b/src/tint/ir/to_program_roundtrip_test.cc
@@ -153,6 +153,25 @@
}
////////////////////////////////////////////////////////////////////////////////
+// Builtin Call
+////////////////////////////////////////////////////////////////////////////////
+TEST_F(IRToProgramRoundtripTest, BuiltinCall_Stmt) {
+ Test(R"(
+fn f() {
+ workgroupBarrier();
+}
+)");
+}
+
+TEST_F(IRToProgramRoundtripTest, BuiltinCall_Expr) {
+ Test(R"(
+fn f(a : i32, b : i32) {
+ var i : i32 = max(a, b);
+}
+)");
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Type Construct
////////////////////////////////////////////////////////////////////////////////
TEST_F(IRToProgramRoundtripTest, TypeConstruct_i32) {