Jlm
Loading...
Searching...
No Matches
type.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Helge Bahmann <hcb@chaoticmind.net>
3 * Copyright 2011 2012 2013 2014 2015 Nico Reißmann <nico.reissmann@gmail.com>
4 * See COPYING for terms of redistribution.
5 */
6
8#include <jlm/rvsdg/graph.hpp>
9#include <jlm/util/Hash.hpp>
10#include <jlm/util/strfmt.hpp>
11
12namespace jlm::rvsdg
13{
14
16
17std::string
18BitType::debug_string() const
19{
20 return jlm::util::strfmt("bit", nbits());
21}
22
23bool
24BitType::operator==(const Type & other) const noexcept
25{
26 auto type = dynamic_cast<const BitType *>(&other);
27 return type != nullptr && this->nbits() == type->nbits();
28}
29
30std::size_t
32{
33 auto typeHash = typeid(BitType).hash_code();
34 auto numBitsHash = std::hash<size_t>()(nbits_);
36}
37
43
44std::shared_ptr<const BitType>
45BitType::Create(std::size_t nbits)
46{
47 static const BitType static_instances[65] = {
48 BitType(0), BitType(1), BitType(2), BitType(3), BitType(4), BitType(5), BitType(6),
49 BitType(7), BitType(8), BitType(9), BitType(10), BitType(11), BitType(12), BitType(13),
50 BitType(14), BitType(15), BitType(16), BitType(17), BitType(18), BitType(19), BitType(20),
51 BitType(21), BitType(22), BitType(23), BitType(24), BitType(25), BitType(26), BitType(27),
52 BitType(28), BitType(29), BitType(30), BitType(31), BitType(32), BitType(33), BitType(34),
53 BitType(35), BitType(36), BitType(37), BitType(38), BitType(39), BitType(40), BitType(41),
54 BitType(42), BitType(43), BitType(44), BitType(45), BitType(46), BitType(47), BitType(48),
55 BitType(49), BitType(50), BitType(51), BitType(52), BitType(53), BitType(54), BitType(55),
56 BitType(56), BitType(57), BitType(58), BitType(59), BitType(60), BitType(61), BitType(62),
57 BitType(63), BitType(64)
58 };
59
60 if (nbits <= 64)
61 {
62 if (nbits == 0)
63 {
64 throw util::Error("Number of bits must be greater than zero.");
65 }
66
67 return std::shared_ptr<const BitType>(std::shared_ptr<void>(), &static_instances[nbits]);
68 }
69 else
70 {
71 return std::make_shared<BitType>(nbits);
72 }
73}
74
75}
bool operator==(const jlm::rvsdg::Type &other) const noexcept override
Definition type.cpp:24
static std::shared_ptr< const BitType > Create(std::size_t nbits)
Creates bit type of specified width.
Definition type.cpp:45
TypeKind Kind() const noexcept override
Return the kind of this type.
Definition type.cpp:39
size_t nbits() const noexcept
Definition type.hpp:26
std::size_t ComputeHash() const noexcept override
Definition type.cpp:31
~BitType() noexcept override
TypeKind
The kinds of types supported in rvsdg.
Definition type.hpp:22
@ Value
Designate a value type.
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
static std::string strfmt(Args... args)
Definition strfmt.hpp:35
std::size_t CombineHashes(std::size_t hash, Args... args)
Definition Hash.hpp:63