00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TORC_PLACER_PLACEMENTSITETYPEMAPPING_HPP
00020 #define TORC_PLACER_PLACEMENTSITETYPEMAPPING_HPP
00021
00022 #include "torc/architecture/DDB.hpp"
00023 #include <string>
00024 #include <vector>
00025 #include <map>
00026 #include <set>
00027
00028 namespace torc {
00029 namespace placer {
00030
00031
00032
00033 class PlacementSiteTypeMapping {
00034 protected:
00035
00036 typedef architecture::DDB DDB;
00037 typedef architecture::Sites Sites;
00038 typedef boost::uint32_t uint32;
00039
00040
00041 typedef std::vector<uint32> InstanceTypeToCandidateTypeMap;
00042
00043 typedef architecture::Site Site;
00044 typedef std::vector<const Site*> SitePtrVector;
00045 typedef std::vector<SitePtrVector> SitePtrVectorVector;
00046 typedef std::vector<SitePtrVectorVector> SitePtrVectorVectorVector;
00047
00048 typedef std::set<Site*> SitePtrSet;
00049 typedef std::vector<SitePtrSet> SitePtrSetVector;
00050 typedef std::vector<SitePtrSetVector> SitePtrSetVectorVector;
00051
00052 public:
00053 class MappingSiteType {
00054 std::string mName;
00055 std::vector<uint32> mLegalSiteTypes;
00056 std::vector<uint32> mLegalInstanceTypes;
00057 public:
00058 MappingSiteType (std::string inName) : mName(inName) {}
00059 const std::string& getName() { return mName; }
00060 std::vector<uint32>& getSiteTypes() { return mLegalSiteTypes; }
00061 std::vector<uint32>& getInstanceTypes() { return mLegalInstanceTypes; }
00062 };
00063
00064 typedef std::vector<MappingSiteType> TypeVector;
00065
00066
00067 protected:
00068
00069 DDB& mDB;
00070 const Sites& mSites;
00071 const architecture::Array<const architecture::PrimitiveDef>& mSiteTypes;
00072
00073 TypeVector mTypeVector;
00074 std::map<std::string, uint32> mTypeLookup;
00075
00076 public:
00077 PlacementSiteTypeMapping(DDB& inDB)
00078 : mDB(inDB), mSites(inDB.getSites()), mSiteTypes(mSites.getSiteTypes()) {
00079
00080 prepareStructures();
00081
00082
00083 for (uint32 i = 0; i < mSites.getSiteTypeCount(); i++) {
00084 addMapData(mSiteTypes[i].getName(), mSiteTypes[i].getName());
00085 }
00086
00087
00088 }
00089 ~PlacementSiteTypeMapping() {}
00090 protected:
00091
00092 void prepareStructures() {
00093 mTypeVector.clear();
00094 mTypeLookup.clear();
00095
00096 for (uint32 i = 0; i < mSites.getSiteTypeCount(); i++) {
00097 mTypeVector.push_back(MappingSiteType(mSiteTypes[i].getName()));
00098 mTypeLookup.insert(std::pair<std::string, uint32>(mSiteTypes[i].getName(), i));
00099 }
00100 }
00101
00102 void addMapData(std::string itype, std::string stype) {
00103 uint32 ii = mTypeLookup[itype];
00104 uint32 si = mTypeLookup[stype];
00105
00106 mTypeVector[ii].getSiteTypes().push_back(si);
00107 mTypeVector[si].getInstanceTypes().push_back(ii);
00108
00109 }
00110 public:
00111 uint32 getNumTypes() { return mTypeLookup.size(); }
00112
00113 std::vector<MappingSiteType>& getTypeVector() {
00114 return mTypeVector;
00115 }
00116
00117 std::vector<uint32>& getLegalSitesForInstance(uint32 inInstanceTypeIndex) {
00118 return mTypeVector[inInstanceTypeIndex].getSiteTypes();
00119 }
00120 std::vector<uint32>& getLegalInstancesForSite(uint32 inSiteTypeIndex) {
00121 return mTypeVector[inSiteTypeIndex].getInstanceTypes();
00122 }
00123 MappingSiteType& getType(uint32 inIndex) { return mTypeVector[inIndex]; }
00124
00125 MappingSiteType& getType(std::string& inName) {
00126 return mTypeVector[mTypeLookup[inName]];
00127 }
00128 const std::string& getName(uint32 inIndex) { return mTypeVector[inIndex].getName(); }
00129
00130
00131 uint32 getTypeIndex(const std::string& inType) { return mTypeLookup[inType]; }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 };
00142 }
00143 }
00144
00145 #endif // TORC_PLACER_PLACEMENTSITETYPEMAPPING_HPP