Skip to content

Commit 137c23d

Browse files
committed
add back removed files
1 parent db5ebec commit 137c23d

File tree

14 files changed

+3577
-0
lines changed

14 files changed

+3577
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//===- IteratedDominanceFrontier.h - Calculate IDF --------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// Compute iterated dominance frontiers using a linear time algorithm.
10+
///
11+
/// The algorithm used here is based on:
12+
///
13+
/// Sreedhar and Gao. A linear time algorithm for placing phi-nodes.
14+
/// In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of
15+
/// Programming Languages
16+
/// POPL '95. ACM, New York, NY, 62-73.
17+
///
18+
/// It has been modified to not explicitly use the DJ graph data structure and
19+
/// to directly compute pruned SSA using per-variable liveness information.
20+
//
21+
//===----------------------------------------------------------------------===//
22+
23+
#ifndef FIR_ANALYSIS_IDF_H
24+
#define FIR_ANALYSIS_IDF_H
25+
26+
#include "mlir/Analysis/Dominance.h"
27+
#include "mlir/IR/Block.h"
28+
#include "mlir/Support/LLVM.h"
29+
30+
namespace mlir {
31+
class Block;
32+
class DominanceInfo;
33+
} // namespace mlir
34+
35+
namespace fir {
36+
37+
/// Determine the iterated dominance frontier, given a set of defining
38+
/// blocks, and optionally, a set of live-in blocks.
39+
///
40+
/// In turn, the results can be used to place phi nodes.
41+
///
42+
/// This algorithm is a linear time computation of Iterated Dominance Frontiers,
43+
/// pruned using the live-in set.
44+
/// By default, liveness is not used to prune the IDF computation.
45+
/// The template parameters should be either BasicBlock* or Inverse<BasicBlock
46+
/// *>, depending on if you want the forward or reverse IDF.
47+
template <class NodeTy, bool IsPostDom>
48+
class IDFCalculator {
49+
public:
50+
IDFCalculator(mlir::DominanceInfo &DT) : DT(DT), useLiveIn(false) {}
51+
52+
/// Give the IDF calculator the set of blocks in which the value is
53+
/// defined. This is equivalent to the set of starting blocks it should be
54+
/// calculating the IDF for (though later gets pruned based on liveness).
55+
///
56+
/// Note: This set *must* live for the entire lifetime of the IDF calculator.
57+
void setDefiningBlocks(const llvm::SmallPtrSetImpl<NodeTy *> &Blocks) {
58+
DefBlocks = &Blocks;
59+
}
60+
61+
/// Give the IDF calculator the set of blocks in which the value is
62+
/// live on entry to the block. This is used to prune the IDF calculation to
63+
/// not include blocks where any phi insertion would be dead.
64+
///
65+
/// Note: This set *must* live for the entire lifetime of the IDF calculator.
66+
67+
void setLiveInBlocks(const llvm::SmallPtrSetImpl<NodeTy *> &Blocks) {
68+
LiveInBlocks = &Blocks;
69+
useLiveIn = true;
70+
}
71+
72+
/// Reset the live-in block set to be empty, and tell the IDF
73+
/// calculator to not use liveness anymore.
74+
void resetLiveInBlocks() {
75+
LiveInBlocks = nullptr;
76+
useLiveIn = false;
77+
}
78+
79+
/// Calculate iterated dominance frontiers
80+
///
81+
/// This uses the linear-time phi algorithm based on DJ-graphs mentioned in
82+
/// the file-level comment. It performs DF->IDF pruning using the live-in
83+
/// set, to avoid computing the IDF for blocks where an inserted PHI node
84+
/// would be dead.
85+
void calculate(llvm::SmallVectorImpl<NodeTy *> &IDFBlocks);
86+
87+
private:
88+
mlir::DominanceInfo &DT;
89+
bool useLiveIn;
90+
const llvm::SmallPtrSetImpl<NodeTy *> *LiveInBlocks;
91+
const llvm::SmallPtrSetImpl<NodeTy *> *DefBlocks;
92+
};
93+
94+
typedef IDFCalculator<mlir::Block, false> ForwardIDFCalculator;
95+
96+
} // namespace fir
97+
#endif

