OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
StackAliasAnalyzer Class Reference

#include <StackAliasAnalyzer.hh>

Inheritance diagram for StackAliasAnalyzer:
Inheritance graph
Collaboration diagram for StackAliasAnalyzer:
Collaboration graph

Public Member Functions

virtual bool isAddressTraceable (DataDependenceGraph &ddg, const ProgramOperation &pop)
 
virtual AliasingResult analyze (DataDependenceGraph &ddg, const ProgramOperation &pop1, const ProgramOperation &pop2, MoveNodeUse::BBRelation bbInfo)
 
 StackAliasAnalyzer (const TCEString &sp)
 
 ~StackAliasAnalyzer ()
 
- Public Member Functions inherited from MemoryAliasAnalyzer
virtual void initProcedure (TTAProgram::Procedure &)
 
virtual ~MemoryAliasAnalyzer ()
 

Static Public Member Functions

static bool getStackOffset (DataDependenceGraph &ddg, const ProgramOperation &pop, long &offset, long &loopIncrement, const TCEString &sp_)
 

Private Attributes

std::map< int, std::pair< long, long > > offsetData_
 
TCEString sp_
 

Additional Inherited Members

- Public Types inherited from MemoryAliasAnalyzer
enum  AliasingResult { ALIAS_FALSE = 0 , ALIAS_TRUE = 1 , ALIAS_UNKNOWN = 2 , ALIAS_PARTIAL = 3 }
 
- Protected Member Functions inherited from MemoryAliasAnalyzer
AliasingResult compareIndeces (int index1, int index2, const ProgramOperation &pop1, const ProgramOperation &pop2)
 
- Static Protected Member Functions inherited from MemoryAliasAnalyzer
static const MoveNodeaddressOperandMove (const ProgramOperation &po)
 
static TwoPartAddressOperandDetection findTwoPartAddressOperands (const ProgramOperation &po)
 
static const MoveNodesearchLoopIndexBasedIncrement (DataDependenceGraph &ddg, const MoveNode &mn, long &loopIncrement)
 
static const MoveNodefindIncrement (const MoveNode &mn, long &increment)
 
static const MoveNodedetectConstantScale (const MoveNode &mn, int &shiftAmount)
 

Detailed Description

Definition at line 46 of file StackAliasAnalyzer.hh.

Constructor & Destructor Documentation

◆ StackAliasAnalyzer()

StackAliasAnalyzer::StackAliasAnalyzer ( const TCEString sp)

Definition at line 236 of file StackAliasAnalyzer.cc.

236 : sp_(sp) {
237}

◆ ~StackAliasAnalyzer()

StackAliasAnalyzer::~StackAliasAnalyzer ( )

Definition at line 234 of file StackAliasAnalyzer.cc.

234{}

Member Function Documentation

◆ analyze()

MemoryAliasAnalyzer::AliasingResult StackAliasAnalyzer::analyze ( DataDependenceGraph ddg,
const ProgramOperation pop1,
const ProgramOperation pop2,
MoveNodeUse::BBRelation  bbRel 
)
virtual

Analyzes aliasing of two memory adderesses.

Checks if they are stack offsets and compares the offsets.

Parameters
ddgddg where they belong.
node1first node to compare
anotheranpther node to compare
Returns
ALIAS_TRUE if they alias, ALIAS_FALSE if they don't or ALIAS_UNKNOWN if cannot analyze.

Implements MemoryAliasAnalyzer.

Definition at line 182 of file StackAliasAnalyzer.cc.

