From patchwork Wed Nov 4 22:10:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 540198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 07CCC1413E0 for ; Thu, 5 Nov 2015 09:10:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=TrtNg7IS; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=XvhRljqMgDtNLYXVe iVCDVxUXKoIWKxsKdcoVR2PxyFMSeFRNHvGgFCVL4LuF1JM9aXh/MznegVpfk+eb toj8fVq4tucUuGlw3T8ioYW327nNy33EieJhV6Tip7m69txlP8D6046PMcEc/9E+ dRSGGRER68UaKrN5bIQSykntaA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=PfJC7MyOfRM4hxE2jKIw3FL BW74=; b=TrtNg7ISRZG8j71Bp394GAFAly2kLq+f4SZZGdD5SNWi6z3q5QGy3P0 nb3fZSqFjdPJ3mZ9fhdCcIJkhOf+KECrABJB8wivDyLXJPw45yqA8PlME9zE2Hoz mmwWICBRBIBdC6IrQIgEIFQ3hYbtM1heTOuOEfYUEis3R5UV0Qms= Received: (qmail 101056 invoked by alias); 4 Nov 2015 22:10:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 101005 invoked by uid 89); 4 Nov 2015 22:10:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Nov 2015 22:10:33 +0000 Received: from svr-orw-fem-05.mgc.mentorg.com ([147.34.97.43]) by relay1.mentorg.com with esmtp id 1Zu6GE-0001g2-Cg from Cesar_Philippidis@mentor.com ; Wed, 04 Nov 2015 14:10:30 -0800 Received: from [127.0.0.1] (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.3.224.2; Wed, 4 Nov 2015 14:10:29 -0800 Subject: Re: [OpenACC] num_gangs, num_workers and vector_length in c++ To: Jason Merrill , Jakub Jelinek References: <5632A573.80002@codesourcery.com> <20151030133753.GA478@tucnak.redhat.com> <563381DF.7030005@codesourcery.com> <20151030170555.GE478@tucnak.redhat.com> <5633DF72.4070006@codesourcery.com> <563A49DD.9070107@redhat.com> CC: "gcc-patches@gcc.gnu.org" , Nathan Sidwell From: Cesar Philippidis Message-ID: <563A8255.3060401@codesourcery.com> Date: Wed, 4 Nov 2015 14:10:29 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <563A49DD.9070107@redhat.com> On 11/04/2015 10:09 AM, Jason Merrill wrote: > A single function is better, to avoid unnecessary code duplication. Thanks. I've applied this patch to trunk. Cesar 2015-11-04 Cesar Philippidis gcc/cp/ * (cp_parser_oacc_single_int_clause): New function. (cp_parser_oacc_clause_vector_length): Delete. (cp_parser_omp_clause_num_gangs): Delete. (cp_parser_omp_clause_num_workers): Delete. (cp_parser_oacc_all_clauses): Use cp_parser_oacc_single_int_clause for num_gangs, num_workers and vector_length. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 12452e6..4f6cd2d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -29590,6 +29590,39 @@ cp_parser_oacc_simple_clause (cp_parser * /* parser */, return c; } + /* OpenACC: + num_gangs ( expression ) + num_workers ( expression ) + vector_length ( expression ) */ + +static tree +cp_parser_oacc_single_int_clause (cp_parser *parser, omp_clause_code code, + const char *str, tree list) +{ + location_t loc = cp_lexer_peek_token (parser->lexer)->location; + + if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) + return list; + + tree t = cp_parser_assignment_expression (parser, NULL, false, false); + + if (t == error_mark_node + || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) + { + cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + return list; + } + + check_no_duplicate_clause (list, code, str, loc); + + tree c = build_omp_clause (loc, code); + OMP_CLAUSE_OPERAND (c, 0) = t; + OMP_CLAUSE_CHAIN (c) = list; + return c; +} + /* OpenACC: gang [( gang-arg-list )] @@ -29713,45 +29746,6 @@ cp_parser_oacc_shape_clause (cp_parser *parser, omp_clause_code kind, return list; } -/* OpenACC: - vector_length ( expression ) */ - -static tree -cp_parser_oacc_clause_vector_length (cp_parser *parser, tree list) -{ - tree t, c; - location_t location = cp_lexer_peek_token (parser->lexer)->location; - bool error = false; - - if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) - return list; - - t = cp_parser_condition (parser); - if (t == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (t))) - { - error_at (location, "expected positive integer expression"); - error = true; - } - - if (error || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) - { - cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, - /*or_comma=*/false, - /*consume_paren=*/true); - return list; - } - - check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length", - location); - - c = build_omp_clause (location, OMP_CLAUSE_VECTOR_LENGTH); - OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t; - OMP_CLAUSE_CHAIN (c) = list; - list = c; - - return list; -} - /* OpenACC 2.0 Parse wait clause or directive parameters. */ @@ -30130,42 +30124,6 @@ cp_parser_omp_clause_nowait (cp_parser * /*parser*/, return c; } -/* OpenACC: - num_gangs ( expression ) */ - -static tree -cp_parser_omp_clause_num_gangs (cp_parser *parser, tree list) -{ - tree t, c; - location_t location = cp_lexer_peek_token (parser->lexer)->location; - - if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) - return list; - - t = cp_parser_condition (parser); - - if (t == error_mark_node - || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) - cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, - /*or_comma=*/false, - /*consume_paren=*/true); - - if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) - { - error_at (location, "expected positive integer expression"); - return list; - } - - check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs", location); - - c = build_omp_clause (location, OMP_CLAUSE_NUM_GANGS); - OMP_CLAUSE_NUM_GANGS_EXPR (c) = t; - OMP_CLAUSE_CHAIN (c) = list; - list = c; - - return list; -} - /* OpenMP 2.5: num_threads ( expression ) */ @@ -30374,43 +30332,6 @@ cp_parser_omp_clause_defaultmap (cp_parser *parser, tree list, return list; } -/* OpenACC: - num_workers ( expression ) */ - -static tree -cp_parser_omp_clause_num_workers (cp_parser *parser, tree list) -{ - tree t, c; - location_t location = cp_lexer_peek_token (parser->lexer)->location; - - if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) - return list; - - t = cp_parser_condition (parser); - - if (t == error_mark_node - || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) - cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, - /*or_comma=*/false, - /*consume_paren=*/true); - - if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) - { - error_at (location, "expected positive integer expression"); - return list; - } - - check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_gangs", - location); - - c = build_omp_clause (location, OMP_CLAUSE_NUM_WORKERS); - OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t; - OMP_CLAUSE_CHAIN (c) = list; - list = c; - - return list; -} - /* OpenMP 2.5: ordered @@ -31422,6 +31343,7 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, { location_t here; pragma_omp_clause c_kind; + omp_clause_code code; const char *c_name; tree prev = clauses; @@ -31488,12 +31410,16 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, c_name = "if"; break; case PRAGMA_OACC_CLAUSE_NUM_GANGS: - clauses = cp_parser_omp_clause_num_gangs (parser, clauses); + code = OMP_CLAUSE_NUM_GANGS; c_name = "num_gangs"; + clauses = cp_parser_oacc_single_int_clause (parser, code, c_name, + clauses); break; case PRAGMA_OACC_CLAUSE_NUM_WORKERS: - clauses = cp_parser_omp_clause_num_workers (parser, clauses); c_name = "num_workers"; + code = OMP_CLAUSE_NUM_WORKERS; + clauses = cp_parser_oacc_single_int_clause (parser, code, c_name, + clauses); break; case PRAGMA_OACC_CLAUSE_PRESENT: clauses = cp_parser_oacc_data_clause (parser, c_kind, clauses); @@ -31534,8 +31460,10 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, c_name, clauses); break; case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH: - clauses = cp_parser_oacc_clause_vector_length (parser, clauses); c_name = "vector_length"; + code = OMP_CLAUSE_VECTOR_LENGTH; + clauses = cp_parser_oacc_single_int_clause (parser, code, c_name, + clauses); break; case PRAGMA_OACC_CLAUSE_WAIT: clauses = cp_parser_oacc_clause_wait (parser, clauses);