353 changes: 353 additions & 0 deletions llvm/include/llvm/ADT/STLExtras.h

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
//
//===-----------------------------------------------------------------------===/

#ifndef MLIR_SUPPORT_TYPESWITCH_H
#define MLIR_SUPPORT_TYPESWITCH_H
#ifndef LLVM_ADT_TYPESWITCH_H
#define LLVM_ADT_TYPESWITCH_H

#include "mlir/Support/LLVM.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Casting.h"

namespace mlir {
namespace llvm {
namespace detail {

template <typename DerivedT, typename T> class TypeSwitchBase {
Expand Down Expand Up @@ -46,7 +46,7 @@ template <typename DerivedT, typename T> class TypeSwitchBase {
/// Note: This inference rules for this overload are very simple: strip
/// pointers and references.
template <typename CallableT> DerivedT &Case(CallableT &&caseFn) {
using Traits = FunctionTraits<std::decay_t<CallableT>>;
using Traits = function_traits<std::decay_t<CallableT>>;
using CaseT = std::remove_cv_t<std::remove_pointer_t<
std::remove_reference_t<typename Traits::template arg_t<0>>>>;

Expand Down Expand Up @@ -171,6 +171,6 @@ class TypeSwitch<T, void>
/// A flag detailing if we have already found a match.
bool foundMatch = false;
};
} // end namespace mlir
} // end namespace llvm

#endif // MLIR_SUPPORT_TYPESWITCH_H
#endif // LLVM_ADT_TYPESWITCH_H
2 changes: 2 additions & 0 deletions llvm/unittests/ADT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ add_llvm_unittest(ADTTests
TinyPtrVectorTest.cpp
TripleTest.cpp
TwineTest.cpp
TypeSwitchTest.cpp
TypeTraitsTest.cpp
WaymarkingTest.cpp
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/ADT/TypeSwitch.h"
#include "llvm/ADT/TypeSwitch.h"
#include "gtest/gtest.h"

using namespace mlir;
using namespace llvm;

namespace {
/// Utility classes to setup casting functionality.
Expand All @@ -28,7 +28,7 @@ struct DerivedD : public DerivedImpl<Base::DerivedD> {};
struct DerivedE : public DerivedImpl<Base::DerivedE> {};
} // end anonymous namespace

TEST(StringSwitchTest, CaseResult) {
TEST(TypeSwitchTest, CaseResult) {
auto translate = [](auto value) {
return TypeSwitch<Base *, int>(&value)
.Case<DerivedA>([](DerivedA *) { return 0; })
Expand All @@ -42,7 +42,7 @@ TEST(StringSwitchTest, CaseResult) {
EXPECT_EQ(-1, translate(DerivedD()));
}

TEST(StringSwitchTest, CasesResult) {
TEST(TypeSwitchTest, CasesResult) {
auto translate = [](auto value) {
return TypeSwitch<Base *, int>(&value)
.Case<DerivedA, DerivedB, DerivedD>([](auto *) { return 0; })
Expand All @@ -56,7 +56,7 @@ TEST(StringSwitchTest, CasesResult) {
EXPECT_EQ(-1, translate(DerivedE()));
}

TEST(StringSwitchTest, CaseVoid) {
TEST(TypeSwitchTest, CaseVoid) {
auto translate = [](auto value) {
int result = -2;
TypeSwitch<Base *>(&value)
Expand All @@ -72,7 +72,7 @@ TEST(StringSwitchTest, CaseVoid) {
EXPECT_EQ(-1, translate(DerivedD()));
}

TEST(StringSwitchTest, CasesVoid) {
TEST(TypeSwitchTest, CasesVoid) {
auto translate = [](auto value) {
int result = -1;
TypeSwitch<Base *>(&value)
Expand Down
79 changes: 79 additions & 0 deletions llvm/unittests/ADT/TypeTraitsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//===- TypeTraitsTest.cpp - type_traits unit tests ------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/STLExtras.h"
#include "gtest/gtest.h"

using namespace llvm;

//===----------------------------------------------------------------------===//
// function_traits
//===----------------------------------------------------------------------===//

namespace {
/// Check a callable type of the form `bool(const int &)`.
template <typename CallableT> struct CheckFunctionTraits {
static_assert(
std::is_same<typename function_traits<CallableT>::result_t, bool>::value,
"expected result_t to be `bool`");
static_assert(
std::is_same<typename function_traits<CallableT>::template arg_t<0>,
const int &>::value,
"expected arg_t<0> to be `const int &`");
static_assert(function_traits<CallableT>::num_args == 1,
"expected num_args to be 1");
};

/// Test function pointers.
using FuncType = bool (*)(const int &);
struct CheckFunctionPointer : CheckFunctionTraits<FuncType> {};

/// Test method pointers.
struct Foo {
bool func(const int &v);
};
struct CheckMethodPointer : CheckFunctionTraits<decltype(&Foo::func)> {};

/// Test lambda references.
LLVM_ATTRIBUTE_UNUSED auto lambdaFunc = [](const int &v) -> bool {
return true;
};
struct CheckLambda : CheckFunctionTraits<decltype(lambdaFunc)> {};

} // end anonymous namespace

//===----------------------------------------------------------------------===//
// is_detected
//===----------------------------------------------------------------------===//

namespace {
struct HasFooMethod {
void foo() {}
};
struct NoFooMethod {};

template <class T> using has_foo_method_t = decltype(std::declval<T &>().foo());

static_assert(is_detected<has_foo_method_t, HasFooMethod>::value,
"expected foo method to be detected");
static_assert(!is_detected<has_foo_method_t, NoFooMethod>::value,
"expected no foo method to be detected");
} // end anonymous namespace

//===----------------------------------------------------------------------===//
// is_invocable
//===----------------------------------------------------------------------===//

void invocable_fn(int);

static_assert(is_invocable<decltype(invocable_fn), int>::value,
"expected function to be invocable");
static_assert(!is_invocable<decltype(invocable_fn), void *>::value,
"expected function not to be invocable");
static_assert(!is_invocable<decltype(invocable_fn), int, int>::value,
"expected function not to be invocable");
1 change: 1 addition & 0 deletions llvm/unittests/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_llvm_unittest(SupportTests
FormatVariadicTest.cpp
GlobPatternTest.cpp
Host.cpp
IndexedAccessorTest.cpp
ItaniumManglingCanonicalizerTest.cpp
JSONTest.cpp
KnownBitsTest.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "gmock/gmock.h"

using namespace mlir;
using namespace mlir::detail;
using namespace llvm;
using namespace llvm::detail;

namespace {
/// Simple indexed accessor range that wraps an array.
Expand All @@ -24,7 +24,7 @@ struct ArrayIndexedAccessorRange
using indexed_accessor_range<ArrayIndexedAccessorRange<T>, T *,
T>::indexed_accessor_range;

/// See `indexed_accessor_range` for details.
/// See `llvm::indexed_accessor_range` for details.
static T &dereference(T *data, ptrdiff_t index) { return data[index]; }
};
} // end anonymous namespace
Expand Down
2 changes: 1 addition & 1 deletion mlir/docs/Tutorials/Toy/Ch-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ everything to the LLVM dialect.
```c++
mlir::ConversionTarget target(getContext());
target.addLegalDialect<mlir::LLVM::LLVMDialect>();
target.addLegalDialect<mlir::LLVMDialect>();
target.addLegalOp<mlir::ModuleOp, mlir::ModuleTerminatorOp>();
```

Expand Down
2 changes: 1 addition & 1 deletion mlir/docs/Tutorials/Toy/Ch-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void ToyDialect::printType(mlir::Type type,
// Print the struct type according to the parser format.
printer << "struct<";
mlir::interleaveComma(structType.getElementTypes(), printer);
llvm::interleaveComma(structType.getElementTypes(), printer);
printer << '>';
}
```
Expand Down
13 changes: 6 additions & 7 deletions mlir/examples/toy/Ch1/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "toy/AST.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"

using namespace toy;
Expand Down Expand Up @@ -76,7 +75,7 @@ template <typename T> static std::string loc(T *node) {

/// Dispatch to a generic expressions to the appropriate subclass using RTTI
void ASTDumper::dump(ExprAST *expr) {
mlir::TypeSwitch<ExprAST *>(expr)
llvm::TypeSwitch<ExprAST *>(expr)
.Case<BinaryExprAST, CallExprAST, LiteralExprAST, NumberExprAST,
PrintExprAST, ReturnExprAST, VarDeclExprAST, VariableExprAST>(
[&](auto *node) { this->dump(node); })
Expand Down Expand Up @@ -127,12 +126,12 @@ void printLitHelper(ExprAST *litOrNum) {

// Print the dimension for this literal first
llvm::errs() << "<";
mlir::interleaveComma(literal->getDims(), llvm::errs());
llvm::interleaveComma(literal->getDims(), llvm::errs());
llvm::errs() << ">";

// Now print the content, recursing on every element of the list
llvm::errs() << "[ ";
mlir::interleaveComma(literal->getValues(), llvm::errs(),
llvm::interleaveComma(literal->getValues(), llvm::errs(),
[&](auto &elt) { printLitHelper(elt.get()); });
llvm::errs() << "]";
}
Expand Down Expand Up @@ -194,7 +193,7 @@ void ASTDumper::dump(PrintExprAST *node) {
/// Print type: only the shape is printed in between '<' and '>'
void ASTDumper::dump(const VarType &type) {
llvm::errs() << "<";
mlir::interleaveComma(type.shape, llvm::errs());
llvm::interleaveComma(type.shape, llvm::errs());
llvm::errs() << ">";
}

Expand All @@ -205,7 +204,7 @@ void ASTDumper::dump(PrototypeAST *node) {
llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
indent();
llvm::errs() << "Params: [";
mlir::interleaveComma(node->getArgs(), llvm::errs(),
llvm::interleaveComma(node->getArgs(), llvm::errs(),
[](auto &arg) { llvm::errs() << arg->getName(); });
llvm::errs() << "]\n";
}
Expand Down
13 changes: 6 additions & 7 deletions mlir/examples/toy/Ch2/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "toy/AST.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"

using namespace toy;
Expand Down Expand Up @@ -76,7 +75,7 @@ template <typename T> static std::string loc(T *node) {

/// Dispatch to a generic expressions to the appropriate subclass using RTTI
void ASTDumper::dump(ExprAST *expr) {
mlir::TypeSwitch<ExprAST *>(expr)
llvm::TypeSwitch<ExprAST *>(expr)
.Case<BinaryExprAST, CallExprAST, LiteralExprAST, NumberExprAST,
PrintExprAST, ReturnExprAST, VarDeclExprAST, VariableExprAST>(
[&](auto *node) { this->dump(node); })
Expand Down Expand Up @@ -127,12 +126,12 @@ void printLitHelper(ExprAST *litOrNum) {

// Print the dimension for this literal first
llvm::errs() << "<";
mlir::interleaveComma(literal->getDims(), llvm::errs());
llvm::interleaveComma(literal->getDims(), llvm::errs());
llvm::errs() << ">";

// Now print the content, recursing on every element of the list
llvm::errs() << "[ ";
mlir::interleaveComma(literal->getValues(), llvm::errs(),
llvm::interleaveComma(literal->getValues(), llvm::errs(),
[&](auto &elt) { printLitHelper(elt.get()); });
llvm::errs() << "]";
}
Expand Down Expand Up @@ -194,7 +193,7 @@ void ASTDumper::dump(PrintExprAST *node) {
/// Print type: only the shape is printed in between '<' and '>'
void ASTDumper::dump(const VarType &type) {
llvm::errs() << "<";
mlir::interleaveComma(type.shape, llvm::errs());
llvm::interleaveComma(type.shape, llvm::errs());
llvm::errs() << ">";
}

Expand All @@ -205,7 +204,7 @@ void ASTDumper::dump(PrototypeAST *node) {
llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
indent();
llvm::errs() << "Params: [";
mlir::interleaveComma(node->getArgs(), llvm::errs(),
llvm::interleaveComma(node->getArgs(), llvm::errs(),
[](auto &arg) { llvm::errs() << arg->getName(); });
llvm::errs() << "]\n";
}
Expand Down
13 changes: 6 additions & 7 deletions mlir/examples/toy/Ch3/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "toy/AST.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"

using namespace toy;
Expand Down Expand Up @@ -76,7 +75,7 @@ template <typename T> static std::string loc(T *node) {

/// Dispatch to a generic expressions to the appropriate subclass using RTTI
void ASTDumper::dump(ExprAST *expr) {
mlir::TypeSwitch<ExprAST *>(expr)
llvm::TypeSwitch<ExprAST *>(expr)
.Case<BinaryExprAST, CallExprAST, LiteralExprAST, NumberExprAST,
PrintExprAST, ReturnExprAST, VarDeclExprAST, VariableExprAST>(
[&](auto *node) { this->dump(node); })
Expand Down Expand Up @@ -127,12 +126,12 @@ void printLitHelper(ExprAST *litOrNum) {

// Print the dimension for this literal first
llvm::errs() << "<";
mlir::interleaveComma(literal->getDims(), llvm::errs());
llvm::interleaveComma(literal->getDims(), llvm::errs());
llvm::errs() << ">";

// Now print the content, recursing on every element of the list
llvm::errs() << "[ ";
mlir::interleaveComma(literal->getValues(), llvm::errs(),
llvm::interleaveComma(literal->getValues(), llvm::errs(),
[&](auto &elt) { printLitHelper(elt.get()); });
llvm::errs() << "]";
}
Expand Down Expand Up @@ -194,7 +193,7 @@ void ASTDumper::dump(PrintExprAST *node) {
/// Print type: only the shape is printed in between '<' and '>'
void ASTDumper::dump(const VarType &type) {
llvm::errs() << "<";
mlir::interleaveComma(type.shape, llvm::errs());
llvm::interleaveComma(type.shape, llvm::errs());
llvm::errs() << ">";
}

Expand All @@ -205,7 +204,7 @@ void ASTDumper::dump(PrototypeAST *node) {
llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
indent();
llvm::errs() << "Params: [";
mlir::interleaveComma(node->getArgs(), llvm::errs(),
llvm::interleaveComma(node->getArgs(), llvm::errs(),
[](auto &arg) { llvm::errs() << arg->getName(); });
llvm::errs() << "]\n";
}
Expand Down
13 changes: 6 additions & 7 deletions mlir/examples/toy/Ch4/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "toy/AST.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"

using namespace toy;
Expand Down Expand Up @@ -76,7 +75,7 @@ template <typename T> static std::string loc(T *node) {

/// Dispatch to a generic expressions to the appropriate subclass using RTTI
void ASTDumper::dump(ExprAST *expr) {
mlir::TypeSwitch<ExprAST *>(expr)
llvm::TypeSwitch<ExprAST *>(expr)
.Case<BinaryExprAST, CallExprAST, LiteralExprAST, NumberExprAST,
PrintExprAST, ReturnExprAST, VarDeclExprAST, VariableExprAST>(
[&](auto *node) { this->dump(node); })
Expand Down Expand Up @@ -127,12 +126,12 @@ void printLitHelper(ExprAST *litOrNum) {

// Print the dimension for this literal first
llvm::errs() << "<";
mlir::interleaveComma(literal->getDims(), llvm::errs());
llvm::interleaveComma(literal->getDims(), llvm::errs());
llvm::errs() << ">";

// Now print the content, recursing on every element of the list
llvm::errs() << "[ ";
mlir::interleaveComma(literal->getValues(), llvm::errs(),
llvm::interleaveComma(literal->getValues(), llvm::errs(),
[&](auto &elt) { printLitHelper(elt.get()); });
llvm::errs() << "]";
}
Expand Down Expand Up @@ -194,7 +193,7 @@ void ASTDumper::dump(PrintExprAST *node) {
/// Print type: only the shape is printed in between '<' and '>'
void ASTDumper::dump(const VarType &type) {
llvm::errs() << "<";
mlir::interleaveComma(type.shape, llvm::errs());
llvm::interleaveComma(type.shape, llvm::errs());
llvm::errs() << ">";
}

Expand All @@ -205,7 +204,7 @@ void ASTDumper::dump(PrototypeAST *node) {
llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
indent();
llvm::errs() << "Params: [";
mlir::interleaveComma(node->getArgs(), llvm::errs(),
llvm::interleaveComma(node->getArgs(), llvm::errs(),
[](auto &arg) { llvm::errs() << arg->getName(); });
llvm::errs() << "]\n";
}
Expand Down
13 changes: 6 additions & 7 deletions mlir/examples/toy/Ch5/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "toy/AST.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"

using namespace toy;
Expand Down Expand Up @@ -76,7 +75,7 @@ template <typename T> static std::string loc(T *node) {

/// Dispatch to a generic expressions to the appropriate subclass using RTTI
void ASTDumper::dump(ExprAST *expr) {
mlir::TypeSwitch<ExprAST *>(expr)
llvm::TypeSwitch<ExprAST *>(expr)
.Case<BinaryExprAST, CallExprAST, LiteralExprAST, NumberExprAST,
PrintExprAST, ReturnExprAST, VarDeclExprAST, VariableExprAST>(
[&](auto *node) { this->dump(node); })
Expand Down Expand Up @@ -127,12 +126,12 @@ void printLitHelper(ExprAST *litOrNum) {

// Print the dimension for this literal first
llvm::errs() << "<";
mlir::interleaveComma(literal->getDims(), llvm::errs());
llvm::interleaveComma(literal->getDims(), llvm::errs());
llvm::errs() << ">";

// Now print the content, recursing on every element of the list
llvm::errs() << "[ ";
mlir::interleaveComma(literal->getValues(), llvm::errs(),
llvm::interleaveComma(literal->getValues(), llvm::errs(),
[&](auto &elt) { printLitHelper(elt.get()); });
llvm::errs() << "]";
}
Expand Down Expand Up @@ -194,7 +193,7 @@ void ASTDumper::dump(PrintExprAST *node) {
/// Print type: only the shape is printed in between '<' and '>'
void ASTDumper::dump(const VarType &type) {
llvm::errs() << "<";
mlir::interleaveComma(type.shape, llvm::errs());
llvm::interleaveComma(type.shape, llvm::errs());
llvm::errs() << ">";
}

Expand All @@ -205,7 +204,7 @@ void ASTDumper::dump(PrototypeAST *node) {
llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
indent();
llvm::errs() << "Params: [";
mlir::interleaveComma(node->getArgs(), llvm::errs(),
llvm::interleaveComma(node->getArgs(), llvm::errs(),
[](auto &arg) { llvm::errs() << arg->getName(); });
llvm::errs() << "]\n";
}
Expand Down
13 changes: 6 additions & 7 deletions mlir/examples/toy/Ch6/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "toy/AST.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"

using namespace toy;
Expand Down Expand Up @@ -76,7 +75,7 @@ template <typename T> static std::string loc(T *node) {

/// Dispatch to a generic expressions to the appropriate subclass using RTTI
void ASTDumper::dump(ExprAST *expr) {
mlir::TypeSwitch<ExprAST *>(expr)
llvm::TypeSwitch<ExprAST *>(expr)
.Case<BinaryExprAST, CallExprAST, LiteralExprAST, NumberExprAST,
PrintExprAST, ReturnExprAST, VarDeclExprAST, VariableExprAST>(
[&](auto *node) { this->dump(node); })
Expand Down Expand Up @@ -127,12 +126,12 @@ void printLitHelper(ExprAST *litOrNum) {

// Print the dimension for this literal first
llvm::errs() << "<";
mlir::interleaveComma(literal->getDims(), llvm::errs());
llvm::interleaveComma(literal->getDims(), llvm::errs());
llvm::errs() << ">";

// Now print the content, recursing on every element of the list
llvm::errs() << "[ ";
mlir::interleaveComma(literal->getValues(), llvm::errs(),
llvm::interleaveComma(literal->getValues(), llvm::errs(),
[&](auto &elt) { printLitHelper(elt.get()); });
llvm::errs() << "]";
}
Expand Down Expand Up @@ -194,7 +193,7 @@ void ASTDumper::dump(PrintExprAST *node) {
/// Print type: only the shape is printed in between '<' and '>'
void ASTDumper::dump(const VarType &type) {
llvm::errs() << "<";
mlir::interleaveComma(type.shape, llvm::errs());
llvm::interleaveComma(type.shape, llvm::errs());
llvm::errs() << ">";
}

Expand All @@ -205,7 +204,7 @@ void ASTDumper::dump(PrototypeAST *node) {
llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
indent();
llvm::errs() << "Params: [";
mlir::interleaveComma(node->getArgs(), llvm::errs(),
llvm::interleaveComma(node->getArgs(), llvm::errs(),
[](auto &arg) { llvm::errs() << arg->getName(); });
llvm::errs() << "]\n";
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch7/mlir/Dialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void ToyDialect::printType(mlir::Type type,

// Print the struct type according to the parser format.
printer << "struct<";
mlir::interleaveComma(structType.getElementTypes(), printer);
llvm::interleaveComma(structType.getElementTypes(), printer);
printer << '>';
}

Expand Down
13 changes: 6 additions & 7 deletions mlir/examples/toy/Ch7/parser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "toy/AST.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"

using namespace toy;
Expand Down Expand Up @@ -78,7 +77,7 @@ template <typename T> static std::string loc(T *node) {

/// Dispatch to a generic expressions to the appropriate subclass using RTTI
void ASTDumper::dump(ExprAST *expr) {
mlir::TypeSwitch<ExprAST *>(expr)
llvm::TypeSwitch<ExprAST *>(expr)
.Case<BinaryExprAST, CallExprAST, LiteralExprAST, NumberExprAST,
PrintExprAST, ReturnExprAST, StructLiteralExprAST, VarDeclExprAST,
VariableExprAST>([&](auto *node) { this->dump(node); })
Expand Down Expand Up @@ -130,12 +129,12 @@ void printLitHelper(ExprAST *litOrNum) {

// Print the dimension for this literal first
llvm::errs() << "<";
mlir::interleaveComma(literal->getDims(), llvm::errs());
llvm::interleaveComma(literal->getDims(), llvm::errs());
llvm::errs() << ">";

// Now print the content, recursing on every element of the list
llvm::errs() << "[ ";
mlir::interleaveComma(literal->getValues(), llvm::errs(),
llvm::interleaveComma(literal->getValues(), llvm::errs(),
[&](auto &elt) { printLitHelper(elt.get()); });
llvm::errs() << "]";
}
Expand Down Expand Up @@ -210,7 +209,7 @@ void ASTDumper::dump(const VarType &type) {
if (!type.name.empty())
llvm::errs() << type.name;
else
mlir::interleaveComma(type.shape, llvm::errs());
llvm::interleaveComma(type.shape, llvm::errs());
llvm::errs() << ">";
}

Expand All @@ -221,7 +220,7 @@ void ASTDumper::dump(PrototypeAST *node) {
llvm::errs() << "Proto '" << node->getName() << "' " << loc(node) << "'\n";
indent();
llvm::errs() << "Params: [";
mlir::interleaveComma(node->getArgs(), llvm::errs(),
llvm::interleaveComma(node->getArgs(), llvm::errs(),
[](auto &arg) { llvm::errs() << arg->getName(); });
llvm::errs() << "]\n";
}
Expand Down
6 changes: 3 additions & 3 deletions mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,16 @@ class StructType : public Type::TypeBase<StructType, CompositeType,

/// Range class for element types.
class ElementTypeRange
: public ::mlir::detail::indexed_accessor_range_base<
: public ::llvm::detail::indexed_accessor_range_base<
ElementTypeRange, const Type *, Type, Type, Type> {
private:
using RangeBaseT::RangeBaseT;

/// See `mlir::detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static const Type *offset_base(const Type *object, ptrdiff_t index) {
return object + index;
}
/// See `mlir::detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static Type dereference_iterator(const Type *object, ptrdiff_t index) {
return object[index];
}
Expand Down
14 changes: 8 additions & 6 deletions mlir/include/mlir/IR/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,14 @@ using DenseIterPtrAndSplat =
template <typename ConcreteT, typename T, typename PointerT = T *,
typename ReferenceT = T &>
class DenseElementIndexedIteratorImpl
: public indexed_accessor_iterator<ConcreteT, DenseIterPtrAndSplat, T,
PointerT, ReferenceT> {
: public llvm::indexed_accessor_iterator<ConcreteT, DenseIterPtrAndSplat, T,
PointerT, ReferenceT> {
protected:
DenseElementIndexedIteratorImpl(const char *data, bool isSplat,
size_t dataIndex)
: indexed_accessor_iterator<ConcreteT, DenseIterPtrAndSplat, T, PointerT,
ReferenceT>({data, isSplat}, dataIndex) {}
: llvm::indexed_accessor_iterator<ConcreteT, DenseIterPtrAndSplat, T,
PointerT, ReferenceT>({data, isSplat},
dataIndex) {}

/// Return the current index for this iterator, adjusted for the case of a
/// splat.
Expand Down Expand Up @@ -746,8 +747,9 @@ class DenseElementsAttr
/// A utility iterator that allows walking over the internal Attribute values
/// of a DenseElementsAttr.
class AttributeElementIterator
: public indexed_accessor_iterator<AttributeElementIterator, const void *,
Attribute, Attribute, Attribute> {
: public llvm::indexed_accessor_iterator<AttributeElementIterator,
const void *, Attribute,
Attribute, Attribute> {
public:
/// Accesses the Attribute value at this iterator position.
Attribute operator*() const;
Expand Down
8 changes: 4 additions & 4 deletions mlir/include/mlir/IR/BlockSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ class PredecessorIterator final

/// This class implements the successor iterators for Block.
class SuccessorRange final
: public detail::indexed_accessor_range_base<SuccessorRange, BlockOperand *,
Block *, Block *, Block *> {
: public llvm::detail::indexed_accessor_range_base<
SuccessorRange, BlockOperand *, Block *, Block *, Block *> {
public:
using RangeBaseT::RangeBaseT;
SuccessorRange(Block *block);
SuccessorRange(Operation *term);

private:
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static BlockOperand *offset_base(BlockOperand *object, ptrdiff_t index) {
return object + index;
}
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static Block *dereference_iterator(BlockOperand *object, ptrdiff_t index) {
return object[index].get();
}
Expand Down
6 changes: 2 additions & 4 deletions mlir/include/mlir/IR/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define MLIR_IR_DIAGNOSTICS_H

#include "mlir/IR/Location.h"
#include "mlir/Support/STLExtras.h"
#include <functional>

namespace llvm {
Expand Down Expand Up @@ -232,9 +231,8 @@ class Diagnostic {
/// is ','.
template <typename T, template <typename> class Container>
Diagnostic &appendRange(const Container<T> &c, const char *delim = ", ") {
interleave(
c, [&](const detail::ValueOfRange<Container<T>> &a) { *this << a; },
[&]() { *this << delim; });
llvm::interleave(
c, [this](const auto &a) { *this << a; }, [&]() { *this << delim; });
return *this;
}

Expand Down
14 changes: 8 additions & 6 deletions mlir/include/mlir/IR/Matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,20 @@ using has_operation_or_value_matcher_t =

/// Statically switch to a Value matcher.
template <typename MatcherClass>
typename std::enable_if_t<is_detected<detail::has_operation_or_value_matcher_t,
MatcherClass, Value>::value,
bool>
typename std::enable_if_t<
llvm::is_detected<detail::has_operation_or_value_matcher_t, MatcherClass,
Value>::value,
bool>
matchOperandOrValueAtIndex(Operation *op, unsigned idx, MatcherClass &matcher) {
return matcher.match(op->getOperand(idx));
}

/// Statically switch to an Operation matcher.
template <typename MatcherClass>
typename std::enable_if_t<is_detected<detail::has_operation_or_value_matcher_t,
MatcherClass, Operation *>::value,
bool>
typename std::enable_if_t<
llvm::is_detected<detail::has_operation_or_value_matcher_t, MatcherClass,
Operation *>::value,
bool>
matchOperandOrValueAtIndex(Operation *op, unsigned idx, MatcherClass &matcher) {
if (auto defOp = op->getOperand(idx).getDefiningOp())
return matcher.match(defOp);
Expand Down
8 changes: 4 additions & 4 deletions mlir/include/mlir/IR/OpDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -1298,16 +1298,16 @@ class Op : public OpState,
/// If 'T' is the same interface as 'interfaceID' return the concept
/// instance.
template <typename T>
static typename std::enable_if<is_detected<has_get_interface_id, T>::value,
void *>::type
static typename std::enable_if<
llvm::is_detected<has_get_interface_id, T>::value, void *>::type
lookup(TypeID interfaceID) {
return (T::getInterfaceID() == interfaceID) ? &T::instance() : nullptr;
}

/// 'T' is known to not be an interface, return nullptr.
template <typename T>
static typename std::enable_if<!is_detected<has_get_interface_id, T>::value,
void *>::type
static typename std::enable_if<
!llvm::is_detected<has_get_interface_id, T>::value, void *>::type
lookup(TypeID) {
return nullptr;
}
Expand Down
10 changes: 5 additions & 5 deletions mlir/include/mlir/IR/OpImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ class OpAsmPrinter {
void printArrowTypeList(TypeRange &&types) {
auto &os = getStream() << " -> ";

bool wrapped = !has_single_element(types) ||
bool wrapped = !llvm::hasSingleElement(types) ||
(*types.begin()).template isa<FunctionType>();
if (wrapped)
os << '(';
interleaveComma(types, *this);
llvm::interleaveComma(types, *this);
if (wrapped)
os << ')';
}
Expand All @@ -131,7 +131,7 @@ class OpAsmPrinter {
void printFunctionalType(InputRangeT &&inputs, ResultRangeT &&results) {
auto &os = getStream();
os << "(";
interleaveComma(inputs, *this);
llvm::interleaveComma(inputs, *this);
os << ")";
printArrowTypeList(results);
}
Expand Down Expand Up @@ -199,11 +199,11 @@ inline OpAsmPrinter &operator<<(OpAsmPrinter &p, Block *value) {
template <typename ValueRangeT>
inline OpAsmPrinter &operator<<(OpAsmPrinter &p,
const ValueTypeRange<ValueRangeT> &types) {
interleaveComma(types, p);
llvm::interleaveComma(types, p);
return p;
}
inline OpAsmPrinter &operator<<(OpAsmPrinter &p, ArrayRef<Type> types) {
interleaveComma(types, p);
llvm::interleaveComma(types, p);
return p;
}

Expand Down
31 changes: 15 additions & 16 deletions mlir/include/mlir/IR/OperationSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class OpPrintingFlags {
/// suitable for a more derived type (e.g. ArrayRef) or a template range
/// parameter.
class TypeRange
: public detail::indexed_accessor_range_base<
: public llvm::detail::indexed_accessor_range_base<
TypeRange,
llvm::PointerUnion<const Value *, const Type *, OpOperand *>, Type,
Type, Type> {
Expand Down Expand Up @@ -589,9 +589,9 @@ class TypeRange
/// * A pointer to the first element of an array of operands.
using OwnerT = llvm::PointerUnion<const Value *, const Type *, OpOperand *>;

/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static OwnerT offset_base(OwnerT object, ptrdiff_t index);
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static Type dereference_iterator(OwnerT object, ptrdiff_t index);

/// Allow access to `offset_base` and `dereference_iterator`.
Expand Down Expand Up @@ -640,9 +640,8 @@ inline bool operator==(ArrayRef<Type> lhs, const ValueTypeRange<RangeT> &rhs) {
// OperandRange

/// This class implements the operand iterators for the Operation class.
class OperandRange final
: public detail::indexed_accessor_range_base<OperandRange, OpOperand *,
Value, Value, Value> {
class OperandRange final : public llvm::detail::indexed_accessor_range_base<
OperandRange, OpOperand *, Value, Value, Value> {
public:
using RangeBaseT::RangeBaseT;
OperandRange(Operation *op);
Expand All @@ -658,11 +657,11 @@ class OperandRange final
unsigned getBeginOperandIndex() const;

private:
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static OpOperand *offset_base(OpOperand *object, ptrdiff_t index) {
return object + index;
}
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static Value dereference_iterator(OpOperand *object, ptrdiff_t index) {
return object[index].get();
}
Expand All @@ -676,8 +675,8 @@ class OperandRange final

/// This class implements the result iterators for the Operation class.
class ResultRange final
: public indexed_accessor_range<ResultRange, Operation *, OpResult,
OpResult, OpResult> {
: public llvm::indexed_accessor_range<ResultRange, Operation *, OpResult,
OpResult, OpResult> {
public:
using indexed_accessor_range<ResultRange, Operation *, OpResult, OpResult,
OpResult>::indexed_accessor_range;
Expand All @@ -690,12 +689,12 @@ class ResultRange final
auto getType() const { return getTypes(); }

private:
/// See `indexed_accessor_range` for details.
/// See `llvm::indexed_accessor_range` for details.
static OpResult dereference(Operation *op, ptrdiff_t index);

/// Allow access to `dereference_iterator`.
friend indexed_accessor_range<ResultRange, Operation *, OpResult, OpResult,
OpResult>;
friend llvm::indexed_accessor_range<ResultRange, Operation *, OpResult,
OpResult, OpResult>;
};

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -730,7 +729,7 @@ struct ValueRangeOwner {
/// suitable for a more derived type (e.g. ArrayRef) or a template range
/// parameter.
class ValueRange final
: public detail::indexed_accessor_range_base<
: public llvm::detail::indexed_accessor_range_base<
ValueRange, detail::ValueRangeOwner, Value, Value, Value> {
public:
using RangeBaseT::RangeBaseT;
Expand Down Expand Up @@ -762,9 +761,9 @@ class ValueRange final
private:
using OwnerT = detail::ValueRangeOwner;

/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static OwnerT offset_base(const OwnerT &owner, ptrdiff_t index);
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static Value dereference_iterator(const OwnerT &owner, ptrdiff_t index);

/// Allow access to `offset_base` and `dereference_iterator`.
Expand Down
6 changes: 3 additions & 3 deletions mlir/include/mlir/IR/Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Region {
/// suitable for a more derived type (e.g. ArrayRef) or a template range
/// parameter.
class RegionRange
: public detail::indexed_accessor_range_base<
: public llvm::detail::indexed_accessor_range_base<
RegionRange, PointerUnion<Region *, const std::unique_ptr<Region> *>,
Region *, Region *, Region *> {
/// The type representing the owner of this range. This is either a list of
Expand All @@ -178,9 +178,9 @@ class RegionRange
RegionRange(ArrayRef<std::unique_ptr<Region>> regions);

private:
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static OwnerT offset_base(const OwnerT &owner, ptrdiff_t index);
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
static Region *dereference_iterator(const OwnerT &owner, ptrdiff_t index);

/// Allow access to `offset_base` and `dereference_iterator`.
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/IR/UseDefLists.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class IRMultiObjectWithUseList : public IRObjectWithUseList<OperandType> {
return {use_begin(value), use_end(value)};
}
bool hasOneUse(ValueType value) const {
return mlir::has_single_element(getUses(value));
return llvm::hasSingleElement(getUses(value));
}
bool use_empty(ValueType value) const {
return use_begin(value) == use_end(value);
Expand Down
4 changes: 2 additions & 2 deletions mlir/include/mlir/Pass/AnalysisManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ using has_is_invalidated = decltype(std::declval<T &>().isInvalidated(

/// Implementation of 'isInvalidated' if the analysis provides a definition.
template <typename AnalysisT>
std::enable_if_t<is_detected<has_is_invalidated, AnalysisT>::value, bool>
std::enable_if_t<llvm::is_detected<has_is_invalidated, AnalysisT>::value, bool>
isInvalidated(AnalysisT &analysis, const PreservedAnalyses &pa) {
return analysis.isInvalidated(pa);
}
/// Default implementation of 'isInvalidated'.
template <typename AnalysisT>
std::enable_if_t<!is_detected<has_is_invalidated, AnalysisT>::value, bool>
std::enable_if_t<!llvm::is_detected<has_is_invalidated, AnalysisT>::value, bool>
isInvalidated(AnalysisT &analysis, const PreservedAnalyses &pa) {
return !pa.isPreserved<AnalysisT>();
}
Expand Down
3 changes: 1 addition & 2 deletions mlir/include/mlir/Pass/PassOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "mlir/Support/LLVM.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -194,7 +193,7 @@ class PassOptions : protected llvm::cl::SubCommand {
auto printElementFn = [&](const DataType &value) {
printValue(os, this->getParser(), value);
};
interleave(*this, os, printElementFn, ",");
llvm::interleave(*this, os, printElementFn, ",");
}

/// Copy the value from the given option into this one.
Expand Down
3 changes: 3 additions & 0 deletions mlir/include/mlir/Support/LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ template <typename KeyT, typename ValueT, typename KeyInfoT, typename BucketT>
class DenseMap;
template <typename Fn> class function_ref;
template <typename IteratorT> class iterator_range;
template <typename T, typename ResultT> class TypeSwitch;

// Other common classes.
class raw_ostream;
Expand Down Expand Up @@ -88,6 +89,8 @@ using llvm::StringLiteral;
using llvm::StringRef;
using llvm::TinyPtrVector;
using llvm::Twine;
template <typename T, typename ResultT = void>
using TypeSwitch = llvm::TypeSwitch<T, ResultT>;

// Other common classes.
using llvm::APFloat;
Expand Down
472 changes: 0 additions & 472 deletions mlir/include/mlir/Support/STLExtras.h

This file was deleted.

15 changes: 7 additions & 8 deletions mlir/include/mlir/Support/StorageUniquer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#ifndef MLIR_SUPPORT_STORAGEUNIQUER_H
#define MLIR_SUPPORT_STORAGEUNIQUER_H

#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/DenseMap.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/Allocator.h"

Expand Down Expand Up @@ -215,7 +214,7 @@ class StorageUniquer {
/// 'ImplTy::getKey' function for the provided arguments.
template <typename ImplTy, typename... Args>
static typename std::enable_if<
is_detected<detail::has_impltype_getkey_t, ImplTy, Args...>::value,
llvm::is_detected<detail::has_impltype_getkey_t, ImplTy, Args...>::value,
typename ImplTy::KeyTy>::type
getKey(Args &&... args) {
return ImplTy::getKey(args...);
Expand All @@ -224,7 +223,7 @@ class StorageUniquer {
/// the 'ImplTy::KeyTy' with the provided arguments.
template <typename ImplTy, typename... Args>
static typename std::enable_if<
!is_detected<detail::has_impltype_getkey_t, ImplTy, Args...>::value,
!llvm::is_detected<detail::has_impltype_getkey_t, ImplTy, Args...>::value,
typename ImplTy::KeyTy>::type
getKey(Args &&... args) {
return typename ImplTy::KeyTy(args...);
Expand All @@ -238,17 +237,17 @@ class StorageUniquer {
/// instance if there is an 'ImplTy::hashKey' overload for 'DerivedKey'.
template <typename ImplTy, typename DerivedKey>
static typename std::enable_if<
is_detected<detail::has_impltype_hash_t, ImplTy, DerivedKey>::value,
llvm::is_detected<detail::has_impltype_hash_t, ImplTy, DerivedKey>::value,
::llvm::hash_code>::type
getHash(unsigned kind, const DerivedKey &derivedKey) {
return llvm::hash_combine(kind, ImplTy::hashKey(derivedKey));
}
/// If there is no 'ImplTy::hashKey' default to using the
/// 'llvm::DenseMapInfo' definition for 'DerivedKey' for generating a hash.
template <typename ImplTy, typename DerivedKey>
static typename std::enable_if<
!is_detected<detail::has_impltype_hash_t, ImplTy, DerivedKey>::value,
::llvm::hash_code>::type
static typename std::enable_if<!llvm::is_detected<detail::has_impltype_hash_t,
ImplTy, DerivedKey>::value,
::llvm::hash_code>::type
getHash(unsigned kind, const DerivedKey &derivedKey) {
return llvm::hash_combine(
kind, DenseMapInfo<DerivedKey>::getHashValue(derivedKey));
Expand Down
12 changes: 7 additions & 5 deletions mlir/include/mlir/Transforms/DialectConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TypeConverter {
/// Note: When attempting to convert a type, e.g. via 'convertType', the
/// mostly recently added conversions will be invoked first.
template <typename FnT,
typename T = typename FunctionTraits<FnT>::template arg_t<0>>
typename T = typename llvm::function_traits<FnT>::template arg_t<0>>
void addConversion(FnT &&callback) {
registerConversion(wrapCallback<T>(std::forward<FnT>(callback)));
}
Expand Down Expand Up @@ -172,7 +172,7 @@ class TypeConverter {
/// different callback forms, that all compose into a single version.
/// With callback of form: `Optional<Type>(T)`
template <typename T, typename FnT>
std::enable_if_t<is_invocable<FnT, T>::value, ConversionCallbackFn>
std::enable_if_t<llvm::is_invocable<FnT, T>::value, ConversionCallbackFn>
wrapCallback(FnT &&callback) {
return wrapCallback<T>([callback = std::forward<FnT>(callback)](
T type, SmallVectorImpl<Type> &results) {
Expand All @@ -187,7 +187,7 @@ class TypeConverter {
}
/// With callback of form: `Optional<LogicalResult>(T, SmallVectorImpl<> &)`
template <typename T, typename FnT>
std::enable_if_t<!is_invocable<FnT, T>::value, ConversionCallbackFn>
std::enable_if_t<!llvm::is_invocable<FnT, T>::value, ConversionCallbackFn>
wrapCallback(FnT &&callback) {
return [callback = std::forward<FnT>(callback)](
Type type,
Expand Down Expand Up @@ -482,7 +482,8 @@ class ConversionTarget {
addDynamicallyLegalOp<OpT2, OpTs...>(callback);
}
template <typename OpT, class Callable>
typename std::enable_if<!is_invocable<Callable, Operation *>::value>::type
typename std::enable_if<
!llvm::is_invocable<Callable, Operation *>::value>::type
addDynamicallyLegalOp(Callable &&callback) {
addDynamicallyLegalOp<OpT>(
[=](Operation *op) { return callback(cast<OpT>(op)); });
Expand Down Expand Up @@ -514,7 +515,8 @@ class ConversionTarget {
markOpRecursivelyLegal<OpT2, OpTs...>(callback);
}
template <typename OpT, class Callable>
typename std::enable_if<!is_invocable<Callable, Operation *>::value>::type
typename std::enable_if<
!llvm::is_invocable<Callable, Operation *>::value>::type
markOpRecursivelyLegal(Callable &&callback) {
markOpRecursivelyLegal<OpT>(
[=](Operation *op) { return callback(cast<OpT>(op)); });
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Analysis/AffineAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "mlir/IR/Function.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Analysis/SliceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "mlir/IR/Function.h"
#include "mlir/IR/Operation.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/SetVector.h"

///
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//

#include "../PassDetail.h"
#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h"
#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
Expand All @@ -27,6 +26,7 @@
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/Passes.h"
#include "mlir/Transforms/Utils.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Type.h"
Expand Down
7 changes: 4 additions & 3 deletions mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ struct AffineForEmptyLoopFolder : public OpRewritePattern<AffineForOp> {
LogicalResult matchAndRewrite(AffineForOp forOp,
PatternRewriter &rewriter) const override {
// Check that the body only contains a terminator.
if (!has_single_element(*forOp.getBody()))
if (!llvm::hasSingleElement(*forOp.getBody()))
return failure();
rewriter.eraseOp(forOp);
return success();
Expand Down Expand Up @@ -1576,7 +1576,8 @@ struct SimplifyDeadElse : public OpRewritePattern<AffineIfOp> {

LogicalResult matchAndRewrite(AffineIfOp ifOp,
PatternRewriter &rewriter) const override {
if (ifOp.elseRegion().empty() || !has_single_element(*ifOp.getElseBlock()))
if (ifOp.elseRegion().empty() ||
!llvm::hasSingleElement(*ifOp.getElseBlock()))
return failure();

rewriter.startRootUpdate(ifOp);
Expand Down Expand Up @@ -2303,7 +2304,7 @@ static void print(OpAsmPrinter &p, AffineParallelOp op) {
}
if (!elideSteps) {
p << " step (";
interleaveComma(steps, p);
llvm::interleaveComma(steps, p);
p << ')';
}
p.printRegion(op.region(), /*printEntryBlockArgs=*/false,
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ static void printAttributions(OpAsmPrinter &p, StringRef keyword,
return;

p << ' ' << keyword << '(';
interleaveComma(values, p,
[&p](BlockArgument v) { p << v << " : " << v.getType(); });
llvm::interleaveComma(
values, p, [&p](BlockArgument v) { p << v << " : " << v.getType(); });
p << ')';
}

Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void insertCopies(Region &region, Location loc, Value from, Value to) {
(void)toType;
assert(fromType.getShape() == toType.getShape());
assert(fromType.getRank() != 0);
assert(has_single_element(region) &&
assert(llvm::hasSingleElement(region) &&
"unstructured control flow not supported");

OpBuilder builder(region.getContext());
Expand Down
5 changes: 2 additions & 3 deletions mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/STLExtras.h"

#include "llvm/ADT/StringSet.h"
#include "llvm/Support/MathExtras.h"
Expand Down Expand Up @@ -1056,7 +1055,7 @@ static void appendMangledType(llvm::raw_string_ostream &ss, Type t) {
appendMangledType(ss, memref.getElementType());
} else if (auto vec = t.dyn_cast<VectorType>()) {
ss << "vector";
interleave(
llvm::interleave(
vec.getShape(), [&](int64_t i) { ss << i; }, [&]() { ss << "x"; });
appendMangledType(ss, vec.getElementType());
} else if (t.isSignlessIntOrIndexOrFloat()) {
Expand All @@ -1074,7 +1073,7 @@ std::string mlir::linalg::generateLibraryCallName(Operation *op) {
llvm::raw_string_ostream ss(name);
ss << "_";
auto types = op->getOperandTypes();
interleave(
llvm::interleave(
types.begin(), types.end(), [&](Type t) { appendMangledType(ss, t); },
[&]() { ss << "_"; });
return ss.str();
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/FoldUtils.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Support/CommandLine.h"
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/FoldUtils.h"

Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/FoldUtils.h"

#include "llvm/ADT/SetVector.h"
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/FoldUtils.h"

#include "llvm/Support/CommandLine.h"
Expand Down
5 changes: 2 additions & 3 deletions mlir/lib/Dialect/Linalg/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/FoldUtils.h"

using namespace mlir;
Expand All @@ -31,7 +30,7 @@ using namespace mlir::loop;
Optional<RegionMatcher::BinaryOpKind>
RegionMatcher::matchAsScalarBinaryOp(GenericOp op) {
auto &region = op.region();
if (!has_single_element(region))
if (!llvm::hasSingleElement(region))
return llvm::None;

Block &block = region.front();
Expand All @@ -41,7 +40,7 @@ RegionMatcher::matchAsScalarBinaryOp(GenericOp op) {
return llvm::None;

auto &ops = block.getOperations();
if (!has_single_element(block.without_terminator()))
if (!llvm::hasSingleElement(block.without_terminator()))
return llvm::None;

using mlir::matchers::m_Val;
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/Dialect/LoopOps/LoopOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "mlir/IR/StandardTypes.h"
#include "mlir/IR/Value.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Support/STLExtras.h"

using namespace mlir;
using namespace mlir::loop;
Expand Down Expand Up @@ -107,7 +106,7 @@ static void print(OpAsmPrinter &p, ForOp op) {
auto regionArgs = op.getRegionIterArgs();
auto operands = op.getIterOperands();

mlir::interleaveComma(llvm::zip(regionArgs, operands), p, [&](auto it) {
llvm::interleaveComma(llvm::zip(regionArgs, operands), p, [&](auto it) {
p << std::get<0>(it) << " = " << std::get<1>(it);
});
p << ")";
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Quant/IR/TypeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static void printUniformQuantizedPerAxisType(UniformQuantizedPerAxisType type,
ArrayRef<double> scales = type.getScales();
ArrayRef<int64_t> zeroPoints = type.getZeroPoints();
out << "{";
interleave(
llvm::interleave(
llvm::seq<size_t>(0, scales.size()), out,
[&](size_t index) {
printQuantParams(scales[index], zeroPoints[index], out);
Expand Down
14 changes: 7 additions & 7 deletions mlir/lib/Dialect/SPIRV/SPIRVDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,12 @@ static void print(StructType type, DialectAsmPrinter &os) {
auto eachFn = [&os](spirv::Decoration decoration) {
os << stringifyDecoration(decoration);
};
interleaveComma(decorations, os, eachFn);
llvm::interleaveComma(decorations, os, eachFn);
os << "]";
}
};
interleaveComma(llvm::seq<unsigned>(0, type.getNumElements()), os,
printMember);
llvm::interleaveComma(llvm::seq<unsigned>(0, type.getNumElements()), os,
printMember);
os << ">";
}

Expand Down Expand Up @@ -856,11 +856,11 @@ static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer) {
auto &os = printer.getStream();
printer << spirv::VerCapExtAttr::getKindName() << "<"
<< spirv::stringifyVersion(triple.getVersion()) << ", [";
interleaveComma(triple.getCapabilities(), os, [&](spirv::Capability cap) {
os << spirv::stringifyCapability(cap);
});
llvm::interleaveComma(
triple.getCapabilities(), os,
[&](spirv::Capability cap) { os << spirv::stringifyCapability(cap); });
printer << "], [";
interleaveComma(triple.getExtensionsAttr(), os, [&](Attribute attr) {
llvm::interleaveComma(triple.getExtensionsAttr(), os, [&](Attribute attr) {
os << attr.cast<StringAttr>().getValue();
});
printer << "]>";
Expand Down
8 changes: 4 additions & 4 deletions mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ static void print(spirv::BranchConditionalOp branchOp, OpAsmPrinter &printer) {

if (auto weights = branchOp.branch_weights()) {
printer << " [";
interleaveComma(weights->getValue(), printer, [&](Attribute a) {
llvm::interleaveComma(weights->getValue(), printer, [&](Attribute a) {
printer << a.cast<IntegerAttr>().getInt();
});
printer << "]";
Expand Down Expand Up @@ -1465,7 +1465,7 @@ static void print(spirv::EntryPointOp entryPointOp, OpAsmPrinter &printer) {
auto interfaceVars = entryPointOp.interface().getValue();
if (!interfaceVars.empty()) {
printer << ", ";
interleaveComma(interfaceVars, printer);
llvm::interleaveComma(interfaceVars, printer);
}
}

Expand Down Expand Up @@ -1521,7 +1521,7 @@ static void print(spirv::ExecutionModeOp execModeOp, OpAsmPrinter &printer) {
if (!values.size())
return;
printer << ", ";
interleaveComma(values, printer, [&](Attribute a) {
llvm::interleaveComma(values, printer, [&](Attribute a) {
printer << a.cast<IntegerAttr>().getInt();
});
}
Expand Down Expand Up @@ -1956,7 +1956,7 @@ static void print(spirv::LoopOp loopOp, OpAsmPrinter &printer) {
/// given `dstBlock`.
static inline bool hasOneBranchOpTo(Block &srcBlock, Block &dstBlock) {
// Check that there is only one op in the `srcBlock`.
if (!has_single_element(srcBlock))
if (!llvm::hasSingleElement(srcBlock))
return false;

auto branchOp = dyn_cast<spirv::BranchOp>(srcBlock.back());
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "mlir/Dialect/SPIRV/Serialization.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Dialect/SPIRV/SPIRVAttributes.h"
#include "mlir/Dialect/SPIRV/SPIRVBinaryUtils.h"
#include "mlir/Dialect/SPIRV/SPIRVDialect.h"
Expand All @@ -26,6 +25,7 @@
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/ADT/bit.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/Dialect/StandardOps/IR/Ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "mlir/IR/TypeUtilities.h"
#include "mlir/IR/Value.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/FormatVariadic.h"
Expand Down Expand Up @@ -499,7 +498,7 @@ struct SimplifyBrToBlockWithSinglePred : public OpRewritePattern<BranchOp> {
// Check that the successor block has a single predecessor.
Block *succ = op.getDest();
Block *opParent = op.getOperation()->getBlock();
if (succ == opParent || !has_single_element(succ->getPredecessors()))
if (succ == opParent || !llvm::hasSingleElement(succ->getPredecessors()))
return failure();

// Merge the successor into the current block and erase the branch.
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/Dialect/Vector/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/StringSet.h"
#include <numeric>

Expand Down Expand Up @@ -1512,7 +1511,7 @@ static void print(OpAsmPrinter &p, TupleOp op) {
p.printOperands(op.getOperands());
p.printOptionalAttrDict(op.getAttrs());
p << " : ";
interleaveComma(op.getOperation()->getOperandTypes(), p);
llvm::interleaveComma(op.getOperation()->getOperandTypes(), p);
}

static LogicalResult verify(TupleOp op) { return success(); }
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Vector/VectorTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "mlir/IR/OperationSupport.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/Types.h"
#include "mlir/Support/STLExtras.h"

#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Vector/VectorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "mlir/IR/Operation.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Support/STLExtras.h"

#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SetVector.h"
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/IR/AffineExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/STLExtras.h"

using namespace mlir;
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/IR/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
Expand Down Expand Up @@ -933,7 +932,7 @@ class ModulePrinter {

template <typename Container, typename UnaryFunctor>
inline void interleaveComma(const Container &c, UnaryFunctor each_fn) const {
mlir::interleaveComma(c, os, each_fn);
llvm::interleaveComma(c, os, each_fn);
}

/// This enum describes the different kinds of elision for the type of an
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ static bool hasSameElementsOrSplat(ShapedType type, const Values &values) {
/// Constructs a new iterator.
DenseElementsAttr::AttributeElementIterator::AttributeElementIterator(
DenseElementsAttr attr, size_t index)
: indexed_accessor_iterator<AttributeElementIterator, const void *,
Attribute, Attribute, Attribute>(
: llvm::indexed_accessor_iterator<AttributeElementIterator, const void *,
Attribute, Attribute, Attribute>(
attr.getAsOpaquePointer(), index) {}

/// Accesses the Attribute value at this iterator position.
Expand Down
11 changes: 6 additions & 5 deletions mlir/lib/IR/FunctionImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ static void printFunctionResultList(OpAsmPrinter &p, ArrayRef<Type> types,
types.size() > 1 || types[0].isa<FunctionType>() || !attrs[0].empty();
if (needsParens)
os << '(';
interleaveComma(llvm::zip(types, attrs), os,
[&](const std::tuple<Type, ArrayRef<NamedAttribute>> &t) {
p.printType(std::get<0>(t));
p.printOptionalAttrDict(std::get<1>(t));
});
llvm::interleaveComma(
llvm::zip(types, attrs), os,
[&](const std::tuple<Type, ArrayRef<NamedAttribute>> &t) {
p.printType(std::get<0>(t));
p.printOptionalAttrDict(std::get<1>(t));
});
if (needsParens)
os << ')';
}
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/IR/MLIRContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "mlir/IR/Location.h"
#include "mlir/IR/Module.h"
#include "mlir/IR/Types.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SetVector.h"
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/IR/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ LogicalResult ModuleOp::verify() {
auto &bodyRegion = getOperation()->getRegion(0);

// The body must contain a single basic block.
if (!has_single_element(bodyRegion))
if (!llvm::hasSingleElement(bodyRegion))
return emitOpError("expected body region to have a single block");

// Check that the body has no block arguments.
Expand Down
10 changes: 5 additions & 5 deletions mlir/lib/IR/OperationSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ TypeRange::TypeRange(ValueRange values) : TypeRange(OwnerT(), values.size()) {
this->base = owner.ptr.get<const Value *>();
}

/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
TypeRange::OwnerT TypeRange::offset_base(OwnerT object, ptrdiff_t index) {
if (auto *value = object.dyn_cast<const Value *>())
return {value + index};
if (auto *operand = object.dyn_cast<OpOperand *>())
return {operand + index};
return {object.dyn_cast<const Type *>() + index};
}
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
Type TypeRange::dereference_iterator(OwnerT object, ptrdiff_t index) {
if (auto *value = object.dyn_cast<const Value *>())
return (value + index)->getType();
Expand Down Expand Up @@ -198,7 +198,7 @@ ArrayRef<Type> ResultRange::getTypes() const {
return getBase()->getResultTypes();
}

/// See `indexed_accessor_range` for details.
/// See `llvm::indexed_accessor_range` for details.
OpResult ResultRange::dereference(Operation *op, ptrdiff_t index) {
return op->getResult(index);
}
Expand All @@ -215,7 +215,7 @@ ValueRange::ValueRange(ResultRange values)
{values.getBase(), static_cast<unsigned>(values.getStartIndex())},
values.size()) {}

/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
ValueRange::OwnerT ValueRange::offset_base(const OwnerT &owner,
ptrdiff_t index) {
if (auto *value = owner.ptr.dyn_cast<const Value *>())
Expand All @@ -225,7 +225,7 @@ ValueRange::OwnerT ValueRange::offset_base(const OwnerT &owner,
Operation *operation = reinterpret_cast<Operation *>(owner.ptr.get<void *>());
return {operation, owner.startIndex + static_cast<unsigned>(index)};
}
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
Value ValueRange::dereference_iterator(const OwnerT &owner, ptrdiff_t index) {
if (auto *value = owner.ptr.dyn_cast<const Value *>())
return value[index];
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/IR/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ RegionRange::RegionRange(MutableArrayRef<Region> regions)
RegionRange::RegionRange(ArrayRef<std::unique_ptr<Region>> regions)
: RegionRange(regions.data(), regions.size()) {}

/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
RegionRange::OwnerT RegionRange::offset_base(const OwnerT &owner,
ptrdiff_t index) {
if (auto *operand = owner.dyn_cast<const std::unique_ptr<Region> *>())
return operand + index;
return &owner.get<Region *>()[index];
}
/// See `detail::indexed_accessor_range_base` for details.
/// See `llvm::detail::indexed_accessor_range_base` for details.
Region *RegionRange::dereference_iterator(const OwnerT &owner,
ptrdiff_t index) {
if (auto *operand = owner.dyn_cast<const std::unique_ptr<Region> *>())
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/IR/StandardTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/Twine.h"

Expand Down
12 changes: 6 additions & 6 deletions mlir/lib/IR/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ SymbolTable::SymbolTable(Operation *symbolTableOp)
"expected operation to have SymbolTable trait");
assert(symbolTableOp->getNumRegions() == 1 &&
"expected operation to have a single region");
assert(has_single_element(symbolTableOp->getRegion(0)) &&
assert(llvm::hasSingleElement(symbolTableOp->getRegion(0)) &&
"expected operation to have a single block");

for (auto &op : symbolTableOp->getRegion(0).front()) {
Expand Down Expand Up @@ -290,7 +290,7 @@ LogicalResult OpTrait::impl::verifySymbolTable(Operation *op) {
if (op->getNumRegions() != 1)
return op->emitOpError()
<< "Operations with a 'SymbolTable' must have exactly one region";
if (!has_single_element(op->getRegion(0)))
if (!llvm::hasSingleElement(op->getRegion(0)))
return op->emitOpError()
<< "Operations with a 'SymbolTable' must have exactly one block";

Expand Down Expand Up @@ -477,8 +477,8 @@ struct SymbolScope {
/// 'walkSymbolUses'.
template <typename CallbackT,
typename std::enable_if_t<!std::is_same<
typename FunctionTraits<CallbackT>::result_t, void>::value> * =
nullptr>
typename llvm::function_traits<CallbackT>::result_t,
void>::value> * = nullptr>
Optional<WalkResult> walk(CallbackT cback) {
if (Region *region = limit.dyn_cast<Region *>())
return walkSymbolUses(*region, cback);
Expand All @@ -488,8 +488,8 @@ struct SymbolScope {
/// void(SymbolTable::SymbolUse use)
template <typename CallbackT,
typename std::enable_if_t<std::is_same<
typename FunctionTraits<CallbackT>::result_t, void>::value> * =
nullptr>
typename llvm::function_traits<CallbackT>::result_t,
void>::value> * = nullptr>
Optional<WalkResult> walk(CallbackT cback) {
return walk([=](SymbolTable::SymbolUse use, ArrayRef<int>) {
return cback(use), WalkResult::advance();
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "mlir/IR/Module.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
Expand Down
20 changes: 11 additions & 9 deletions mlir/lib/Pass/Pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ void Pass::copyOptionValuesFrom(const Pass *other) {
void Pass::printAsTextualPipeline(raw_ostream &os) {
// Special case for adaptors to use the 'op_name(sub_passes)' format.
if (auto *adaptor = getAdaptorPassBase(this)) {
interleaveComma(adaptor->getPassManagers(), os, [&](OpPassManager &pm) {
os << pm.getOpName() << "(";
pm.printAsTextualPipeline(os);
os << ")";
});
llvm::interleaveComma(adaptor->getPassManagers(), os,
[&](OpPassManager &pm) {
os << pm.getOpName() << "(";
pm.printAsTextualPipeline(os);
os << ")";
});
return;
}
// Otherwise, print the pass argument followed by its options. If the pass
Expand Down Expand Up @@ -295,9 +296,10 @@ void OpPassManager::printAsTextualPipeline(raw_ostream &os) {
impl->passes, [](const std::unique_ptr<Pass> &pass) {
return !isa<VerifierPass>(pass);
});
interleaveComma(filteredPasses, os, [&](const std::unique_ptr<Pass> &pass) {
pass->printAsTextualPipeline(os);
});
llvm::interleaveComma(filteredPasses, os,
[&](const std::unique_ptr<Pass> &pass) {
pass->printAsTextualPipeline(os);
});
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -358,7 +360,7 @@ void OpToOpPassAdaptorBase::mergeInto(OpToOpPassAdaptorBase &rhs) {
std::string OpToOpPassAdaptorBase::getName() {
std::string name = "Pipeline Collection : [";
llvm::raw_string_ostream os(name);
interleaveComma(getPassManagers(), os, [&](OpPassManager &pm) {
llvm::interleaveComma(getPassManagers(), os, [&](OpPassManager &pm) {
os << '\'' << pm.getOpName() << '\'';
});
os << ']';
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Pass/PassRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void detail::PassOptions::print(raw_ostream &os) {

// Interleave the options with ' '.
os << '{';
interleave(
llvm::interleave(
orderedOps, os, [&](OptionBase *option) { option->print(os); }, " ");
os << '}';
}
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/TableGen/OpTrait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

#include "mlir/TableGen/OpTrait.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/TableGen/OpInterfaces.h"
#include "mlir/TableGen/Predicate.h"
#include "llvm/ADT/StringExtras.h"
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/TableGen/Operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
//===----------------------------------------------------------------------===//

#include "mlir/TableGen/Operator.h"
#include "mlir/ADT/TypeSwitch.h"
#include "mlir/TableGen/OpTrait.h"
#include "mlir/TableGen/Predicate.h"
#include "mlir/TableGen/Type.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/TableGen/Error.h"
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/TableGen/Successor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//===----------------------------------------------------------------------===//

#include "mlir/TableGen/Successor.h"
#include "mlir/ADT/TypeSwitch.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/TableGen/Record.h"

using namespace mlir;
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/TableGen/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

#include "mlir/TableGen/Type.h"
#include "mlir/ADT/TypeSwitch.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/TableGen/Record.h"

using namespace mlir;
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#include "mlir/Target/LLVMIR/ModuleTranslation.h"

#include "DebugTranslation.h"
#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Module.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/TypeSwitch.h"

#include "llvm/ADT/SetVector.h"
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
Expand Down Expand Up @@ -316,7 +316,7 @@ ModuleTranslation::convertOmpOperation(Operation &opInst,
ompBuilder = std::make_unique<llvm::OpenMPIRBuilder>(*llvmModule);
ompBuilder->initialize();
}
return mlir::TypeSwitch<Operation *, LogicalResult>(&opInst)
return llvm::TypeSwitch<Operation *, LogicalResult>(&opInst)
.Case([&](omp::BarrierOp) {
ompBuilder->CreateBarrier(builder.saveIP(), llvm::omp::OMPD_barrier);
return success();
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Transforms/DialectConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ OperationLegalizer::legalizePattern(Operation *op, RewritePattern *pattern,
auto &os = rewriterImpl.logger;
os.getOStream() << "\n";
os.startLine() << "* Pattern : '" << pattern->getRootKind() << " -> (";
interleaveComma(pattern->getGeneratedOps(), llvm::dbgs());
llvm::interleaveComma(pattern->getGeneratedOps(), llvm::dbgs());
os.getOStream() << ")' {\n";
os.indent();
});
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Transforms/Utils/LoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ LogicalResult mlir::loopUnrollByFactor(AffineForOp forOp,
return promoteIfSingleIteration(forOp);

// Nothing in the loop body other than the terminator.
if (has_single_element(forOp.getBody()->getOperations()))
if (llvm::hasSingleElement(forOp.getBody()->getOperations()))
return success();

// Loops where the lower bound is a max expression isn't supported for
Expand Down Expand Up @@ -538,7 +538,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp,
return promoteIfSingleIteration(forOp);

// Nothing in the loop body other than the terminator.
if (has_single_element(forOp.getBody()->getOperations()))
if (llvm::hasSingleElement(forOp.getBody()->getOperations()))
return success();

// Loops where both lower and upper bounds are multi-result maps won't be
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Transforms/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "mlir/Transforms/Utils.h"

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Analysis/AffineAnalysis.h"
#include "mlir/Analysis/AffineStructures.h"
#include "mlir/Analysis/Dominance.h"
Expand All @@ -24,6 +23,7 @@
#include "mlir/IR/Module.h"
#include "mlir/Support/MathExtras.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/TypeSwitch.h"
using namespace mlir;

/// Return true if this operation dereferences one or more memref's.
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/Transforms/ViewOpGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "mlir/IR/Block.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/Support/CommandLine.h"

using namespace mlir;
Expand Down Expand Up @@ -65,7 +64,7 @@ std::string DOTGraphTraits<Block *>::getNodeLabel(Operation *op, Block *b) {
}

// Print resultant types
interleaveComma(op->getResultTypes(), os);
llvm::interleaveComma(op->getResultTypes(), os);
os << "\n";

// A value used to elide large container attribute.
Expand Down
3 changes: 1 addition & 2 deletions mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/Passes.h"

#include "llvm/ADT/STLExtras.h"
Expand Down Expand Up @@ -120,7 +119,7 @@ void VectorizerTestPass::testVectorShapeRatio(llvm::raw_ostream &outs) {
opInst->emitRemark("NOT MATCHED");
} else {
outs << "\nmatched: " << *opInst << " with shape ratio: ";
interleaveComma(MutableArrayRef<int64_t>(*ratio), outs);
llvm::interleaveComma(MutableArrayRef<int64_t>(*ratio), outs);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void PrintOpAvailability::runOnFunction() {
os << opName << " extensions: [";
for (const auto &exts : extension.getExtensions()) {
os << " [";
interleaveComma(exts, os, [&](spirv::Extension ext) {
llvm::interleaveComma(exts, os, [&](spirv::Extension ext) {
os << spirv::stringifyExtension(ext);
});
os << "]";
Expand All @@ -63,7 +63,7 @@ void PrintOpAvailability::runOnFunction() {
os << opName << " capabilities: [";
for (const auto &caps : capability.getCapabilities()) {
os << " [";
interleaveComma(caps, os, [&](spirv::Capability cap) {
llvm::interleaveComma(caps, os, [&](spirv::Capability cap) {
os << spirv::stringifyCapability(cap);
});
os << "]";
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Analysis/AffineAnalysis.h"
#include "mlir/Analysis/AffineStructures.h"
#include "mlir/Analysis/Utils.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Builders.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"

#define DEBUG_TYPE "memref-bound-check"
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void TestMemRefStrideCalculation::runOnFunction() {
else
llvm::outs() << offset;
llvm::outs() << " strides: ";
interleaveComma(strides, llvm::outs(), [&](int64_t v) {
llvm::interleaveComma(strides, llvm::outs(), [&](int64_t v) {
if (v == MemRefType::getDynamicStrideOrOffset())
llvm::outs() << "?";
else
Expand Down
64 changes: 33 additions & 31 deletions mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -1480,22 +1479,23 @@ void TCParser::printReferenceIterators(llvm::raw_ostream &os, StringRef opId,
std::string iteratorsStr;
llvm::raw_string_ostream ss(iteratorsStr);
unsigned pos = 0;
interleaveComma(state.dims, ss, [&](std::pair<StringRef, AffineExpr> p) {
bool reduction = false;
for (auto &expr : state.expressions) {
visitPostorder(*expr, [&](const Expression &e) {
if (auto *pTensorExpr = dyn_cast<TensorExpr>(&e)) {
if (pTensorExpr->reductionDimensions.count(pos) > 0)
reduction = true;
llvm::interleaveComma(
state.dims, ss, [&](std::pair<StringRef, AffineExpr> p) {
bool reduction = false;
for (auto &expr : state.expressions) {
visitPostorder(*expr, [&](const Expression &e) {
if (auto *pTensorExpr = dyn_cast<TensorExpr>(&e)) {
if (pTensorExpr->reductionDimensions.count(pos) > 0)
reduction = true;
}
});
if (reduction)
break;
}
ss << (reduction ? "getReductionIteratorTypeName()"
: "getParallelIteratorTypeName()");
pos++;
});
if (reduction)
break;
}
ss << (reduction ? "getReductionIteratorTypeName()"
: "getParallelIteratorTypeName()");
pos++;
});
ss.flush();

os << llvm::formatv(referenceReferenceIteratorsFmt, opId, iteratorsStr);
Expand All @@ -1515,16 +1515,17 @@ void TCParser::printReferenceIndexingMaps(llvm::raw_ostream &os, StringRef opId,

std::string dimsStr;
llvm::raw_string_ostream ss(dimsStr);
interleaveComma(state.dims, ss,
[&](std::pair<StringRef, AffineExpr> p) { ss << p.second; });
llvm::interleaveComma(
state.dims, ss,
[&](std::pair<StringRef, AffineExpr> p) { ss << p.second; });
ss.flush();

std::string mapsStr;
llvm::raw_string_ostream mapsStringStream(mapsStr);
SmallVector<TensorUse, 4> orderedUses(state.orderedTensorArgs.size());
for (auto it : state.orderedTensorArgs)
orderedUses[it.second] = it.first;
interleaveComma(orderedUses, mapsStringStream, [&](TensorUse u) {
llvm::interleaveComma(orderedUses, mapsStringStream, [&](TensorUse u) {
assert(u.indexingMap);
const char *mapFmt = "\n\tAffineMap::get({0}, 0, {1})";
if (u.indexingMap.isEmpty()) {
Expand All @@ -1535,7 +1536,7 @@ void TCParser::printReferenceIndexingMaps(llvm::raw_ostream &os, StringRef opId,
std::string exprsStr;
llvm::raw_string_ostream exprsStringStream(exprsStr);
exprsStringStream << "{";
interleaveComma(u.indexingMap.getResults(), exprsStringStream);
llvm::interleaveComma(u.indexingMap.getResults(), exprsStringStream);
exprsStringStream << "}";
exprsStringStream.flush();

Expand Down Expand Up @@ -1563,10 +1564,10 @@ void TCParser::printRegionBuilder(llvm::raw_ostream &os, StringRef opId,
} else {
std::string subExprs;
llvm::raw_string_ostream subExprsStringStream(subExprs);
interleaveComma(pTensorExpr->expressions, subExprsStringStream,
[&](const std::unique_ptr<Expression> &e) {
printExpr(subExprsStringStream, *e);
});
llvm::interleaveComma(pTensorExpr->expressions, subExprsStringStream,
[&](const std::unique_ptr<Expression> &e) {
printExpr(subExprsStringStream, *e);
});
subExprsStringStream.flush();
const char *tensorExprFmt = "\n ValueHandle _{0} = {1}({2});";
os << llvm::formatv(tensorExprFmt, ++count, pTensorExpr->opId, subExprs);
Expand All @@ -1586,10 +1587,11 @@ void TCParser::printRegionBuilder(llvm::raw_ostream &os, StringRef opId,
unsigned idx = 0;
std::string valueHandleStr;
llvm::raw_string_ostream valueHandleStringStream(valueHandleStr);
interleaveComma(state.orderedTensorArgs, valueHandleStringStream, [&](auto) {
valueHandleStringStream << "_" << idx << "(args[" << idx << "])";
idx++;
});
llvm::interleaveComma(
state.orderedTensorArgs, valueHandleStringStream, [&](auto) {
valueHandleStringStream << "_" << idx << "(args[" << idx << "])";
idx++;
});

std::string expressionsStr;
llvm::raw_string_ostream expressionStringStream(expressionsStr);
Expand All @@ -1601,10 +1603,10 @@ void TCParser::printRegionBuilder(llvm::raw_ostream &os, StringRef opId,

std::string yieldStr;
llvm::raw_string_ostream yieldStringStream(yieldStr);
interleaveComma(state.expressions, yieldStringStream,
[&](const std::unique_ptr<Expression> &e) {
printExpr(yieldStringStream, *e);
});
llvm::interleaveComma(state.expressions, yieldStringStream,
[&](const std::unique_ptr<Expression> &e) {
printExpr(yieldStringStream, *e);
});

valueHandleStringStream.flush();
expressionStringStream.flush();
Expand Down
1 change: 0 additions & 1 deletion mlir/tools/mlir-tblgen/DialectGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Support/STLExtras.h"
#include "mlir/Support/StringExtras.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
Expand Down
5 changes: 2 additions & 3 deletions mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Support/STLExtras.h"
#include "mlir/TableGen/GenInfo.h"

#include "llvm/ADT/SmallBitVector.h"
Expand Down Expand Up @@ -183,7 +182,7 @@ class LLVMIntrinsic {
template <typename Range>
void printBracketedRange(const Range &range, llvm::raw_ostream &os) {
os << '[';
mlir::interleaveComma(range, os);
llvm::interleaveComma(range, os);
os << ']';
}

Expand Down Expand Up @@ -213,7 +212,7 @@ static bool emitIntrinsic(const llvm::Record &record, llvm::raw_ostream &os) {
printBracketedRange(traits, os);
os << ", " << (intr.getNumResults() == 0 ? 0 : 1) << ">, Arguments<(ins"
<< (operands.empty() ? "" : " ");
mlir::interleaveComma(operands, os);
llvm::interleaveComma(operands, os);
os << ")>;\n\n";

return false;
Expand Down
23 changes: 12 additions & 11 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//

#include "OpFormatGen.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Support/StringExtras.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
Expand Down Expand Up @@ -1107,14 +1106,16 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder(OpMethodBody &body,
body << " " << builderOpState
<< ".addAttribute(\"operand_segment_sizes\", "
"odsBuilder->getI32VectorAttr({";
interleaveComma(llvm::seq<int>(0, op.getNumOperands()), body, [&](int i) {
if (op.getOperand(i).isOptional())
body << "(" << getArgumentName(op, i) << " ? 1 : 0)";
else if (op.getOperand(i).isVariadic())
body << "static_cast<int32_t>(" << getArgumentName(op, i) << ".size())";
else
body << "1";
});
llvm::interleaveComma(
llvm::seq<int>(0, op.getNumOperands()), body, [&](int i) {
if (op.getOperand(i).isOptional())
body << "(" << getArgumentName(op, i) << " ? 1 : 0)";
else if (op.getOperand(i).isVariadic())
body << "static_cast<int32_t>(" << getArgumentName(op, i)
<< ".size())";
else
body << "1";
});
body << "}));\n";
}

Expand Down Expand Up @@ -1212,7 +1213,7 @@ void OpEmitter::genOpInterfaceMethods() {
continue;
std::string args;
llvm::raw_string_ostream os(args);
mlir::interleaveComma(method.getArguments(), os,
llvm::interleaveComma(method.getArguments(), os,
[&](const OpInterfaceMethod::Argument &arg) {
os << arg.type << " " << arg.name;
});
Expand Down Expand Up @@ -1766,7 +1767,7 @@ static void emitOpClasses(const std::vector<Record *> &defs, raw_ostream &os,
static void emitOpList(const std::vector<Record *> &defs, raw_ostream &os) {
IfDefScope scope("GET_OP_LIST", os);

interleave(
llvm::interleave(
// TODO: We are constructing the Operator wrapper instance just for
// getting it's qualified class name here. Reduce the overhead by having a
// lightweight version of Operator class just for that purpose.
Expand Down
24 changes: 12 additions & 12 deletions mlir/tools/mlir-tblgen/OpFormatGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//===----------------------------------------------------------------------===//

#include "OpFormatGen.h"
#include "mlir/ADT/TypeSwitch.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
#include "mlir/TableGen/OpClass.h"
Expand All @@ -20,6 +18,7 @@
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Signals.h"
#include "llvm/TableGen/Error.h"
Expand Down Expand Up @@ -795,7 +794,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
body << " if (parser.resolveOperands(";
if (op.getNumOperands() > 1) {
body << "llvm::concat<const OpAsmParser::OperandType>(";
interleaveComma(op.getOperands(), body, [&](auto &operand) {
llvm::interleaveComma(op.getOperands(), body, [&](auto &operand) {
body << operand.name << "Operands";
});
body << ")";
Expand All @@ -815,11 +814,12 @@ void OperationFormat::genParserTypeResolution(Operator &op,
// the case of a single range, so guard it here.
if (op.getNumOperands() > 1) {
body << "llvm::concat<const Type>(";
interleaveComma(llvm::seq<int>(0, op.getNumOperands()), body, [&](int i) {
body << "ArrayRef<Type>(";
emitTypeResolver(operandTypes[i], op.getOperand(i).name);
body << ")";
});
llvm::interleaveComma(
llvm::seq<int>(0, op.getNumOperands()), body, [&](int i) {
body << "ArrayRef<Type>(";
emitTypeResolver(operandTypes[i], op.getOperand(i).name);
body << ")";
});
body << ")";
} else {
emitTypeResolver(operandTypes.front(), op.getOperand(0).name);
Expand Down Expand Up @@ -875,7 +875,7 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
else
body << "1";
};
interleaveComma(op.getOperands(), body, interleaveFn);
llvm::interleaveComma(op.getOperands(), body, interleaveFn);
body << "}));\n";
}
}
Expand All @@ -897,7 +897,7 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
// Elide the variadic segment size attributes if necessary.
if (!fmt.allOperands && op.getTrait("OpTrait::AttrSizedOperandSegments"))
body << "\"operand_segment_sizes\", ";
interleaveComma(usedAttributes, body, [&](const NamedAttribute *attr) {
llvm::interleaveComma(usedAttributes, body, [&](const NamedAttribute *attr) {
body << "\"" << attr->name << "\"";
});
body << "});\n";
Expand Down Expand Up @@ -1016,13 +1016,13 @@ static void genElementPrinter(Element *element, OpMethodBody &body,
} else if (auto *successor = dyn_cast<SuccessorVariable>(element)) {
const NamedSuccessor *var = successor->getVar();
if (var->isVariadic())
body << " interleaveComma(" << var->name << "(), p);\n";
body << " llvm::interleaveComma(" << var->name << "(), p);\n";
else
body << " p << " << var->name << "();\n";
} else if (isa<OperandsDirective>(element)) {
body << " p << getOperation()->getOperands();\n";
} else if (isa<SuccessorsDirective>(element)) {
body << " interleaveComma(getOperation()->getSuccessors(), p);\n";
body << " llvm::interleaveComma(getOperation()->getSuccessors(), p);\n";
} else if (auto *dir = dyn_cast<TypeDirective>(element)) {
body << " p << ";
genTypeOperandPrinter(dir->getOperand(), body) << ";\n";
Expand Down
21 changes: 10 additions & 11 deletions mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

#include "DocGenUtilities.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
#include "mlir/TableGen/OpInterfaces.h"
Expand All @@ -36,10 +35,10 @@ static void emitMethodNameAndArgs(const OpInterfaceMethod &method,
os << method.getName() << '(';
if (addOperationArg)
os << "Operation *tablegen_opaque_op" << (method.arg_empty() ? "" : ", ");
interleaveComma(method.getArguments(), os,
[&](const OpInterfaceMethod::Argument &arg) {
os << arg.type << " " << arg.name;
});
llvm::interleaveComma(method.getArguments(), os,
[&](const OpInterfaceMethod::Argument &arg) {
os << arg.type << " " << arg.name;
});
os << ')';
}

Expand Down Expand Up @@ -72,7 +71,7 @@ static void emitInterfaceDef(OpInterface &interface, raw_ostream &os) {
os << " {\n return getImpl()->" << method.getName() << '(';
if (!method.isStatic())
os << "getOperation()" << (method.arg_empty() ? "" : ", ");
interleaveComma(
llvm::interleaveComma(
method.getArguments(), os,
[&](const OpInterfaceMethod::Argument &arg) { os << arg.name; });
os << ");\n }\n";
Expand Down Expand Up @@ -135,7 +134,7 @@ static void emitModelDecl(OpInterface &interface, raw_ostream &os) {

// Add the arguments to the call.
os << method.getName() << '(';
interleaveComma(
llvm::interleaveComma(
method.getArguments(), os,
[&](const OpInterfaceMethod::Argument &arg) { os << arg.name; });
os << ");\n }\n";
Expand Down Expand Up @@ -255,10 +254,10 @@ static void emitInterfaceDoc(const Record &interfaceDef, raw_ostream &os) {
if (method.isStatic())
os << "static ";
emitCPPType(method.getReturnType(), os) << method.getName() << '(';
interleaveComma(method.getArguments(), os,
[&](const OpInterfaceMethod::Argument &arg) {
emitCPPType(arg.type, os) << arg.name;
});
llvm::interleaveComma(method.getArguments(), os,
[&](const OpInterfaceMethod::Argument &arg) {
emitCPPType(arg.type, os) << arg.name;
});
os << ");\n```\n";

// Emit the description.
Expand Down
3 changes: 1 addition & 2 deletions mlir/tools/mlir-tblgen/RewriterGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Support/STLExtras.h"
#include "mlir/TableGen/Attribute.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
Expand Down Expand Up @@ -500,7 +499,7 @@ void PatternEmitter::emit(StringRef rewriteName) {
llvm::sort(sortedResultOps, [&](const Operator *lhs, const Operator *rhs) {
return lhs->getOperationName() < rhs->getOperationName();
});
interleaveComma(sortedResultOps, os, [&](const Operator *op) {
llvm::interleaveComma(sortedResultOps, os, [&](const Operator *op) {
os << '"' << op->getOperationName() << '"';
});
os << formatv(R"(}, {0}, context) {{})", pattern.getBenefit()) << "\n";
Expand Down
3 changes: 1 addition & 2 deletions mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Support/STLExtras.h"
#include "mlir/Support/StringExtras.h"
#include "mlir/TableGen/Attribute.h"
#include "mlir/TableGen/Format.h"
Expand Down Expand Up @@ -1305,7 +1304,7 @@ static bool emitCapabilityImplication(const RecordKeeper &recordKeeper,
os << " case Capability::" << enumerant.getSymbol()
<< ": {static const Capability implies[" << impliedCapsDefs.size()
<< "] = {";
mlir::interleaveComma(impliedCapsDefs, os, [&](const Record *capDef) {
llvm::interleaveComma(impliedCapsDefs, os, [&](const Record *capDef) {
os << "Capability::" << EnumAttrCase(capDef).getSymbol();
});
os << "}; return ArrayRef<Capability>(implies, " << impliedCapsDefs.size()
Expand Down
5 changes: 0 additions & 5 deletions mlir/unittests/ADT/CMakeLists.txt

This file was deleted.

2 changes: 0 additions & 2 deletions mlir/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ function(add_mlir_unittest test_dirname)
add_unittest(MLIRUnitTests ${test_dirname} ${ARGN})
endfunction()

add_subdirectory(ADT)
add_subdirectory(Dialect)
add_subdirectory(IR)
add_subdirectory(Pass)
add_subdirectory(SDBM)
add_subdirectory(Support)
add_subdirectory(TableGen)
6 changes: 0 additions & 6 deletions mlir/unittests/Support/CMakeLists.txt

This file was deleted.