Skip to content

Commit

Permalink
Enablement of GenISAIntrinsics target on LLVM16
Browse files Browse the repository at this point in the history
Enablement of GenISAIntrinsics target on LLVM16

* Updated ShiftAmount of UnsignedDivisionByConstantInfo calculation based on https://reviews.llvm.org/D141014
* Used newer API (isKillLocation) in getVariableLocation
* Updated LLVMWrapper for InlineFunction and slightly refactored it
  • Loading branch information
bokrzesi authored and igcbot committed Aug 28, 2024
1 parent b2aefc8 commit 21ecde9
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion IGC/AdaptorCommon/DivergentBarrierPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ void DivergentBarrierPass::generateBody(
for (auto* CI : ContCalls)
{
InlineFunctionInfo IFI;
bool CanInline = IGCLLVM::InlineFunction(CI, IFI, nullptr, false);
bool CanInline = IGCLLVM::InlineFunction(*CI, IFI, nullptr, false);
IGC_ASSERT_MESSAGE(CanInline, "failed to inline?");
}

Expand Down
3 changes: 2 additions & 1 deletion IGC/Compiler/LegalizationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SPDX-License-Identifier: MIT
#include "GenISAIntrinsics/GenIntrinsicInst.h"
#include "Probe/Assertion.h"
#include "LLVM3DBuilder/BuiltinsFrontend.hpp"
#include "llvm/Support/Casting.h"


using namespace llvm;
Expand Down Expand Up @@ -2200,7 +2201,7 @@ void Legalization::visitIntrinsicInst(llvm::IntrinsicInst& I)
Value* result = (llvmBuilder.*replacementFunc)(argument);
InlineFunctionInfo IFI;
I.replaceAllUsesWith(result);
IGCLLVM::InlineFunction(static_cast<CallInst*>(result), IFI, nullptr, false);
IGCLLVM::InlineFunction(*cast<CallBase>(result), IFI, nullptr, false);
I.eraseFromParent();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ bool InlineUnmaskedFunctionsPass::runOnModule(llvm::Module& M)

llvm::InlineFunctionInfo IFI;
for (auto *CB : Calls)
IGCLLVM::InlineFunction(CB, IFI);
IGCLLVM::InlineFunction(*CB, IFI);

for (Function *F : Funcs) {
F->removeDeadConstantUsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3918,7 +3918,7 @@ static void fixBlockDataBeforeRemoval(BasicBlock *BB, BasicBlock *SuccBB) {
while (auto *DBG = dyn_cast<DbgVariableIntrinsic>(BB->begin())) {
DBG->moveBefore(InsertBefore);
if (!HasOnePred)
IGCLLVM::setDbgVariableLocationToUndef(DBG);
IGCLLVM::setKillLocation(DBG);
}
}

Expand Down
2 changes: 1 addition & 1 deletion IGC/VectorCompiler/lib/GenXCodeGen/GenXTidyControlFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void moveDbgBeforeBlockRemoval(BasicBlock *BB, Instruction *InsertBefore,
while (auto *DBG = dyn_cast<llvm::DbgVariableIntrinsic>(BB->begin())) {
DBG->moveBefore(InsertBefore);
if (MakeUndef)
IGCLLVM::setDbgVariableLocationToUndef(DBG);
IGCLLVM::setKillLocation(DBG);
}
IGC_ASSERT_MESSAGE(BB->front().isTerminator(), "Expected that only terminator instruction remains");
}
Expand Down
5 changes: 4 additions & 1 deletion IGC/WrapperLLVM/include/llvmWrapper/ADT/APInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ inline bool IsAddition(const UnsignedDivisionByConstantInfo &mu) {
}

inline unsigned ShiftAmount(const UnsignedDivisionByConstantInfo &mu) {
#if LLVM_VERSION_MAJOR >= 14
#if LLVM_VERSION_MAJOR >= 16
// Basing on this: https://reviews.llvm.org/D141014
return IsAddition(mu) ? mu.PostShift + 1 : mu.PostShift;
#elif LLVM_VERSION_MAJOR >= 14
return mu.ShiftAmount;
#else
return mu.s;
Expand Down
28 changes: 22 additions & 6 deletions IGC/WrapperLLVM/include/llvmWrapper/IR/IntrinsicInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,51 @@ SPDX-License-Identifier: MIT
#include <llvm/IR/Constants.h>
#include <llvm/IR/IntrinsicInst.h>
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Support/Casting.h"

#include "Probe/Assertion.h"

namespace IGCLLVM
{
inline bool isKillLocation(const llvm::DbgVariableIntrinsic* DbgInst)
{
IGC_ASSERT(DbgInst);
#if LLVM_VERSION_MAJOR <= 12
return llvm::dyn_cast<llvm::UndefValue>(DbgInst->getVariableLocation());
#elif LLVM_VERSION_MAJOR <= 15
return DbgInst->isUndef();
#else // LLVM_VERSION_MAJOR >= 16
return DbgInst->isKillLocation();
#endif
}

inline llvm::Value* getVariableLocation(const llvm::DbgVariableIntrinsic* DbgInst)
{
IGC_ASSERT(DbgInst);
#if LLVM_VERSION_MAJOR <= 12
return DbgInst->getVariableLocation();
#else
IGC_ASSERT_MESSAGE(((DbgInst->getNumVariableLocationOps() == 1) || DbgInst->isUndef()),
IGC_ASSERT_MESSAGE((DbgInst->getNumVariableLocationOps() == 1) || isKillLocation(DbgInst),
"unsupported number of location ops");
return DbgInst->getVariableLocationOp(0);
#endif
}

inline void setDbgVariableLocationToUndef(llvm::DbgVariableIntrinsic *DbgInst)
inline void setKillLocation(llvm::DbgVariableIntrinsic *DbgInst)
{
IGC_ASSERT(DbgInst);

#if LLVM_VERSION_MAJOR <= 12
auto *OP = DbgInst->getVariableLocation();
IGC_ASSERT_MESSAGE(OP != nullptr, "Empty dbg var not supported");

auto *Undef = llvm::UndefValue::get(OP->getType());
DbgInst->setOperand(
0, llvm::MetadataAsValue::get(DbgInst->getContext(),
llvm::ValueAsMetadata::get(Undef)));
#else
DbgInst->setOperand(0, llvm::MetadataAsValue::get(DbgInst->getContext(),
llvm::ValueAsMetadata::get(Undef)));
#elif LLVM_VERSION_MAJOR <= 15
DbgInst->setUndef();
#else // LLVM_VERSION_MAJOR >= 16
DbgInst->setKillLocation();
#endif
}

Expand Down
20 changes: 10 additions & 10 deletions IGC/WrapperLLVM/include/llvmWrapper/Transforms/Utils/Cloning.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ SPDX-License-Identifier: MIT

#include "llvm/Config/llvm-config.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Support/Casting.h"
#include "Probe/Assertion.h"

namespace IGCLLVM
{
inline bool InlineFunction(llvm::CallInst* CB, llvm::InlineFunctionInfo& IFI,
inline bool InlineFunction(llvm::CallBase& CB, llvm::InlineFunctionInfo& IFI,
llvm::AAResults* CalleeAAR = nullptr,
bool InsertLifetime = true,
llvm::Function* ForwardVarArgsTo = nullptr)
{
return llvm::InlineFunction(
#if LLVM_VERSION_MAJOR < 11
CB
#else
*llvm::dyn_cast<llvm::CallBase>(CB)
#endif
, IFI, CalleeAAR, InsertLifetime, ForwardVarArgsTo)
#if LLVM_VERSION_MAJOR >= 11
.isSuccess()
auto* CI = llvm::dyn_cast<llvm::CallInst>(&CB);
IGC_ASSERT(CI);
return llvm::InlineFunction(CI, IFI, CalleeAAR, InsertLifetime, ForwardVarArgsTo);
#elif LLVM_VERSION_MAJOR <= 15
return llvm::InlineFunction(CB, IFI, CalleeAAR, InsertLifetime, ForwardVarArgsTo).isSuccess();
#else // LLVM_VERSION_MAJOR >= 16
return llvm::InlineFunction(CB, IFI, true, CalleeAAR, InsertLifetime, ForwardVarArgsTo).isSuccess();
#endif
;
}

#if LLVM_VERSION_MAJOR < 13
Expand Down
2 changes: 1 addition & 1 deletion IGC/common/LLVMUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ void InlineHelper::InlineAndOptimize(CallInst* callInst)
auto* fn = callInst->getFunction();

InlineFunctionInfo IFI;
bool CanInline = IGCLLVM::InlineFunction(callInst, IFI);
bool CanInline = IGCLLVM::InlineFunction(*callInst, IFI);
IGC_ASSERT_MESSAGE(CanInline, "failed to inline?");

auto& perFnAllocas = m_InlinedStaticArrayAllocas[fn];
Expand Down

0 comments on commit 21ecde9

Please sign in to comment.