Add Op* prefix to instructions that have to be emited

This commit is contained in:
ReinUsesLisp 2018-10-31 21:22:00 -03:00
parent ba3a3a74d7
commit a08aeec982
15 changed files with 149 additions and 144 deletions

View file

@ -7,10 +7,10 @@ add_library(sirit
stream.h
operand.cpp
operand.h
literal-number.cpp
literal-number.h
literal-string.cpp
literal-string.h
literal_number.cpp
literal_number.h
literal_string.cpp
literal_string.h
common_types.h
insts.h
insts/type.cpp

View file

@ -10,31 +10,31 @@
namespace Sirit {
Ref Module::ConstantTrue(Ref result_type) {
Ref Module::OpConstantTrue(Ref result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantTrue, bound, result_type));
}
Ref Module::ConstantFalse(Ref result_type) {
Ref Module::OpConstantFalse(Ref result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantFalse, bound, result_type));
}
Ref Module::Constant(Ref result_type, const Literal& literal) {
Ref Module::OpConstant(Ref result_type, const Literal& literal) {
auto op{new Op(spv::Op::OpConstant, bound, result_type)};
op->Add(literal);
return AddDeclaration(op);
}
Ref Module::ConstantComposite(Ref result_type,
const std::vector<Ref>& constituents) {
Ref Module::OpConstantComposite(Ref result_type,
const std::vector<Ref>& constituents) {
auto op{new Op(spv::Op::OpConstantComposite, bound, result_type)};
op->Add(constituents);
return AddDeclaration(op);
}
Ref Module::ConstantSampler(Ref result_type,
spv::SamplerAddressingMode addressing_mode,
bool normalized,
spv::SamplerFilterMode filter_mode) {
Ref Module::OpConstantSampler(Ref result_type,
spv::SamplerAddressingMode addressing_mode,
bool normalized,
spv::SamplerFilterMode filter_mode) {
AddCapability(spv::Capability::LiteralSampler);
AddCapability(spv::Capability::Kernel);
auto op{new Op(spv::Op::OpConstantSampler, bound, result_type)};
@ -44,7 +44,7 @@ Ref Module::ConstantSampler(Ref result_type,
return AddDeclaration(op);
}
Ref Module::ConstantNull(Ref result_type) {
Ref Module::OpConstantNull(Ref result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantNull, bound, result_type));
}

View file

@ -9,7 +9,7 @@
namespace Sirit {
Ref Module::Name(Ref target, const std::string& name) {
Ref Module::OpName(Ref target, const std::string& name) {
auto op{new Op(spv::Op::OpName)};
op->Add(target);
op->Add(name);

View file

@ -9,9 +9,9 @@
namespace Sirit {
Ref Module::LoopMerge(Ref merge_block, Ref continue_target,
spv::LoopControlMask loop_control,
const std::vector<Ref>& literals) {
Ref Module::OpLoopMerge(Ref merge_block, Ref continue_target,
spv::LoopControlMask loop_control,
const std::vector<Ref>& literals) {
auto op{new Op(spv::Op::OpLoopMerge)};
op->Add(merge_block);
op->Add(continue_target);
@ -20,25 +20,25 @@ Ref Module::LoopMerge(Ref merge_block, Ref continue_target,
return AddCode(op);
}
Ref Module::SelectionMerge(Ref merge_block,
spv::SelectionControlMask selection_control) {
Ref Module::OpSelectionMerge(Ref merge_block,
spv::SelectionControlMask selection_control) {
auto op{new Op(spv::Op::OpSelectionMerge)};
op->Add(merge_block);
AddEnum(op, selection_control);
return AddCode(op);
}
Ref Module::Label() { return AddCode(spv::Op::OpLabel, bound++); }
Ref Module::OpLabel() { return AddCode(spv::Op::OpLabel, bound++); }
Ref Module::Branch(Ref target_label) {
Ref Module::OpBranch(Ref target_label) {
auto op{new Op(spv::Op::OpBranch)};
op->Add(target_label);
return AddCode(op);
}
Ref Module::BranchConditional(Ref condition, Ref true_label, Ref false_label,
std::uint32_t true_weight,
std::uint32_t false_weight) {
Ref Module::OpBranchConditional(Ref condition, Ref true_label, Ref false_label,
std::uint32_t true_weight,
std::uint32_t false_weight) {
auto op{new Op(spv::Op::OpBranchConditional)};
op->Add(condition);
op->Add(true_label);
@ -50,6 +50,6 @@ Ref Module::BranchConditional(Ref condition, Ref true_label, Ref false_label,
return AddCode(op);
}
Ref Module::Return() { return AddCode(spv::Op::OpReturn); }
Ref Module::OpReturn() { return AddCode(spv::Op::OpReturn); }
} // namespace Sirit

View file

@ -9,14 +9,15 @@
namespace Sirit {
Ref Module::Function(Ref result_type, spv::FunctionControlMask function_control,
Ref function_type) {
Ref Module::OpFunction(Ref result_type,
spv::FunctionControlMask function_control,
Ref function_type) {
auto op{new Op{spv::Op::OpFunction, bound++, result_type}};
op->Add(static_cast<u32>(function_control));
op->Add(function_type);
return AddCode(op);
}
Ref Module::FunctionEnd() { return AddCode(spv::Op::OpFunctionEnd); }
Ref Module::OpFunctionEnd() { return AddCode(spv::Op::OpFunctionEnd); }
} // namespace Sirit

View file

@ -10,8 +10,8 @@
namespace Sirit {
Ref Module::Variable(Ref result_type, spv::StorageClass storage_class,
Ref initializer) {
Ref Module::OpVariable(Ref result_type, spv::StorageClass storage_class,
Ref initializer) {
auto op{new Op(spv::Op::OpVariable, bound++, result_type)};
AddEnum(op, storage_class);
if (initializer) {
@ -20,8 +20,8 @@ Ref Module::Variable(Ref result_type, spv::StorageClass storage_class,
return AddCode(op);
}
Ref Module::Load(Ref result_type, Ref pointer,
std::optional<spv::MemoryAccessMask> memory_access) {
Ref Module::OpLoad(Ref result_type, Ref pointer,
std::optional<spv::MemoryAccessMask> memory_access) {
auto op{new Op(spv::Op::OpLoad, bound++, result_type)};
op->Add(pointer);
if (memory_access) {
@ -30,8 +30,8 @@ Ref Module::Load(Ref result_type, Ref pointer,
return AddCode(op);
}
Ref Module::Store(Ref pointer, Ref object,
std::optional<spv::MemoryAccessMask> memory_access) {
Ref Module::OpStore(Ref pointer, Ref object,
std::optional<spv::MemoryAccessMask> memory_access) {
auto op{new Op(spv::Op::OpStore)};
op->Add(pointer);
op->Add(object);
@ -41,8 +41,8 @@ Ref Module::Store(Ref pointer, Ref object,
return AddCode(op);
}
Ref Module::AccessChain(Ref result_type, Ref base,
const std::vector<Ref>& indexes) {
Ref Module::OpAccessChain(Ref result_type, Ref base,
const std::vector<Ref>& indexes) {
assert(indexes.size() > 0);
auto op{new Op(spv::Op::OpAccessChain, bound++, result_type)};
op->Add(base);
@ -50,8 +50,8 @@ Ref Module::AccessChain(Ref result_type, Ref base,
return AddCode(op);
}
Ref Module::CompositeInsert(Ref result_type, Ref object, Ref composite,
const std::vector<Literal>& indexes) {
Ref Module::OpCompositeInsert(Ref result_type, Ref object, Ref composite,
const std::vector<Literal>& indexes) {
auto op{new Op(spv::Op::OpCompositeInsert, bound++, result_type)};
op->Add(object);
op->Add(composite);

View file

@ -10,7 +10,7 @@
namespace Sirit {
Ref Module::Undef(Ref result_type) {
Ref Module::OpUndef(Ref result_type) {
return AddCode(new Op(spv::Op::OpUndef, bound++, result_type));
}

View file

@ -12,15 +12,15 @@
namespace Sirit {
Ref Module::TypeVoid() {
Ref Module::OpTypeVoid() {
return AddDeclaration(new Op(spv::Op::OpTypeVoid, bound));
}
Ref Module::TypeBool() {
Ref Module::OpTypeBool() {
return AddDeclaration(new Op(spv::Op::OpTypeBool, bound));
}
Ref Module::TypeInt(int width, bool is_signed) {
Ref Module::OpTypeInt(int width, bool is_signed) {
if (width == 8) {
AddCapability(spv::Capability::Int8);
} else if (width == 16) {
@ -34,7 +34,7 @@ Ref Module::TypeInt(int width, bool is_signed) {
return AddDeclaration(op);
}
Ref Module::TypeFloat(int width) {
Ref Module::OpTypeFloat(int width) {
if (width == 16) {
AddCapability(spv::Capability::Float16);
} else if (width == 64) {
@ -45,7 +45,7 @@ Ref Module::TypeFloat(int width) {
return AddDeclaration(op);
}
Ref Module::TypeVector(Ref component_type, int component_count) {
Ref Module::OpTypeVector(Ref component_type, int component_count) {
assert(component_count >= 2);
auto op{new Op(spv::Op::OpTypeVector, bound)};
op->Add(component_type);
@ -53,7 +53,7 @@ Ref Module::TypeVector(Ref component_type, int component_count) {
return AddDeclaration(op);
}
Ref Module::TypeMatrix(Ref column_type, int column_count) {
Ref Module::OpTypeMatrix(Ref column_type, int column_count) {
assert(column_count >= 2);
AddCapability(spv::Capability::Matrix);
Op* op{new Op(spv::Op::OpTypeMatrix, bound)};
@ -62,9 +62,9 @@ Ref Module::TypeMatrix(Ref column_type, int column_count) {
return AddDeclaration(op);
}
Ref Module::TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed,
bool ms, int sampled, spv::ImageFormat image_format,
std::optional<spv::AccessQualifier> access_qualifier) {
Ref Module::OpTypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed,
bool ms, int sampled, spv::ImageFormat image_format,
std::optional<spv::AccessQualifier> access_qualifier) {
switch (dim) {
case spv::Dim::Dim1D:
AddCapability(spv::Capability::Sampled1D);
@ -140,44 +140,44 @@ Ref Module::TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed,
return AddDeclaration(op);
}
Ref Module::TypeSampler() {
Ref Module::OpTypeSampler() {
return AddDeclaration(new Op(spv::Op::OpTypeSampler, bound));
}
Ref Module::TypeSampledImage(Ref image_type) {
Ref Module::OpTypeSampledImage(Ref image_type) {
auto op{new Op(spv::Op::OpTypeSampledImage, bound)};
op->Add(image_type);
return AddDeclaration(op);
}
Ref Module::TypeArray(Ref element_type, Ref length) {
Ref Module::OpTypeArray(Ref element_type, Ref length) {
auto op{new Op(spv::Op::OpTypeArray, bound)};
op->Add(element_type);
op->Add(length);
return AddDeclaration(op);
}
Ref Module::TypeRuntimeArray(Ref element_type) {
Ref Module::OpTypeRuntimeArray(Ref element_type) {
AddCapability(spv::Capability::Shader);
auto op{new Op(spv::Op::OpTypeRuntimeArray, bound)};
op->Add(element_type);
return AddDeclaration(op);
}
Ref Module::TypeStruct(const std::vector<Ref>& members) {
Ref Module::OpTypeStruct(const std::vector<Ref>& members) {
auto op{new Op(spv::Op::OpTypeStruct, bound)};
op->Add(members);
return AddDeclaration(op);
}
Ref Module::TypeOpaque(const std::string& name) {
Ref Module::OpTypeOpaque(const std::string& name) {
AddCapability(spv::Capability::Kernel);
auto op{new Op(spv::Op::OpTypeOpaque, bound)};
op->Add(name);
return AddDeclaration(op);
}
Ref Module::TypePointer(spv::StorageClass storage_class, Ref type) {
Ref Module::OpTypePointer(spv::StorageClass storage_class, Ref type) {
switch (storage_class) {
case spv::StorageClass::Uniform:
case spv::StorageClass::Output:
@ -199,34 +199,34 @@ Ref Module::TypePointer(spv::StorageClass storage_class, Ref type) {
return AddDeclaration(op);
}
Ref Module::TypeFunction(Ref return_type, const std::vector<Ref>& arguments) {
Ref Module::OpTypeFunction(Ref return_type, const std::vector<Ref>& arguments) {
auto op{new Op(spv::Op::OpTypeFunction, bound)};
op->Add(return_type);
op->Add(arguments);
return AddDeclaration(op);
}
Ref Module::TypeEvent() {
Ref Module::OpTypeEvent() {
AddCapability(spv::Capability::Kernel);
return AddDeclaration(new Op(spv::Op::OpTypeEvent, bound));
}
Ref Module::TypeDeviceEvent() {
Ref Module::OpTypeDeviceEvent() {
AddCapability(spv::Capability::DeviceEnqueue);
return AddDeclaration(new Op(spv::Op::OpTypeDeviceEvent, bound));
}
Ref Module::TypeReserveId() {
Ref Module::OpTypeReserveId() {
AddCapability(spv::Capability::Pipes);
return AddDeclaration(new Op(spv::Op::OpTypeReserveId, bound));
}
Ref Module::TypeQueue() {
Ref Module::OpTypeQueue() {
AddCapability(spv::Capability::DeviceEnqueue);
return AddDeclaration(new Op(spv::Op::OpTypeQueue, bound));
}
Ref Module::TypePipe(spv::AccessQualifier access_qualifier) {
Ref Module::OpTypePipe(spv::AccessQualifier access_qualifier) {
AddCapability(spv::Capability::Pipes);
auto op{new Op(spv::Op::OpTypePipe, bound)};
op->Add(static_cast<u32>(access_qualifier));

View file

@ -4,7 +4,7 @@
* Lesser General Public License version 2.1 or any later version.
*/
#include "literal-number.h"
#include "literal_number.h"
#include <cassert>
namespace Sirit {

View file

@ -24,6 +24,7 @@ class LiteralNumber : public Operand {
template <typename T> static LiteralNumber* Create(T value) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
LiteralNumber* number = new LiteralNumber(std::type_index(typeid(T)));
if (number->is_32 = sizeof(T) == 4; number->is_32) {
number->raw = *reinterpret_cast<u32*>(&value);
@ -34,7 +35,7 @@ class LiteralNumber : public Operand {
}
private:
std::type_index type;
const std::type_index type;
bool is_32;
u64 raw;
};

View file

@ -4,7 +4,9 @@
* Lesser General Public License version 2.1 or any later version.
*/
#include "literal-string.h"
#include "literal_string.h"
#include "common_types.h"
#include <string>
namespace Sirit {

View file

@ -23,7 +23,7 @@ class LiteralString : public Operand {
virtual bool operator==(const Operand& other) const;
private:
std::string string;
const std::string string;
};
} // namespace Sirit

View file

@ -7,8 +7,8 @@
#include <cassert>
#include "common_types.h"
#include "literal-number.h"
#include "literal-string.h"
#include "literal_number.h"
#include "literal_string.h"
#include "op.h"
#include "operand.h"
@ -88,6 +88,7 @@ void Op::Add(const Literal& literal) {
return LiteralNumber::Create(std::get<5>(literal));
default:
assert(!"invalid literal type");
abort();
}
}();
Sink(operand);