@@ -1183,32 +1183,27 @@ Value *SPIRVToLLVM::mapValue(SPIRVValue *BV, Value *V) {
1183
1183
CallInst *
1184
1184
SPIRVToLLVM::expandOCLBuiltinWithScalarArg (CallInst *CI,
1185
1185
const std::string &FuncName) {
1186
- assert (CI->getCalledFunction () && " Unexpected indirect call" );
1187
- AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1188
1186
if (!CI->getOperand (0 )->getType ()->isVectorTy () &&
1189
1187
CI->getOperand (1 )->getType ()->isVectorTy ()) {
1190
- return mutateCallInstOCL (
1191
- M, CI,
1192
- [=](CallInst *, std::vector<Value *> &Args) {
1193
- auto VecElemCount =
1194
- cast<VectorType>(CI->getOperand (1 )->getType ())->getElementCount ();
1195
- Value *NewVec = nullptr ;
1196
- if (auto CA = dyn_cast<Constant>(Args[0 ]))
1197
- NewVec = ConstantVector::getSplat (VecElemCount, CA);
1198
- else {
1199
- NewVec = ConstantVector::getSplat (
1200
- VecElemCount, Constant::getNullValue (Args[0 ]->getType ()));
1201
- NewVec = InsertElementInst::Create (NewVec, Args[0 ], getInt32 (M, 0 ),
1202
- " " , CI);
1203
- NewVec = new ShuffleVectorInst (
1204
- NewVec, NewVec,
1205
- ConstantVector::getSplat (VecElemCount, getInt32 (M, 0 )), " " , CI);
1206
- }
1207
- NewVec->takeName (Args[0 ]);
1208
- Args[0 ] = NewVec;
1209
- return FuncName;
1210
- },
1211
- &Attrs);
1188
+ auto VecElemCount =
1189
+ cast<VectorType>(CI->getOperand (1 )->getType ())->getElementCount ();
1190
+ auto Mutator = mutateCallInst (CI, FuncName);
1191
+ Mutator.mapArg (0 , [=](Value *Arg) {
1192
+ Value *NewVec = nullptr ;
1193
+ if (auto *CA = dyn_cast<Constant>(Arg))
1194
+ NewVec = ConstantVector::getSplat (VecElemCount, CA);
1195
+ else {
1196
+ NewVec = ConstantVector::getSplat (
1197
+ VecElemCount, Constant::getNullValue (Arg->getType ()));
1198
+ NewVec = InsertElementInst::Create (NewVec, Arg, getInt32 (M, 0 ), " " , CI);
1199
+ NewVec = new ShuffleVectorInst (
1200
+ NewVec, NewVec,
1201
+ ConstantVector::getSplat (VecElemCount, getInt32 (M, 0 )), " " , CI);
1202
+ }
1203
+ NewVec->takeName (Arg);
1204
+ return NewVec;
1205
+ });
1206
+ return cast<CallInst>(Mutator.getMutated ());
1212
1207
}
1213
1208
return CI;
1214
1209
}
@@ -4463,49 +4458,26 @@ SPIRVToLLVM::transLinkageType(const SPIRVValue *V) {
4463
4458
4464
4459
Instruction *SPIRVToLLVM::transAllAny (SPIRVInstruction *I, BasicBlock *BB) {
4465
4460
CallInst *CI = cast<CallInst>(transSPIRVBuiltinFromInst (I, BB));
4466
- assert (CI->getCalledFunction () && " Unexpected indirect call" );
4467
- BuiltinFuncMangleInfo BtnInfo;
4468
- AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
4469
- return cast<Instruction>(mapValue (
4470
- I, ::mutateCallInst (
4471
- M, CI,
4472
- [=](CallInst *, std::vector<Value *> &Args) {
4473
- auto *OldArg = CI->getOperand (0 );
4474
- auto *NewArgTy = FixedVectorType::get (
4475
- Type::getInt8Ty (*Context),
4476
- cast<FixedVectorType>(OldArg->getType ())->getNumElements ());
4477
- auto *NewArg =
4478
- CastInst::CreateSExtOrBitCast (OldArg, NewArgTy, " " , CI);
4479
- Args[0 ] = NewArg;
4480
- return getSPIRVFuncName (I->getOpCode (), getSPIRVFuncSuffix (I));
4481
- },
4482
- &BtnInfo, &Attrs, /* TakeFuncName=*/ true )));
4461
+ auto Mutator = mutateCallInst (
4462
+ CI, getSPIRVFuncName (I->getOpCode (), getSPIRVFuncSuffix (I)));
4463
+ Mutator.mapArg (0 , [](IRBuilder<> &Builder, Value *OldArg) {
4464
+ auto *NewArgTy = OldArg->getType ()->getWithNewBitWidth (8 );
4465
+ return Builder.CreateSExtOrBitCast (OldArg, NewArgTy);
4466
+ });
4467
+ return cast<Instruction>(Mutator.getMutated ());
4483
4468
}
4484
4469
4485
4470
Instruction *SPIRVToLLVM::transRelational (SPIRVInstruction *I, BasicBlock *BB) {
4486
4471
CallInst *CI = cast<CallInst>(transSPIRVBuiltinFromInst (I, BB));
4487
- assert (CI->getCalledFunction () && " Unexpected indirect call" );
4488
- BuiltinFuncMangleInfo BtnInfo;
4489
- AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
4490
- return cast<Instruction>(mapValue (
4491
- I, ::mutateCallInst (
4492
- M, CI,
4493
- [=](CallInst *, std::vector<Value *> &Args, llvm::Type *&RetTy) {
4494
- if (CI->getType ()->isVectorTy ()) {
4495
- RetTy = FixedVectorType::get (
4496
- Type::getInt8Ty (*Context),
4497
- cast<FixedVectorType>(CI->getType ())->getNumElements ());
4498
- }
4499
- return getSPIRVFuncName (I->getOpCode (), getSPIRVFuncSuffix (I));
4500
- },
4501
- [=](CallInst *NewCI) -> Instruction * {
4502
- Type *RetTy = CI->getType ();
4503
- if (RetTy == NewCI->getType ())
4504
- return NewCI;
4505
- return CastInst::CreateTruncOrBitCast (NewCI, RetTy, " " ,
4506
- NewCI->getNextNode ());
4507
- },
4508
- &BtnInfo, &Attrs, /* TakeFuncName=*/ true )));
4472
+ auto Mutator = mutateCallInst (
4473
+ CI, getSPIRVFuncName (I->getOpCode (), getSPIRVFuncSuffix (I)));
4474
+ if (CI->getType ()->isVectorTy ()) {
4475
+ Type *RetTy = CI->getType ()->getWithNewBitWidth (8 );
4476
+ Mutator.changeReturnType (RetTy, [=](IRBuilder<> &Builder, CallInst *NewCI) {
4477
+ return Builder.CreateTruncOrBitCast (NewCI, CI->getType ());
4478
+ });
4479
+ }
4480
+ return cast<Instruction>(Mutator.getMutated ());
4509
4481
}
4510
4482
4511
4483
std::unique_ptr<SPIRVModule> readSpirvModule (std::istream &IS,
0 commit comments