OpenASIP  2.0
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 
42 class Operation;
43 class Operand;
44 namespace TTAMachine {
45  class RegisterFile;
46 }
47 
48 /**
49  * The key definition for ImmInfo.
50  */
51 using 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  */
58 class ImmInfoValue : public std::pair<
59  int, /* = The bit width of the immediate */
60  bool /* = Sign extends */ > {
61 public:
62 
63  ImmInfoValue();
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  */
82 class ImmInfo : public std::multimap<ImmInfoKey, ImmInfoValue> {
83 public:
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 
127  static int registerImmediateLoadWidth(
128  const TTAMachine::RegisterFile& targetRF,
129  bool allowSignExtension = false);
130 
131 };
132 
133 #endif /* IMMINFO_HH */
Operand
Definition: Operand.hh:52
ImmInfo::immediateValueBounds
std::pair< int64_t, int64_t > immediateValueBounds(const ImmInfoKey &key, int destWidth) const
Definition: ImmInfo.cc:219
ImmInfoValue::ImmInfoValue
ImmInfoValue()
Definition: ImmInfo.cc:164
ImmInfo::canTakeImmediateByWidth
bool canTakeImmediateByWidth(const Operation &operation, int inputOperandId, int bitWidth)
Definition: ImmInfo.cc:275
ImmInfo::count
size_t count(const ImmInfoKey &key) const
Definition: ImmInfo.hh:87
ImmInfoValue
Definition: ImmInfo.hh:58
ImmInfoValue::lowerBound
int64_t lowerBound() const
Definition: ImmInfo.cc:181
ImmInfoKey
std::pair< std::string, int > ImmInfoKey
Definition: ImmInfo.hh:53
ImmInfo::key
static ImmInfoKey key(const Operation &operation, int inputOperandId)
Definition: ImmInfo.cc:57
ImmInfoValue::upperBound
int64_t upperBound() const
Definition: ImmInfo.cc:193
ImmInfo::canTakeImmediate
bool canTakeImmediate(const Operation &operation, int inputOperandId, int64_t value, int destWidth)
Definition: ImmInfo.cc:252
ImmInfo::widestImmediate
const ImmInfoValue & widestImmediate(const ImmInfoKey &key) const
Definition: ImmInfo.cc:89
Operation
Definition: Operation.hh:59
ImmInfo::ImmInfo
ImmInfo()=default
ImmInfo::~ImmInfo
virtual ~ImmInfo()=default
ImmInfoValue::width
int width() const
Definition: ImmInfo.hh:71
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAMachine
Definition: Assembler.hh:48
ImmInfo
Definition: ImmInfo.hh:82
ImmInfoValue::signExtending
bool signExtending() const
Definition: ImmInfo.hh:75
ImmInfo::narrowestImmediate
const ImmInfoValue & narrowestImmediate(const ImmInfoKey &key) const
Definition: ImmInfo.cc:140
ImmInfo::registerImmediateLoadWidth
static int registerImmediateLoadWidth(const TTAMachine::RegisterFile &targetRF, bool allowSignExtension=false)
Definition: ImmInfo.cc:326