/// <summary cref="IBackendCodeGenerator.GenerateCode(IfBranch)"/> public void GenerateCode(IfBranch branch) { var primitiveCondition = LoadPrimitive(branch.Condition); var condition = EnsureHardwareRegister(primitiveCondition); // Use the actual branch targets from the schedule var(trueTarget, falseTarget) = branch.GetNotInvertedBranchTargets(); // The current schedule has inverted all if conditions with implicit branch // targets to simplify the work of the PTX assembler if (Schedule.IsImplicitSuccessor(branch.BasicBlock, trueTarget)) { // Jump to false target in the else case using var command = BeginCommand( PTXInstructions.BranchOperation, new PredicateConfiguration( condition, isTrue: branch.IsInverted)); var targetLabel = blockLookup[falseTarget]; command.AppendLabel(targetLabel); } else { if (branch.IsInverted) { Utilities.Swap(ref trueTarget, ref falseTarget); } using (var command = BeginCommand( PTXInstructions.BranchOperation, new PredicateConfiguration(condition, isTrue: true))) { var targetLabel = blockLookup[trueTarget]; command.AppendLabel(targetLabel); } // Jump to false target in the else case using (var command = BeginCommand(PTXInstructions.BranchOperation)) { var targetLabel = blockLookup[falseTarget]; command.AppendLabel(targetLabel); } } }