[flang] code review comments
authorEric Schweitz <eschweitz@nvidia.com>
Fri, 22 Feb 2019 23:17:57 +0000 (15:17 -0800)
committerEric Schweitz <eschweitz@nvidia.com>
Fri, 22 Feb 2019 23:17:57 +0000 (15:17 -0800)
Original-commit: flang-compiler/f18@ef9bfa4bd7bed6a5cb3a78ae7abc9fb428f8d7e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/293

flang/lib/FIR/basicblock.cc [moved from flang/lib/IntermediateRepresentation/basicblock.cc with 93% similarity]
flang/lib/FIR/basicblock.h [moved from flang/lib/IntermediateRepresentation/basicblock.h with 87% similarity]
flang/lib/FIR/procedure.cc [moved from flang/lib/IntermediateRepresentation/procedure.cc with 79% similarity]
flang/lib/FIR/procedure.h [moved from flang/lib/IntermediateRepresentation/procedure.h with 94% similarity]
flang/lib/FIR/program.cc [moved from flang/lib/IntermediateRepresentation/program.cc with 93% similarity]
flang/lib/FIR/program.h [moved from flang/lib/IntermediateRepresentation/program.h with 90% similarity]
flang/lib/FIR/region.cc [moved from flang/lib/IntermediateRepresentation/region.cc with 96% similarity]
flang/lib/FIR/region.h [moved from flang/lib/IntermediateRepresentation/region.h with 95% similarity]

similarity index 93%
rename from flang/lib/IntermediateRepresentation/basicblock.cc
rename to flang/lib/FIR/basicblock.cc
index 2c33067..3ea2126 100644 (file)
@@ -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 {
similarity index 87%
rename from flang/lib/IntermediateRepresentation/basicblock.h
rename to flang/lib/FIR/basicblock.h
index 37d8a05..4175bf9 100644 (file)
 // 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 <iostream>
 
-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<BasicBlock *> &Predecessors() { return predecessors_; }
+  std::vector<BasicBlock *> &preds() { return preds_; }
   StatementListType &Statements() { return statementList_; }
   BasicBlock *SplitEdge(BasicBlock *toBlock) { return nullptr; }
 
 private:
   StatementListType statementList_;
-  std::vector<BasicBlock *> predecessors_;
+  std::vector<BasicBlock *> preds_;
   explicit BasicBlock(Region *parentRegion, BasicBlock *insertBefore);
 };
 
 inline std::list<BasicBlock *> pred_list(BasicBlock &block) {
   return std::list<BasicBlock *>{
-      block.Predecessors().begin(), block.Predecessors().end()};
+      block.preds().begin(), block.preds().end()};
 }
 
 }
similarity index 79%
rename from flang/lib/IntermediateRepresentation/procedure.cc
rename to flang/lib/FIR/procedure.cc
index 64b4c73..44bd44a 100644 (file)
@@ -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);
similarity index 94%
rename from flang/lib/IntermediateRepresentation/procedure.h
rename to flang/lib/FIR/procedure.h
index c343565..37a1da1 100644 (file)
@@ -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;
similarity index 93%
rename from flang/lib/IntermediateRepresentation/program.cc
rename to flang/lib/FIR/program.cc
index 2e6c547..87fc7c8 100644 (file)
 
 #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) {
similarity index 90%
rename from flang/lib/IntermediateRepresentation/program.h
rename to flang/lib/FIR/program.h
index d097596..cf2be11 100644 (file)
@@ -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 <string>
 
-namespace Fortran::IntermediateRepresentation {
+namespace Fortran::FIR {
 
 class Procedure;
 struct GraphWriter;
@@ -35,7 +35,6 @@ public:
   using ProcedureMapType = llvm::StringMap<Procedure *>;
 
   explicit Program(llvm::StringRef id);
-  ~Program();
   void insertBefore(Procedure *subprog, Procedure *before = nullptr);
   ProcedureListType &getSublist(Procedure *) { return procedureList_; }
   bool containsProcedure(llvm::StringRef name) {
similarity index 96%
rename from flang/lib/IntermediateRepresentation/region.cc
rename to flang/lib/FIR/region.cc
index eeb6a03..495862b 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "program.h"
 
-namespace Fortran::IntermediateRepresentation {
+namespace Fortran::FIR {
 
 Region::Region(
     Procedure *procedure, Scope *scope, Region *inRegion, Region *insertBefore)
similarity index 95%
rename from flang/lib/IntermediateRepresentation/region.h
rename to flang/lib/FIR/region.h
index 1cd1562..6b506a4 100644 (file)
 // 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;