Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
2
2022fall-Compiler_CMinus
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李晓奇
2022fall-Compiler_CMinus
Commits
4a232c57
Commit
4a232c57
authored
Feb 04, 2023
by
lxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modified project structure
parent
78a60f29
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
1 deletion
+87
-1
CMakeLists.txt
CMakeLists.txt
+1
-0
include/codegen/codegen.hpp
include/codegen/codegen.hpp
+9
-1
include/codegen/liverange.hpp
include/codegen/liverange.hpp
+76
-0
src/codegen/CMakeLists.txt
src/codegen/CMakeLists.txt
+1
-0
No files found.
CMakeLists.txt
View file @
4a232c57
...
...
@@ -49,5 +49,6 @@ include_directories(${PROJECT_SOURCE_DIR})
include_directories
(
${
PROJECT_BINARY_DIR
}
)
include_directories
(
include/lightir
)
include_directories
(
include/optimization
)
include_directories
(
include/codegen
)
add_subdirectory
(
src
)
add_subdirectory
(
tests
)
include/codegen.hpp
→
include/codegen
/codegen
.hpp
View file @
4a232c57
...
...
@@ -2,13 +2,17 @@
#define CODEGEN_HPP
#include "BasicBlock.h"
#include "Constant.h"
#include "Function.h"
#include "IRprinter.h"
#include "Instruction.h"
#include "Module.h"
#include "Value.h"
#include "liverange.hpp"
#include "logging.hpp"
#define __RO_PART__
#include <map>
#include <ostream>
#include <vector>
...
...
@@ -23,7 +27,7 @@ using std::vector;
class
CodeGen
{
public:
CodeGen
(
Module
*
m
odule
)
:
m
(
module
)
{}
CodeGen
(
Module
*
m
_
)
:
m
(
m_
),
LRA
(
m_
,
phi_map
)
{}
string
print
()
{
string
result
;
...
...
@@ -143,12 +147,16 @@ class CodeGen {
std
::
map
<
Function
*
,
std
::
map
<
int
,
int
>>
func_arg_off
;
// to $sp
std
::
map
<
Function
*
,
int
>
func_arg_N
;
// total space for args
std
::
map
<
BasicBlock
*
,
std
::
vector
<
std
::
pair
<
Value
*
,
Value
*>>>
phi_map
;
std
::
map
<
Constant
*
,
std
::
string
>
ROdata
;
unsigned
int
stackN
;
// function local vars and so on
Function
*
cur_func
;
Module
*
m
;
vector
<
string
>
output
;
// register allocation
LiveRangeAnalyzer
LRA
;
};
#endif
include/codegen/liverange.hpp
0 → 100644
View file @
4a232c57
#ifndef LIVERANGE_HPP
#define LIVERANGE_HPP
#include "BasicBlock.h"
#include "Function.h"
#include "Instruction.h"
#include "Module.h"
#include "Value.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
using
std
::
map
;
using
std
::
pair
;
using
std
::
set
;
using
std
::
string
;
using
std
::
vector
;
#define __LRA_PRINT__
class
LiveRangeAnalyzer
{
friend
class
CodeGen
;
using
LiveSet
=
set
<
Value
*>
;
using
PhiMap
=
map
<
BasicBlock
*
,
vector
<
pair
<
Value
*
,
Value
*>>>
;
public:
struct
Interval
{
Interval
(
int
a
,
int
b
)
:
i
(
a
),
j
(
b
)
{}
Interval
()
=
delete
;
int
i
,
j
;
};
LiveRangeAnalyzer
(
Module
*
m_
,
PhiMap
&
phi_map_
)
:
m
(
m_
),
phi_map
(
phi_map_
)
{}
LiveRangeAnalyzer
()
=
delete
;
void
run
();
void
clear
();
void
print
(
Function
*
func
,
bool
printSet
=
true
);
string
print_liveSet
(
LiveSet
&
ls
)
{
string
s
=
"[ "
;
for
(
auto
k
:
ls
)
s
+=
k
->
get_name
()
+
" "
;
s
+=
"]"
;
return
s
;
}
private:
Module
*
m
;
// Function *func;
map
<
Value
*
,
Interval
>
liverange
;
map
<
int
,
LiveSet
>
IN
,
OUT
;
map
<
Value
*
,
int
>
instr_id
;
map
<
pair
<
Value
*
,
Value
*>
,
int
>
cpstmt_id
;
const
PhiMap
&
phi_map
;
void
make_id
(
Function
*
);
void
run
(
Function
*
);
LiveSet
joinFor
(
BasicBlock
*
bb
);
void
union_ip
(
LiveSet
&
dest
,
LiveSet
&
src
)
{
LiveSet
res
;
set_union
(
dest
.
begin
(),
dest
.
end
(),
src
.
begin
(),
src
.
end
(),
std
::
inserter
(
res
,
res
.
begin
()));
dest
=
res
;
}
// Require: out-set is already set
// Return: the in-set(will not set IN-map)
LiveSet
transferFunction
(
Instruction
*
);
};
#endif
src/codegen/CMakeLists.txt
View file @
4a232c57
add_library
(
codegen STATIC
codegen.cpp
liverange.cpp
)
target_link_libraries
(
common
)
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