Ignore:
Timestamp:
Dec 16, 2016, 4:16:28 PM (3 years ago)
Author:
nmedfort
Message:

Rewrite of the CarryManager? to support non-carry-collapsing loops.

File:
1 edited

Legend:

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

    r5217 r5227  
    9999}
    100100
    101 inline void printType(const Type * type, raw_string_ostream & out) {
    102     if (auto st = dyn_cast<IDISA::StreamType>(type)) {
    103         out << "<" << st->getNumElements() << " x s" << st->getFieldWidth() << ">";
    104     } else {
    105         type->print(out);
    106     }
    107 }
    108 
    109101using TypeId = PabloAST::ClassTypeId;
    110102
     
    201193
    202194PabloAST * PabloBuilder::createAssign(PabloAST * const variable, PabloAST * const value) {
    203     if (variable->getType() != value->getType()) {
    204         std::string tmp;
    205         raw_string_ostream out(tmp);
    206         out << "Cannot assign ";
    207         value->print(out);
    208         out << " to ";
    209         variable->print(out);
    210         out << ": type of ";
    211         value->print(out);
    212         out << " ";
    213         printType(value->getType(), out);
    214         out << " does not match ";
    215         variable->print(out);
    216         out << " ";
    217         printType(variable->getType(), out);
    218         throw std::runtime_error(out.str());
    219     }
    220195    return mPb->createAssign(variable, value);
    221196}
     
    426401    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
    427402        return getInteger(cast<Integer>(expr1)->value() + cast<Integer>(expr2)->value());
     403    } else if (isa<Integer>(expr1)) {
     404        if (cast<Integer>(expr1)->value() == 0) {
     405            return expr2;
     406        }
     407    } else if (isa<Integer>(expr2)) {
     408        if (cast<Integer>(expr2)->value() == 0) {
     409            return expr1;
     410        }
    428411    }
    429412    MAKE_BINARY(createAdd, TypeId::Add, expr1, expr2);
    430     return result;
    431 }
    432 
    433 PabloAST * PabloBuilder::createAdd(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
    434     if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
    435         return getInteger(cast<Integer>(expr1)->value() + cast<Integer>(expr2)->value());
    436     }
    437     MAKE_NAMED_BINARY(createAdd, TypeId::Add, prefix, expr1, expr2);
    438413    return result;
    439414}
     
    442417    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
    443418        return getInteger(cast<Integer>(expr1)->value() - cast<Integer>(expr2)->value());
     419    } else if (isa<Integer>(expr1)) {
     420        if (cast<Integer>(expr1)->value() == 0) {
     421            return expr2;
     422        }
     423    } else if (isa<Integer>(expr2)) {
     424        if (cast<Integer>(expr2)->value() == 0) {
     425            return expr1;
     426        }
    444427    }
    445428    MAKE_BINARY(createSubtract, TypeId::Subtract, expr1, expr2);
     
    447430}
    448431
    449 PabloAST * PabloBuilder::createSubtract(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
     432PabloAST * PabloBuilder::createLessThan(PabloAST * expr1, PabloAST * expr2) {
    450433    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
    451         return getInteger(cast<Integer>(expr1)->value() - cast<Integer>(expr2)->value());
    452     }
    453     MAKE_NAMED_BINARY(createSubtract, TypeId::Subtract, prefix, expr1, expr2);
     434        return getInteger(cast<Integer>(expr1)->value() < cast<Integer>(expr2)->value() ? 1 : 0);
     435    }
     436    MAKE_BINARY(createLessThan, TypeId::LessThan, expr1, expr2);
    454437    return result;
    455438}
Note: See TracChangeset for help on using the changeset viewer.