Skip to content

Commit

Permalink
checkpoint before refactoring PooledObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Oct 1, 2024
1 parent 6822723 commit 563cc18
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/luisa/luisa-compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@
#include <luisa/xir/function.h>
#include <luisa/xir/ilist.h>
#include <luisa/xir/instruction.h>
#include <luisa/xir/instructions/branch.h>
#include <luisa/xir/metadata.h>
#include <luisa/xir/metadata/location.h>
#include <luisa/xir/name.h>
#include <luisa/xir/pool.h>
#include <luisa/xir/shared.h>
Expand Down
19 changes: 19 additions & 0 deletions include/luisa/xir/argument.h
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
#pragma once

#include <luisa/xir/value.h>

namespace luisa::compute::xir {

class Argument : public Value {

private:
bool _by_ref = false;

public:
explicit Argument(const Type *type = nullptr,
bool by_ref = false,
const Name *name = nullptr) noexcept;
void set_by_ref(bool by_ref) noexcept { _by_ref = by_ref; }
[[nodiscard]] auto by_ref() const noexcept { return _by_ref; }
};

}// namespace luisa::compute::xir
15 changes: 14 additions & 1 deletion include/luisa/xir/basic_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@ namespace luisa::compute::xir {
class Function;
class Instruction;

class LC_XIR_API BasicBlock : public Value {
class LC_XIR_API BasicBlock : public PooledObject {

private:
Function *_function = nullptr;
BasicBlock *_parent_block = nullptr;
const Name *_name = nullptr;
InlineInstructionList _instructions;

public:
explicit BasicBlock(Function *function = nullptr,
BasicBlock *parent_block = nullptr,
const Name *name = nullptr) noexcept;
void set_function(Function *function) noexcept;
void set_parent_block(BasicBlock *parent_block) noexcept;
void set_name(const Name *name) noexcept;
[[nodiscard]] auto function() const noexcept { return _function; }
[[nodiscard]] auto parent_block() const noexcept { return _parent_block; }
[[nodiscard]] auto name() const noexcept { return _name; }
[[nodiscard]] auto &instructions() noexcept { return _instructions; }
[[nodiscard]] auto &instructions() const noexcept { return _instructions; }
};

}// namespace luisa::compute::xir
9 changes: 9 additions & 0 deletions include/luisa/xir/function.h
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#pragma once

#include <luisa/xir/pool.h>

namespace luisa::compute::xir {

class Function : public PooledObject {
};

}// namespace luisa::compute::xir
19 changes: 19 additions & 0 deletions include/luisa/xir/instructions/branch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <luisa/xir/instruction.h>

namespace luisa::compute::xir {

class BasicBlock;

class BranchInst : public Instruction {

private:
BasicBlock *_true_block = nullptr;
BasicBlock *_false_block = nullptr;

public:

};

}// namespace luisa::compute::xir
8 changes: 8 additions & 0 deletions include/luisa/xir/instructions/loop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <luisa/xir/instruction.h>

namespace luisa::compute::xir {


}
9 changes: 9 additions & 0 deletions include/luisa/xir/metadata/location.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <luisa/xir/metadata.h>

namespace luisa::compute::xir {



}
11 changes: 11 additions & 0 deletions include/luisa/xir/shared.h
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
#pragma once

#include <luisa/xir/value.h>

namespace luisa::compute::xir {

class Shared : public Value {
public:
using Value::Value;
};

}// namespace luisa::compute::xir
7 changes: 7 additions & 0 deletions src/xir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ set(LUISA_COMPUTE_XIR_SOURCES
use.cpp
user.cpp
value.cpp

# derived instructions
instructions/branch.cpp
instructions/loop.cpp

# derived metadata
metadata/location.cpp
)

add_library(luisa-compute-xir SHARED ${LUISA_COMPUTE_XIR_SOURCES})
Expand Down
8 changes: 8 additions & 0 deletions src/xir/argument.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <luisa/xir/argument.h>

namespace luisa::compute::xir {

Argument::Argument(const Type *type, bool by_ref, const Name *name) noexcept
: Value{type, name}, _by_ref{by_ref} {}

}// namespace luisa::compute::xir
18 changes: 18 additions & 0 deletions src/xir/basic_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,22 @@

namespace luisa::compute::xir {

BasicBlock::BasicBlock(Function *function, BasicBlock *parent_block, const Name *name) noexcept
: _function{function}, _parent_block{parent_block}, _name{name} {
_instructions.head_sentinel()->set_parent_block(this);
_instructions.tail_sentinel()->set_parent_block(this);
}

void BasicBlock::set_function(Function *function) noexcept {
_function = function;
}

void BasicBlock::set_parent_block(BasicBlock *parent_block) noexcept {
_parent_block = parent_block;
}

void BasicBlock::set_name(const Name *name) noexcept {
_name = name;
}

}// namespace luisa::compute::xir
5 changes: 5 additions & 0 deletions src/xir/function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <luisa/xir/function.h>

namespace luisa::compute::xir {

}
7 changes: 6 additions & 1 deletion src/xir/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

namespace luisa::compute::xir {

Instruction::Instruction(const Type *type, BasicBlock *parent_block, const Name *name) noexcept
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 {
Super::remove_self();
set_parent_block(nullptr);
remove_operand_uses();
}

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

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

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

namespace luisa::compute::xir {

}
5 changes: 5 additions & 0 deletions src/xir/instructions/loop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <luisa/xir/instructions/loop.h>

namespace luisa::compute::xir {

}
7 changes: 7 additions & 0 deletions src/xir/metadata/location.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <luisa/xir/metadata/location.h>

namespace luisa::compute::xir {



}
5 changes: 5 additions & 0 deletions src/xir/shared.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <luisa/xir/shared.h>

namespace luisa::compute::xir {

}

0 comments on commit 563cc18

Please sign in to comment.