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