From 1ee88d3c81cec19f5a54b593f2b40e5084dc57f9 Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Wed, 20 Feb 2019 08:57:05 -0800 Subject: [PATCH] [flang] Fixes for building with clang++ and other misc. from review Original-commit: flang-compiler/f18@c3cdc327863036213dab26abf9e97f23a968c197 Reviewed-on: https://github.com/flang-compiler/f18/pull/319 Tree-same-pre-rewrite: false --- flang/lib/FIR/afforestation.cc | 18 +++++++++++++++++- flang/lib/FIR/afforestation.h | 4 ++-- flang/lib/FIR/builder.h | 2 +- flang/lib/FIR/common.h | 4 ++-- flang/lib/FIR/graph-writer.h | 3 ++- flang/lib/FIR/mixin.h | 18 +++++++++++------- flang/lib/FIR/procedure.h | 2 +- flang/lib/FIR/program.h | 2 +- flang/lib/FIR/statement.def | 32 ++++++++++++++++---------------- flang/lib/FIR/statements.cc | 4 ++-- flang/lib/FIR/statements.h | 19 ++++++++++--------- flang/lib/FIR/stmt.h | 9 +++++---- 12 files changed, 70 insertions(+), 47 deletions(-) diff --git a/flang/lib/FIR/afforestation.cc b/flang/lib/FIR/afforestation.cc index 1934673..5d114fc 100644 --- a/flang/lib/FIR/afforestation.cc +++ b/flang/lib/FIR/afforestation.cc @@ -240,6 +240,7 @@ std::tuple FindStack( SEMANTICS_FAILED("construct name not on stack"); return {}; } + template parser::Label GetErr(const T &stmt) { if constexpr (std::is_same_v || std::is_same_v) { @@ -271,6 +272,7 @@ template parser::Label GetErr(const T &stmt) { } return 0; } + template parser::Label GetEor(const T &stmt) { if constexpr (std::is_same_v || std::is_same_v) { @@ -289,6 +291,7 @@ template parser::Label GetEor(const T &stmt) { } return 0; } + template parser::Label GetEnd(const T &stmt) { if constexpr (std::is_same_v || std::is_same_v) { @@ -307,6 +310,7 @@ template parser::Label GetEnd(const T &stmt) { } return 0; } + template void errLabelSpec(const T &s, std::list &ops, const parser::Statement &ec, AnalysisData &ad) { @@ -319,6 +323,7 @@ void errLabelSpec(const T &s, std::list &ops, ops.emplace_back(LinearAction{ec}); } } + template void threeLabelSpec(const T &s, std::list &ops, const parser::Statement &ec, AnalysisData &ad) { @@ -339,6 +344,7 @@ void threeLabelSpec(const T &s, std::list &ops, ops.emplace_back(LinearAction{ec}); } } + template std::vector toLabelRef(AnalysisData &ad, const T &labels) { std::vector result; @@ -523,12 +529,14 @@ Evaluation GetSwitchCaseSelector(const parser::CaseConstruct *caseConstruct) { .statement.t) .thing.typedExpr.get()}; } + template const std::optional &GetSwitchAssociateName( const CT *selectConstruct) { return std::get<1>( std::get>(selectConstruct->t).statement.t); } + template void DumpSwitchWithSelector( const CONSTRUCT *construct, char const *const name, GSF getSelector) { @@ -845,9 +853,10 @@ struct SwitchTypeArguments { }; template -static bool IsDefault(const typename T::ValueType &valueType) { +bool IsDefault(const typename T::ValueType &valueType) { return std::holds_alternative(valueType); } + template void cleanupSwitchPairs(LinearLabelRef &defLab, std::vector &values, @@ -908,6 +917,7 @@ static std::vector populateSwitchValues( } return result; } + static std::vector populateSwitchValues( const std::list &list) { std::vector result; @@ -932,6 +942,7 @@ static std::vector populateSwitchValues( } return result; } + static std::vector populateSwitchValues( const std::list &list) { std::vector result; @@ -1036,6 +1047,7 @@ const T *FindReadWriteSpecifier( } return nullptr; } + const parser::IoUnit *FindReadWriteIoUnit( const std::optional &ioUnit, const std::list &specifiers) { @@ -1142,7 +1154,9 @@ struct FortranIRLowering { ~FortranIRLowering() { CHECK(!builder_); } template constexpr bool Pre(const A &) { return true; } + template constexpr void Post(const A &) {} + void Post(const parser::MainProgram &mainp) { std::string mainName{"_MAIN"s}; if (auto &ps{ @@ -1168,6 +1182,7 @@ struct FortranIRLowering { } Program *program() { return fir_; } + template void ProcessRoutine(const T &here, const std::string &name) { CHECK(!fir_->containsProcedure(name)); @@ -1853,6 +1868,7 @@ struct FortranIRLowering { falseBlock, _1)); } } + template void AddOrQueueSwitch(const Evaluation &condition, LinearLabelRef defaultLabel, diff --git a/flang/lib/FIR/afforestation.h b/flang/lib/FIR/afforestation.h index 3906665..4b89c36 100644 --- a/flang/lib/FIR/afforestation.h +++ b/flang/lib/FIR/afforestation.h @@ -18,7 +18,7 @@ #include namespace Fortran::parser { -class Program; +struct Program; } namespace Fortran::semantics { @@ -34,4 +34,4 @@ Program *CreateFortranIR(const parser::Program &program, semantics::SemanticsContext &semanticsContext, bool debugLinearIR = false); } -#endif +#endif // FORTRAN_FIR_AFFORESTATION_H_ diff --git a/flang/lib/FIR/builder.h b/flang/lib/FIR/builder.h index fc653df..c962dac 100644 --- a/flang/lib/FIR/builder.h +++ b/flang/lib/FIR/builder.h @@ -68,7 +68,7 @@ struct FIRBuilder { return Insert(DeallocateStmt::Create(object)); } template Statement &CreateExpr(const A *a) { - return Insert(ExprStmt::Create(a)); + return Insert(ApplyExprStmt::Create(a)); } Statement &CreateIOCall( InputOutputCallType call, IOCallArguments &&arguments) { diff --git a/flang/lib/FIR/common.h b/flang/lib/FIR/common.h index e99af2d..e426ed0 100644 --- a/flang/lib/FIR/common.h +++ b/flang/lib/FIR/common.h @@ -39,8 +39,8 @@ namespace Fortran::FIR { class Statement; class BasicBlock; -struct Program; -struct GraphWriter; +class Program; +class GraphWriter; struct Attribute { enum { IntentIn, IntentOut, IntentInOut } attribute; diff --git a/flang/lib/FIR/graph-writer.h b/flang/lib/FIR/graph-writer.h index bf380f9..14bea2a 100644 --- a/flang/lib/FIR/graph-writer.h +++ b/flang/lib/FIR/graph-writer.h @@ -26,7 +26,8 @@ namespace Fortran::FIR { -struct GraphWriter { +class GraphWriter { +public: static void setOutput(llvm::raw_ostream *output) { defaultOutput_ = output; } static void setOutput(const std::string &filename) { std::error_code ec; diff --git a/flang/lib/FIR/mixin.h b/flang/lib/FIR/mixin.h index 763bd33..bde2895 100644 --- a/flang/lib/FIR/mixin.h +++ b/flang/lib/FIR/mixin.h @@ -23,9 +23,11 @@ namespace Fortran::FIR { +inline constexpr bool has_size(std::size_t size) { return size > 0; } + template struct SumTypeMixin {}; template // T must be std::variant<...> -struct SumTypeMixin>> { +struct SumTypeMixin)>> { template SumTypeMixin(A &&x) : u{std::move(x)} {} using SumTypeTrait = std::true_type; SumTypeMixin(SumTypeMixin &&) = default; @@ -38,7 +40,9 @@ struct SumTypeMixin>> { template struct SumTypeCopyMixin {}; template // T must be std::variant<...> -struct SumTypeCopyMixin>> { +struct SumTypeCopyMixin)>> { + template SumTypeCopyMixin(A &&x) : u{std::move(x)} {} + template SumTypeCopyMixin(const A &x) : u{x} {} using CopyableSumTypeTrait = std::true_type; SumTypeCopyMixin(SumTypeCopyMixin &&) = default; SumTypeCopyMixin &operator=(SumTypeCopyMixin &&) = default; @@ -47,16 +51,16 @@ struct SumTypeCopyMixin>> { SumTypeCopyMixin() = delete; T u; }; -#define SUM_TYPE_COPY_MIXIN(Derived) \ - Derived(const Derived &derived) : SumTypeCopyMixin(derived) {} \ - Derived &operator=(const Derived &derived) { \ - SumTypeCopyMixin::operator=(derived); \ +#define SUM_TYPE_COPY_MIXIN(DT) \ + DT(const DT &derived) : SumTypeCopyMixin(derived.u) {} \ + DT &operator=(const DT &derived) { \ + SumTypeCopyMixin::operator=(derived.u); \ return *this; \ } template struct ProductTypeMixin {}; template // T must be std::tuple<...> -struct ProductTypeMixin>> { +struct ProductTypeMixin)>> { template ProductTypeMixin(A &&x) : t{std::move(x)} {} using ProductTypeTrait = std::true_type; ProductTypeMixin(ProductTypeMixin &&) = default; diff --git a/flang/lib/FIR/procedure.h b/flang/lib/FIR/procedure.h index 750573c..043c937 100644 --- a/flang/lib/FIR/procedure.h +++ b/flang/lib/FIR/procedure.h @@ -25,7 +25,7 @@ namespace Fortran::FIR { class Program; class Region; -struct GraphWriter; +class GraphWriter; class Procedure final : public llvm::ilist_node, public ChildMixin { diff --git a/flang/lib/FIR/program.h b/flang/lib/FIR/program.h index b9022f3..d40853c 100644 --- a/flang/lib/FIR/program.h +++ b/flang/lib/FIR/program.h @@ -26,7 +26,7 @@ namespace Fortran::FIR { class Procedure; -struct GraphWriter; +class GraphWriter; class Program final { public: diff --git a/flang/lib/FIR/statement.def b/flang/lib/FIR/statement.def index 7a24b64..713fc85 100644 --- a/flang/lib/FIR/statement.def +++ b/flang/lib/FIR/statement.def @@ -26,18 +26,18 @@ #define LAST_TERM_STMT(num) #endif -#ifndef FIRST_BINARY_STMT -#define FIRST_BINARY_STMT(num) +#ifndef FIRST_COMPUTE_STMT +#define FIRST_COMPUTE_STMT(num) #endif -#ifndef HANDLE_BINARY_STMT +#ifndef HANDLE_COMPUTE_STMT #ifndef HANDLE_STMT -#define HANDLE_BINARY_STMT(num, opcode, instclass) +#define HANDLE_COMPUTE_STMT(num, opcode, instclass) #else -#define HANDLE_BINARY_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class) +#define HANDLE_COMPUTE_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class) #endif #endif -#ifndef LAST_BINARY_STMT -#define LAST_BINARY_STMT(num) +#ifndef LAST_COMPUTE_STMT +#define LAST_COMPUTE_STMT(num) #endif #ifndef FIRST_MEMORY_STMT @@ -116,12 +116,12 @@ LAST_TERM_STMT(8) // Standard actions - These instructions capture computations as // evaluate::expressions -FIRST_BINARY_STMT(9) -HANDLE_BINARY_STMT(9, Assign, AssignmentStmt) -HANDLE_BINARY_STMT(10, PtrAssign, PointerAssignStmt) -HANDLE_BINARY_STMT(11, LblAssign, LabelAssignStmt) -HANDLE_BINARY_STMT(12, Expr, ExprStmt) -LAST_BINARY_STMT(12) +FIRST_COMPUTE_STMT(9) +HANDLE_COMPUTE_STMT(9, Assign, AssignmentStmt) +HANDLE_COMPUTE_STMT(10, PtrAssign, PointerAssignStmt) +HANDLE_COMPUTE_STMT(11, LblAssign, LabelAssignStmt) +HANDLE_COMPUTE_STMT(12, ApplyExpr, ApplyExprStmt) +LAST_COMPUTE_STMT(12) // Memory operators - These instructions capture ALLOCATE and DEALLOCATE // Fortran statements @@ -148,9 +148,9 @@ LAST_OTHER_STMT(24) #undef HANDLE_TERM_STMT #undef LAST_TERM_STMT -#undef FIRST_BINARY_STMT -#undef HANDLE_BINARY_STMT -#undef LAST_BINARY_STMT +#undef FIRST_COMPUTE_STMT +#undef HANDLE_COMPUTE_STMT +#undef LAST_COMPUTE_STMT #undef FIRST_MEMORY_STMT #undef HANDLE_MEMORY_STMT diff --git a/flang/lib/FIR/statements.cc b/flang/lib/FIR/statements.cc index afc3816..f2e29cc 100644 --- a/flang/lib/FIR/statements.cc +++ b/flang/lib/FIR/statements.cc @@ -191,7 +191,7 @@ std::string Statement::dump() const { }, [](const LabelAssignStmt &) { return "lblassn"s; }, [](const DisassociateStmt &) { return "NULLIFY"s; }, - [](const ExprStmt &expressionStatement) { + [](const ApplyExprStmt &applyExpression) { return std::visit( common::visitors{ [](const parser::AssociateStmt *) { @@ -215,7 +215,7 @@ std::string Statement::dump() const { return FIR::dump(genericExpressionWrapper); }, }, - expressionStatement.u); + applyExpression.u); }, [](const ScopeEnterStmt &) { return "scopeenter"s; }, [](const ScopeExitStmt &) { return "scopeexit"s; }, diff --git a/flang/lib/FIR/statements.h b/flang/lib/FIR/statements.h index 01f6f19..8005259 100644 --- a/flang/lib/FIR/statements.h +++ b/flang/lib/FIR/statements.h @@ -25,17 +25,17 @@ namespace Fortran::FIR { #define HANDLE_STMT(num, opcode, name) struct name; #include "statement.def" -struct Statement; +class Statement; CLASS_TRAIT(StatementTrait) CLASS_TRAIT(TerminatorTrait) CLASS_TRAIT(ActionTrait) -struct Evaluation - : public SumTypeCopyMixin> { +class Evaluation : public SumTypeCopyMixin> { +public: SUM_TYPE_COPY_MIXIN(Evaluation) - Evaluation(PathVariable *pv) : SumTypeCopyMixin{pv} { + Evaluation(PathVariable *pv) : SumTypeCopyMixin(pv) { if (const auto *designator{ std::get_if>(&pv->u)}) { if (const auto *obj{std::get_if(&(*designator)->u)}) { @@ -358,17 +358,18 @@ private: }; /// expressions that must be evaluated in various statements -struct ExprStmt +struct ApplyExprStmt : public ActionStmt_impl, public SumTypeCopyMixin> { - template static ExprStmt Create(const T *e) { - return ExprStmt{e}; + template static ApplyExprStmt Create(const T *e) { + return ApplyExprStmt{e}; } private: - template explicit ExprStmt(const T *e) : SumTypeCopyMixin{e} {} + template + explicit ApplyExprStmt(const T *e) : SumTypeCopyMixin{e} {} // Evaluation evaluation_; }; diff --git a/flang/lib/FIR/stmt.h b/flang/lib/FIR/stmt.h index 7ba99fa..5a33145 100644 --- a/flang/lib/FIR/stmt.h +++ b/flang/lib/FIR/stmt.h @@ -22,13 +22,14 @@ namespace Fortran::FIR { /// Sum type over all statement classes -struct Statement : public SumTypeMixin>, - public ChildMixin, - public llvm::ilist_node { + >>, + public ChildMixin, + public llvm::ilist_node { +public: template Statement(BasicBlock *p, A &&t) : SumTypeMixin{t}, ChildMixin{p} { parent->insertBefore(this); -- 2.7.4