OpenASIP  2.0
ConstantAliasAnalyzer.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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 ConstantAliasAnalyzer.cc
26  *
27  * Implementation of ConstantAliasAnalyzer class.
28  *
29  * This class does simple alias analysis between memove addresses
30  * that come directly from immediates.
31  *
32  * @author Heikki Kultala 2007 (heikki.kultala-no.spam-tut.fi)
33  * @note rating: red
34  */
35 
36 #include "ConstantAliasAnalyzer.hh"
37 
38 #include "MoveNode.hh"
39 #include "Move.hh"
40 #include "DataDependenceGraph.hh"
41 #include "Terminal.hh"
42 #include "Operation.hh"
43 #include "MoveNodeSet.hh"
44 
45 using namespace TTAProgram;
46 using namespace TTAMachine;
47 
48 
49 
51  DataDependenceGraph& ddg, const ProgramOperation& po,
52  long& addr, long& loopIncrement) {
53  const MoveNode* mn = addressOperandMove(po);
54  addr = 0;
55  while (mn != NULL && mn->isMove()) {
56  if (mn->isSourceVariable()) {
57  MoveNode* prevSrc = ddg.onlyRegisterRawSource(*mn,2,2);
58  MoveNode* loopSrc = ddg.onlyRegisterRawSource(*mn,2,1);
59  if (prevSrc == NULL) {
60  break;
61  }
62  if (loopSrc) {
63  if (!findIncrement(*loopSrc, loopIncrement)) {
64  return false;
65  }
66  }
67  mn = prevSrc;
68  } else {
69  if (mn->isSourceOperation()) {
70  const MoveNode* incrementInput = findIncrement(*mn, addr);
71  if (incrementInput != NULL) {
72  mn = incrementInput;
73  } else {
74  mn = searchLoopIndexBasedIncrement(ddg, *mn, loopIncrement);
75  }
76  } else {
77  if (mn->isMove()) {
78  const Move& move = mn->move();
79  if (!move.isFunctionCall()) {
80  const Terminal& src = move.source();
81  if (src.isImmediate()) {
82  addr += src.value().unsignedValue();
83  return true;
84  }
85  }
86  }
87  return false;
88  }
89  }
90  }
91  return false;
92 }
93 
94 bool
96  DataDependenceGraph& ddg, const ProgramOperation& po) {
97  long tmp;
98  long tmp2 = 0;
99  return getConstantAddress(ddg, po, tmp, tmp2);
100 }
101 
102 // TODO: does not handle unaligned 64-bit memory operations well.
105  DataDependenceGraph& ddg,
106  const ProgramOperation& pop1,
107  const ProgramOperation& pop2,
108  MoveNodeUse::BBRelation bbRel) {
109 
110  long addr1, addr2;
111  long inc1 = 0, inc2 = 0;
112 
113  if (!getConstantAddress(ddg, pop1, addr1, inc1) ||
114  !getConstantAddress(ddg, pop2, addr2, inc2)) {
115  return ALIAS_UNKNOWN;
116  }
117 
118  // if updated different amount, may overlap?
119  if (inc1 != inc2) {
120  return ALIAS_UNKNOWN;
121  }
122 
123  if (bbRel != MoveNodeUse::LOOP) {
124  return compareIndeces(addr1, addr2, pop1, pop2);
125  } else {
126  return compareIndeces(addr1, addr2+inc2, pop1, pop2);
127  }
128 }
129 
TTAProgram
Definition: Estimator.hh:65
ConstantAliasAnalyzer::~ConstantAliasAnalyzer
~ConstantAliasAnalyzer()
Definition: ConstantAliasAnalyzer.cc:130
MoveNodeUse::BBRelation
BBRelation
Definition: MoveNodeUse.hh:23
TTAProgram::Move::isFunctionCall
bool isFunctionCall() const
Definition: Move.cc:219
DataDependenceGraph.hh
ProgramOperation
Definition: ProgramOperation.hh:70
MoveNode
Definition: MoveNode.hh:65
Terminal.hh
ConstantAliasAnalyzer.hh
DataDependenceGraph::onlyRegisterRawSource
MoveNode * onlyRegisterRawSource(const MoveNode &mn, int allowGuardEdges=2, int backEdges=0) const
Definition: DataDependenceGraph.cc:4083
ConstantAliasAnalyzer::analyze
virtual AliasingResult analyze(DataDependenceGraph &ddg, const ProgramOperation &pop1, const ProgramOperation &pop2, MoveNodeUse::BBRelation bbInfo)
Definition: ConstantAliasAnalyzer.cc:104
MemoryAliasAnalyzer::AliasingResult
AliasingResult
Definition: MemoryAliasAnalyzer.hh:50
MoveNode::isMove
bool isMove() const
Operation.hh
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
TTAProgram::Terminal::value
virtual SimValue value() const
Definition: Terminal.cc:178
TTAProgram::Move
Definition: Move.hh:55
MoveNodeUse::LOOP
@ LOOP
Definition: MoveNodeUse.hh:26
ConstantAliasAnalyzer::isAddressTraceable
virtual bool isAddressTraceable(DataDependenceGraph &ddg, const ProgramOperation &pop)
Definition: ConstantAliasAnalyzer.cc:95
SimValue::unsignedValue
unsigned int unsignedValue() const
Definition: SimValue.cc:919
MoveNode::isSourceVariable
bool isSourceVariable() const
Definition: MoveNode.cc:196
MoveNode::move
TTAProgram::Move & move()
MoveNodeSet.hh
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
ConstantAliasAnalyzer::getConstantAddress
static bool getConstantAddress(DataDependenceGraph &ddg, const ProgramOperation &po, long &addr, long &loopIncrement)
Definition: ConstantAliasAnalyzer.cc:50
Move.hh
TTAMachine
Definition: Assembler.hh:48
TTAProgram::Terminal::isImmediate
virtual bool isImmediate() const
Definition: Terminal.cc:63
MoveNode.hh