tint/ir: Replace getter with raw fields for more classes
There's an odd mix of IR classes that use raw fields, and others that have getters. Migrate a bunch of those getters to raw fields. Change-Id: I5c80abe16d3b4e6e5e9dc8f985611f9edfe5cdc6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131621 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Ben Clayton <bclayton@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
895d240fbf
commit
146b67e0cd
|
@ -19,8 +19,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Binary);
|
|||
|
||||
namespace tint::ir {
|
||||
|
||||
Binary::Binary(uint32_t id, Kind kind, const type::Type* ty, Value* lhs, Value* rhs)
|
||||
: Base(id, ty), kind_(kind), lhs_(lhs), rhs_(rhs) {
|
||||
Binary::Binary(uint32_t identifier, Kind kind, const type::Type* ty, Value* lhs, Value* rhs)
|
||||
: Base(identifier, ty), kind_(kind), lhs_(lhs), rhs_(rhs) {
|
||||
TINT_ASSERT(IR, lhs_);
|
||||
TINT_ASSERT(IR, rhs_);
|
||||
lhs_->AddUsage(this);
|
||||
|
|
|
@ -19,8 +19,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Bitcast);
|
|||
|
||||
namespace tint::ir {
|
||||
|
||||
Bitcast::Bitcast(uint32_t id, const type::Type* type, Value* val)
|
||||
: Base(id, type, utils::Vector{val}) {}
|
||||
Bitcast::Bitcast(uint32_t identifier, const type::Type* ty, Value* val)
|
||||
: Base(identifier, ty, utils::Vector{val}) {}
|
||||
|
||||
Bitcast::~Bitcast() = default;
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ TEST_F(IR_InstructionTest, Bitcast) {
|
|||
ASSERT_TRUE(inst->Is<ir::Bitcast>());
|
||||
ASSERT_NE(inst->Type(), nullptr);
|
||||
|
||||
ASSERT_EQ(inst->Args().Length(), 1u);
|
||||
ASSERT_TRUE(inst->Args()[0]->Is<Constant>());
|
||||
auto val = inst->Args()[0]->As<Constant>()->value;
|
||||
ASSERT_EQ(inst->args.Length(), 1u);
|
||||
ASSERT_TRUE(inst->args[0]->Is<Constant>());
|
||||
auto val = inst->args[0]->As<Constant>()->value;
|
||||
ASSERT_TRUE(val->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(4_i, val->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ TEST_F(IR_InstructionTest, Bitcast_Usage) {
|
|||
const auto* inst =
|
||||
b.builder.Bitcast(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i));
|
||||
|
||||
ASSERT_EQ(inst->Args().Length(), 1u);
|
||||
ASSERT_NE(inst->Args()[0], nullptr);
|
||||
ASSERT_EQ(inst->Args()[0]->Usage().Length(), 1u);
|
||||
EXPECT_EQ(inst->Args()[0]->Usage()[0], inst);
|
||||
ASSERT_EQ(inst->args.Length(), 1u);
|
||||
ASSERT_NE(inst->args[0], nullptr);
|
||||
ASSERT_EQ(inst->args[0]->Usage().Length(), 1u);
|
||||
EXPECT_EQ(inst->args[0]->Usage()[0], inst);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ir/builtin.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/debug.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ir::Builtin);
|
||||
|
@ -20,11 +23,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Builtin);
|
|||
// \cond DO_NOT_DOCUMENT
|
||||
namespace tint::ir {
|
||||
|
||||
Builtin::Builtin(uint32_t id,
|
||||
const type::Type* type,
|
||||
Builtin::Builtin(uint32_t identifier,
|
||||
const type::Type* ty,
|
||||
builtin::Function func,
|
||||
utils::VectorRef<Value*> args)
|
||||
: Base(id, type, args), func_(func) {}
|
||||
utils::VectorRef<Value*> arguments)
|
||||
: Base(identifier, ty, std::move(arguments)), func_(func) {}
|
||||
|
||||
Builtin::~Builtin() = default;
|
||||
|
||||
|
|
|
@ -14,14 +14,14 @@
|
|||
|
||||
#include "src/tint/ir/call.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ir::Call);
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
Call::Call() : Base() {}
|
||||
|
||||
Call::Call(uint32_t id, const type::Type* type, utils::VectorRef<Value*> args)
|
||||
: Base(id, type), args_(args) {
|
||||
Call::Call(uint32_t identifier, const type::Type* ty, utils::VectorRef<Value*> arguments)
|
||||
: Base(identifier, ty), args(std::move(arguments)) {
|
||||
for (auto* arg : args) {
|
||||
arg->AddUsage(this);
|
||||
}
|
||||
|
|
|
@ -30,20 +30,17 @@ class Call : public utils::Castable<Call, Instruction> {
|
|||
Call& operator=(const Call& inst) = delete;
|
||||
Call& operator=(Call&& inst) = delete;
|
||||
|
||||
/// @returns the constructor arguments
|
||||
utils::VectorRef<Value*> Args() const { return args_; }
|
||||
/// The constructor arguments
|
||||
utils::Vector<Value*, 1> args;
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
Call();
|
||||
Call() = delete;
|
||||
/// Constructor
|
||||
/// @param id the instruction id
|
||||
/// @param type the result type
|
||||
/// @param args the constructor arguments
|
||||
Call(uint32_t id, const type::Type* type, utils::VectorRef<Value*> args);
|
||||
|
||||
private:
|
||||
utils::Vector<Value*, 1> args_;
|
||||
};
|
||||
|
||||
} // namespace tint::ir
|
||||
|
|
|
@ -13,14 +13,17 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ir/construct.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/debug.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ir::Construct);
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
Construct::Construct(uint32_t id, const type::Type* type, utils::VectorRef<Value*> args)
|
||||
: Base(id, type, args) {}
|
||||
Construct::Construct(uint32_t identifier, const type::Type* ty, utils::VectorRef<Value*> arguments)
|
||||
: Base(identifier, ty, std::move(arguments)) {}
|
||||
|
||||
Construct::~Construct() = default;
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Convert);
|
|||
|
||||
namespace tint::ir {
|
||||
|
||||
Convert::Convert(uint32_t id,
|
||||
Convert::Convert(uint32_t identifier,
|
||||
const type::Type* to_type,
|
||||
const type::Type* from_type,
|
||||
utils::VectorRef<Value*> args)
|
||||
: Base(id, to_type, args), from_type_(from_type) {}
|
||||
utils::VectorRef<Value*> arguments)
|
||||
: Base(identifier, to_type, arguments), from_type_(from_type) {}
|
||||
|
||||
Convert::~Convert() = default;
|
||||
|
||||
|
|
|
@ -355,7 +355,11 @@ void Disassembler::EmitValue(const Value* val) {
|
|||
emit(constant->value);
|
||||
},
|
||||
[&](const ir::Instruction* i) {
|
||||
out_ << "%" << std::to_string(i->Id());
|
||||
if (i->id == ir::Instruction::kNoID) {
|
||||
out_ << "<no-id>";
|
||||
} else {
|
||||
out_ << "%" << i->id;
|
||||
}
|
||||
if (i->Type() != nullptr) {
|
||||
out_ << ":" << i->Type()->FriendlyName();
|
||||
}
|
||||
|
@ -389,27 +393,27 @@ void Disassembler::EmitInstruction(const Instruction* inst) {
|
|||
},
|
||||
[&](const ir::Store* s) {
|
||||
out_ << "store ";
|
||||
EmitValue(s->To());
|
||||
EmitValue(s->to);
|
||||
out_ << ", ";
|
||||
EmitValue(s->From());
|
||||
EmitValue(s->from);
|
||||
},
|
||||
[&](const ir::UserCall* uc) {
|
||||
EmitValue(uc);
|
||||
out_ << " = call " << uc->Name().Name();
|
||||
if (uc->Args().Length() > 0) {
|
||||
out_ << " = call " << uc->name.Name();
|
||||
if (uc->args.Length() > 0) {
|
||||
out_ << ", ";
|
||||
}
|
||||
EmitArgs(uc);
|
||||
},
|
||||
[&](const ir::Var* v) {
|
||||
EmitValue(v);
|
||||
out_ << " = var " << v->AddressSpace() << " " << v->Access();
|
||||
out_ << " = var " << v->address_space << " " << v->access;
|
||||
});
|
||||
}
|
||||
|
||||
void Disassembler::EmitArgs(const Call* call) {
|
||||
bool first = true;
|
||||
for (const auto* arg : call->Args()) {
|
||||
for (const auto* arg : call->args) {
|
||||
if (!first) {
|
||||
out_ << ", ";
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Discard);
|
|||
|
||||
namespace tint::ir {
|
||||
|
||||
Discard::Discard() : Base() {}
|
||||
Discard::Discard() : Base(kNoID, nullptr, utils::Empty) {}
|
||||
|
||||
Discard::~Discard() = default;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace tint::ir {
|
|||
|
||||
Instruction::Instruction() = default;
|
||||
|
||||
Instruction::Instruction(uint32_t id, const type::Type* ty) : id_(id), type_(ty) {}
|
||||
Instruction::Instruction(uint32_t identifier, const type::Type* ty) : id(identifier), type(ty) {}
|
||||
|
||||
Instruction::~Instruction() = default;
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ namespace tint::ir {
|
|||
/// An instruction in the IR.
|
||||
class Instruction : public utils::Castable<Instruction, Value> {
|
||||
public:
|
||||
/// The identifier used by instructions that have no value.
|
||||
static constexpr uint32_t kNoID = 0;
|
||||
|
||||
Instruction(const Instruction& inst) = delete;
|
||||
Instruction(Instruction&& inst) = delete;
|
||||
/// Destructor
|
||||
|
@ -31,10 +34,14 @@ class Instruction : public utils::Castable<Instruction, Value> {
|
|||
Instruction& operator=(const Instruction& inst) = delete;
|
||||
Instruction& operator=(Instruction&& inst) = delete;
|
||||
|
||||
/// @returns the id of the instruction
|
||||
uint32_t Id() const { return id_; }
|
||||
/// @returns the type of the value
|
||||
const type::Type* Type() const override { return type_; }
|
||||
const type::Type* Type() const override { return type; }
|
||||
|
||||
/// The instruction identifier
|
||||
const uint32_t id = kNoID;
|
||||
|
||||
/// The instruction type
|
||||
const type::Type* type = nullptr;
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
|
@ -43,10 +50,6 @@ class Instruction : public utils::Castable<Instruction, Value> {
|
|||
/// @param id the instruction id
|
||||
/// @param type the result type
|
||||
Instruction(uint32_t id, const type::Type* type);
|
||||
|
||||
private:
|
||||
uint32_t id_ = 0;
|
||||
const type::Type* type_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace tint::ir
|
||||
|
|
|
@ -19,11 +19,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Store);
|
|||
|
||||
namespace tint::ir {
|
||||
|
||||
Store::Store(Value* to, Value* from) : Base(), to_(to), from_(from) {
|
||||
TINT_ASSERT(IR, to_);
|
||||
TINT_ASSERT(IR, from_);
|
||||
to_->AddUsage(this);
|
||||
from_->AddUsage(this);
|
||||
Store::Store(Value* t, Value* f) : Base(), to(t), from(f) {
|
||||
TINT_ASSERT(IR, to);
|
||||
TINT_ASSERT(IR, from);
|
||||
to->AddUsage(this);
|
||||
from->AddUsage(this);
|
||||
}
|
||||
|
||||
Store::~Store() = default;
|
||||
|
|
|
@ -34,14 +34,10 @@ class Store : public utils::Castable<Store, Instruction> {
|
|||
Store& operator=(const Store& inst) = delete;
|
||||
Store& operator=(Store&& inst) = delete;
|
||||
|
||||
/// @returns the value being stored too
|
||||
const Value* To() const { return to_; }
|
||||
/// @returns the value being stored
|
||||
const Value* From() const { return from_; }
|
||||
|
||||
private:
|
||||
Value* to_ = nullptr;
|
||||
Value* from_ = nullptr;
|
||||
/// the value being stored to
|
||||
Value* to = nullptr;
|
||||
/// the value being stored
|
||||
Value* from = nullptr;
|
||||
};
|
||||
|
||||
} // namespace tint::ir
|
||||
|
|
|
@ -31,10 +31,10 @@ TEST_F(IR_InstructionTest, CreateStore) {
|
|||
const auto* inst = b.builder.Store(to, b.builder.Constant(4_i));
|
||||
|
||||
ASSERT_TRUE(inst->Is<Store>());
|
||||
ASSERT_EQ(inst->To(), to);
|
||||
ASSERT_EQ(inst->to, to);
|
||||
|
||||
ASSERT_TRUE(inst->From()->Is<Constant>());
|
||||
auto lhs = inst->From()->As<Constant>()->value;
|
||||
ASSERT_TRUE(inst->from->Is<Constant>());
|
||||
auto lhs = inst->from->As<Constant>()->value;
|
||||
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
}
|
||||
|
@ -45,13 +45,13 @@ TEST_F(IR_InstructionTest, Store_Usage) {
|
|||
auto* to = b.builder.Discard();
|
||||
const auto* inst = b.builder.Store(to, b.builder.Constant(4_i));
|
||||
|
||||
ASSERT_NE(inst->To(), nullptr);
|
||||
ASSERT_EQ(inst->To()->Usage().Length(), 1u);
|
||||
EXPECT_EQ(inst->To()->Usage()[0], inst);
|
||||
ASSERT_NE(inst->to, nullptr);
|
||||
ASSERT_EQ(inst->to->Usage().Length(), 1u);
|
||||
EXPECT_EQ(inst->to->Usage()[0], inst);
|
||||
|
||||
ASSERT_NE(inst->From(), nullptr);
|
||||
ASSERT_EQ(inst->From()->Usage().Length(), 1u);
|
||||
EXPECT_EQ(inst->From()->Usage()[0], inst);
|
||||
ASSERT_NE(inst->from, nullptr);
|
||||
ASSERT_EQ(inst->from->Usage().Length(), 1u);
|
||||
EXPECT_EQ(inst->from->Usage()[0], inst);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -19,8 +19,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Unary);
|
|||
|
||||
namespace tint::ir {
|
||||
|
||||
Unary::Unary(uint32_t id, Kind kind, const type::Type* type, Value* val)
|
||||
: Base(id, type), kind_(kind), val_(val) {
|
||||
Unary::Unary(uint32_t identifier, Kind kind, const type::Type* ty, Value* val)
|
||||
: Base(identifier, ty), kind_(kind), val_(val) {
|
||||
TINT_ASSERT(IR, val_);
|
||||
val_->AddUsage(this);
|
||||
}
|
||||
|
|
|
@ -13,14 +13,20 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ir/user_call.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/debug.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ir::UserCall);
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
UserCall::UserCall(uint32_t id, const type::Type* type, Symbol name, utils::VectorRef<Value*> args)
|
||||
: Base(id, type, args), name_(name) {}
|
||||
UserCall::UserCall(uint32_t identifier,
|
||||
const type::Type* ty,
|
||||
Symbol n,
|
||||
utils::VectorRef<Value*> arguments)
|
||||
: Base(identifier, ty, std::move(arguments)), name(n) {}
|
||||
|
||||
UserCall::~UserCall() = default;
|
||||
|
||||
|
|
|
@ -37,11 +37,8 @@ class UserCall : public utils::Castable<UserCall, Call> {
|
|||
UserCall& operator=(const UserCall& inst) = delete;
|
||||
UserCall& operator=(UserCall&& inst) = delete;
|
||||
|
||||
/// @returns the function name
|
||||
Symbol Name() const { return name_; }
|
||||
|
||||
private:
|
||||
Symbol name_{};
|
||||
/// The function name
|
||||
Symbol name;
|
||||
};
|
||||
|
||||
} // namespace tint::ir
|
||||
|
|
|
@ -19,11 +19,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Var);
|
|||
|
||||
namespace tint::ir {
|
||||
|
||||
Var::Var(uint32_t id,
|
||||
Var::Var(uint32_t identifier,
|
||||
const type::Type* ty,
|
||||
builtin::AddressSpace address_space,
|
||||
builtin::Access access)
|
||||
: Base(id, ty), address_space_(address_space), access_(access) {}
|
||||
builtin::AddressSpace addr_space,
|
||||
builtin::Access acc)
|
||||
: Base(identifier, ty), address_space(addr_space), access(acc) {}
|
||||
|
||||
Var::~Var() = default;
|
||||
|
||||
|
|
|
@ -41,15 +41,11 @@ class Var : public utils::Castable<Var, Instruction> {
|
|||
Var& operator=(const Var& inst) = delete;
|
||||
Var& operator=(Var&& inst) = delete;
|
||||
|
||||
/// @returns the address space
|
||||
builtin::AddressSpace AddressSpace() const { return address_space_; }
|
||||
/// The variable address space
|
||||
builtin::AddressSpace address_space = builtin::AddressSpace::kUndefined;
|
||||
|
||||
/// @returns the access mode
|
||||
builtin::Access Access() const { return access_; }
|
||||
|
||||
private:
|
||||
builtin::AddressSpace address_space_;
|
||||
builtin::Access access_;
|
||||
/// The variable access mode
|
||||
builtin::Access access = builtin::Access::kUndefined;
|
||||
};
|
||||
|
||||
} // namespace tint::ir
|
||||
|
|
|
@ -423,9 +423,9 @@ class Castable : public BASE {
|
|||
using TrueBase = BASE;
|
||||
|
||||
/// Constructor
|
||||
/// @param args the arguments to forward to the base class.
|
||||
/// @param arguments the arguments to forward to the base class.
|
||||
template <typename... ARGS>
|
||||
inline explicit Castable(ARGS&&... args) : TrueBase(std::forward<ARGS>(args)...) {
|
||||
inline explicit Castable(ARGS&&... arguments) : TrueBase(std::forward<ARGS>(arguments)...) {
|
||||
this->type_info_ = &TypeInfo::Of<CLASS>();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue