diff --git a/mlir/include/mlir/Support/LLVM.h b/mlir/include/mlir/Support/LLVM.h index 63225f132940..d3f3cd519682 100644 --- a/mlir/include/mlir/Support/LLVM.h +++ b/mlir/include/mlir/Support/LLVM.h @@ -29,69 +29,68 @@ // We include these two headers because they cannot be practically forward // declared, and are effectively language features. -#include "llvm/Support/Casting.h" #include "llvm/ADT/None.h" +#include "llvm/Support/Casting.h" // Forward declarations. namespace llvm { - // Containers. - class StringRef; - class StringLiteral; - class Twine; - template class SmallPtrSetImpl; - template class SmallPtrSet; - template class SmallVectorImpl; - template class SmallVector; - template class SmallString; - template class ArrayRef; - template class MutableArrayRef; - template class TinyPtrVector; - template class Optional; - template class PointerUnion; - namespace detail { - template struct DenseMapPair; - } - template struct DenseMapInfo; - template - class DenseMap; +// Containers. +class StringRef; +class StringLiteral; +class Twine; +template class SmallPtrSetImpl; +template class SmallPtrSet; +template class SmallVectorImpl; +template class SmallVector; +template class SmallString; +template class ArrayRef; +template class MutableArrayRef; +template class TinyPtrVector; +template class Optional; +template class PointerUnion; +namespace detail { +template struct DenseMapPair; +} +template struct DenseMapInfo; +template +class DenseMap; - // Other common classes. - class raw_ostream; - class APInt; - class APFloat; +// Other common classes. +class raw_ostream; +class APInt; +class APFloat; } // end namespace llvm - namespace mlir { - // Casting operators. - using llvm::isa; - using llvm::cast; - using llvm::dyn_cast; - using llvm::dyn_cast_or_null; - using llvm::cast_or_null; +// Casting operators. +using llvm::cast; +using llvm::cast_or_null; +using llvm::dyn_cast; +using llvm::dyn_cast_or_null; +using llvm::isa; - // Containers. - using llvm::None; - using llvm::Optional; - using llvm::SmallPtrSetImpl; - using llvm::SmallPtrSet; - using llvm::SmallString; - using llvm::StringRef; - using llvm::StringLiteral; - using llvm::Twine; - using llvm::SmallVectorImpl; - using llvm::SmallVector; - using llvm::ArrayRef; - using llvm::MutableArrayRef; - using llvm::TinyPtrVector; - using llvm::PointerUnion; - using llvm::DenseMap; +// Containers. +using llvm::ArrayRef; +using llvm::DenseMap; +using llvm::MutableArrayRef; +using llvm::None; +using llvm::Optional; +using llvm::PointerUnion; +using llvm::SmallPtrSet; +using llvm::SmallPtrSetImpl; +using llvm::SmallString; +using llvm::SmallVector; +using llvm::SmallVectorImpl; +using llvm::StringLiteral; +using llvm::StringRef; +using llvm::TinyPtrVector; +using llvm::Twine; - // Other common classes. - using llvm::raw_ostream; - using llvm::APInt; - using llvm::APFloat; - using llvm::NoneType; -} // end namespace swift +// Other common classes. +using llvm::APFloat; +using llvm::APInt; +using llvm::NoneType; +using llvm::raw_ostream; +} // namespace mlir #endif // MLIR_SUPPORT_LLVM_H diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 64b5a2c5026d..55cc98ce34cd 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -86,8 +86,7 @@ private: DenseMap affineMapIds; int nextAffineMapId = 0; }; -} // end anonymous namespace - +} // end anonymous namespace // TODO Support visiting other types/instructions when implemented. void ModuleState::visitType(const Type *type) { @@ -235,7 +234,8 @@ void ModulePrinter::print(const Module *module) { mapAndId.first->print(os); os << '\n'; } - for (auto *fn : module->functionList) print(fn); + for (auto *fn : module->functionList) + print(fn); } void ModulePrinter::print(const Attribute *attr) const { @@ -308,7 +308,8 @@ void ModulePrinter::print(const Type *type) const { case Type::Kind::Vector: { auto *v = cast(type); os << "vector<"; - for (auto dim : v->getShape()) os << dim << 'x'; + for (auto dim : v->getShape()) + os << dim << 'x'; os << *v->getElementType() << '>'; return; } @@ -549,7 +550,7 @@ private: DenseMap valueIDs; unsigned nextValueID = 0; }; -} // end anonymous namespace +} // end anonymous namespace void FunctionState::printOperation(const Operation *op) { os << " "; @@ -632,7 +633,7 @@ private: void numberValuesInBlock(const BasicBlock *block); }; -} // end anonymous namespace +} // end anonymous namespace CFGFunctionPrinter::CFGFunctionPrinter(const CFGFunction *function, const ModulePrinter &other) @@ -665,7 +666,8 @@ void CFGFunctionPrinter::print() { printFunctionSignature(getFunction()); os << " {\n"; - for (auto &block : *function) print(&block); + for (auto &block : *function) + print(&block); os << "}\n\n"; } @@ -768,7 +770,7 @@ private: const MLFunction *function; int numSpaces; }; -} // end anonymous namespace +} // end anonymous namespace MLFunctionPrinter::MLFunctionPrinter(const MLFunction *function, const ModulePrinter &other) @@ -843,9 +845,7 @@ void Attribute::print(raw_ostream &os) const { ModulePrinter(os, state).print(this); } -void Attribute::dump() const { - print(llvm::errs()); -} +void Attribute::dump() const { print(llvm::errs()); } void Type::print(raw_ostream &os) const { ModuleState state(getContext()); diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index 8d2de1097613..a6086e5f8f38 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -33,16 +33,16 @@ using namespace mlir; using namespace llvm; namespace { -struct FunctionTypeKeyInfo : DenseMapInfo { +struct FunctionTypeKeyInfo : DenseMapInfo { // Functions are uniqued based on their inputs and results. - using KeyTy = std::pair, ArrayRef>; - using DenseMapInfo::getHashValue; - using DenseMapInfo::isEqual; + using KeyTy = std::pair, ArrayRef>; + using DenseMapInfo::getHashValue; + using DenseMapInfo::isEqual; static unsigned getHashValue(KeyTy key) { - return hash_combine(hash_combine_range(key.first.begin(), key.first.end()), - hash_combine_range(key.second.begin(), - key.second.end())); + return hash_combine( + hash_combine_range(key.first.begin(), key.first.end()), + hash_combine_range(key.second.begin(), key.second.end())); } static bool isEqual(const KeyTy &lhs, const FunctionType *rhs) { @@ -75,16 +75,16 @@ struct AffineMapKeyInfo : DenseMapInfo { } }; -struct VectorTypeKeyInfo : DenseMapInfo { +struct VectorTypeKeyInfo : DenseMapInfo { // Vectors are uniqued based on their element type and shape. - using KeyTy = std::pair>; - using DenseMapInfo::getHashValue; - using DenseMapInfo::isEqual; + using KeyTy = std::pair>; + using DenseMapInfo::getHashValue; + using DenseMapInfo::isEqual; static unsigned getHashValue(KeyTy key) { - return hash_combine(DenseMapInfo::getHashValue(key.first), - hash_combine_range(key.second.begin(), - key.second.end())); + return hash_combine( + DenseMapInfo::getHashValue(key.first), + hash_combine_range(key.second.begin(), key.second.end())); } static bool isEqual(const KeyTy &lhs, const VectorType *rhs) { @@ -94,16 +94,16 @@ struct VectorTypeKeyInfo : DenseMapInfo { } }; -struct RankedTensorTypeKeyInfo : DenseMapInfo { +struct RankedTensorTypeKeyInfo : DenseMapInfo { // Ranked tensors are uniqued based on their element type and shape. - using KeyTy = std::pair>; - using DenseMapInfo::getHashValue; - using DenseMapInfo::isEqual; + using KeyTy = std::pair>; + using DenseMapInfo::getHashValue; + using DenseMapInfo::isEqual; static unsigned getHashValue(KeyTy key) { - return hash_combine(DenseMapInfo::getHashValue(key.first), - hash_combine_range(key.second.begin(), - key.second.end())); + return hash_combine( + DenseMapInfo::getHashValue(key.first), + hash_combine_range(key.second.begin(), key.second.end())); } static bool isEqual(const KeyTy &lhs, const RankedTensorType *rhs) { @@ -113,17 +113,17 @@ struct RankedTensorTypeKeyInfo : DenseMapInfo { } }; -struct MemRefTypeKeyInfo : DenseMapInfo { +struct MemRefTypeKeyInfo : DenseMapInfo { // MemRefs are uniqued based on their element type, shape, affine map // composition, and memory space. - using KeyTy = std::tuple, ArrayRef, - unsigned>; - using DenseMapInfo::getHashValue; - using DenseMapInfo::isEqual; + using KeyTy = + std::tuple, ArrayRef, unsigned>; + using DenseMapInfo::getHashValue; + using DenseMapInfo::isEqual; static unsigned getHashValue(KeyTy key) { return hash_combine( - DenseMapInfo::getHashValue(std::get<0>(key)), + DenseMapInfo::getHashValue(std::get<0>(key)), hash_combine_range(std::get<1>(key).begin(), std::get<1>(key).end()), hash_combine_range(std::get<2>(key).begin(), std::get<2>(key).end()), std::get<3>(key)); @@ -137,11 +137,11 @@ struct MemRefTypeKeyInfo : DenseMapInfo { } }; -struct ArrayAttrKeyInfo : DenseMapInfo { +struct ArrayAttrKeyInfo : DenseMapInfo { // Array attributes are uniqued based on their elements. - using KeyTy = ArrayRef; - using DenseMapInfo::getHashValue; - using DenseMapInfo::isEqual; + using KeyTy = ArrayRef; + using DenseMapInfo::getHashValue; + using DenseMapInfo::isEqual; static unsigned getHashValue(KeyTy key) { return hash_combine_range(key.begin(), key.end()); @@ -173,7 +173,6 @@ struct AttributeListKeyInfo : DenseMapInfo { } // end anonymous namespace. - namespace mlir { /// This is the implementation of the MLIRContext class, using the pImpl idiom. /// This class is completely private to this file, so everything is public. @@ -186,10 +185,11 @@ public: OperationSet operationSet; /// These are identifiers uniqued into this MLIRContext. - llvm::StringMap identifiers; + llvm::StringMap identifiers; // Primitive type uniquing. - PrimitiveType *primitives[int(Type::Kind::LAST_PRIMITIVE_TYPE)+1] = {nullptr}; + PrimitiveType *primitives[int(Type::Kind::LAST_PRIMITIVE_TYPE) + 1] = { + nullptr}; // Affine map uniquing. using AffineMapSet = DenseSet; @@ -201,36 +201,36 @@ public: affineExprs; /// Integer type uniquing. - DenseMap integers; + DenseMap integers; /// Function type uniquing. - using FunctionTypeSet = DenseSet; + using FunctionTypeSet = DenseSet; FunctionTypeSet functions; /// Vector type uniquing. - using VectorTypeSet = DenseSet; + using VectorTypeSet = DenseSet; VectorTypeSet vectors; /// Ranked tensor type uniquing. - using RankedTensorTypeSet = DenseSet; + using RankedTensorTypeSet = + DenseSet; RankedTensorTypeSet rankedTensors; /// Unranked tensor type uniquing. - DenseMap unrankedTensors; + DenseMap unrankedTensors; /// MemRef type uniquing. - using MemRefTypeSet = DenseSet; + using MemRefTypeSet = DenseSet; MemRefTypeSet memrefs; // Attribute uniquing. - BoolAttr *boolAttrs[2] = { nullptr }; - DenseMap integerAttrs; - DenseMap floatAttrs; - StringMap stringAttrs; - using ArrayAttrSet = DenseSet; + BoolAttr *boolAttrs[2] = {nullptr}; + DenseMap integerAttrs; + DenseMap floatAttrs; + StringMap stringAttrs; + using ArrayAttrSet = DenseSet; ArrayAttrSet arrayAttrs; - DenseMap affineMapAttrs; + DenseMap affineMapAttrs; using AttributeListSet = DenseSet; AttributeListSet attributeLists; @@ -242,8 +242,7 @@ public: /// Copy the specified array of elements into memory managed by our bump /// pointer allocator. This assumes the elements are all PODs. - template - ArrayRef copyInto(ArrayRef elements) { + template ArrayRef copyInto(ArrayRef elements) { auto result = allocator.Allocate(elements.size()); std::uninitialized_copy(elements.begin(), elements.end(), result); return ArrayRef(result, elements.size()); @@ -251,11 +250,9 @@ public: }; } // end namespace mlir -MLIRContext::MLIRContext() : impl(new MLIRContextImpl()) { -} +MLIRContext::MLIRContext() : impl(new MLIRContextImpl()) {} -MLIRContext::~MLIRContext() { -} +MLIRContext::~MLIRContext() {} /// Return the operation set associated with the specified MLIRContext object. OperationSet &OperationSet::get(MLIRContext *context) { @@ -301,7 +298,7 @@ PrimitiveType *PrimitiveType::get(Kind kind, MLIRContext *context) { auto *ptr = impl.allocator.Allocate(); // Initialize the memory using placement new. - new(ptr) PrimitiveType(kind, context); + new (ptr) PrimitiveType(kind, context); // Cache and return it. return impl.primitives[(int)kind] = ptr; @@ -319,7 +316,8 @@ IntegerType *IntegerType::get(unsigned width, MLIRContext *context) { return result; } -FunctionType *FunctionType::get(ArrayRef inputs, ArrayRef results, +FunctionType *FunctionType::get(ArrayRef inputs, + ArrayRef results, MLIRContext *context) { auto &impl = context->getImpl(); @@ -335,15 +333,15 @@ FunctionType *FunctionType::get(ArrayRef inputs, ArrayRef results, auto *result = impl.allocator.Allocate(); // Copy the inputs and results into the bump pointer. - SmallVector types; - types.reserve(inputs.size()+results.size()); + SmallVector types; + types.reserve(inputs.size() + results.size()); types.append(inputs.begin(), inputs.end()); types.append(results.begin(), results.end()); - auto typesList = impl.copyInto(ArrayRef(types)); + auto typesList = impl.copyInto(ArrayRef(types)); // Initialize the memory using placement new. - new (result) FunctionType(typesList.data(), inputs.size(), results.size(), - context); + new (result) + FunctionType(typesList.data(), inputs.size(), results.size(), context); // Cache and return it. return *existing.first = result; @@ -378,9 +376,8 @@ VectorType *VectorType::get(ArrayRef shape, Type *elementType) { return *existing.first = result; } - TensorType::TensorType(Kind kind, Type *elementType, MLIRContext *context) - : Type(kind, context), elementType(elementType) { + : Type(kind, context), elementType(elementType) { assert((isa(elementType) || isa(elementType) || isa(elementType)) && "tensor elements must be primitives or vectors"); @@ -433,14 +430,14 @@ UnrankedTensorType *UnrankedTensorType::get(Type *elementType) { } MemRefType *MemRefType::get(ArrayRef shape, Type *elementType, - ArrayRef affineMapComposition, + ArrayRef affineMapComposition, unsigned memorySpace) { auto *context = elementType->getContext(); auto &impl = context->getImpl(); // Look to see if we already have this memref type. - auto key = std::make_tuple(elementType, shape, affineMapComposition, - memorySpace); + auto key = + std::make_tuple(elementType, shape, affineMapComposition, memorySpace); auto existing = impl.memrefs.insert_as(nullptr, key); // If we already have it, return that value. @@ -455,8 +452,8 @@ MemRefType *MemRefType::get(ArrayRef shape, Type *elementType, // Copy the affine map composition into the bump pointer. // TODO(andydavis) Assert that the structure of the composition is valid. - affineMapComposition = impl.copyInto(ArrayRef( - affineMapComposition)); + affineMapComposition = + impl.copyInto(ArrayRef(affineMapComposition)); // Initialize the memory using placement new. new (result) MemRefType(shape, elementType, affineMapComposition, memorySpace, @@ -519,7 +516,7 @@ StringAttr *StringAttr::get(StringRef bytes, MLIRContext *context) { return result; } -ArrayAttr *ArrayAttr::get(ArrayRef value, MLIRContext *context) { +ArrayAttr *ArrayAttr::get(ArrayRef value, MLIRContext *context) { auto &impl = context->getImpl(); // Look to see if we already have this. @@ -542,7 +539,7 @@ ArrayAttr *ArrayAttr::get(ArrayRef value, MLIRContext *context) { return *existing.first = result; } -AffineMapAttr *AffineMapAttr::get(AffineMap* value, MLIRContext *context) { +AffineMapAttr *AffineMapAttr::get(AffineMap *value, MLIRContext *context) { auto *&result = context->getImpl().affineMapAttrs[value]; if (result) return result;