Skip to content

Commit 20eb73d

Browse files
skc7jeffdaily
authored andcommitted
[LLVM] Update apis incompatible with llvm versions in codegen (pytorch#110200)
Opaque pointers support is disabled in llvm 14 and enabled by default from llvm 15 and above. setOpaquePointers api usage is deprecated from llvm 16. Removed this API. Update CreateMalloc and CreateFree apis for latest llvm release. Pull Request resolved: pytorch#110200 Approved by: https://github.com/Skylion007
1 parent 55d2b79 commit 20eb73d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

torch/csrc/jit/tensorexpr/llvm_codegen.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ LLVMCodeGenImpl::LLVMCodeGenImpl(
491491
irb_(getContext()),
492492
kernel_func_name_(std::move(kernel_func_name)),
493493
bufsExtAlloc_(ExternalAllocBufFinder::find(stmt)) {
494-
#if LLVM_VERSION_MAJOR >= 15
495-
context_->setOpaquePointers(true);
496-
#endif
497494
if (!triple) {
498495
triple = LLVMTargetTriple();
499496
}
@@ -2573,14 +2570,18 @@ void LLVMCodeGenImpl::visit(AllocatePtr v) {
25732570
}
25742571
}
25752572

2573+
#if LLVM_VERSION_MAJOR > 17
2574+
llvm::Instruction* I = irb_.CreateMalloc(
2575+
LongTy_, dtypeToLLVM(v->dtype()), size, nullptr, nullptr, "");
2576+
#else
25762577
llvm::Instruction* I = llvm::CallInst::CreateMalloc(
25772578
irb_.GetInsertBlock(),
25782579
LongTy_,
25792580
dtypeToLLVM(v->dtype()),
25802581
size,
25812582
nullptr,
25822583
nullptr);
2583-
2584+
#endif
25842585
// Insert the bitcast into the block.
25852586
irb_.SetInsertPoint(irb_.GetInsertBlock());
25862587
llvm::Value* malloc = irb_.Insert(I);
@@ -2607,7 +2608,11 @@ void LLVMCodeGenImpl::visit(FreePtr v) {
26072608
: varToVal_.at(v->buffer_var());
26082609

26092610
if (!llvm::isa<llvm::AllocaInst>(ptr)) {
2611+
#if LLVM_VERSION_MAJOR > 17
2612+
irb_.Insert(irb_.CreateFree(ptr));
2613+
#else
26102614
irb_.Insert(llvm::CallInst::CreateFree(ptr, irb_.GetInsertBlock()));
2615+
#endif
26112616
}
26122617
}
26132618

0 commit comments

Comments
 (0)