From 41fa58112f00960da137b8ec76168b5a0321af33 Mon Sep 17 00:00:00 2001 From: "Gorban, Igor" Date: Thu, 31 Oct 2024 14:44:13 +0000 Subject: [PATCH] Fix memory types for llvm-16 build . --- .../llvm/GenXIntrinsics/GenXIntrinsics.h | 3 ++ .../include/llvm/GenXIntrinsics/Intrinsics.py | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/GenXIntrinsics/include/llvm/GenXIntrinsics/GenXIntrinsics.h b/GenXIntrinsics/include/llvm/GenXIntrinsics/GenXIntrinsics.h index b687ae9..acdcbf3 100644 --- a/GenXIntrinsics/include/llvm/GenXIntrinsics/GenXIntrinsics.h +++ b/GenXIntrinsics/include/llvm/GenXIntrinsics/GenXIntrinsics.h @@ -23,6 +23,9 @@ SPDX-License-Identifier: MIT #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Instructions.h" #include "llvm/GenXIntrinsics/GenXVersion.h" +#if LLVM_VERSION_MAJOR >= 16 +#include "llvm/Support/ModRef.h" +#endif namespace llvm { diff --git a/GenXIntrinsics/include/llvm/GenXIntrinsics/Intrinsics.py b/GenXIntrinsics/include/llvm/GenXIntrinsics/Intrinsics.py index 603840b..da41407 100755 --- a/GenXIntrinsics/include/llvm/GenXIntrinsics/Intrinsics.py +++ b/GenXIntrinsics/include/llvm/GenXIntrinsics/Intrinsics.py @@ -76,6 +76,12 @@ "SideEffects": set(["NoUnwind"]), } +modref_map = { + "ReadNone": "none", + "ReadOnly": "readOnly", + "WriteOnly": "writeOnly" +} + # order does really matter. # It is used to define ordering between the respected platforms platform_list = [ @@ -102,6 +108,21 @@ def getAttributeList(Attrs): s = reduce(lambda acc, v: attribute_map[v] | acc, Attrs, set()) return ['Attribute::'+x for x in sorted(s)] + +def getAttributeListModRef(Attrs): + """ + Takes a list of attribute names, calculates the union, + and returns a list of the the given attributes + """ + s = reduce(lambda acc, v: attribute_map[v] | acc, Attrs, set()) + attr = [] + for x in sorted(s): + if x in modref_map: + attr += ['addMemoryAttr(MemoryEffects::' + modref_map[x] + '())'] + else: + attr += ['addAttribute(Attribute::'+x+')'] + return attr + Intrinsics = dict() parse = sys.argv @@ -536,12 +557,18 @@ def createAttributeTable(): for i in range(len(attribute_Array)): #Building case statements Attrs = getAttributeList([x.strip() for x in attribute_Array[i].split(',')]) + AttrModRef = getAttributeListModRef([x.strip() for x in attribute_Array[i].split(',')]) f.write(""" case {num}: {{ + #if LLVM_VERSION_MAJOR >= 16 + AttrBuilder Atts(C); + Atts.{attrs_mod}; + #else const Attribute::AttrKind Atts[] = {{{attrs}}}; + #endif AS[0] = AttributeList::get(C, AttributeList::FunctionIndex, Atts); NumAttrs = 1; break; - }}\n""".format(num=i+1, attrs=','.join(Attrs))) + }}\n""".format(num=i+1, attrs_mod='.'.join(AttrModRef), attrs=','.join(Attrs))) f.write(" }\n" " }\n" " return AttributeList::get(C, ArrayRef(AS, NumAttrs));\n"