// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::emit_barrier(unsigned int, unsigned int, unsigned int)
void CompilerMSL::emit_barrier(uint32_t id_exe_scope, uint32_t id_mem_scope, uint32_t id_mem_sem)
{
	if (get_entry_point().model != ExecutionModelGLCompute)
		return;

	string bar_stmt = "threadgroup_barrier(mem_flags::";

	uint32_t mem_sem = id_mem_sem ? get<SPIRConstant>(id_mem_sem).scalar() : uint32_t(MemorySemanticsMaskNone);

	if (mem_sem & MemorySemanticsCrossWorkgroupMemoryMask)
		bar_stmt += "mem_device";
	else if (mem_sem & (MemorySemanticsSubgroupMemoryMask | MemorySemanticsWorkgroupMemoryMask |
	                    MemorySemanticsAtomicCounterMemoryMask))
		bar_stmt += "mem_threadgroup";
	else if (mem_sem & MemorySemanticsImageMemoryMask)
		bar_stmt += "mem_texture";
	else
		bar_stmt += "mem_none";

	if (msl_options.is_ios() && msl_options.supports_msl_version(2))
	{
		bar_stmt += ", ";

		// Use the wider of the two scopes (smaller value)
		uint32_t exe_scope = id_exe_scope ? get<SPIRConstant>(id_exe_scope).scalar() : uint32_t(ScopeInvocation);
		uint32_t mem_scope = id_mem_scope ? get<SPIRConstant>(id_mem_scope).scalar() : uint32_t(ScopeInvocation);
		uint32_t scope = min(exe_scope, mem_scope);
		switch (scope)
		{
		case ScopeCrossDevice:
		case ScopeDevice:
			bar_stmt += "memory_scope_device";
			break;

		case ScopeSubgroup:
		case ScopeInvocation:
			bar_stmt += "memory_scope_simdgroup";
			break;

		case ScopeWorkgroup:
		default:
			bar_stmt += "memory_scope_threadgroup";
			break;
		}
	}

	bar_stmt += ");";

	statement(bar_stmt);

	assert(current_emitting_block);
	flush_control_dependent_expressions(current_emitting_block->self);
	flush_all_active_variables();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movl %ecx, %r15d
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
callq 0x12fa4
cmpl $0x5, 0xb8(%rax)
jne 0x7610c
leaq 0x274db(%rip), %rsi     # 0x9d4c1
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x6100
testl %r15d, %r15d
je 0x76030
movq %rbx, %rdi
movl %r15d, %esi
callq 0x17bce
movl 0x10(%rax), %eax
btl $0x9, %eax
jb 0x7601d
testw $0x580, %ax             # imm = 0x580
je 0x76026
leaq 0x274d1(%rip), %rsi     # 0x9d4ec
jmp 0x76037
leaq 0x274bd(%rip), %rsi     # 0x9d4e1
jmp 0x76037
btl $0xb, %eax
jb 0x76119
leaq 0x274d1(%rip), %rsi     # 0x9d508
leaq 0x10(%rsp), %rdi
callq 0x64d0
cmpl $0x0, 0x7cc(%rbx)
jne 0x760c5
cmpl $0x4e20, 0x7d0(%rbx)    # imm = 0x4E20
jb 0x760c5
leaq 0x1f02e(%rip), %rsi     # 0x9508b
leaq 0x10(%rsp), %rdi
callq 0x64d0
pushq $0x4
popq %r12
movl %r12d, %r15d
testl %r14d, %r14d
je 0x76082
movq %rbx, %rdi
movl %r14d, %esi
callq 0x17bce
movl 0x10(%rax), %r15d
testl %ebp, %ebp
je 0x76094
movq %rbx, %rdi
movl %ebp, %esi
callq 0x17bce
movl 0x10(%rax), %r12d
cmpl %r15d, %r12d
cmovbl %r12d, %r15d
cmpl $0x5, %r15d
jae 0x760b4
movl %r15d, %eax
leaq 0x2501d(%rip), %rcx     # 0x9b0c8
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
jmp 0x760bb
leaq 0x27481(%rip), %rsi     # 0x9d53c
leaq 0x10(%rsp), %rdi
callq 0x64d0
leaq 0x239b4(%rip), %rsi     # 0x99a80
leaq 0x10(%rsp), %rdi
callq 0x64d0
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x9da6
movq 0x410(%rbx), %rax
testq %rax, %rax
je 0x76125
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x10956
movq %rbx, %rdi
callq 0x109b8
leaq 0x10(%rsp), %rdi
callq 0x6548
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x273dc(%rip), %rsi     # 0x9d4fc
jmp 0x76037
leaq 0x1eb27(%rip), %rdi     # 0x94c53
leaq 0x25288(%rip), %rsi     # 0x9b3bb
leaq 0x2741b(%rip), %rcx     # 0x9d555
movl $0x9e7, %edx            # imm = 0x9E7
callq 0x61c0
jmp 0x7614a
jmp 0x7614a
jmp 0x7614a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0
nop