Skip to content

Commit ed37f7f

Browse files
hughperkinstaichi-gardener
authored andcommitted
adding boolean to builder
1 parent 96a5c46 commit ed37f7f

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

taichi/ir/ir_builder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ LoopIndexStmt *IRBuilder::get_loop_index(Stmt *loop, int index) {
138138
return insert(Stmt::make_typed<LoopIndexStmt>(loop, index));
139139
}
140140

141+
ConstStmt *IRBuilder::get_bool(bool value) {
142+
return insert(Stmt::make_typed<ConstStmt>(TypedConstant(
143+
TypeFactory::get_instance().get_primitive_type(PrimitiveTypeID::u1),
144+
value)));
145+
}
146+
141147
ConstStmt *IRBuilder::get_int32(int32 value) {
142148
return insert(Stmt::make_typed<ConstStmt>(TypedConstant(
143149
TypeFactory::get_instance().get_primitive_type(PrimitiveTypeID::i32),

taichi/ir/ir_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class IRBuilder {
130130
LoopIndexStmt *get_loop_index(Stmt *loop, int index = 0);
131131

132132
// Constants. TODO: add more types
133+
ConstStmt *get_bool(bool value);
133134
ConstStmt *get_int32(int32 value);
134135
ConstStmt *get_int64(int64 value);
135136
ConstStmt *get_uint32(uint32 value);

tests/cpp/ir/ir_builder_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44
#include "taichi/ir/statements.h"
55
#include "tests/cpp/program/test_program.h"
66
#include "tests/cpp/ir/ndarray_kernel.h"
7+
#include "taichi/ir/transforms.h"
78
#ifdef TI_WITH_VULKAN
89
#include "taichi/rhi/vulkan/vulkan_loader.h"
910
#endif
1011

1112
namespace taichi::lang {
1213

14+
TEST(IRBuilder, Bool) {
15+
IRBuilder builder;
16+
auto *bool_true = builder.get_bool(true);
17+
auto *bool_false = builder.get_bool(false);
18+
auto ir = builder.extract_ir();
19+
// auto *result = builder.create_print(bool_true, "", "");
20+
// auto *print = result->cast<PrintStmt>();
21+
auto print = irpass::make_pass_printer(true, true, "", bool_true);
22+
// irpass::re_id(ir);
23+
std::cout << std::flush;
24+
irpass::print(bool_true);
25+
std::cout << std::flush;
26+
std::cout << std::flush;
27+
irpass::print(bool_false);
28+
std::cout << std::flush;
29+
}
30+
1331
TEST(IRBuilder, Basic) {
1432
IRBuilder builder;
1533
auto *lhs = builder.get_int32(40);

0 commit comments

Comments
 (0)