Skip to content

Commit 0c38d8d

Browse files
authored
Handle other address spaces on stack2heap (rust-lang#772)
1 parent 0d1c595 commit 0c38d8d

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

enzyme/Enzyme/FunctionUtils.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -310,30 +310,12 @@ static inline void UpgradeAllocasToMallocs(Function *NewF,
310310
IntegerType::get(AI->getContext(), 64),
311311
AI->getAlignment()))}));
312312

313-
#if LLVM_VERSION_MAJOR >= 14
314-
if (ConstantInt *size = dyn_cast<ConstantInt>(CI->getOperand(0))) {
315-
CI->addDereferenceableRetAttr(size->getLimitedValue());
316-
#if !defined(FLANG) && !defined(ROCM)
317-
AttrBuilder B(CI->getContext());
318-
#else
319-
AttrBuilder B;
320-
#endif
321-
B.addDereferenceableOrNullAttr(size->getLimitedValue());
322-
CI->setAttributes(
323-
CI->getAttributes().addRetAttributes(CI->getContext(), B));
324-
}
325-
CI->addAttributeAtIndex(AttributeList::ReturnIndex, Attribute::NoAlias);
326-
CI->addAttributeAtIndex(AttributeList::ReturnIndex, Attribute::NonNull);
327-
#else
328-
if (ConstantInt *size = dyn_cast<ConstantInt>(CI->getOperand(0))) {
329-
CI->addDereferenceableAttr(llvm::AttributeList::ReturnIndex,
330-
size->getLimitedValue());
331-
CI->addDereferenceableOrNullAttr(llvm::AttributeList::ReturnIndex,
332-
size->getLimitedValue());
333-
}
334-
CI->addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
335-
CI->addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
336-
#endif
313+
auto PT0 = cast<PointerType>(rep->getType());
314+
auto PT1 = cast<PointerType>(AI->getType());
315+
if (PT0->getAddressSpace() != PT1->getAddressSpace())
316+
rep = B.CreateAddrSpaceCast(rep,
317+
PointerType::get(PT0->getPointerElementType(),
318+
PT1->getAddressSpace()));
337319
assert(rep->getType() == AI->getType());
338320
AI->replaceAllUsesWith(rep);
339321
AI->eraseFromParent();

0 commit comments

Comments
 (0)