// File: jstaursky[P]hutch/src/Sleigh/slgh_compile.cc
// Function: SleighCompile::checkUniqueAllocation()
void SleighCompile::checkUniqueAllocation(void)

{ // With crossbuilds,  temporaries may need to survive across instructions in a packet, so here we
  // provide space in the offset of the temporary (within the unique space) so that the run-time sleigh
  // engine can alter the value to prevent collisions with other nearby instructions
  if (unique_allocatemask == 0) return;	// We don't have any crossbuild directives

  unique_allocatemask = 0xff;	// Provide 8 bits of free space
  int4 sa = 8;
  int4 secsize = sections.size(); // This is the upper bound for section numbers
  SubtableSymbol *sym = root; // Start with the instruction table
  int4 i = -1;
  for(;;) {
    int4 numconst = sym->getNumConstructors();
    for(int4 j=0;j<numconst;++j) {
      Constructor *ct = sym->getConstructor(j);
      ConstructTpl *tpl = ct->getTempl();
      if (tpl != (ConstructTpl *)0)
	shiftUniqueConstruct(tpl,sa);
      for(int4 k=0;k<secsize;++k) {
	ConstructTpl *namedtpl = ct->getNamedTempl(k);
	if (namedtpl != (ConstructTpl *)0)
	  shiftUniqueConstruct(namedtpl,sa);
      }
    }
    i+=1;
    if (i>=tables.size()) break;
    sym = tables[i];
  }
  uintm ubase = getUniqueBase(); // We have to adjust the unique base
  ubase <<= sa;
  setUniqueBase(ubase);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpl $0x0, 0x1d4(%rax)
jne 0x63362
jmp 0x634ab
movq -0x58(%rbp), %rdi
movl $0xff, 0x1d4(%rdi)
movl $0x8, -0xc(%rbp)
addq $0x2a0, %rdi            # imm = 0x2A0
callq 0x6be70
movq %rax, %rcx
movq -0x58(%rbp), %rax
movl %ecx, -0x10(%rbp)
movq 0x190(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rdi
callq 0x6a660
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x63439
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x6a680
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x52880
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x633ea
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x67cd0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x63429
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0xaa8d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x6341c
movq -0x48(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x67cd0
jmp 0x6341e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x633f1
jmp 0x6342b
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x633b2
movq -0x58(%rbp), %rdi
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
movq %rax, -0x60(%rbp)
addq $0x288, %rdi            # imm = 0x288
callq 0x6af50
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jb 0x63468
jmp 0x63488
movq -0x58(%rbp), %rdi
addq $0x288, %rdi            # imm = 0x288
movslq -0x1c(%rbp), %rsi
callq 0x6af70
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x6339f
movq -0x58(%rbp), %rdi
callq 0x57ca0
movq -0x58(%rbp), %rdi
movl %eax, -0x4c(%rbp)
movl -0xc(%rbp), %ecx
movl -0x4c(%rbp), %eax
shll %cl, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %esi
callq 0x57cf0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)