// File: gvaumour[P]cache-simulator/src/Hierarchy.cc
// Function: Hierarchy::L1sdeallocate(unsigned long)
void
Hierarchy::L1sdeallocate(uint64_t addr)
{
	
	//Invalidation of a cache line in LLC, need to invalidate all trackers in L1s
	DirectoryEntry* entry = m_directory->getEntry(addr);
	if( entry->isInL1() )
	{
		DPRINTF(DebugHierarchy, "Hierarchy::Deallocation of the block[%#lx] from LLC, invalidation of L1s\n" , addr);
		entry->print();
		
		set<int> nodes = m_directory->getTrackers(addr);

		bool isDirty = false;
		for(auto node : nodes)
			isDirty = isDirty || m_private_caches[node]->receiveInvalidation(addr);
		
		m_LLC->getEntry(addr)->isDirty = isDirty;
		
		m_directory->resetTrackersToEntry(addr);
		m_directory->setCoherenceState(addr , CLEAN_LLC);
	}		
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rax), %rdi
movq 0xc8(%rsp), %rsi
callq 0x27b00
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x33fc0
testb $0x1, %al
jne 0x33753
jmp 0x33987
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x56a0
movq 0x20(%rsp), %rdx
leaq 0x3ebe7(%rip), %rsi     # 0x72358
leaq 0xa0(%rsp), %rdi
callq 0x5530
jmp 0x33780
leaq 0x60869(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x33a00
movq %rax, 0x18(%rsp)
jmp 0x3379f
leaq 0xa0(%rsp), %rdi
callq 0x5768
leaq 0x9f(%rsp), %rdi
callq 0x53e0
movq 0x18(%rsp), %rax
cmpq $0x0, %rax
je 0x33825
movq 0xc8(%rsp), %rsi
leaq 0x3ef24(%rip), %rdi     # 0x726f7
movb $0x0, %al
callq 0x5060
jmp 0x33825
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x33813
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5768
leaq 0x9f(%rsp), %rdi
callq 0x53e0
jmp 0x3398f
movq 0xc0(%rsp), %rdi
callq 0x27720
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0xc8(%rsp), %rdx
leaq 0x58(%rsp), %rdi
callq 0x27da0
movb $0x0, 0x57(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x33ef0
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x28ad0
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x28ab0
testb $0x1, %al
jne 0x33892
jmp 0x33914
leaq 0x40(%rsp), %rdi
callq 0x33f20
movl (%rax), %eax
movl %eax, 0x34(%rsp)
movb $0x1, %al
testb $0x1, 0x57(%rsp)
movb %al, 0x17(%rsp)
jne 0x338de
movq 0x28(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0x33ec0
movq (%rax), %rdi
movq 0xc8(%rsp), %rsi
callq 0x46e60
movb %al, 0x16(%rsp)
jmp 0x338d4
movb 0x16(%rsp), %al
movb %al, 0x17(%rsp)
jmp 0x338de
movb 0x17(%rsp), %al
andb $0x1, %al
movb %al, 0x57(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x2bab0
jmp 0x3387a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x28d00
jmp 0x3398f
movq 0x28(%rsp), %rax
movb 0x57(%rsp), %cl
movb %cl, 0x7(%rsp)
movq 0x18(%rax), %rdi
movq 0xc8(%rsp), %rsi
callq 0x46fe0
movq %rax, 0x8(%rsp)
jmp 0x33939
movq 0x28(%rsp), %rax
movq 0x8(%rsp), %rcx
movb 0x7(%rsp), %dl
andb $0x1, %dl
movb %dl, 0x1(%rcx)
movq 0x20(%rax), %rdi
movq 0xc8(%rsp), %rsi
callq 0x27fc0
jmp 0x33960
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0xc8(%rsp), %rsi
movl $0x6, %edx
callq 0x27f50
jmp 0x3397d
leaq 0x58(%rsp), %rdi
callq 0x28d00
addq $0xd8, %rsp
retq
movq 0x90(%rsp), %rdi
callq 0x5690
nopl (%rax)