OpenASIP  2.0
Public Member Functions | Static Public Member Functions | List of all members
ImmInfo Class Reference

#include <ImmInfo.hh>

Inheritance diagram for ImmInfo:
Inheritance graph
Collaboration diagram for ImmInfo:
Collaboration graph

Public Member Functions

 ImmInfo ()=default
 
virtual ~ImmInfo ()=default
 
size_t count (const ImmInfoKey &key) const
 
size_t count (const Operation &operation, const Operand &operand) const
 
size_t count (const Operation &operation, int inputOperandId) const
 
const ImmInfoValuewidestImmediate (const ImmInfoKey &key) const
 
const ImmInfoValuewidestImmediate (const Operation &operation, const Operand &operand) const
 
const ImmInfoValuewidestImmediate (const Operation &operation, int inputOperandId) const
 
const ImmInfoValuenarrowestImmediate (const ImmInfoKey &key) const
 
std::pair< int64_t, int64_t > immediateValueBounds (const ImmInfoKey &key, int destWidth) const
 
std::pair< int64_t, int64_t > immediateValueBounds (const Operation &operation, const Operand &operand, int destWidth) const
 
std::pair< int64_t, int64_t > immediateValueBounds (const Operation &operation, int inputOperandId, int destWidth) const
 
bool canTakeImmediate (const Operation &operation, int inputOperandId, int64_t value, int destWidth)
 
bool canTakeImmediateByWidth (const Operation &operation, int inputOperandId, int bitWidth)
 

Static Public Member Functions

static ImmInfoKey key (const Operation &operation, int inputOperandId)
 
static ImmInfoKey key (const Operation &operation, const Operand &operand)
 
static int registerImmediateLoadWidth (const TTAMachine::RegisterFile &targetRF, bool allowSignExtension=false)
 

Detailed Description

Definition at line 82 of file ImmInfo.hh.

Constructor & Destructor Documentation

◆ ImmInfo()

ImmInfo::ImmInfo ( )
default

◆ ~ImmInfo()

virtual ImmInfo::~ImmInfo ( )
virtualdefault

Member Function Documentation

◆ canTakeImmediate()

bool ImmInfo::canTakeImmediate ( const Operation operation,
int  inputOperandId,
int64_t  value,
int  destWidth 
)

Definition at line 252 of file ImmInfo.cc.

256  {
257 
258  auto unsignedReqBits = MathTools::requiredBits(value);
259  auto signedReqBits = MathTools::requiredBitsSigned(value);
260  auto theKey = key(operation, inputOperandId);
261  const_iterator it_begin = lower_bound(theKey);
262  const_iterator it_end = upper_bound(theKey);
263  const_iterator it;
264  for (it = it_begin; it != it_end; it++) {
265  const ImmInfoValue& imm = it->second;
266  if ((imm.signExtending() && signedReqBits <= imm.width()) ||
267  (unsignedReqBits <= imm.width())) {
268  return true;
269  }
270  }
271  return false;
272 }

References key(), MathTools::requiredBits(), MathTools::requiredBitsSigned(), ImmInfoValue::signExtending(), and ImmInfoValue::width().

Referenced by TDGen::getLLVMPatternWithConstants().

Here is the call graph for this function:

◆ canTakeImmediateByWidth()

bool ImmInfo::canTakeImmediateByWidth ( const Operation operation,
int  inputOperandId,
int  bitWidth 
)

Definition at line 275 of file ImmInfo.cc.

278  {
279 
280  auto theKey = key(operation, inputOperandId);
281  const_iterator it_begin = lower_bound(theKey);
282  const_iterator it_end = upper_bound(theKey);
283  const_iterator it;
284  for (it = it_begin; it != it_end; it++) {
285  const ImmInfoValue& info = it->second;
286  if (bitWidth <= info.width()) return true;
287  }
288  return false;
289 }

References key(), and ImmInfoValue::width().

Referenced by TDGen::getLLVMPatternWithConstants().

Here is the call graph for this function:

◆ count() [1/3]

size_t ImmInfo::count ( const ImmInfoKey key) const
inline

Definition at line 87 of file ImmInfo.hh.

87  {
88  return std::multimap<ImmInfoKey, ImmInfoValue>::count(key);
89  }

References key().

Referenced by TDGen::areImmediateOperandsLegal(), count(), and OperationDAGSelector::findDags().

Here is the call graph for this function:

◆ count() [2/3]

size_t ImmInfo::count ( const Operation operation,
const Operand operand 
) const

Returns the entry count for operation, operand pair (key).

Definition at line 70 of file ImmInfo.cc.

70  {
71  return std::multimap<ImmInfoKey, ImmInfoValue>::count(
72  key(operation, operand));
73 }

References key().

Here is the call graph for this function:

◆ count() [3/3]

size_t ImmInfo::count ( const Operation operation,
int  inputOperandId 
) const

Returns the entry count for operation, operand pair (key).

Definition at line 80 of file ImmInfo.cc.

80  {
81  return count(operation, operation.operand(inputOperandId));
82 }

References count(), and Operation::operand().

Here is the call graph for this function:

◆ immediateValueBounds() [1/3]