include/fir/Attribute.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIR_ATTRIBUTE_H
16+
#define FIR_ATTRIBUTE_H
17+
18+
#include "mlir/IR/Attributes.h"
19+
20+
namespace fir {
21+
22+
class FIROpsDialect;
23+
24+
namespace detail {
25+
struct TypeAttributeStorage;
26+
}
27+
28+
enum AttributeKind {
29+
FIR_ATTR = mlir::Attribute::FIRST_FIR_ATTR,
30+
FIR_EXACTTYPE, // instance_of, precise type relation
31+
FIR_SUBCLASS, // subsumed_by, is-a (subclass) relation
32+
FIR_POINT,
33+
FIR_CLOSEDCLOSED_INTERVAL,
34+
FIR_OPENCLOSED_INTERVAL,
35+
FIR_CLOSEDOPEN_INTERVAL,
36+
};
37+
38+
class ExactTypeAttr
39+
: public mlir::Attribute::AttrBase<ExactTypeAttr, mlir::Attribute,
40+
detail::TypeAttributeStorage> {
41+
public:
42+
using Base::Base;
43+
using ValueType = mlir::Type;
44+
45+
static llvm::StringRef getAttrName() { return "instance"; }
46+
static ExactTypeAttr get(mlir::Type value);
47+
48+
mlir::Type getType() const;
49+
50+
constexpr static bool kindof(unsigned kind) { return kind == getId(); }
51+
constexpr static unsigned getId() { return AttributeKind::FIR_EXACTTYPE; }
52+
};
53+
54+
class SubclassAttr
55+
: public mlir::Attribute::AttrBase<SubclassAttr, mlir::Attribute,
56+
detail::TypeAttributeStorage> {
57+
public:
58+
using Base::Base;
59+
using ValueType = mlir::Type;
60+
61+
static llvm::StringRef getAttrName() { return "subsumed"; }
62+
static SubclassAttr get(mlir::Type value);
63+
64+
mlir::Type getType() const;
65+
66+
constexpr static bool kindof(unsigned kind) { return kind == getId(); }
67+
constexpr static unsigned getId() { return AttributeKind::FIR_SUBCLASS; }
68+
};
69+
70+
class ClosedIntervalAttr
71+
: public mlir::Attribute::AttrBase<ClosedIntervalAttr> {
72+
public:
73+
using Base::Base;
74+
75+
static llvm::StringRef getAttrName() { return "interval"; }
76+
static ClosedIntervalAttr get(mlir::MLIRContext *ctxt);
77+
constexpr static bool kindof(unsigned kind) { return kind == getId(); }
78+
constexpr static unsigned getId() {
79+
return AttributeKind::FIR_CLOSEDCLOSED_INTERVAL;
80+
}
81+
};
82+
83+
class UpperBoundAttr : public mlir::Attribute::AttrBase<UpperBoundAttr> {
84+
public:
85+
using Base::Base;
86+
87+
static llvm::StringRef getAttrName() { return "upper"; }
88+
static UpperBoundAttr get(mlir::MLIRContext *ctxt);
89+
constexpr static bool kindof(unsigned kind) { return kind == getId(); }
90+
constexpr static unsigned getId() {
91+
return AttributeKind::FIR_OPENCLOSED_INTERVAL;
92+
}
93+
};
94+
95+
class LowerBoundAttr : public mlir::Attribute::AttrBase<LowerBoundAttr> {
96+
public:
97+
using Base::Base;
98+
99+
static llvm::StringRef getAttrName() { return "lower"; }
100+
static LowerBoundAttr get(mlir::MLIRContext *ctxt);
101+
constexpr static bool kindof(unsigned kind) { return kind == getId(); }
102+
constexpr static unsigned getId() {
103+
return AttributeKind::FIR_CLOSEDOPEN_INTERVAL;
104+
}
105+
};
106+
107+
class PointIntervalAttr : public mlir::Attribute::AttrBase<PointIntervalAttr> {
108+
public:
109+
using Base::Base;
110+
111+
static llvm::StringRef getAttrName() { return "point"; }
112+
static PointIntervalAttr get(mlir::MLIRContext *ctxt);
113+
constexpr static bool kindof(unsigned kind) { return kind == getId(); }
114+
constexpr static unsigned getId() { return AttributeKind::FIR_POINT; }
115+
};
116+
117+
mlir::Attribute parseFirAttribute(FIROpsDialect *dialect,
118+
llvm::StringRef rawText, mlir::Type type,
119+
mlir::Location loc);
120+
121+
} // namespace fir
122+
123+
#endif // FIR_ATTRIBUTE_H

include/fir/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(LLVM_TARGET_DEFINITIONS FIROps.td)
2+
mlir_tablegen(FIROps.h.inc -gen-op-decls)
3+
mlir_tablegen(FIROps.cpp.inc -gen-op-defs)
4+
add_public_tablegen_target(FIROpsIncGen)

