reg_alloc.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <bitset>
  6. #include "common/bit_field.h"
  7. #include "common/common_types.h"
  8. namespace Shader::IR {
  9. class Inst;
  10. class Value;
  11. } // namespace Shader::IR
  12. namespace Shader::Backend::GLASM {
  13. class EmitContext;
  14. struct Id {
  15. union {
  16. u32 raw;
  17. BitField<0, 30, u32> index;
  18. BitField<30, 1, u32> is_spill;
  19. BitField<31, 1, u32> is_condition_code;
  20. };
  21. };
  22. class RegAlloc {
  23. public:
  24. RegAlloc(EmitContext& ctx_) : ctx{ctx_} {}
  25. std::string Define(IR::Inst& inst);
  26. std::string Consume(const IR::Value& value);
  27. [[nodiscard]] size_t NumUsedRegisters() const noexcept {
  28. return num_used_registers;
  29. }
  30. private:
  31. static constexpr size_t NUM_REGS = 4096;
  32. static constexpr size_t NUM_ELEMENTS = 4;
  33. EmitContext& ctx;
  34. std::string Consume(IR::Inst& inst);
  35. Id Alloc();
  36. void Free(Id id);
  37. size_t num_used_registers{};
  38. std::bitset<NUM_REGS> register_use{};
  39. };
  40. } // namespace Shader::Backend::GLASM