DifferentiableLocsVisitor.cpp

Go to the documentation of this file.
00001 
00015 #include <OpenAnalysis/ExprTree/DifferentiableLocsVisitor.hpp>
00016 
00017 namespace OA {
00018 
00019 //static bool debug = true;
00020 
00021 DifferentiableLocsVisitor::DifferentiableLocsVisitor(
00022           OA_ptr<Alias::Interface> alias) : mAlias(alias)
00023 {
00024 }
00025 
00028 void DifferentiableLocsVisitor::visitNode(ExprTree::Node&)
00029 {
00030     assert(0);
00031 }
00032 
00033 void DifferentiableLocsVisitor::visitOpNode(ExprTree::OpNode& n)
00034 {
00035     
00036   // visit each child
00037   OA_ptr<ExprTree::Node> nodePtr;
00038   ExprTree::ChildNodesIterator cNodesIter(n);
00039   for ( ; cNodesIter.isValid(); ++cNodesIter) {
00040       nodePtr = cNodesIter.current();
00041 
00042       nodePtr->acceptVisitor(*this);
00043   } 
00044 }
00045 
00046 void DifferentiableLocsVisitor::visitCallNode(ExprTree::CallNode& n)
00047 {
00048   // not doing anything because callsite parameter expressions
00049   // will be visited separately
00050 
00051 }
00052 
00053 void DifferentiableLocsVisitor::visitMemRefNode(ExprTree::MemRefNode& n)
00054 {
00055     
00056   MemRefHandle memref = n.getHandle();
00057 
00058   //if (debug) {
00059   //  std::cout << "DiffLocsVisitor::visitMemRefNode():\n"
00060   //            << "\tmemRefHandle = (hval= " << memref.hval() << ")\n";
00061   //}
00062 
00063   // add all may locations of this reference to our set of differentiable
00064   // locations.  Notice that MemRefNode will only have top
00065   // memory reference handle.  For example, if memory reference is A[i] then
00066   // there is no way to get to memory reference handle for i through the
00067   // expression tree for A[i] + 3.  This is good in this case because array
00068   // index variables aren't considered differentiable.
00069   OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(memref);
00070 
00071   for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00072     //if (debug) {
00073     //  std::cout << "\t\tinserting loc into mDiffLocs\n";
00074     //}
00075       mDiffLocs->insert(locIterPtr->current());
00076   }
00077 }
00078 
00079 void DifferentiableLocsVisitor::visitConstSymNode(ExprTree::ConstSymNode& n)
00080 {
00081     
00082   // constants aren't differentiable
00083 }
00084 
00085 void DifferentiableLocsVisitor::visitConstValNode(ExprTree::ConstValNode& n)
00086 {
00087 
00088   // constants aren't differentiable
00089 }
00090 
00091 
00092 } // end of OA namespace
00093