Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h
4574 views
/****************************************************************************1* Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* @file builder_misc.h23*24* @brief miscellaneous builder functions25*26* Notes:27*28******************************************************************************/29#pragma once3031Constant* C(bool i);32Constant* C(char i);33Constant* C(uint8_t i);34Constant* C(int i);35Constant* C(int64_t i);36Constant* C(uint64_t i);37Constant* C(uint16_t i);38Constant* C(uint32_t i);39Constant* C(float i);4041template <typename Ty>42Constant* C(const std::initializer_list<Ty>& constList)43{44std::vector<Constant*> vConsts;45for (auto i : constList)46{47vConsts.push_back(C((Ty)i));48}49return ConstantVector::get(vConsts);50}5152template <typename Ty>53Constant* C(const std::vector<Ty>& constList)54{55std::vector<Constant*> vConsts;56for (auto i : constList)57{58vConsts.push_back(C((Ty)i));59}60return ConstantVector::get(vConsts);61}6263template <typename Ty>64Constant* CA(LLVMContext& ctx, ArrayRef<Ty> constList)65{66return ConstantDataArray::get(ctx, constList);67}6869template <typename Ty>70Constant* CInc(uint32_t base, uint32_t count)71{72std::vector<Constant*> vConsts;7374for (uint32_t i = 0; i < count; i++)75{76vConsts.push_back(C((Ty)base));77base++;78}79return ConstantVector::get(vConsts);80}8182Constant* PRED(bool pred);8384Value* VIMMED1(uint64_t i);85Value* VIMMED1_16(uint64_t i);8687Value* VIMMED1(int i);88Value* VIMMED1_16(int i);8990Value* VIMMED1(uint32_t i);91Value* VIMMED1_16(uint32_t i);9293Value* VIMMED1(float i);94Value* VIMMED1_16(float i);9596Value* VIMMED1(bool i);97Value* VIMMED1_16(bool i);9899Value* VUNDEF(Type* t);100101Value* VUNDEF_F();102Value* VUNDEF_F_16();103104Value* VUNDEF_I();105Value* VUNDEF_I_16();106107Value* VUNDEF(Type* ty, uint32_t size);108109Value* VUNDEF_IPTR();110111Value* VBROADCAST(Value* src, const llvm::Twine& name = "");112Value* VBROADCAST_16(Value* src);113114Value* VRCP(Value* va, const llvm::Twine& name = "");115Value* VPLANEPS(Value* vA, Value* vB, Value* vC, Value*& vX, Value*& vY);116117uint32_t IMMED(Value* i);118int32_t S_IMMED(Value* i);119120CallInst* CALL(Value* Callee, const std::initializer_list<Value*>& args, const llvm::Twine& name = "");121CallInst* CALL(Value* Callee)122{123#if LLVM_VERSION_MAJOR >= 11124// Not a great idea - we loose type info (Function) calling CALL125// and then we recast it here. Good for now, but needs to be126// more clean - optimally just always CALL a Function127return CALLA(FunctionCallee(cast<Function>(Callee)));128#else129return CALLA(Callee);130#endif131}132CallInst* CALL(Value* Callee, Value* arg);133CallInst* CALL2(Value* Callee, Value* arg1, Value* arg2);134CallInst* CALL3(Value* Callee, Value* arg1, Value* arg2, Value* arg3);135136Value* MASK(Value* vmask);137Value* MASK_16(Value* vmask);138139Value* VMASK(Value* mask);140Value* VMASK_16(Value* mask);141142Value* VMOVMSK(Value* mask);143144//////////////////////////////////////////////////////////////////////////145/// @brief Float / Fixed-point conversions146//////////////////////////////////////////////////////////////////////////147// Signed148Value* VCVT_F32_FIXED_SI(Value* vFloat,149uint32_t numIntBits,150uint32_t numFracBits,151const llvm::Twine& name = "");152Value* VCVT_FIXED_SI_F32(Value* vFixed,153uint32_t numIntBits,154uint32_t numFracBits,155const llvm::Twine& name = "");156// Unsigned157Value* VCVT_F32_FIXED_UI(Value* vFloat,158uint32_t numIntBits,159uint32_t numFracBits,160const llvm::Twine& name = "");161Value* VCVT_FIXED_UI_F32(Value* vFixed,162uint32_t numIntBits,163uint32_t numFracBits,164const llvm::Twine& name = "");165166//////////////////////////////////////////////////////////////////////////167/// @brief functions that build IR to call x86 intrinsics directly, or168/// emulate them with other instructions if not available on the host169//////////////////////////////////////////////////////////////////////////170171Value* EXTRACT_16(Value* x, uint32_t imm);172Value* JOIN_16(Value* a, Value* b);173174Value* PSHUFB(Value* a, Value* b);175Value* PMOVSXBD(Value* a);176Value* PMOVSXWD(Value* a);177Value* CVTPH2PS(Value* a, const llvm::Twine& name = "");178Value* CVTPS2PH(Value* a, Value* rounding);179Value* PMAXSD(Value* a, Value* b);180Value* PMINSD(Value* a, Value* b);181Value* PMAXUD(Value* a, Value* b);182Value* PMINUD(Value* a, Value* b);183Value* VABSPS(Value* a);184Value* FMADDPS(Value* a, Value* b, Value* c);185186Value* ICLAMP(Value* src, Value* low, Value* high, const llvm::Twine& name = "");187Value* FCLAMP(Value* src, Value* low, Value* high);188Value* FCLAMP(Value* src, float low, float high);189190CallInst* PRINT(const std::string& printStr);191CallInst* PRINT(const std::string& printStr, const std::initializer_list<Value*>& printArgs);192193Value* VPOPCNT(Value* a);194195Value* INT3()196{197return DEBUGTRAP();198}199200201Value* VEXTRACTI128(Value* a, Constant* imm8);202Value* VINSERTI128(Value* a, Value* b, Constant* imm8);203204// rdtsc buckets macros205void RDTSC_START(Value* pBucketMgr, Value* pId);206void RDTSC_STOP(Value* pBucketMgr, Value* pId);207208Value* CreateEntryAlloca(Function* pFunc, Type* pType);209Value* CreateEntryAlloca(Function* pFunc, Type* pType, Value* pArraySize);210211uint32_t GetTypeSize(Type* pType);212213214