-
Notifications
You must be signed in to change notification settings - Fork 261
Enable translation of ac_fixed functions #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2375,6 +2375,19 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F, | |
| auto *IntrinsicCall = Builder.CreateIntrinsic(IID, RetTy, Args); | ||
| return mapValue(BV, IntrinsicCall); | ||
| } | ||
| case OpFixedSqrtINTEL: | ||
| case OpFixedRecipINTEL: | ||
| case OpFixedRsqrtINTEL: | ||
| case OpFixedSinINTEL: | ||
| case OpFixedCosINTEL: | ||
| case OpFixedSinCosINTEL: | ||
| case OpFixedSinPiINTEL: | ||
| case OpFixedCosPiINTEL: | ||
| case OpFixedSinCosPiINTEL: | ||
| case OpFixedLogINTEL: | ||
| case OpFixedExpINTEL: | ||
| return mapValue( | ||
| BV, transFixedPointInst(static_cast<SPIRVInstruction *>(BV), BB)); | ||
| default: { | ||
| auto OC = BV->getOpCode(); | ||
| if (isSPIRVCmpInstTransToLLVMInst(static_cast<SPIRVInstruction *>(BV))) { | ||
|
|
@@ -2399,6 +2412,64 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F, | |
| } | ||
| } | ||
|
|
||
| CallInst *SPIRVToLLVM::transFixedPointInst(SPIRVInstruction *BI, | ||
| BasicBlock *BB) { | ||
| // LLVM fixed point functions return value: | ||
| // iN | ||
| // Arguments: | ||
| // A(iN), S(i1), I(i32), rI(i32), Quantization(i32), Overflow(i32) | ||
|
|
||
| // SPIR-V fixed point instruction contains: | ||
| // <id>ResTy Res<id> <id>InTy In<id> \ | ||
| // Literal S Literal I Literal rI Literal Q Literal O | ||
|
|
||
| Type *RetTy = transType(BI->getType()); | ||
|
|
||
| auto Inst = static_cast<SPIRVFixedPointIntelInst *>(BI); | ||
| Type *InTy = transType(Inst->getOperand(1)->getType()); | ||
|
|
||
| IntegerType *Int32Ty = IntegerType::get(*Context, 32); | ||
| IntegerType *Int1Ty = IntegerType::get(*Context, 1); | ||
|
|
||
| SmallVector<Type *, 7> ArgTys = {InTy, Int1Ty, Int32Ty, | ||
| Int32Ty, Int32Ty, Int32Ty}; | ||
| FunctionType *FT = FunctionType::get(RetTy, ArgTys, false); | ||
|
|
||
| // Add meaningful suffix at the end of the function name to avoid ascending | ||
| // numerical suffixes. It is useful in situations, where the same function is | ||
| // called twice or more in one basic block. So, the function name is formed in | ||
| // the following way: [FuncName].[ReturnTy].[InputTy] | ||
| std::stringstream Suffix; | ||
| Suffix << ".i" << RetTy->getIntegerBitWidth() << ".i" | ||
vmaksimo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| << InTy->getIntegerBitWidth(); | ||
|
|
||
| Op OpCode = Inst->getOpCode(); | ||
| std::string FuncName = SPIRVFixedPointIntelMap::rmap(OpCode) + Suffix.str(); | ||
|
|
||
| FunctionCallee FCallee = M->getOrInsertFunction(FuncName, FT); | ||
|
|
||
| if (Function *Fn = dyn_cast<Function>(FCallee.getCallee())) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check if this is Function*? What if this is not so?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We check that it is a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, actually we expect that it will be always Function* because we insert function call on the line above. |
||
| Fn->setCallingConv(CallingConv::SPIR_FUNC); | ||
| if (isFuncNoUnwind()) | ||
| Fn->addFnAttr(Attribute::NoUnwind); | ||
| } | ||
|
|
||
| // Words contain: | ||
| // <id>InTy In<id> Literal S Literal I Literal rI Literal Q Literal O | ||
| auto Words = Inst->getOpWords(); | ||
| std::vector<Value *> Args = { | ||
| transValue(Inst->getOperand(1), BB->getParent(), BB) /* A - input */, | ||
| ConstantInt::get(Int1Ty, Words[2]) /* S - indicator of signedness */, | ||
| ConstantInt::get(Int32Ty, | ||
| Words[3]) /* I - fixed-point location of the input */, | ||
| ConstantInt::get(Int32Ty, | ||
| Words[4]) /* rI - fixed-point location of the result*/, | ||
| ConstantInt::get(Int32Ty, Words[5]) /* Quantization mode */, | ||
| ConstantInt::get(Int32Ty, Words[6]) /* Overflow mode */}; | ||
|
|
||
| return CallInst::Create(FCallee, Args, "", BB); | ||
| } | ||
|
|
||
| template <class SourceTy, class FuncTy> | ||
| bool SPIRVToLLVM::foreachFuncCtlMask(SourceTy Source, FuncTy Func) { | ||
| SPIRVWord FCM = Source->getFuncCtlMask(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
N?