Skip to content

Commit

Permalink
Fix memory types for llvm-16 build
Browse files Browse the repository at this point in the history
.
  • Loading branch information
igorban-intel authored and sys-cmllvm committed Nov 26, 2024
1 parent 4daa8d1 commit 41fa581
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions GenXIntrinsics/include/llvm/GenXIntrinsics/GenXIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
29 changes: 28 additions & 1 deletion GenXIntrinsics/include/llvm/GenXIntrinsics/Intrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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

Expand Down Expand Up @@ -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<AttributeList>(AS, NumAttrs));\n"
Expand Down

0 comments on commit 41fa581

Please sign in to comment.