Skip to content

Commit 10fa8a8

Browse files
stepasitewsmoses
authored andcommitted
Attribute::Memory fixes (#7)
but still getting zeros instead of derivatives
1 parent b8c8938 commit 10fa8a8

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

enzyme/Enzyme/Enzyme.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,9 @@ class EnzymeBase {
20172017
#if LLVM_VERSION_MAJOR >= 16
20182018
Fn->setMemoryEffects(MemoryEffects::inaccessibleMemOnly());
20192019
CI->addAttribute(AttributeList::FunctionIndex,
2020-
Attribute::Memory);
2020+
Attribute::getWithMemoryEffects(
2021+
CI->getContext(),
2022+
MemoryEffects::inaccessibleMemOnly()));
20212023
#else
20222024
Fn->addFnAttr(Attribute::InaccessibleMemOnly);
20232025
CI->addAttribute(AttributeList::FunctionIndex,
@@ -2040,7 +2042,10 @@ class EnzymeBase {
20402042
if (Fn->getName() == "frexp" || Fn->getName() == "frexpf" ||
20412043
Fn->getName() == "frexpl") {
20422044
#if LLVM_VERSION_MAJOR >= 16
2043-
CI->addAttribute(AttributeList::FunctionIndex, Attribute::Memory);
2045+
CI->addAttribute(AttributeList::FunctionIndex,
2046+
Attribute::getWithMemoryEffects(
2047+
CI->getContext(),
2048+
MemoryEffects::argMemOnly()));
20442049
#else
20452050
CI->addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly);
20462051
#endif
@@ -2061,7 +2066,9 @@ class EnzymeBase {
20612066
#if LLVM_VERSION_MAJOR >= 16
20622067
Fn->setMemoryEffects(MemoryEffects::inaccessibleMemOnly());
20632068
CI->addAttribute(AttributeList::FunctionIndex,
2064-
Attribute::Memory);
2069+
Attribute::getWithMemoryEffects(
2070+
CI->getContext(),
2071+
MemoryEffects::inaccessibleMemOnly()));
20652072
#else
20662073
Fn->addFnAttr(Attribute::InaccessibleMemOnly);
20672074
CI->addAttribute(AttributeList::FunctionIndex,
@@ -2072,7 +2079,9 @@ class EnzymeBase {
20722079
#if LLVM_VERSION_MAJOR >= 16
20732080
Fn->setMemoryEffects(MemoryEffects::inaccessibleOrArgMemOnly());
20742081
CI->addAttribute(AttributeList::FunctionIndex,
2075-
Attribute::Memory);
2082+
Attribute::getWithMemoryEffects(
2083+
CI->getContext(),
2084+
MemoryEffects::inaccessibleOrArgMemOnly()));
20762085
#else
20772086
Fn->addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
20782087
CI->addAttribute(AttributeList::FunctionIndex,
@@ -2096,7 +2105,9 @@ class EnzymeBase {
20962105
#if LLVM_VERSION_MAJOR >= 16
20972106
Fn->setMemoryEffects(MemoryEffects::inaccessibleOrArgMemOnly());
20982107
CI->addAttribute(AttributeList::FunctionIndex,
2099-
Attribute::Memory);
2108+
Attribute::getWithMemoryEffects(
2109+
CI->getContext(),
2110+
MemoryEffects::inaccessibleOrArgMemOnly()));
21002111
#else
21012112
Fn->addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
21022113
CI->addAttribute(AttributeList::FunctionIndex,
@@ -2123,7 +2134,9 @@ class EnzymeBase {
21232134
#if LLVM_VERSION_MAJOR >= 16
21242135
Fn->setMemoryEffects(MemoryEffects::inaccessibleOrArgMemOnly());
21252136
CI->addAttribute(AttributeList::FunctionIndex,
2126-
Attribute::Memory);
2137+
Attribute::getWithMemoryEffects(
2138+
CI->getContext(),
2139+
MemoryEffects::inaccessibleOrArgMemOnly()));
21272140
#else
21282141
Fn->addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
21292142
CI->addAttribute(AttributeList::FunctionIndex,
@@ -2150,7 +2163,9 @@ class EnzymeBase {
21502163
#if LLVM_VERSION_MAJOR >= 16
21512164
Fn->setMemoryEffects(MemoryEffects::inaccessibleOrArgMemOnly());
21522165
CI->addAttribute(AttributeList::FunctionIndex,
2153-
Attribute::Memory);
2166+
Attribute::getWithMemoryEffects(
2167+
CI->getContext(),
2168+
MemoryEffects::inaccessibleOrArgMemOnly()));
21542169
#else
21552170
Fn->addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
21562171
CI->addAttribute(AttributeList::FunctionIndex,
@@ -2182,7 +2197,9 @@ class EnzymeBase {
21822197
#if LLVM_VERSION_MAJOR >= 16
21832198
Fn->setMemoryEffects(MemoryEffects::inaccessibleOrArgMemOnly());
21842199
CI->addAttribute(AttributeList::FunctionIndex,
2185-
Attribute::Memory);
2200+
Attribute::getWithMemoryEffects(
2201+
CI->getContext(),
2202+
MemoryEffects::inaccessibleOrArgMemOnly()));
21862203
#else
21872204
Fn->addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
21882205
CI->addAttribute(AttributeList::FunctionIndex,

enzyme/Enzyme/FunctionUtils.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,7 @@ Function *CreateMPIWrapper(Function *F) {
927927
Attribute::NoFree,
928928
Attribute::NoSync,
929929
#endif
930-
#if LLVM_VERSION_MAJOR >= 16
931-
Attribute::Memory
932-
#else
930+
#if LLVM_VERSION_MAJOR < 16
933931
Attribute::InaccessibleMemOnly
934932
#endif
935933
};
@@ -940,6 +938,11 @@ Function *CreateMPIWrapper(Function *F) {
940938
W->addAttribute(AttributeList::FunctionIndex, attr);
941939
#endif
942940
}
941+
#if LLVM_VERSION_MAJOR >= 16
942+
W->addFnAttr(Attribute::getWithMemoryEffects(
943+
F->getContext(),
944+
MemoryEffects::inaccessibleOrArgMemOnly()));
945+
#endif
943946
#if LLVM_VERSION_MAJOR >= 14
944947
W->addFnAttr(Attribute::get(F->getContext(), "enzyme_inactive"));
945948
#else

0 commit comments

Comments
 (0)