From f7f819c97b147301ac3744c6b8305fc7a1d68c7e Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Fri, 22 Feb 2019 15:17:57 -0800 Subject: [PATCH] [flang] code review comments Original-commit: flang-compiler/f18@ef9bfa4bd7bed6a5cb3a78ae7abc9fb428f8d7e2 Reviewed-on: https://github.com/flang-compiler/f18/pull/293 --- .../basicblock.cc | 6 +++--- .../basicblock.h | 12 ++++++------ .../procedure.cc | 22 +++++++++++----------- .../procedure.h | 6 +++--- .../{IntermediateRepresentation => FIR}/program.cc | 3 +-- .../{IntermediateRepresentation => FIR}/program.h | 7 +++---- .../{IntermediateRepresentation => FIR}/region.cc | 2 +- .../{IntermediateRepresentation => FIR}/region.h | 6 +++--- 8 files changed, 31 insertions(+), 33 deletions(-) rename flang/lib/{IntermediateRepresentation => FIR}/basicblock.cc (93%) rename flang/lib/{IntermediateRepresentation => FIR}/basicblock.h (87%) rename flang/lib/{IntermediateRepresentation => FIR}/procedure.cc (79%) rename flang/lib/{IntermediateRepresentation => FIR}/procedure.h (94%) rename flang/lib/{IntermediateRepresentation => FIR}/program.cc (93%) rename flang/lib/{IntermediateRepresentation => FIR}/program.h (90%) rename flang/lib/{IntermediateRepresentation => FIR}/region.cc (96%) rename flang/lib/{IntermediateRepresentation => FIR}/region.h (95%) diff --git a/flang/lib/IntermediateRepresentation/basicblock.cc b/flang/lib/FIR/basicblock.cc similarity index 93% rename from flang/lib/IntermediateRepresentation/basicblock.cc rename to flang/lib/FIR/basicblock.cc index 2c33067..3ea2126 100644 --- a/flang/lib/IntermediateRepresentation/basicblock.cc +++ b/flang/lib/FIR/basicblock.cc @@ -15,7 +15,7 @@ #include "program.h" #include "stmt.h" -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { BasicBlock::BasicBlock(Region *parentRegion, BasicBlock *insertBefore) : ChildMixin{parentRegion} { @@ -33,10 +33,10 @@ void BasicBlock::insertBefore(Statement *stmt, Statement *before) { } void BasicBlock::addPred(BasicBlock *bb) { - for (auto *p : predecessors_) { + for (auto *p : preds_) { if (p == bb) return; } - predecessors_.push_back(bb); + preds_.push_back(bb); } const Statement *BasicBlock::getTerminator() const { diff --git a/flang/lib/IntermediateRepresentation/basicblock.h b/flang/lib/FIR/basicblock.h similarity index 87% rename from flang/lib/IntermediateRepresentation/basicblock.h rename to flang/lib/FIR/basicblock.h index 37d8a05..4175bf9 100644 --- a/flang/lib/IntermediateRepresentation/basicblock.h +++ b/flang/lib/FIR/basicblock.h @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef FORTRAN_INTERMEDIATEREPRESENTATION_BASICBLOCK_H_ -#define FORTRAN_INTERMEDIATEREPRESENTATION_BASICBLOCK_H_ +#ifndef FORTRAN_FIR_BASICBLOCK_H_ +#define FORTRAN_FIR_BASICBLOCK_H_ #include "mixin.h" #include "region.h" #include -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { class Region; class Statement; @@ -54,19 +54,19 @@ public: void SetRegion(Region *region) { parent = region; } Region *GetRegion() const { return parent; } void addPred(BasicBlock *bb); - std::vector &Predecessors() { return predecessors_; } + std::vector &preds() { return preds_; } StatementListType &Statements() { return statementList_; } BasicBlock *SplitEdge(BasicBlock *toBlock) { return nullptr; } private: StatementListType statementList_; - std::vector predecessors_; + std::vector preds_; explicit BasicBlock(Region *parentRegion, BasicBlock *insertBefore); }; inline std::list pred_list(BasicBlock &block) { return std::list{ - block.Predecessors().begin(), block.Predecessors().end()}; + block.preds().begin(), block.preds().end()}; } } diff --git a/flang/lib/IntermediateRepresentation/procedure.cc b/flang/lib/FIR/procedure.cc similarity index 79% rename from flang/lib/IntermediateRepresentation/procedure.cc rename to flang/lib/FIR/procedure.cc index 64b4c73..44bd44a 100644 --- a/flang/lib/IntermediateRepresentation/procedure.cc +++ b/flang/lib/FIR/procedure.cc @@ -14,7 +14,7 @@ #include "procedure.h" -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { Procedure::Procedure(Program *program, FunctionType *ty, LinkageTypes lt, unsigned addrSpace, const llvm::Twine &n, Procedure *before) @@ -63,16 +63,16 @@ void Procedure::FlattenRegions() { for (auto &block : GetBlocks()) { auto *region{block.GetRegion()}; if (!region->IsOutermost()) { - for (auto *successor : succ_list(block)) { - auto *successorRegion{successor->GetRegion()}; - if (successorRegion != region && - DistinctScopes(successorRegion, region)) { - if (IsAncestor(region, successorRegion)) { - AddEnterScopes(RegionDepth(region, successorRegion), - successor->SplitEdge(&block)); - } else if (IsAncestor(successorRegion, region)) { - AddExitScopes(RegionDepth(successorRegion, region), - block.SplitEdge(successor)); + for (auto *succ : succ_list(block)) { + auto *succRegion{succ->GetRegion()}; + if (succRegion != region && + DistinctScopes(succRegion, region)) { + if (IsAncestor(region, succRegion)) { + AddEnterScopes(RegionDepth(region, succRegion), + succ->SplitEdge(&block)); + } else if (IsAncestor(succRegion, region)) { + AddExitScopes(RegionDepth(succRegion, region), + block.SplitEdge(succ)); } else { // TODO: edge to a cousin region CHECK(false); diff --git a/flang/lib/IntermediateRepresentation/procedure.h b/flang/lib/FIR/procedure.h similarity index 94% rename from flang/lib/IntermediateRepresentation/procedure.h rename to flang/lib/FIR/procedure.h index c343565..37a1da1 100644 --- a/flang/lib/IntermediateRepresentation/procedure.h +++ b/flang/lib/FIR/procedure.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef FORTRAN_INTERMEDIATEREPRESENTATION_PROCEDURE_H_ -#define FORTRAN_INTERMEDIATEREPRESENTATION_PROCEDURE_H_ +#ifndef FORTRAN_FIR_PROCEDURE_H_ +#define FORTRAN_FIR_PROCEDURE_H_ #include "mixin.h" #include "program.h" @@ -21,7 +21,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { class Program; class Region; diff --git a/flang/lib/IntermediateRepresentation/program.cc b/flang/lib/FIR/program.cc similarity index 93% rename from flang/lib/IntermediateRepresentation/program.cc rename to flang/lib/FIR/program.cc index 2e6c547..87fc7c8 100644 --- a/flang/lib/IntermediateRepresentation/program.cc +++ b/flang/lib/FIR/program.cc @@ -14,10 +14,9 @@ #include "program.h" -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { Program::Program(llvm::StringRef id) : name_{id} {} -Program::~Program() { procedureMap_.clear(); } void Program::insertBefore(Procedure *subprog, Procedure *before) { if (before) { diff --git a/flang/lib/IntermediateRepresentation/program.h b/flang/lib/FIR/program.h similarity index 90% rename from flang/lib/IntermediateRepresentation/program.h rename to flang/lib/FIR/program.h index d097596..cf2be11 100644 --- a/flang/lib/IntermediateRepresentation/program.h +++ b/flang/lib/FIR/program.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef FORTRAN_INTERMEDIATEREPRESENTATION_PROGRAM_H_ -#define FORTRAN_INTERMEDIATEREPRESENTATION_PROGRAM_H_ +#ifndef FORTRAN_FIR_PROGRAM_H_ +#define FORTRAN_FIR_PROGRAM_H_ #include "common.h" #include "procedure.h" @@ -23,7 +23,7 @@ #include "llvm/ADT/Twine.h" #include -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { class Procedure; struct GraphWriter; @@ -35,7 +35,6 @@ public: using ProcedureMapType = llvm::StringMap; explicit Program(llvm::StringRef id); - ~Program(); void insertBefore(Procedure *subprog, Procedure *before = nullptr); ProcedureListType &getSublist(Procedure *) { return procedureList_; } bool containsProcedure(llvm::StringRef name) { diff --git a/flang/lib/IntermediateRepresentation/region.cc b/flang/lib/FIR/region.cc similarity index 96% rename from flang/lib/IntermediateRepresentation/region.cc rename to flang/lib/FIR/region.cc index eeb6a03..495862b 100644 --- a/flang/lib/IntermediateRepresentation/region.cc +++ b/flang/lib/FIR/region.cc @@ -14,7 +14,7 @@ #include "program.h" -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { Region::Region( Procedure *procedure, Scope *scope, Region *inRegion, Region *insertBefore) diff --git a/flang/lib/IntermediateRepresentation/region.h b/flang/lib/FIR/region.h similarity index 95% rename from flang/lib/IntermediateRepresentation/region.h rename to flang/lib/FIR/region.h index 1cd1562..6b506a4 100644 --- a/flang/lib/IntermediateRepresentation/region.h +++ b/flang/lib/FIR/region.h @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef FORTRAN_INTERMEDIATEREPRESENTATION_REGION_H_ -#define FORTRAN_INTERMEDIATEREPRESENTATION_REGION_H_ +#ifndef FORTRAN_FIR_REGION_H_ +#define FORTRAN_FIR_REGION_H_ #include "procedure.h" #include "stmt.h" #include "../semantics/semantics.h" -namespace Fortran::IntermediateRepresentation { +namespace Fortran::FIR { class Procedure; class BasicBlock; -- 2.7.4