コード例 #1
0
ファイル: pfor_selector.cpp プロジェクト: zmanchun/insieme
	RegionList PForBodySelector::getRegions(const core::NodePtr& node) const {
		RegionList res;
		auto pfor = node->getNodeManager().getLangExtension<lang::ParallelExtension>().getPFor();
		core::visitDepthFirstPrunable(core::NodeAddress(node), [&](const core::CallExprAddress& cur) -> bool {
			if(*cur.getAddressedNode()->getFunctionExpr() != *pfor) { return false; }
			core::ExpressionAddress body = cur->getArgument(4);
			if(body->getNodeType() == core::NT_BindExpr) { body = body.as<core::BindExprAddress>()->getCall()->getFunctionExpr(); }
			if(body->getNodeType() == core::NT_LambdaExpr) { res.push_back(body.as<core::LambdaExprAddress>()->getBody()); }
			return true;
		}, false);

		return res;
	}
コード例 #2
0
ファイル: meta_infos.cpp プロジェクト: insieme/insieme
	void migrateMetaInfos(const core::NodePtr& src, const core::NodePtr& dest) {
		// skip operation if there is nothing to do
		if(!src || !dest || src == dest) { return; }

		// just iterate through all annotations and move meta information
		for(const auto& cur : src->getAnnotations()) {
			// skip non-meta info annotations
			if(!isMetaInfo(cur.second)) { continue; }

			// move annotation (using the clone operation)
			cur.second->clone(cur.second, dest);
		}
	}
コード例 #3
0
ファイル: header_tagger.cpp プロジェクト: zmanchun/insieme
void HeaderTagger::addHeaderForDecl(const core::NodePtr& node, const clang::Decl* decl, bool attachUserDefined) const {
	// check whether there is a declaration at all
	if(!decl) { return; }

	// the node was already annotated, what is the point of doint it again?
	if(insieme::annotations::c::hasIncludeAttached(node)) { return; }

	if(VLOG_IS_ON(2)) {
		std::string name("UNNAMED");
		if(const clang::NamedDecl* nmd = llvm::dyn_cast<clang::NamedDecl>(decl)) { name = nmd->getQualifiedNameAsString(); }
		VLOG(2) << "Searching header for: " << node << " of type " << node->getNodeType() << " [clang: " << name << "]";
	}

	string fileName = getTopLevelInclude(decl->getLocation());

	// file must be a header file
	if(!isHeaderFile(fileName)) {
		VLOG(2) << "'" << fileName << "' not a headerfile";
		return; // not to be attached
	}

	// do not add headers for external declarations unless those are within the std-library
	if(const clang::FunctionDecl* funDecl = llvm::dyn_cast<clang::FunctionDecl>(decl)) {
		// TODO: this is just based on integration tests - to make them work, no real foundation :(
		if(funDecl->isExternC() && !(isStdLibHeader(fileName) || isIntrinsicHeader(fileName))) { return; }
	}

	// get absolute path of header file
	fs::path header = fs::canonical(fileName);

	if(auto stdLibHeader = toStdLibHeader(header)) {
		header = *stdLibHeader;
	} else if(auto interceptedLibHeader = toInterceptedLibHeader(header)) {
		header = *interceptedLibHeader;
	} else if(auto intrinsicHeader = toIntrinsicHeader(header)) {
		header = *intrinsicHeader;
	} else if(auto userLibHeader = toUserLibHeader(header)) {
		if(attachUserDefined) {
			header = *userLibHeader;
		} else {
			return;
		}
	}

	VLOG(2) << "		header to be attached: " << header.string();

	// use resulting header
	insieme::annotations::c::attachInclude(node, header.string());
}
コード例 #4
0
	RegionList ParallelSelector::getRegions(const core::NodePtr& node) const {
		RegionList res;
		auto parallel = node->getNodeManager().getLangExtension<lang::ParallelExtension>().getParallel();
		core::visitDepthFirst(core::NodeAddress(node), [&](const core::CallExprAddress& cur) -> bool {
			if(*cur.getAddressedNode()->getFunctionExpr() != *parallel) { return false; }

			core::JobExprAddress job = cur->getArgument(0).as<core::JobExprAddress>();
			core::ExpressionAddress addr = job->getBody();

			if(addr->getNodeType() == core::NT_BindExpr) { addr = addr.as<core::BindExprAddress>()->getCall()->getFunctionExpr(); }

			if(addr->getNodeType() == core::NT_LambdaExpr) { res.push_back(addr.as<core::LambdaExprAddress>()->getBody()); }

			return true;

		}, false);

		return res;
	}
コード例 #5
0
ファイル: name_manager.cpp プロジェクト: zmanchun/insieme
	void SimpleNameManager::setName(const core::NodePtr& ptr, const string& name) {
		// disabled since name collisions might happen with overloaded functions!
		// assert_true((!isUsed(name) || (lookup(ptr) && *lookup(ptr) == name))) << "Cannot bind to name already used!";

		// everything is in the global scope
		auto names = &globalScope.names;
		auto used = &globalScope.usedNames;

		// unless it is a variable
		if(ptr->getNodeType() == core::NT_Variable) {
			names = &varScope.back().names;
			used = &varScope.back().usedNames;
		}

		// insert into data structures
		__unused auto res = names->insert(make_pair(ptr, name));

		// disabled since name collisions might happen with overloaded member functions!
		// assert_true((res.second || res.first->second == name)) << "Tried to alter name after already being bound!";
		used->insert(name);
	}