include/fir/Dialect.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIR_DIALECT_H
16+
#define FIR_DIALECT_H
17+
18+
#include "mlir/IR/Dialect.h"
19+
20+
namespace llvm {
21+
class raw_ostream;
22+
class StringRef;
23+
} // namespace llvm
24+
25+
namespace mlir {
26+
class Attribute;
27+
class Location;
28+
class MLIRContext;
29+
class Type;
30+
} // namespace mlir
31+
32+
namespace fir {
33+
34+
/// FIR dialect
35+
class FIROpsDialect final : public mlir::Dialect {
36+
public:
37+
explicit FIROpsDialect(mlir::MLIRContext *ctx);
38+
virtual ~FIROpsDialect();
39+
40+
static llvm::StringRef getDialectNamespace() { return "fir"; }
41+
42+
mlir::Type parseType(llvm::StringRef rawData,
43+
mlir::Location loc) const override;
44+
void printType(mlir::Type ty, llvm::raw_ostream &os) const override;
45+
46+
mlir::Attribute parseAttribute(llvm::StringRef rawText, mlir::Type type,
47+
mlir::Location loc) const override;
48+
void printAttribute(mlir::Attribute attr,
49+
llvm::raw_ostream &os) const override;
50+
};
51+
52+
} // namespace fir
53+
54+
#endif // FIR_DIALECT_H

include/fir/FIROps.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FIR_FIROPS_H
16+
#define FIR_FIROPS_H
17+
18+
#include "mlir/IR/Builders.h"
19+
#include "mlir/IR/OpImplementation.h"
20+
#include "llvm/ADT/ArrayRef.h"
21+
#include "llvm/ADT/StringRef.h"
22+
23+
using namespace mlir;
24+
using llvm::ArrayRef;
25+
using llvm::StringRef;
26+
27+
namespace fir {
28+
29+
class FirEndOp;
30+
31+
/// `fir.global` is a typed symbol with an optional list of initializers.
32+
class GlobalOp
33+
: public mlir::Op<
34+
GlobalOp, mlir::OpTrait::ZeroOperands, mlir::OpTrait::ZeroResult,
35+
mlir::OpTrait::IsIsolatedFromAbove,
36+
mlir::OpTrait::SingleBlockImplicitTerminator<FirEndOp>::Impl> {
37+
public:
38+
using Op::Op;
39+
using Op::print;
40+
41+
static llvm::StringRef getOperationName() { return "fir.global"; }
42+
static llvm::StringRef getTypeAttrName() { return "type"; }
43+
44+
static void build(mlir::Builder *builder, mlir::OperationState *result,
45+
llvm::StringRef name, mlir::Type type,
46+
llvm::ArrayRef<mlir::NamedAttribute> attrs);
47+
48+
/// Operation hooks.
49+
static mlir::ParseResult parse(mlir::OpAsmParser &parser,
50+
mlir::OperationState &result);
51+
void print(mlir::OpAsmPrinter &p);
52+
mlir::LogicalResult verify();
53+
54+
mlir::Type getType() {
55+
return getAttrOfType<TypeAttr>(getTypeAttrName()).getValue();
56+
}
57+
58+
void appendInitialValue(mlir::Operation *op);
59+
60+
private:
61+
mlir::Region &front();
62+
};
63+
64+
/// `fir.dispatch_table` is an untyped symbol that is a list of associations
65+
/// between method identifiers and a FuncOp symbol.
66+
class DispatchTableOp
67+
: public mlir::Op<
68+
DispatchTableOp, mlir::OpTrait::ZeroOperands,
69+
mlir::OpTrait::ZeroResult, mlir::OpTrait::IsIsolatedFromAbove,
70+
mlir::OpTrait::SingleBlockImplicitTerminator<FirEndOp>::Impl> {
71+
public:
72+
using Op::Op;
73+
74+
static llvm::StringRef getOperationName() { return "fir.dispatch_table"; }
75+
76+
static void build(mlir::Builder *builder, mlir::OperationState *result,
77+
llvm::StringRef name, mlir::Type type,
78+
llvm::ArrayRef<mlir::NamedAttribute> attrs);
79+
80+
/// Operation hooks.
81+
static mlir::ParseResult parse(mlir::OpAsmParser &parser,
82+
mlir::OperationState &result);
83+
void print(mlir::OpAsmPrinter &p);
84+
mlir::LogicalResult verify();
85+
86+
void appendTableEntry(mlir::Operation *op);
87+
88+
private:
89+
mlir::Region &front();
90+
};
91+
92+
mlir::ParseResult isValidCaseAttr(mlir::Attribute attr);
93+
unsigned getCaseArgumentOffset(llvm::ArrayRef<mlir::Attribute> cases,
94+
unsigned dest);
95+
mlir::ParseResult parseSelector(mlir::OpAsmParser *parser,
96+
mlir::OperationState *result,
97+
mlir::OpAsmParser::OperandType &selector,
98+
mlir::Type &type);
99+
100+
#define GET_OP_CLASSES
101+
#include "fir/FIROps.h.inc"
102+
103+
LoopOp getForInductionVarOwner(mlir::Value *val);
104+
105+
} // namespace fir
106+
107+
#endif // FIR_FIROPS_H

0 commit comments

Comments
 (0)