mirror of
https://github.com/RPCSX/SPIRV-Tools.git
synced 2025-03-07 10:47:57 +00:00
Kill the spvCheckReturn macro.
This commit is contained in:
parent
75bf78c70b
commit
5abf40816a
@ -68,9 +68,10 @@ spv_result_t spvValidateIDs(
|
||||
const spv_ext_inst_table extInstTable, const ValidationState_t& state,
|
||||
spv_position position, spv_diagnostic* pDiagnostic) {
|
||||
position->index = SPV_INDEX_INSTRUCTION;
|
||||
spvCheckReturn(spvValidateInstructionIDs(pInsts, count, opcodeTable,
|
||||
operandTable, extInstTable, state,
|
||||
position, pDiagnostic));
|
||||
if (auto error =
|
||||
spvValidateInstructionIDs(pInsts, count, opcodeTable, operandTable,
|
||||
extInstTable, state, position, pDiagnostic))
|
||||
return error;
|
||||
return SPV_SUCCESS;
|
||||
}
|
||||
|
||||
@ -132,10 +133,10 @@ spv_result_t ProcessInstruction(void* user_data,
|
||||
|
||||
DebugInstructionPass(_, inst);
|
||||
// TODO(umar): Perform data rules pass
|
||||
spvCheckReturn(IdPass(_, inst));
|
||||
spvCheckReturn(ModuleLayoutPass(_, inst));
|
||||
spvCheckReturn(CfgPass(_, inst));
|
||||
spvCheckReturn(InstructionPass(_, inst));
|
||||
if (auto error = IdPass(_, inst)) return error;
|
||||
if (auto error = ModuleLayoutPass(_, inst)) return error;
|
||||
if (auto error = CfgPass(_, inst)) return error;
|
||||
if (auto error = InstructionPass(_, inst)) return error;
|
||||
|
||||
return SPV_SUCCESS;
|
||||
}
|
||||
@ -166,7 +167,9 @@ void PrintBlocks(ValidationState_t& _, libspirv::Function func) {
|
||||
#ifdef __clang__
|
||||
#define UNUSED(func) [[gnu::unused]] func
|
||||
#elif defined(__GNUC__)
|
||||
#define UNUSED(func) func __attribute__((unused)); func
|
||||
#define UNUSED(func) \
|
||||
func __attribute__((unused)); \
|
||||
func
|
||||
#elif defined(_MSC_VER)
|
||||
#define UNUSED(func) func
|
||||
#endif
|
||||
@ -204,9 +207,10 @@ spv_result_t spvValidate(const spv_const_context context,
|
||||
// NOTE: Parse the module and perform inline validation checks. These
|
||||
// checks do not require the the knowledge of the whole module.
|
||||
ValidationState_t vstate(pDiagnostic, context);
|
||||
spvCheckReturn(spvBinaryParse(context, &vstate, binary->code,
|
||||
binary->wordCount, setHeader,
|
||||
ProcessInstruction, pDiagnostic));
|
||||
if (auto error =
|
||||
spvBinaryParse(context, &vstate, binary->code, binary->wordCount,
|
||||
setHeader, ProcessInstruction, pDiagnostic))
|
||||
return error;
|
||||
|
||||
if (vstate.in_function_body())
|
||||
return vstate.diag(SPV_ERROR_INVALID_LAYOUT)
|
||||
@ -230,9 +234,9 @@ spv_result_t spvValidate(const spv_const_context context,
|
||||
|
||||
// CFG checks are performed after the binary has been parsed
|
||||
// and the CFGPass has collected information about the control flow
|
||||
spvCheckReturn(PerformCfgChecks(vstate));
|
||||
spvCheckReturn(UpdateIdUse(vstate));
|
||||
spvCheckReturn(CheckIdDefinitionDominateUse(vstate));
|
||||
if (auto error = PerformCfgChecks(vstate)) return error;
|
||||
if (auto error = UpdateIdUse(vstate)) return error;
|
||||
if (auto error = CheckIdDefinitionDominateUse(vstate)) return error;
|
||||
|
||||
// NOTE: Copy each instruction for easier processing
|
||||
std::vector<spv_instruction_t> instructions;
|
||||
@ -250,10 +254,8 @@ spv_result_t spvValidate(const spv_const_context context,
|
||||
}
|
||||
|
||||
position.index = SPV_INDEX_INSTRUCTION;
|
||||
spvCheckReturn(spvValidateIDs(instructions.data(), instructions.size(),
|
||||
context->opcode_table, context->operand_table,
|
||||
context->ext_inst_table, vstate, &position,
|
||||
pDiagnostic));
|
||||
|
||||
return SPV_SUCCESS;
|
||||
return spvValidateIDs(instructions.data(), instructions.size(),
|
||||
context->opcode_table, context->operand_table,
|
||||
context->ext_inst_table, vstate, &position,
|
||||
pDiagnostic);
|
||||
}
|
||||
|
@ -196,7 +196,4 @@ spv_result_t spvValidateIDs(const spv_instruction_t* pInstructions,
|
||||
const spv_ext_inst_table extInstTable,
|
||||
spv_position position, spv_diagnostic* pDiagnostic);
|
||||
|
||||
#define spvCheckReturn(expression) \
|
||||
if (spv_result_t error = (expression)) return error;
|
||||
|
||||
#endif // LIBSPIRV_VALIDATE_H_
|
||||
|
@ -416,11 +416,10 @@ spv_result_t PerformCfgChecks(ValidationState_t& _) {
|
||||
auto ignore_edge = [](cbb_ptr, cbb_ptr) {};
|
||||
if (!function.ordered_blocks().empty()) {
|
||||
/// calculate dominators
|
||||
DepthFirstTraversal(function.first_block(),
|
||||
function.AugmentedCFGSuccessorsFunction(),
|
||||
ignore_block,
|
||||
[&](cbb_ptr b) { postorder.push_back(b); },
|
||||
ignore_edge);
|
||||
DepthFirstTraversal(
|
||||
function.first_block(), function.AugmentedCFGSuccessorsFunction(),
|
||||
ignore_block, [&](cbb_ptr b) { postorder.push_back(b); },
|
||||
ignore_edge);
|
||||
auto edges = libspirv::CalculateDominators(
|
||||
postorder, function.AugmentedCFGPredecessorsFunction());
|
||||
for (auto edge : edges) {
|
||||
@ -428,11 +427,10 @@ spv_result_t PerformCfgChecks(ValidationState_t& _) {
|
||||
}
|
||||
|
||||
/// calculate post dominators
|
||||
DepthFirstTraversal(function.pseudo_exit_block(),
|
||||
function.AugmentedCFGPredecessorsFunction(),
|
||||
ignore_block,
|
||||
[&](cbb_ptr b) { postdom_postorder.push_back(b); },
|
||||
ignore_edge);
|
||||
DepthFirstTraversal(
|
||||
function.pseudo_exit_block(),
|
||||
function.AugmentedCFGPredecessorsFunction(), ignore_block,
|
||||
[&](cbb_ptr b) { postdom_postorder.push_back(b); }, ignore_edge);
|
||||
auto postdom_edges = libspirv::CalculateDominators(
|
||||
postdom_postorder, function.AugmentedCFGSuccessorsFunction());
|
||||
for (auto edge : postdom_edges) {
|
||||
@ -468,7 +466,8 @@ spv_result_t PerformCfgChecks(ValidationState_t& _) {
|
||||
|
||||
/// Structured control flow checks are only required for shader capabilities
|
||||
if (_.HasCapability(SpvCapabilityShader)) {
|
||||
spvCheckReturn(StructuredControlFlowChecks(_, function, back_edges));
|
||||
if (auto error = StructuredControlFlowChecks(_, function, back_edges))
|
||||
return error;
|
||||
}
|
||||
}
|
||||
return SPV_SUCCESS;
|
||||
@ -479,21 +478,24 @@ spv_result_t CfgPass(ValidationState_t& _,
|
||||
SpvOp opcode = static_cast<SpvOp>(inst->opcode);
|
||||
switch (opcode) {
|
||||
case SpvOpLabel:
|
||||
spvCheckReturn(_.current_function().RegisterBlock(inst->result_id));
|
||||
if (auto error = _.current_function().RegisterBlock(inst->result_id))
|
||||
return error;
|
||||
break;
|
||||
case SpvOpLoopMerge: {
|
||||
uint32_t merge_block = inst->words[inst->operands[0].offset];
|
||||
uint32_t continue_block = inst->words[inst->operands[1].offset];
|
||||
CFG_ASSERT(MergeBlockAssert, merge_block);
|
||||
|
||||
spvCheckReturn(
|
||||
_.current_function().RegisterLoopMerge(merge_block, continue_block));
|
||||
if (auto error = _.current_function().RegisterLoopMerge(merge_block,
|
||||
continue_block))
|
||||
return error;
|
||||
} break;
|
||||
case SpvOpSelectionMerge: {
|
||||
uint32_t merge_block = inst->words[inst->operands[0].offset];
|
||||
CFG_ASSERT(MergeBlockAssert, merge_block);
|
||||
|
||||
spvCheckReturn(_.current_function().RegisterSelectionMerge(merge_block));
|
||||
if (auto error = _.current_function().RegisterSelectionMerge(merge_block))
|
||||
return error;
|
||||
} break;
|
||||
case SpvOpBranch: {
|
||||
uint32_t target = inst->words[inst->operands[0].offset];
|
||||
|
@ -89,12 +89,15 @@ spv_result_t FunctionScopedInstructions(ValidationState_t& _,
|
||||
}
|
||||
auto control_mask = static_cast<SpvFunctionControlMask>(
|
||||
inst->words[inst->operands[2].offset]);
|
||||
spvCheckReturn(
|
||||
_.RegisterFunction(inst->result_id, inst->type_id, control_mask,
|
||||
inst->words[inst->operands[3].offset]));
|
||||
if (_.current_layout_section() == kLayoutFunctionDefinitions)
|
||||
spvCheckReturn(_.current_function().RegisterSetFunctionDeclType(
|
||||
FunctionDecl::kFunctionDeclDefinition));
|
||||
if (auto error =
|
||||
_.RegisterFunction(inst->result_id, inst->type_id, control_mask,
|
||||
inst->words[inst->operands[3].offset]))
|
||||
return error;
|
||||
if (_.current_layout_section() == kLayoutFunctionDefinitions) {
|
||||
if (auto error = _.current_function().RegisterSetFunctionDeclType(
|
||||
FunctionDecl::kFunctionDeclDefinition))
|
||||
return error;
|
||||
}
|
||||
} break;
|
||||
|
||||
case SpvOpFunctionParameter:
|
||||
@ -108,8 +111,9 @@ spv_result_t FunctionScopedInstructions(ValidationState_t& _,
|
||||
<< "Function parameters must only appear immediately after "
|
||||
"the function definition";
|
||||
}
|
||||
spvCheckReturn(_.current_function().RegisterFunctionParameter(
|
||||
inst->result_id, inst->type_id));
|
||||
if (auto error = _.current_function().RegisterFunctionParameter(
|
||||
inst->result_id, inst->type_id))
|
||||
return error;
|
||||
break;
|
||||
|
||||
case SpvOpFunctionEnd:
|
||||
@ -128,10 +132,11 @@ spv_result_t FunctionScopedInstructions(ValidationState_t& _,
|
||||
"function definitions.";
|
||||
}
|
||||
if (_.current_layout_section() == kLayoutFunctionDeclarations) {
|
||||
spvCheckReturn(_.current_function().RegisterSetFunctionDeclType(
|
||||
FunctionDecl::kFunctionDeclDeclaration));
|
||||
if (auto error = _.current_function().RegisterSetFunctionDeclType(
|
||||
FunctionDecl::kFunctionDeclDeclaration))
|
||||
return error;
|
||||
}
|
||||
spvCheckReturn(_.RegisterFunctionEnd());
|
||||
if (auto error = _.RegisterFunctionEnd()) return error;
|
||||
break;
|
||||
|
||||
case SpvOpLine:
|
||||
@ -151,8 +156,9 @@ spv_result_t FunctionScopedInstructions(ValidationState_t& _,
|
||||
}
|
||||
if (_.current_layout_section() == kLayoutFunctionDeclarations) {
|
||||
_.ProgressToNextLayoutSectionOrder();
|
||||
spvCheckReturn(_.current_function().RegisterSetFunctionDeclType(
|
||||
FunctionDecl::kFunctionDeclDefinition));
|
||||
if (auto error = _.current_function().RegisterSetFunctionDeclType(
|
||||
FunctionDecl::kFunctionDeclDefinition))
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -198,13 +204,15 @@ spv_result_t ModuleLayoutPass(ValidationState_t& _,
|
||||
case kLayoutDebug2:
|
||||
case kLayoutAnnotations:
|
||||
case kLayoutTypes:
|
||||
spvCheckReturn(ModuleScopedInstructions(_, inst, opcode));
|
||||
if (auto error = ModuleScopedInstructions(_, inst, opcode)) return error;
|
||||
break;
|
||||
case kLayoutFunctionDeclarations:
|
||||
case kLayoutFunctionDefinitions:
|
||||
spvCheckReturn(FunctionScopedInstructions(_, inst, opcode));
|
||||
if (auto error = FunctionScopedInstructions(_, inst, opcode)) {
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
} // switch(getLayoutSection())
|
||||
}
|
||||
return SPV_SUCCESS;
|
||||
}
|
||||
} /// namespace libspirv
|
||||
|
Loading…
x
Reference in New Issue
Block a user