00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00034 #ifndef _RTA_H_
00035 #define _RTA_H_
00036
00037 #include <inttypes.h>
00038 #include <stdio.h>
00039
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043
00044 #define RTA_API static inline
00045
00051 typedef enum {
00052 RTA_DYNAMIC = 0x5a,
00053 RTA_STATIC = 1,
00054 } RTA_TYPE;
00060 typedef enum {
00061 V_0_9 = 0,
00062 V_1_0 = 0x0123456789abcdefLL
00063 } RTA_MAGIC;
00069 typedef enum {
00070 RTA_X8664 = 0, RTA_X8632 = 1,
00071 RTA_IA64 = 2, RTA_MIPS = 3,
00072 } RTA_TARGET;
00073
00077 typedef enum {
00078 RTA_FREQUENT = 0,
00079 RTA_INFREQUENT = 1,
00080 RTA_FREQ_UNKNOWN = 2
00081 } RTA_FREQ;
00082
00083 #define RTA_SCN_NAME_PREFIX ".rta."
00084 #define RTA_SCN_NAME_PREFIX_LEN 5
00085 #define RTA_DATA_SCN_NAME ".rta.data"
00086 #define RTA_INDEX_SCN_NAME ".rta.index"
00087
00088 typedef enum {
00089 RTA_EXTRA_UNKNOWN = 0,
00090 RTA_EXTRA_RESULT = 1,
00091 RTA_EXTRA_OPERAND = 2,
00092 } RTA_EXTRA_TYPE;
00093
00101 typedef struct {
00102 UINT64 start;
00103 UINT64 data_off;
00104 UINT32 size;
00105 char padding[4];
00106 } Rta_Idx_Ent;
00107
00108
00109 RTA_API UINT64 Rta_idx_ent_start(const Rta_Idx_Ent *ent) { return ent->start; }
00110 RTA_API UINT64 Rta_idx_ent_data_off(const Rta_Idx_Ent *ent) { return ent->data_off; }
00111 RTA_API UINT32 Rta_idx_ent_size(const Rta_Idx_Ent *ent) { return ent->size; }
00112
00113 RTA_API void Rta_idx_ent_set_start(Rta_Idx_Ent *ent, UINT64 start) {
00114 FmtAssert(ent, ("The pointer to Rta_Idx_Ent is NULL"));
00115 ent->start = start;
00116 }
00117 RTA_API void Rta_idx_ent_set_data_off(Rta_Idx_Ent *ent, UINT64 data_off) {
00118 FmtAssert(ent, ("The pointer to Rta_Idx_Ent is NULL"));
00119 ent->data_off = data_off;
00120 }
00121 RTA_API void Rta_idx_ent_set_size(Rta_Idx_Ent *ent, UINT32 size) {
00122 FmtAssert(ent, ("The pointer to Rta_Idx_Ent is NULL"));
00123 ent->size = size;
00124 }
00125
00139 typedef struct {
00140 UINT64 magic;
00141 INT32 pu_off;
00142 UINT16 type;
00143 UINT16 target;
00144 UINT16 pu_num;
00145 UINT16 flags;
00146 char padding[4];
00147 } Rta_Hdr;
00148
00149
00150 RTA_API RTA_MAGIC Rta_hdr_magic(const Rta_Hdr *h) { return (RTA_MAGIC)h->magic; }
00151 RTA_API RTA_TYPE Rta_hdr_type(const Rta_Hdr *h) { return (RTA_TYPE)h->type; }
00152 RTA_API RTA_TARGET Rta_hdr_target(const Rta_Hdr *h) { return (RTA_TARGET)h->target; }
00153 RTA_API INT32 Rta_hdr_pu_off(const Rta_Hdr *h) { return h->pu_off; }
00154 RTA_API UINT16 Rta_hdr_pu_num(const Rta_Hdr *h) { return h->pu_num; }
00155 RTA_API UINT16 Rta_hdr_flags(const Rta_Hdr *h) { return h->flags; }
00156
00157 RTA_API void Rta_hdr_set_magic(Rta_Hdr *h, RTA_MAGIC magic) {
00158 FmtAssert(h, ("The pointer to Rta_Hdr is NULL"));
00159 h->magic = (UINT64)magic;
00160 }
00161 RTA_API void Rta_hdr_set_type(Rta_Hdr *h, RTA_TYPE type) {
00162 FmtAssert(h, ("The pointer to Rta_Hdr is NULL"));
00163 h->type = (UINT16)type;
00164 }
00165 RTA_API void Rta_hdr_set_target(Rta_Hdr *h, RTA_TARGET target) {
00166 FmtAssert(h, ("The pointer to Rta_Hdr is NULL"));
00167 h->target = (UINT16)target;
00168 }
00169 RTA_API void Rta_hdr_set_pu_off(Rta_Hdr *h, INT32 pu_off) {
00170 FmtAssert(h, ("The pointer to Rta_Hdr is NULL"));
00171 h->pu_off = pu_off;
00172 }
00173 RTA_API void Rta_hdr_set_pu_num(Rta_Hdr *h, UINT16 pu_num) {
00174 FmtAssert(h, ("The pointer to Rta_Hdr is NULL"));
00175 h->pu_num = pu_num;
00176 }
00177 RTA_API void Rta_hdr_set_flags(Rta_Hdr *h, UINT16 flags) {
00178 FmtAssert(h, ("The pointer to Rta_Hdr is NULL"));
00179 h->flags = flags;
00180 }
00181
00219 typedef struct {
00220 UINT64 start;
00221 UINT32 size;
00222 UINT32 name;
00223 INT32 bb_off;
00224 INT32 cfg_off;
00225 UINT32 maxregs;
00226 UINT16 bb_num;
00227 UINT16 bb_begin;
00228 UINT16 entry;
00229 UINT16 exit;
00230 UINT16 flags;
00231 INT16 link;
00232
00233 } Rta_Pu;
00234
00235
00236 RTA_API UINT64 Rta_pu_start(const Rta_Pu *ph) { return ph->start; }
00237 RTA_API UINT32 Rta_pu_size(const Rta_Pu *ph) { return ph->size; }
00238 RTA_API UINT32 Rta_pu_name(const Rta_Pu *ph) { return ph->name; }
00239 RTA_API INT32 Rta_pu_bb_off(const Rta_Pu *ph) { return ph->bb_off; }
00240 RTA_API INT32 Rta_pu_cfg_off(const Rta_Pu *ph) { return ph->cfg_off; }
00241 RTA_API UINT16 Rta_pu_bb_num(const Rta_Pu *ph) { return ph->bb_num; }
00242 RTA_API UINT16 Rta_pu_bb_begin(const Rta_Pu *ph) { return ph->bb_begin; }
00243 RTA_API UINT16 Rta_pu_entry(const Rta_Pu *ph) { return ph->entry; }
00244 RTA_API UINT16 Rta_pu_exit(const Rta_Pu *ph) { return ph->exit; }
00245 RTA_API UINT16 Rta_pu_flags(const Rta_Pu *ph) { return ph->flags; }
00246 RTA_API INT16 Rta_pu_link(const Rta_Pu *ph) { return ph->link; }
00247 RTA_API UINT32 Rta_pu_maxregs(const Rta_Pu *ph) { return ph->maxregs; }
00248
00249 RTA_API void Rta_pu_set_start(Rta_Pu *ph, UINT64 start) {
00250 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00251 ph->start = start;
00252 }
00253 RTA_API void Rta_pu_set_size(Rta_Pu *ph, UINT32 size) {
00254 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00255 ph->size = size;
00256 }
00257 RTA_API void Rta_pu_set_name(Rta_Pu *ph, UINT32 name) {
00258 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00259 ph->name = name;
00260 }
00261 RTA_API void Rta_pu_set_bb_off(Rta_Pu *ph, INT32 bb_off) {
00262 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00263 ph->bb_off = bb_off;
00264 }
00265 RTA_API void Rta_pu_set_cfg_off(Rta_Pu *ph, INT32 cfg_off) {
00266 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00267 ph->cfg_off = cfg_off;
00268 }
00269 RTA_API void Rta_pu_set_bb_num(Rta_Pu *ph, UINT16 bb_num) {
00270 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00271 ph->bb_num = bb_num;
00272 }
00273 RTA_API void Rta_pu_set_bb_begin(Rta_Pu *ph, UINT16 bb_begin) {
00274 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00275 ph->bb_begin = bb_begin;
00276 }
00277 RTA_API void Rta_pu_set_entry(Rta_Pu *ph, UINT16 entry) {
00278 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00279 ph->entry = entry;
00280 }
00281 RTA_API void Rta_pu_set_exit(Rta_Pu *ph, UINT16 exit) {
00282 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00283 ph->exit = exit;
00284 }
00285 RTA_API void Rta_pu_set_flags(Rta_Pu *ph, UINT16 flags) {
00286 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00287 ph->flags = flags;
00288 }
00289 RTA_API void Rta_pu_set_link(Rta_Pu *ph, UINT16 link) {
00290 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00291 ph->link = link;
00292 }
00293 RTA_API void Rta_pu_set_maxregs(Rta_Pu *ph, UINT32 maxregs) {
00294 FmtAssert(ph, ("The pointer to Rta_Pu is NULL"));
00295 ph->maxregs = maxregs;
00296 }
00297
00304 typedef struct {
00305 UINT32 start;
00306 UINT32 size;
00307 INT32 op_off;
00308 UINT16 plink;
00309 UINT16 slink;
00310 UINT16 op_num;
00311 UINT16 flags;
00312 char padding[4];
00313 } Rta_Bb;
00314
00315
00316 RTA_API UINT32 Rta_bb_start(const Rta_Bb *bh) { return bh->start; }
00317 RTA_API UINT32 Rta_bb_size(const Rta_Bb *bh) { return bh->size; }
00318 RTA_API INT32 Rta_bb_op_off(const Rta_Bb *bh) { return bh->op_off; }
00319 RTA_API UINT16 Rta_bb_plink(const Rta_Bb *bh) { return bh->plink; }
00320 RTA_API UINT16 Rta_bb_slink(const Rta_Bb *bh) { return bh->slink; }
00321 RTA_API UINT16 Rta_bb_op_num(const Rta_Bb *bh) { return bh->op_num; }
00322 RTA_API UINT16 Rta_bb_flags(const Rta_Bb *bh) { return bh->flags; }
00323
00324 RTA_API void Rta_bb_set_start(Rta_Bb *bh, UINT32 start) {
00325 FmtAssert(bh, ("The pointer to Rta_Bb is NULL"));
00326 bh->start = start;
00327 }
00328 RTA_API void Rta_bb_set_size(Rta_Bb *bh, UINT32 size) {
00329 FmtAssert(bh, ("The pointer to Rta_Bb is NULL"));
00330 bh->size = size;
00331 }
00332 RTA_API void Rta_bb_set_op_off(Rta_Bb *bh, INT32 op_off) {
00333 FmtAssert(bh, ("The pointer to Rta_Bb is NULL"));
00334 bh->op_off = op_off;
00335 }
00336 RTA_API void Rta_bb_set_plink(Rta_Bb *bh, UINT16 plink) {
00337 FmtAssert(bh, ("The pointer to Rta_Bb is NULL"));
00338 bh->plink = plink;
00339 }
00340 RTA_API void Rta_bb_set_slink(Rta_Bb *bh, UINT16 slink) {
00341 FmtAssert(bh, ("The pointer to Rta_Bb is NULL"));
00342 bh->slink = slink;
00343 }
00344 RTA_API void Rta_bb_set_op_num (Rta_Bb *bh, UINT16 op_num) {
00345 FmtAssert(bh, ("The pointer to Rta_Bb is NULL"));
00346 bh->op_num = op_num;
00347 }
00348 RTA_API void Rta_bb_set_flags(Rta_Bb *bh, UINT16 flags) {
00349 FmtAssert(bh, ("The pointer to Rta_Bb is NULL"));
00350 bh->flags = flags;
00351 }
00352
00359 typedef UINT16 Rta_Edge;
00360
00361 const INT RTA_EDGE_BB_BITS = 14;
00362
00363
00364 RTA_API RTA_FREQ Rta_edge_freq(const Rta_Edge * num) { return (RTA_FREQ)(*num>>RTA_EDGE_BB_BITS); }
00365 RTA_API UINT16 Rta_edge_bb(const Rta_Edge * num) { return *num & ((1<<RTA_EDGE_BB_BITS)-1); }
00366
00367 RTA_API Rta_Edge Rta_edge(RTA_FREQ freq, UINT16 bb) { return (freq<<RTA_EDGE_BB_BITS) + bb; }
00368
00372 typedef UINT16 Rta_Tn;
00373
00384 typedef struct {
00385 INT32 extra;
00386 UINT16 opcode;
00387 UINT16 result1;
00388 UINT16 opnd1;
00389 UINT16 opnd2;
00390 UINT16 flags;
00391 char padding[2];
00392 } Rta_Op;
00393
00394
00395 RTA_API INT32 Rta_op_extra(const Rta_Op *op) { return op->extra; }
00396 RTA_API UINT16 Rta_op_opcode(const Rta_Op *op) { return op->opcode; }
00397 RTA_API Rta_Tn Rta_op_result1(const Rta_Op *op) { return op->result1; }
00398 RTA_API Rta_Tn Rta_op_opnd1(const Rta_Op *op) { return op->opnd1; }
00399 RTA_API Rta_Tn Rta_op_opnd2(const Rta_Op *op) { return op->opnd2; }
00400 RTA_API UINT16 Rta_op_flags(const Rta_Op *op) { return op->flags; }
00401
00402 RTA_API void Rta_op_set_extra(Rta_Op *op, INT32 extra) {
00403 FmtAssert(op, ("The pointer to Rta_Op is NULL"));
00404 op->extra = extra;
00405 }
00406 RTA_API void Rta_op_set_opcode(Rta_Op *op, UINT16 opcode) {
00407 FmtAssert(op, ("The pointer to Rta_Op is NULL"));
00408 op->opcode = opcode;
00409 }
00410 RTA_API void Rta_op_set_result1(Rta_Op *op, Rta_Tn result1) {
00411 FmtAssert(op, ("The pointer to Rta_Op is NULL"));
00412 op->result1 = result1;
00413 }
00414 RTA_API void Rta_op_set_opnd1(Rta_Op *op, Rta_Tn opnd1) {
00415 FmtAssert(op, ("The pointer to Rta_Op is NULL"));
00416 op->opnd1 = opnd1;
00417 }
00418 RTA_API void Rta_op_set_opnd2(Rta_Op *op, Rta_Tn opnd2) {
00419 FmtAssert(op, ("The pointer to Rta_Op is NULL"));
00420 op->opnd2 = opnd2;
00421 }
00422 RTA_API void Rta_op_set_flags(Rta_Op *op, UINT16 flags) {
00423 FmtAssert(op, ("The pointer to Rta_Op is NULL"));
00424 op->flags = flags;
00425 }
00426
00440 typedef struct {
00441 INT32 offset;
00442 UINT16 type;
00443 UINT16 flags;
00444 } Rta_Extra;
00445
00446
00447 RTA_API INT32 Rta_extra_offset(const Rta_Extra *ex) { return ex->offset; }
00448 RTA_API RTA_EXTRA_TYPE Rta_extra_type(const Rta_Extra *ex) { return (RTA_EXTRA_TYPE)ex->type; }
00449 RTA_API UINT16 Rta_extra_flags(const Rta_Extra *ex) { return ex->flags & ((1<<15)-1); }
00450 RTA_API BOOL Rta_extra_last(const Rta_Extra *ex) { return ex->flags & (1<<15); }
00451
00452 RTA_API void Rta_extra_set_offset(Rta_Extra *ex, INT32 offset) {
00453 FmtAssert(ex, ("The pointer to Rta_Extra is NULL"));
00454 ex->offset = offset;
00455 }
00456 RTA_API void Rta_extra_set_type(Rta_Extra *ex, RTA_EXTRA_TYPE type) {
00457 FmtAssert(ex, ("The pointer to Rta_Extra is NULL"));
00458 ex->type = (UINT16)type;
00459 }
00460 RTA_API void Rta_extra_set_flags(Rta_Extra *ex, UINT16 flags) {
00461 FmtAssert(ex, ("The pointer to Rta_Extra is NULL"));
00462 ex->flags &= 1<<15;
00463 ex->flags |= flags & ((1<<15)-1);
00464 }
00465 RTA_API void Rta_extra_set_last(Rta_Extra *ex, BOOL last) {
00466 FmtAssert(ex, ("The pointer to Rta_Extra is NULL"));
00467 if (last)
00468 ex->flags |= 1<<15;
00469 else
00470 ex->flags &= (1<<15)-1;
00471 }
00472
00473
00474 RTA_API Rta_Pu* Rta_pu_iter(Rta_Hdr* p) { return (Rta_Pu *)((char *)p + Rta_hdr_pu_off(p)); }
00475 RTA_API Rta_Bb* Rta_bb_iter(Rta_Pu* p) { return (Rta_Bb *)((char *)p + Rta_pu_bb_off(p)); }
00476
00477
00478
00479 void Print_rta_hdr(FILE *f, const Rta_Hdr *hdr, const char *indent);
00480 void Print_rta_pu_title(FILE *f, const char *indent);
00481 void Print_rta_pu(FILE *f, const Rta_Pu *pu, const char *indent);
00482 void Print_rta_bb_title(FILE *f, const char *indent);
00483 void Print_rta_bb(FILE *f, UINT64 pc, const Rta_Bb *bb, INT i, const char *indent);
00484 void Print_rta_idx_ent(FILE *f, const Rta_Idx_Ent *ent, const char *indent);
00485
00486 #ifdef __cplusplus
00487 }
00488 #endif
00489
00490 #endif // _RTA_H_