OpenASIP 2.2
Loading...
Searching...
No Matches
OperationPoolPimpl.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2015 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 OperationPoolPimpl.cc
26 *
27 * Definition of OperationPoolPimpl (private implementation) class.
28 *
29 * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-tut.fi)
30 * @author Pekka Jääskeläinen 2011,2015
31 * @note rating: red
32 */
33
34#include <string>
35#include <vector>
36
37#include "OperationPool.hh"
38#include "OperationModule.hh"
39#include "Operation.hh"
40#include "Operand.hh"
44#include "Environment.hh"
45#include "FileSystem.hh"
46#include "Application.hh"
47#include "AssocTools.hh"
48#include "SequenceTools.hh"
49#include "StringTools.hh"
50#include "Application.hh"
51#include "OperationIndex.hh"
52#include "OperationPoolPimpl.hh"
54#include "TCEString.hh"
55#include "ObjectState.hh"
56
57// disable warnings from LLVm headers
58#pragma GCC diagnostic ignored "-Wunused-parameter"
59
60#include <llvm/MC/MCInstrDesc.h>
61#include <llvm/MC/MCInstrInfo.h>
62
63#pragma GCC diagnostic warning "-Wunused-parameter"
64
65using std::vector;
66using std::string;
67
70const llvm::MCInstrInfo* OperationPoolPimpl::llvmTargetInstrInfo_(NULL);
71
72/**
73 * The constructor
74 */
76 // if this is a first created instance of OperationPool,
77 // initialize the OperationIndex instance with the search paths
78 if (index_ == NULL) {
79 index_ = new OperationIndex();
80 vector<string> paths = Environment::osalPaths();
81 for (unsigned int i = 0; i < paths.size(); i++) {
82 index_->addPath(paths[i]);
83 }
84 }
85}
86
87/**
88 * The destructor
89 */
92
93/**
94 * Cleans up the static Operation cache.
95 *
96 * Deletes also the Operation instances, so be sure you are not using
97 * them after calling this!
98 */
99void
105
106/**
107 * Looks up an operation identified by its name and returns a reference to it.
108 *
109 * The first found operation is returned. If operation is not found, a null
110 * operation is returned.
111 *
112 * @param name The name of the operation.
113 * @return The wanted operation.
114 */
117
118 OperationTable::iterator it =
120 if (it != operationCache_.end()) {
121 return *((*it).second);
122 }
123
124 // If llvmTargetInstrInfo_ is set, the scheduler is called
125 // directly from LLVM code gen. Use the TargetInstrDesc as
126 // the source for operation info instead.
127 if (llvmTargetInstrInfo_ != NULL) {
128 for (unsigned opc = 0; opc < llvmTargetInstrInfo_->getNumOpcodes();
129 ++opc) {
130 const llvm::MCInstrDesc& tid = llvmTargetInstrInfo_->get(opc);
131 TCEString operName =
132 TCEString(llvmTargetInstrInfo_->getName(opc).str()).lower();
133 if (operName == TCEString(name).lower()) {
134 Operation* llvmOperation = loadFromLLVM(tid);
135 operationCache_[operName] = llvmOperation;
136 return *llvmOperation;
137 }
138 }
140 TCEString("Did not find info for LLVM operation ") + name);
141 }
142
143 OperationModule& module = index_->moduleOf(name);
144 if (&module == &NullOperationModule::instance()) {
146 }
147
148 Operation* effective = index_->effectiveOperation(name);
149 if (effective != NULL) {
151 return *effective;
152 } else {
153 return NullOperation::instance();
154 }
155}
156
157/**
158 * Loads an OSAL Operation from LLVM TargetInstrDesc.
159 *
160 * Used for avoiding the need for .xml OSAL databases when TCE scheduler
161 * is called directly for non-TTA LLVM targets.
162 */
165const llvm::MCInstrDesc& tid
166) {
167 TCEString opName = llvmTargetInstrInfo_->getName(tid.getOpcode()).str();
169
170 unsigned outputs = tid.getNumDefs();
171 unsigned inputs = tid.getNumOperands() - outputs;
172
173 // at least a minimal implicit trigger input
174 // RET of SPU does not include the implicit link register
175 // operand even though it will be generated in the final
176 // assembly to just an absolute jump to it
177 if (inputs == 0)
178 inputs = 1;
179
180 for (unsigned opr = 0; opr < outputs; ++opr) {
181 Operand* operand =
182 new Operand(false, inputs + opr + 1, Operand::UINT_WORD);
183 op->addOutput(operand);
184 }
185
186 for (unsigned opr = 0; opr < inputs; ++opr) {
187 Operand* operand = new Operand(true, opr + 1, Operand::UINT_WORD);
188 op->addInput(operand);
189 }
190 if (tid.isCall()) {
191 op->setCall(true);
192 op->setControlFlowOperation(true);
193 }
194 if (tid.isBranch() || tid.isReturn()) {
195 op->setBranch(true);
196 op->setControlFlowOperation(true);
197 }
198 if (tid.mayLoad()) {
199 op->setReadsMemory(true);
200 }
201 if (tid.mayStore()) {
202 op->setWritesMemory(true);
203 }
204 return op;
205}
206
207/**
208 * Returns the operation index of operation pool.
209 *
210 * @return The operation index.
211 */
214 assert(index_ != NULL);
215 return *index_;
216}
217
218bool
220 if (op.affectsCount() > 0 || op.affectedByCount() > 0)
221 return true;
222 for (const auto& entry : operationCache_) {
223 const Operation& other = *entry.second;
224 if (other.dependsOn(op))
225 return true;
226 }
227 return false;
228}
#define abortWithError(message)
#define assert(condition)
static void deleteAllValues(ContainerType &aMap)
static std::vector< std::string > osalPaths()
static NullOperationBehavior & instance()
static NullOperationModule & instance()
static NullOperation & instance()
@ UINT_WORD
Definition Operand.hh:60
Operation * effectiveOperation(const TCEString &name)
void addPath(const std::string &path)
Operation & operation(const char *name)
static OperationIndex * index_
Indexed table used to find out which operation module contains the given operation.
std::map< std::string, Operation * > OperationTable
Container for operations indexed by their names.
static OperationTable operationCache_
Contains all operations that have been already requested by the client.
Operation * loadFromLLVM(const llvm::MCInstrDesc &tid)
bool sharesState(const Operation &op)
OperationIndex & index()
static const llvm::MCInstrInfo * llvmTargetInstrInfo_
If this is set, OSAL data is loaded from the TargetInstrInfo instead of .opp XML files....
virtual void setWritesMemory(bool setting)
Definition Operation.cc:639
virtual int affectedByCount() const
Definition Operation.cc:416
virtual bool dependsOn(const Operation &op) const
Definition Operation.cc:458
virtual void setCall(bool setting)
Definition Operation.cc:359
virtual void addOutput(Operand *operand)
Definition Operation.cc:513
virtual void setControlFlowOperation(bool setting)
Definition Operation.cc:335
virtual void addInput(Operand *operand)
Definition Operation.cc:508
virtual int affectsCount() const
Definition Operation.cc:402
virtual void setBranch(bool setting)
Definition Operation.cc:368
virtual void setReadsMemory(bool setting)
Definition Operation.cc:631
static std::string stringToLower(const std::string &source)
TCEString lower() const
Definition TCEString.cc:78