1337 fprintf(fp,"opnd_array(%d)->",idx);
1338 if (idx == 0)
1339 fprintf(fp,"int_format(ra, this, st); // %s\n", rep_var);
1340 else
1341 fprintf(fp,"ext_format(ra, this,idx%d, st); // %s\n", idx, rep_var );
1342 }
1343 }
1344
1345 // Seach through operands to determine parameters unique positions.
1346 void InstructForm::set_unique_opnds() {
1347 uint* uniq_idx = NULL;
1348 uint nopnds = num_opnds();
1349 uint num_uniq = nopnds;
1350 uint i;
1351 _uniq_idx_length = 0;
1352 if (nopnds > 0) {
1353 // Allocate index array. Worst case we're mapping from each
1354 // component back to an index and any DEF always goes at 0 so the
1355 // length of the array has to be the number of components + 1.
1356 _uniq_idx_length = _components.count() + 1;
1357 uniq_idx = (uint*) malloc(sizeof(uint) * _uniq_idx_length);
1358 for (i = 0; i < _uniq_idx_length; i++) {
1359 uniq_idx[i] = i;
1360 }
1361 }
1362 // Do it only if there is a match rule and no expand rule. With an
1363 // expand rule it is done by creating new mach node in Expand()
1364 // method.
1365 if (nopnds > 0 && _matrule != NULL && _exprule == NULL) {
1366 const char *name;
1367 uint count;
1368 bool has_dupl_use = false;
1369
1370 _parameters.reset();
1371 while ((name = _parameters.iter()) != NULL) {
1372 count = 0;
1373 uint position = 0;
1374 uint uniq_position = 0;
1375 _components.reset();
1376 Component *comp = NULL;
1377 if (sets_result()) {
3432 if( !cnt ) strcpy(buf,"_leaf");
3433 return cnt-1;
3434 }
3435 return cnt;
3436 }
3437
3438
3439 //------------------------------build_internalop-------------------------------
3440 // Build string representation of subtree
3441 void MatchNode::build_internalop( ) {
3442 char *iop, *subtree;
3443 const char *lstr, *rstr;
3444 // Build string representation of subtree
3445 // Operation lchildType rchildType
3446 int len = (int)strlen(_opType) + 4;
3447 lstr = (_lChild) ? ((_lChild->_internalop) ?
3448 _lChild->_internalop : _lChild->_opType) : "";
3449 rstr = (_rChild) ? ((_rChild->_internalop) ?
3450 _rChild->_internalop : _rChild->_opType) : "";
3451 len += (int)strlen(lstr) + (int)strlen(rstr);
3452 subtree = (char *)malloc(len);
3453 sprintf(subtree,"_%s_%s_%s", _opType, lstr, rstr);
3454 // Hash the subtree string in _internalOps; if a name exists, use it
3455 iop = (char *)_AD._internalOps[subtree];
3456 // Else create a unique name, and add it to the hash table
3457 if (iop == NULL) {
3458 iop = subtree;
3459 _AD._internalOps.Insert(subtree, iop);
3460 _AD._internalOpNames.addName(iop);
3461 _AD._internalMatch.Insert(iop, this);
3462 }
3463 // Add the internal operand name to the MatchNode
3464 _internalop = iop;
3465 _result = iop;
3466 }
3467
3468
3469 void MatchNode::dump() {
3470 output(stderr);
3471 }
3472
3846 bool is_set = ( strcmp(_opType, "Set") == 0 );
3847 if( _lChild )
3848 _lChild->swap_commutative_op(is_set, id);
3849 if( _rChild )
3850 _rChild->swap_commutative_op(is_set, id);
3851
3852 // If not the root, reduce this subtree to an internal operand
3853 if( !atroot && (_lChild || _rChild) ) {
3854 build_internalop();
3855 }
3856 }
3857
3858 //-------------------------- swap_commutative_op ------------------------------
3859 // Recursively swap specified commutative operation with subtree operands.
3860 void MatchRule::matchrule_swap_commutative_op(const char* instr_ident, int count, int& match_rules_cnt) {
3861 assert(match_rules_cnt < 100," too many match rule clones");
3862 // Clone
3863 MatchRule* clone = new MatchRule(_AD, this);
3864 // Swap operands of commutative operation
3865 ((MatchNode*)clone)->swap_commutative_op(true, count);
3866 char* buf = (char*) malloc(strlen(instr_ident) + 4);
3867 sprintf(buf, "%s_%d", instr_ident, match_rules_cnt++);
3868 clone->_result = buf;
3869
3870 clone->_next = this->_next;
3871 this-> _next = clone;
3872 if( (--count) > 0 ) {
3873 this-> matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
3874 clone->matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
3875 }
3876 }
3877
3878 //------------------------------MatchRule--------------------------------------
3879 MatchRule::MatchRule(ArchDesc &ad)
3880 : MatchNode(ad), _depth(0), _construct(NULL), _numchilds(0) {
3881 _next = NULL;
3882 }
3883
3884 MatchRule::MatchRule(ArchDesc &ad, MatchRule* mRule)
3885 : MatchNode(ad, *mRule, 0), _depth(mRule->_depth),
3886 _construct(mRule->_construct), _numchilds(mRule->_numchilds) {
|
1337 fprintf(fp,"opnd_array(%d)->",idx);
1338 if (idx == 0)
1339 fprintf(fp,"int_format(ra, this, st); // %s\n", rep_var);
1340 else
1341 fprintf(fp,"ext_format(ra, this,idx%d, st); // %s\n", idx, rep_var );
1342 }
1343 }
1344
1345 // Seach through operands to determine parameters unique positions.
1346 void InstructForm::set_unique_opnds() {
1347 uint* uniq_idx = NULL;
1348 uint nopnds = num_opnds();
1349 uint num_uniq = nopnds;
1350 uint i;
1351 _uniq_idx_length = 0;
1352 if (nopnds > 0) {
1353 // Allocate index array. Worst case we're mapping from each
1354 // component back to an index and any DEF always goes at 0 so the
1355 // length of the array has to be the number of components + 1.
1356 _uniq_idx_length = _components.count() + 1;
1357 uniq_idx = (uint*) AllocateHeap(sizeof(uint) * _uniq_idx_length);
1358 for (i = 0; i < _uniq_idx_length; i++) {
1359 uniq_idx[i] = i;
1360 }
1361 }
1362 // Do it only if there is a match rule and no expand rule. With an
1363 // expand rule it is done by creating new mach node in Expand()
1364 // method.
1365 if (nopnds > 0 && _matrule != NULL && _exprule == NULL) {
1366 const char *name;
1367 uint count;
1368 bool has_dupl_use = false;
1369
1370 _parameters.reset();
1371 while ((name = _parameters.iter()) != NULL) {
1372 count = 0;
1373 uint position = 0;
1374 uint uniq_position = 0;
1375 _components.reset();
1376 Component *comp = NULL;
1377 if (sets_result()) {
3432 if( !cnt ) strcpy(buf,"_leaf");
3433 return cnt-1;
3434 }
3435 return cnt;
3436 }
3437
3438
3439 //------------------------------build_internalop-------------------------------
3440 // Build string representation of subtree
3441 void MatchNode::build_internalop( ) {
3442 char *iop, *subtree;
3443 const char *lstr, *rstr;
3444 // Build string representation of subtree
3445 // Operation lchildType rchildType
3446 int len = (int)strlen(_opType) + 4;
3447 lstr = (_lChild) ? ((_lChild->_internalop) ?
3448 _lChild->_internalop : _lChild->_opType) : "";
3449 rstr = (_rChild) ? ((_rChild->_internalop) ?
3450 _rChild->_internalop : _rChild->_opType) : "";
3451 len += (int)strlen(lstr) + (int)strlen(rstr);
3452 subtree = (char *)AllocateHeap(len);
3453 sprintf(subtree,"_%s_%s_%s", _opType, lstr, rstr);
3454 // Hash the subtree string in _internalOps; if a name exists, use it
3455 iop = (char *)_AD._internalOps[subtree];
3456 // Else create a unique name, and add it to the hash table
3457 if (iop == NULL) {
3458 iop = subtree;
3459 _AD._internalOps.Insert(subtree, iop);
3460 _AD._internalOpNames.addName(iop);
3461 _AD._internalMatch.Insert(iop, this);
3462 }
3463 // Add the internal operand name to the MatchNode
3464 _internalop = iop;
3465 _result = iop;
3466 }
3467
3468
3469 void MatchNode::dump() {
3470 output(stderr);
3471 }
3472
3846 bool is_set = ( strcmp(_opType, "Set") == 0 );
3847 if( _lChild )
3848 _lChild->swap_commutative_op(is_set, id);
3849 if( _rChild )
3850 _rChild->swap_commutative_op(is_set, id);
3851
3852 // If not the root, reduce this subtree to an internal operand
3853 if( !atroot && (_lChild || _rChild) ) {
3854 build_internalop();
3855 }
3856 }
3857
3858 //-------------------------- swap_commutative_op ------------------------------
3859 // Recursively swap specified commutative operation with subtree operands.
3860 void MatchRule::matchrule_swap_commutative_op(const char* instr_ident, int count, int& match_rules_cnt) {
3861 assert(match_rules_cnt < 100," too many match rule clones");
3862 // Clone
3863 MatchRule* clone = new MatchRule(_AD, this);
3864 // Swap operands of commutative operation
3865 ((MatchNode*)clone)->swap_commutative_op(true, count);
3866 char* buf = (char*) AllocateHeap(strlen(instr_ident) + 4);
3867 sprintf(buf, "%s_%d", instr_ident, match_rules_cnt++);
3868 clone->_result = buf;
3869
3870 clone->_next = this->_next;
3871 this-> _next = clone;
3872 if( (--count) > 0 ) {
3873 this-> matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
3874 clone->matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
3875 }
3876 }
3877
3878 //------------------------------MatchRule--------------------------------------
3879 MatchRule::MatchRule(ArchDesc &ad)
3880 : MatchNode(ad), _depth(0), _construct(NULL), _numchilds(0) {
3881 _next = NULL;
3882 }
3883
3884 MatchRule::MatchRule(ArchDesc &ad, MatchRule* mRule)
3885 : MatchNode(ad, *mRule, 0), _depth(mRule->_depth),
3886 _construct(mRule->_construct), _numchilds(mRule->_numchilds) {
|