Skip to content

Commit

Permalink
Fix build against llvm tot
Browse files Browse the repository at this point in the history
.
  • Loading branch information
igorban-intel authored and sys-cmllvm committed Dec 22, 2022
1 parent 88083f8 commit dd72efa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 34 deletions.
21 changes: 6 additions & 15 deletions GenXIntrinsics/include/llvm/GenXIntrinsics/GenXIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ SPDX-License-Identifier: MIT
#include "llvm/IR/Instructions.h"
#include "llvm/GenXIntrinsics/GenXVersion.h"


namespace VCINTR {
#if VC_INTR_LLVM_VERSION_MAJOR < 16
const llvm::NoneType None = llvm::None;
#else
inline constexpr std::nullopt_t None = std::nullopt;
#endif
} // namespace VCINTR

namespace llvm {

namespace GenXIntrinsic {
Expand Down Expand Up @@ -182,15 +173,15 @@ inline bool isGenXNonTrivialIntrinsic(const Value *V) {

/// GenXIntrinsic::getGenXName(ID) - Return the LLVM name for a GenX intrinsic,
/// such as "llvm.genx.lane.id".
std::string getGenXName(ID id, ArrayRef<Type *> Tys = VCINTR::None);
std::string getGenXName(ID id, ArrayRef<Type *> Tys = {});

ID lookupGenXIntrinsicID(StringRef Name);

AttributeList getAttributes(LLVMContext &C, ID id);

/// GenXIntrinsic::getGenXType(ID) - Return the function type for an intrinsic.
FunctionType *getGenXType(LLVMContext &Context, GenXIntrinsic::ID id,
ArrayRef<Type *> Tys = VCINTR::None);
ArrayRef<Type *> Tys = {});

/// GenXIntrinsic::getGenXDeclaration(M, ID) - Create or insert a GenX LLVM
/// Function declaration for an intrinsic, and return it.
Expand All @@ -199,7 +190,7 @@ FunctionType *getGenXType(LLVMContext &Context, GenXIntrinsic::ID id,
/// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
/// intrinsic, Tys must provide exactly one type for each overloaded type in
/// the intrinsic.
Function *getGenXDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = VCINTR::None);
Function *getGenXDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {});

void getIntrinsicInfoTableEntries(
GenXIntrinsic::ID id,
Expand Down Expand Up @@ -271,11 +262,11 @@ inline bool isAnyNonTrivialIntrinsic(const Value *V) {

/// GenXIntrinsic::getAnyName(ID) - Return the LLVM name for LLVM or GenX
/// intrinsic, such as "llvm.genx.lane.id".
std::string getAnyName(unsigned id, ArrayRef<Type *> Tys = VCINTR::None);
std::string getAnyName(unsigned id, ArrayRef<Type *> Tys = {});

/// GenXIntrinsic::getAnyType(ID) - Return the function type for an intrinsic.
inline FunctionType *getAnyType(LLVMContext &Context, unsigned id,
ArrayRef<Type *> Tys = VCINTR::None) {
ArrayRef<Type *> Tys = {}) {
assert(isAnyNonTrivialIntrinsic(id));
if (isGenXIntrinsic(id))
return getGenXType(Context, (ID)id, Tys);
Expand Down Expand Up @@ -303,7 +294,7 @@ bool isOverloadedRet(unsigned IntrinID);
/// intrinsic, Tys must provide exactly one type for each overloaded type in
/// the intrinsic.
inline Function *getAnyDeclaration(Module *M, unsigned id,
ArrayRef<Type *> Tys = VCINTR::None) {
ArrayRef<Type *> Tys = {}) {
assert(isAnyNonTrivialIntrinsic(id));
if (isGenXIntrinsic(id)) {
return getGenXDeclaration(M, (ID)id, Tys);
Expand Down
10 changes: 0 additions & 10 deletions GenXIntrinsics/include/llvmVCWrapper/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ inline const ArgKind &getValue(const llvm::Optional<ArgKind> &opt) {
#endif
}

#if VC_INTR_LLVM_VERSION_MAJOR > 15
template <class ArgKind> inline ArgKind &getValue(std::optional<ArgKind> &opt) {
return opt.value();
}

template <class ArgKind>
inline const ArgKind &getValue(const std::optional<ArgKind> &opt) {
return opt.value();
}
#endif
} // namespace VCINTR

#endif // VCINTR_IR_INSTRUCTIONS_H
11 changes: 7 additions & 4 deletions GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVReaderAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static SPIRVArgDesc parseSPIRVIRImageType(StringRef TyName) {

static Optional<SPIRVArgDesc> parseIntelType(StringRef TyName) {
if (!TyName.consume_front(IntelTypes::TypePrefix))
return None;
return {};

SPIRVType MainType;
std::tie(MainType, TyName) = parseIntelMainType(TyName);
Expand All @@ -215,7 +215,7 @@ static Optional<SPIRVArgDesc> parseIntelType(StringRef TyName) {

static Optional<SPIRVArgDesc> parseOCLType(StringRef TyName) {
if (!TyName.consume_front(OCLTypes::TypePrefix))
return None;
return {};

// Sampler type.
if (TyName.consume_front(OCLTypes::Sampler)) {
Expand All @@ -229,7 +229,7 @@ static Optional<SPIRVArgDesc> parseOCLType(StringRef TyName) {

static Optional<SPIRVArgDesc> parseSPIRVIRType(StringRef TyName) {
if (!TyName.consume_front(SPIRVIRTypes::TypePrefix))
return None;
return {};

if (TyName.consume_front(SPIRVIRTypes::Sampler))
return {SPIRVType::Sampler};
Expand Down Expand Up @@ -491,8 +491,11 @@ static void rewriteKernelArguments(Function &F) {

Function *NewF = transformKernelSignature(F, ArgDescs);
F.getParent()->getFunctionList().insert(F.getIterator(), NewF);
#if VC_INTR_LLVM_VERSION_MAJOR > 15
NewF->splice(NewF->begin(), &F);
#else
NewF->getBasicBlockList().splice(NewF->begin(), F.getBasicBlockList());

#endif
// Rewrite uses and delete conversion intrinsics.
for (int i = 0, e = ArgDescs.size(); i != e; ++i) {
Argument &OldArg = *std::next(F.arg_begin(), i);
Expand Down
10 changes: 7 additions & 3 deletions GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVWriterAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ static SPIRVArgDesc parseArgDesc(StringRef Desc) {
.Case(ArgDesc::Image3d, SPIRVType::Image3d)
.Case(ArgDesc::SVM, SPIRVType::Pointer)
.Case(ArgDesc::Sampler, SPIRVType::Sampler)
.Default(None);
.Default({});
}

if (!AccTy) {
AccTy = StringSwitch<Optional<AccessType>>(Tok)
.Case(ArgDesc::ReadOnly, AccessType::ReadOnly)
.Case(ArgDesc::WriteOnly, AccessType::WriteOnly)
.Case(ArgDesc::ReadWrite, AccessType::ReadWrite)
.Default(None);
.Default({});
}

if (Ty && AccTy)
Expand Down Expand Up @@ -372,7 +372,7 @@ static Optional<ArgKind> extractArgumentKind(const Argument &Arg) {
const Function *F = Arg.getParent();
const AttributeList Attrs = F->getAttributes();
if (!Attrs.hasParamAttr(Arg.getArgNo(), VCFunctionMD::VCArgumentKind))
return None;
return {};

const Attribute Attr =
Attrs.getParamAttr(Arg.getArgNo(), VCFunctionMD::VCArgumentKind);
Expand Down Expand Up @@ -434,7 +434,11 @@ static void rewriteKernelArguments(Function &F) {

Function *NewF = transformKernelSignature(F, ArgDescs);
F.getParent()->getFunctionList().insert(F.getIterator(), NewF);
#if VC_INTR_LLVM_VERSION_MAJOR > 15
NewF->splice(NewF->begin(), &F);
#else
NewF->getBasicBlockList().splice(NewF->begin(), F.getBasicBlockList());
#endif

Instruction *InsPt = &NewF->getEntryBlock().front();
for (auto ArgPair : llvm::zip(F.args(), NewF->args())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,14 @@ static void rewriteSingleElementVectorSignature(Function &F,
NewF.copyMetadata(&F, 0);
NewF.recalculateIntrinsicID();
F.getParent()->getFunctionList().insert(F.getIterator(), &NewF);
#if VC_INTR_LLVM_VERSION_MAJOR > 15
NewF.splice(NewF.begin(), &F);
#else
NewF.getBasicBlockList().splice(NewF.begin(), F.getBasicBlockList());

#endif
manageSingleElementVectorAttributes(F, NewF);

if (NewF.getBasicBlockList().size() > 0) {
if (NewF.size() > 0) {
for (auto ArgPair : llvm::zip(F.args(), NewF.args()))
replaceAllUsesWith(std::get<0>(ArgPair), std::get<1>(ArgPair), NewF);
if (NewF.getReturnType() != F.getReturnType())
Expand Down

0 comments on commit dd72efa

Please sign in to comment.