gallium/swr: Fix LLVM 11 compilation issues

Changes needed to adapt to LLVM API changes in vector
and pointer types.

Reviewed-by: Krzysztof Raszkowski <krzysztof.raszkowski@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4769>
This commit is contained in:
Jan Zielinski 2020-04-27 22:05:35 +02:00 committed by Marge Bot
parent 5082ac007d
commit 4a523baa00
8 changed files with 156 additions and 35 deletions

View File

@ -52,7 +52,7 @@ intrinsics = [
['VPSHUFB', ['a', 'b'], 'a'],
['VPERMD', ['a', 'idx'], 'a'],
['VPERMPS', ['idx', 'a'], 'a'],
['VCVTPD2PS', ['a'], 'VectorType::get(mFP32Ty, a->getType()->getVectorNumElements())'],
['VCVTPD2PS', ['a'], 'VectorType::get(mFP32Ty, VEC_GET_NUM_ELEMS)'],
['VCVTPS2PH', ['a', 'round'], 'mSimdInt16Ty'],
['VHSUBPS', ['a', 'b'], 'a'],
['VPTESTC', ['a', 'b'], 'mInt32Ty'],
@ -258,7 +258,7 @@ def generate_meta_h(output_dir):
# determine the return type of the intrinsic. It can either be:
# - type of one of the input arguments
# - snippet of code to set the return type
if ret in args:
returnTy = ret + '->getType()'
else:

View File

@ -1,5 +1,5 @@
//============================================================================
// Copyright (C) 2014-2017 Intel Corporation. All Rights Reserved.
// Copyright (C) 2014-2020 Intel Corporation. All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -46,6 +46,11 @@ ${func['decl']}
%for arg in func['args']:
argTypes.push_back(${arg}->getType());
%endfor
#if LLVM_VERSION_MAJOR >= 11
#define VEC_GET_NUM_ELEMS cast<VectorType>(a->getType())->getNumElements()
#else
#define VEC_GET_NUM_ELEMS a->getType()->getVectorNumElements()
#endif
FunctionType* pFuncTy = FunctionType::get(${ func['returnType'] }, argTypes, false);
%else:
FunctionType* pFuncTy = FunctionType::get(${ func['returnType'] }, {}, false);

View File

@ -313,7 +313,11 @@ DIType* JitManager::GetDebugType(Type* pTy)
case Type::PointerTyID:
return builder.createPointerType(GetDebugType(pTy->getPointerElementType()), 64, 64);
break;
#if LLVM_VERSION_MAJOR >= 11
case Type::FixedVectorTyID:
#else
case Type::VectorTyID:
#endif
return GetDebugVectorType(pTy);
break;
case Type::FunctionTyID:
@ -382,11 +386,20 @@ DIType* JitManager::GetDebugVectorType(Type* pTy)
uint32_t size = DL.getTypeAllocSizeInBits(pVecTy);
uint32_t alignment = DL.getABITypeAlignment(pVecTy);
SmallVector<Metadata*, 1> Elems;
#if LLVM_VERSION_MAJOR >= 11
Elems.push_back(builder.getOrCreateSubrange(0, pVecTy->getNumElements()));
#else
Elems.push_back(builder.getOrCreateSubrange(0, pVecTy->getVectorNumElements()));
#endif
return builder.createVectorType(size,
alignment,
#if LLVM_VERSION_MAJOR >= 11
GetDebugType(pVecTy->getElementType()),
#else
GetDebugType(pVecTy->getVectorElementType()),
#endif
builder.getOrCreateArray(Elems));
}

View File

