blob: 69df70a539aab990db4895f134015e2a8ae630d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef RCC_CODEGEN_MACHINECOMBINERPATTERN_H
#define RCC_CODEGEN_MACHINECOMBINERPATTERN_H
#include "rcc/CodeGen/MachineIRTypes.h"
#include "rcc/Support/Error.h"
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <unordered_map>
#include <vector>
namespace rcc {
enum class MachineCombinerStage : std::uint8_t {
SelectedSSA,
PreRegisterAllocation,
PostRegisterAllocation,
PostFrame,
};
using MachineCombinerStageMask = std::uint8_t;
[[nodiscard]] constexpr MachineCombinerStageMask
machineCombinerStageMask(MachineCombinerStage Stage) noexcept {
return static_cast<MachineCombinerStageMask>(1U << static_cast<std::uint8_t>(Stage));
}
enum class MachineCombinerPredicateKind : std::uint8_t {
ImmediateEquals,
RegisterEquals,
PhysicalRegisterEquals,
RegisterIsVirtual,
RegisterIsPhysical,
};
struct MachineCombinerPredicate final {
MachineCombinerPredicateKind Kind = MachineCombinerPredicateKind::ImmediateEquals;
std::size_t Operand = 0;
std::size_t OtherOperand = 0;
std::int64_t Value = 0;
};
enum class MachineCombinerActionKind : std::uint8_t {
ReplaceDefWithOperandAndErase,
};
struct MachineCombinerAction final {
MachineCombinerActionKind Kind = MachineCombinerActionKind::ReplaceDefWithOperandAndErase;
std::size_t DefinitionOperand = 0;
std::size_t SourceOperand = 0;
};
struct MachineCombinerPattern final {
std::string Name;
Opcode RootOpcode;
MachineCombinerStageMask Stages = 0;
std::vector<MachineCombinerPredicate> Predicates;
MachineCombinerAction Action;
};
class TargetMachineCombinerInfo final {
public:
[[nodiscard]] static Expected<TargetMachineCombinerInfo>
create(std::vector<MachineCombinerPattern> Patterns);
[[nodiscard]] std::span<const MachineCombinerPattern> patterns(Opcode RootOpcode) const noexcept;
private:
explicit TargetMachineCombinerInfo(std::vector<MachineCombinerPattern> Patterns)
: Patterns(std::move(Patterns)) {}
std::vector<MachineCombinerPattern> Patterns;
std::unordered_map<Opcode, std::vector<MachineCombinerPattern>> MatchTable;
};
} // namespace rcc
#endif // RCC_CODEGEN_MACHINECOMBINERPATTERN_H
|