// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r15d
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
callq 0x15f76
cmpl $0x5, 0xb8(%rax)
jne 0x92965
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2fce3(%rip), %rsi     # 0xc2509
leaq 0x2fcfb(%rip), %rdx     # 0xc2528
leaq 0x8(%rsp), %rdi
callq 0x7be0
testl %r15d, %r15d
je 0x92873
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1c036
movl 0x10(%rax), %eax
btl $0x9, %eax
jb 0x92860
testl $0x580, %eax            # imm = 0x580
je 0x92869
leaq 0x2fcd6(%rip), %rsi     # 0xc2534
jmp 0x9287a
leaq 0x2fcc2(%rip), %rsi     # 0xc2529
jmp 0x9287a
btl $0xb, %eax
jb 0x92974
leaq 0x2fcd6(%rip), %rsi     # 0xc2550
leaq 0x8(%rsp), %rdi
callq 0x64e0
cmpl $0x0, 0x7cc(%rbx)
jne 0x92911
cmpl $0x4e20, 0x7d0(%rbx)    # imm = 0x4E20
jb 0x92911
leaq 0x27807(%rip), %rsi     # 0xba0ab
leaq 0x8(%rsp), %rdi
callq 0x64e0
movl $0x4, %r13d
movl $0x4, %r15d
testl %r14d, %r14d
je 0x928ce
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1c036
movl 0x10(%rax), %r15d
testl %ebp, %ebp
je 0x928e0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1c036
movl 0x10(%rax), %r13d
cmpl %r15d, %r13d
cmovbl %r13d, %r15d
cmpl $0x5, %r15d
jae 0x92900
movl %r15d, %eax
leaq 0x2d801(%rip), %rcx     # 0xc00f8
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
jmp 0x92907
leaq 0x2fc7d(%rip), %rsi     # 0xc2584
leaq 0x8(%rsp), %rdi
callq 0x64e0
leaq 0x2c1d8(%rip), %rsi     # 0xbeaf0
leaq 0x8(%rsp), %rdi
callq 0x64e0
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xb634
movq 0x410(%rbx), %rax
testq %rax, %rax
je 0x92980
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x12fb0
movq %rbx, %rdi
callq 0x13028
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x92965
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2fbc9(%rip), %rsi     # 0xc2544
jmp 0x9287a
leaq 0x272ec(%rip), %rdi     # 0xb9c73
leaq 0x2da75(%rip), %rsi     # 0xc0403
leaq 0x2fc08(%rip), %rcx     # 0xc259d
movl $0x9e7, %edx            # imm = 0x9E7
callq 0x61b0
jmp 0x929a5
jmp 0x929a5
jmp 0x929a5
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x929bf
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop