@@ -1884,10 +1884,9 @@ bool EmitVisitor::visit(SpirvIntrinsicInstruction *inst) {
18841884 }
18851885
18861886 for (const auto operand : inst->getOperands ()) {
1887- // TODO: Handle Literals with other types.
1888- auto literalOperand = dyn_cast<SpirvConstantInteger>(operand);
1889- if (literalOperand && literalOperand->getLiteral ()) {
1890- curInst.push_back (literalOperand->getValue ().getZExtValue ());
1887+ auto literalOperand = dyn_cast<SpirvConstant>(operand);
1888+ if (literalOperand && literalOperand->isLiteral ()) {
1889+ typeHandler.emitLiteral (literalOperand, curInst);
18911890 } else {
18921891 curInst.push_back (getOrAssignResultId<SpirvInstruction>(operand));
18931892 }
@@ -2451,6 +2450,24 @@ uint32_t EmitTypeHandler::emitType(const SpirvType *type) {
24512450 initTypeInstruction (spv::Op::OpTypeRayQueryKHR);
24522451 curTypeInst.push_back (id);
24532452 finalizeTypeInstruction ();
2453+ } else if (const auto *spvIntrinsicType =
2454+ dyn_cast<SpirvIntrinsicType>(type)) {
2455+ initTypeInstruction (static_cast <spv::Op>(spvIntrinsicType->getOpCode ()));
2456+ curTypeInst.push_back (id);
2457+ for (const SpvIntrinsicTypeOperand &operand :
2458+ spvIntrinsicType->getOperands ()) {
2459+ if (operand.isTypeOperand ) {
2460+ curTypeInst.push_back (emitType (operand.operand_as_type ));
2461+ } else {
2462+ auto *literal = dyn_cast<SpirvConstant>(operand.operand_as_inst );
2463+ if (literal && literal->isLiteral ()) {
2464+ emitLiteral (literal, curTypeInst);
2465+ } else {
2466+ curTypeInst.push_back (getOrAssignResultId (operand.operand_as_inst ));
2467+ }
2468+ }
2469+ }
2470+ finalizeTypeInstruction ();
24542471 }
24552472 // Hybrid Types
24562473 // Note: The type lowering pass should lower all types to SpirvTypes.
@@ -2467,6 +2484,50 @@ uint32_t EmitTypeHandler::emitType(const SpirvType *type) {
24672484 return id;
24682485}
24692486
2487+ template <typename vecType>
2488+ void EmitTypeHandler::emitIntLiteral (const SpirvConstantInteger *intLiteral,
2489+ vecType &outInst) {
2490+ const auto &literalVal = intLiteral->getValue ();
2491+ bool positive = !literalVal.isNegative ();
2492+ if (literalVal.getBitWidth () <= 32 ) {
2493+ outInst.push_back (positive ? literalVal.getZExtValue ()
2494+ : literalVal.getSExtValue ());
2495+ } else {
2496+ assert (literalVal.getBitWidth () == 64 );
2497+ uint64_t val =
2498+ positive ? literalVal.getZExtValue () : literalVal.getSExtValue ();
2499+ outInst.push_back (static_cast <unsigned >(val));
2500+ outInst.push_back (static_cast <unsigned >(val >> 32 ));
2501+ }
2502+ }
2503+
2504+ template <typename vecType>
2505+ void EmitTypeHandler::emitFloatLiteral (const SpirvConstantFloat *fLiteral ,
2506+ vecType &outInst) {
2507+ const auto &literalVal = fLiteral ->getValue ();
2508+ const auto bitwidth = llvm::APFloat::getSizeInBits (literalVal.getSemantics ());
2509+ if (bitwidth <= 32 ) {
2510+ outInst.push_back (literalVal.bitcastToAPInt ().getZExtValue ());
2511+ } else {
2512+ assert (bitwidth == 64 );
2513+ uint64_t val = literalVal.bitcastToAPInt ().getZExtValue ();
2514+ outInst.push_back (static_cast <unsigned >(val));
2515+ outInst.push_back (static_cast <unsigned >(val >> 32 ));
2516+ }
2517+ }
2518+
2519+ template <typename VecType>
2520+ void EmitTypeHandler::emitLiteral (const SpirvConstant *literal,
2521+ VecType &outInst) {
2522+ if (auto boolLiteral = dyn_cast<SpirvConstantBoolean>(literal)) {
2523+ outInst.push_back (static_cast <unsigned >(boolLiteral->getValue ()));
2524+ } else if (auto intLiteral = dyn_cast<SpirvConstantInteger>(literal)) {
2525+ emitIntLiteral (intLiteral, outInst);
2526+ } else if (auto fLiteral = dyn_cast<SpirvConstantFloat>(literal)) {
2527+ emitFloatLiteral (fLiteral , outInst);
2528+ }
2529+ }
2530+
24702531void EmitTypeHandler::emitDecoration (uint32_t typeResultId,
24712532 spv::Decoration decoration,
24722533 llvm::ArrayRef<uint32_t > decorationParams,
0 commit comments