bool InstanceModel::SaveGroupInfo(wxString file) const { if (file.IsEmpty()) file = m_groupFile; using namespace boost::property_tree; ptree pt; pt.put<int>("formatVersion", GROUP_FILE_FORMAT_VERSION); try { typedef std::map<InstanceGroup *, InstVector> GroupListMap; GroupListMap groupLists; for (auto iter = m_instances.begin(); iter != m_instances.end(); iter++) { InstanceGroup *group = GetInstanceGroup(*iter); if (group != nullptr) groupLists[group].push_back(*iter); } ptree groupsPtree; for (auto iter = groupLists.begin(); iter != groupLists.end(); iter++) { InstanceGroup *group = iter->first; InstVector gList = iter->second; ptree groupTree; groupTree.put<bool>("hidden", group->IsHidden()); ptree instList; for (auto iter2 = gList.begin(); iter2 != gList.end(); iter2++) { instList.push_back(std::make_pair("", ptree(stdStr((*iter2)->GetInstID())))); } groupTree.put_child("instances", instList); groupsPtree.push_back(std::make_pair(stdStr(group->GetName()), groupTree)); } pt.put_child("groups", groupsPtree); write_json(stdStr(file), pt); } catch (json_parser_error e) { wxLogError(_("Failed to read group list.\nJSON parser error at line %i: %s"), e.line(), wxStr(e.message()).c_str()); return false; } catch (ptree_error e) { wxLogError(_("Failed to save group list. Unknown ptree error.")); return false; } return true; }
//------------------------------------------------------------------------------ InstVector filterUsers(llvm::Instruction *used, InstVector &users) { BasicBlock *block = used->getParent(); InstVector result; std::copy_if( users.begin(), users.end(), std::back_inserter(result), [block](Instruction *inst) { return inst->getParent() == block; }); return result; }
//------------------------------------------------------------------------------ // Build a vector with all the uses of the given value. InstVector findUsers(llvm::Value *value) { InstVector result; for (auto user = value->user_begin(), end = value->user_end(); user != end; ++user) { if (Instruction *inst = dyn_cast<Instruction>(*user)) { result.push_back(inst); } } return result; }
//------------------------------------------------------------------------------ void applyMap(InstVector &insts, Map &map, InstVector &result) { result.clear(); result.reserve(insts.size()); for (auto inst : insts) { Value *newValue = map[inst]; if (newValue != nullptr) { if (Instruction *newInst = dyn_cast<Instruction>(newValue)) { result.push_back(newInst); } } } }
void QpTree::makeQpTree(InstVector &insts) { IPF_ASSERT(qpMap.size() == 1); slot = 1; // init slot (position in mask) for (InstVector::iterator it=insts.begin(); it!=insts.end(); it++) { Inst *inst = *it; // iterate insts if (isDefOnePred(inst)) { // if inst defs one predicate opnd OpndVector &opnds = inst->getOpnds(); // get opnds of the inst QpNode *qpNode = findQpNode(opnds[0]); // inst qp is predecessor for predicates defined in the inst makeQpNode(qpNode, opnds[2]); // make qpNode for the predicate opnd (it is always second one) continue; } if (isDefTwoPreds(inst)) { // if inst defs two predicate opnds OpndVector &opnds = inst->getOpnds(); // get opnds of the inst QpNode *qpNode = findQpNode(opnds[0]); // inst qp is predecessor for predicates defined in the inst QpNode *p1Node = makeQpNode(qpNode, opnds[1]); // make qpNode for first predicate opnd QpNode *p2Node = makeQpNode(qpNode, opnds[2]); // make qpNode for second predicate opnd if (isDefComps(inst) == false) continue; // inst does not define mutually complemen predicates - continue if (p1Node != NULL) p1Node->setCompNode(p2Node); // p2Node complements p1Node if (p2Node != NULL) p2Node->setCompNode(p1Node); // p1Node complements p2Node } } for (QpMap::iterator it=qpMap.begin(); it!=qpMap.end(); it++) { QpNode *qpNode = it->second; // iterate all qpNodes in the tree qpNode->initCompMask(); // set comp mask (to speed up getCompMask) } for (QpMap::iterator it=qpMap.begin(); it!=qpMap.end(); it++) { QpNode *qpNode = it->second; // iterate all qpNodes in the tree qpNode->initLiveMask(); // set live masks (predicate spaces which do not complement) } }
//------------------------------------------------------------------------------ ValueVector ToValueVector(InstVector &insts) { ValueVector result; std::copy(insts.begin(), insts.end(), std::back_inserter(result)); return result; }