diff --git a/src/tint/ir/binary.h b/src/tint/ir/binary.h index 400e3819cb..503bf43c51 100644 --- a/src/tint/ir/binary.h +++ b/src/tint/ir/binary.h @@ -56,12 +56,12 @@ class Binary : public utils::Castable { /// @param lhs the lhs of the instruction /// @param rhs the rhs of the instruction Binary(Kind kind, Value* result, Value* lhs, Value* rhs); - Binary(const Binary& instr) = delete; - Binary(Binary&& instr) = delete; + Binary(const Binary& inst) = delete; + Binary(Binary&& inst) = delete; ~Binary() override; - Binary& operator=(const Binary& instr) = delete; - Binary& operator=(Binary&& instr) = delete; + Binary& operator=(const Binary& inst) = delete; + Binary& operator=(Binary&& inst) = delete; /// @returns the kind of instruction Kind GetKind() const { return kind_; } diff --git a/src/tint/ir/binary_test.cc b/src/tint/ir/binary_test.cc index 6be82f936a..13d7992e56 100644 --- a/src/tint/ir/binary_test.cc +++ b/src/tint/ir/binary_test.cc @@ -27,27 +27,27 @@ TEST_F(IR_InstructionTest, CreateAnd) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.And(b.builder.ir.types.Get(), b.builder.Constant(4_i), - b.builder.Constant(2_i)); + const auto* inst = b.builder.And(b.builder.ir.types.Get(), b.builder.Constant(4_i), + b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kAnd); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kAnd); - ASSERT_TRUE(instr->Result()->Is()); - ASSERT_NE(instr->Result()->Type(), nullptr); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + ASSERT_NE(inst->Result()->Type(), nullptr); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 & 2"); } @@ -55,26 +55,26 @@ TEST_F(IR_InstructionTest, CreateOr) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Or(b.builder.ir.types.Get(), b.builder.Constant(4_i), - b.builder.Constant(2_i)); + const auto* inst = b.builder.Or(b.builder.ir.types.Get(), b.builder.Constant(4_i), + b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kOr); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kOr); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 | 2"); } @@ -82,26 +82,26 @@ TEST_F(IR_InstructionTest, CreateXor) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Xor(b.builder.ir.types.Get(), b.builder.Constant(4_i), - b.builder.Constant(2_i)); + const auto* inst = b.builder.Xor(b.builder.ir.types.Get(), b.builder.Constant(4_i), + b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kXor); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kXor); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 ^ 2"); } @@ -109,26 +109,26 @@ TEST_F(IR_InstructionTest, CreateLogicalAnd) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.LogicalAnd(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.LogicalAnd(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kLogicalAnd); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalAnd); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 && 2"); } @@ -136,26 +136,26 @@ TEST_F(IR_InstructionTest, CreateLogicalOr) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.LogicalOr(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.LogicalOr(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kLogicalOr); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalOr); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 || 2"); } @@ -163,26 +163,26 @@ TEST_F(IR_InstructionTest, CreateEqual) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Equal(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.Equal(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kEqual); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kEqual); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 == 2"); } @@ -190,26 +190,26 @@ TEST_F(IR_InstructionTest, CreateNotEqual) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.NotEqual(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.NotEqual(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kNotEqual); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kNotEqual); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 != 2"); } @@ -217,26 +217,26 @@ TEST_F(IR_InstructionTest, CreateLessThan) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.LessThan(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.LessThan(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kLessThan); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kLessThan); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 < 2"); } @@ -244,26 +244,26 @@ TEST_F(IR_InstructionTest, CreateGreaterThan) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.GreaterThan(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.GreaterThan(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kGreaterThan); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kGreaterThan); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 > 2"); } @@ -271,26 +271,26 @@ TEST_F(IR_InstructionTest, CreateLessThanEqual) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.LessThanEqual(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.LessThanEqual(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kLessThanEqual); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kLessThanEqual); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 <= 2"); } @@ -298,26 +298,26 @@ TEST_F(IR_InstructionTest, CreateGreaterThanEqual) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.GreaterThanEqual( - b.builder.ir.types.Get(), b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.GreaterThanEqual(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kGreaterThanEqual); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kGreaterThanEqual); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = 4 >= 2"); } @@ -325,26 +325,26 @@ TEST_F(IR_InstructionTest, CreateShiftLeft) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.ShiftLeft(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.ShiftLeft(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kShiftLeft); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kShiftLeft); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 << 2"); } @@ -352,26 +352,26 @@ TEST_F(IR_InstructionTest, CreateShiftRight) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.ShiftRight(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.ShiftRight(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kShiftRight); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kShiftRight); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 >> 2"); } @@ -379,26 +379,26 @@ TEST_F(IR_InstructionTest, CreateAdd) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Add(b.builder.ir.types.Get(), b.builder.Constant(4_i), - b.builder.Constant(2_i)); + const auto* inst = b.builder.Add(b.builder.ir.types.Get(), b.builder.Constant(4_i), + b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kAdd); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kAdd); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 + 2"); } @@ -406,26 +406,26 @@ TEST_F(IR_InstructionTest, CreateSubtract) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Subtract(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.Subtract(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kSubtract); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kSubtract); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 - 2"); } @@ -433,26 +433,26 @@ TEST_F(IR_InstructionTest, CreateMultiply) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Multiply(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.Multiply(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kMultiply); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kMultiply); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 * 2"); } @@ -460,26 +460,26 @@ TEST_F(IR_InstructionTest, CreateDivide) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Divide(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.Divide(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kDivide); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kDivide); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 / 2"); } @@ -487,26 +487,26 @@ TEST_F(IR_InstructionTest, CreateModulo) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Modulo(b.builder.ir.types.Get(), - b.builder.Constant(4_i), b.builder.Constant(2_i)); + const auto* inst = b.builder.Modulo(b.builder.ir.types.Get(), + b.builder.Constant(4_i), b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kModulo); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kModulo); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->LHS()->Is()); - auto lhs = instr->LHS()->As()->value; + ASSERT_TRUE(inst->LHS()->Is()); + auto lhs = inst->LHS()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); - ASSERT_TRUE(instr->RHS()->Is()); - auto rhs = instr->RHS()->As()->value; + ASSERT_TRUE(inst->RHS()->Is()); + auto rhs = inst->RHS()->As()->value; ASSERT_TRUE(rhs->Is>()); EXPECT_EQ(2_i, rhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4 % 2"); } @@ -514,22 +514,22 @@ TEST_F(IR_InstructionTest, Binary_Usage) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.And(b.builder.ir.types.Get(), b.builder.Constant(4_i), - b.builder.Constant(2_i)); + const auto* inst = b.builder.And(b.builder.ir.types.Get(), b.builder.Constant(4_i), + b.builder.Constant(2_i)); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kAnd); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kAnd); - ASSERT_NE(instr->Result(), nullptr); - ASSERT_EQ(instr->Result()->Usage().Length(), 1u); - EXPECT_EQ(instr->Result()->Usage()[0], instr); + ASSERT_NE(inst->Result(), nullptr); + ASSERT_EQ(inst->Result()->Usage().Length(), 1u); + EXPECT_EQ(inst->Result()->Usage()[0], inst); - ASSERT_NE(instr->LHS(), nullptr); - ASSERT_EQ(instr->LHS()->Usage().Length(), 1u); - EXPECT_EQ(instr->LHS()->Usage()[0], instr); + ASSERT_NE(inst->LHS(), nullptr); + ASSERT_EQ(inst->LHS()->Usage().Length(), 1u); + EXPECT_EQ(inst->LHS()->Usage()[0], inst); - ASSERT_NE(instr->RHS(), nullptr); - ASSERT_EQ(instr->RHS()->Usage().Length(), 1u); - EXPECT_EQ(instr->RHS()->Usage()[0], instr); + ASSERT_NE(inst->RHS(), nullptr); + ASSERT_EQ(inst->RHS()->Usage().Length(), 1u); + EXPECT_EQ(inst->RHS()->Usage()[0], inst); } TEST_F(IR_InstructionTest, Binary_Usage_DuplicateValue) { @@ -538,19 +538,19 @@ TEST_F(IR_InstructionTest, Binary_Usage_DuplicateValue) { auto val = b.builder.Constant(4_i); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.And(b.builder.ir.types.Get(), val, val); + const auto* inst = b.builder.And(b.builder.ir.types.Get(), val, val); - EXPECT_EQ(instr->GetKind(), Binary::Kind::kAnd); + EXPECT_EQ(inst->GetKind(), Binary::Kind::kAnd); - ASSERT_NE(instr->Result(), nullptr); - ASSERT_EQ(instr->Result()->Usage().Length(), 1u); - EXPECT_EQ(instr->Result()->Usage()[0], instr); + ASSERT_NE(inst->Result(), nullptr); + ASSERT_EQ(inst->Result()->Usage().Length(), 1u); + EXPECT_EQ(inst->Result()->Usage()[0], inst); - ASSERT_EQ(instr->LHS(), instr->RHS()); + ASSERT_EQ(inst->LHS(), inst->RHS()); - ASSERT_NE(instr->LHS(), nullptr); - ASSERT_EQ(instr->LHS()->Usage().Length(), 1u); - EXPECT_EQ(instr->LHS()->Usage()[0], instr); + ASSERT_NE(inst->LHS(), nullptr); + ASSERT_EQ(inst->LHS()->Usage().Length(), 1u); + EXPECT_EQ(inst->LHS()->Usage()[0], inst); } } // namespace diff --git a/src/tint/ir/bitcast.h b/src/tint/ir/bitcast.h index c7d9cb8e6e..2faa959a0d 100644 --- a/src/tint/ir/bitcast.h +++ b/src/tint/ir/bitcast.h @@ -28,12 +28,12 @@ class Bitcast : public utils::Castable { /// @param result the result value /// @param val the value being bitcast Bitcast(Value* result, Value* val); - Bitcast(const Bitcast& instr) = delete; - Bitcast(Bitcast&& instr) = delete; + Bitcast(const Bitcast& inst) = delete; + Bitcast(Bitcast&& inst) = delete; ~Bitcast() override; - Bitcast& operator=(const Bitcast& instr) = delete; - Bitcast& operator=(Bitcast&& instr) = delete; + Bitcast& operator=(const Bitcast& inst) = delete; + Bitcast& operator=(Bitcast&& inst) = delete; /// @returns the left-hand-side value for the instruction const Value* Val() const { return val_; } diff --git a/src/tint/ir/bitcast_test.cc b/src/tint/ir/bitcast_test.cc index 2e6ca9dd90..62bef6b981 100644 --- a/src/tint/ir/bitcast_test.cc +++ b/src/tint/ir/bitcast_test.cc @@ -27,20 +27,20 @@ TEST_F(IR_InstructionTest, Bitcast) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = + const auto* inst = b.builder.Bitcast(b.builder.ir.types.Get(), b.builder.Constant(4_i)); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); - ASSERT_NE(instr->Result()->Type(), nullptr); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); + ASSERT_NE(inst->Result()->Type(), nullptr); - ASSERT_TRUE(instr->Val()->Is()); - auto val = instr->Val()->As()->value; + ASSERT_TRUE(inst->Val()->Is()); + auto val = inst->Val()->As()->value; ASSERT_TRUE(val->Is>()); EXPECT_EQ(4_i, val->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = bitcast(4)"); } @@ -48,16 +48,16 @@ TEST_F(IR_InstructionTest, Bitcast_Usage) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = + const auto* inst = b.builder.Bitcast(b.builder.ir.types.Get(), b.builder.Constant(4_i)); - ASSERT_NE(instr->Result(), nullptr); - ASSERT_EQ(instr->Result()->Usage().Length(), 1u); - EXPECT_EQ(instr->Result()->Usage()[0], instr); + ASSERT_NE(inst->Result(), nullptr); + ASSERT_EQ(inst->Result()->Usage().Length(), 1u); + EXPECT_EQ(inst->Result()->Usage()[0], inst); - ASSERT_NE(instr->Val(), nullptr); - ASSERT_EQ(instr->Val()->Usage().Length(), 1u); - EXPECT_EQ(instr->Val()->Usage()[0], instr); + ASSERT_NE(inst->Val(), nullptr); + ASSERT_EQ(inst->Val()->Usage().Length(), 1u); + EXPECT_EQ(inst->Val()->Usage()[0], inst); } } // namespace diff --git a/src/tint/ir/builder_impl.cc b/src/tint/ir/builder_impl.cc index 1f0f79aacb..ffa3fc079c 100644 --- a/src/tint/ir/builder_impl.cc +++ b/src/tint/ir/builder_impl.cc @@ -291,69 +291,69 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement* } auto* ty = lhs.Get()->Type(); - Binary* instr = nullptr; + Binary* inst = nullptr; switch (stmt->op) { case ast::BinaryOp::kAnd: - instr = builder.And(ty, lhs.Get(), rhs.Get()); + inst = builder.And(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kOr: - instr = builder.Or(ty, lhs.Get(), rhs.Get()); + inst = builder.Or(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kXor: - instr = builder.Xor(ty, lhs.Get(), rhs.Get()); + inst = builder.Xor(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLogicalAnd: - instr = builder.LogicalAnd(ty, lhs.Get(), rhs.Get()); + inst = builder.LogicalAnd(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLogicalOr: - instr = builder.LogicalOr(ty, lhs.Get(), rhs.Get()); + inst = builder.LogicalOr(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kEqual: - instr = builder.Equal(ty, lhs.Get(), rhs.Get()); + inst = builder.Equal(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kNotEqual: - instr = builder.NotEqual(ty, lhs.Get(), rhs.Get()); + inst = builder.NotEqual(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLessThan: - instr = builder.LessThan(ty, lhs.Get(), rhs.Get()); + inst = builder.LessThan(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kGreaterThan: - instr = builder.GreaterThan(ty, lhs.Get(), rhs.Get()); + inst = builder.GreaterThan(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLessThanEqual: - instr = builder.LessThanEqual(ty, lhs.Get(), rhs.Get()); + inst = builder.LessThanEqual(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kGreaterThanEqual: - instr = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get()); + inst = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kShiftLeft: - instr = builder.ShiftLeft(ty, lhs.Get(), rhs.Get()); + inst = builder.ShiftLeft(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kShiftRight: - instr = builder.ShiftRight(ty, lhs.Get(), rhs.Get()); + inst = builder.ShiftRight(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kAdd: - instr = builder.Add(ty, lhs.Get(), rhs.Get()); + inst = builder.Add(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kSubtract: - instr = builder.Subtract(ty, lhs.Get(), rhs.Get()); + inst = builder.Subtract(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kMultiply: - instr = builder.Multiply(ty, lhs.Get(), rhs.Get()); + inst = builder.Multiply(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kDivide: - instr = builder.Divide(ty, lhs.Get(), rhs.Get()); + inst = builder.Divide(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kModulo: - instr = builder.Modulo(ty, lhs.Get(), rhs.Get()); + inst = builder.Modulo(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kNone: TINT_ICE(IR, diagnostics_) << "missing binary operand type"; return; } - current_flow_block->instructions.Push(instr); + current_flow_block->instructions.Push(inst); - auto store = builder.Store(lhs.Get(), instr->Result()); + auto store = builder.Store(lhs.Get(), inst->Result()); current_flow_block->instructions.Push(store); } @@ -617,8 +617,8 @@ void BuilderImpl::EmitContinue(const ast::ContinueStatement*) { // discard that would probably make sense as a FlowNode but would then require figuring out the // multi-level exit that is triggered. void BuilderImpl::EmitDiscard(const ast::DiscardStatement*) { - auto* instr = builder.Discard(); - current_flow_block->instructions.Push(instr); + auto* inst = builder.Discard(); + current_flow_block->instructions.Push(inst); } void BuilderImpl::EmitBreakIf(const ast::BreakIfStatement* stmt) { @@ -718,27 +718,27 @@ utils::Result BuilderImpl::EmitUnary(const ast::UnaryOpExpression* expr) auto* sem = program_->Sem().Get(expr); auto* ty = sem->Type()->Clone(clone_ctx_.type_ctx); - Unary* instr = nullptr; + Unary* inst = nullptr; switch (expr->op) { case ast::UnaryOp::kAddressOf: - instr = builder.AddressOf(ty, val.Get()); + inst = builder.AddressOf(ty, val.Get()); break; case ast::UnaryOp::kComplement: - instr = builder.Complement(ty, val.Get()); + inst = builder.Complement(ty, val.Get()); break; case ast::UnaryOp::kIndirection: - instr = builder.Indirection(ty, val.Get()); + inst = builder.Indirection(ty, val.Get()); break; case ast::UnaryOp::kNegation: - instr = builder.Negation(ty, val.Get()); + inst = builder.Negation(ty, val.Get()); break; case ast::UnaryOp::kNot: - instr = builder.Not(ty, val.Get()); + inst = builder.Not(ty, val.Get()); break; } - current_flow_block->instructions.Push(instr); - return instr->Result(); + current_flow_block->instructions.Push(inst); + return inst->Result(); } utils::Result BuilderImpl::EmitBinary(const ast::BinaryExpression* expr) { @@ -755,69 +755,69 @@ utils::Result BuilderImpl::EmitBinary(const ast::BinaryExpression* expr) auto* sem = program_->Sem().Get(expr); auto* ty = sem->Type()->Clone(clone_ctx_.type_ctx); - Binary* instr = nullptr; + Binary* inst = nullptr; switch (expr->op) { case ast::BinaryOp::kAnd: - instr = builder.And(ty, lhs.Get(), rhs.Get()); + inst = builder.And(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kOr: - instr = builder.Or(ty, lhs.Get(), rhs.Get()); + inst = builder.Or(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kXor: - instr = builder.Xor(ty, lhs.Get(), rhs.Get()); + inst = builder.Xor(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLogicalAnd: - instr = builder.LogicalAnd(ty, lhs.Get(), rhs.Get()); + inst = builder.LogicalAnd(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLogicalOr: - instr = builder.LogicalOr(ty, lhs.Get(), rhs.Get()); + inst = builder.LogicalOr(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kEqual: - instr = builder.Equal(ty, lhs.Get(), rhs.Get()); + inst = builder.Equal(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kNotEqual: - instr = builder.NotEqual(ty, lhs.Get(), rhs.Get()); + inst = builder.NotEqual(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLessThan: - instr = builder.LessThan(ty, lhs.Get(), rhs.Get()); + inst = builder.LessThan(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kGreaterThan: - instr = builder.GreaterThan(ty, lhs.Get(), rhs.Get()); + inst = builder.GreaterThan(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kLessThanEqual: - instr = builder.LessThanEqual(ty, lhs.Get(), rhs.Get()); + inst = builder.LessThanEqual(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kGreaterThanEqual: - instr = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get()); + inst = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kShiftLeft: - instr = builder.ShiftLeft(ty, lhs.Get(), rhs.Get()); + inst = builder.ShiftLeft(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kShiftRight: - instr = builder.ShiftRight(ty, lhs.Get(), rhs.Get()); + inst = builder.ShiftRight(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kAdd: - instr = builder.Add(ty, lhs.Get(), rhs.Get()); + inst = builder.Add(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kSubtract: - instr = builder.Subtract(ty, lhs.Get(), rhs.Get()); + inst = builder.Subtract(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kMultiply: - instr = builder.Multiply(ty, lhs.Get(), rhs.Get()); + inst = builder.Multiply(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kDivide: - instr = builder.Divide(ty, lhs.Get(), rhs.Get()); + inst = builder.Divide(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kModulo: - instr = builder.Modulo(ty, lhs.Get(), rhs.Get()); + inst = builder.Modulo(ty, lhs.Get(), rhs.Get()); break; case ast::BinaryOp::kNone: TINT_ICE(IR, diagnostics_) << "missing binary operand type"; return utils::Failure; } - current_flow_block->instructions.Push(instr); - return instr->Result(); + current_flow_block->instructions.Push(inst); + return inst->Result(); } utils::Result BuilderImpl::EmitBitcast(const ast::BitcastExpression* expr) { @@ -828,10 +828,10 @@ utils::Result BuilderImpl::EmitBitcast(const ast::BitcastExpression* exp auto* sem = program_->Sem().Get(expr); auto* ty = sem->Type()->Clone(clone_ctx_.type_ctx); - auto* instr = builder.Bitcast(ty, val.Get()); + auto* inst = builder.Bitcast(ty, val.Get()); - current_flow_block->instructions.Push(instr); - return instr->Result(); + current_flow_block->instructions.Push(inst); + return inst->Result(); } void BuilderImpl::EmitCall(const ast::CallStatement* stmt) { @@ -874,29 +874,29 @@ utils::Result BuilderImpl::EmitCall(const ast::CallExpression* expr) { auto* ty = sem->Target()->ReturnType()->Clone(clone_ctx_.type_ctx); - Instruction* instr = nullptr; + Instruction* inst = nullptr; // If this is a builtin function, emit the specific builtin value if (auto* b = sem->Target()->As()) { - instr = builder.Builtin(ty, b->Type(), args); + inst = builder.Builtin(ty, b->Type(), args); } else if (sem->Target()->As()) { - instr = builder.Construct(ty, std::move(args)); + inst = builder.Construct(ty, std::move(args)); } else if (auto* conv = sem->Target()->As()) { auto* from = conv->Source()->Clone(clone_ctx_.type_ctx); - instr = builder.Convert(ty, from, std::move(args)); + inst = builder.Convert(ty, from, std::move(args)); } else if (expr->target->identifier->Is()) { TINT_UNIMPLEMENTED(IR, diagnostics_) << "missing templated ident support"; return utils::Failure; } else { // Not a builtin and not a templated call, so this is a user function. auto name = CloneSymbol(expr->target->identifier->symbol); - instr = builder.UserCall(ty, name, std::move(args)); + inst = builder.UserCall(ty, name, std::move(args)); } - if (instr == nullptr) { + if (inst == nullptr) { return utils::Failure; } - current_flow_block->instructions.Push(instr); - return instr->Result(); + current_flow_block->instructions.Push(inst); + return inst->Result(); } utils::Result BuilderImpl::EmitLiteral(const ast::LiteralExpression* lit) { diff --git a/src/tint/ir/builtin.h b/src/tint/ir/builtin.h index b1fd61d348..2367766448 100644 --- a/src/tint/ir/builtin.h +++ b/src/tint/ir/builtin.h @@ -30,12 +30,12 @@ class Builtin : public utils::Castable { /// @param func the builtin function /// @param args the conversion arguments Builtin(Value* result, builtin::Function func, utils::VectorRef args); - Builtin(const Builtin& instr) = delete; - Builtin(Builtin&& instr) = delete; + Builtin(const Builtin& inst) = delete; + Builtin(Builtin&& inst) = delete; ~Builtin() override; - Builtin& operator=(const Builtin& instr) = delete; - Builtin& operator=(Builtin&& instr) = delete; + Builtin& operator=(const Builtin& inst) = delete; + Builtin& operator=(Builtin&& inst) = delete; /// @returns the builtin function builtin::Function Func() const { return func_; } diff --git a/src/tint/ir/call.h b/src/tint/ir/call.h index e7bf68422c..4a237e0610 100644 --- a/src/tint/ir/call.h +++ b/src/tint/ir/call.h @@ -28,12 +28,12 @@ class Call : public utils::Castable { /// @param result the result value /// @param args the constructor arguments Call(Value* result, utils::VectorRef args); - Call(const Call& instr) = delete; - Call(Call&& instr) = delete; + Call(const Call& inst) = delete; + Call(Call&& inst) = delete; ~Call() override; - Call& operator=(const Call& instr) = delete; - Call& operator=(Call&& instr) = delete; + Call& operator=(const Call& inst) = delete; + Call& operator=(Call&& inst) = delete; /// @returns the constructor arguments utils::VectorRef Args() const { return args_; } diff --git a/src/tint/ir/construct.h b/src/tint/ir/construct.h index c9d18193c1..8d8a5107c4 100644 --- a/src/tint/ir/construct.h +++ b/src/tint/ir/construct.h @@ -28,12 +28,12 @@ class Construct : public utils::Castable { /// @param result the result value /// @param args the constructor arguments Construct(Value* result, utils::VectorRef args); - Construct(const Construct& instr) = delete; - Construct(Construct&& instr) = delete; + Construct(const Construct& inst) = delete; + Construct(Construct&& inst) = delete; ~Construct() override; - Construct& operator=(const Construct& instr) = delete; - Construct& operator=(Construct&& instr) = delete; + Construct& operator=(const Construct& inst) = delete; + Construct& operator=(Construct&& inst) = delete; /// Write the instruction to the given stream /// @param out the stream to write to diff --git a/src/tint/ir/convert.h b/src/tint/ir/convert.h index d157e0316e..082597ceff 100644 --- a/src/tint/ir/convert.h +++ b/src/tint/ir/convert.h @@ -30,12 +30,12 @@ class Convert : public utils::Castable { /// @param from the type being converted from /// @param args the conversion arguments Convert(Value* result, const type::Type* from, utils::VectorRef args); - Convert(const Convert& instr) = delete; - Convert(Convert&& instr) = delete; + Convert(const Convert& inst) = delete; + Convert(Convert&& inst) = delete; ~Convert() override; - Convert& operator=(const Convert& instr) = delete; - Convert& operator=(Convert&& instr) = delete; + Convert& operator=(const Convert& inst) = delete; + Convert& operator=(Convert&& inst) = delete; /// @returns the from type const type::Type* From() const { return from_; } diff --git a/src/tint/ir/disassembler.cc b/src/tint/ir/disassembler.cc index c3bb0061e1..506ec2d438 100644 --- a/src/tint/ir/disassembler.cc +++ b/src/tint/ir/disassembler.cc @@ -62,9 +62,9 @@ utils::StringStream& Disassembler::Indent() { } void Disassembler::EmitBlockInstructions(const Block* b) { - for (const auto* instr : b->instructions) { + for (const auto* inst : b->instructions) { Indent(); - instr->ToString(out_) << std::endl; + inst->ToString(out_) << std::endl; } } diff --git a/src/tint/ir/discard.h b/src/tint/ir/discard.h index b27dc9d0ad..52a8e95d91 100644 --- a/src/tint/ir/discard.h +++ b/src/tint/ir/discard.h @@ -27,12 +27,12 @@ class Discard : public utils::Castable { /// Constructor /// @param result the result id explicit Discard(Value* result); - Discard(const Discard& instr) = delete; - Discard(Discard&& instr) = delete; + Discard(const Discard& inst) = delete; + Discard(Discard&& inst) = delete; ~Discard() override; - Discard& operator=(const Discard& instr) = delete; - Discard& operator=(Discard&& instr) = delete; + Discard& operator=(const Discard& inst) = delete; + Discard& operator=(Discard&& inst) = delete; /// Write the instruction to the given stream /// @param out the stream to write to diff --git a/src/tint/ir/discard_test.cc b/src/tint/ir/discard_test.cc index 0f2fb5d281..6bace7dc7a 100644 --- a/src/tint/ir/discard_test.cc +++ b/src/tint/ir/discard_test.cc @@ -25,15 +25,15 @@ TEST_F(IR_InstructionTest, Discard) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = b.builder.Discard(); + const auto* inst = b.builder.Discard(); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); - ASSERT_NE(instr->Result()->Type(), nullptr); - ASSERT_NE(instr->Result()->Type()->As(), nullptr); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); + ASSERT_NE(inst->Result()->Type(), nullptr); + ASSERT_NE(inst->Result()->Type()->As(), nullptr); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (void) = discard"); } diff --git a/src/tint/ir/instruction.h b/src/tint/ir/instruction.h index df965e4704..e4f5589e6e 100644 --- a/src/tint/ir/instruction.h +++ b/src/tint/ir/instruction.h @@ -24,13 +24,13 @@ namespace tint::ir { /// An instruction in the IR. class Instruction : public utils::Castable { public: - Instruction(const Instruction& instr) = delete; - Instruction(Instruction&& instr) = delete; + Instruction(const Instruction& inst) = delete; + Instruction(Instruction&& inst) = delete; /// Destructor ~Instruction() override; - Instruction& operator=(const Instruction& instr) = delete; - Instruction& operator=(Instruction&& instr) = delete; + Instruction& operator=(const Instruction& inst) = delete; + Instruction& operator=(Instruction&& inst) = delete; /// @returns the result value for the instruction Value* Result() const { return result_; } diff --git a/src/tint/ir/store.h b/src/tint/ir/store.h index 57544fc9bc..2419441cd1 100644 --- a/src/tint/ir/store.h +++ b/src/tint/ir/store.h @@ -28,12 +28,12 @@ class Store : public utils::Castable { /// @param to the value to store too /// @param from the value being stored from Store(Value* to, Value* from); - Store(const Store& instr) = delete; - Store(Store&& instr) = delete; + Store(const Store& inst) = delete; + Store(Store&& inst) = delete; ~Store() override; - Store& operator=(const Store& instr) = delete; - Store& operator=(Store&& instr) = delete; + Store& operator=(const Store& inst) = delete; + Store& operator=(Store&& inst) = delete; /// @returns the value being stored const Value* from() const { return from_; } diff --git a/src/tint/ir/store_test.cc b/src/tint/ir/store_test.cc index e0632dd62a..87b96de9f6 100644 --- a/src/tint/ir/store_test.cc +++ b/src/tint/ir/store_test.cc @@ -29,19 +29,19 @@ TEST_F(IR_InstructionTest, CreateStore) { b.builder.next_runtime_id = Runtime::Id(42); auto* rt = b.builder.Runtime(b.builder.ir.types.Get()); - const auto* instr = b.builder.Store(rt, b.builder.Constant(4_i)); + const auto* inst = b.builder.Store(rt, b.builder.Constant(4_i)); - ASSERT_TRUE(instr->Result()->Is()); - ASSERT_NE(instr->Result()->Type(), nullptr); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + ASSERT_NE(inst->Result()->Type(), nullptr); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->from()->Is()); - auto lhs = instr->from()->As()->value; + ASSERT_TRUE(inst->from()->Is()); + auto lhs = inst->from()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = 4"); } @@ -50,15 +50,15 @@ TEST_F(IR_InstructionTest, Store_Usage) { b.builder.next_runtime_id = Runtime::Id(42); auto* rt = b.builder.Runtime(b.builder.ir.types.Get()); - const auto* instr = b.builder.Store(rt, b.builder.Constant(4_i)); + const auto* inst = b.builder.Store(rt, b.builder.Constant(4_i)); - ASSERT_NE(instr->Result(), nullptr); - ASSERT_EQ(instr->Result()->Usage().Length(), 1u); - EXPECT_EQ(instr->Result()->Usage()[0], instr); + ASSERT_NE(inst->Result(), nullptr); + ASSERT_EQ(inst->Result()->Usage().Length(), 1u); + EXPECT_EQ(inst->Result()->Usage()[0], inst); - ASSERT_NE(instr->from(), nullptr); - ASSERT_EQ(instr->from()->Usage().Length(), 1u); - EXPECT_EQ(instr->from()->Usage()[0], instr); + ASSERT_NE(inst->from(), nullptr); + ASSERT_EQ(inst->from()->Usage().Length(), 1u); + EXPECT_EQ(inst->from()->Usage()[0], inst); } } // namespace diff --git a/src/tint/ir/unary.h b/src/tint/ir/unary.h index 0337b4f2ce..54221c9e3a 100644 --- a/src/tint/ir/unary.h +++ b/src/tint/ir/unary.h @@ -38,12 +38,12 @@ class Unary : public utils::Castable { /// @param result the result value /// @param val the lhs of the instruction Unary(Kind kind, Value* result, Value* val); - Unary(const Unary& instr) = delete; - Unary(Unary&& instr) = delete; + Unary(const Unary& inst) = delete; + Unary(Unary&& inst) = delete; ~Unary() override; - Unary& operator=(const Unary& instr) = delete; - Unary& operator=(Unary&& instr) = delete; + Unary& operator=(const Unary& inst) = delete; + Unary& operator=(Unary&& inst) = delete; /// @returns the kind of instruction Kind GetKind() const { return kind_; } diff --git a/src/tint/ir/unary_test.cc b/src/tint/ir/unary_test.cc index cfc5579ada..4e028eb970 100644 --- a/src/tint/ir/unary_test.cc +++ b/src/tint/ir/unary_test.cc @@ -28,25 +28,25 @@ TEST_F(IR_InstructionTest, CreateAddressOf) { b.builder.next_runtime_id = Runtime::Id(42); // TODO(dsinclair): This would be better as an identifier, but works for now. - const auto* instr = + const auto* inst = b.builder.AddressOf(b.builder.ir.types.Get( b.builder.ir.types.Get(), builtin::AddressSpace::kPrivate, builtin::Access::kReadWrite), b.builder.Constant(4_i)); - EXPECT_EQ(instr->GetKind(), Unary::Kind::kAddressOf); + EXPECT_EQ(inst->GetKind(), Unary::Kind::kAddressOf); - ASSERT_TRUE(instr->Result()->Is()); - ASSERT_NE(instr->Result()->Type(), nullptr); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + ASSERT_NE(inst->Result()->Type(), nullptr); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->Val()->Is()); - auto lhs = instr->Val()->As()->value; + ASSERT_TRUE(inst->Val()->Is()); + auto lhs = inst->Val()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (ptr) = &4"); } @@ -54,21 +54,21 @@ TEST_F(IR_InstructionTest, CreateComplement) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = + const auto* inst = b.builder.Complement(b.builder.ir.types.Get(), b.builder.Constant(4_i)); - EXPECT_EQ(instr->GetKind(), Unary::Kind::kComplement); + EXPECT_EQ(inst->GetKind(), Unary::Kind::kComplement); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->Val()->Is()); - auto lhs = instr->Val()->As()->value; + ASSERT_TRUE(inst->Val()->Is()); + auto lhs = inst->Val()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = ~4"); } @@ -77,21 +77,21 @@ TEST_F(IR_InstructionTest, CreateIndirection) { b.builder.next_runtime_id = Runtime::Id(42); // TODO(dsinclair): This would be better as an identifier, but works for now. - const auto* instr = + const auto* inst = b.builder.Indirection(b.builder.ir.types.Get(), b.builder.Constant(4_i)); - EXPECT_EQ(instr->GetKind(), Unary::Kind::kIndirection); + EXPECT_EQ(inst->GetKind(), Unary::Kind::kIndirection); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->Val()->Is()); - auto lhs = instr->Val()->As()->value; + ASSERT_TRUE(inst->Val()->Is()); + auto lhs = inst->Val()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = *4"); } @@ -99,21 +99,21 @@ TEST_F(IR_InstructionTest, CreateNegation) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = + const auto* inst = b.builder.Negation(b.builder.ir.types.Get(), b.builder.Constant(4_i)); - EXPECT_EQ(instr->GetKind(), Unary::Kind::kNegation); + EXPECT_EQ(inst->GetKind(), Unary::Kind::kNegation); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->Val()->Is()); - auto lhs = instr->Val()->As()->value; + ASSERT_TRUE(inst->Val()->Is()); + auto lhs = inst->Val()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_EQ(4_i, lhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (i32) = -4"); } @@ -121,21 +121,21 @@ TEST_F(IR_InstructionTest, CreateNot) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = + const auto* inst = b.builder.Not(b.builder.ir.types.Get(), b.builder.Constant(true)); - EXPECT_EQ(instr->GetKind(), Unary::Kind::kNot); + EXPECT_EQ(inst->GetKind(), Unary::Kind::kNot); - ASSERT_TRUE(instr->Result()->Is()); - EXPECT_EQ(Runtime::Id(42), instr->Result()->As()->AsId()); + ASSERT_TRUE(inst->Result()->Is()); + EXPECT_EQ(Runtime::Id(42), inst->Result()->As()->AsId()); - ASSERT_TRUE(instr->Val()->Is()); - auto lhs = instr->Val()->As()->value; + ASSERT_TRUE(inst->Val()->Is()); + auto lhs = inst->Val()->As()->value; ASSERT_TRUE(lhs->Is>()); EXPECT_TRUE(lhs->As>()->ValueAs()); utils::StringStream str; - instr->ToString(str); + inst->ToString(str); EXPECT_EQ(str.str(), "%42 (bool) = !true"); } @@ -143,18 +143,18 @@ TEST_F(IR_InstructionTest, Unary_Usage) { auto& b = CreateEmptyBuilder(); b.builder.next_runtime_id = Runtime::Id(42); - const auto* instr = + const auto* inst = b.builder.Negation(b.builder.ir.types.Get(), b.builder.Constant(4_i)); - EXPECT_EQ(instr->GetKind(), Unary::Kind::kNegation); + EXPECT_EQ(inst->GetKind(), Unary::Kind::kNegation); - ASSERT_NE(instr->Result(), nullptr); - ASSERT_EQ(instr->Result()->Usage().Length(), 1u); - EXPECT_EQ(instr->Result()->Usage()[0], instr); + ASSERT_NE(inst->Result(), nullptr); + ASSERT_EQ(inst->Result()->Usage().Length(), 1u); + EXPECT_EQ(inst->Result()->Usage()[0], inst); - ASSERT_NE(instr->Val(), nullptr); - ASSERT_EQ(instr->Val()->Usage().Length(), 1u); - EXPECT_EQ(instr->Val()->Usage()[0], instr); + ASSERT_NE(inst->Val(), nullptr); + ASSERT_EQ(inst->Val()->Usage().Length(), 1u); + EXPECT_EQ(inst->Val()->Usage()[0], inst); } } // namespace diff --git a/src/tint/ir/user_call.h b/src/tint/ir/user_call.h index 0662455881..9cd0e6bfba 100644 --- a/src/tint/ir/user_call.h +++ b/src/tint/ir/user_call.h @@ -30,12 +30,12 @@ class UserCall : public utils::Castable { /// @param name the function name /// @param args the function arguments UserCall(Value* result, Symbol name, utils::VectorRef args); - UserCall(const UserCall& instr) = delete; - UserCall(UserCall&& instr) = delete; + UserCall(const UserCall& inst) = delete; + UserCall(UserCall&& inst) = delete; ~UserCall() override; - UserCall& operator=(const UserCall& instr) = delete; - UserCall& operator=(UserCall&& instr) = delete; + UserCall& operator=(const UserCall& inst) = delete; + UserCall& operator=(UserCall&& inst) = delete; /// @returns the function name Symbol Name() const { return name_; } diff --git a/src/tint/ir/value.h b/src/tint/ir/value.h index e2a642b3a4..e866f67fb3 100644 --- a/src/tint/ir/value.h +++ b/src/tint/ir/value.h @@ -40,8 +40,8 @@ class Value : public utils::Castable { Value& operator=(Value&&) = delete; /// Adds an instruction which uses this value. - /// @param instr the instruction - void AddUsage(const Instruction* instr) { uses_.Add(instr); } + /// @param inst the instruction + void AddUsage(const Instruction* inst) { uses_.Add(inst); } /// @returns the vector of instructions which use this value. An instruction will only be /// returned once even if that instruction uses the given value multiple times.