-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test utility to create a DataDepGraph
- Loading branch information
1 parent
4556a00
commit bf32b46
Showing
3 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef OPTSCHED_TESTS_DDG_H | ||
#define OPTSCHED_TESTS_DDG_H | ||
|
||
#include "opt-sched/Scheduler/data_dep.h" | ||
#include "simple_machine_model.h" | ||
#include "gtest/gtest.h" | ||
#include <memory> | ||
#include <string> | ||
|
||
std::shared_ptr<llvm::opt_sched::DataDepGraph> | ||
makeDDG(const std::string &DDG, | ||
llvm::opt_sched::MachineModel *Model = nullptr) { | ||
using namespace llvm::opt_sched; | ||
|
||
class SimpleDDG : public DataDepGraph { | ||
public: | ||
using DataDepGraph::DataDepGraph; | ||
|
||
void convertSUnits(bool, bool) override { | ||
FAIL() << "Unsupported operation convertSUnits()"; | ||
} | ||
void convertRegFiles() override { | ||
FAIL() << "Unsupported operation convertRegFile()"; | ||
} | ||
}; | ||
|
||
struct DDGData { | ||
std::unique_ptr<MachineModel> Model = nullptr; | ||
SimpleDDG DDG; | ||
|
||
DDGData(MachineModel *Model) : DDG(Model) {} | ||
DDGData() | ||
: Model(llvm::make_unique<MachineModel>(simpleMachineModel())), | ||
DDG(Model.get()) {} | ||
}; | ||
|
||
auto Result = | ||
Model ? std::make_shared<DDGData>(Model) : std::make_shared<DDGData>(); | ||
auto Ret = Result->DDG.ReadFromString(DDG); | ||
EXPECT_TRUE(Ret != RES_ERROR && Ret != RES_FAIL && Ret != RES_TIMEOUT) | ||
<< "Failed to parse DDG"; | ||
return std::shared_ptr<DataDepGraph>(Result, &Result->DDG); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "ddg.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
using namespace llvm::opt_sched; | ||
|
||
namespace { | ||
TEST(SimpleDDG, CanBeMade) { | ||
std::shared_ptr<DataDepGraph> DDG = makeDDG(R"( | ||
dag 7 "Simple" | ||
{ | ||
dag_id fake:3 | ||
dag_weight 1.000000 | ||
compiler LLVM | ||
dag_lb -1 | ||
dag_ub -1 | ||
nodes | ||
node 0 "Inst" | ||
sched_order 0 | ||
issue_cycle 0 | ||
node 1 "Inst" | ||
sched_order 1 | ||
issue_cycle 1 | ||
node 2 "Inst" | ||
sched_order 2 | ||
issue_cycle 2 | ||
node 3 "Inst" | ||
sched_order 3 | ||
issue_cycle 3 | ||
node 4 "Inst" | ||
sched_order 4 | ||
issue_cycle 4 | ||
node 5 "artificial" "__optsched_entry" | ||
node 6 "artificial" | ||
dependencies | ||
dep 0 1 "other" 0 | ||
dep 1 2 "other" 0 | ||
dep 2 6 "other" 0 | ||
dep 3 4 "data" 1 | ||
dep 4 6 "other" 0 | ||
dep 5 3 "other" 0 | ||
dep 5 0 "other" 0 | ||
} | ||
)"); | ||
|
||
EXPECT_EQ(7, DDG->GetNodeCnt()); | ||
} | ||
|
||
TEST(SimpleDDG, CanBeMadeWithRealData) { | ||
MachineModel Model = simpleMachineModel(); | ||
{ | ||
InstTypeInfo Info; | ||
Info.issuType = Model.getDefaultIssueType(); | ||
Info.name = "ATOMIC_FENCE"; | ||
Info.isCntxtDep = false; | ||
Info.ltncy = 0; | ||
Info.pipelined = true; | ||
Info.sprtd = true; | ||
Info.blksCycle = true; | ||
Model.AddInstType(Info); | ||
|
||
Info.name = "S_BARRIER"; | ||
Model.AddInstType(Info); | ||
|
||
Info.name = "S_ADD_I32"; | ||
Info.ltncy = 1; | ||
Model.AddInstType(Info); | ||
|
||
Info.name = "S_CMP_LT_U32"; | ||
Info.ltncy = 1; | ||
Model.AddInstType(Info); | ||
} | ||
|
||
std::shared_ptr<DataDepGraph> DDG = makeDDG(R"( | ||
dag 7 "Simple" | ||
{ | ||
dag_id kernel_c18_sdk_94:3 | ||
dag_weight 1.000000 | ||
compiler LLVM | ||
dag_lb -1 | ||
dag_ub -1 | ||
nodes | ||
node 0 "ATOMIC_FENCE" | ||
sched_order 0 | ||
issue_cycle 0 | ||
node 1 "S_BARRIER" "S_BARRIER" | ||
sched_order 1 | ||
issue_cycle 1 | ||
node 2 "ATOMIC_FENCE" "ATOMIC_FENCE" | ||
sched_order 2 | ||
issue_cycle 2 | ||
node 3 "S_ADD_I32" "S_ADD_I32" | ||
sched_order 3 | ||
issue_cycle 3 | ||
node 4 "S_CMP_LT_U32" "S_CMP_LT_U32" | ||
sched_order 4 | ||
issue_cycle 4 | ||
node 5 "artificial" "__optsched_entry" | ||
node 6 "artificial" | ||
dependencies | ||
dep 0 1 "other" 0 | ||
dep 1 2 "other" 0 | ||
dep 2 6 "other" 0 | ||
dep 3 4 "data" 1 | ||
dep 4 6 "other" 0 | ||
dep 5 3 "other" 0 | ||
dep 5 0 "other" 0 | ||
} | ||
)", | ||
&Model); | ||
|
||
EXPECT_EQ(7, DDG->GetNodeCnt()); | ||
} | ||
} // namespace |