Ignore:
Timestamp:
Dec 1, 2015, 5:13:00 PM (3 years ago)
Author:
nmedfort
Message:

Bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4885 r4886  
    223223    }
    224224    return insertAtInsertionPoint(new Mod64ScanThru(from, thru, makeName(prefix, false)));
     225}
     226
     227template<typename Type>
     228static inline Type * isBinary(PabloAST * expr) {
     229    if (isa<Type>(expr) && cast<Type>(expr)->getNumOperands() == 2) {
     230        return cast<Type>(expr);
     231    }
     232    return nullptr;
    225233}
    226234
     
    241249            return createZeroes();
    242250        }
    243     } else if (Or * or1 = dyn_cast<Or>(expr1)) {
     251    } else if (Or * or1 = isBinary<Or>(expr1)) {
    244252        if (equals(or1->getOperand(0), expr2) || equals(or1->getOperand(1), expr2)) {
    245253            return expr2;
    246254        }
    247     } else if (Or * or2 = dyn_cast<Or>(expr2)) {
     255    } else if (Or * or2 = isBinary<Or>(expr2)) {
    248256        if (equals(or2->getOperand(0), expr1) || equals(or2->getOperand(1), expr1)) {
    249257            return expr1;
    250258        }
    251     }
    252     if (isa<Not>(expr1) || expr1 > expr2) {
    253         std::swap(expr1, expr2);
    254259    }
    255260    return insertAtInsertionPoint(new And(expr1, expr2, makeName("and_")));
     
    274279            return createZeroes();
    275280        }
    276     } else if (Or * or1 = dyn_cast<Or>(expr1)) {
     281    } else if (Or * or1 = isBinary<Or>(expr1)) {
    277282        if (equals(or1->getOperand(0), expr2) || equals(or1->getOperand(1), expr2)) {
    278283            return expr2;
    279284        }
    280     } else if (Or * or2 = dyn_cast<Or>(expr2)) {
     285    } else if (Or * or2 = isBinary<Or>(expr2)) {
    281286        if (equals(or2->getOperand(0), expr1) || equals(or2->getOperand(1), expr1)) {
    282287            return expr1;
    283288        }
    284289    }
    285     if (isa<Not>(expr1) || expr1 > expr2) {
    286         std::swap(expr1, expr2);
    287     }
    288290    return insertAtInsertionPoint(new And(expr1, expr2, makeName(prefix, false)));
    289291}
    290292
    291 And * PabloBlock::createAnd(const unsigned operands, PabloAST * value) {
    292     return insertAtInsertionPoint(new And(operands, value, makeName("and_")));
     293And * PabloBlock::createAnd(const unsigned reserved) {
     294    return insertAtInsertionPoint(new And(reserved, makeName("and_")));
    293295}
    294296
     
    301303        return expr1;
    302304    } else if (Not * not1 = dyn_cast<Not>(expr1)) {
    303         // ¬a√b = ¬¬(¬a√b) = ¬(a ∧ ¬b)
     305        // ¬a√b = ¬¬(¬a âˆš b) = ¬(a ∧ ¬b)
    304306        return createNot(createAnd(not1->getOperand(0), createNot(expr2)));
    305307    } else if (Not * not2 = dyn_cast<Not>(expr2)) {
    306         // a√¬b = ¬¬(¬b√a) = ¬(b ∧ ¬a)
     308        // a√¬b = ¬¬(¬b âˆš a) = ¬(b ∧ ¬a)
    307309        return createNot(createAnd(not2->getOperand(0), createNot(expr1)));
    308310    } else if (equals(expr1, expr2)) {
    309311        return expr1;
    310     } else if (And * and1 = dyn_cast<And>(expr1)) {
    311         if (And * and2 = dyn_cast<And>(expr2)) {
     312    } else if (And * and1 = isBinary<And>(expr1)) {
     313        if (And * and2 = isBinary<And>(expr2)) {
    312314            PabloAST * const expr1a = and1->getOperand(0);
    313315            PabloAST * const expr1b = and1->getOperand(1);
     
    325327                return createAnd(expr1b, createOr(expr1a, expr2b));
    326328            }
    327         } else if (equals(and1->getOperand(0), expr2) || equals(and1->getOperand(1), expr2)){
    328             // (a∧b) √ a = a
     329        } else if (equals(and1->getOperand(0), expr2) || equals(and1->getOperand(1), expr2)) {
     330            // (a âˆ§ b) √ a = a
    329331            return expr2;
    330332        }
    331     } else if (And * and2 = dyn_cast<And>(expr2)) {
     333    } else if (And * and2 = isBinary<And>(expr2)) {
    332334        if (equals(and2->getOperand(0), expr1) || equals(and2->getOperand(1), expr1)) {
    333335            return expr1;
    334336        }
    335     }
    336     if (expr1 > expr2) {
    337         std::swap(expr1, expr2);
    338337    }
    339338    return insertAtInsertionPoint(new Or(expr1, expr2, makeName("or_")));
     
    353352        // a√¬b = ¬¬(¬b√a) = ¬(b ∧ ¬a)
    354353        return createNot(createAnd(not2->getOperand(0), createNot(expr1)), prefix);
    355     } else if (And * and1 = dyn_cast<And>(expr1)) {
    356         if (And * and2 = dyn_cast<And>(expr2)) {
     354    } else if (And * and1 = isBinary<And>(expr1)) {
     355        if (And * and2 = isBinary<And>(expr2)) {
    357356            PabloAST * const expr1a = and1->getOperand(0);
    358357            PabloAST * const expr1b = and1->getOperand(1);
     
    374373            return expr2;
    375374        }
    376     } else if (And * and2 = dyn_cast<And>(expr2)) {
     375    } else if (And * and2 = isBinary<And>(expr2)) {
    377376        if (equals(and2->getOperand(0), expr1) || equals(and2->getOperand(1), expr1)) {
    378377            return expr1;
    379378        }
    380379    }
    381     if (expr1 > expr2) {
    382         std::swap(expr1, expr2);
    383     }
    384380    return insertAtInsertionPoint(new Or(expr1, expr2, makeName(prefix, false)));
    385381}
    386382
    387 Or * PabloBlock::createOr(const unsigned operands, PabloAST * value) {
    388     return insertAtInsertionPoint(new Or(operands, value, makeName("or_")));
     383Or * PabloBlock::createOr(const unsigned reserved) {
     384    return insertAtInsertionPoint(new Or(reserved, makeName("or_")));
    389385}
    390386
     
    407403        }
    408404    }
    409     if (expr1 > expr2) {
    410         std::swap(expr1, expr2);
    411     }
    412405    return insertAtInsertionPoint(new Xor(expr1, expr2, makeName("xor_")));
    413406}
     
    431424        }
    432425    }
    433     if (expr1 > expr2) {
    434         std::swap(expr1, expr2);
    435     }
    436426    return insertAtInsertionPoint(new Xor(expr1, expr2, makeName(prefix, false)));
     427}
     428
     429Xor * PabloBlock::createXor(const unsigned reserved) {
     430    return insertAtInsertionPoint(new Xor(reserved, makeName("xor_")));
    437431}
    438432
Note: See TracChangeset for help on using the changeset viewer.