@ -652,11 +652,11 @@ namespace SwrJit
Value* pDst, Value* vSrc, Value* vOffsets, Value* vMask, MEM_CLIENT usage)
{
AssertMemoryUsageParams(pDst, usage);
// if (vSrc->getType() != mSimdFP32Ty)
// {
// vSrc = BITCAST(vSrc, mSimdFP32Ty);
// }
#if LLVM_VERSION_MAJOR >= 11
SWR_ASSERT(cast<VectorType>(vSrc->getType())->getElementType()->isFloatTy());
#else
SWR_ASSERT(vSrc->getType()->getVectorElementType()->isFloatTy());
#endif
VSCATTERPS(pDst, vMask, vOffsets, vSrc, C(1));
return;

View File

@ -320,14 +320,24 @@ namespace SwrJit
std::vector<Value*> args;
for (auto arg : argsList)
args.push_back(arg);
#if LLVM_VERSION_MAJOR >= 11
// see comment to CALLA(Callee) function in the header
return CALLA(FunctionCallee(cast<Function>(Callee)), args, name);
#else
return CALLA(Callee, args, name);
#endif
}
CallInst* Builder::CALL(Value* Callee, Value* arg)
{
std::vector<Value*> args;
args.push_back(arg);
#if LLVM_VERSION_MAJOR >= 11
// see comment to CALLA(Callee) function in the header
return CALLA(FunctionCallee(cast<Function>(Callee)), args);
#else
return CALLA(Callee, args);
#endif
}
CallInst* Builder::CALL2(Value* Callee, Value* arg1, Value* arg2)
@ -335,7 +345,12 @@ namespace SwrJit
std::vector<Value*> args;
args.push_back(arg1);
args.push_back(arg2);
#if LLVM_VERSION_MAJOR >= 11
// see comment to CALLA(Callee) function in the header
return CALLA(FunctionCallee(cast<Function>(Callee)), args);
#else
return CALLA(Callee, args);
#endif
}
CallInst* Builder::CALL3(Value* Callee, Value* arg1, Value* arg2, Value* arg3)
@ -344,7 +359,12 @@ namespace SwrJit
args.push_back(arg1);
args.push_back(arg2);
args.push_back(arg3);
#if LLVM_VERSION_MAJOR >= 11
// see comment to CALLA(Callee) function in the header
return CALLA(FunctionCallee(cast<Function>(Callee)), args);
#else
return CALLA(Callee, args);
#endif
}
Value* Builder::VRCP(Value* va, const llvm::Twine& name)
@ -391,7 +411,9 @@ namespace SwrJit
if (pType->isVectorTy())
{
Type* pContainedType = pType->getContainedType(0);
#if LLVM_VERSION_MAJOR >= 11
VectorType* pVectorType = cast<VectorType>(pType);
#endif
if (toupper(tempStr[pos + 1]) == 'X')
{
tempStr[pos] = '0';
@ -402,7 +424,11 @@ namespace SwrJit
printCallArgs.push_back(VEXTRACT(pArg, C(0)));
std::string vectorFormatStr;
#if LLVM_VERSION_MAJOR >= 11
for (uint32_t i = 1; i < pVectorType->getNumElements(); ++i)
#else
for (uint32_t i = 1; i < pType->getVectorNumElements(); ++i)
#endif
{
vectorFormatStr += "0x%08X ";
printCallArgs.push_back(VEXTRACT(pArg, C(i)));
@ -414,7 +440,11 @@ namespace SwrJit
else if ((tempStr[pos + 1] == 'f') && (pContainedType->isFloatTy()))
{
uint32_t i = 0;
for (; i < (pArg->getType()->getVectorNumElements()) - 1; i++)
#if LLVM_VERSION_MAJOR >= 11
for (; i < pVectorType->getNumElements() - 1; i++)
#else
for (; i < pType->getVectorNumElements() - 1; i++)
#endif
{
tempStr.insert(pos, std::string("%f "));
pos += 3;
@ -427,7 +457,11 @@ namespace SwrJit
else if ((tempStr[pos + 1] == 'd') && (pContainedType->isIntegerTy()))
{
uint32_t i = 0;
for (; i < (pArg->getType()->getVectorNumElements()) - 1; i++)
#if LLVM_VERSION_MAJOR >= 11
for (; i < pVectorType->getNumElements() - 1; i++)
#else
for (; i < pType->getVectorNumElements() - 1; i++)
#endif
{
tempStr.insert(pos, std::string("%d "));
pos += 3;
@ -440,7 +474,11 @@ namespace SwrJit
else if ((tempStr[pos + 1] == 'u') && (pContainedType->isIntegerTy()))
{
uint32_t i = 0;
for (; i < (pArg->getType()->getVectorNumElements()) - 1; i++)
#if LLVM_VERSION_MAJOR >= 11
for (; i < pVectorType->getNumElements() - 1; i++)
#else
for (; i < pType->getVectorNumElements() - 1; i++)
#endif
{
tempStr.insert(pos, std::string("%d "));
pos += 3;
@ -555,8 +593,14 @@ namespace SwrJit
/// @brief Convert <Nxi1> llvm mask to integer
Value* Builder::VMOVMSK(Value* mask)
{
#if LLVM_VERSION_MAJOR >= 11
VectorType* pVectorType = cast<VectorType>(mask->getType());
SWR_ASSERT(pVectorType->getElementType() == mInt1Ty);
uint32_t numLanes = pVectorType->getNumElements();
#else
SWR_ASSERT(mask->getType()->getVectorElementType() == mInt1Ty);
uint32_t numLanes = mask->getType()->getVectorNumElements();
#endif
Value* i32Result;
if (numLanes == 8)
{
@ -662,7 +706,11 @@ namespace SwrJit
Value* Builder::CVTPH2PS(Value* a, const llvm::Twine& name)
{
// Bitcast Nxint16 to Nxhalf
#if LLVM_VERSION_MAJOR >= 11
uint32_t numElems = cast<VectorType>(a->getType())->getNumElements();
#else
uint32_t numElems = a->getType()->getVectorNumElements();
#endif
Value* input = BITCAST(a, VectorType::get(mFP16Ty, numElems));
return FP_EXT(input, VectorType::get(mFP32Ty, numElems), name);

View File

@ -118,11 +118,17 @@ Value* VPLANEPS(Value* vA, Value* vB, Value* vC, Value*& vX, Value*& vY);
uint32_t IMMED(Value* i);
int32_t S_IMMED(Value* i);
CallInst*
CALL(Value* Callee, const std::initializer_list<Value*>& args, const llvm::Twine& name = "");
CallInst* CALL(Value* Callee, const std::initializer_list<Value*>& args, const llvm::Twine& name = "");
CallInst* CALL(Value* Callee)
{
#if LLVM_VERSION_MAJOR >= 11
// Not a great idea - we loose type info (Function) calling CALL
// and then we recast it here. Good for now, but needs to be
// more clean - optimally just always CALL a Function
return CALLA(FunctionCallee(cast<Function>(Callee)));
#else
return CALLA(Callee);
#endif
}
CallInst* CALL(Value* Callee, Value* arg);
CallInst* CALL2(Value* Callee, Value* arg1, Value* arg2);

View File

@ -1584,7 +1584,12 @@ void FetchJit::Shuffle8bpcGatherd(Shuffle8bpcArgs& args)
if (compCtrl[i] == ComponentControl::StoreSrc)
{
std::vector<uint32_t> vShuffleMasks[4] = {
#if LLVM_VERSION_MAJOR >= 11
using MaskType = int32_t;
#else
using MaskType = uint32_t;
#endif
std::vector<MaskType> vShuffleMasks[4] = {
{0, 4, 8, 12, 16, 20, 24, 28}, // x
{1, 5, 9, 13, 17, 21, 25, 29}, // y
{2, 6, 10, 14, 18, 22, 26, 30}, // z

View File

@ -161,6 +161,15 @@ namespace SwrJit
}};
// clang-format on
static uint32_t getBitWidth(VectorType *pVTy)
{
#if LLVM_VERSION_MAJOR >= 11
return pVTy->getNumElements() * pVTy->getElementType()->getPrimitiveSizeInBits();
#else
return pVTy->getBitWidth();
#endif
}
struct LowerX86 : public FunctionPass
{
LowerX86(Builder* b = nullptr) : FunctionPass(ID), B(b)
@ -246,7 +255,7 @@ namespace SwrJit
}
SWR_ASSERT(pVecTy->isVectorTy(), "Couldn't determine vector size");
uint32_t width = cast<VectorType>(pVecTy)->getBitWidth();
uint32_t width = getBitWidth(cast<VectorType>(pVecTy));
switch (width)
{
case 256:
@ -301,7 +310,11 @@ namespace SwrJit
// Convert <N x i1> mask to <N x i32> x86 mask
Value* VectorMask(Value* vi1Mask)
{
#if LLVM_VERSION_MAJOR >= 11
uint32_t numElem = cast<VectorType>(vi1Mask->getType())->getNumElements();
#else
uint32_t numElem = vi1Mask->getType()->getVectorNumElements();
#endif
return B->S_EXT(vi1Mask, VectorType::get(B->mInt32Ty, numElem));
}
@ -486,7 +499,12 @@ namespace SwrJit
else
{
v32Result = UndefValue::get(v32A->getType());
for (uint32_t l = 0; l < v32A->getType()->getVectorNumElements(); ++l)
#if LLVM_VERSION_MAJOR >= 11
uint32_t numElem = cast<VectorType>(v32A->getType())->getNumElements();
#else
uint32_t numElem = v32A->getType()->getVectorNumElements();
#endif
for (uint32_t l = 0; l < numElem; ++l)
{
auto i32Index = B->VEXTRACT(vi32Index, B->C(l));
auto val = B->VEXTRACT(v32A, i32Index);
@ -507,9 +525,16 @@ namespace SwrJit
auto i8Scale = pCallInst->getArgOperand(4);
pBase = B->POINTER_CAST(pBase, PointerType::get(B->mInt8Ty, 0));
#if LLVM_VERSION_MAJOR >= 11
VectorType* pVectorType = cast<VectorType>(vSrc->getType());
uint32_t numElem = pVectorType->getNumElements();
auto srcTy = pVectorType->getElementType();
#else
uint32_t numElem = vSrc->getType()->getVectorNumElements();
auto i32Scale = B->Z_EXT(i8Scale, B->mInt32Ty);
auto srcTy = vSrc->getType()->getVectorElementType();
#endif
auto i32Scale = B->Z_EXT(i8Scale, B->mInt32Ty);
Value* v32Gather = nullptr;
if (arch == AVX)
{
@ -572,12 +597,19 @@ namespace SwrJit
else if (width == W512)
{
// Double pump 4-wide for 64bit elements
#if LLVM_VERSION_MAJOR >= 11
if (cast<VectorType>(vSrc->getType())->getElementType() == B->mDoubleTy)
#else
if (vSrc->getType()->getVectorElementType() == B->mDoubleTy)
#endif
{
auto v64Mask = pThis->VectorMask(vi1Mask);
v64Mask = B->S_EXT(
v64Mask,
VectorType::get(B->mInt64Ty, v64Mask->getType()->getVectorNumElements()));
#if LLVM_VERSION_MAJOR >= 11
uint32_t numElem = cast<VectorType>(v64Mask->getType())->getNumElements();
#else
uint32_t numElem = v64Mask->getType()->getVectorNumElements();
#endif
v64Mask = B->S_EXT(v64Mask, VectorType::get(B->mInt64Ty, numElem));
v64Mask = B->BITCAST(v64Mask, vSrc->getType());
Value* src0 = B->VSHUFFLE(vSrc, vSrc, B->C({0, 1, 2, 3}));
@ -589,23 +621,25 @@ namespace SwrJit
Value* mask0 = B->VSHUFFLE(v64Mask, v64Mask, B->C({0, 1, 2, 3}));
Value* mask1 = B->VSHUFFLE(v64Mask, v64Mask, B->C({4, 5, 6, 7}));
src0 = B->BITCAST(
src0,
VectorType::get(B->mInt64Ty, src0->getType()->getVectorNumElements()));
mask0 = B->BITCAST(
mask0,
VectorType::get(B->mInt64Ty, mask0->getType()->getVectorNumElements()));
#if LLVM_VERSION_MAJOR >= 11
uint32_t numElemSrc0 = cast<VectorType>(src0->getType())->getNumElements();
uint32_t numElemMask0 = cast<VectorType>(mask0->getType())->getNumElements();
uint32_t numElemSrc1 = cast<VectorType>(src1->getType())->getNumElements();
uint32_t numElemMask1 = cast<VectorType>(mask1->getType())->getNumElements();
#else
uint32_t numElemSrc0 = src0->getType()->getVectorNumElements();
uint32_t numElemMask0 = mask0->getType()->getVectorNumElements();
uint32_t numElemSrc1 = src1->getType()->getVectorNumElements();
uint32_t numElemMask1 = mask1->getType()->getVectorNumElements();
#endif
src0 = B->BITCAST(src0, VectorType::get(B->mInt64Ty, numElemSrc0));
mask0 = B->BITCAST(mask0, VectorType::get(B->mInt64Ty, numElemMask0));
Value* gather0 =
B->CALL(pX86IntrinFunc, {src0, pBase, indices0, mask0, i8Scale});
src1 = B->BITCAST(
src1,
VectorType::get(B->mInt64Ty, src1->getType()->getVectorNumElements()));
mask1 = B->BITCAST(
mask1,
VectorType::get(B->mInt64Ty, mask1->getType()->getVectorNumElements()));
src1 = B->BITCAST(src1, VectorType::get(B->mInt64Ty, numElemSrc1));
mask1 = B->BITCAST(mask1, VectorType::get(B->mInt64Ty, numElemMask1));
Value* gather1 =
B->CALL(pX86IntrinFunc, {src1, pBase, indices1, mask1, i8Scale});
v32Gather = B->VSHUFFLE(gather0, gather1, B->C({0, 1, 2, 3, 4, 5, 6, 7}));
v32Gather = B->BITCAST(v32Gather, vSrc->getType());
}
@ -845,10 +879,15 @@ namespace SwrJit
auto argType = arg.get()->getType();
if (argType->isVectorTy())
{
#if LLVM_VERSION_MAJOR >= 11
uint32_t vecWidth = cast<VectorType>(argType)->getNumElements();
auto elemTy = cast<VectorType>(argType)->getElementType();
#else
uint32_t vecWidth = argType->getVectorNumElements();
auto elemTy = argType->getVectorElementType();
#endif
Value* lanes = B->CInc<int>(i * vecWidth / 2, vecWidth / 2);
Value* argToPush = B->VSHUFFLE(
arg.get(), B->VUNDEF(argType->getVectorElementType(), vecWidth), lanes);
Value* argToPush = B->VSHUFFLE(arg.get(), B->VUNDEF(elemTy, vecWidth), lanes);
args.push_back(argToPush);
}
else
@ -862,8 +901,13 @@ namespace SwrJit
if (result[0]->getType()->isVectorTy())
{
assert(result[1]->getType()->isVectorTy());
#if LLVM_VERSION_MAJOR >= 11
vecWidth = cast<VectorType>(result[0]->getType())->getNumElements() +
cast<VectorType>(result[1]->getType())->getNumElements();
#else
vecWidth = result[0]->getType()->getVectorNumElements() +
result[1]->getType()->getVectorNumElements();
#endif
}
else
{