184 {
185
186 long addr1, addr2;
187 long incr1, incr2;
188 auto i = offsetData_.find(pop1.poId());
189 if (i != offsetData_.end()) {
190 if (i->second.first != INT_MAX) {
191 addr1 = i->second.first;
192 incr1 = i->second.second;
193 } else {
194 return ALIAS_UNKNOWN;
195 }
196 } else {
197 if (!(getStackOffset(ddg, pop1, addr1, incr1, sp_))) {
198 offsetData_[pop1.poId()] = std::make_pair(INT_MAX, incr1);
199 return ALIAS_UNKNOWN;
200 } else {
201 offsetData_[pop1.poId()] = std::make_pair(addr1, incr1);
202 }
203 }
204
205 i = offsetData_.find(pop2.poId());
206 if (i != offsetData_.end()) {
207 if (i->second.first != INT_MAX) {
208 addr2 = i->second.first;
209 incr2 = i->second.second;
210 } else {
211 return ALIAS_UNKNOWN;
212 }
213 } else {
214 if (!(getStackOffset(ddg, pop2, addr2, incr2, sp_))) {
215 offsetData_[pop2.poId()] = std::make_pair(INT_MAX, incr2);
216 return ALIAS_UNKNOWN;
217 } else {
218 offsetData_[pop2.poId()] = std::make_pair(addr2, incr2);
219 }
220
221 }
222
223 if (incr1 != incr2) {
224 return ALIAS_UNKNOWN;
225 }
226
227 if (bbRel != MoveNodeUse::LOOP) {
228 return compareIndeces(addr1, addr2, pop1, pop2);
229 } else {
230 return compareIndeces(addr1 + incr1, addr2, pop1, pop2);
231 }
232}
AliasingResult compareIndeces(int index1, int index2, const ProgramOperation &pop1, const ProgramOperation &pop2)
unsigned int poId() const
static bool getStackOffset(DataDependenceGraph &ddg, const ProgramOperation &pop, long &offset, long &loopIncrement, const TCEString &sp_)
std::map< int, std::pair< long, long > > offsetData_

References MemoryAliasAnalyzer::ALIAS_UNKNOWN, MemoryAliasAnalyzer::compareIndeces(), getStackOffset(), MoveNodeUse::LOOP, offsetData_, ProgramOperation::poId(), and sp_.

Here is the call graph for this function:

◆ getStackOffset()

bool StackAliasAnalyzer::getStackOffset ( DataDependenceGraph ddg,
const ProgramOperation pop,
long &  stackOffset,
long &  loopIncrement,
const TCEString sp 
)
static

Gets stack offset of a move which is transporting an address.

Parameters
ddgDDG where to track the address from.
nodeNode which transfers the address.
stackOffsetplace where to return the stack offset.
Returns
true if can calculate stack offset, false if not stack offset.

Definition at line 90 of file StackAliasAnalyzer.cc.

92 {
93
94 stackOffset = 0;
95 loopIncrement = 0;
96
97 // TODO: support for base+offset ops here.
98
99 const MoveNode* mn = addressOperandMove(pop);
100 if (mn == NULL) {
101
102 int offsetMul = 0;
103 TwoPartAddressOperandDetection addressParts =
105 switch(addressParts.offsetOperation) {
106 case TwoPartAddressOperandDetection::ADD:
107 offsetMul = 1;
108 break;
109 case TwoPartAddressOperandDetection::SUB:
110 offsetMul = -1;
111 break;
112 case TwoPartAddressOperandDetection::NOT_FOUND:
113 return false;
114 }
115
116 MoveNodeSet& addr1Set = pop.inputNode(addressParts.operand1);
117 MoveNodeSet& addr2Set = pop.inputNode(addressParts.operand2);
118 if (addr1Set.count() != 1) {
119 return false;
120 }
121 if (addr2Set.count() != 1) {
122 return false;
123 }
124 MoveNode& addr1 = addr1Set.at(0);
125 MoveNode& addr2 = addr2Set.at(0);
126
127 if (addr1.isSourceConstant()) {
128 int offsetVal = addr1.move().source().value().intValue();
129 stackOffset += (offsetMul * offsetVal);
130 mn = &addr2;
131 }
132
133 if (addr2.isSourceConstant()) {
134 int offsetVal = addr2.move().source().value().intValue();
135 stackOffset += (offsetMul * offsetVal);
136 mn = &addr1;
137 }
138 }
139
140 while(mn != NULL && mn->isMove()) {
141 if (mn->isSourceVariable()) {
142 if (mn->isSourceReg(sp)) {
143 return true;
144 }
145
146 MoveNode* prevSrc = ddg.onlyRegisterRawSource(*mn,2,2);
147 MoveNode* loopSrc = ddg.onlyRegisterRawSource(*mn,2,1);
148 // borken ddg??
149 if (prevSrc == NULL) {
150 break;
151 }
152 if (loopSrc) {
153 if (!findIncrement(*loopSrc, loopIncrement)) {
154 return false;
155 }
156 }
157 mn = prevSrc;
158 } else {
159 if (mn->isSourceOperation()) {
160 const MoveNode* incrementInput = findIncrement(*mn, stackOffset);
161 mn = incrementInput;
162 } else {
163 return false;
164 }
165 }
166 }
167 return false;
168}
MoveNode * onlyRegisterRawSource(const MoveNode &mn, int allowGuardEdges=2, int backEdges=0) const
static const MoveNode * findIncrement(const MoveNode &mn, long &increment)
static const MoveNode * addressOperandMove(const ProgramOperation &po)
static TwoPartAddressOperandDetection findTwoPartAddressOperands(const ProgramOperation &po)
int count() const
MoveNode & at(int index)
bool isSourceReg(const std::string &reg) const
Definition MoveNode.cc:798
bool isSourceVariable() const
Definition MoveNode.cc:196
bool isMove() const
TTAProgram::Move & move()
bool isSourceOperation() const
Definition MoveNode.cc:168
bool isSourceConstant() const
Definition MoveNode.cc:238
MoveNodeSet & inputNode(int in) const
int intValue() const
Definition SimValue.cc:895
Terminal & source() const
Definition Move.cc:302
virtual SimValue value() const
Definition Terminal.cc:178