std::pair< int64_t, int64_t > ImmInfo::immediateValueBounds ( const ImmInfoKey key,
int  destWidth 
) const

Returns smallest and largest number that can be transported to operation operand.

The bounds are merged from multiple immediate sources. For example, if immediates can be transported from two different sources, where the one is 4 bits zero extending and the another is 3 bits sign extending, the resulting bound is [-4, 15].

if destination bit width is specified, then the bounds are ...TODO

Parameters
destWidthThe destination width, where the immediates are transported to. By default it is unspecified/unlimited.
Returns
std::pair, where the first is smallest value and second is largest. If no immediate can be transported, (0, 0) is returned.

Definition at line 219 of file ImmInfo.cc.

220  {
221 
222  std::pair<int64_t, int64_t> result{ 0, 0 };
223 
224  const_iterator it_begin = lower_bound(key);
225  const_iterator it_end = upper_bound(key);
226  const_iterator it;
227  for (it = it_begin; it != it_end; it++) {
228  if (destWidth > 0) {
229  if (it->second.width() >= destWidth) {
230  return { (-(1ll << (destWidth-1))), ((1ll << destWidth)-1) };
231  }
232  }
233 
234  int64_t currLowerBound = 0;
235  int64_t currUpperBound = 0;
236  if (it->second.signExtending()) {
237  currLowerBound = -(1ll << (it->second.width()-1));
238  currUpperBound = (1ll << (it->second.width()-1))-1;
239  } else {
240  currUpperBound = (1ll << (it->second.width()))-1;
241  }
242 
243  result.first = std::min(result.first, currLowerBound);
244  result.second = std::max(result.second, currUpperBound);
245  }
246 
247  return result;
248 }

References key().

Referenced by TDGen::createConstantMaterializationPatterns(), and immediateValueBounds().

Here is the call graph for this function:

◆ immediateValueBounds() [2/3]

std::pair< int64_t, int64_t > ImmInfo::immediateValueBounds ( const Operation operation,
const Operand operand,
int  destWidth 
) const

Same as immediateValueBounds(const ImmInfoKey& key).

Definition at line 296 of file ImmInfo.cc.

299  {
300  return immediateValueBounds(key(operation, operand), destWidth);
301 }

References immediateValueBounds(), and key().

Here is the call graph for this function:

◆ immediateValueBounds() [3/3]

std::pair< int64_t, int64_t > ImmInfo::immediateValueBounds ( const Operation operation,
int  inputOperandId,
int  destWidth 
) const

Same as immediateValueBounds(const ImmInfoKey& key).

Definition at line 309 of file ImmInfo.cc.

312  {
313 
314  return immediateValueBounds(
315  operation, operation.operand(inputOperandId), destWidth);
316 }

References immediateValueBounds(), and Operation::operand().

Here is the call graph for this function:

◆ key() [1/2]

ImmInfoKey ImmInfo::key ( const Operation operation,
const Operand operand 
)
static

Definition at line 61 of file ImmInfo.cc.

61  {
62  return std::make_pair(operation.name().upper(), operand.index());
63 }

References Operand::index(), Operation::name(), and TCEString::upper().

Here is the call graph for this function:

◆ key() [2/2]

ImmInfoKey ImmInfo::key ( const Operation operation,
int  inputOperandId 
)
static

Returns key for ImmInfo data structure.

Definition at line 57 of file ImmInfo.cc.

57  {
58  return std::make_pair(operation.name().upper(), inputOperandId);
59 }

References Operation::name(), and TCEString::upper().

Referenced by canTakeImmediate(), canTakeImmediateByWidth(), count(), TDGen::dagNodeToString(), TDGen::immediateOperandNameForEmulatedOperation(), immediateValueBounds(), narrowestImmediate(), TDGen::patInputs(), widestImmediate(), and TDGen::writeIntegerImmediateDefs().

Here is the call graph for this function:

◆ narrowestImmediate()

const ImmInfoValue & ImmInfo::narrowestImmediate ( const ImmInfoKey key) const

returns narrowest (non-zero width) immediate bit width by the key.

Definition at line 140 of file ImmInfo.cc.

140  {
141  if (std::multimap<ImmInfoKey, ImmInfoValue>::count(key)) {
142  const_iterator it;
143  const_iterator it_largest = lower_bound(key);
144  const_iterator it_begin = it_largest;
145  it_begin++;
146  const_iterator it_end = upper_bound(key);
147  for (it = it_begin; it != it_end; it++) {
148  if (*it < *it_largest) {
149  it_largest = it;
150  }
151  }
152  assert(it_largest != it_end);
153  return it_largest->second;
154  } else {
156  "No immediate info found for the key.");
157  }
158 }

References assert, key(), and THROW_EXCEPTION.

Here is the call graph for this function:

◆ registerImmediateLoadWidth()

int ImmInfo::registerImmediateLoadWidth ( const TTAMachine::RegisterFile targetRF,
bool  allowSignExtension = false 
)
static

Returns maximum immediate in bit width which can be transported to the RF.

Parameters
targetRFThe target register file.
allowSignExtensionIf representation of the transported immediate should not change set it to false (default).

