当前位置: 首页>>代码示例>>C++>>正文


C++ IntrinsicInst::setCalledFunction方法代码示例

本文整理汇总了C++中IntrinsicInst::setCalledFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ IntrinsicInst::setCalledFunction方法的具体用法?C++ IntrinsicInst::setCalledFunction怎么用?C++ IntrinsicInst::setCalledFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IntrinsicInst的用法示例。


在下文中一共展示了IntrinsicInst::setCalledFunction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: decomposeIntrinsics


//.........这里部分代码省略.........

                    llvm::Type* newCoordType;
                    if (newCoordWidth > 1)
                        newCoordType = llvm::VectorType::get(GetBasicType(coords), newCoordWidth);
                    else
                        newCoordType = GetBasicType(coords);

                    // create space to hold results
                    llvm::Value* newCoords   = llvm::UndefValue::get(newCoordType);
                    llvm::Value* smearedProj = llvm::UndefValue::get(newCoordType);

                    if (newCoordWidth > 1) {
                        for (int i = 0; i < newCoordWidth; ++i) {
                            llvm::Value* idx = MakeUnsignedConstant(module->getContext(), i);

                            // smear projection
                            smearedProj = builder.CreateInsertElement(smearedProj, divisor, idx);

                            // shrink coordinates to remove projection component
                            llvm::Value* oldCoord = builder.CreateExtractElement(coords, idx);
                            newCoords = builder.CreateInsertElement(newCoords, oldCoord, idx);
                        }
                    } else {
                        smearedProj = divisor;
                        newCoords = builder.CreateExtractElement(coords, MakeUnsignedConstant(module->getContext(), 0));
                    }

                    // divide coordinates
                    newCoords = builder.CreateFDiv(newCoords, smearedProj);

                    //
                    // Remaining code declares new intrinsic and modifies call arguments
                    //

                    // build up argTypes for flexible parameters, including result
                    llvm::SmallVector<llvm::Type*, 5> types;

                    // result type
                    types.push_back(intrinsic->getType());

                    // use new coords to reflect shrink
                    types.push_back(newCoords->getType());

                    // add offset
                    switch (intrinsic->getIntrinsicID()) {
                    case Intrinsic::gla_fTextureSampleLodRefZOffset:
                    case Intrinsic::gla_fTextureSampleLodRefZOffsetGrad:
                        types.push_back(intrinsic->getArgOperand(ETOOffset)->getType());
                    default:
                        break;
                    }

                    // add gradients
                    switch (intrinsic->getIntrinsicID()) {
                    case Intrinsic::gla_fTextureSampleLodRefZOffsetGrad:
                        types.push_back(intrinsic->getArgOperand(ETODPdx)->getType());
                        types.push_back(intrinsic->getArgOperand(ETODPdy)->getType());
                    default:
                        break;
                    }

                    // declare the new intrinsic
                    // TODO: functionality: texturing correctness: is this getting the correct non-projective form?
                    Function* texture = Intrinsic::getDeclaration(module, intrinsic->getIntrinsicID(), types);

                    // modify arguments to match new intrinsic
                    intrinsic->setCalledFunction(texture);
                    intrinsic->setArgOperand(ETOFlag, MakeUnsignedConstant(module->getContext(), texFlags));
                    intrinsic->setArgOperand(ETOCoord, newCoords);

                    switch (intrinsic->getIntrinsicID()) {
                    case Intrinsic::gla_fTextureSampleLodRefZ:
                    case Intrinsic::gla_fTextureSampleLodRefZOffset:
                    case Intrinsic::gla_fTextureSampleLodRefZOffsetGrad:
                        intrinsic->setArgOperand(ETORefZ, builder.CreateFDiv(intrinsic->getArgOperand(ETORefZ), divisor));                        
                    default:
                        break;
                    }

                    // mark our change, but don't replace the intrinsic
                    changed = true;
                }
            }
            break;

        default:
            // The cases above needs to be comprehensive in terms of checking
            // for what intrinsics to decompose.  If not there the assumption is
            // it never needs to be decomposed.
            break;
        }

        if (newInst) {
            inst->replaceAllUsesWith(newInst);
            inst->dropAllReferences();
            inst->eraseFromParent();
            changed = true;
        }
    }
}
开发者ID:OllyGinger,项目名称:LunarGLASS,代码行数:101,代码来源:DecomposeInsts.cpp


注:本文中的IntrinsicInst::setCalledFunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。