From 8d6fe3edeb4146e130a2bca3f4c96a7b5d1275dc Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Mon, 11 Nov 2024 10:08:47 -0500 Subject: [PATCH] [gccjit] clean up and add features from ABI 29 --- include/mlir-gccjit/Conversion/TypeConverter.h | 3 +-- include/mlir-gccjit/IR/GCCJITOps.td | 2 ++ src/Conversion/ConvertMemrefToGCCJIT.cpp | 1 - src/GCCJITOps.cpp | 2 ++ src/Translation/TranslateToGCCJIT.cpp | 8 ++++++++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/mlir-gccjit/Conversion/TypeConverter.h b/include/mlir-gccjit/Conversion/TypeConverter.h index bac909d..b77e56c 100644 --- a/include/mlir-gccjit/Conversion/TypeConverter.h +++ b/include/mlir-gccjit/Conversion/TypeConverter.h @@ -15,15 +15,14 @@ #ifndef MLIR_GCCJIT_CONVERSION_TYPECONVERTER_H #define MLIR_GCCJIT_CONVERSION_TYPECONVERTER_H -#include #include #include +#include #include #include #include "mlir-gccjit/IR/GCCJITAttrs.h" #include "mlir-gccjit/IR/GCCJITTypes.h" -#include "mlir/IR/MLIRContext.h" namespace mlir::gccjit { class GCCJITTypeConverter : public TypeConverter { diff --git a/include/mlir-gccjit/IR/GCCJITOps.td b/include/mlir-gccjit/IR/GCCJITOps.td index 1b5e8d5..08a9af9 100644 --- a/include/mlir-gccjit/IR/GCCJITOps.td +++ b/include/mlir-gccjit/IR/GCCJITOps.td @@ -305,6 +305,7 @@ def GlobalOp : GCCJIT_Op<"global", [IsolatedFromAbove]> { }]; let arguments = (ins GlbKind:$glb_kind, + UnitAttr:$readonly, SymbolNameAttr:$sym_name, TypeAttrOf:$type, OptionalAttr:$reg_name, @@ -317,6 +318,7 @@ def GlobalOp : GCCJIT_Op<"global", [IsolatedFromAbove]> { let regions = (region AnyRegion:$body); let assemblyFormat = [{ $glb_kind + custom($readonly) $sym_name oilist ( `reg` `(` qualified($reg_name) `)` | diff --git a/src/Conversion/ConvertMemrefToGCCJIT.cpp b/src/Conversion/ConvertMemrefToGCCJIT.cpp index 86ece3e..406c3b9 100644 --- a/src/Conversion/ConvertMemrefToGCCJIT.cpp +++ b/src/Conversion/ConvertMemrefToGCCJIT.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include #include diff --git a/src/GCCJITOps.cpp b/src/GCCJITOps.cpp index 81023b7..5912254 100644 --- a/src/GCCJITOps.cpp +++ b/src/GCCJITOps.cpp @@ -331,6 +331,8 @@ constexpr ParseNamedUnitAttr parseLazyAttribute{"lazy"}; constexpr PrintNamedUnitAttr printLazyAttribute{"lazy"}; constexpr ParseNamedUnitAttr parseWeakAttr{"weak"}; constexpr PrintNamedUnitAttr printWeakAttr{"weak"}; +constexpr ParseNamedUnitAttr parseReadOnlyAttr{"readonly"}; +constexpr PrintNamedUnitAttr printReadOnlyAttr{"readonly"}; ParseResult parseAsmOperands(OpAsmParser &parser, ArrayAttr &constrains, ArrayAttr &symbols, diff --git a/src/Translation/TranslateToGCCJIT.cpp b/src/Translation/TranslateToGCCJIT.cpp index f667f20..3704478 100644 --- a/src/Translation/TranslateToGCCJIT.cpp +++ b/src/Translation/TranslateToGCCJIT.cpp @@ -377,6 +377,14 @@ void GCCJITTranslation::declareAllFunctionAndGlobals() { gcc_jit_lvalue_add_string_attribute(globalHandle, GCC_JIT_VARIABLE_ATTRIBUTE_VISIBILITY, visibility->str().c_str()); + + if ([[maybe_unused]] auto readonly = global.getReadonly()) { +#ifdef LIBGCCJIT_HAVE_gcc_jit_global_set_readonly + gcc_jit_global_set_readonly(globalHandle); +#else + llvm_unreachable("gcc_jit_global_set_readonly is not available"); +#endif + } if (auto initializer = global.getInitializer()) { llvm::TypeSwitch(*initializer) .Case([&](StringAttr attr) {