================ @@ -369,14 +369,102 @@ llvm::Type *CommonSPIRTargetCodeGenInfo::getOpenCLType(CodeGenModule &CGM, return nullptr; } +// Gets a spirv.IntegralConstant or spirv.Literal. If IntegralType is present, +// returns an IntegralConstant, otherwise returns a Literal. +static llvm::Type *getInlineSpirvConstant(CodeGenModule &CGM, + llvm::Type *IntegralType, + llvm::APInt Value) { + llvm::LLVMContext &Ctx = CGM.getLLVMContext(); + + // Convert the APInt value to an array of uint32_t words + llvm::SmallVector<uint32_t> Words; + + while (Value.ugt(0)) { + uint32_t Word = Value.trunc(32).getZExtValue(); + Value.lshrInPlace(32); + + Words.push_back(Word); + } + if (Words.size() == 0) + Words.push_back(0); + + if (IntegralType) { + return llvm::TargetExtType::get(Ctx, "spirv.IntegralConstant", + {IntegralType}, Words); + } else { + return llvm::TargetExtType::get(Ctx, "spirv.Literal", {}, Words); + } ---------------- llvm-beanz wrote:
nit: [braces](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements) & [else](https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return) ```suggestion if (IntegralType) return llvm::TargetExtType::get(Ctx, "spirv.IntegralConstant", {IntegralType}, Words); return llvm::TargetExtType::get(Ctx, "spirv.Literal", {}, Words); ``` https://github.com/llvm/llvm-project/pull/134034 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits