2021-05-05 07:19:08 +02:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <bitset>
|
|
|
|
|
2021-05-08 21:46:32 +02:00
|
|
|
#include "common/bit_field.h"
|
2021-05-05 07:19:08 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Shader::IR {
|
|
|
|
class Inst;
|
|
|
|
class Value;
|
|
|
|
} // namespace Shader::IR
|
|
|
|
|
|
|
|
namespace Shader::Backend::GLASM {
|
|
|
|
|
2021-05-07 11:31:30 +02:00
|
|
|
class EmitContext;
|
|
|
|
|
2021-05-05 07:19:08 +02:00
|
|
|
struct Id {
|
2021-05-08 21:46:32 +02:00
|
|
|
union {
|
|
|
|
u32 raw;
|
|
|
|
BitField<0, 30, u32> index;
|
|
|
|
BitField<30, 1, u32> is_spill;
|
|
|
|
BitField<31, 1, u32> is_condition_code;
|
|
|
|
};
|
2021-05-05 07:19:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class RegAlloc {
|
|
|
|
public:
|
2021-05-07 11:31:30 +02:00
|
|
|
RegAlloc(EmitContext& ctx_) : ctx{ctx_} {}
|
|
|
|
|
|
|
|
std::string Define(IR::Inst& inst);
|
2021-05-05 07:19:08 +02:00
|
|
|
|
|
|
|
std::string Consume(const IR::Value& value);
|
|
|
|
|
2021-05-07 11:31:30 +02:00
|
|
|
[[nodiscard]] size_t NumUsedRegisters() const noexcept {
|
|
|
|
return num_used_registers;
|
|
|
|
}
|
|
|
|
|
2021-05-05 07:19:08 +02:00
|
|
|
private:
|
|
|
|
static constexpr size_t NUM_REGS = 4096;
|
|
|
|
static constexpr size_t NUM_ELEMENTS = 4;
|
|
|
|
|
2021-05-07 11:31:30 +02:00
|
|
|
EmitContext& ctx;
|
|
|
|
|
2021-05-05 07:19:08 +02:00
|
|
|
std::string Consume(IR::Inst& inst);
|
|
|
|
|
2021-05-07 11:31:30 +02:00
|
|
|
Id Alloc();
|
2021-05-05 07:19:08 +02:00
|
|
|
|
|
|
|
void Free(Id id);
|
|
|
|
|
|
|
|
size_t num_used_registers{};
|
|
|
|
std::bitset<NUM_REGS> register_use{};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Shader::Backend::GLASM
|