Skip to content

Commit

Permalink
good
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Oct 1, 2024
1 parent 8b7faeb commit 6822723
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 20 deletions.
6 changes: 3 additions & 3 deletions include/luisa/ast/constant_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class LC_AST_API ConstantData {
friend class CallableLibrary;

private:
const Type *_type;
const std::byte *_raw;
uint64_t _hash;
const Type *_type = nullptr;
const std::byte *_raw = nullptr;
uint64_t _hash = 0ull;

private:
ConstantData(const Type *type, const std::byte *data, uint64_t hash) noexcept;
Expand Down
8 changes: 6 additions & 2 deletions include/luisa/xir/constant.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#pragma once

#include <luisa/ast/constant_data.h>
#include <luisa/xir/value.h>

namespace luisa::compute::xir {

class LC_XIR_API Constant : public Value {

private:
luisa::vector<std::byte> _data;
ConstantData _data;

public:

Constant() noexcept = default;
explicit Constant(ConstantData data, const Name *name = nullptr) noexcept;
void set_data(ConstantData data) noexcept;
[[nodiscard]] auto data() const noexcept { return _data; }
};

}// namespace luisa::compute::xir
11 changes: 9 additions & 2 deletions include/luisa/xir/ilist.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class IntrusiveListImpl : public concepts::Noncopyable {
template<typename T, typename Base = PooledObject>
class IntrusiveNode : public Base {

public:
using Super = IntrusiveNode;
using Base::Base;
static_assert(std::is_base_of_v<PooledObject, Base>);

private:
Expand Down Expand Up @@ -133,14 +136,14 @@ class IntrusiveNode : public Base {
assert(!node->is_linked() && "Inserting a linked node into a list.");
assert(!is_head_sentinel() && "Inserting before a head sentinel.");
node->_prev = _prev;
node->_next = this;
node->_next = static_cast<T *>(this);
_prev = node;
}
virtual void insert_after_self(T *node) noexcept {
assert(!node->is_linked() && "Inserting a linked node into a list.");
assert(!is_tail_sentinel() && "Inserting after a tail sentinel.");
node->_next = _next;
node->_prev = this;
node->_prev = static_cast<T *>(this);
_next = node;
}
};
Expand Down Expand Up @@ -231,6 +234,10 @@ class IntrusiveForwardList {
// intrusive node for singly-doubly linked lists
template<typename T, typename Base = PooledObject>
class IntrusiveForwardNode : public Base {

public:
using Super = IntrusiveForwardNode;
using Base::Base;
static_assert(std::is_base_of_v<PooledObject, Base>);

private:
Expand Down
4 changes: 3 additions & 1 deletion include/luisa/xir/instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class LC_XIR_API Instruction : public IntrusiveNode<Instruction, User> {
BasicBlock *_parent_block = nullptr;

public:
explicit Instruction(BasicBlock *parent_block = nullptr) noexcept;
explicit Instruction(const Type *type = nullptr,
BasicBlock *parent_block = nullptr,
const Name *name = nullptr) noexcept;
void remove_self() noexcept override;
void insert_before_self(Instruction *node) noexcept override;
void insert_after_self(Instruction *node) noexcept override;
Expand Down
1 change: 1 addition & 0 deletions include/luisa/xir/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LC_XIR_API User : public Value {
luisa::vector<Use *> _operands;

public:
using Value::Value;
void remove_operand_uses() noexcept;
void add_operand_uses() noexcept;
void set_operands(luisa::vector<Use *> operands) noexcept;
Expand Down
6 changes: 5 additions & 1 deletion include/luisa/xir/value.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include <luisa/ast/type.h>
#include <luisa/xir/use.h>
#include <luisa/xir/metadata.h>
#include <luisa/xir/name.h>

namespace luisa::compute {
class Type;
}// namespace luisa::compute

namespace luisa::compute::xir {

class LC_XIR_API Value : public PooledObject {
Expand All @@ -16,6 +19,7 @@ class LC_XIR_API Value : public PooledObject {
MetadataList _metadata_list;

public:
explicit Value(const Type *type = nullptr, const Name *name = nullptr) noexcept;
void set_type(const Type *type) noexcept { _type = type; }
void set_name(const Name *name) noexcept { _name = name; }

Expand Down
17 changes: 17 additions & 0 deletions src/xir/constant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <luisa/core/logging.h>
#include <luisa/xir/constant.h>

namespace luisa::compute::xir {

Constant::Constant(ConstantData data, const Name *name) noexcept
: Value{data.type(), name} { set_data(data); }

void Constant::set_data(ConstantData data) noexcept {
LUISA_DEBUG_ASSERT(data.type() == type(),
"Constant data type mismatch: {} vs {}",
data.type()->description(),
type()->description());
_data = data;
}

}// namespace luisa::compute::xir
10 changes: 5 additions & 5 deletions src/xir/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace luisa::compute::xir {

Instruction::Instruction(BasicBlock *parent_block) noexcept
: _parent_block{parent_block} {}
Instruction::Instruction(const Type *type, BasicBlock *parent_block, const Name *name) noexcept
: Super{type, name} { set_parent_block(parent_block); }

void Instruction::remove_self() noexcept {
IntrusiveNode::remove_self();
Super::remove_self();
remove_operand_uses();
}

void Instruction::insert_before_self(Instruction *node) noexcept {
IntrusiveNode::insert_before_self(node);
Super::insert_before_self(node);
node->add_operand_uses();
}

void Instruction::insert_after_self(Instruction *node) noexcept {
IntrusiveNode::insert_after_self(node);
Super::insert_after_self(node);
node->add_operand_uses();
}

Expand Down
6 changes: 3 additions & 3 deletions src/xir/use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ void Use::set_value(Value *value) noexcept {
if (_value == value) { return; }
remove_self();
_value = value;
if (_value) {
_value->use_list().insert_front(this);
if (_value != nullptr) {
add_to_list(_value->use_list());
}
}

void Use::set_user(User *user) noexcept {
_user = user;
if (!is_linked() && _value != nullptr) {
_value->use_list().insert_front(this);
add_to_list(_value->use_list());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/xir/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void User::remove_operand_uses() noexcept {
void User::add_operand_uses() noexcept {
for (auto o : _operands) {
if (auto value = o->value(); value && !o->is_linked()) {
value->use_list().insert_front(o);
o->add_to_list(value->use_list());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/xir/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace luisa::compute::xir {

Value::Value(const Type *type, const Name *name) noexcept
: _type{type}, _name{name} {}


}
}// namespace luisa::compute::xir

0 comments on commit 6822723

Please sign in to comment.