Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
latte
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zygzagZ
latte
Commits
726a943e
Commit
726a943e
authored
Jan 06, 2021
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Quad refactor
parent
5ea4aec5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
35 deletions
+60
-35
Compiler.cpp
src/Compiler.cpp
+2
-0
Quadruple.h
src/codeGen/Quadruple.h
+47
-30
RegisterAllocator.cpp
src/codeGen/RegisterAllocator.cpp
+8
-3
RegisterAllocator.h
src/codeGen/RegisterAllocator.h
+3
-2
No files found.
src/Compiler.cpp
View file @
726a943e
...
...
@@ -59,6 +59,8 @@ void Compiler::compileFunction(const FunctionInfoPtr& f) {
RegisterAllocator
regGen
(
quadEnv
);
regGen
.
allocate
();
for
(
const
auto
&
b
:
quadEnv
.
blocks
)
{
for
(
const
auto
&
q
:
b
->
quads
)
{
buf
<<
q
->
toString
()
<<
endl
;
...
...
src/codeGen/Quadruple.h
View file @
726a943e
...
...
@@ -46,7 +46,13 @@ public:
virtual
std
::
string
toString
()
const
{
return
to_string
(
lineno
)
+
"
\t
"
;
};
virtual
bool
isFinal
()
const
{
return
false
;
}
virtual
void
useVariables
()
{};
virtual
void
useVariables
()
{
auto
self
=
shared_from_this
();
for
(
const
auto
&
v
:
vars
())
{
if
(
v
)
v
->
uses
.
emplace_back
(
self
);
}
};
virtual
vector
<
VariablePtr
>
vars
()
const
{
return
{};
};
};
class
QWriteVar
:
public
Quadruple
{
...
...
@@ -56,6 +62,7 @@ public:
std
::
string
toString
()
const
override
{
return
Quadruple
::
toString
()
+
"
\t
"
+
(
loc
?
(
loc
->
name
+
" := "
)
:
""
);
}
void
useVariables
()
override
{
Quadruple
::
useVariables
();
if
(
loc
)
loc
->
writes
.
emplace_back
(
shared_from_this
());
}
};
...
...
@@ -82,10 +89,9 @@ public:
else
return
QWriteVar
::
toString
()
+
args
[
0
]
->
name
+
" "
+
Op
::
name
(
op
)
+
" "
+
args
[
1
]
->
name
;
}
void
useVariables
()
override
{
QWriteVar
::
useVariables
();
auto
self
=
shared_from_this
();
for
(
const
auto
&
a
:
args
)
if
(
a
)
a
->
uses
.
emplace_back
(
self
);
vector
<
VariablePtr
>
vars
()
const
override
{
return
args
;
}
};
...
...
@@ -121,9 +127,11 @@ public:
bool
isFinal
()
const
override
{
return
true
;
}
void
useVariables
()
override
{
if
(
left
)
left
->
uses
.
emplace_back
(
shared_from_this
());
if
(
right
)
right
->
uses
.
emplace_back
(
shared_from_this
());
vector
<
VariablePtr
>
vars
()
const
override
{
auto
ret
=
QJump
::
vars
();
if
(
left
)
ret
.
emplace_back
(
left
);
if
(
right
)
ret
.
emplace_back
(
right
);
return
ret
;
}
};
...
...
@@ -144,8 +152,10 @@ public:
}
}
void
useVariables
()
override
{
if
(
param
)
param
->
uses
.
emplace_back
(
shared_from_this
());
vector
<
VariablePtr
>
vars
()
const
override
{
auto
ret
=
Quadruple
::
vars
();
if
(
param
)
ret
.
emplace_back
(
param
);
return
ret
;
}
};
...
...
@@ -165,20 +175,21 @@ public:
}
}
void
useVariables
()
override
{
QWriteVar
::
useVariables
();
if
(
self
)
self
->
uses
.
emplace_back
(
shared_from_this
());
vector
<
VariablePtr
>
vars
()
const
override
{
auto
ret
=
QWriteVar
::
vars
();
if
(
self
)
ret
.
emplace_back
(
self
);
return
ret
;
}
};
class
QReturn
:
public
Quadruple
{
public:
VariablePtr
ret
;
explicit
QReturn
(
VariablePtr
ret
)
:
ret
(
std
::
move
(
ret
))
{};
VariablePtr
val
;
explicit
QReturn
(
VariablePtr
ret
)
:
val
(
std
::
move
(
ret
))
{};
std
::
string
toString
()
const
override
{
if
(
ret
)
{
return
Quadruple
::
toString
()
+
"
\t
return "
+
ret
->
name
;
if
(
val
)
{
return
Quadruple
::
toString
()
+
"
\t
return "
+
val
->
name
;
}
else
{
return
Quadruple
::
toString
()
+
"
\t
return"
;
}
...
...
@@ -186,8 +197,10 @@ public:
bool
isFinal
()
const
override
{
return
true
;
}
void
useVariables
()
override
{
if
(
ret
)
ret
->
uses
.
emplace_back
(
shared_from_this
());
vector
<
VariablePtr
>
vars
()
const
override
{
auto
ret
=
Quadruple
::
vars
();
if
(
val
)
ret
.
emplace_back
(
val
);
return
ret
;
}
};
...
...
@@ -205,10 +218,11 @@ public:
return
ret
+
access
.
toString
();
}
void
useVariables
()
override
{
QWriteVar
::
useVariables
();
if
(
access
.
base
)
access
.
base
->
uses
.
emplace_back
(
shared_from_this
());
if
(
access
.
index
)
access
.
index
->
uses
.
emplace_back
(
shared_from_this
());
vector
<
VariablePtr
>
vars
()
const
override
{
auto
ret
=
QWriteVar
::
vars
();
if
(
access
.
base
)
ret
.
emplace_back
(
access
.
base
);
if
(
access
.
index
)
ret
.
emplace_back
(
access
.
index
);
return
ret
;
}
};
...
...
@@ -222,10 +236,12 @@ public:
std
::
string
toString
()
const
override
{
return
Quadruple
::
toString
()
+
"
\t
"
+
loc
.
toString
()
+
" := "
+
val
->
name
;
}
void
useVariables
()
override
{
if
(
loc
.
base
)
loc
.
base
->
uses
.
emplace_back
(
shared_from_this
());
if
(
loc
.
index
)
loc
.
index
->
uses
.
emplace_back
(
shared_from_this
());
if
(
val
)
val
->
uses
.
emplace_back
(
shared_from_this
());
vector
<
VariablePtr
>
vars
()
const
override
{
auto
ret
=
Quadruple
::
vars
();
if
(
loc
.
base
)
ret
.
emplace_back
(
loc
.
base
);
if
(
loc
.
index
)
ret
.
emplace_back
(
loc
.
index
);
if
(
val
)
ret
.
emplace_back
(
val
);
return
ret
;
}
};
...
...
@@ -244,9 +260,10 @@ public:
return
ret
;
}
void
useVariables
()
override
{
QWriteVar
::
useVariables
();
if
(
count
)
count
->
uses
.
emplace_back
(
shared_from_this
());
vector
<
VariablePtr
>
vars
()
const
override
{
auto
ret
=
QWriteVar
::
vars
();
if
(
count
)
ret
.
emplace_back
(
count
);
return
ret
;
}
};
...
...
src/codeGen/RegisterAllocator.cpp
View file @
726a943e
...
...
@@ -3,14 +3,15 @@
#include "setOverloads.h"
void
RegisterAllocator
::
analyseLive
()
{
for
(
auto
v
:
vars
)
{
for
(
auto
q
:
v
->
uses
)
{
for
(
const
auto
&
v
:
vars
)
{
for
(
const
auto
&
q
:
v
->
uses
)
{
q
->
block
->
flow
.
use
.
emplace
(
v
);
}
for
(
auto
q
:
v
->
writes
)
{
for
(
const
auto
&
q
:
v
->
writes
)
{
q
->
block
->
flow
.
def
.
emplace
(
v
);
}
}
for
(
const
auto
&
b
:
blocks
)
{
for
(
const
auto
&
phiMap
:
b
->
phi
)
{
for
(
const
auto
&
phiRow
:
phiMap
)
{
...
...
@@ -35,4 +36,8 @@ void RegisterAllocator::analyseLive() {
}
if
(
!
changed
)
break
;
}
}
void
RegisterAllocator
::
allocate
()
{
analyseLive
();
}
\ No newline at end of file
src/codeGen/RegisterAllocator.h
View file @
726a943e
...
...
@@ -14,7 +14,7 @@ class Register : public std::enable_shared_from_this<Register> {
class
RegisterAllocator
{
public:
RegisterAllocator
(
const
QuadrupleGenerator
::
Result
&
r
)
:
blocks
(
r
.
blocks
),
vars
(
r
.
vars
)
{}
explicit
RegisterAllocator
(
const
QuadrupleGenerator
::
Result
&
r
)
:
blocks
(
r
.
blocks
),
vars
(
r
.
vars
)
{}
void
processQJump
(
shared_ptr
<
QJump
>
q
);
void
processQJumpCond
(
shared_ptr
<
QJumpCond
>
q
);
void
processQLabel
(
shared_ptr
<
QLabel
>
q
);
...
...
@@ -26,8 +26,9 @@ public:
void
processQAssign
(
shared_ptr
<
QAssign
>
q
);
void
processQCall
(
shared_ptr
<
QCall
>
q
);
void
a
nalyseLiv
e
();
void
a
llocat
e
();
private:
void
analyseLive
();
vector
<
BasicBlockPtr
>
blocks
;
vector
<
VariablePtr
>
vars
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment