dom/include/circuit.h

140 lines
3.4 KiB
C++

/*
* MIT License
*
* Copyright (c) 2020-2022 Peking University
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* Circuit.h
*
* circuit structure
*/
#pragma once
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include "abc.h"
#define inf 100000000
#define INF 100000000
struct DoubleCut {
set<string> names;
string Name1, Name2;
int mindep, Area;
double AreaFlow;
DoubleCut() {
Name1 = "", Name2 = "";
mindep = 0;
Area = 0;
AreaFlow = 0;
}
DoubleCut(set<string> n, string nm1, string nm2, int dep, int area, double AF) {
names = n;
Name1 = nm1, Name2 = nm2;
mindep = dep;
Area = area;
AreaFlow = AF;
}
};
struct Cut {
set<string> names;
string Name;
int mindep, Area, fin;
double AreaFlow;
Cut() {
Name = "";
mindep = 0;
Area = 0;
AreaFlow = 0;
}
Cut(set<string> n, string nm, double dep, double area, double f, double AF) {
names = n;
Name = nm;
mindep = dep;
Area = area;
fin = f;
AreaFlow = AF;
}
bool operator < (const Cut A) const{
return mindep > A.mindep || (mindep == A.mindep && Area < A.Area)
|| (mindep == A.mindep && Area == A.Area && AreaFlow < A.AreaFlow);
}
};
struct Var {
string name;
bool is_in, is_out;
int depth;
vector<string> pre; // precursors
vector<string> suc; // successors
set<set<string> > cuts[10]; //K cuts
set<string> Rcut; //represent cut
//set<string> Rdcut;
Cut Fcut; // First Cut
string Partner;
int mindep, Area, fin;
double AreaFlow;
Var(string name_, bool is_in_, bool is_out_);
};
struct Circuit {
string benchmark;
map<string, Var*> graph;
int Dep;
pair<int, pair<int, int> > abc_res;
vector<string> input;
vector<string> output;
int abc_lut[10]; // there are abc_lut[k] k-input LUTs after abc lut mapping
int abc_lut_area; // total area after abc lut mapping
Circuit(string benchmark_);
~Circuit();
void standard_cell_map(string lib);
void lut_map(string lib);
pair<int, pair<int, int> > get_abc_result();
void write_dot(); // visualize the circuit
};
/* CIRCUIT_H_ */