-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependencies.c
More file actions
188 lines (167 loc) · 5.4 KB
/
Copy pathdependencies.c
File metadata and controls
188 lines (167 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include "schedutils.h"
// NEED TO CHECK IF ANTIS ARE SAME AS TRUE, so if R1 dep instr or R2 = O1 dep instr or O2 dep instr Can't find anti dependencies for this yet
void addIn(Instruction temp, Instruction head, int index){
//Checking for memory dependancies
//Checking for repetitive adding of dependancies
if(index >= 2) //if 2nd or 3rd or 4th is dependant on memory instruction and it's the same, but case 1 takes care of this
if((head->depends[1]->restricts != NULL && head->depends[1]->restricts == temp)){
head->depends[index]->restricts = NULL;
return;
}
if(index >= 3) //if 3rd or 4th register is dependant on instruction but it's the same as instruction of 2nd reg.
if((head->depends[2]->restricts!= NULL && head->depends[2]->restricts==temp)){
head->depends[index]->restricts = NULL;
return;
}
if(index > 3)
if((head->depends[3]->restricts!= NULL && head->depends[3]->restricts==temp)){
head->depends[index]->restricts = NULL;
return;
}
//Setting the dependencies up
head->depends[index]->restricts = temp;
if(index > 2){
head->depends[index]->isAnti = 1;
temp->hasAnti = 1;
}
else
head->depends[index]->isAnti = 0;
int i = 0;
while(temp->successors[i] != NULL && i < temp->numInstructions){
i++;
}
if(temp->numInstructions > i)
temp->successors[i] = head;
head->numdepends++;
}
void deps(Instruction head){
Instruction temp = head;
// FOR TRUE DEPENDENCIES RAW (FIRST REGISTER)
if(head->firstReg != NULL && head->firstReg->isRegister == 0){ //It's a register and we have to find true dependencies for this one.
while(temp->prev != NULL){ //If RAR, then don't add in, break;
temp = temp->prev;
if(temp->outputReg1 != NULL && temp->outputReg1->isRegister == 0 && temp->outputReg1->value == head->firstReg->value){
addIn(temp, head, 1);
break;
}
else if(temp->outputReg2 != NULL && temp->outputReg2->isRegister == 0 && temp->outputReg2->value == head->firstReg->value){
addIn(temp, head, 1);
break;
}
}
}
temp = head;
// RAW (SECOND REGISTER)
if(head->secondReg != NULL && head->secondReg->isRegister == 0){ // Second reg and we have to find true dependencies for these ones.
while(temp->prev != NULL){
temp = temp->prev;
if(temp->outputReg1 != NULL && temp->outputReg1->isRegister == 0 && temp->outputReg1->value == head->secondReg->value){
addIn(temp, head, 2);
break;
}
else if(temp->outputReg2 != NULL && temp->outputReg2->isRegister == 0 && temp->outputReg2->value == head->secondReg->value){
addIn(temp, head, 2);
break;
}
}
}
temp=head;
// FOR ANTI DEPENDENCIES WAR (FIRST OUTPUT REGISTER)
if(head->outputReg1 != NULL && head->outputReg1->isRegister == 0){ //It's a register and we have to find true dependencies for this one.
while(temp->prev != NULL){
temp = temp->prev;
if(temp->firstReg != NULL && temp->firstReg->isRegister == 0 && temp->firstReg->value == head->outputReg1->value){
addIn(temp, head, 3);
break;
}
else if(temp->secondReg != NULL && temp->secondReg->isRegister == 0 && temp->secondReg->value == head->outputReg1->value){
addIn(temp, head, 3);
break;
}
}
}
temp = head;
// WAR (SECOND OUTPUT REGISTER)
if(head->outputReg2 != NULL && head->outputReg2->isRegister == 0){ // Second reg and we have to find true dependencies for these ones.
while(temp->prev != NULL){
temp = temp->prev;
if(temp->firstReg != NULL && temp->firstReg->isRegister == 0 && temp->firstReg->value == head->outputReg2->value){
addIn(temp, head, 4);
break;
}
else if(temp->secondReg != NULL && temp->secondReg->isRegister == 0 && temp->secondReg->value == head->outputReg2->value){
addIn(temp, head, 4);
break;
}
}
}
}
void memory_deps(Instruction head, int index){
Instruction temp = head;
//Malloc for all the other memory dependences
int i = 0; int j = 0;
i = 0; j = 0;
while(temp->prev != NULL){
temp = temp->prev;
//printNode(temp);
if(index == 0){ // Is OUtput
if(temp->ismemwrite == 1 && temp->ismemread != 1){
while(i < temp->numInstructions && temp->successors[i] != NULL){
i++;
}
temp->successors[i] = head;
while(j< temp->numInstructions && head->memoryDepends[j] != NULL){
j++;
}
head->memoryDepends[j] = temp;
}
}
else if(index == 1){ //is write
if(temp->ismemread == 1){
while(i < temp->numInstructions && temp->successors[i] != NULL){
i++;
}
temp->successors[i] = head;
while(j< temp->numInstructions && head->memoryDepends[j] != NULL){
j++;
}
head->memoryDepends[j] = temp;
}
}
else{ //is a read
if(temp->ismemwrite == 1&& temp->ismemread != 1){
while(i < temp->numInstructions && temp->successors[i] != NULL){
i++;
}
temp->successors[i] = head;
while(j< temp->numInstructions && head->memoryDepends[j] != NULL){
j++;
}
head->memoryDepends[j] = temp;
}
}
}
//puts(" ");
}
void buildDeps(Instruction head){
// If operation is nop, then no dependencies
while(head != NULL){
if(head->opcode != NOP) // If an operation other than 'no op'
{
if(head->ismemread ==1 && head->ismemwrite !=1){ //Is a read (LOAD)
memory_deps(head, 2);
}
else if(head->ismemwrite==1 && head->ismemread != 1){ //Is a write (STORE)
memory_deps(head, 1);
}
else if(head->ismem ==0){ //is I/O
memory_deps(head, 0);
}
deps(head);
}
head = head->prev;
}
}