References MemoryAliasAnalyzer::addressOperandMove(), MoveNodeSet::at(), MoveNodeSet::count(), MemoryAliasAnalyzer::findIncrement(), MemoryAliasAnalyzer::findTwoPartAddressOperands(), ProgramOperation::inputNode(), SimValue::intValue(), MoveNode::isMove(), MoveNode::isSourceConstant(), MoveNode::isSourceOperation(), MoveNode::isSourceReg(), MoveNode::isSourceVariable(), MoveNode::move(), MemoryAliasAnalyzer::TwoPartAddressOperandDetection::offsetOperation, DataDependenceGraph::onlyRegisterRawSource(), MemoryAliasAnalyzer::TwoPartAddressOperandDetection::operand1, MemoryAliasAnalyzer::TwoPartAddressOperandDetection::operand2, TTAProgram::Move::source(), and TTAProgram::Terminal::value().

Referenced by GlobalVsStackAA::analyze(), analyze(), GlobalVsStackAA::isAddressTraceable(), and isAddressTraceable().

Here is the call graph for this function:

◆ isAddressTraceable()

bool StackAliasAnalyzer::isAddressTraceable ( DataDependenceGraph ddg,
const ProgramOperation pop 
)
virtual

Checks if the node contains an adress that is an stack offset.

Parameters
ddgDDG where to analyze from
mnthe node being checked
Returns
true if is a traceable stack offset, false if not.

Implements MemoryAliasAnalyzer.

Definition at line 62 of file StackAliasAnalyzer.cc.

63 {
64 auto i = offsetData_.find(pop.poId());
65 if (i != offsetData_.end()) {
66 return i->second.first != INT_MAX;
67 } else {
68 long tmp, tmp2;
69 bool analyzable = getStackOffset(ddg, pop, tmp, tmp2, sp_);
70 if (analyzable) {
71 offsetData_[pop.poId()] = std::make_pair(tmp,tmp2);
72 return true;
73 } else {
74 offsetData_[pop.poId()] = std::make_pair(INT_MAX,tmp2);
75 return false;
76 }
77 }
78 return false;
79}

References getStackOffset(), offsetData_, ProgramOperation::poId(), and sp_.

Here is the call graph for this function:

Member Data Documentation

◆ offsetData_

std::map<int, std::pair<long, long> > StackAliasAnalyzer::offsetData_
private

Definition at line 62 of file StackAliasAnalyzer.hh.

Referenced by analyze(), and isAddressTraceable().

◆ sp_

TCEString StackAliasAnalyzer::sp_
private

Definition at line 64 of file StackAliasAnalyzer.hh.

Referenced by analyze(), and isAddressTraceable().


The documentation for this class was generated from the following files: