示例#1
0
AstNodePtr SymbolicFunction :: CodeGen( AstInterface &_fa) const
{
  AstInterface::AstNodeList l;
  for (const_iterator i = args.begin(); i != args.end(); ++i) {
     SymbolicVal cur = *i;
     AstNodePtr curast = cur.CodeGen(_fa); 
     l.push_back(curast);
  }
  if (t == AstInterface::OP_NONE) {
     return _fa.CreateFunctionCall( op, l);
  }
  else if (t == AstInterface::OP_ARRAY_ACCESS) {
        AstNodePtr arr = l.front();
        l.pop_front();
        return _fa.CreateArrayAccess(arr, l);
     }
  else if (t == AstInterface::OP_ASSIGN && l.size() == 2) {
        return _fa.CreateAssignment(l.front(), l.back());
     }
  else if (l.size() == 2) 
      return _fa.CreateBinaryOP( t, l.front(), l.back());
  else {
      assert(l.size() == 1);
      return _fa.CreateUnaryOP( t, l.front());
  }
}
示例#2
0
AstNodePtr ArrayInterface::
impl_access_array_elem (CPPAstInterface& fa, const AstNodePtr& array,
                           const AstInterface::AstNodeList& ivarAst)
{
  SymbolicFunctionDeclarationGroup elem;

  ArrayOptDescriptor desc;
  if (get_array_opt(fa, array, desc)) 
  {
    elem = desc.get_elem();
  }
  else 
  {
    ArrayDefineDescriptor desc1;
    if (!ArrayAnnotation::get_inst()->known_array( fa, array, &desc1))
      assert(false);
    elem = desc1.get_elem();
  }
  elem.replace_var("this", SymbolicAstWrap(array));
  elem.replace_var( "dimension", ivarAst.size());
  AstNodePtr r;
  if (! elem.get_val(fa, ivarAst, r))
     assert(false);
  return r;
}
示例#3
0
CopyArrayConfig 
ComputeCopyConfig( const DepCompAstRefAnal& stmtorder,
                   const DepCompCopyArrayCollect::CopyArrayUnit& unit,
                   const DepCompAstRefGraphNode* initcut)
{
    assert (unit.refs.size() > 0);

    AstInterface& ai = LoopTransformInterface::getAstInterface();
    const DepCompAstRef& initInfo = initcut->GetInfo();

    AstNodePtr lhs;
    bool is_init = ai.IsAssignment(initInfo.stmt->GetOrigStmt(), &lhs) 
                   && (lhs == initcut->GetInfo().orig);
    AstNodeType inittype;
    if (ai.IsExpression(initInfo.orig, &inittype)==AST_NULL)
      assert(false);
    bool has_write = false;

    AstNodePtr arr;
    std::string arrname, elemtypename;
    ai.GetTypeInfo(inittype, 0, &elemtypename); //QY: strip out ref info &
    AstNodeType elemtype = ai.GetType(elemtypename);

    AstInterface::AstNodeList initIndex;
    if (!LoopTransformInterface::IsArrayAccess(initInfo.orig, &arr, &initIndex) || !ai.IsVarRef(arr,0,&arrname))
       assert(false);

    SelectArray cursel(elemtype, arrname, initIndex.size());
    cursel.select(initInfo.stmt, unit.root, initIndex);

    for (DepCompCopyArrayCollect::CopyArrayUnit::NodeSet::const_iterator p = unit.refs.begin();
          !p.ReachEnd(); ++p)  {
        const DepCompAstRefGraphNode* curref = *p;
        const DepCompAstRef& curinfo = curref->GetInfo();
        if (stmtorder.is_mod_ref(curinfo.orig))
            has_write = true;
        AstInterface::AstNodeList curIndex;
        if (!LoopTransformInterface::IsArrayAccess(curinfo.orig, 0, &curIndex))
           assert(false);
        if (cursel.select(curinfo.stmt, unit.root, curIndex)) 
          is_init = false;
   }
   cursel.set_bufsize(ai);
   LoopTreeNode* shift = 0;
   if (unit.carrybyroot)
       shift = unit.root; 
   int copyopt = 0;
   if (!is_init) 
      copyopt |= INIT_COPY;
   if  (has_write)
      copyopt |= SAVE_COPY;
      
   CopyArrayOpt opt = (CopyArrayOpt)copyopt;
   CopyArrayConfig curconfig(ai, cursel, opt, shift);
   return curconfig;
}
示例#4
0
AstNodePtr LoopTransformInterface:: 
CreateDynamicFusionConfig( const AstNodePtr& groupNum, AstInterface::AstNodeList& args, int &id)
{ assert(fa != 0); 
  std::string name = "DynamicFusionConfig";
  ++configIndex;
  args.push_front( fa->CreateConstInt( args.size() ) );
  args.push_front( fa->CreateConstInt(configIndex) );
  AstNodePtr invoc = fa->CreateFunctionCall( "DynamicFusionConfig",  args); 
  return fa->CreateAssignment ( groupNum, invoc) ;
}
AstNodePtr LoopTransformInterface:: 
CreateDynamicFusionConfig( const AstNodePtr& groupNum, AstInterface::AstNodeList& args, int &id)
{ assert(fa != 0); 
  std::string name = "DynamicFusionConfig";
  ++configIndex;
  args.push_back( fa->CreateConstInt(configIndex).get_ptr() );
  args.push_back( fa->CreateConstInt( args.size() ).get_ptr() );
  std::string funname = "DynamicFusionConfig";
  AstNodePtr invoc = fa->CreateFunctionCall( funname,  args.begin(), args.end()); 
  return fa->CreateAssignment ( groupNum, invoc) ;
}
ReplaceParams:: 
ReplaceParams ( const ParamDescriptor& decl, AstInterface::AstNodeList& args,
                Map2Object<AstInterface*,AstNodePtr,AstNodePtr>* codegen)
{
  assert(decl.size() == args.size());
  int index = 0;
  for (AstInterface::AstNodeList::iterator p1 = args.begin();
       p1 != args.end(); ++p1, ++index) {
    AstNodePtr curAst = *p1;
    string curpar = decl[index];
    SymbolicAstWrap curarg(curAst, codegen);
    parmap[curpar] = curarg;
  }
}
示例#7
0
AstNodePtr ArrayUseAccessFunction::
CreateArrayAccess( AstInterface& fa, const AstNodePtr& arr,
                                AstInterface::AstNodeList& index)
{
  if (prev != 0)
     return prev->CreateArrayAccess(fa, arr, index);
  if (index.size() > 1) {
     AstInterface::AstNodeList tmp = index;
     tmp.push_front(arr);
     return fa.CreateFunctionCall(funcname, tmp);
  }
  else 
     return fa.CreateArrayAccess(arr, index);
}
示例#8
0
AstNodePtr ArrayInterface::
impl_reshape_array( CPPAstInterface& fa, 
                    const AstNodePtr& array,
                    AstInterface::AstNodeList& ivarAst)
{
  ArrayDefineDescriptor desc;
  if (!ArrayAnnotation::get_inst()->known_array( fa, array, &desc))
    return AST_NULL;

  SymbolicFunctionDeclarationGroup reshape = desc.get_reshape();
  reshape.replace_var( "this", SymbolicAstWrap(array));
  reshape.replace_var( "dimension", ivarAst.size());

  AstNodePtr r;
  if (!reshape.get_val( fa, ivarAst, r)) {
     std::cerr << "Error: cannot extract value from reshape spec: \n";
     reshape.write(std::cerr);
     std::cerr << std::endl;
     assert(false);
  }
  return r;
}