Definition at line 326 of file ImmInfo.cc.

328  {
329 
330  using namespace TTAMachine;
331  using MCC = MachineConnectivityCheck;
332 
333  int result = 0;
334  assert(targetRF.machine());
335  const Machine& mach = *targetRF.machine();
336 
337  for (const Bus* bus : mach.busNavigator()) {
338  if (MCC::busConnectedToRF(*bus, targetRF)) {
339  int immWidth = bus->immediateWidth();
340  if (!allowSignExtension && bus->signExtends()) {
341  immWidth -= 1;
342  }
343  result = std::max(result, immWidth);
344  }
345  }
346 
347  for (auto* iu : mach.immediateUnitNavigator()) {
348  for (auto* it : mach.instructionTemplateNavigator()) {
349  int supportedWidth = it->supportedWidth(*iu);
350  if (!allowSignExtension && iu->signExtends()) {
351  supportedWidth -= 1;
352  }
353  result = std::max(result, supportedWidth);
354  }
355  }
356 
357  return result;
358 }

References assert, TTAMachine::Machine::busNavigator(), TTAMachine::Machine::immediateUnitNavigator(), TTAMachine::Machine::instructionTemplateNavigator(), and TTAMachine::Component::machine().

Referenced by llvm::TCETargetMachine::calculateSupportedImmediates().

Here is the call graph for this function:

◆ widestImmediate() [1/3]

const ImmInfoValue & ImmInfo::widestImmediate ( const ImmInfoKey key) const

Returns the entry count by the key.

Definition at line 89 of file ImmInfo.cc.

89  {
90  if (std::multimap<ImmInfoKey, ImmInfoValue>::count(key)) {
91  const_iterator it;
92  const_iterator it_largest = this->lower_bound(key);
93  const_iterator it_begin = it_largest;
94  it_begin++;
95  const_iterator it_end = this->upper_bound(key);
96  for (it = it_begin; it != it_end; it++) {
97  if (*it > *it_largest) {
98  it_largest = it;
99  }
100  }
101  assert(it_largest != it_end);
102  return it_largest->second;
103  } else {
104  THROW_EXCEPTION(InstanceNotFound, "No immediate info for key found.");
105  }
106 }

References assert, key(), and THROW_EXCEPTION.

Referenced by widestImmediate().

Here is the call graph for this function:

◆ widestImmediate() [2/3]

const ImmInfoValue & ImmInfo::widestImmediate ( const Operation operation,
const Operand operand 
) const

returns widest immediate bit width by the key.

Parameters
operationThe operation as the part of the key.
inputOperandIdThe input operand of the operation as the of the key.

Definition at line 116 of file ImmInfo.cc.

117  {
118 
119  return widestImmediate(key(operation, operand));
120 }

References key(), and widestImmediate().

Here is the call graph for this function:

◆ widestImmediate() [3/3]

const ImmInfoValue & ImmInfo::widestImmediate ( const Operation operation,
int  inputOperandId 
) const

returns widest immediate bit width by the key.

Parameters
operationThe operation as the part of the key.
inputOperandIdThe input operand id of the operation as the of the key.

Definition at line 130 of file ImmInfo.cc.

131  {
132 
133  return widestImmediate(operation, operation.operand(inputOperandId));
134 }

References Operation::operand(), and widestImmediate().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
ImmInfo::immediateValueBounds
std::pair< int64_t, int64_t > immediateValueBounds(const ImmInfoKey &key, int destWidth) const
Definition: ImmInfo.cc:219
MachineConnectivityCheck
Definition: MachineConnectivityCheck.hh:69
ImmInfo::count
size_t count(const ImmInfoKey &key) const
Definition: ImmInfo.hh:87
ImmInfoValue
Definition: ImmInfo.hh:58
TTAMachine::Bus
Definition: Bus.hh:53
TCEString::upper
TCEString upper() const
Definition: TCEString.cc:86
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
ImmInfo::key
static ImmInfoKey key(const Operation &operation, int inputOperandId)
Definition: ImmInfo.cc:57
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::Machine::immediateUnitNavigator
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition: Machine.cc:416
THROW_EXCEPTION
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition: Exception.hh:39
Operand::index
virtual int index() const
Definition: Operand.cc:135
MathTools::requiredBits
static int requiredBits(unsigned long int number)
ImmInfo::widestImmediate
const ImmInfoValue & widestImmediate(const ImmInfoKey &key) const
Definition: ImmInfo.cc:89
Operation::operand
virtual Operand & operand(int id) const
Definition: Operation.cc:541
TTAMachine::Component::machine
virtual Machine * machine() const
ImmInfoValue::width
int width() const
Definition: ImmInfo.hh:71
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
TTAMachine
Definition: Assembler.hh:48
TTAMachine::Machine::instructionTemplateNavigator
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition: Machine.cc:428
MathTools::requiredBitsSigned
static int requiredBitsSigned(SLongWord number)
ImmInfoValue::signExtending
bool signExtending() const
Definition: ImmInfo.hh:75
InstanceNotFound
Definition: Exception.hh:304
TTAMachine::Machine
Definition: Machine.hh:73