[flang] latest changes

Original-commit: flang-compiler/f18@c4278fe1aa
Reviewed-on: https://github.com/flang-compiler/f18/pull/696
Tree-same-pre-rewrite: false
This commit is contained in:
Eric Schweitz 2019-09-17 14:23:20 -07:00
parent 6bff59ec6b
commit cca3c31176
5 changed files with 1262 additions and 147 deletions

View file

@ -0,0 +1,93 @@
//===- IteratedDominanceFrontier.h - Calculate IDF --------------*- C++ -*-===//
//===----------------------------------------------------------------------===//
/// \file
/// Compute iterated dominance frontiers using a linear time algorithm.
///
/// The algorithm used here is based on:
///
/// Sreedhar and Gao. A linear time algorithm for placing phi-nodes.
/// In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of
/// Programming Languages
/// POPL '95. ACM, New York, NY, 62-73.
///
/// It has been modified to not explicitly use the DJ graph data structure and
/// to directly compute pruned SSA using per-variable liveness information.
//
//===----------------------------------------------------------------------===//
#ifndef FIR_ANALYSIS_IDF_H
#define FIR_ANALYSIS_IDF_H
#include "mlir/Analysis/Dominance.h"
#include "mlir/IR/Block.h"
#include "mlir/Support/LLVM.h"
namespace mlir {
class Block;
class DominanceInfo;
}
namespace fir {
/// Determine the iterated dominance frontier, given a set of defining
/// blocks, and optionally, a set of live-in blocks.
///
/// In turn, the results can be used to place phi nodes.
///
/// This algorithm is a linear time computation of Iterated Dominance Frontiers,
/// pruned using the live-in set.
/// By default, liveness is not used to prune the IDF computation.
/// The template parameters should be either BasicBlock* or Inverse<BasicBlock
/// *>, depending on if you want the forward or reverse IDF.
template <class NodeTy, bool IsPostDom>
class IDFCalculator {
public:
IDFCalculator(mlir::DominanceInfo &DT)
: DT(DT), useLiveIn(false) {}
/// Give the IDF calculator the set of blocks in which the value is
/// defined. This is equivalent to the set of starting blocks it should be
/// calculating the IDF for (though later gets pruned based on liveness).
///
/// Note: This set *must* live for the entire lifetime of the IDF calculator.
void setDefiningBlocks(const llvm::SmallPtrSetImpl<NodeTy *> &Blocks) {
DefBlocks = &Blocks;
}
/// Give the IDF calculator the set of blocks in which the value is
/// live on entry to the block. This is used to prune the IDF calculation to
/// not include blocks where any phi insertion would be dead.
///
/// Note: This set *must* live for the entire lifetime of the IDF calculator.
void setLiveInBlocks(const llvm::SmallPtrSetImpl<NodeTy *> &Blocks) {
LiveInBlocks = &Blocks;
useLiveIn = true;
}
/// Reset the live-in block set to be empty, and tell the IDF
/// calculator to not use liveness anymore.
void resetLiveInBlocks() {
LiveInBlocks = nullptr;
useLiveIn = false;
}
/// Calculate iterated dominance frontiers
///
/// This uses the linear-time phi algorithm based on DJ-graphs mentioned in
/// the file-level comment. It performs DF->IDF pruning using the live-in
/// set, to avoid computing the IDF for blocks where an inserted PHI node
/// would be dead.
void calculate(llvm::SmallVectorImpl<NodeTy *> &IDFBlocks);
private:
mlir::DominanceInfo &DT;
bool useLiveIn;
const llvm::SmallPtrSetImpl<NodeTy *> *LiveInBlocks;
const llvm::SmallPtrSetImpl<NodeTy *> *DefBlocks;
};
typedef IDFCalculator<mlir::Block, false> ForwardIDFCalculator;
} // namespace fir
#endif

View file

@ -0,0 +1,4 @@
set(LLVM_TARGET_DEFINITIONS FIROps.td)
mlir_tablegen(FIROps.h.inc -gen-op-decls)
mlir_tablegen(FIROps.cpp.inc -gen-op-defs)
add_public_tablegen_target(FIROpsIncGen)

View file

@ -17,10 +17,8 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/FunctionSupport.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/OpImplementation.h"
using namespace mlir;
using llvm::ArrayRef;
@ -92,21 +90,13 @@ private:
mlir::ParseResult isValidCaseAttr(mlir::Attribute attr);
unsigned getCaseArgumentOffset(
llvm::ArrayRef<mlir::Attribute> cases, unsigned dest);
mlir::ParseResult parseSelector(mlir::OpAsmParser *parser,
mlir::OperationState *result, mlir::OpAsmParser::OperandType &selector,
mlir::Type &type);
#define GET_OP_CLASSES
#include "fir/FIROps.h.inc"
mlir::ParseResult parseCallOp(
mlir::OpAsmParser *parser, mlir::OperationState *result);
void printCallOp(mlir::OpAsmPrinter *p, fir::CallOp call);
mlir::ParseResult parseDispatchOp(
mlir::OpAsmParser *parser, mlir::OperationState *result);
mlir::ParseResult parseDTEntryOp(
mlir::OpAsmParser *parser, mlir::OperationState *result);
LoopOp getForInductionVarOwner(mlir::Value *val);
} // namespace fir

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,38 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef FIR_TRANSFORMS_MEMTOREG_H
#define FIR_TRANSFORMS_MEMTOREG_H
/// A pass to convert the FIR dialect from "Mem-SSA" form to "Reg-SSA"
/// form. This pass is a port of LLVM's mem2reg pass, but modified for the FIR
/// dialect as well as the restructuring of MLIR's representation to present PHI
/// nodes as block arguments.
#include <memory>
namespace mlir {
template<typename> class OpPassBase;
class FuncOp;
using FunctionPassBase = OpPassBase<FuncOp>;
}
namespace fir {
/// Creates a pass to convert FIR into a reg SSA form
std::unique_ptr<mlir::FunctionPassBase> createMemToRegPass();
} // fir
#endif // FIR_TRANSFORMS_MEMTOREG_H