OpenASIP 2.2
Loading...
Searching...
No Matches
ImmInfo.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2016 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/*
25 * @file ImmInfo.hh
26 *
27 * Implementation/Declaration of ImmInfo class.
28 *
29 * Created on: 8.3.2016
30 * @author Henry Linjamäki 2016 (henry.linjamaki-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#ifndef IMMINFO_HH
35#define IMMINFO_HH
36
37#include <map>
38#include <utility>
39#include <string>
40
41
42class Operation;
43class Operand;
44namespace TTAMachine {
45 class RegisterFile;
46}
47
48/**
49 * The key definition for ImmInfo.
50 */
51using ImmInfoKey = std::pair<
52 std::string, /* = The name of the operation. */
53 int /* = The ID of the operand. */ >;
54
55/**
56 * The stored immediate result in ImmInfo.
57 */
58class ImmInfoValue : public std::pair<
59 int, /* = The bit width of the immediate */
60 bool /* = Sign extends */ > {
61public:
62
64 ImmInfoValue(int immediateWidth, bool signExtending);
65
66 int64_t lowerBound() const;
67 int64_t upperBound() const;
68 /**
69 * Returns bit width of the immediate.
70 */
71 int width() const { return first; }
72 /**
73 * Return true if the immediate is sign extending.
74 */
75 bool signExtending() const { return second; }
76};
77
78/*
79 * Container class for short immediate analysis results.
80 *
81 */
82class ImmInfo : public std::multimap<ImmInfoKey, ImmInfoValue> {
83public:
84 ImmInfo() = default;
85 virtual ~ImmInfo() = default;
86
87 size_t count(const ImmInfoKey& key) const {
88 return std::multimap<ImmInfoKey, ImmInfoValue>::count(key);
89 }
90 size_t count(const Operation& operation, const Operand& operand) const;
91 size_t count(const Operation& operation, int inputOperandId) const;
92
93 const ImmInfoValue& widestImmediate(const ImmInfoKey& key) const;
95 const Operation& operation, const Operand& operand) const;
97 const Operation& operation, int inputOperandId) const;
98 const ImmInfoValue& narrowestImmediate(const ImmInfoKey& key) const;
99
100 std::pair<int64_t, int64_t> immediateValueBounds(
101 const ImmInfoKey& key, int destWidth) const;
102 std::pair<int64_t, int64_t> immediateValueBounds(
103 const Operation& operation, const Operand& operand,
104 int destWidth) const;
105 std::pair<int64_t, int64_t> immediateValueBounds(
106 const Operation& operation, int inputOperandId,
107 int destWidth) const;
108
109 bool canTakeImmediate(
110 const Operation& operation,
111 int inputOperandId,
112 int64_t value,
113 int destWidth);
114
116 const Operation& operation,
117 int inputOperandId,
118 int bitWidth);
119
120 static ImmInfoKey key(
121 const Operation& operation,
122 int inputOperandId);
123 static ImmInfoKey key(
124 const Operation& operation,
125 const Operand& operand);
126
128 const TTAMachine::RegisterFile& targetRF,
129 bool allowSignExtension = false);
130
131};
132
133#endif /* IMMINFO_HH */
std::pair< std::string, int > ImmInfoKey
Definition ImmInfo.hh:53
int64_t lowerBound() const
Definition ImmInfo.cc:181
int64_t upperBound() const
Definition ImmInfo.cc:193
bool signExtending() const
Definition ImmInfo.hh:75
int width() const
Definition ImmInfo.hh:71
const ImmInfoValue & widestImmediate(const ImmInfoKey &key) const
Definition ImmInfo.cc:89
static int registerImmediateLoadWidth(const TTAMachine::RegisterFile &targetRF, bool allowSignExtension=false)
Definition ImmInfo.cc:326
ImmInfo()=default
bool canTakeImmediate(const Operation &operation, int inputOperandId, int64_t value, int destWidth)
Definition ImmInfo.cc:252
static ImmInfoKey key(const Operation &operation, int inputOperandId)
Definition ImmInfo.cc:57
bool canTakeImmediateByWidth(const Operation &operation, int inputOperandId, int bitWidth)
Definition ImmInfo.cc:275
virtual ~ImmInfo()=default
std::pair< int64_t, int64_t > immediateValueBounds(const ImmInfoKey &key, int destWidth) const
Definition ImmInfo.cc:219
size_t count(const ImmInfoKey &key) const
Definition ImmInfo.hh:87
const ImmInfoValue & narrowestImmediate(const ImmInfoKey &key) const
Definition ImmInfo.cc:140