2
0
Эх сурвалжийг харах

[spirv] Frontend decides function parameter type.

Making it the responsiblity of the front-end to decide whether the
function parameter type should be a pointer or not (same behavior as v1)
Ehsan Nasiri 6 жил өмнө
parent
commit
7adf35a9cd

+ 3 - 1
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -525,9 +525,11 @@ SpirvInstruction *DeclResultIdMapper::getDeclEvalInfo(const ValueDecl *decl) {
 SpirvFunctionParameter *
 DeclResultIdMapper::createFnParam(const ParmVarDecl *param) {
   const auto type = getTypeOrFnRetType(param);
+  const auto *ptrType =
+      spvContext.getPointerType(type, spv::StorageClass::Function);
   const auto loc = param->getLocation();
   SpirvFunctionParameter *fnParamInstr =
-      spvBuilder.addFnParam(type, loc, param->getName());
+      spvBuilder.addFnParam(ptrType, loc, param->getName());
 
   bool isAlias = false;
   (void)getTypeAndCreateCounterForPotentialAliasVar(param, &isAlias);

+ 1 - 2
tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

@@ -63,8 +63,7 @@ bool LowerTypeVisitor::visitInstruction(SpirvInstruction *instr) {
     }
     break;
   }
-  // Variables and function parameters must have a pointer type.
-  case spv::Op::OpFunctionParameter:
+  // Variables must have a pointer type.
   case spv::Op::OpVariable: {
     const SpirvType *pointerType =
         spvContext.getPointerType(resultType, instr->getStorageClass());

+ 1 - 1
tools/clang/lib/SPIRV/SpirvInstruction.cpp

@@ -88,7 +88,7 @@ SpirvInstruction::SpirvInstruction(Kind k, spv::Op op, QualType astType,
     : kind(k), opcode(op), astResultType(astType), resultId(id), srcLoc(loc),
       debugName(), resultType(nullptr), resultTypeId(0),
       layoutRule(SpirvLayoutRule::Void), containsAlias(false),
-      storageClass(spv::StorageClass::Max), isRValue_(false),
+      storageClass(spv::StorageClass::Function), isRValue_(false),
       isRelaxedPrecision_(false), isNonUniform_(false) {}
 
 SpirvCapability::SpirvCapability(SourceLocation loc, spv::Capability cap)