[Mlir-commits] [mlir] 12875ed - [mlir] generate enum translation functions with unused attribute

Alex Zinenko llvmlistbot at llvm.org
Thu Feb 18 00:44:48 PST 2021


Author: Alex Zinenko
Date: 2021-02-18T09:44:40+01:00
New Revision: 12875ed97607648b92595b7bf9a8ede550b25342

URL: https://github.com/llvm/llvm-project/commit/12875ed97607648b92595b7bf9a8ede550b25342
DIFF: https://github.com/llvm/llvm-project/commit/12875ed97607648b92595b7bf9a8ede550b25342.diff

LOG: [mlir] generate enum translation functions with unused attribute

The functions translating enums to LLVM IR are generated in a single
file included in many places, not all of which use all translations.
Generate functions with "unused" attribute to silence compiler warnings.

Reviewed By: mehdi_amini

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

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
    mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
    mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
index 5fbb291922f1..baf7107db80f 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
@@ -26,11 +26,6 @@ using namespace mlir;
 using namespace mlir::LLVM;
 using mlir::LLVM::detail::getLLVMConstant;
 
-// The include below has a static function unused in this translation unit,
-// declare it as such to silence a warning.
-static LLVM_ATTRIBUTE_UNUSED ::llvm::GlobalValue::LinkageTypes
-convertLinkageToLLVM(::mlir::LLVM::Linkage value);
-
 #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
 
 /// Convert MLIR integer comparison predicate to LLVM IR comparison predicate.

diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 73dc16c27559..d52cc78a48fc 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -46,11 +46,6 @@ using namespace mlir;
 using namespace mlir::LLVM;
 using namespace mlir::LLVM::detail;
 
-// The include below has a static function unused in this translation unit,
-// declare it as such to silence a warning.
-static LLVM_ATTRIBUTE_UNUSED ::llvm::InlineAsm::AsmDialect
-convertAsmDialectToLLVM(::mlir::LLVM::AsmDialect value);
-
 #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
 
 /// Builds a constant of a sequential LLVM type `type`, potentially containing

diff  --git a/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp b/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp
index 42b053a9ed64..06c2330a660d 100644
--- a/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp
+++ b/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp
@@ -222,8 +222,9 @@ static void emitOneEnumToConversion(const llvm::Record *record,
   StringRef cppNamespace = enumAttr.getCppNamespace();
 
   // Emit the function converting the enum attribute to its LLVM counterpart.
-  os << formatv("static {0} convert{1}ToLLVM({2}::{1} value) {{\n", llvmClass,
-                cppClassName, cppNamespace);
+  os << formatv(
+      "static LLVM_ATTRIBUTE_UNUSED {0} convert{1}ToLLVM({2}::{1} value) {{\n",
+      llvmClass, cppClassName, cppNamespace);
   os << "  switch (value) {\n";
 
   for (const auto &enumerant : enumAttr.getAllCases()) {
@@ -251,7 +252,8 @@ static void emitOneEnumFromConversion(const llvm::Record *record,
   StringRef cppNamespace = enumAttr.getCppNamespace();
 
   // Emit the function converting the enum attribute from its LLVM counterpart.
-  os << formatv("inline {0}::{1} convert{1}FromLLVM({2} value) {{\n",
+  os << formatv("inline LLVM_ATTRIBUTE_UNUSED {0}::{1} convert{1}FromLLVM({2} "
+                "value) {{\n",
                 cppNamespace, cppClassName, llvmClass);
   os << "  switch (value) {\n";
 


        


More information about the Mlir-commits mailing list