OpenASIP 2.2
Loading...
Searching...
No Matches
MachineInstrDDG.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2012 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 MachineInstrDDG.hh
26 *
27 * Declaration of MachineInstrDDG class.
28 *
29 * @author Pekka Jääskeläinen 2010-2012
30 * @note rating: red
31 */
32
33#ifndef TCE_MACHINE_INSTR_DDG_HH
34#define TCE_MACHINE_INSTR_DDG_HH
35
36#include "CompilerWarnings.hh"
37
38IGNORE_COMPILER_WARNING("-Wunused-parameter")
39#ifdef __clang__
40IGNORE_COMPILER_WARNING("-Wunused-private-field")
41#endif
42
43#include "BoostGraph.hh"
44#include "GraphNode.hh"
45#include "GraphEdge.hh"
46#include <set>
47#include <map>
48#include <sstream>
49#include "llvm/CodeGen/TargetRegisterInfo.h"
50#include "llvm/CodeGen/TargetInstrInfo.h"
51#include "llvm/Target/TargetMachine.h"
52
53namespace llvm {
54 class MachineFunction;
55 class MachineInstr;
56}
57
58struct MIDDGNode : public GraphNode {
59 MIDDGNode() : GraphNode(), mi_(NULL), address_(-1), optimalCycle_(-1) {}
60 MIDDGNode(const llvm::MachineInstr& mi, int sequentialAddress) :
62
63 virtual ~MIDDGNode() {}
64
65 bool operator<(const MIDDGNode& other) const {
66 return other.sequentialAddress() < this->sequentialAddress();
67 }
68 bool operator==(const MIDDGNode& other) const {
69 return other.mi_ == this->mi_;
70 }
71
72 const llvm::MachineInstr* machineInstr() const { return mi_; }
73 int sequentialAddress() const { return address_; }
74
75 std::string dotString() const;
77
78 void setOptimalCycle(int cycle) { optimalCycle_ = cycle; }
79 int optimalCycle() const { return optimalCycle_; }
80private:
81 const llvm::MachineInstr* mi_;
84};
85
86struct MIDDGEdge : public GraphEdge {
92
96
97 MIDDGEdge(unsigned reg) :
99
100 MIDDGEdge(unsigned reg, DependenceType type) :
101 GraphEdge(), reg_(reg), dependenceType_(type) {}
102
103
104 virtual ~MIDDGEdge() {}
105
107 return (boost::format("label=\"%d %s\"") % reg_ % typeAsString()).
108 str();
109 }
110
112 return (boost::format("%d %s") % reg_ % typeAsString()).str();
113 }
114
115private:
116
117 std::string typeAsString() const {
118 std::string type = "unknown";
120 type = "RaW";
121 else if (dependenceType_ == DEP_WAR)
122 type = "WaR";
123 else if (dependenceType_ == DEP_WAW)
124 type = "WaW";
125 return type;
126 }
127
128 unsigned reg_;
129 unsigned char dependenceType_; // DependenceType
130};
131
132/**
133 * Data Dependence Graph constructed from non-register allocated LLVM
134 * MachineInstructions.
135 *
136 * Only true dependencies supported at the moment. Later we can might add
137 * support for adding the false dependencies introduced by the register
138 * allocator, if needed.
139 */
141 public BoostGraph<MIDDGNode, MIDDGEdge> {
142public:
143 typedef unsigned Register;
144 typedef std::set<Register> RegisterSet;
145
146 explicit MachineInstrDDG(const MachineInstrDDG& parent);
147
149 llvm::MachineFunction& mf,
150 bool onlyTrueDeps=true);
151
152 virtual ~MachineInstrDDG();
153
155
156 MIDDGNode* vregDefiner(Register vreg) const { return definers_[vreg]; };
157 MIDDGNode* lastVregUser(Register vreg) const;
158
159 int falseDepHeightDelta(Register vreg, Register physReg) const;
160 void assignPhysReg(Register vreg, Register physReg);
161
163 const MIDDGNode& node,
164 Register physReg) const;
165
167
168 TCEString dotString() const;
169
171
172private:
173 typedef std::map<Register, MIDDGNode*> DefinerMap;
174 typedef std::map<Register, NodeSet> UserMap;
175 typedef std::map<Register, Register> RegisterMap;
176
177 std::pair<MIDDGNode*, MIDDGNode*>
178 createFalseDepEdge(Register vreg, Register physReg) const;
179
180 // all register indices in the DDG
182 // the MachineInstructions* that define the virtual regs
185
187 std::set<MIDDGEdge*> edges_;
188 std::map<Register, MIDDGNode*> lastPhysRegUsers_;
189 std::map<Register, MIDDGNode*> lastPhysRegDefiners_;
191
192 // do not add any false deps in case this is true
193 const bool onlyTrueDeps_;
194
195 // in case a schedule has been computed, these contain the limits
198 mutable std::map<int, std::list<MIDDGNode*> > schedule_;
199
200 llvm::MachineFunction& mf_;
201 const llvm::TargetRegisterInfo* regInfo_;
202
204};
205
207
208
209#endif
210
#define IGNORE_COMPILER_WARNING(X)
#define POP_COMPILER_DIAGS
Node & node(const int index) const
std::set< MIDDGNode *, typename GraphNode::Comparator > NodeSet
Definition BoostGraph.hh:86
void setPrintOnlyCriticalPath(bool flag)
std::map< Register, Register > RegisterMap
std::map< Register, NodeSet > UserMap
std::set< Register > RegisterSet
const llvm::TargetRegisterInfo * regInfo_
bool preceedingNodeUsesOrDefinesReg(const MIDDGNode &node, Register physReg) const
TCEString dotString() const
std::pair< MIDDGNode *, MIDDGNode * > createFalseDepEdge(Register vreg, Register physReg) const
int falseDepHeightDelta(Register vreg, Register physReg) const
llvm::MachineFunction & mf_
std::map< Register, MIDDGNode * > DefinerMap
std::map< int, std::list< MIDDGNode * > > schedule_
std::map< Register, MIDDGNode * > lastPhysRegDefiners_
MIDDGNode * lastVregUser(Register vreg) const
std::set< MIDDGEdge * > edges_
virtual ~MachineInstrDDG()
RegisterMap regAssignments_
const bool onlyTrueDeps_
void assignPhysReg(Register vreg, Register physReg)
MIDDGNode * vregDefiner(Register vreg) const
std::map< Register, MIDDGNode * > lastPhysRegUsers_
RegisterSet allRegisters() const
RegisterSet allRegisters_
virtual ~MIDDGEdge()
unsigned char dependenceType_
TCEString toString() const
MIDDGEdge(unsigned reg)
std::string typeAsString() const
TCEString dotString() const
MIDDGEdge(unsigned reg, DependenceType type)
int optimalCycle() const
int sequentialAddress() const
const llvm::MachineInstr * machineInstr() const
virtual ~MIDDGNode()
bool operator<(const MIDDGNode &other) const
TCEString osalOperationName() const
bool operator==(const MIDDGNode &other) const
MIDDGNode(const llvm::MachineInstr &mi, int sequentialAddress)
std::string dotString() const
void setOptimalCycle(int cycle)
const llvm::MachineInstr * mi_