@@ -2385,13 +2385,6 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
2385
2385
BV->getName (), BB));
2386
2386
}
2387
2387
2388
- case OpImageQuerySize:
2389
- case OpImageQuerySizeLod: {
2390
- return mapValue (
2391
- BV, transSPIRVBuiltinFromInst (static_cast <SPIRVInstruction *>(BV), BB,
2392
- /* AddRetTypePostfix=*/ true ));
2393
- }
2394
-
2395
2388
case OpBitReverse: {
2396
2389
auto *BR = static_cast <SPIRVUnary *>(BV);
2397
2390
auto Ty = transType (BV->getType ());
@@ -2670,7 +2663,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
2670
2663
auto BI = static_cast <SPIRVInstruction *>(BV);
2671
2664
Value *Inst = nullptr ;
2672
2665
if (BI->hasFPRoundingMode () || BI->isSaturatedConversion ())
2673
- Inst = transOCLBuiltinFromInst (BI, BB);
2666
+ Inst = transSPIRVBuiltinFromInst (BI, BB);
2674
2667
else
2675
2668
Inst = transConvertInst (BV, F, BB);
2676
2669
return mapValue (BV, Inst);
@@ -3252,10 +3245,16 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName,
3252
3245
HasFuncPtrArg = true ;
3253
3246
}
3254
3247
}
3255
- if (!HasFuncPtrArg)
3256
- mangleOpenClBuiltin (FuncName, ArgTys, MangledName);
3257
- else
3248
+ if (!HasFuncPtrArg) {
3249
+ if (BM->getDesiredBIsRepresentation () != BIsRepresentation::SPIRVFriendlyIR)
3250
+ mangleOpenClBuiltin (FuncName, ArgTys, MangledName);
3251
+ else
3252
+ MangledName =
3253
+ getSPIRVFriendlyIRFunctionName (FuncName, BI->getOpCode (), ArgTys);
3254
+
3255
+ } else {
3258
3256
MangledName = decorateSPIRVFunction (FuncName);
3257
+ }
3259
3258
Function *Func = M->getFunction (MangledName);
3260
3259
FunctionType *FT = FunctionType::get (RetTy, ArgTys, false );
3261
3260
// ToDo: Some intermediate functions have duplicate names with
@@ -3399,22 +3398,42 @@ std::string getSPIRVFuncSuffix(SPIRVInstruction *BI) {
3399
3398
break ;
3400
3399
}
3401
3400
}
3401
+ if (BI->hasDecorate (DecorationSaturatedConversion)) {
3402
+ Suffix += kSPIRVPostfix ::Divider;
3403
+ Suffix += kSPIRVPostfix ::Sat;
3404
+ }
3405
+ SPIRVFPRoundingModeKind Kind;
3406
+ if (BI->hasFPRoundingMode (&Kind)) {
3407
+ Suffix += kSPIRVPostfix ::Divider;
3408
+ Suffix += SPIRSPIRVFPRoundingModeMap::rmap (Kind);
3409
+ }
3402
3410
return Suffix;
3403
3411
}
3404
3412
3405
3413
Instruction *SPIRVToLLVM::transSPIRVBuiltinFromInst (SPIRVInstruction *BI,
3406
- BasicBlock *BB,
3407
- bool AddRetTypePostfix) {
3414
+ BasicBlock *BB) {
3408
3415
assert (BB && " Invalid BB" );
3416
+ const auto OC = BI->getOpCode ();
3417
+ bool AddRetTypePostfix = false ;
3418
+ if (OC == OpImageQuerySizeLod || OC == OpImageQuerySize)
3419
+ AddRetTypePostfix = true ;
3420
+
3421
+ bool IsRetSigned = false ;
3422
+ if (isCvtOpCode (OC)) {
3423
+ AddRetTypePostfix = true ;
3424
+ if (OC == OpConvertUToF || OC == OpSatConvertUToS)
3425
+ IsRetSigned = true ;
3426
+ }
3427
+
3409
3428
if (AddRetTypePostfix) {
3410
3429
const Type *RetTy =
3411
3430
BI->hasType () ? transType (BI->getType ()) : Type::getVoidTy (*Context);
3412
- return transBuiltinFromInst (getSPIRVFuncName (BI-> getOpCode () , RetTy) +
3431
+ return transBuiltinFromInst (getSPIRVFuncName (OC , RetTy, IsRetSigned ) +
3413
3432
getSPIRVFuncSuffix (BI),
3414
3433
BI, BB);
3415
3434
}
3416
- return transBuiltinFromInst (
3417
- getSPIRVFuncName (BI-> getOpCode (), getSPIRVFuncSuffix (BI)), BI, BB);
3435
+ return transBuiltinFromInst (getSPIRVFuncName (OC, getSPIRVFuncSuffix (BI)), BI,
3436
+ BB);
3418
3437
}
3419
3438
3420
3439
bool SPIRVToLLVM::translate () {
0 commit comments