Changeset 6159


Ignore:
Timestamp:
Sep 9, 2018, 10:09:53 AM (2 months ago)
Author:
cameron
Message:

Optimization of intersect/diff

Location:
icGREP/icgrep-devel/icgrep/re
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_diff.cpp

    r5267 r6159  
    11/*
    2  *  Copyright (c) 2014 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    66
    77#include "re_diff.h"
    8 #include "re_cc.h"
     8#include <re/re_cc.h>
     9#include <re/re_name.h>
    910#include <llvm/Support/Casting.h>
    1011
     
    1415
    1516RE * makeDiff(RE * lh, RE * rh) {
    16     if (isa<CC>(lh) && isa<CC>(rh)) {
    17         return subtractCC(cast<CC>(lh), cast<CC>(rh));
     17    if (defined<CC>(lh) && defined<CC>(rh)) {
     18        CC * lh_cc = defCast<CC>(lh);
     19        CC * rh_cc = defCast<CC>(rh);
     20        if (lh_cc->getAlphabet() == rh_cc->getAlphabet())
     21            return subtractCC(lh_cc, rh_cc);
    1822    }
    1923    return new Diff(lh, rh);
  • icGREP/icgrep-devel/icgrep/re/re_intersect.cpp

    r5267 r6159  
    11/*
    2  *  Copyright (c) 2014 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    77#include "re_intersect.h"
    88#include "re_cc.h"
     9#include <re/re_name.h>
    910#include <llvm/Support/Casting.h>
    1011
     
    1415
    1516RE * makeIntersect(RE * lh, RE * rh) {
    16     if (isa<CC>(lh) && isa<CC>(rh)) {
    17         return intersectCC(cast<CC>(lh), cast<CC>(rh));
     17    if (defined<CC>(lh) && defined<CC>(rh)) {
     18        CC * lh_cc = defCast<CC>(lh);
     19        CC * rh_cc = defCast<CC>(rh);
     20        if (lh_cc->getAlphabet() == rh_cc->getAlphabet())
     21            return intersectCC(lh_cc, rh_cc);
    1822    }
    1923    return new Intersect(lh, rh);
    2024}
    21    
     25
    2226}
  • icGREP/icgrep-devel/icgrep/re/re_name.h

    r5887 r6159  
    183183}
    184184
     185template <typename To, typename FromTy> bool defined(FromTy * e) {
     186    if (llvm::isa<To>(e)) return true;
     187    if (llvm::isa<re::Name>(e)) {
     188        re::RE * def = llvm::cast<re::Name>(e)->getDefinition();
     189        return def && defined<To, FromTy>(def);
     190    }
     191    return false;
     192}
     193
     194template <typename To, typename FromTy> To * defCast(FromTy * e) {
     195    if (llvm::isa<To>(e)) return llvm::cast<To>(e);
     196    if (llvm::isa<re::Name>(e)) {
     197        re::RE * def = llvm::cast<re::Name>(e)->getDefinition();
     198        if (def) return defCast<To, FromTy>(def);
     199    }
     200    return nullptr;
     201}
     202
     203
    185204#endif // RE_NAME_H
Note: See TracChangeset for help on using the changeset viewer.