forked from OSchip/llvm-project
Deconst-ify MLIRContext, and detemplatize some stuff now that const is gone.
PiperOrigin-RevId: 239976764
This commit is contained in:
parent
888554c0c6
commit
405aa0af9e
|
@ -40,10 +40,10 @@ public:
|
|||
void map(Value *from, Value *to) { valueMap[from] = to; }
|
||||
|
||||
/// Erases a mapping for 'from'.
|
||||
void erase(const IRObjectWithUseList *from) { valueMap.erase(from); }
|
||||
void erase(IRObjectWithUseList *from) { valueMap.erase(from); }
|
||||
|
||||
/// Checks to see if a mapping for 'from' exists.
|
||||
bool contains(const IRObjectWithUseList *from) const {
|
||||
bool contains(IRObjectWithUseList *from) const {
|
||||
return valueMap.count(from);
|
||||
}
|
||||
|
||||
|
@ -72,12 +72,12 @@ private:
|
|||
/// Utility lookupOrValue that looks up an existing key or returns the
|
||||
/// provided value. This function assumes that if a mapping does exist, then
|
||||
/// it is of 'T' type.
|
||||
template <typename T> T *lookupOrValue(const T *from, T *value) const {
|
||||
template <typename T> T *lookupOrValue(T *from, T *value) const {
|
||||
auto it = valueMap.find(from);
|
||||
return it != valueMap.end() ? static_cast<T *>(it->second) : value;
|
||||
}
|
||||
|
||||
llvm::DenseMap<const IRObjectWithUseList *, IRObjectWithUseList *> valueMap;
|
||||
llvm::DenseMap<IRObjectWithUseList *, IRObjectWithUseList *> valueMap;
|
||||
};
|
||||
|
||||
} // end namespace mlir
|
||||
|
|
|
@ -35,7 +35,7 @@ class MLIRContext;
|
|||
class Identifier {
|
||||
public:
|
||||
/// Return an identifier for the specified string.
|
||||
static Identifier get(StringRef str, const MLIRContext *context);
|
||||
static Identifier get(StringRef str, MLIRContext *context);
|
||||
Identifier(const Identifier &) = default;
|
||||
Identifier &operator=(const Identifier &other) = default;
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ class BlockAndValueMapping;
|
|||
class Location;
|
||||
class MLIRContext;
|
||||
template <typename OpType> class OpPointer;
|
||||
template <typename ObjectType, typename ElementType> class OperandIterator;
|
||||
template <typename ObjectType, typename ElementType> class ResultIterator;
|
||||
template <typename ObjectType, typename ElementType> class ResultTypeIterator;
|
||||
class OperandIterator;
|
||||
class ResultIterator;
|
||||
class ResultTypeIterator;
|
||||
|
||||
/// Terminator operations can have Block operands to represent successors.
|
||||
using BlockOperand = IROperandImpl<Block>;
|
||||
|
@ -157,8 +157,8 @@ public:
|
|||
return getInstOperand(idx).set(value);
|
||||
}
|
||||
|
||||
// Support non-const operand iteration.
|
||||
using operand_iterator = OperandIterator<Instruction, Value>;
|
||||
// Support operand iteration.
|
||||
using operand_iterator = OperandIterator;
|
||||
using operand_range = llvm::iterator_range<operand_iterator>;
|
||||
|
||||
operand_iterator operand_begin();
|
||||
|
@ -185,7 +185,7 @@ public:
|
|||
Value *getResult(unsigned idx) { return &getInstResult(idx); }
|
||||
|
||||
// Support result iteration.
|
||||
using result_iterator = ResultIterator<Instruction, Value>;
|
||||
using result_iterator = ResultIterator;
|
||||
result_iterator result_begin();
|
||||
result_iterator result_end();
|
||||
llvm::iterator_range<result_iterator> getResults();
|
||||
|
@ -197,7 +197,7 @@ public:
|
|||
InstResult &getInstResult(unsigned idx) { return getInstResults()[idx]; }
|
||||
|
||||
// Support result type iteration.
|
||||
using result_type_iterator = ResultTypeIterator<Instruction, Type>;
|
||||
using result_type_iterator = ResultTypeIterator;
|
||||
result_type_iterator result_type_begin();
|
||||
result_type_iterator result_type_end();
|
||||
llvm::iterator_range<result_type_iterator> getResultTypes();
|
||||
|
@ -505,21 +505,17 @@ inline raw_ostream &operator<<(raw_ostream &os, Instruction &inst) {
|
|||
return os;
|
||||
}
|
||||
|
||||
/// This template implements the const/non-const operand iterators for the
|
||||
/// This class implements the const/non-const operand iterators for the
|
||||
/// Instruction class in terms of getOperand(idx).
|
||||
template <typename ObjectType, typename ElementType>
|
||||
class OperandIterator final
|
||||
: public IndexedAccessorIterator<OperandIterator<ObjectType, ElementType>,
|
||||
ObjectType, ElementType> {
|
||||
: public IndexedAccessorIterator<OperandIterator, Instruction, Value> {
|
||||
public:
|
||||
/// Initializes the operand iterator to the specified operand index.
|
||||
OperandIterator(ObjectType *object, unsigned index)
|
||||
: IndexedAccessorIterator<OperandIterator<ObjectType, ElementType>,
|
||||
ObjectType, ElementType>(object, index) {}
|
||||
OperandIterator(Instruction *object, unsigned index)
|
||||
: IndexedAccessorIterator<OperandIterator, Instruction, Value>(object,
|
||||
index) {}
|
||||
|
||||
ElementType *operator*() const {
|
||||
return this->object->getOperand(this->index);
|
||||
}
|
||||
Value *operator*() const { return this->object->getOperand(this->index); }
|
||||
};
|
||||
|
||||
// Implement the inline operand iterator methods.
|
||||
|
@ -535,41 +531,28 @@ inline auto Instruction::getOperands() -> operand_range {
|
|||
return {operand_begin(), operand_end()};
|
||||
}
|
||||
|
||||
/// This template implements the result iterators for the Instruction class
|
||||
/// This class implements the result iterators for the Instruction class
|
||||
/// in terms of getResult(idx).
|
||||
template <typename ObjectType, typename ElementType>
|
||||
class ResultIterator final
|
||||
: public IndexedAccessorIterator<ResultIterator<ObjectType, ElementType>,
|
||||
ObjectType, ElementType> {
|
||||
: public IndexedAccessorIterator<ResultIterator, Instruction, Value> {
|
||||
public:
|
||||
/// Initializes the result iterator to the specified index.
|
||||
ResultIterator(ObjectType *object, unsigned index)
|
||||
: IndexedAccessorIterator<ResultIterator<ObjectType, ElementType>,
|
||||
ObjectType, ElementType>(object, index) {}
|
||||
ResultIterator(Instruction *object, unsigned index)
|
||||
: IndexedAccessorIterator<ResultIterator, Instruction, Value>(object,
|
||||
index) {}
|
||||
|
||||
ElementType *operator*() const {
|
||||
return this->object->getResult(this->index);
|
||||
}
|
||||
Value *operator*() const { return this->object->getResult(this->index); }
|
||||
};
|
||||
|
||||
/// This template implements the result type iterators for the Instruction
|
||||
/// This class implements the result type iterators for the Instruction
|
||||
/// class in terms of getResult(idx)->getType().
|
||||
template <typename ObjectType, typename ElementType>
|
||||
class ResultTypeIterator final
|
||||
: public IndexedAccessorIterator<
|
||||
ResultTypeIterator<ObjectType, ElementType>, ObjectType,
|
||||
ElementType> {
|
||||
: public IndexedAccessorIterator<ResultTypeIterator, Instruction, Value> {
|
||||
public:
|
||||
/// Initializes the result type iterator to the specified index.
|
||||
ResultTypeIterator(ObjectType *object, unsigned index)
|
||||
: IndexedAccessorIterator<ResultTypeIterator<ObjectType, ElementType>,
|
||||
ObjectType, ElementType>(object, index) {}
|
||||
|
||||
/// Support converting to the const variant. This will be a no-op for const
|
||||
/// variant.
|
||||
operator ResultTypeIterator<const ObjectType, const ElementType>() const {
|
||||
return ResultTypeIterator<const ObjectType, const ElementType>(this->object,
|
||||
this->index);
|
||||
ResultTypeIterator(Instruction *object, unsigned index)
|
||||
: IndexedAccessorIterator<ResultTypeIterator, Instruction, Value>(object,
|
||||
index) {
|
||||
}
|
||||
|
||||
Type operator*() const {
|
||||
|
|
|
@ -43,16 +43,16 @@ public:
|
|||
~MLIRContext();
|
||||
|
||||
/// Return information about all registered IR dialects.
|
||||
std::vector<Dialect *> getRegisteredDialects() const;
|
||||
std::vector<Dialect *> getRegisteredDialects();
|
||||
|
||||
/// Get a registered IR dialect with the given namespace. If an exact match is
|
||||
/// not found, then return nullptr.
|
||||
Dialect *getRegisteredDialect(StringRef name) const;
|
||||
Dialect *getRegisteredDialect(StringRef name);
|
||||
|
||||
/// Return information about all registered operations. This isn't very
|
||||
/// efficient: typically you should ask the operations about their properties
|
||||
/// directly.
|
||||
std::vector<AbstractOperation *> getRegisteredOperations() const;
|
||||
std::vector<AbstractOperation *> getRegisteredOperations();
|
||||
|
||||
/// This is the interpretation of a diagnostic that is emitted to the
|
||||
/// diagnostic handler below.
|
||||
|
@ -77,21 +77,21 @@ public:
|
|||
void registerDiagnosticHandler(const DiagnosticHandlerTy &handler);
|
||||
|
||||
/// Return the current diagnostic handler, or null if none is present.
|
||||
DiagnosticHandlerTy getDiagnosticHandler() const;
|
||||
DiagnosticHandlerTy getDiagnosticHandler();
|
||||
|
||||
/// Emit a diagnostic using the registered issue handle if present, or with
|
||||
/// the default behavior if not. The MLIR compiler should not generally
|
||||
/// interact with this, it should use methods on Instruction instead.
|
||||
void emitDiagnostic(Location location, const Twine &message,
|
||||
DiagnosticKind kind) const;
|
||||
DiagnosticKind kind);
|
||||
|
||||
/// Emit an error message using the registered issue handle if present, or to
|
||||
/// the standard error stream otherwise and return true.
|
||||
bool emitError(Location location, const Twine &message) const;
|
||||
bool emitError(Location location, const Twine &message);
|
||||
|
||||
// This is effectively private given that only MLIRContext.cpp can see the
|
||||
// MLIRContextImpl type.
|
||||
MLIRContextImpl &getImpl() const { return *impl.get(); }
|
||||
MLIRContextImpl &getImpl() { return *impl.get(); }
|
||||
|
||||
private:
|
||||
const std::unique_ptr<MLIRContextImpl> impl;
|
||||
|
|
|
@ -616,7 +616,7 @@ void MLIRContext::registerDiagnosticHandler(
|
|||
}
|
||||
|
||||
/// Return the current diagnostic handler, or null if none is present.
|
||||
auto MLIRContext::getDiagnosticHandler() const -> DiagnosticHandlerTy {
|
||||
auto MLIRContext::getDiagnosticHandler() -> DiagnosticHandlerTy {
|
||||
// Lock access to the context diagnostic handler.
|
||||
llvm::sys::SmartScopedReader<true> contextLock(getImpl().contextMutex);
|
||||
return getImpl().diagnosticHandler;
|
||||
|
@ -626,7 +626,7 @@ auto MLIRContext::getDiagnosticHandler() const -> DiagnosticHandlerTy {
|
|||
/// with the default behavior if not. The MLIR compiler should not generally
|
||||
/// interact with this, it should use methods on Instruction instead.
|
||||
void MLIRContext::emitDiagnostic(Location location, const llvm::Twine &message,
|
||||
DiagnosticKind kind) const {
|
||||
DiagnosticKind kind) {
|
||||
// Check to see if we are emitting a diagnostic on a fused location.
|
||||
if (auto fusedLoc = location.dyn_cast<FusedLoc>()) {
|
||||
auto fusedLocs = fusedLoc->getLocations();
|
||||
|
@ -665,8 +665,7 @@ void MLIRContext::emitDiagnostic(Location location, const llvm::Twine &message,
|
|||
os.flush();
|
||||
}
|
||||
|
||||
bool MLIRContext::emitError(Location location,
|
||||
const llvm::Twine &message) const {
|
||||
bool MLIRContext::emitError(Location location, const llvm::Twine &message) {
|
||||
emitDiagnostic(location, message, DiagnosticKind::Error);
|
||||
return true;
|
||||
}
|
||||
|
@ -676,7 +675,7 @@ bool MLIRContext::emitError(Location location,
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Return information about all registered IR dialects.
|
||||
std::vector<Dialect *> MLIRContext::getRegisteredDialects() const {
|
||||
std::vector<Dialect *> MLIRContext::getRegisteredDialects() {
|
||||
// Lock access to the context registry.
|
||||
llvm::sys::SmartScopedReader<true> registryLock(getImpl().contextMutex);
|
||||
|
||||
|
@ -689,7 +688,7 @@ std::vector<Dialect *> MLIRContext::getRegisteredDialects() const {
|
|||
|
||||
/// Get a registered IR dialect with the given namespace. If none is found,
|
||||
/// then return nullptr.
|
||||
Dialect *MLIRContext::getRegisteredDialect(StringRef name) const {
|
||||
Dialect *MLIRContext::getRegisteredDialect(StringRef name) {
|
||||
// Lock access to the context registry.
|
||||
llvm::sys::SmartScopedReader<true> registryLock(getImpl().contextMutex);
|
||||
for (auto &dialect : getImpl().dialects)
|
||||
|
@ -711,7 +710,7 @@ void Dialect::registerDialect(MLIRContext *context) {
|
|||
/// Return information about all registered operations. This isn't very
|
||||
/// efficient, typically you should ask the operations about their properties
|
||||
/// directly.
|
||||
std::vector<AbstractOperation *> MLIRContext::getRegisteredOperations() const {
|
||||
std::vector<AbstractOperation *> MLIRContext::getRegisteredOperations() {
|
||||
std::vector<std::pair<StringRef, AbstractOperation *>> opsToSort;
|
||||
|
||||
{ // Lock access to the context registry.
|
||||
|
@ -783,7 +782,7 @@ const AbstractOperation *AbstractOperation::lookup(StringRef opName,
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Return an identifier for the specified string.
|
||||
Identifier Identifier::get(StringRef str, const MLIRContext *context) {
|
||||
Identifier Identifier::get(StringRef str, MLIRContext *context) {
|
||||
assert(!str.empty() && "Cannot create an empty identifier");
|
||||
assert(str.find('\0') == StringRef::npos &&
|
||||
"Cannot create an identifier with a nul character");
|
||||
|
|
Loading…
Reference in New Issue