@@ -397,6 +397,9 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
397
397
}
398
398
}
399
399
400
+ // Emit error if type is bfloat. LLVM native bfloat type is not supported.
401
+ BM->getErrorLog ().checkError (!T->isBFloatTy (),
402
+ SPIRVEC_UnsupportedLLVMBFloatType);
400
403
if (T->isFloatingPointTy ())
401
404
return mapType (T, BM->addFloatType (T->getPrimitiveSizeInBits ()));
402
405
@@ -441,7 +444,8 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
441
444
// It must be at least 1.
442
445
const auto ArraySize =
443
446
T->getArrayNumElements () ? T->getArrayNumElements () :
444
- (M->getTargetTriple () == " spirv64-amd-amdhsa" ? UINT32_MAX : 1 );
447
+ (M->getTargetTriple ().getVendor () == Triple::VendorType::AMD
448
+ ? UINT32_MAX : 1 );
445
449
446
450
Type *ElTy = T->getArrayElementType ();
447
451
SPIRVType *TransType = BM->addArrayType (
@@ -753,7 +757,7 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(SPIRVType *ET, unsigned AddrSpc) {
753
757
return transPointerType (ET, SPIRAS_Private);
754
758
if (BM->isAllowedToUseExtension (ExtensionID::SPV_KHR_untyped_pointers) &&
755
759
!(ET->isTypeArray () || ET->isTypeVector () || ET->isSPIRVOpaqueType () ||
756
- (M->getTargetTriple () == " spirv64-amd-amdhsa " &&
760
+ (M->getTargetTriple (). getVendor () == Triple::VendorType::AMD &&
757
761
ET->getOpCode () == OpTypeFunction))) {
758
762
TranslatedTy = BM->addUntypedPointerKHRType (
759
763
SPIRSPIRVAddrSpaceMap::map (static_cast <SPIRAddressSpace>(AddrSpc)));
@@ -842,12 +846,12 @@ SPIRVType *LLVMToSPIRVBase::transScavengedType(Value *V) {
842
846
// error. To be on the safe side, an assertion is added to check printf
843
847
// never reaches this point.
844
848
assert (F->getName () != " printf" );
845
- if (M->getTargetTriple () != " spirv64-amd-amdhsa " )
849
+ if (M->getTargetTriple (). getVendor () != Triple::VendorType::AMD )
846
850
BM->getErrorLog ().checkError (!FnTy->isVarArg (),
847
851
SPIRVEC_UnsupportedVarArgFunction);
848
852
849
853
SPIRVType *RT = transType (FnTy->getReturnType ());
850
- if (M->getTargetTriple () == " spirv64-amd-amdhsa " &&
854
+ if (M->getTargetTriple (). getVendor () == Triple::VendorType::AMD &&
851
855
F->hasName () && F->getName ().contains (" dispatch.ptr" ))
852
856
RT = transType (PointerType::get (F->getContext (), SPIRAS_Constant));
853
857
@@ -1596,7 +1600,8 @@ SPIRVValue *LLVMToSPIRVBase::transUnaryInst(UnaryInstruction *U,
1596
1600
return BM->addUndef (ExpectedTy);
1597
1601
}
1598
1602
}
1599
- if (isa<VAArgInst>(U) && M->getTargetTriple () == " spirv64-amd-amdhsa" ) {
1603
+ if (isa<VAArgInst>(U) &&
1604
+ M->getTargetTriple ().getVendor () == Triple::VendorType::AMD) {
1600
1605
SPIRVType *ExpectedTy = transScavengedType (U);
1601
1606
return BM->addUndef (ExpectedTy);
1602
1607
}
@@ -1606,7 +1611,7 @@ SPIRVValue *LLVMToSPIRVBase::transUnaryInst(UnaryInstruction *U,
1606
1611
const auto SrcAddrSpace = Cast->getSrcTy ()->getPointerAddressSpace ();
1607
1612
const auto DestAddrSpace = Cast->getDestTy ()->getPointerAddressSpace ();
1608
1613
if (DestAddrSpace == SPIRAS_Generic) {
1609
- if (M->getTargetTriple () != " spirv64-amd-amdhsa " )
1614
+ if (M->getTargetTriple (). getVendor () != Triple::VendorType::AMD )
1610
1615
getErrorLog ().checkError (
1611
1616
SrcAddrSpace != SPIRAS_Constant, SPIRVEC_InvalidModule, U,
1612
1617
" Casts from constant address space to generic are illegal\n " );
@@ -1649,7 +1654,7 @@ SPIRVValue *LLVMToSPIRVBase::transUnaryInst(UnaryInstruction *U,
1649
1654
SrcAddrSpace == SPIRAS_Generic, SPIRVEC_InvalidModule, U,
1650
1655
" Casts from private/local/global address space are allowed only to "
1651
1656
" generic\n " );
1652
- if (M->getTargetTriple () != " spirv64-amd-amdhsa " )
1657
+ if (M->getTargetTriple (). getVendor () != Triple::VendorType::AMD )
1653
1658
getErrorLog ().checkError (
1654
1659
DestAddrSpace != SPIRAS_Constant, SPIRVEC_InvalidModule, U,
1655
1660
" Casts from generic address space to constant are illegal\n " );
@@ -2131,7 +2136,7 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
2131
2136
GV->isConstant (), transLinkageType (GV), BVarInit, GV->getName ().str (),
2132
2137
StorageClass, nullptr ));
2133
2138
if (GV->isExternallyInitialized () &&
2134
- M->getTargetTriple () == " spirv64-amd-amdhsa " )
2139
+ M->getTargetTriple (). getVendor () == Triple::VendorType::AMD )
2135
2140
BVar->addDecorate (DecorationUserTypeGOOGLE,
2136
2141
BM->getString (" externally_initialized" )->getId ());
2137
2142
@@ -2320,10 +2325,11 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
2320
2325
BB));
2321
2326
2322
2327
if (AllocaInst *Alc = dyn_cast<AllocaInst>(V)) {
2323
- SPIRVType *TranslatedTy = M->getTargetTriple () != " spirv64-amd-amdhsa" ?
2324
- transScavengedType (V) :
2325
- BM->addPointerType (StorageClassFunction,
2326
- transType (Alc->getAllocatedType ()));
2328
+ SPIRVType *TranslatedTy =
2329
+ M->getTargetTriple ().getVendor () != Triple::VendorType::AMD
2330
+ ? transScavengedType (V)
2331
+ : BM->addPointerType (StorageClassFunction,
2332
+ transType (Alc->getAllocatedType ()));
2327
2333
if (Alc->isArrayAllocation ()) {
2328
2334
SPIRVValue *Length = transValue (Alc->getArraySize (), BB);
2329
2335
assert (Length && " Couldn't translate array size!" );
@@ -3140,7 +3146,7 @@ bool LLVMToSPIRVBase::transDecoration(Value *V, SPIRVValue *BV) {
3140
3146
((Opcode == Instruction::FNeg || Opcode == Instruction::FCmp ||
3141
3147
BV->isExtInst ()) &&
3142
3148
BM->isAllowedToUseVersion (VersionNumber::SPIRV_1_6)) ||
3143
- (M->getTargetTriple () == " spirv64-amd-amdhsa " &&
3149
+ (M->getTargetTriple (). getVendor () == Triple::VendorType::AMD &&
3144
3150
Opcode == Instruction::Call)) {
3145
3151
FastMathFlags FMF = BVF->getFastMathFlags ();
3146
3152
SPIRVWord M{0 };
@@ -3260,7 +3266,8 @@ void LLVMToSPIRVBase::transMemAliasingINTELDecorations(Instruction *Inst,
3260
3266
if (!BM->isAllowedToUseExtension (
3261
3267
ExtensionID::SPV_INTEL_memory_access_aliasing))
3262
3268
return ;
3263
- if (!BV->hasId () && M->getTargetTriple () == " spirv64-amd-amdhsa" ) // Fences
3269
+ if (!BV->hasId () &&
3270
+ M->getTargetTriple ().getVendor () == Triple::VendorType::AMD) // Fences
3264
3271
return ;
3265
3272
if (MDNode *AliasingListMD = Inst->getMetadata (LLVMContext::MD_alias_scope)) {
3266
3273
auto *MemAliasList = addMemAliasingINTELInstructions (BM, AliasingListMD);
@@ -5074,7 +5081,7 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
5074
5081
const APInt Inf = APFloat::getInf (Semantics).bitcastToAPInt ();
5075
5082
const APInt AllOneMantissa =
5076
5083
APFloat::getLargest (Semantics).bitcastToAPInt () & ~Inf;
5077
-
5084
+ const APInt OneValue = APInt (BitSize, 1 );
5078
5085
// Some checks can be inverted tests for simple cases, for example
5079
5086
// simultaneous check for inf, normal, subnormal and zero is a check for
5080
5087
// non nan.
@@ -5183,8 +5190,10 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
5183
5190
BM->addUnaryInst (OpBitcast, OpSPIRVTy, InputFloat, BB);
5184
5191
auto *MantissaConst = transValue (
5185
5192
Constant::getIntegerValue (IntOpLLVMTy, AllOneMantissa), BB);
5193
+ auto *ConstOne =
5194
+ transValue (Constant::getIntegerValue (IntOpLLVMTy, OneValue), BB);
5186
5195
auto *MinusOne =
5187
- BM->addBinaryInst (OpISub, OpSPIRVTy, BitCastToInt, MantissaConst , BB);
5196
+ BM->addBinaryInst (OpISub, OpSPIRVTy, BitCastToInt, ConstOne , BB);
5188
5197
auto *TestIsSubnormal =
5189
5198
BM->addCmpInst (OpULessThan, ResTy, MinusOne, MantissaConst, BB);
5190
5199
if (FPClass & fcPosSubnormal && FPClass & fcNegSubnormal)
@@ -5529,7 +5538,7 @@ SPIRVValue *LLVMToSPIRVBase::transAsmINTEL(InlineAsm *IA) {
5529
5538
// TODO: intention here is to provide information about actual target
5530
5539
// but in fact spir-64 is substituted as triple when translator works
5531
5540
// eventually we need to fix it (not urgent)
5532
- StringRef TripleStr (M->getTargetTriple ());
5541
+ StringRef TripleStr (M->getTargetTriple (). str () );
5533
5542
auto *AsmTarget = static_cast <SPIRVAsmTargetINTEL *>(
5534
5543
BM->getOrAddAsmTargetINTEL (TripleStr.str ()));
5535
5544
auto *SIA = BM->addAsmINTEL (
@@ -5980,7 +5989,7 @@ bool isEmptyLLVMModule(Module *M) {
5980
5989
}
5981
5990
5982
5991
bool LLVMToSPIRVBase::translate () {
5983
- if (M->getTargetTriple () == " spirv64-amd-amdhsa " )
5992
+ if (M->getTargetTriple (). getVendor () == Triple::VendorType::AMD )
5984
5993
BM->setGeneratorVer (UINT16_MAX);
5985
5994
else
5986
5995
BM->setGeneratorVer (KTranslatorVer);
@@ -7043,7 +7052,8 @@ bool isValidLLVMModule(Module *M, SPIRVErrorLog &ErrorLog) {
7043
7052
7044
7053
Triple TT (M->getTargetTriple ());
7045
7054
if (!ErrorLog.checkError (isSupportedTriple (TT), SPIRVEC_InvalidTargetTriple,
7046
- " Actual target triple is " + M->getTargetTriple ()))
7055
+ " Actual target triple is " +
7056
+ M->getTargetTriple ().str ()))
7047
7057
return false ;
7048
7058
7049
7059
return true ;
@@ -7144,7 +7154,7 @@ bool runSpirvBackend(Module *M, std::string &Result, std::string &ErrMsg,
7144
7154
? Triple::spirv64
7145
7155
: Triple::spirv32,
7146
7156
TargetTriple.getSubArch ());
7147
- M->setTargetTriple (TargetTriple. str () );
7157
+ M->setTargetTriple (TargetTriple);
7148
7158
// We need to reset Data Layout to conform with the TargetMachine
7149
7159
M->setDataLayout (" " );
7150
7160
}
@@ -7153,7 +7163,7 @@ bool runSpirvBackend(Module *M, std::string &Result, std::string &ErrMsg,
7153
7163
TargetTriple.setTriple (DefaultTriple);
7154
7164
TargetTriple.setArch (TargetTriple.getArch (),
7155
7165
spirvVersionToSubArch (TranslatorOpts.getMaxVersion ()));
7156
- M->setTargetTriple (TargetTriple. str () );
7166
+ M->setTargetTriple (TargetTriple);
7157
7167
}
7158
7168
7159
7169
// Translate the Module into SPIR-V
0 commit comments