[mlir] Cleanup: Fix warnings in MLIR
authorMatthias Springer <springerm@google.com>
Fri, 6 Aug 2021 01:28:12 +0000 (10:28 +0900)
committerMatthias Springer <springerm@google.com>
Fri, 6 Aug 2021 01:36:37 +0000 (10:36 +0900)
Tested with gcc-10. Other compilers may generate additional warnings. This does not fix all warnings. There are a few extra ones in LLVMCore and MLIR.

* `OpEmitter::getAttrNameIndex`: -Wunused-function (function is private and not used anywhere)
* `PrintOpPass` copy constructor: -Wextra ("Base class should be explicitly initialized in the copy constructor")
* `LegalizeForLLVMExport.cpp`: -Woverflow (overflow is expected, silence warning by making the cast explicit)

Differential Revision: https://reviews.llvm.org/D107525

mlir/lib/Dialect/X86Vector/Transforms/LegalizeForLLVMExport.cpp
mlir/lib/Transforms/ViewOpGraph.cpp
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

index 6cd028a..c2a7a19 100644 (file)
@@ -115,7 +115,7 @@ struct DotOpConversion : public ConvertOpToLLVMPattern<DotOp> {
     auto opType = adaptor.a().getType();
     Type llvmIntType = IntegerType::get(&getTypeConverter()->getContext(), 8);
     // Dot product of all elements, broadcasted to all elements.
-    auto attr = rewriter.getI8IntegerAttr(0xff);
+    auto attr = rewriter.getI8IntegerAttr(static_cast<int8_t>(0xff));
     Value scale =
         rewriter.create<LLVM::ConstantOp>(op.getLoc(), llvmIntType, attr);
     rewriter.replaceOpWithNewOp<DotIntrOp>(op, opType, adaptor.a(), adaptor.b(),
index 199c5a3..641df28 100644 (file)
@@ -71,7 +71,7 @@ public:
 class PrintOpPass : public ViewOpGraphPassBase<PrintOpPass> {
 public:
   PrintOpPass(raw_ostream &os) : os(os) {}
-  PrintOpPass(const PrintOpPass &o) : os(o.os.getOStream()) {}
+  PrintOpPass(const PrintOpPass &o) : PrintOpPass(o.os.getOStream()) {}
 
   void runOnOperation() override {
     emitGraph([&]() {
index 1c630e0..2a85161 100644 (file)
@@ -341,10 +341,6 @@ private:
   // Generate methods for accessing the attribute names of this operation.
   void genAttrNameGetters();
 
-  // Return the index of the given attribute name. This is a relative ordering
-  // for this name, used in attribute getters.
-  unsigned getAttrNameIndex(StringRef attrName) const;
-
   // Generates the OpAsmOpInterface for this operation if possible.
   void genOpAsmInterface();
 
@@ -750,13 +746,6 @@ void OpEmitter::genAttrNameGetters() {
   }
 }
 
-unsigned OpEmitter::getAttrNameIndex(StringRef attrName) const {
-  auto it = attributeNames.find(attrName);
-  assert(it != attributeNames.end() && "expected attribute name to have been "
-                                       "registered in genAttrNameGetters");
-  return it->second;
-}
-
 void OpEmitter::genAttrGetters() {
   FmtContext fctx;
   fctx.withBuilder("::mlir::Builder((*this)->getContext())");