MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
normalize.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/def.h"
4
5namespace mim {
6
7/// Utility class when folding constants in normalizers.
8class Res {
9public:
11 : data_{} {}
12 template<class T>
13 Res(T val)
14 : data_(mim::bitcast<u64>(val)) {}
15
16 constexpr const u64& operator*() const& { return *data_; }
17 constexpr u64& operator*() & { return *data_; }
18 explicit operator bool() const { return data_.has_value(); }
19
20private:
21 std::optional<u64> data_;
22};
23
24[[nodiscard]] int commute_(const Def* a, const Def* b);
25
26/// Swap Lit to left - or smaller Def::gid, if no lit present.
27[[nodiscard]] inline bool commute(const Def* a, const Def* b) { return commute_(a, b) > 0; }
28
29} // namespace mim
Base class for all Defs.
Definition def.h:198
constexpr u64 & operator*() &
Definition normalize.h:17
constexpr const u64 & operator*() const &
Definition normalize.h:16
Res(T val)
Definition normalize.h:13
Definition ast.h:14
D bitcast(const S &src)
A bitcast from src of type S to D.
Definition util.h:22
bool commute(const Def *a, const Def *b)
Swap Lit to left - or smaller Def::gid, if no lit present.
Definition normalize.h:27
int commute_(const Def *a, const Def *b)
Definition normalize.cpp:9
uint64_t u64
Definition types.h:34