2018-06-24 07:03:42 +08:00
|
|
|
//===- AsmPrinter.cpp - MLIR Assembly Printer Implementation --------------===//
|
|
|
|
//
|
|
|
|
// Copyright 2019 The MLIR Authors.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
// =============================================================================
|
|
|
|
//
|
|
|
|
// This file implements the MLIR AsmPrinter class, which is used to implement
|
|
|
|
// the various print() methods on the core IR objects.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-06-30 09:09:29 +08:00
|
|
|
#include "mlir/IR/AffineExpr.h"
|
|
|
|
#include "mlir/IR/AffineMap.h"
|
2018-07-05 11:45:39 +08:00
|
|
|
#include "mlir/IR/Attributes.h"
|
2019-03-02 08:58:00 +08:00
|
|
|
#include "mlir/IR/Dialect.h"
|
2018-12-28 03:07:34 +08:00
|
|
|
#include "mlir/IR/Function.h"
|
2018-08-08 05:24:38 +08:00
|
|
|
#include "mlir/IR/IntegerSet.h"
|
2019-01-11 14:08:39 +08:00
|
|
|
#include "mlir/IR/MLIRContext.h"
|
2019-03-02 08:58:00 +08:00
|
|
|
#include "mlir/IR/Matchers.h"
|
2018-06-24 07:03:42 +08:00
|
|
|
#include "mlir/IR/Module.h"
|
2018-07-25 07:07:22 +08:00
|
|
|
#include "mlir/IR/OpImplementation.h"
|
2019-03-27 05:45:38 +08:00
|
|
|
#include "mlir/IR/Operation.h"
|
2019-01-04 06:29:52 +08:00
|
|
|
#include "mlir/IR/StandardTypes.h"
|
2018-06-24 07:03:42 +08:00
|
|
|
#include "mlir/Support/STLExtras.h"
|
2018-08-16 00:09:54 +08:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
2018-06-24 07:03:42 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2019-05-07 01:36:32 +08:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2018-11-13 06:58:53 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2019-01-11 14:08:39 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2018-08-02 01:43:18 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/StringSet.h"
|
2019-01-24 05:11:23 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2019-01-11 14:08:39 +08:00
|
|
|
#include "llvm/Support/Regex.h"
|
2018-06-24 07:03:42 +08:00
|
|
|
using namespace mlir;
|
|
|
|
|
2018-07-19 01:16:05 +08:00
|
|
|
void Identifier::print(raw_ostream &os) const { os << str(); }
|
2018-06-24 07:03:42 +08:00
|
|
|
|
2018-07-19 01:16:05 +08:00
|
|
|
void Identifier::dump() const { print(llvm::errs()); }
|
2018-07-05 11:45:39 +08:00
|
|
|
|
2018-10-10 13:08:52 +08:00
|
|
|
void OperationName::print(raw_ostream &os) const { os << getStringRef(); }
|
|
|
|
|
|
|
|
void OperationName::dump() const { print(llvm::errs()); }
|
|
|
|
|
2018-07-25 07:07:22 +08:00
|
|
|
OpAsmPrinter::~OpAsmPrinter() {}
|
|
|
|
|
2018-07-18 07:56:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-07-21 00:35:47 +08:00
|
|
|
// ModuleState
|
2018-07-18 07:56:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-01-24 05:11:23 +08:00
|
|
|
// TODO(riverriddle) Rethink this flag when we have a pass that can remove debug
|
|
|
|
// info or when we have a system for printer flags.
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
shouldPrintDebugInfoOpt("mlir-print-debuginfo",
|
2019-01-26 12:37:33 +08:00
|
|
|
llvm::cl::desc("Print debug info in MLIR output"),
|
2019-01-24 05:11:23 +08:00
|
|
|
llvm::cl::init(false));
|
|
|
|
|
2019-01-26 12:37:33 +08:00
|
|
|
static llvm::cl::opt<bool> printPrettyDebugInfo(
|
|
|
|
"mlir-pretty-debuginfo",
|
|
|
|
llvm::cl::desc("Print pretty debug info in MLIR output"),
|
|
|
|
llvm::cl::init(false));
|
|
|
|
|
2019-02-05 05:01:06 +08:00
|
|
|
// Use the generic op output form in the function printer even if the custom
|
|
|
|
// form is defined.
|
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
printGenericOpForm("mlir-print-op-generic",
|
|
|
|
llvm::cl::desc("Print the generic op form"),
|
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
|
|
|
|
2018-07-18 07:56:54 +08:00
|
|
|
namespace {
|
2019-05-10 03:08:13 +08:00
|
|
|
/// A special index constant used for non-kind attribute aliases.
|
|
|
|
static constexpr int kNonAttrKindAlias = -1;
|
|
|
|
|
2018-07-19 01:16:05 +08:00
|
|
|
class ModuleState {
|
2019-05-07 01:36:32 +08:00
|
|
|
|
2018-07-19 01:16:05 +08:00
|
|
|
public:
|
2018-10-22 10:49:31 +08:00
|
|
|
/// This is the current context if it is knowable, otherwise this is null.
|
|
|
|
MLIRContext *const context;
|
2018-07-18 07:56:54 +08:00
|
|
|
|
2018-10-22 10:49:31 +08:00
|
|
|
explicit ModuleState(MLIRContext *context) : context(context) {}
|
2018-07-18 07:56:54 +08:00
|
|
|
|
2018-07-21 00:35:47 +08:00
|
|
|
// Initializes module state, populating affine map state.
|
2019-07-03 01:49:17 +08:00
|
|
|
void initialize(Module module);
|
2018-07-18 07:56:54 +08:00
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
Twine getAttributeAlias(Attribute attr) const {
|
|
|
|
auto alias = attrToAlias.find(attr);
|
|
|
|
if (alias == attrToAlias.end())
|
|
|
|
return Twine();
|
|
|
|
|
|
|
|
// Return the alias for this attribute, along with the index if this was
|
|
|
|
// generated by a kind alias.
|
|
|
|
int kindIndex = alias->second.second;
|
|
|
|
return alias->second.first +
|
|
|
|
(kindIndex == kNonAttrKindAlias ? Twine() : Twine(kindIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
void printAttributeAliases(raw_ostream &os) const {
|
|
|
|
auto printAlias = [&](StringRef alias, Attribute attr, int index) {
|
|
|
|
os << '#' << alias;
|
|
|
|
if (index != kNonAttrKindAlias)
|
|
|
|
os << index;
|
|
|
|
os << " = " << attr << '\n';
|
|
|
|
};
|
|
|
|
|
|
|
|
// Print all of the attribute kind aliases.
|
|
|
|
for (auto &kindAlias : attrKindToAlias) {
|
|
|
|
for (unsigned i = 0, e = kindAlias.second.second.size(); i != e; ++i)
|
|
|
|
printAlias(kindAlias.second.first, kindAlias.second.second[i], i);
|
|
|
|
os << "\n";
|
2018-07-18 07:56:54 +08:00
|
|
|
}
|
2018-07-21 00:35:47 +08:00
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
// In a second pass print all of the remaining attribute aliases that aren't
|
|
|
|
// kind aliases.
|
|
|
|
for (Attribute attr : usedAttributes) {
|
|
|
|
auto alias = attrToAlias.find(attr);
|
|
|
|
if (alias != attrToAlias.end() &&
|
|
|
|
alias->second.second == kNonAttrKindAlias)
|
|
|
|
printAlias(alias->second.first, attr, alias->second.second);
|
2018-08-08 05:24:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 14:08:39 +08:00
|
|
|
StringRef getTypeAlias(Type ty) const { return typeToAlias.lookup(ty); }
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
void printTypeAliases(raw_ostream &os) const {
|
|
|
|
for (Type type : usedTypes) {
|
|
|
|
auto alias = typeToAlias.find(type);
|
|
|
|
if (alias != typeToAlias.end())
|
|
|
|
os << '!' << alias->second << " = type " << type << '\n';
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
private:
|
|
|
|
void recordAttributeReference(Attribute attr) {
|
|
|
|
// Don't recheck attributes that have already been seen or those that
|
|
|
|
// already have an alias.
|
|
|
|
if (!usedAttributes.insert(attr) || attrToAlias.count(attr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If this attribute kind has an alias, then record one for this attribute.
|
|
|
|
auto alias = attrKindToAlias.find(static_cast<unsigned>(attr.getKind()));
|
|
|
|
if (alias == attrKindToAlias.end())
|
|
|
|
return;
|
|
|
|
std::pair<StringRef, int> attrAlias(alias->second.first,
|
|
|
|
alias->second.second.size());
|
|
|
|
attrToAlias.insert({attr, attrAlias});
|
|
|
|
alias->second.second.push_back(attr);
|
2018-08-08 05:24:38 +08:00
|
|
|
}
|
|
|
|
|
2019-01-11 14:08:39 +08:00
|
|
|
void recordTypeReference(Type ty) { usedTypes.insert(ty); }
|
|
|
|
|
2018-07-18 07:56:54 +08:00
|
|
|
// Visit functions.
|
2019-03-28 23:24:38 +08:00
|
|
|
void visitOperation(Operation *op);
|
2018-10-31 05:59:22 +08:00
|
|
|
void visitType(Type type);
|
2018-10-26 06:46:10 +08:00
|
|
|
void visitAttribute(Attribute attr);
|
2018-07-19 07:29:21 +08:00
|
|
|
|
2019-01-11 14:08:39 +08:00
|
|
|
// Initialize symbol aliases.
|
|
|
|
void initializeSymbolAliases();
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
/// Set of attributes known to be used within the module.
|
|
|
|
llvm::SetVector<Attribute> usedAttributes;
|
2018-08-08 05:24:38 +08:00
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
/// Mapping between attribute and a pair comprised of a base alias name and a
|
|
|
|
/// count suffix. If the suffix is set to -1, it is not displayed.
|
|
|
|
llvm::MapVector<Attribute, std::pair<StringRef, int>> attrToAlias;
|
2019-01-11 14:08:39 +08:00
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
/// Mapping between attribute kind and a pair comprised of a base alias name
|
|
|
|
/// and a unique list of attributes belonging to this kind sorted by location
|
|
|
|
/// seen in the module.
|
|
|
|
llvm::MapVector<unsigned, std::pair<StringRef, std::vector<Attribute>>>
|
|
|
|
attrKindToAlias;
|
|
|
|
|
|
|
|
/// Set of types known to be used within the module.
|
2019-01-11 14:08:39 +08:00
|
|
|
llvm::SetVector<Type> usedTypes;
|
2019-05-07 01:36:32 +08:00
|
|
|
|
|
|
|
/// A mapping between a type and a given alias.
|
2019-01-11 14:08:39 +08:00
|
|
|
DenseMap<Type, StringRef> typeToAlias;
|
2018-07-18 07:56:54 +08:00
|
|
|
};
|
2018-07-24 02:44:40 +08:00
|
|
|
} // end anonymous namespace
|
2018-07-18 07:56:54 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// TODO Support visiting other types/operations when implemented.
|
2018-10-31 05:59:22 +08:00
|
|
|
void ModuleState::visitType(Type type) {
|
2019-01-11 14:08:39 +08:00
|
|
|
recordTypeReference(type);
|
2018-10-31 05:59:22 +08:00
|
|
|
if (auto funcType = type.dyn_cast<FunctionType>()) {
|
2018-07-18 07:56:54 +08:00
|
|
|
// Visit input and result types for functions.
|
2018-10-31 05:59:22 +08:00
|
|
|
for (auto input : funcType.getInputs())
|
2018-07-18 07:56:54 +08:00
|
|
|
visitType(input);
|
2018-10-31 05:59:22 +08:00
|
|
|
for (auto result : funcType.getResults())
|
2018-07-18 07:56:54 +08:00
|
|
|
visitType(result);
|
2019-05-18 06:23:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto memref = type.dyn_cast<MemRefType>()) {
|
2018-07-18 07:56:54 +08:00
|
|
|
// Visit affine maps in memref type.
|
2019-05-07 01:36:32 +08:00
|
|
|
for (auto map : memref.getAffineMaps())
|
|
|
|
recordAttributeReference(AffineMapAttr::get(map));
|
2019-05-18 06:23:44 +08:00
|
|
|
}
|
|
|
|
if (auto shapedType = type.dyn_cast<ShapedType>()) {
|
|
|
|
visitType(shapedType.getElementType());
|
2018-07-18 07:56:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 06:46:10 +08:00
|
|
|
void ModuleState::visitAttribute(Attribute attr) {
|
2019-05-07 01:36:32 +08:00
|
|
|
recordAttributeReference(attr);
|
|
|
|
if (auto arrayAttr = attr.dyn_cast<ArrayAttr>())
|
|
|
|
for (auto elt : arrayAttr.getValue())
|
2018-07-19 07:29:21 +08:00
|
|
|
visitAttribute(elt);
|
|
|
|
}
|
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
void ModuleState::visitOperation(Operation *op) {
|
2018-12-30 07:33:43 +08:00
|
|
|
// Visit all the types used in the operation.
|
2019-05-25 04:28:55 +08:00
|
|
|
for (auto type : op->getOperandTypes())
|
|
|
|
visitType(type);
|
|
|
|
for (auto type : op->getResultTypes())
|
|
|
|
visitType(type);
|
2018-12-30 07:33:43 +08:00
|
|
|
|
|
|
|
// Visit each of the attributes.
|
2019-03-28 23:24:38 +08:00
|
|
|
for (auto elt : op->getAttrs())
|
2018-12-30 07:33:43 +08:00
|
|
|
visitAttribute(elt.second);
|
2018-08-08 05:24:38 +08:00
|
|
|
}
|
|
|
|
|
2019-01-11 14:08:39 +08:00
|
|
|
// Utility to generate a function to register a symbol alias.
|
2019-05-07 01:36:32 +08:00
|
|
|
static bool canRegisterAlias(StringRef name, llvm::StringSet<> &usedAliases) {
|
2019-01-11 14:08:39 +08:00
|
|
|
assert(!name.empty() && "expected alias name to be non-empty");
|
|
|
|
// TODO(riverriddle) Assert that the provided alias name can be lexed as
|
|
|
|
// an identifier.
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
// Check that the alias doesn't contain a '.' character and the name is not
|
|
|
|
// already in use.
|
|
|
|
return !name.contains('.') && usedAliases.insert(name).second;
|
2019-01-11 14:08:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleState::initializeSymbolAliases() {
|
|
|
|
// Track the identifiers in use for each symbol so that the same identifier
|
|
|
|
// isn't used twice.
|
|
|
|
llvm::StringSet<> usedAliases;
|
|
|
|
|
|
|
|
// Get the currently registered dialects.
|
|
|
|
auto dialects = context->getRegisteredDialects();
|
|
|
|
|
|
|
|
// Collect the set of aliases from each dialect.
|
2019-05-07 01:36:32 +08:00
|
|
|
SmallVector<std::pair<unsigned, StringRef>, 8> attributeKindAliases;
|
|
|
|
SmallVector<std::pair<Attribute, StringRef>, 8> attributeAliases;
|
|
|
|
SmallVector<std::pair<Type, StringRef>, 16> typeAliases;
|
|
|
|
|
|
|
|
// AffineMap/Integer set have specific kind aliases.
|
2019-05-14 03:34:42 +08:00
|
|
|
attributeKindAliases.emplace_back(StandardAttributes::AffineMap, "map");
|
|
|
|
attributeKindAliases.emplace_back(StandardAttributes::IntegerSet, "set");
|
2019-05-07 01:36:32 +08:00
|
|
|
|
2019-01-11 14:08:39 +08:00
|
|
|
for (auto *dialect : dialects) {
|
2019-05-07 01:36:32 +08:00
|
|
|
dialect->getAttributeKindAliases(attributeKindAliases);
|
|
|
|
dialect->getAttributeAliases(attributeAliases);
|
2019-01-11 14:08:39 +08:00
|
|
|
dialect->getTypeAliases(typeAliases);
|
|
|
|
}
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
// Setup the attribute kind aliases.
|
|
|
|
StringRef alias;
|
|
|
|
unsigned attrKind;
|
|
|
|
for (auto &attrAliasPair : attributeKindAliases) {
|
|
|
|
std::tie(attrKind, alias) = attrAliasPair;
|
|
|
|
assert(!alias.empty() && "expected non-empty alias string");
|
|
|
|
if (!usedAliases.count(alias) && !alias.contains('.'))
|
|
|
|
attrKindToAlias.insert({attrKind, {alias, {}}});
|
2019-01-11 14:08:39 +08:00
|
|
|
}
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
// Clear the set of used identifiers so that the attribute kind aliases are
|
|
|
|
// just a prefix and not the full alias, i.e. there may be some overlap.
|
|
|
|
usedAliases.clear();
|
|
|
|
|
|
|
|
// Register the attribute aliases.
|
|
|
|
// Create a regex for the attribute kind alias names, these have a prefix with
|
|
|
|
// a counter appended to the end. We prevent normal aliases from having these
|
|
|
|
// names to avoid collisions.
|
|
|
|
llvm::Regex reservedAttrNames("[0-9]+$");
|
|
|
|
|
|
|
|
// Attribute value aliases.
|
|
|
|
Attribute attr;
|
|
|
|
for (auto &attrAliasPair : attributeAliases) {
|
|
|
|
std::tie(attr, alias) = attrAliasPair;
|
|
|
|
if (!reservedAttrNames.match(alias) && canRegisterAlias(alias, usedAliases))
|
|
|
|
attrToAlias.insert({attr, {alias, kNonAttrKindAlias}});
|
2019-01-11 14:08:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the set of used identifiers as types can have the same identifiers as
|
|
|
|
// affine structures.
|
|
|
|
usedAliases.clear();
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
// Type aliases.
|
2019-01-11 14:08:39 +08:00
|
|
|
for (auto &typeAliasPair : typeAliases)
|
2019-05-07 01:36:32 +08:00
|
|
|
if (canRegisterAlias(typeAliasPair.second, usedAliases))
|
|
|
|
typeToAlias.insert(typeAliasPair);
|
2019-01-11 14:08:39 +08:00
|
|
|
}
|
|
|
|
|
2018-08-08 05:24:38 +08:00
|
|
|
// Initializes module state, populating affine map and integer set state.
|
2019-07-03 01:49:17 +08:00
|
|
|
void ModuleState::initialize(Module module) {
|
2019-05-07 01:36:32 +08:00
|
|
|
// Initialize the symbol aliases.
|
|
|
|
initializeSymbolAliases();
|
|
|
|
|
|
|
|
// Walk the module and visit each operation.
|
2019-07-03 01:49:17 +08:00
|
|
|
for (auto fn : module) {
|
2018-12-30 07:33:43 +08:00
|
|
|
visitType(fn.getType());
|
2019-05-07 01:36:32 +08:00
|
|
|
for (auto attr : fn.getAttrs())
|
|
|
|
ModuleState::visitAttribute(attr.second);
|
2018-12-30 07:33:43 +08:00
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
fn.walk([&](Operation *op) { ModuleState::visitOperation(op); });
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ModulePrinter
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class ModulePrinter {
|
|
|
|
public:
|
|
|
|
ModulePrinter(raw_ostream &os, ModuleState &state) : os(os), state(state) {}
|
2019-03-21 12:14:59 +08:00
|
|
|
explicit ModulePrinter(ModulePrinter &printer)
|
2018-07-21 00:35:47 +08:00
|
|
|
: os(printer.os), state(printer.state) {}
|
|
|
|
|
|
|
|
template <typename Container, typename UnaryFunctor>
|
|
|
|
inline void interleaveComma(const Container &c, UnaryFunctor each_fn) const {
|
|
|
|
interleave(c.begin(), c.end(), each_fn, [&]() { os << ", "; });
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:49:17 +08:00
|
|
|
void print(Module module);
|
2019-06-27 09:29:25 +08:00
|
|
|
|
|
|
|
/// Print the given attribute. If 'mayElideType' is true, some attributes are
|
|
|
|
/// printed without the type when the type matches the default used in the
|
|
|
|
/// parser (for example i64 is the default for integer attributes).
|
|
|
|
void printAttribute(Attribute attr, bool mayElideType = false);
|
2019-02-05 23:12:46 +08:00
|
|
|
|
2018-10-31 05:59:22 +08:00
|
|
|
void printType(Type type);
|
2019-07-02 01:29:09 +08:00
|
|
|
void print(Function fn);
|
2019-06-22 09:27:49 +08:00
|
|
|
void printLocation(LocationAttr loc);
|
2018-07-21 00:35:47 +08:00
|
|
|
|
2018-10-10 07:39:24 +08:00
|
|
|
void printAffineMap(AffineMap map);
|
2019-06-26 01:29:53 +08:00
|
|
|
void printAffineExpr(
|
|
|
|
AffineExpr expr,
|
|
|
|
llvm::function_ref<void(unsigned, bool)> printValueName = nullptr);
|
2018-10-09 04:47:18 +08:00
|
|
|
void printAffineConstraint(AffineExpr expr, bool isEq);
|
2018-10-11 00:45:59 +08:00
|
|
|
void printIntegerSet(IntegerSet set);
|
2018-07-21 00:35:47 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
raw_ostream &os;
|
|
|
|
ModuleState &state;
|
|
|
|
|
2018-09-19 07:36:26 +08:00
|
|
|
void printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
2019-03-02 03:29:01 +08:00
|
|
|
ArrayRef<StringRef> elidedAttrs = {});
|
2019-01-24 05:11:23 +08:00
|
|
|
void printTrailingLocation(Location loc);
|
2019-06-22 09:27:49 +08:00
|
|
|
void printLocationInternal(LocationAttr loc, bool pretty = false);
|
2018-10-26 06:46:10 +08:00
|
|
|
void printDenseElementsAttr(DenseElementsAttr attr);
|
2018-07-21 00:35:47 +08:00
|
|
|
|
2018-08-01 07:21:36 +08:00
|
|
|
/// This enum is used to represent the binding stength of the enclosing
|
2018-10-10 01:59:27 +08:00
|
|
|
/// context that an AffineExprStorage is being printed in, so we can
|
2018-10-09 04:47:18 +08:00
|
|
|
/// intelligently produce parens.
|
2018-08-01 07:21:36 +08:00
|
|
|
enum class BindingStrength {
|
|
|
|
Weak, // + and -
|
|
|
|
Strong, // All other binary operators.
|
|
|
|
};
|
2019-06-26 01:29:53 +08:00
|
|
|
void printAffineExprInternal(
|
|
|
|
AffineExpr expr, BindingStrength enclosingTightness,
|
|
|
|
llvm::function_ref<void(unsigned, bool)> printValueName = nullptr);
|
2018-07-21 00:35:47 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2019-01-24 05:11:23 +08:00
|
|
|
void ModulePrinter::printTrailingLocation(Location loc) {
|
|
|
|
// Check to see if we are printing debug information.
|
|
|
|
if (!shouldPrintDebugInfoOpt)
|
|
|
|
return;
|
|
|
|
|
2019-01-24 08:37:45 +08:00
|
|
|
os << " ";
|
|
|
|
printLocation(loc);
|
2019-01-24 05:11:23 +08:00
|
|
|
}
|
|
|
|
|
2019-06-22 09:27:49 +08:00
|
|
|
void ModulePrinter::printLocationInternal(LocationAttr loc, bool pretty) {
|
2019-01-24 05:11:23 +08:00
|
|
|
switch (loc.getKind()) {
|
2019-06-22 09:27:49 +08:00
|
|
|
case StandardAttributes::UnknownLocation:
|
2019-01-26 12:37:33 +08:00
|
|
|
if (pretty)
|
|
|
|
os << "[unknown]";
|
|
|
|
else
|
|
|
|
os << "unknown";
|
2019-01-24 05:11:23 +08:00
|
|
|
break;
|
2019-06-22 09:27:49 +08:00
|
|
|
case StandardAttributes::FileLineColLocation: {
|
2019-01-24 05:11:23 +08:00
|
|
|
auto fileLoc = loc.cast<FileLineColLoc>();
|
2019-01-26 12:37:33 +08:00
|
|
|
auto mayQuote = pretty ? "" : "\"";
|
|
|
|
os << mayQuote << fileLoc.getFilename() << mayQuote << ':'
|
|
|
|
<< fileLoc.getLine() << ':' << fileLoc.getColumn();
|
2019-01-24 05:11:23 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-06-22 09:27:49 +08:00
|
|
|
case StandardAttributes::NameLocation: {
|
2019-05-14 05:45:48 +08:00
|
|
|
auto nameLoc = loc.cast<NameLoc>();
|
|
|
|
os << '\"' << nameLoc.getName() << '\"';
|
|
|
|
|
|
|
|
// Print the child if it isn't unknown.
|
|
|
|
auto childLoc = nameLoc.getChildLoc();
|
|
|
|
if (!childLoc.isa<UnknownLoc>()) {
|
|
|
|
os << '(';
|
|
|
|
printLocationInternal(childLoc, pretty);
|
|
|
|
os << ')';
|
|
|
|
}
|
2019-01-24 05:11:23 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-06-22 09:27:49 +08:00
|
|
|
case StandardAttributes::CallSiteLocation: {
|
2019-01-24 05:11:23 +08:00
|
|
|
auto callLocation = loc.cast<CallSiteLoc>();
|
|
|
|
auto caller = callLocation.getCaller();
|
2019-01-26 12:37:33 +08:00
|
|
|
auto callee = callLocation.getCallee();
|
|
|
|
if (!pretty)
|
|
|
|
os << "callsite(";
|
|
|
|
printLocationInternal(callee, pretty);
|
|
|
|
if (pretty) {
|
|
|
|
if (callee.isa<NameLoc>()) {
|
|
|
|
if (caller.isa<FileLineColLoc>()) {
|
|
|
|
os << " at ";
|
|
|
|
} else {
|
|
|
|
os << "\n at ";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os << "\n at ";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os << " at ";
|
|
|
|
}
|
|
|
|
printLocationInternal(caller, pretty);
|
|
|
|
if (!pretty)
|
|
|
|
os << ")";
|
2019-01-24 05:11:23 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-06-22 09:27:49 +08:00
|
|
|
case StandardAttributes::FusedLocation: {
|
2019-01-24 05:11:23 +08:00
|
|
|
auto fusedLoc = loc.cast<FusedLoc>();
|
2019-01-26 12:37:33 +08:00
|
|
|
if (!pretty)
|
|
|
|
os << "fused";
|
2019-01-24 05:11:23 +08:00
|
|
|
if (auto metadata = fusedLoc.getMetadata())
|
|
|
|
os << '<' << metadata << '>';
|
|
|
|
os << '[';
|
|
|
|
interleave(
|
|
|
|
fusedLoc.getLocations(),
|
2019-01-26 12:37:33 +08:00
|
|
|
[&](Location loc) { printLocationInternal(loc, pretty); },
|
2019-01-24 05:11:23 +08:00
|
|
|
[&]() { os << ", "; });
|
|
|
|
os << ']';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:49:17 +08:00
|
|
|
void ModulePrinter::print(Module module) {
|
2019-05-07 01:36:32 +08:00
|
|
|
// Output the aliases at the top level.
|
|
|
|
state.printAttributeAliases(os);
|
|
|
|
state.printTypeAliases(os);
|
|
|
|
|
|
|
|
// Print the module.
|
2019-07-03 01:49:17 +08:00
|
|
|
for (auto fn : module)
|
2019-07-02 01:29:09 +08:00
|
|
|
print(fn);
|
2018-07-18 07:56:54 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:09:54 +08:00
|
|
|
/// Print a floating point value in a way that the parser will be able to
|
|
|
|
/// round-trip losslessly.
|
2018-10-21 09:31:49 +08:00
|
|
|
static void printFloatValue(const APFloat &apValue, raw_ostream &os) {
|
2018-08-16 00:09:54 +08:00
|
|
|
// We would like to output the FP constant value in exponential notation,
|
|
|
|
// but we cannot do this if doing so will lose precision. Check here to
|
|
|
|
// make sure that we only output it in exponential format if we can parse
|
|
|
|
// the value back and get the same value.
|
|
|
|
bool isInf = apValue.isInfinity();
|
|
|
|
bool isNaN = apValue.isNaN();
|
|
|
|
if (!isInf && !isNaN) {
|
|
|
|
SmallString<128> strValue;
|
|
|
|
apValue.toString(strValue, 6, 0, false);
|
|
|
|
|
|
|
|
// Check to make sure that the stringized number is not some string like
|
|
|
|
// "Inf" or NaN, that atof will accept, but the lexer will not. Check
|
|
|
|
// that the string matches the "[-+]?[0-9]" regex.
|
|
|
|
assert(((strValue[0] >= '0' && strValue[0] <= '9') ||
|
|
|
|
((strValue[0] == '-' || strValue[0] == '+') &&
|
|
|
|
(strValue[1] >= '0' && strValue[1] <= '9'))) &&
|
|
|
|
"[-+]?[0-9] regex does not match!");
|
|
|
|
// Reparse stringized version!
|
2018-12-17 23:19:53 +08:00
|
|
|
if (APFloat(apValue.getSemantics(), strValue).bitwiseIsEqual(apValue)) {
|
2018-08-16 00:09:54 +08:00
|
|
|
os << strValue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 09:31:49 +08:00
|
|
|
SmallVector<char, 16> str;
|
|
|
|
apValue.toString(str);
|
|
|
|
os << str;
|
2018-08-16 00:09:54 +08:00
|
|
|
}
|
|
|
|
|
2019-06-22 09:27:49 +08:00
|
|
|
void ModulePrinter::printLocation(LocationAttr loc) {
|
2019-01-26 12:37:33 +08:00
|
|
|
if (printPrettyDebugInfo) {
|
|
|
|
printLocationInternal(loc, /*pretty=*/true);
|
|
|
|
} else {
|
|
|
|
os << "loc(";
|
|
|
|
printLocationInternal(loc);
|
|
|
|
os << ')';
|
|
|
|
}
|
2019-01-24 05:11:23 +08:00
|
|
|
}
|
|
|
|
|
2019-05-16 00:10:52 +08:00
|
|
|
/// Returns if the given dialect symbol data is simple enough to print in the
|
|
|
|
/// pretty form, i.e. without the enclosing "".
|
|
|
|
static bool isDialectSymbolSimpleEnoughForPrettyForm(StringRef symName) {
|
|
|
|
// The name must start with an identifier.
|
|
|
|
if (symName.empty() || !isalpha(symName.front()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Ignore all the characters that are valid in an identifier in the symbol
|
|
|
|
// name.
|
|
|
|
symName =
|
|
|
|
symName.drop_while([](char c) { return llvm::isAlnum(c) || c == '.'; });
|
|
|
|
if (symName.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If we got to an unexpected character, then it must be a <>. Check those
|
|
|
|
// recursively.
|
|
|
|
if (symName.front() != '<' || symName.back() != '>')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SmallVector<char, 8> nestedPunctuation;
|
|
|
|
do {
|
|
|
|
// If we ran out of characters, then we had a punctuation mismatch.
|
|
|
|
if (symName.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto c = symName.front();
|
|
|
|
symName = symName.drop_front();
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
// We never allow null characters. This is an EOF indicator for the lexer
|
|
|
|
// which we could handle, but isn't important for any known dialect.
|
|
|
|
case '\0':
|
|
|
|
return false;
|
|
|
|
case '<':
|
|
|
|
case '[':
|
|
|
|
case '(':
|
|
|
|
case '{':
|
|
|
|
nestedPunctuation.push_back(c);
|
|
|
|
continue;
|
|
|
|
// Reject types with mismatched brackets.
|
|
|
|
case '>':
|
|
|
|
if (nestedPunctuation.pop_back_val() != '<')
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
if (nestedPunctuation.pop_back_val() != '[')
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
if (nestedPunctuation.pop_back_val() != '(')
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case '}':
|
|
|
|
if (nestedPunctuation.pop_back_val() != '{')
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're done when the punctuation is fully matched.
|
|
|
|
} while (!nestedPunctuation.empty());
|
|
|
|
|
|
|
|
// If there were extra characters, then we failed.
|
|
|
|
return symName.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Print the given dialect symbol to the stream.
|
|
|
|
static void printDialectSymbol(raw_ostream &os, StringRef symPrefix,
|
|
|
|
StringRef dialectName, StringRef symString) {
|
|
|
|
os << symPrefix << dialectName;
|
|
|
|
|
|
|
|
// If this symbol name is simple enough, print it directly in pretty form,
|
|
|
|
// otherwise, we print it as an escaped string.
|
|
|
|
if (isDialectSymbolSimpleEnoughForPrettyForm(symString)) {
|
|
|
|
os << '.' << symString;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: escape the symbol name, it could contain " characters.
|
|
|
|
os << "<\"" << symString << "\">";
|
|
|
|
}
|
|
|
|
|
2019-06-27 09:29:25 +08:00
|
|
|
void ModulePrinter::printAttribute(Attribute attr, bool mayElideType) {
|
2018-11-30 10:47:39 +08:00
|
|
|
if (!attr) {
|
|
|
|
os << "<<NULL ATTRIBUTE>>";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-07 01:36:32 +08:00
|
|
|
// Check for an alias for this attribute.
|
|
|
|
Twine alias = state.getAttributeAlias(attr);
|
|
|
|
if (!alias.isTriviallyEmpty()) {
|
|
|
|
os << '#' << alias;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-26 06:46:10 +08:00
|
|
|
switch (attr.getKind()) {
|
2019-05-16 00:10:52 +08:00
|
|
|
default: {
|
|
|
|
auto &dialect = attr.getDialect();
|
|
|
|
|
|
|
|
// Ask the dialect to serialize the attribute to a string.
|
|
|
|
std::string attrName;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream attrNameStr(attrName);
|
|
|
|
dialect.printAttribute(attr, attrNameStr);
|
|
|
|
}
|
2019-05-14 03:34:42 +08:00
|
|
|
|
2019-05-16 00:10:52 +08:00
|
|
|
printDialectSymbol(os, "#", dialect.getNamespace(), attrName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case StandardAttributes::Opaque: {
|
|
|
|
auto opaqueAttr = attr.cast<OpaqueAttr>();
|
|
|
|
printDialectSymbol(os, "#", opaqueAttr.getDialectNamespace(),
|
|
|
|
opaqueAttr.getAttrData());
|
|
|
|
break;
|
|
|
|
}
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::Unit:
|
2019-04-26 00:56:09 +08:00
|
|
|
os << "unit";
|
|
|
|
break;
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::Bool:
|
2018-10-26 06:46:10 +08:00
|
|
|
os << (attr.cast<BoolAttr>().getValue() ? "true" : "false");
|
2019-06-27 09:29:25 +08:00
|
|
|
|
|
|
|
// BoolAttr always elides the type.
|
|
|
|
return;
|
2019-06-01 00:24:48 +08:00
|
|
|
case StandardAttributes::Dictionary:
|
|
|
|
os << '{';
|
|
|
|
interleaveComma(attr.cast<DictionaryAttr>().getValue(),
|
|
|
|
[&](NamedAttribute attr) {
|
2019-06-26 10:06:06 +08:00
|
|
|
os << attr.first << " = ";
|
2019-06-01 00:24:48 +08:00
|
|
|
printAttribute(attr.second);
|
|
|
|
});
|
|
|
|
os << '}';
|
|
|
|
break;
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::Integer: {
|
2018-11-16 09:53:51 +08:00
|
|
|
auto intAttr = attr.cast<IntegerAttr>();
|
|
|
|
// Print all integer attributes as signed unless i1.
|
2018-12-18 02:05:56 +08:00
|
|
|
bool isSigned = intAttr.getType().isIndex() ||
|
|
|
|
intAttr.getType().getIntOrFloatBitWidth() != 1;
|
2018-11-16 09:53:51 +08:00
|
|
|
intAttr.getValue().print(os, isSigned);
|
2019-06-27 09:29:25 +08:00
|
|
|
|
|
|
|
// IntegerAttr elides the type if I64.
|
|
|
|
if (mayElideType && intAttr.getType().isInteger(64))
|
|
|
|
return;
|
2018-07-19 07:29:21 +08:00
|
|
|
break;
|
2018-11-16 09:53:51 +08:00
|
|
|
}
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::Float: {
|
2019-02-05 23:12:46 +08:00
|
|
|
auto floatAttr = attr.cast<FloatAttr>();
|
|
|
|
printFloatValue(floatAttr.getValue(), os);
|
2019-06-27 09:29:25 +08:00
|
|
|
|
|
|
|
// FloatAttr elides the type if F64.
|
|
|
|
if (mayElideType && floatAttr.getType().isF64())
|
|
|
|
return;
|
2018-07-19 07:29:21 +08:00
|
|
|
break;
|
2019-02-05 23:12:46 +08:00
|
|
|
}
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::String:
|
2018-08-16 00:09:54 +08:00
|
|
|
os << '"';
|
2018-10-26 06:46:10 +08:00
|
|
|
printEscapedString(attr.cast<StringAttr>().getValue(), os);
|
2018-08-16 00:09:54 +08:00
|
|
|
os << '"';
|
2018-07-19 07:29:21 +08:00
|
|
|
break;
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::Array:
|
2018-07-19 07:29:21 +08:00
|
|
|
os << '[';
|
2019-06-27 09:29:25 +08:00
|
|
|
interleaveComma(attr.cast<ArrayAttr>().getValue(), [&](Attribute attr) {
|
|
|
|
printAttribute(attr, /*mayElideType=*/true);
|
|
|
|
});
|
2018-07-19 07:29:21 +08:00
|
|
|
os << ']';
|
|
|
|
break;
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::AffineMap:
|
2019-05-07 01:36:32 +08:00
|
|
|
attr.cast<AffineMapAttr>().getValue().print(os);
|
2019-06-27 09:29:25 +08:00
|
|
|
|
|
|
|
// AffineMap always elides the type.
|
|
|
|
return;
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::IntegerSet:
|
2019-05-07 01:36:32 +08:00
|
|
|
attr.cast<IntegerSetAttr>().getValue().print(os);
|
2018-10-26 13:13:03 +08:00
|
|
|
break;
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::Type:
|
2018-10-26 06:46:10 +08:00
|
|
|
printType(attr.cast<TypeAttr>().getValue());
|
2018-07-19 07:29:21 +08:00
|
|
|
break;
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::Function: {
|
2019-05-23 04:41:23 +08:00
|
|
|
os << '@' << attr.cast<FunctionAttr>().getValue();
|
2018-08-20 12:17:22 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::OpaqueElements: {
|
2018-10-26 06:46:10 +08:00
|
|
|
auto eltsAttr = attr.cast<OpaqueElementsAttr>();
|
2019-06-26 07:06:13 +08:00
|
|
|
os << "opaque<\"" << eltsAttr.getDialect()->getNamespace() << "\", ";
|
2019-06-27 09:29:25 +08:00
|
|
|
os << '"' << "0x" << llvm::toHex(eltsAttr.getValue()) << "\">";
|
2018-10-24 04:44:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-06-07 07:15:42 +08:00
|
|
|
case StandardAttributes::DenseElements: {
|
2018-10-26 06:46:10 +08:00
|
|
|
auto eltsAttr = attr.cast<DenseElementsAttr>();
|
2018-10-19 04:54:44 +08:00
|
|
|
os << "dense<";
|
|
|
|
printDenseElementsAttr(eltsAttr);
|
2019-06-27 09:29:25 +08:00
|
|
|
os << '>';
|
2018-10-19 04:54:44 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-05-14 03:34:42 +08:00
|
|
|
case StandardAttributes::SparseElements: {
|
2018-10-26 06:46:10 +08:00
|
|
|
auto elementsAttr = attr.cast<SparseElementsAttr>();
|
Add support to constant sparse tensor / vector attribute
The SparseElementsAttr uses (COO) Coordinate List encoding to represents a
sparse tensor / vector. Specifically, the coordinates and values are stored as
two dense elements attributes. The first dense elements attribute is a 2-D
attribute with shape [N, ndims], which contains the indices of the elements
with nonzero values in the constant vector/tensor. The second elements
attribute is a 1-D attribute list with shape [N], which supplies the values for
each element in the first elements attribute. ndims is the rank of the
vector/tensor and N is the total nonzero elements.
The syntax is:
`sparse<` (tensor-type | vector-type)`, ` indices-attribute-list, values-attribute-list `>`
Example: a sparse tensor
sparse<vector<3x4xi32>, [[0, 0], [1, 2]], [1, 2]> represents the dense tensor
[[1, 0, 0, 0]
[0, 0, 2, 0]
[0, 0, 0, 0]]
PiperOrigin-RevId: 217764319
2018-10-19 05:02:20 +08:00
|
|
|
os << "sparse<";
|
2018-10-26 06:46:10 +08:00
|
|
|
printDenseElementsAttr(elementsAttr.getIndices());
|
Add support to constant sparse tensor / vector attribute
The SparseElementsAttr uses (COO) Coordinate List encoding to represents a
sparse tensor / vector. Specifically, the coordinates and values are stored as
two dense elements attributes. The first dense elements attribute is a 2-D
attribute with shape [N, ndims], which contains the indices of the elements
with nonzero values in the constant vector/tensor. The second elements
attribute is a 1-D attribute list with shape [N], which supplies the values for
each element in the first elements attribute. ndims is the rank of the
vector/tensor and N is the total nonzero elements.
The syntax is:
`sparse<` (tensor-type | vector-type)`, ` indices-attribute-list, values-attribute-list `>`
Example: a sparse tensor
sparse<vector<3x4xi32>, [[0, 0], [1, 2]], [1, 2]> represents the dense tensor
[[1, 0, 0, 0]
[0, 0, 2, 0]
[0, 0, 0, 0]]
PiperOrigin-RevId: 217764319
2018-10-19 05:02:20 +08:00
|
|
|
os << ", ";
|
2018-10-26 06:46:10 +08:00
|
|
|
printDenseElementsAttr(elementsAttr.getValues());
|
2019-06-27 09:29:25 +08:00
|
|
|
os << '>';
|
Add support to constant sparse tensor / vector attribute
The SparseElementsAttr uses (COO) Coordinate List encoding to represents a
sparse tensor / vector. Specifically, the coordinates and values are stored as
two dense elements attributes. The first dense elements attribute is a 2-D
attribute with shape [N, ndims], which contains the indices of the elements
with nonzero values in the constant vector/tensor. The second elements
attribute is a 1-D attribute list with shape [N], which supplies the values for
each element in the first elements attribute. ndims is the rank of the
vector/tensor and N is the total nonzero elements.
The syntax is:
`sparse<` (tensor-type | vector-type)`, ` indices-attribute-list, values-attribute-list `>`
Example: a sparse tensor
sparse<vector<3x4xi32>, [[0, 0], [1, 2]], [1, 2]> represents the dense tensor
[[1, 0, 0, 0]
[0, 0, 2, 0]
[0, 0, 0, 0]]
PiperOrigin-RevId: 217764319
2018-10-19 05:02:20 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-06-22 09:27:49 +08:00
|
|
|
|
|
|
|
// Location attributes.
|
|
|
|
case StandardAttributes::CallSiteLocation:
|
|
|
|
case StandardAttributes::FileLineColLocation:
|
|
|
|
case StandardAttributes::FusedLocation:
|
|
|
|
case StandardAttributes::NameLocation:
|
|
|
|
case StandardAttributes::UnknownLocation:
|
|
|
|
printLocation(attr.cast<LocationAttr>());
|
|
|
|
break;
|
2018-07-19 07:29:21 +08:00
|
|
|
}
|
2019-06-27 09:29:25 +08:00
|
|
|
|
|
|
|
// Print the type if it isn't a 'none' type.
|
|
|
|
auto attrType = attr.getType();
|
|
|
|
if (!attrType.isa<NoneType>()) {
|
|
|
|
os << " : ";
|
|
|
|
printType(attrType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Print the integer element of the given DenseElementsAttr at 'index'.
|
|
|
|
static void printDenseIntElement(DenseElementsAttr attr, raw_ostream &os,
|
|
|
|
unsigned index) {
|
|
|
|
APInt value = *std::next(attr.getIntValues().begin(), index);
|
|
|
|
value.print(os, /*isSigned=*/value.getBitWidth() != 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Print the float element of the given DenseElementsAttr at 'index'.
|
|
|
|
static void printDenseFloatElement(DenseElementsAttr attr, raw_ostream &os,
|
|
|
|
unsigned index) {
|
|
|
|
APFloat value = *std::next(attr.getFloatValues().begin(), index);
|
|
|
|
printFloatValue(value, os);
|
2018-07-19 07:29:21 +08:00
|
|
|
}
|
|
|
|
|
2018-10-26 06:46:10 +08:00
|
|
|
void ModulePrinter::printDenseElementsAttr(DenseElementsAttr attr) {
|
2018-10-31 05:59:22 +08:00
|
|
|
auto type = attr.getType();
|
|
|
|
auto shape = type.getShape();
|
|
|
|
auto rank = type.getRank();
|
2018-10-19 04:54:44 +08:00
|
|
|
|
2019-06-27 09:29:25 +08:00
|
|
|
// The function used to print elements of this attribute.
|
|
|
|
auto printEltFn = type.getElementType().isa<IntegerType>()
|
|
|
|
? printDenseIntElement
|
|
|
|
: printDenseFloatElement;
|
2018-10-19 04:54:44 +08:00
|
|
|
|
2019-06-13 06:05:45 +08:00
|
|
|
// Special case for 0-d and splat tensors.
|
|
|
|
if (attr.isSplat()) {
|
2019-06-27 09:29:25 +08:00
|
|
|
printEltFn(attr, os, 0);
|
2019-04-02 01:01:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-19 04:54:44 +08:00
|
|
|
// Special case for degenerate tensors.
|
2019-06-27 09:29:25 +08:00
|
|
|
auto numElements = type.getNumElements();
|
|
|
|
if (numElements == 0) {
|
2018-10-19 04:54:44 +08:00
|
|
|
for (int i = 0; i < rank; ++i)
|
|
|
|
os << '[';
|
|
|
|
for (int i = 0; i < rank; ++i)
|
|
|
|
os << ']';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We use a mixed-radix counter to iterate through the shape. When we bump a
|
|
|
|
// non-least-significant digit, we emit a close bracket. When we next emit an
|
|
|
|
// element we re-open all closed brackets.
|
|
|
|
|
|
|
|
// The mixed-radix counter, with radices in 'shape'.
|
|
|
|
SmallVector<unsigned, 4> counter(rank, 0);
|
|
|
|
// The number of brackets that have been opened and not closed.
|
|
|
|
unsigned openBrackets = 0;
|
|
|
|
|
|
|
|
auto bumpCounter = [&]() {
|
|
|
|
// Bump the least significant digit.
|
|
|
|
++counter[rank - 1];
|
|
|
|
// Iterate backwards bubbling back the increment.
|
|
|
|
for (unsigned i = rank - 1; i > 0; --i)
|
|
|
|
if (counter[i] >= shape[i]) {
|
|
|
|
// Index 'i' is rolled over. Bump (i-1) and close a bracket.
|
|
|
|
counter[i] = 0;
|
|
|
|
++counter[i - 1];
|
|
|
|
--openBrackets;
|
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-27 09:29:25 +08:00
|
|
|
for (unsigned idx = 0, e = numElements; idx != e; ++idx) {
|
2018-10-19 04:54:44 +08:00
|
|
|
if (idx != 0)
|
|
|
|
os << ", ";
|
|
|
|
while (openBrackets++ < rank)
|
|
|
|
os << '[';
|
|
|
|
openBrackets = rank;
|
2019-06-27 09:29:25 +08:00
|
|
|
printEltFn(attr, os, idx);
|
2018-10-19 04:54:44 +08:00
|
|
|
bumpCounter();
|
|
|
|
}
|
|
|
|
while (openBrackets-- > 0)
|
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
|
2018-10-31 05:59:22 +08:00
|
|
|
void ModulePrinter::printType(Type type) {
|
2019-01-11 14:08:39 +08:00
|
|
|
// Check for an alias for this type.
|
|
|
|
StringRef alias = state.getTypeAlias(type);
|
|
|
|
if (!alias.empty()) {
|
|
|
|
os << '!' << alias;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-31 05:59:22 +08:00
|
|
|
switch (type.getKind()) {
|
2019-01-03 06:16:40 +08:00
|
|
|
default: {
|
|
|
|
auto &dialect = type.getDialect();
|
2019-04-06 14:56:49 +08:00
|
|
|
|
|
|
|
// Ask the dialect to serialize the type to a string.
|
|
|
|
std::string typeName;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream typeNameStr(typeName);
|
|
|
|
dialect.printType(type, typeNameStr);
|
|
|
|
}
|
|
|
|
|
2019-05-16 00:10:52 +08:00
|
|
|
printDialectSymbol(os, "!", dialect.getNamespace(), typeName);
|
2019-01-03 06:16:40 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-04-04 07:49:01 +08:00
|
|
|
case Type::Kind::Opaque: {
|
|
|
|
auto opaqueTy = type.cast<OpaqueType>();
|
2019-05-16 00:10:52 +08:00
|
|
|
printDialectSymbol(os, "!", opaqueTy.getDialectNamespace(),
|
|
|
|
opaqueTy.getTypeData());
|
2019-01-08 01:58:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-02-13 03:08:04 +08:00
|
|
|
case StandardTypes::Index:
|
2018-10-07 08:21:53 +08:00
|
|
|
os << "index";
|
2018-07-19 01:16:05 +08:00
|
|
|
return;
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::BF16:
|
2018-07-19 01:16:05 +08:00
|
|
|
os << "bf16";
|
|
|
|
return;
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::F16:
|
2018-07-19 01:16:05 +08:00
|
|
|
os << "f16";
|
|
|
|
return;
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::F32:
|
2018-07-19 01:16:05 +08:00
|
|
|
os << "f32";
|
|
|
|
return;
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::F64:
|
2018-07-19 01:16:05 +08:00
|
|
|
os << "f64";
|
|
|
|
return;
|
2018-07-18 07:56:54 +08:00
|
|
|
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::Integer: {
|
2018-10-31 05:59:22 +08:00
|
|
|
auto integer = type.cast<IntegerType>();
|
|
|
|
os << 'i' << integer.getWidth();
|
2018-07-18 07:56:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Type::Kind::Function: {
|
2018-10-31 05:59:22 +08:00
|
|
|
auto func = type.cast<FunctionType>();
|
2018-07-18 07:56:54 +08:00
|
|
|
os << '(';
|
2018-10-31 05:59:22 +08:00
|
|
|
interleaveComma(func.getInputs(), [&](Type type) { printType(type); });
|
2018-07-18 07:56:54 +08:00
|
|
|
os << ") -> ";
|
2018-10-31 05:59:22 +08:00
|
|
|
auto results = func.getResults();
|
2019-02-06 03:47:02 +08:00
|
|
|
if (results.size() == 1 && !results[0].isa<FunctionType>())
|
2018-10-31 05:59:22 +08:00
|
|
|
os << results[0];
|
2018-07-18 07:56:54 +08:00
|
|
|
else {
|
|
|
|
os << '(';
|
2018-10-31 05:59:22 +08:00
|
|
|
interleaveComma(results, [&](Type type) { printType(type); });
|
2018-07-18 07:56:54 +08:00
|
|
|
os << ')';
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::Vector: {
|
2018-10-31 05:59:22 +08:00
|
|
|
auto v = type.cast<VectorType>();
|
2018-07-18 07:56:54 +08:00
|
|
|
os << "vector<";
|
2018-10-31 05:59:22 +08:00
|
|
|
for (auto dim : v.getShape())
|
2018-07-24 02:44:40 +08:00
|
|
|
os << dim << 'x';
|
2018-10-31 05:59:22 +08:00
|
|
|
os << v.getElementType() << '>';
|
2018-07-18 07:56:54 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::RankedTensor: {
|
2018-10-31 05:59:22 +08:00
|
|
|
auto v = type.cast<RankedTensorType>();
|
2018-07-18 07:56:54 +08:00
|
|
|
os << "tensor<";
|
2018-10-31 05:59:22 +08:00
|
|
|
for (auto dim : v.getShape()) {
|
2018-07-18 07:56:54 +08:00
|
|
|
if (dim < 0)
|
|
|
|
os << '?';
|
|
|
|
else
|
|
|
|
os << dim;
|
|
|
|
os << 'x';
|
|
|
|
}
|
2018-10-31 05:59:22 +08:00
|
|
|
os << v.getElementType() << '>';
|
2018-07-18 07:56:54 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::UnrankedTensor: {
|
2018-10-31 05:59:22 +08:00
|
|
|
auto v = type.cast<UnrankedTensorType>();
|
2018-09-14 01:43:35 +08:00
|
|
|
os << "tensor<*x";
|
2018-10-31 05:59:22 +08:00
|
|
|
printType(v.getElementType());
|
2018-07-26 03:55:50 +08:00
|
|
|
os << '>';
|
2018-07-18 07:56:54 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-01-04 06:29:52 +08:00
|
|
|
case StandardTypes::MemRef: {
|
2018-10-31 05:59:22 +08:00
|
|
|
auto v = type.cast<MemRefType>();
|
2018-07-18 07:56:54 +08:00
|
|
|
os << "memref<";
|
2018-10-31 05:59:22 +08:00
|
|
|
for (auto dim : v.getShape()) {
|
2018-07-18 07:56:54 +08:00
|
|
|
if (dim < 0)
|
|
|
|
os << '?';
|
|
|
|
else
|
|
|
|
os << dim;
|
|
|
|
os << 'x';
|
|
|
|
}
|
2018-10-31 05:59:22 +08:00
|
|
|
printType(v.getElementType());
|
|
|
|
for (auto map : v.getAffineMaps()) {
|
2018-07-18 07:56:54 +08:00
|
|
|
os << ", ";
|
2019-05-07 01:36:32 +08:00
|
|
|
printAttribute(AffineMapAttr::get(map));
|
2018-07-18 07:56:54 +08:00
|
|
|
}
|
2018-07-26 03:55:50 +08:00
|
|
|
// Only print the memory space if it is the non-default one.
|
2018-10-31 05:59:22 +08:00
|
|
|
if (v.getMemorySpace())
|
|
|
|
os << ", " << v.getMemorySpace();
|
2018-07-18 07:56:54 +08:00
|
|
|
os << '>';
|
|
|
|
return;
|
|
|
|
}
|
2019-03-30 13:23:34 +08:00
|
|
|
case StandardTypes::Complex:
|
|
|
|
os << "complex<";
|
|
|
|
printType(type.cast<ComplexType>().getElementType());
|
|
|
|
os << '>';
|
|
|
|
return;
|
2019-03-20 01:59:02 +08:00
|
|
|
case StandardTypes::Tuple: {
|
|
|
|
auto tuple = type.cast<TupleType>();
|
|
|
|
os << "tuple<";
|
|
|
|
interleaveComma(tuple.getTypes(), [&](Type type) { printType(type); });
|
|
|
|
os << '>';
|
|
|
|
return;
|
|
|
|
}
|
2019-04-28 09:35:04 +08:00
|
|
|
case StandardTypes::None:
|
|
|
|
os << "none";
|
|
|
|
return;
|
2018-07-18 07:56:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 00:35:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Affine expressions and maps
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-06-26 01:29:53 +08:00
|
|
|
void ModulePrinter::printAffineExpr(
|
|
|
|
AffineExpr expr, llvm::function_ref<void(unsigned, bool)> printValueName) {
|
|
|
|
printAffineExprInternal(expr, BindingStrength::Weak, printValueName);
|
2018-08-01 07:21:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePrinter::printAffineExprInternal(
|
2019-06-24 22:31:52 +08:00
|
|
|
AffineExpr expr, BindingStrength enclosingTightness,
|
2019-06-26 01:29:53 +08:00
|
|
|
llvm::function_ref<void(unsigned, bool)> printValueName) {
|
2018-08-01 07:21:36 +08:00
|
|
|
const char *binopSpelling = nullptr;
|
2018-10-10 01:59:27 +08:00
|
|
|
switch (expr.getKind()) {
|
2019-06-24 22:31:52 +08:00
|
|
|
case AffineExprKind::SymbolId: {
|
|
|
|
unsigned pos = expr.cast<AffineSymbolExpr>().getPosition();
|
2019-06-26 01:29:53 +08:00
|
|
|
if (printValueName)
|
|
|
|
printValueName(pos, /*isSymbol=*/true);
|
2019-06-24 22:31:52 +08:00
|
|
|
else
|
|
|
|
os << 's' << pos;
|
2018-07-21 00:35:47 +08:00
|
|
|
return;
|
2019-06-24 22:31:52 +08:00
|
|
|
}
|
|
|
|
case AffineExprKind::DimId: {
|
|
|
|
unsigned pos = expr.cast<AffineDimExpr>().getPosition();
|
2019-06-26 01:29:53 +08:00
|
|
|
if (printValueName)
|
|
|
|
printValueName(pos, /*isSymbol=*/false);
|
2019-06-24 22:31:52 +08:00
|
|
|
else
|
|
|
|
os << 'd' << pos;
|
2018-07-21 00:35:47 +08:00
|
|
|
return;
|
2019-06-24 22:31:52 +08:00
|
|
|
}
|
2018-10-09 01:20:25 +08:00
|
|
|
case AffineExprKind::Constant:
|
2018-10-10 01:59:27 +08:00
|
|
|
os << expr.cast<AffineConstantExpr>().getValue();
|
2018-07-21 00:35:47 +08:00
|
|
|
return;
|
2018-10-09 01:20:25 +08:00
|
|
|
case AffineExprKind::Add:
|
2018-08-01 07:21:36 +08:00
|
|
|
binopSpelling = " + ";
|
|
|
|
break;
|
2018-10-09 01:20:25 +08:00
|
|
|
case AffineExprKind::Mul:
|
2018-08-01 07:21:36 +08:00
|
|
|
binopSpelling = " * ";
|
|
|
|
break;
|
2018-10-09 01:20:25 +08:00
|
|
|
case AffineExprKind::FloorDiv:
|
2018-08-01 07:21:36 +08:00
|
|
|
binopSpelling = " floordiv ";
|
|
|
|
break;
|
2018-10-09 01:20:25 +08:00
|
|
|
case AffineExprKind::CeilDiv:
|
2018-08-01 07:21:36 +08:00
|
|
|
binopSpelling = " ceildiv ";
|
|
|
|
break;
|
2018-10-09 01:20:25 +08:00
|
|
|
case AffineExprKind::Mod:
|
2018-08-01 07:21:36 +08:00
|
|
|
binopSpelling = " mod ";
|
|
|
|
break;
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
|
|
|
|
2018-10-09 04:47:18 +08:00
|
|
|
auto binOp = expr.cast<AffineBinaryOpExpr>();
|
2019-01-21 22:59:58 +08:00
|
|
|
AffineExpr lhsExpr = binOp.getLHS();
|
|
|
|
AffineExpr rhsExpr = binOp.getRHS();
|
2018-07-21 00:35:47 +08:00
|
|
|
|
2018-08-01 07:21:36 +08:00
|
|
|
// Handle tightly binding binary operators.
|
2018-10-10 01:59:27 +08:00
|
|
|
if (binOp.getKind() != AffineExprKind::Add) {
|
2018-08-01 07:21:36 +08:00
|
|
|
if (enclosingTightness == BindingStrength::Strong)
|
|
|
|
os << '(';
|
|
|
|
|
2019-01-21 22:59:58 +08:00
|
|
|
// Pretty print multiplication with -1.
|
|
|
|
auto rhsConst = rhsExpr.dyn_cast<AffineConstantExpr>();
|
|
|
|
if (rhsConst && rhsConst.getValue() == -1) {
|
|
|
|
os << "-";
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(lhsExpr, BindingStrength::Strong, printValueName);
|
2019-01-21 22:59:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(lhsExpr, BindingStrength::Strong, printValueName);
|
|
|
|
|
2018-08-01 07:21:36 +08:00
|
|
|
os << binopSpelling;
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(rhsExpr, BindingStrength::Strong, printValueName);
|
2018-08-01 07:21:36 +08:00
|
|
|
|
|
|
|
if (enclosingTightness == BindingStrength::Strong)
|
|
|
|
os << ')';
|
2018-07-21 00:35:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print out special "pretty" forms for add.
|
2018-08-01 07:21:36 +08:00
|
|
|
if (enclosingTightness == BindingStrength::Strong)
|
|
|
|
os << '(';
|
2018-07-21 00:35:47 +08:00
|
|
|
|
|
|
|
// Pretty print addition to a product that has a negative operand as a
|
|
|
|
// subtraction.
|
2018-10-09 04:47:18 +08:00
|
|
|
if (auto rhs = rhsExpr.dyn_cast<AffineBinaryOpExpr>()) {
|
2018-10-10 01:59:27 +08:00
|
|
|
if (rhs.getKind() == AffineExprKind::Mul) {
|
|
|
|
AffineExpr rrhsExpr = rhs.getRHS();
|
2018-10-09 04:47:18 +08:00
|
|
|
if (auto rrhs = rrhsExpr.dyn_cast<AffineConstantExpr>()) {
|
2018-10-10 01:59:27 +08:00
|
|
|
if (rrhs.getValue() == -1) {
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(lhsExpr, BindingStrength::Weak,
|
|
|
|
printValueName);
|
2018-08-01 07:21:36 +08:00
|
|
|
os << " - ";
|
2018-10-19 09:18:04 +08:00
|
|
|
if (rhs.getLHS().getKind() == AffineExprKind::Add) {
|
2019-06-24 22:31:52 +08:00
|
|
|
printAffineExprInternal(rhs.getLHS(), BindingStrength::Strong,
|
2019-06-26 01:29:53 +08:00
|
|
|
printValueName);
|
2018-10-19 09:18:04 +08:00
|
|
|
} else {
|
2019-06-24 22:31:52 +08:00
|
|
|
printAffineExprInternal(rhs.getLHS(), BindingStrength::Weak,
|
2019-06-26 01:29:53 +08:00
|
|
|
printValueName);
|
2018-10-19 09:18:04 +08:00
|
|
|
}
|
2018-08-01 07:21:36 +08:00
|
|
|
|
|
|
|
if (enclosingTightness == BindingStrength::Strong)
|
|
|
|
os << ')';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 01:59:27 +08:00
|
|
|
if (rrhs.getValue() < -1) {
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(lhsExpr, BindingStrength::Weak,
|
|
|
|
printValueName);
|
2018-08-02 13:02:00 +08:00
|
|
|
os << " - ";
|
2019-06-24 22:31:52 +08:00
|
|
|
printAffineExprInternal(rhs.getLHS(), BindingStrength::Strong,
|
2019-06-26 01:29:53 +08:00
|
|
|
printValueName);
|
2018-10-10 01:59:27 +08:00
|
|
|
os << " * " << -rrhs.getValue();
|
2018-08-01 07:21:36 +08:00
|
|
|
if (enclosingTightness == BindingStrength::Strong)
|
|
|
|
os << ')';
|
2018-07-21 00:35:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pretty print addition to a negative number as a subtraction.
|
2019-01-21 22:59:58 +08:00
|
|
|
if (auto rhsConst = rhsExpr.dyn_cast<AffineConstantExpr>()) {
|
|
|
|
if (rhsConst.getValue() < 0) {
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(lhsExpr, BindingStrength::Weak, printValueName);
|
2019-01-21 22:59:58 +08:00
|
|
|
os << " - " << -rhsConst.getValue();
|
2018-08-08 05:24:38 +08:00
|
|
|
if (enclosingTightness == BindingStrength::Strong)
|
|
|
|
os << ')';
|
2018-07-21 00:35:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(lhsExpr, BindingStrength::Weak, printValueName);
|
|
|
|
|
2018-07-21 00:35:47 +08:00
|
|
|
os << " + ";
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExprInternal(rhsExpr, BindingStrength::Weak, printValueName);
|
2018-08-01 07:21:36 +08:00
|
|
|
|
|
|
|
if (enclosingTightness == BindingStrength::Strong)
|
|
|
|
os << ')';
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
|
|
|
|
2018-10-09 04:47:18 +08:00
|
|
|
void ModulePrinter::printAffineConstraint(AffineExpr expr, bool isEq) {
|
2018-08-08 05:24:38 +08:00
|
|
|
printAffineExprInternal(expr, BindingStrength::Weak);
|
|
|
|
isEq ? os << " == 0" : os << " >= 0";
|
|
|
|
}
|
|
|
|
|
2018-10-10 07:39:24 +08:00
|
|
|
void ModulePrinter::printAffineMap(AffineMap map) {
|
2018-07-21 00:35:47 +08:00
|
|
|
// Dimension identifiers.
|
|
|
|
os << '(';
|
2018-10-10 07:39:24 +08:00
|
|
|
for (int i = 0; i < (int)map.getNumDims() - 1; ++i)
|
2018-07-30 05:13:03 +08:00
|
|
|
os << 'd' << i << ", ";
|
2018-10-10 07:39:24 +08:00
|
|
|
if (map.getNumDims() >= 1)
|
|
|
|
os << 'd' << map.getNumDims() - 1;
|
2018-07-30 05:13:03 +08:00
|
|
|
os << ')';
|
2018-07-21 00:35:47 +08:00
|
|
|
|
|
|
|
// Symbolic identifiers.
|
2018-10-10 07:39:24 +08:00
|
|
|
if (map.getNumSymbols() != 0) {
|
2018-07-30 05:13:03 +08:00
|
|
|
os << '[';
|
2018-10-10 07:39:24 +08:00
|
|
|
for (unsigned i = 0; i < map.getNumSymbols() - 1; ++i)
|
2018-07-30 05:13:03 +08:00
|
|
|
os << 's' << i << ", ";
|
2018-10-10 07:39:24 +08:00
|
|
|
if (map.getNumSymbols() >= 1)
|
|
|
|
os << 's' << map.getNumSymbols() - 1;
|
2018-07-30 05:13:03 +08:00
|
|
|
os << ']';
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AffineMap should have at least one result.
|
2018-10-10 07:39:24 +08:00
|
|
|
assert(!map.getResults().empty());
|
2018-07-21 00:35:47 +08:00
|
|
|
// Result affine expressions.
|
|
|
|
os << " -> (";
|
2018-10-10 07:39:24 +08:00
|
|
|
interleaveComma(map.getResults(),
|
2018-10-09 04:47:18 +08:00
|
|
|
[&](AffineExpr expr) { printAffineExpr(expr); });
|
2018-07-30 05:13:03 +08:00
|
|
|
os << ')';
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
|
|
|
|
2018-10-11 00:45:59 +08:00
|
|
|
void ModulePrinter::printIntegerSet(IntegerSet set) {
|
2018-08-08 05:24:38 +08:00
|
|
|
// Dimension identifiers.
|
|
|
|
os << '(';
|
2018-10-11 00:45:59 +08:00
|
|
|
for (unsigned i = 1; i < set.getNumDims(); ++i)
|
2018-08-08 05:24:38 +08:00
|
|
|
os << 'd' << i - 1 << ", ";
|
2018-10-11 00:45:59 +08:00
|
|
|
if (set.getNumDims() >= 1)
|
|
|
|
os << 'd' << set.getNumDims() - 1;
|
2018-08-08 05:24:38 +08:00
|
|
|
os << ')';
|
|
|
|
|
|
|
|
// Symbolic identifiers.
|
2018-10-11 00:45:59 +08:00
|
|
|
if (set.getNumSymbols() != 0) {
|
2018-08-08 05:24:38 +08:00
|
|
|
os << '[';
|
2018-10-11 00:45:59 +08:00
|
|
|
for (unsigned i = 0; i < set.getNumSymbols() - 1; ++i)
|
2018-08-08 05:24:38 +08:00
|
|
|
os << 's' << i << ", ";
|
2018-10-11 00:45:59 +08:00
|
|
|
if (set.getNumSymbols() >= 1)
|
|
|
|
os << 's' << set.getNumSymbols() - 1;
|
2018-08-08 05:24:38 +08:00
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print constraints.
|
|
|
|
os << " : (";
|
2019-05-04 10:48:57 +08:00
|
|
|
int numConstraints = set.getNumConstraints();
|
2018-08-08 05:24:38 +08:00
|
|
|
for (int i = 1; i < numConstraints; ++i) {
|
2018-10-11 00:45:59 +08:00
|
|
|
printAffineConstraint(set.getConstraint(i - 1), set.isEq(i - 1));
|
2018-08-08 05:24:38 +08:00
|
|
|
os << ", ";
|
|
|
|
}
|
|
|
|
if (numConstraints >= 1)
|
2018-10-11 00:45:59 +08:00
|
|
|
printAffineConstraint(set.getConstraint(numConstraints - 1),
|
|
|
|
set.isEq(numConstraints - 1));
|
2018-08-08 05:24:38 +08:00
|
|
|
os << ')';
|
|
|
|
}
|
|
|
|
|
2018-06-24 07:03:42 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Function printing
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-09-19 07:36:26 +08:00
|
|
|
void ModulePrinter::printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
2019-03-02 03:29:01 +08:00
|
|
|
ArrayRef<StringRef> elidedAttrs) {
|
2018-09-19 07:36:26 +08:00
|
|
|
// If there are no attributes, then there is nothing to be done.
|
|
|
|
if (attrs.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Filter out any attributes that shouldn't be included.
|
|
|
|
SmallVector<NamedAttribute, 8> filteredAttrs;
|
|
|
|
for (auto attr : attrs) {
|
|
|
|
// If the caller has requested that this attribute be ignored, then drop it.
|
2019-03-03 14:34:18 +08:00
|
|
|
if (llvm::any_of(elidedAttrs,
|
|
|
|
[&](StringRef elided) { return attr.first.is(elided); }))
|
|
|
|
continue;
|
2018-09-19 07:36:26 +08:00
|
|
|
|
|
|
|
// Otherwise add it to our filteredAttrs list.
|
2019-03-03 14:34:18 +08:00
|
|
|
filteredAttrs.push_back(attr);
|
2018-09-19 07:36:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no attributes left to print after filtering, then we're done.
|
|
|
|
if (filteredAttrs.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Otherwise, print them all out in braces.
|
|
|
|
os << " {";
|
|
|
|
interleaveComma(filteredAttrs, [&](NamedAttribute attr) {
|
2019-04-26 00:56:09 +08:00
|
|
|
os << attr.first;
|
|
|
|
|
|
|
|
// Pretty printing elides the attribute value for unit attributes.
|
|
|
|
if (attr.second.isa<UnitAttr>())
|
|
|
|
return;
|
|
|
|
|
2019-06-26 10:06:06 +08:00
|
|
|
os << " = ";
|
2019-06-27 09:29:25 +08:00
|
|
|
printAttribute(attr.second);
|
2018-09-19 07:36:26 +08:00
|
|
|
});
|
|
|
|
os << '}';
|
|
|
|
}
|
|
|
|
|
2018-07-10 08:42:46 +08:00
|
|
|
namespace {
|
|
|
|
|
2018-07-25 07:07:22 +08:00
|
|
|
// FunctionPrinter contains common functionality for printing
|
2018-07-10 08:42:46 +08:00
|
|
|
// CFG and ML functions.
|
2018-07-25 07:07:22 +08:00
|
|
|
class FunctionPrinter : public ModulePrinter, private OpAsmPrinter {
|
2018-07-10 08:42:46 +08:00
|
|
|
public:
|
2019-07-02 01:29:09 +08:00
|
|
|
FunctionPrinter(Function function, ModulePrinter &other);
|
2018-12-29 03:41:56 +08:00
|
|
|
|
|
|
|
// Prints the function as a whole.
|
|
|
|
void print();
|
|
|
|
|
|
|
|
// Print the function signature.
|
2018-12-30 05:56:57 +08:00
|
|
|
void printFunctionSignature();
|
2018-12-29 03:41:56 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// Methods to print operations.
|
|
|
|
void print(Operation *op);
|
2019-03-27 20:11:58 +08:00
|
|
|
void print(Block *block, bool printBlockArgs = true,
|
|
|
|
bool printBlockTerminator = true);
|
2018-07-10 08:42:46 +08:00
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
void printOperation(Operation *op);
|
2019-05-10 13:45:38 +08:00
|
|
|
void printGenericOp(Operation *op) override;
|
2018-07-25 07:07:22 +08:00
|
|
|
|
|
|
|
// Implement OpAsmPrinter.
|
2019-05-10 13:45:38 +08:00
|
|
|
raw_ostream &getStream() const override { return os; }
|
|
|
|
void printType(Type type) override { ModulePrinter::printType(type); }
|
|
|
|
void printAttribute(Attribute attr) override {
|
|
|
|
ModulePrinter::printAttribute(attr);
|
|
|
|
}
|
|
|
|
void printOperand(Value *value) override { printValueID(value); }
|
2018-08-04 02:12:34 +08:00
|
|
|
|
2018-08-03 07:54:36 +08:00
|
|
|
void printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
2019-05-10 13:45:38 +08:00
|
|
|
ArrayRef<StringRef> elidedAttrs = {}) override {
|
2018-09-19 07:36:26 +08:00
|
|
|
return ModulePrinter::printOptionalAttrDict(attrs, elidedAttrs);
|
|
|
|
};
|
2018-07-10 08:42:46 +08:00
|
|
|
|
2018-08-02 01:43:18 +08:00
|
|
|
enum { nameSentinel = ~0U };
|
|
|
|
|
2019-03-22 08:53:00 +08:00
|
|
|
void printBlockName(Block *block) {
|
2018-12-31 08:22:50 +08:00
|
|
|
auto id = getBlockID(block);
|
|
|
|
if (id != ~0U)
|
|
|
|
os << "^bb" << id;
|
|
|
|
else
|
|
|
|
os << "^INVALIDBLOCK";
|
|
|
|
}
|
2018-08-02 01:43:18 +08:00
|
|
|
|
2019-03-22 08:53:00 +08:00
|
|
|
unsigned getBlockID(Block *block) {
|
2018-12-29 05:07:39 +08:00
|
|
|
auto it = blockIDs.find(block);
|
2018-12-31 08:22:50 +08:00
|
|
|
return it != blockIDs.end() ? it->second : ~0U;
|
2018-07-21 00:28:54 +08:00
|
|
|
}
|
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
void printSuccessorAndUseList(Operation *term, unsigned index) override;
|
2018-07-21 09:41:34 +08:00
|
|
|
|
2019-03-15 01:38:44 +08:00
|
|
|
/// Print a region.
|
2019-03-27 20:11:58 +08:00
|
|
|
void printRegion(Region &blocks, bool printEntryBlockArgs,
|
|
|
|
bool printBlockTerminators) override {
|
2019-01-26 04:48:25 +08:00
|
|
|
os << " {\n";
|
2019-01-27 04:40:12 +08:00
|
|
|
if (!blocks.empty()) {
|
|
|
|
auto *entryBlock = &blocks.front();
|
|
|
|
print(entryBlock,
|
2019-03-27 20:11:58 +08:00
|
|
|
printEntryBlockArgs && entryBlock->getNumArguments() != 0,
|
|
|
|
printBlockTerminators);
|
2019-01-27 04:40:12 +08:00
|
|
|
for (auto &b : llvm::drop_begin(blocks.getBlocks(), 1))
|
|
|
|
print(&b);
|
|
|
|
}
|
2019-01-26 04:48:25 +08:00
|
|
|
os.indent(currentIndent) << "}";
|
|
|
|
}
|
|
|
|
|
2019-06-24 22:31:52 +08:00
|
|
|
void printAffineMapOfSSAIds(AffineMapAttr mapAttr,
|
|
|
|
ArrayRef<Value *> operands) {
|
|
|
|
AffineMap map = mapAttr.getValue();
|
|
|
|
unsigned numDims = map.getNumDims();
|
2019-06-26 01:29:53 +08:00
|
|
|
auto printValueName = [&](unsigned pos, bool isSymbol) {
|
|
|
|
unsigned index = isSymbol ? numDims + pos : pos;
|
|
|
|
assert(index < operands.size());
|
|
|
|
if (isSymbol)
|
|
|
|
os << "symbol(";
|
|
|
|
printValueID(operands[index]);
|
|
|
|
if (isSymbol)
|
|
|
|
os << ')';
|
|
|
|
};
|
|
|
|
|
2019-06-24 22:31:52 +08:00
|
|
|
interleaveComma(map.getResults(), [&](AffineExpr expr) {
|
2019-06-26 01:29:53 +08:00
|
|
|
printAffineExpr(expr, printValueName);
|
2019-06-24 22:31:52 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// Number of spaces used for indenting nested operations.
|
2018-12-29 03:41:56 +08:00
|
|
|
const static unsigned indentWidth = 2;
|
2018-07-31 06:18:10 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
protected:
|
2019-03-24 06:09:06 +08:00
|
|
|
void numberValueID(Value *value);
|
2019-03-22 08:53:00 +08:00
|
|
|
void numberValuesInBlock(Block &block);
|
2019-03-24 06:09:06 +08:00
|
|
|
void printValueID(Value *value, bool printResultNo = true) const;
|
2018-07-21 00:28:54 +08:00
|
|
|
|
|
|
|
private:
|
2019-07-02 01:29:09 +08:00
|
|
|
Function function;
|
2018-12-29 03:41:56 +08:00
|
|
|
|
2018-08-02 01:43:18 +08:00
|
|
|
/// This is the value ID for each SSA value in the current function. If this
|
|
|
|
/// returns ~0, then the valueID has an entry in valueNames.
|
2019-03-24 06:09:06 +08:00
|
|
|
DenseMap<Value *, unsigned> valueIDs;
|
|
|
|
DenseMap<Value *, StringRef> valueNames;
|
2018-08-02 01:43:18 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
/// This is the block ID for each block in the current function.
|
2019-03-22 08:53:00 +08:00
|
|
|
DenseMap<Block *, unsigned> blockIDs;
|
2018-12-29 03:41:56 +08:00
|
|
|
|
2018-08-02 01:43:18 +08:00
|
|
|
/// This keeps track of all of the non-numeric names that are in flight,
|
|
|
|
/// allowing us to check for duplicates.
|
|
|
|
llvm::StringSet<> usedNames;
|
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// This is the current indentation level for nested structures.
|
|
|
|
unsigned currentIndent = 0;
|
|
|
|
|
2018-08-02 01:43:18 +08:00
|
|
|
/// This is the next value ID to assign in numbering.
|
2018-07-21 00:28:54 +08:00
|
|
|
unsigned nextValueID = 0;
|
2019-01-27 04:40:12 +08:00
|
|
|
/// This is the ID to assign to the next region entry block argument.
|
|
|
|
unsigned nextRegionArgumentID = 0;
|
2018-12-29 00:48:09 +08:00
|
|
|
/// This is the next ID to assign to a Function argument.
|
2018-08-02 01:43:18 +08:00
|
|
|
unsigned nextArgumentID = 0;
|
|
|
|
/// This is the next ID to assign when a name conflict is detected.
|
|
|
|
unsigned nextConflictID = 0;
|
2018-12-29 03:41:56 +08:00
|
|
|
/// This is the next block ID to assign in numbering.
|
|
|
|
unsigned nextBlockID = 0;
|
2018-07-10 08:42:46 +08:00
|
|
|
};
|
2018-07-24 02:44:40 +08:00
|
|
|
} // end anonymous namespace
|
2018-07-10 08:42:46 +08:00
|
|
|
|
2019-07-02 01:29:09 +08:00
|
|
|
FunctionPrinter::FunctionPrinter(Function function, ModulePrinter &other)
|
2018-12-29 03:41:56 +08:00
|
|
|
: ModulePrinter(other), function(function) {
|
2018-07-10 08:42:46 +08:00
|
|
|
|
2019-07-02 01:29:09 +08:00
|
|
|
for (auto &block : function)
|
2018-12-29 03:41:56 +08:00
|
|
|
numberValuesInBlock(block);
|
2018-07-10 08:42:46 +08:00
|
|
|
}
|
|
|
|
|
2019-03-15 01:38:44 +08:00
|
|
|
/// Number all of the SSA values in the specified block. Values get numbered
|
|
|
|
/// continuously throughout regions. In particular, we traverse the regions
|
|
|
|
/// held by operations and number values in depth-first pre-order.
|
2019-03-22 08:53:00 +08:00
|
|
|
void FunctionPrinter::numberValuesInBlock(Block &block) {
|
2019-03-28 23:24:38 +08:00
|
|
|
// Each block gets a unique ID, and all of the operations within it get
|
2018-12-29 03:41:56 +08:00
|
|
|
// numbered as well.
|
2018-12-29 05:07:39 +08:00
|
|
|
blockIDs[&block] = nextBlockID++;
|
2018-07-21 00:28:54 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
for (auto *arg : block.getArguments())
|
2018-07-23 06:45:24 +08:00
|
|
|
numberValueID(arg);
|
2018-12-29 03:41:56 +08:00
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
for (auto &op : block) {
|
|
|
|
// We number operation that have results, and we only number the first
|
2018-07-21 00:28:54 +08:00
|
|
|
// result.
|
2019-03-28 23:24:38 +08:00
|
|
|
if (op.getNumResults() != 0)
|
|
|
|
numberValueID(op.getResult(0));
|
|
|
|
for (auto ®ion : op.getRegions())
|
2019-03-22 08:53:00 +08:00
|
|
|
for (auto &block : region)
|
2019-02-04 02:03:46 +08:00
|
|
|
numberValuesInBlock(block);
|
2018-07-21 00:28:54 +08:00
|
|
|
}
|
2018-06-24 07:03:42 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 06:09:06 +08:00
|
|
|
void FunctionPrinter::numberValueID(Value *value) {
|
2018-12-29 03:41:56 +08:00
|
|
|
assert(!valueIDs.count(value) && "Value numbered multiple times");
|
2018-06-24 07:03:42 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
SmallString<32> specialNameBuffer;
|
|
|
|
llvm::raw_svector_ostream specialName(specialNameBuffer);
|
2018-07-23 06:45:24 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// Give constant integers special names.
|
2019-03-27 08:05:09 +08:00
|
|
|
if (auto *op = value->getDefiningOp()) {
|
2019-03-02 08:58:00 +08:00
|
|
|
Attribute cst;
|
2019-03-25 14:26:39 +08:00
|
|
|
if (m_Constant(&cst).match(op)) {
|
2019-03-02 08:58:00 +08:00
|
|
|
Type type = op->getResult(0)->getType();
|
|
|
|
if (auto intCst = cst.dyn_cast<IntegerAttr>()) {
|
|
|
|
if (type.isIndex()) {
|
2019-05-07 01:36:32 +08:00
|
|
|
specialName << 'c' << intCst.getInt();
|
2019-03-02 08:58:00 +08:00
|
|
|
} else if (type.cast<IntegerType>().isInteger(1)) {
|
|
|
|
// i1 constants get special names.
|
|
|
|
specialName << (intCst.getInt() ? "true" : "false");
|
|
|
|
} else {
|
2019-05-07 01:36:32 +08:00
|
|
|
specialName << 'c' << intCst.getInt() << '_' << type;
|
2019-03-02 08:58:00 +08:00
|
|
|
}
|
2019-05-23 04:41:23 +08:00
|
|
|
} else if (type.isa<FunctionType>()) {
|
2018-12-29 03:41:56 +08:00
|
|
|
specialName << 'f';
|
2019-03-02 08:58:00 +08:00
|
|
|
} else {
|
2018-12-29 03:41:56 +08:00
|
|
|
specialName << "cst";
|
2019-03-02 08:58:00 +08:00
|
|
|
}
|
2018-12-29 03:41:56 +08:00
|
|
|
}
|
2018-07-23 06:45:24 +08:00
|
|
|
}
|
2018-07-28 02:10:12 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
if (specialNameBuffer.empty()) {
|
|
|
|
switch (value->getKind()) {
|
|
|
|
case Value::Kind::BlockArgument:
|
2019-01-27 04:40:12 +08:00
|
|
|
// If this is an argument to the function, give it an 'arg' name. If the
|
|
|
|
// argument is to an entry block of an operation region, give it an 'i'
|
|
|
|
// name.
|
|
|
|
if (auto *block = cast<BlockArgument>(value)->getOwner()) {
|
2019-03-15 01:38:44 +08:00
|
|
|
auto *parentRegion = block->getParent();
|
|
|
|
if (parentRegion && block == &parentRegion->front()) {
|
|
|
|
if (parentRegion->getContainingFunction())
|
2018-12-29 03:41:56 +08:00
|
|
|
specialName << "arg" << nextArgumentID++;
|
2019-01-27 04:40:12 +08:00
|
|
|
else
|
|
|
|
specialName << "i" << nextRegionArgumentID++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 03:41:56 +08:00
|
|
|
// Otherwise number it normally.
|
|
|
|
valueIDs[value] = nextValueID++;
|
|
|
|
return;
|
2019-03-27 08:05:09 +08:00
|
|
|
case Value::Kind::OpResult:
|
2018-12-29 03:41:56 +08:00
|
|
|
// This is an uninteresting result, give it a boring number and be
|
|
|
|
// done with it.
|
|
|
|
valueIDs[value] = nextValueID++;
|
|
|
|
return;
|
|
|
|
}
|
2018-07-28 02:10:12 +08:00
|
|
|
}
|
2018-06-24 07:03:42 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// Ok, this value had an interesting name. Remember it with a sentinel.
|
|
|
|
valueIDs[value] = nameSentinel;
|
2018-06-24 07:03:42 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// Remember that we've used this name, checking to see if we had a conflict.
|
|
|
|
auto insertRes = usedNames.insert(specialName.str());
|
|
|
|
if (insertRes.second) {
|
|
|
|
// If this is the first use of the name, then we're successful!
|
|
|
|
valueNames[value] = insertRes.first->first();
|
2018-09-07 00:17:08 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-07-23 23:42:19 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// Otherwise, we had a conflict - probe until we find a unique name. This
|
|
|
|
// is guaranteed to terminate (and usually in a single iteration) because it
|
|
|
|
// generates new names by incrementing nextConflictID.
|
|
|
|
while (1) {
|
|
|
|
std::string probeName =
|
|
|
|
specialName.str().str() + "_" + llvm::utostr(nextConflictID++);
|
|
|
|
insertRes = usedNames.insert(probeName);
|
|
|
|
if (insertRes.second) {
|
|
|
|
// If this is the first use of the name, then we're successful!
|
|
|
|
valueNames[value] = insertRes.first->first();
|
|
|
|
return;
|
|
|
|
}
|
2018-11-16 01:56:06 +08:00
|
|
|
}
|
2018-07-27 09:09:20 +08:00
|
|
|
}
|
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
void FunctionPrinter::print() {
|
2018-12-30 05:56:57 +08:00
|
|
|
printFunctionSignature();
|
2018-07-27 09:09:20 +08:00
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// Print out function attributes, if present.
|
2019-07-02 01:29:09 +08:00
|
|
|
auto attrs = function.getAttrs();
|
2018-12-29 03:41:56 +08:00
|
|
|
if (!attrs.empty()) {
|
|
|
|
os << "\n attributes ";
|
|
|
|
printOptionalAttrDict(attrs);
|
|
|
|
}
|
2018-07-04 08:51:28 +08:00
|
|
|
|
2019-01-24 05:11:23 +08:00
|
|
|
// Print the trailing location.
|
2019-07-02 01:29:09 +08:00
|
|
|
printTrailingLocation(function.getLoc());
|
2019-01-24 05:11:23 +08:00
|
|
|
|
2019-07-02 01:29:09 +08:00
|
|
|
if (!function.empty()) {
|
|
|
|
printRegion(function.getBody(), /*printEntryBlockArgs=*/false,
|
2019-03-27 20:11:58 +08:00
|
|
|
/*printBlockTerminators=*/true);
|
2019-01-27 04:40:12 +08:00
|
|
|
os << "\n";
|
2018-12-29 03:41:56 +08:00
|
|
|
}
|
|
|
|
os << '\n';
|
2018-07-04 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 05:56:57 +08:00
|
|
|
void FunctionPrinter::printFunctionSignature() {
|
2019-07-02 01:29:09 +08:00
|
|
|
os << "func @" << function.getName() << '(';
|
2018-12-30 05:56:57 +08:00
|
|
|
|
2019-07-02 01:29:09 +08:00
|
|
|
auto fnType = function.getType();
|
|
|
|
bool isExternal = function.isExternal();
|
|
|
|
for (unsigned i = 0, e = function.getNumArguments(); i != e; ++i) {
|
2019-03-01 01:30:52 +08:00
|
|
|
if (i > 0)
|
|
|
|
os << ", ";
|
2018-12-30 05:56:57 +08:00
|
|
|
|
2019-03-01 01:30:52 +08:00
|
|
|
// If this is an external function, don't print argument labels.
|
|
|
|
if (!isExternal) {
|
2019-07-02 01:29:09 +08:00
|
|
|
printOperand(function.getArgument(i));
|
2018-12-30 05:56:57 +08:00
|
|
|
os << ": ";
|
|
|
|
}
|
2019-03-01 01:30:52 +08:00
|
|
|
|
|
|
|
printType(fnType.getInput(i));
|
|
|
|
|
|
|
|
// Print the attributes for this argument.
|
2019-07-02 01:29:09 +08:00
|
|
|
printOptionalAttrDict(function.getArgAttrs(i));
|
2018-12-30 05:56:57 +08:00
|
|
|
}
|
2018-12-29 03:41:56 +08:00
|
|
|
os << ')';
|
|
|
|
|
2018-12-30 05:56:57 +08:00
|
|
|
switch (fnType.getResults().size()) {
|
|
|
|
case 0:
|
|
|
|
break;
|
2019-02-06 03:47:02 +08:00
|
|
|
case 1: {
|
2018-12-30 05:56:57 +08:00
|
|
|
os << " -> ";
|
2019-02-06 03:47:02 +08:00
|
|
|
auto resultType = fnType.getResults()[0];
|
|
|
|
bool resultIsFunc = resultType.isa<FunctionType>();
|
|
|
|
if (resultIsFunc)
|
|
|
|
os << '(';
|
|
|
|
printType(resultType);
|
|
|
|
if (resultIsFunc)
|
|
|
|
os << ')';
|
2018-12-30 05:56:57 +08:00
|
|
|
break;
|
2019-02-06 03:47:02 +08:00
|
|
|
}
|
2018-12-30 05:56:57 +08:00
|
|
|
default:
|
|
|
|
os << " -> (";
|
|
|
|
interleaveComma(fnType.getResults(),
|
|
|
|
[&](Type eltType) { printType(eltType); });
|
|
|
|
os << ')';
|
|
|
|
break;
|
|
|
|
}
|
2018-08-07 02:54:39 +08:00
|
|
|
}
|
|
|
|
|
2019-03-27 20:11:58 +08:00
|
|
|
void FunctionPrinter::print(Block *block, bool printBlockArgs,
|
|
|
|
bool printBlockTerminator) {
|
2019-01-29 13:23:53 +08:00
|
|
|
// Print the block label and argument list if requested.
|
2019-01-27 04:40:12 +08:00
|
|
|
if (printBlockArgs) {
|
2018-12-29 03:41:56 +08:00
|
|
|
os.indent(currentIndent);
|
2018-12-29 05:07:39 +08:00
|
|
|
printBlockName(block);
|
2018-12-29 03:41:56 +08:00
|
|
|
|
|
|
|
// Print the argument list if non-empty.
|
|
|
|
if (!block->args_empty()) {
|
|
|
|
os << '(';
|
2019-03-22 08:53:00 +08:00
|
|
|
interleaveComma(block->getArguments(), [&](BlockArgument *arg) {
|
2018-12-29 03:41:56 +08:00
|
|
|
printValueID(arg);
|
|
|
|
os << ": ";
|
|
|
|
printType(arg->getType());
|
|
|
|
});
|
|
|
|
os << ')';
|
|
|
|
}
|
|
|
|
os << ':';
|
|
|
|
|
|
|
|
// Print out some context information about the predecessors of this block.
|
|
|
|
if (!block->getFunction()) {
|
|
|
|
os << "\t// block is not in a function!";
|
|
|
|
} else if (block->hasNoPredecessors()) {
|
2018-12-30 05:56:57 +08:00
|
|
|
os << "\t// no predecessors";
|
2018-12-29 03:41:56 +08:00
|
|
|
} else if (auto *pred = block->getSinglePredecessor()) {
|
|
|
|
os << "\t// pred: ";
|
2018-12-29 05:07:39 +08:00
|
|
|
printBlockName(pred);
|
2018-12-29 03:41:56 +08:00
|
|
|
} else {
|
|
|
|
// We want to print the predecessors in increasing numeric order, not in
|
|
|
|
// whatever order the use-list is in, so gather and sort them.
|
2019-03-22 08:53:00 +08:00
|
|
|
SmallVector<std::pair<unsigned, Block *>, 4> predIDs;
|
2018-12-29 03:41:56 +08:00
|
|
|
for (auto *pred : block->getPredecessors())
|
2018-12-31 08:22:50 +08:00
|
|
|
predIDs.push_back({getBlockID(pred), pred});
|
2018-12-29 03:41:56 +08:00
|
|
|
llvm::array_pod_sort(predIDs.begin(), predIDs.end());
|
|
|
|
|
|
|
|
os << "\t// " << predIDs.size() << " preds: ";
|
|
|
|
|
2019-03-22 08:53:00 +08:00
|
|
|
interleaveComma(predIDs, [&](std::pair<unsigned, Block *> pred) {
|
2018-12-31 08:22:50 +08:00
|
|
|
printBlockName(pred.second);
|
|
|
|
});
|
2018-12-29 03:41:56 +08:00
|
|
|
}
|
|
|
|
os << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
currentIndent += indentWidth;
|
2019-03-27 20:11:58 +08:00
|
|
|
auto range = llvm::make_range(
|
|
|
|
block->getOperations().begin(),
|
|
|
|
std::prev(block->getOperations().end(), printBlockTerminator ? 0 : 1));
|
2019-03-28 23:24:38 +08:00
|
|
|
for (auto &op : range) {
|
|
|
|
print(&op);
|
2018-12-29 03:41:56 +08:00
|
|
|
os << '\n';
|
2018-07-15 15:06:54 +08:00
|
|
|
}
|
2018-12-29 03:41:56 +08:00
|
|
|
currentIndent -= indentWidth;
|
2018-07-14 04:03:13 +08:00
|
|
|
}
|
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
void FunctionPrinter::print(Operation *op) {
|
2018-12-29 03:41:56 +08:00
|
|
|
os.indent(currentIndent);
|
2019-03-28 23:24:38 +08:00
|
|
|
printOperation(op);
|
|
|
|
printTrailingLocation(op->getLoc());
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
2018-07-04 08:51:28 +08:00
|
|
|
|
2019-03-24 06:09:06 +08:00
|
|
|
void FunctionPrinter::printValueID(Value *value, bool printResultNo) const {
|
2018-12-29 03:41:56 +08:00
|
|
|
int resultNo = -1;
|
|
|
|
auto lookupValue = value;
|
|
|
|
|
2019-03-28 23:24:38 +08:00
|
|
|
// If this is a reference to the result of a multi-result operation or
|
|
|
|
// operation, print out the # identifier and make sure to map our lookup
|
|
|
|
// to the first result of the operation.
|
2019-03-27 08:05:09 +08:00
|
|
|
if (auto *result = dyn_cast<OpResult>(value)) {
|
2018-12-29 03:41:56 +08:00
|
|
|
if (result->getOwner()->getNumResults() != 1) {
|
|
|
|
resultNo = result->getResultNumber();
|
|
|
|
lookupValue = result->getOwner()->getResult(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = valueIDs.find(lookupValue);
|
|
|
|
if (it == valueIDs.end()) {
|
|
|
|
os << "<<INVALID SSA VALUE>>";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
os << '%';
|
|
|
|
if (it->second != nameSentinel) {
|
|
|
|
os << it->second;
|
|
|
|
} else {
|
|
|
|
auto nameIt = valueNames.find(lookupValue);
|
|
|
|
assert(nameIt != valueNames.end() && "Didn't have a name entry?");
|
|
|
|
os << nameIt->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resultNo != -1 && printResultNo)
|
|
|
|
os << '#' << resultNo;
|
|
|
|
}
|
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
void FunctionPrinter::printOperation(Operation *op) {
|
2019-03-29 05:58:52 +08:00
|
|
|
if (size_t numResults = op->getNumResults()) {
|
2018-12-29 03:41:56 +08:00
|
|
|
printValueID(op->getResult(0), /*printResultNo=*/false);
|
2019-03-29 05:58:52 +08:00
|
|
|
if (numResults > 1)
|
|
|
|
os << ':' << numResults;
|
2018-12-29 03:41:56 +08:00
|
|
|
os << " = ";
|
|
|
|
}
|
|
|
|
|
2019-02-05 05:01:06 +08:00
|
|
|
if (printGenericOpForm)
|
|
|
|
return printGenericOp(op);
|
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// Check to see if this is a known operation. If so, use the registered
|
|
|
|
// custom printer hook.
|
|
|
|
if (auto *opInfo = op->getAbstractOperation()) {
|
2019-03-25 14:26:39 +08:00
|
|
|
opInfo->printAssembly(op, this);
|
2018-12-29 03:41:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-24 03:26:56 +08:00
|
|
|
// Otherwise print with the generic assembly form.
|
|
|
|
printGenericOp(op);
|
2018-12-29 03:41:56 +08:00
|
|
|
}
|
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
void FunctionPrinter::printGenericOp(Operation *op) {
|
2018-12-29 03:41:56 +08:00
|
|
|
os << '"';
|
|
|
|
printEscapedString(op->getName().getStringRef(), os);
|
|
|
|
os << "\"(";
|
|
|
|
|
2019-01-10 04:28:30 +08:00
|
|
|
// Get the list of operands that are not successor operands.
|
|
|
|
unsigned totalNumSuccessorOperands = 0;
|
|
|
|
unsigned numSuccessors = op->getNumSuccessors();
|
|
|
|
for (unsigned i = 0; i < numSuccessors; ++i)
|
|
|
|
totalNumSuccessorOperands += op->getNumSuccessorOperands(i);
|
|
|
|
unsigned numProperOperands = op->getNumOperands() - totalNumSuccessorOperands;
|
2019-03-24 06:09:06 +08:00
|
|
|
SmallVector<Value *, 8> properOperands(
|
2019-01-10 04:28:30 +08:00
|
|
|
op->operand_begin(), std::next(op->operand_begin(), numProperOperands));
|
|
|
|
|
2019-03-24 06:09:06 +08:00
|
|
|
interleaveComma(properOperands, [&](Value *value) { printValueID(value); });
|
2018-12-29 03:41:56 +08:00
|
|
|
|
|
|
|
os << ')';
|
2019-01-10 04:28:30 +08:00
|
|
|
|
|
|
|
// For terminators, print the list of successors and their operands.
|
2019-02-09 01:52:26 +08:00
|
|
|
if (numSuccessors != 0) {
|
2019-01-10 04:28:30 +08:00
|
|
|
os << '[';
|
|
|
|
for (unsigned i = 0; i < numSuccessors; ++i) {
|
|
|
|
if (i != 0)
|
|
|
|
os << ", ";
|
|
|
|
printSuccessorAndUseList(op, i);
|
|
|
|
}
|
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
|
2019-05-06 16:40:13 +08:00
|
|
|
// Print regions.
|
|
|
|
if (op->getNumRegions() != 0) {
|
|
|
|
os << " (";
|
|
|
|
interleaveComma(op->getRegions(), [&](Region ®ion) {
|
|
|
|
printRegion(region, /*printEntryBlockArgs=*/true,
|
|
|
|
/*printBlockTerminators=*/true);
|
|
|
|
});
|
|
|
|
os << ')';
|
|
|
|
}
|
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
auto attrs = op->getAttrs();
|
|
|
|
printOptionalAttrDict(attrs);
|
|
|
|
|
|
|
|
// Print the type signature of the operation.
|
2019-06-18 06:31:53 +08:00
|
|
|
os << " : ";
|
|
|
|
printFunctionalType(op);
|
2018-12-29 03:41:56 +08:00
|
|
|
}
|
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
void FunctionPrinter::printSuccessorAndUseList(Operation *term,
|
2018-12-29 03:41:56 +08:00
|
|
|
unsigned index) {
|
2018-12-29 05:07:39 +08:00
|
|
|
printBlockName(term->getSuccessor(index));
|
2018-12-29 03:41:56 +08:00
|
|
|
|
|
|
|
auto succOperands = term->getSuccessorOperands(index);
|
|
|
|
if (succOperands.begin() == succOperands.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
os << '(';
|
|
|
|
interleaveComma(succOperands,
|
2019-03-24 06:09:06 +08:00
|
|
|
[this](Value *operand) { printValueID(operand); });
|
2018-12-29 03:41:56 +08:00
|
|
|
os << " : ";
|
2019-03-24 06:09:06 +08:00
|
|
|
interleaveComma(succOperands,
|
|
|
|
[this](Value *operand) { printType(operand->getType()); });
|
2018-12-29 03:41:56 +08:00
|
|
|
os << ')';
|
2018-07-04 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2018-12-29 03:41:56 +08:00
|
|
|
// Prints function with initialized module state.
|
2019-07-02 01:29:09 +08:00
|
|
|
void ModulePrinter::print(Function fn) { FunctionPrinter(fn, *this).print(); }
|
2018-07-18 07:56:54 +08:00
|
|
|
|
2018-07-04 08:51:28 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// print and dump methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
2018-06-29 11:45:33 +08:00
|
|
|
|
2018-07-19 07:29:21 +08:00
|
|
|
void Attribute::print(raw_ostream &os) const {
|
2018-07-21 00:35:47 +08:00
|
|
|
ModuleState state(/*no context is known*/ nullptr);
|
2019-06-27 09:29:25 +08:00
|
|
|
ModulePrinter(os, state).printAttribute(*this);
|
2018-07-19 07:29:21 +08:00
|
|
|
}
|
|
|
|
|
2019-04-17 07:47:41 +08:00
|
|
|
void Attribute::dump() const {
|
|
|
|
print(llvm::errs());
|
|
|
|
llvm::errs() << "\n";
|
|
|
|
}
|
2018-07-19 07:29:21 +08:00
|
|
|
|
2019-05-15 22:54:28 +08:00
|
|
|
void Type::print(raw_ostream &os) {
|
2018-07-21 00:35:47 +08:00
|
|
|
ModuleState state(getContext());
|
2018-10-31 05:59:22 +08:00
|
|
|
ModulePrinter(os, state).printType(*this);
|
2018-07-18 07:56:54 +08:00
|
|
|
}
|
|
|
|
|
2019-05-15 22:54:28 +08:00
|
|
|
void Type::dump() { print(llvm::errs()); }
|
2018-07-18 07:56:54 +08:00
|
|
|
|
2018-10-10 07:39:24 +08:00
|
|
|
void AffineMap::dump() const {
|
2018-07-17 00:45:22 +08:00
|
|
|
print(llvm::errs());
|
|
|
|
llvm::errs() << "\n";
|
|
|
|
}
|
2018-07-10 00:00:25 +08:00
|
|
|
|
2018-10-11 00:45:59 +08:00
|
|
|
void IntegerSet::dump() const {
|
2018-08-08 05:24:38 +08:00
|
|
|
print(llvm::errs());
|
|
|
|
llvm::errs() << "\n";
|
|
|
|
}
|
|
|
|
|
2018-10-10 01:59:27 +08:00
|
|
|
void AffineExpr::print(raw_ostream &os) const {
|
2019-01-08 09:34:26 +08:00
|
|
|
if (expr == nullptr) {
|
|
|
|
os << "null affine expr";
|
|
|
|
return;
|
|
|
|
}
|
2018-10-22 10:49:31 +08:00
|
|
|
ModuleState state(getContext());
|
2018-10-10 01:59:27 +08:00
|
|
|
ModulePrinter(os, state).printAffineExpr(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AffineExpr::dump() const {
|
|
|
|
print(llvm::errs());
|
|
|
|
llvm::errs() << "\n";
|
2018-06-30 09:09:29 +08:00
|
|
|
}
|
|
|
|
|
2018-10-10 07:39:24 +08:00
|
|
|
void AffineMap::print(raw_ostream &os) const {
|
2019-01-08 09:34:26 +08:00
|
|
|
if (map == nullptr) {
|
|
|
|
os << "null affine map";
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 02:47:10 +08:00
|
|
|
ModuleState state(getContext());
|
2018-10-10 07:39:24 +08:00
|
|
|
ModulePrinter(os, state).printAffineMap(*this);
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
2018-07-12 12:31:07 +08:00
|
|
|
|
2018-10-11 00:45:59 +08:00
|
|
|
void IntegerSet::print(raw_ostream &os) const {
|
2018-08-08 05:24:38 +08:00
|
|
|
ModuleState state(/*no context is known*/ nullptr);
|
2018-10-11 00:45:59 +08:00
|
|
|
ModulePrinter(os, state).printIntegerSet(*this);
|
2018-08-08 05:24:38 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 06:09:06 +08:00
|
|
|
void Value::print(raw_ostream &os) {
|
2018-08-03 08:16:58 +08:00
|
|
|
switch (getKind()) {
|
2018-12-28 06:35:10 +08:00
|
|
|
case Value::Kind::BlockArgument:
|
2018-08-03 08:16:58 +08:00
|
|
|
// TODO: Improve this.
|
2018-12-25 10:01:01 +08:00
|
|
|
os << "<block argument>\n";
|
2018-08-03 08:16:58 +08:00
|
|
|
return;
|
2019-03-27 08:05:09 +08:00
|
|
|
case Value::Kind::OpResult:
|
|
|
|
return getDefiningOp()->print(os);
|
2018-08-03 08:16:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 06:09:06 +08:00
|
|
|
void Value::dump() { print(llvm::errs()); }
|
2018-08-03 08:16:58 +08:00
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
void Operation::print(raw_ostream &os) {
|
2019-07-02 01:29:09 +08:00
|
|
|
auto function = getFunction();
|
2018-12-28 03:07:34 +08:00
|
|
|
if (!function) {
|
2018-08-04 02:12:34 +08:00
|
|
|
os << "<<UNLINKED INSTRUCTION>>\n";
|
|
|
|
return;
|
|
|
|
}
|
2018-12-29 03:41:56 +08:00
|
|
|
|
2019-07-02 01:29:09 +08:00
|
|
|
ModuleState state(function.getContext());
|
2018-12-29 03:41:56 +08:00
|
|
|
ModulePrinter modulePrinter(os, state);
|
|
|
|
FunctionPrinter(function, modulePrinter).print(this);
|
2018-07-21 00:35:47 +08:00
|
|
|
}
|
2018-07-12 12:31:07 +08:00
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
void Operation::dump() {
|
2018-07-21 00:35:47 +08:00
|
|
|
print(llvm::errs());
|
|
|
|
llvm::errs() << "\n";
|
2018-06-30 09:09:29 +08:00
|
|
|
}
|
|
|
|
|
2019-03-22 08:53:00 +08:00
|
|
|
void Block::print(raw_ostream &os) {
|
2019-07-02 01:29:09 +08:00
|
|
|
auto function = getFunction();
|
2018-12-28 03:07:34 +08:00
|
|
|
if (!function) {
|
2018-08-04 02:12:34 +08:00
|
|
|
os << "<<UNLINKED BLOCK>>\n";
|
|
|
|
return;
|
|
|
|
}
|
2018-12-28 03:07:34 +08:00
|
|
|
|
2019-07-02 01:29:09 +08:00
|
|
|
ModuleState state(function.getContext());
|
2018-12-29 03:41:56 +08:00
|
|
|
ModulePrinter modulePrinter(os, state);
|
|
|
|
FunctionPrinter(function, modulePrinter).print(this);
|
2018-06-24 07:03:42 +08:00
|
|
|
}
|
|
|
|
|
2019-03-22 08:53:00 +08:00
|
|
|
void Block::dump() { print(llvm::errs()); }
|
2018-06-24 07:03:42 +08:00
|
|
|
|
2018-12-29 13:24:30 +08:00
|
|
|
/// Print out the name of the block without printing its body.
|
2018-12-29 05:07:39 +08:00
|
|
|
void Block::printAsOperand(raw_ostream &os, bool printType) {
|
2018-09-22 05:40:36 +08:00
|
|
|
if (!getFunction()) {
|
|
|
|
os << "<<UNLINKED BLOCK>>\n";
|
|
|
|
return;
|
|
|
|
}
|
2019-07-02 01:29:09 +08:00
|
|
|
ModuleState state(getFunction().getContext());
|
2018-09-22 05:40:36 +08:00
|
|
|
ModulePrinter modulePrinter(os, state);
|
2018-12-29 05:07:39 +08:00
|
|
|
FunctionPrinter(getFunction(), modulePrinter).printBlockName(this);
|
2018-09-22 05:40:36 +08:00
|
|
|
}
|
|
|
|
|
2019-03-22 02:39:22 +08:00
|
|
|
void Function::print(raw_ostream &os) {
|
2018-07-21 00:35:47 +08:00
|
|
|
ModuleState state(getContext());
|
2019-07-02 01:29:09 +08:00
|
|
|
ModulePrinter(os, state).print(*this);
|
2018-06-24 07:03:42 +08:00
|
|
|
}
|
|
|
|
|
2019-03-22 02:39:22 +08:00
|
|
|
void Function::dump() { print(llvm::errs()); }
|
2018-07-19 01:16:05 +08:00
|
|
|
|
2019-03-21 12:14:59 +08:00
|
|
|
void Module::print(raw_ostream &os) {
|
2018-07-21 00:35:47 +08:00
|
|
|
ModuleState state(getContext());
|
2019-07-03 01:49:17 +08:00
|
|
|
state.initialize(*this);
|
|
|
|
ModulePrinter(os, state).print(*this);
|
2018-06-24 07:03:42 +08:00
|
|
|
}
|
|
|
|
|
2019-03-21 12:14:59 +08:00
|
|
|
void Module::dump() { print(llvm::errs()); }
|