Skip to content

Commit 71fbdab

Browse files
Merge pull request #197 from Bo-Yuan-Huang/cleanup
[v1.1.1] Bug fix and clean up
2 parents 46fcf64 + 81418cc commit 71fbdab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+769
-1218
lines changed

.semaphore/semaphore.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ blocks:
1414
- name: build_install_test
1515
commands:
1616
- sudo apt-get update
17-
- sudo apt-get install -y bison flex libboost-all-dev z3 libz3-dev
18-
- export CC=gcc-7
19-
- export CXX=g++-7
17+
- sudo apt-get install -y bison flex z3 libz3-dev
18+
- export CC=gcc-8
19+
- export CXX=g++-8
2020
- mkdir build
2121
- cd build
22-
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DILANG_BUILD_SYNTH=ON
22+
- cmake .. -DCMAKE_BUILD_TYPE=Debug
2323
- make -j$(nproc)
2424
- sudo make install
2525
- make run_test

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ jobs:
6060
- g++-7
6161
before_install:
6262
- echo -n | openssl s_client -connect https://scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
63-
before_script:
6463
- eval "${MATRIX_EVAL}"
64+
before_script:
6565
- source $TRAVIS_BUILD_DIR/scripts/travis/install-externs.sh $TRAVIS_BUILD_DIR
6666
script:
6767
- source $TRAVIS_BUILD_DIR/scripts/travis/build-static.sh $TRAVIS_BUILD_DIR
@@ -75,7 +75,6 @@ addons:
7575
- lcov
7676
- flex
7777
- bison
78-
- libboost-all-dev
7978
- z3
8079
- libz3-dev
8180
- g++-7

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ endif()
1111
# PROJECT
1212
# name version language
1313
# ---------------------------------------------------------------------------- #
14-
project(ilang VERSION 1.1.0
14+
project(ilang VERSION 1.1.1
1515
LANGUAGES CXX
1616
)
1717

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ brew install bison flex z3
5959

6060
| OS | Compiler | CMake | z3 | Bison | Flex | Build |
6161
| ------------------------- | ------------ | ------ | ----- | ----- | ------ | ------- |
62-
| Ubuntu 16.04 (Xenial) | clang 7.0.0 | 3.12.4 | 4.4.1 | 3.0.4 | 2.6.0 | Debug |
6362
| Ubuntu 16.04 (Xenial) | gcc 7.5.0 | 3.12.4 | 4.4.1 | 3.0.4 | 2.6.0 | Debug |
64-
| Ubuntu 16.04 (Xenial) | gcc 7.5.0 | 3.17.0 | 4.4.1 | 3.0.4 | 2.6.0 | Release |
65-
| Ubuntu 18.04 (Bionic) | clang 6.0.0 | 3.10.2 | 4.4.1 | 3.0.4 | 2.6.4 | Debug |
66-
| Ubuntu 18.04 (Bionic) | gcc 7.5.0 | 3.10.2 | 4.4.1 | 3.0.4 | 2.6.4 | Debug |
67-
| Ubuntu 18.04 (Bionic) | gcc 7.5.0 | 3.17.0 | 4.4.1 | 3.0.4 | 2.6.4 | Release |
68-
| Ubuntu 20.04 (Focal Fosa) | gcc 7.4.0 | 3.17.0 | 4.4.1 | 3.0.4 | 2.6.4 | Release |
63+
| Ubuntu 16.04 (Xenial) | gcc 7.5.0 | 3.10.2 | 4.4.1 | 3.0.4 | 2.6.0 | Release |
64+
| Ubuntu 18.04 (Bionic) | gcc 8.4.0 | 3.10.2 | 4.4.1 | 3.0.4 | 2.6.4 | Debug |
65+
| Ubuntu 18.04 (Bionic) | gcc 8.4.0 | 3.10.2 | 4.4.1 | 3.0.4 | 2.6.4 | Release |
66+
| Ubuntu 20.04 (Focal Fosa) | gcc 9.3.0 | 3.17.0 | 4.8.7 | 3.0.4 | 2.6.4 | Release |
6967
| OSX 10.15.4 (Catalina) | Xcode 11.4.1 | 3.17.2 | 4.8.8 | 3.6.2 | 2.5.35 | Debug |
7068
| OSX 10.15.4 (Catalina) | Xcode 11.4.1 | 3.17.2 | 4.8.8 | 3.6.2 | 2.5.35 | Release |
7169
| Windows Server 2016 | VS 2017 | 3.17.2 | 4.8.8 | 3.3.2 | 2.6.4 | Release |

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build_script:
1010
- cd $APPVEYOR_BUILD_FOLDER
1111
- mkdir -p build
1212
- cd build
13-
- cmake .. -DCMAKE_BUILD_TYPE=Release
13+
- cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-9
1414
- make -j$(nproc)
1515
- sudo make install
1616
- make test

azure-pipelines.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
sudo apt-get update
6464
sudo apt-get install bison
6565
sudo apt-get install flex
66-
sudo apt-get install libboost-all-dev
6766
sudo apt-get install z3
6867
sudo apt-get install libz3-dev
6968
displayName: 'package'
@@ -84,14 +83,13 @@ jobs:
8483
sudo apt-get update
8584
sudo apt-get install bison
8685
sudo apt-get install flex
87-
sudo apt-get install libboost-all-dev
8886
sudo apt-get install z3
8987
sudo apt-get install libz3-dev
9088
displayName: 'package'
9189
- script: |
9290
mkdir -p build
9391
cd build
94-
cmake .. -DCMAKE_BUILD_TYPE=Release
92+
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-8
9593
cmake --build .
9694
sudo cmake --build . --target install
9795
cmake --build . --target test

include/ilang/ila-mngr/pass.h

+19-9
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,38 @@
1111
/// \namespace ilang
1212
namespace ilang {
1313

14+
/// \namespace pass
15+
namespace pass {
16+
1417
/// Infer the control flow graph among the child-instructions (instr. seq.)
15-
bool PassInferChildProgCFG(const InstrLvlAbsPtr& m);
18+
bool InferChildProgCFG(const InstrLvlAbsPtr& m);
1619

1720
/// Map the child program (and its entry point) to the parent instruction
18-
bool PassMapChildProgEntryPoint(const InstrLvlAbsPtr& m);
21+
bool MapChildProgEntryPoint(const InstrLvlAbsPtr& m);
1922

2023
/// Rewrite the conditional STORE in the AST.
21-
bool PassRewriteConditionalStore(const InstrLvlAbsPtr& m);
24+
bool RewriteConditionalStore(const InstrLvlAbsPtr& m);
2225

2326
/// Rewrite the STORE-LOAD pattern in the AST.
24-
bool PassRewriteStoreLoad(const InstrLvlAbsPtr& m);
27+
bool RewriteStoreLoad(const InstrLvlAbsPtr& m);
2528

2629
/// A pass template for rewriting AST in an ILA.
2730
/// \param[in] m The target ILA.
2831
/// \param[in] Rewr The pass-specific rewriting function.
29-
bool PassRewriteGeneric(const InstrLvlAbsPtr& m,
30-
std::function<ExprPtr(const ExprPtr)> Rewr);
32+
bool RewriteGeneric(const InstrLvlAbsPtr& m,
33+
std::function<ExprPtr(const ExprPtr)> Rewr);
3134

32-
/// Simplify instruction state updates.
33-
/// \param[in] m The target ILA.
35+
/// \brief Simplify instructions (across the hierarchy) semantically (z3).
36+
/// \param[in] m The top-level ILA.
3437
/// \param[in] timeout Max time (ms) for each SMT query. (-1 for default)
35-
bool PassSimplifyInstrUpdate(const InstrLvlAbsPtr& m, const int& timeout = -1);
38+
bool SimplifySemantic(const InstrLvlAbsCnstPtr& m, const int& timeout = -1);
39+
40+
/// \brief Simplify instructions (across the hierarchy) syntactically.
41+
/// (Light-weight simplification, no SMT query.)
42+
/// \param[in] m The top-level ILA.
43+
bool SimplifySyntactic(const InstrLvlAbsPtr& m);
44+
45+
} // namespace pass
3646

3747
}; // namespace ilang
3848

include/ilang/ila-mngr/u_rewriter.h

+17-13
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,42 @@ class FuncObjRewrExpr {
1515
FuncObjRewrExpr(const ExprMap& rule) : rule_(rule) {}
1616

1717
/// Return the rewritten result.
18-
ExprPtr get(const ExprPtr e) const;
18+
ExprPtr get(const ExprPtr& e) const;
1919

2020
/// Pre-process: return true (break) if the node has been visited.
21-
bool pre(const ExprPtr e) const;
21+
bool pre(const ExprPtr& e) const;
2222
/// Post-process: update the rewriting rule map.
23-
void post(const ExprPtr e);
23+
void post(const ExprPtr& e);
2424

2525
protected:
2626
/// Internal rewriting table.
2727
ExprMap rule_;
2828

2929
/// Rewrite all sorts of Expr.
30-
virtual ExprPtr Rewrite(const ExprPtr e) const;
30+
virtual ExprPtr Rewrite(const ExprPtr& e) const;
3131
/// Rewrite Operation sorted Expr.
32-
virtual ExprPtr RewriteOp(const ExprPtr e) const;
32+
virtual ExprPtr RewriteOp(const ExprPtr& e) const;
3333

3434
}; // class FuncObjRewrExpr
3535

3636
/// \brief Function object for rewriting ILA tree.
3737
class FuncObjRewrIla {
38-
public:
38+
private:
3939
/// Type for storing ILA to ILA mapping.
4040
typedef CnstIlaMap IlaMap;
4141

42+
public:
4243
/// Constructor.
4344
FuncObjRewrIla(const IlaMap& ila_map, const ExprMap& expr_map)
4445
: ila_map_(ila_map), expr_map_(expr_map) {}
4546

4647
/// Return the mapped ILA.
47-
InstrLvlAbsPtr get(const InstrLvlAbsCnstPtr m) const;
48+
InstrLvlAbsPtr get(const InstrLvlAbsCnstPtr& m) const;
4849

4950
/// Pre-processing: create new ILA based on the given source.
50-
bool pre(const InstrLvlAbsCnstPtr src);
51+
bool pre(const InstrLvlAbsCnstPtr& src);
5152
/// Nothing.
52-
void post(const InstrLvlAbsCnstPtr src) const;
53+
void post(const InstrLvlAbsCnstPtr& src) const;
5354

5455
private:
5556
/// ILA mapping.
@@ -71,21 +72,24 @@ class FuncObjFlatIla {
7172
- Hongce
7273
*/
7374

74-
public:
75+
private:
7576
/// Type for storing ILA to ILA mapping.
7677
typedef CnstIlaMap IlaMap;
77-
typedef std::stack<ExprPtr> ValidCondStack;
7878

79+
public:
7980
/// Constructor.
8081
FuncObjFlatIla(const InstrLvlAbsCnstPtr& top_, const IlaMap& ila_map,
8182
const ExprMap& expr_map);
8283

8384
/// Pre-processing: create new ILA based on the given source.
84-
bool pre(const InstrLvlAbsCnstPtr src);
85+
bool pre(const InstrLvlAbsCnstPtr& src);
8586
/// Nothing.
86-
void post(const InstrLvlAbsCnstPtr src);
87+
void post(const InstrLvlAbsCnstPtr& src);
8788

8889
private:
90+
/// Type for holding valid condition stack across the hierarchy.
91+
typedef std::stack<ExprPtr> ValidCondStack;
92+
8993
/// ILA mapping.
9094
IlaMap ila_map_;
9195
/// Expr mapping.

include/ilang/ila-mngr/u_smt_switch.h

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class SmtSwitchItf {
5555
// ------------------------- HELPERS -------------------------------------- //
5656
/// Insert the SMT Term of the given node into the map.
5757
void PopulateExprMap(const ExprPtr expr);
58-
/// Make Term of expr based on its argument terms.
59-
smt::Term Expr2Term(const ExprPtr expr, const smt::TermVec& arg_terms);
6058
/// Make Term of expr variable.
6159
smt::Term ExprVar2Term(const ExprPtr expr);
6260
/// Make Term of expr constant.

include/ilang/ila-mngr/u_unroller.h

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class Unroller {
5757
ZExpr GetZ3Expr(const ExprPtr e);
5858
/// Return the z3::expr representing a and b are equal at their time.
5959
ZExpr Equal(const ExprPtr va, const int& ta, const ExprPtr vb, const int& tb);
60+
/// Return the z3::func_decl representing f.
61+
z3::func_decl GetZ3FuncDecl(const FuncPtr& f) const;
6062

6163
protected:
6264
// ------------------------- MEMBERS -------------------------------------- //

include/ilang/ila/hash_ast.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ namespace ilang {
1414
/// \brief Simplifier for AST trees by sharing nodes based on the hash value.
1515
class ExprMngr {
1616
public:
17+
/// Pointer type for passing shared ast simplifier.
18+
typedef std::shared_ptr<ExprMngr> ExprMngrPtr;
19+
1720
// ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
1821
/// Default constructor.
1922
ExprMngr();
2023
/// Default destructor.
2124
~ExprMngr();
2225

23-
/// Pointer type for passing shared ast simplifier.
24-
typedef std::shared_ptr<ExprMngr> ExprMngrPtr;
25-
/// Type for cacheing the AST node hashing.
26-
typedef std::unordered_map<size_t, const ExprPtr> HashTable;
27-
2826
// ------------------------- HELPERS -------------------------------------- //
2927
/// \brief Create an object and return the pointer. Used for hiding
3028
/// implementation specific types.
@@ -36,18 +34,18 @@ class ExprMngr {
3634

3735
// ------------------------- METHODS -------------------------------------- //
3836
/// Return the AST node representative.
39-
ExprPtr GetRep(const ExprPtr node);
37+
ExprPtr GetRep(const ExprPtr& node);
4038
/// Function object for sharing ast nodes.
41-
void operator()(const ExprPtr node);
39+
void operator()(const ExprPtr& node);
4240

4341
private:
4442
// ------------------------- MEMBERS -------------------------------------- //
4543
/// The map for AST nodes.
46-
HashTable map_;
44+
std::unordered_map<std::string, ExprPtr> map_;
4745

4846
// ------------------------- HELPER FUNCTIONS ----------------------------- //
4947
/// Hash function.
50-
size_t Hash(const ExprPtr node) const;
48+
static std::string Hash(const ExprPtr& node);
5149

5250
}; // class ExprMngr
5351

include/ilang/ilang++.h

+23-6
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ class FuncRef {
398398
// ------------------------- ACCESSORS/MUTATORS --------------------------- //
399399
/// Return the function name as std::string.
400400
std::string name() const;
401+
/// Return the wrapped Func pointer.
402+
inline FuncPtr get() const { return ptr_; }
401403

402404
// ------------------------- METHODS -------------------------------------- //
403405
/// Apply the function with no argument.
@@ -409,11 +411,6 @@ class FuncRef {
409411
/// Apply the function with multiple arguments.
410412
ExprRef operator()(const std::vector<ExprRef>& argvec) const;
411413

412-
private:
413-
// ------------------------- ACCESSORS/MUTATORS --------------------------- //
414-
/// Return the wrapped Func pointer.
415-
inline FuncPtr get() const { return ptr_; }
416-
417414
}; // class FuncRef
418415

419416
/// \brief The wrapper of Instr (instruction).
@@ -583,6 +580,18 @@ class Ila {
583580
/// top-level parent instructions.
584581
void FlattenHierarchy();
585582

583+
/// \brief Supported pass ID.
584+
typedef enum PassID {
585+
SIMPLIFY_SYNTACTIC = 0,
586+
SIMPLIFY_SEMANTIC,
587+
REWRITE_CONDITIONAL_STORE,
588+
REWRITE_LOAD_FROM_STORE
589+
} PassID;
590+
591+
/// \brief Execute the specified passes in order.
592+
/// \param[in] passes the list of passes to execute.
593+
bool ExecutePass(const std::vector<PassID>& passes) const;
594+
586595
}; // class Ila
587596

588597
/******************************************************************************/
@@ -607,6 +616,7 @@ bool ExportIlaPortable(const Ila& ila, const std::string& file_name);
607616
/// \param[in] file_name the name of the ILA portable (JSON) file to import.
608617
Ila ImportIlaPortable(const std::string& file_name);
609618

619+
#ifdef SYNTH_INTERFACE
610620
/// \brief Import the synthesized abstraction from file.
611621
/// \param[in] file_name the name of the synthesized abstraction (.ila) file.
612622
/// \param[in] ila_name the name of the generated ILA.
@@ -620,9 +630,14 @@ Ila ImportSynthAbstraction(const std::string& file_name,
620630
/// \param[in] ila_name the name pf the generated child-ILA.
621631
void ImportChildSynthAbstraction(const std::string& file_name, Ila& parent,
622632
const std::string& ila_name);
633+
#endif // SYNTH_INTERFACE
623634

624635
/// \brief Generate the SystemC simulator.
625-
void ExportSysCSim(const Ila& ila, const std::string& dir_path);
636+
/// \param [in] ila the top-level ILA to generate.
637+
/// \param [in] dir_path directory path of the generated simulator.
638+
/// \param [in] optimize set true to enable optimization.
639+
void ExportSysCSim(const Ila& ila, const std::string& dir_path,
640+
bool optimize = false);
626641

627642
/******************************************************************************/
628643
// Verification.
@@ -692,6 +707,8 @@ class IlaZ3Unroller {
692707
/// Return the z3::expr representing a and b are equal at their time.
693708
z3::expr Equal(const ExprRef& va, const int& ta, const ExprRef& vb,
694709
const int& tb);
710+
/// Return the z3::func_decl representing f.
711+
z3::func_decl GetZ3FuncDecl(const FuncRef& f) const;
695712

696713
private:
697714
// ------------------------- MEMBERS -------------------------------------- //

include/ilang/target-sc/ilator.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class Ilator {
2929
// ------------------------- METHODS -------------------------------------- //
3030
/// \brief Generate the SystemC simulator.
3131
/// \param[in] dst the directory path for the generated simulator.
32-
void Generate(const std::string& dst);
32+
/// \param[in] opt set true to enable optimization.
33+
void Generate(const std::string& dst, bool opt);
3334

3435
private:
3536
/// Internal type of the string buffer.
@@ -74,14 +75,16 @@ class Ilator {
7475
/// Check if the ILA model contains unsupported patterns.
7576
bool SanityCheck() const;
7677
/// Generation bootstrap, e.g., creating directories.
77-
bool Bootstrap(const std::string& root);
78+
bool Bootstrap(const std::string& root, bool opt);
7879

7980
/// Interpret instruction semantics (decode and state updates).
8081
bool GenerateInstrContent(const InstrPtr& instr, const std::string& dir);
8182
/// Special handle for memory updates.
8283
bool GenerateMemoryUpdate(const std::string& dir);
8384
/// Special handle for constant memory.
8485
bool GenerateConstantMemory(const std::string& dir);
86+
/// Generate setup function for initial condition.
87+
bool GenerateInitialSetup(const std::string& dir);
8588
/// Generate the instruction scheduler and driver.
8689
bool GenerateExecuteKernel(const std::string& dir);
8790
/// Generate the shared header files.
@@ -91,7 +94,7 @@ class Ilator {
9194

9295
/// Translate expression node to SystemC statements.
9396
bool RenderExpr(const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
94-
/// Translation routine entry point.
97+
/// Translation routine for entrypoint.
9598
void DfsExpr(const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
9699
/// Translation routine for variable.
97100
void DfsVar(const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut) const;

0 commit comments

Comments
 (0)