Ignore:
Timestamp:
Nov 6, 2016, 8:37:11 PM (3 years ago)
Author:
nmedfort
Message:

Initial work on adding types to PabloAST and mutable Var objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r5160 r5202  
    88#define PE_PabloAST_H
    99
     10#include <pablo/type/streamtype.h>
    1011#include <llvm/Support/Casting.h>
    1112#include <llvm/Support/Compiler.h>
    1213#include <boost/iterator/iterator_facade.hpp>
    13 #include <iterator>
    1414#include <util/slab_allocator.h>
    1515#include <type_traits>
    16 #include <unordered_map>
    1716#include <vector>
    18 #include <pablo/pablo_type.h>
    1917
    2018using namespace llvm;
     
    2523class Statement;
    2624class String;
     25class Branch;
    2726
    2827class PabloAST {
     
    3029    friend class Variadic;
    3130    friend class StatementList;
    32     friend class Var;
    33     friend class If;   
    34     friend class While;
     31    friend class Branch;
    3532    friend class PabloBlock;
    3633    friend class Prototype;
     
    3835    friend class SymbolGenerator;
    3936    friend class Count;
     37    friend class Var;
     38    friend void addUsage(PabloAST *, PabloBlock *);
     39    friend void removeUsage(PabloAST *, PabloBlock *);
    4040public:
    4141
     
    4545    using user_iterator = Users::iterator;
    4646    using const_user_iterator = Users::const_iterator;
     47
     48    static inline bool classof(const PabloAST *) {
     49        return true;
     50    }
     51    static inline bool classof(const void *) {
     52        return false;
     53    }
    4754
    4855    enum class ClassTypeId : unsigned {
     
    5259        , Ones
    5360        // Internal types
    54         , Var
     61        , Var       
    5562        , Integer
    5663        , String
     
    7683        // Variable assignments
    7784        , Assign
    78         , Next
     85        , Extract     
    7986        , Call
    8087        , SetIthBit
     
    8390        , While
    8491    };
    85     inline ClassTypeId getClassTypeId() const {
     92
     93    inline ClassTypeId getClassTypeId() const noexcept {
    8694        return mClassTypeId;
     95    }
     96
     97    inline llvm::Type * getType() const noexcept {
     98        return mType;
     99    }
     100
     101    inline void setType(Type * type) noexcept {
     102        mType = type;
     103    }
     104
     105    inline const String * getName() const noexcept {
     106        return mName;
     107    }
     108
     109    inline void setName(const String * const name) noexcept {
     110        mName = name;
    87111    }
    88112
     
    111135    }
    112136
    113     inline const PabloType * getType() const {
    114         return mType;
    115     }
    116 
    117137    void replaceAllUsesWith(PabloAST * const expr);
    118138
     
    121141    }
    122142
    123     void* operator new (std::size_t size) noexcept {
     143    void * operator new (std::size_t size) noexcept {
    124144        return mAllocator.allocate(size);
    125145    }
     
    129149    }
    130150
     151    void print(raw_ostream & O) const;
     152
    131153protected:
    132     inline PabloAST(const ClassTypeId id, const PabloType * const type)
     154    inline PabloAST(const ClassTypeId id, Type * const type, const String * name)
    133155    : mClassTypeId(id)
    134156    , mType(type)
     157    , mName(name)
    135158    , mUsers(mVectorAllocator)
    136159    {
    137160
    138161    }
    139     void addUser(PabloAST * const user);
    140     void removeUser(PabloAST * const user);
     162    bool addUser(PabloAST * const user);
     163    bool removeUser(PabloAST * const user);
    141164    virtual ~PabloAST() {
    142165        mUsers.clear();
    143166    }   
    144     static void throwIfNonMatchingTypes(const PabloAST * const a, const PabloAST * const b);
    145     static void throwIfNonMatchingType(const PabloAST * const a, const PabloType::TypeId typeId);
    146167    static Allocator        mAllocator;
    147168    static VectorAllocator  mVectorAllocator;
    148169private:
    149170    const ClassTypeId       mClassTypeId;
    150     const PabloType * const mType;
     171    Type *                  mType;
     172    const String *          mName;
    151173    Users                   mUsers;
    152174};
     
    155177
    156178bool dominates(const PabloAST * const expr1, const PabloAST * const expr2);
     179
     180bool postdominates(const PabloAST * const expr1, const PabloAST * const expr2);
    157181
    158182class StatementList;
     
    166190    friend class Simplifier;
    167191    friend class PabloBlock;
    168     template <class ValueType, class ValueList>
    169     friend void checkEscapedValueList(const Statement *, const PabloAST * const, PabloAST * const, ValueList &);
    170192public:
    171193    static inline bool classof(const PabloAST * e) {
     
    210232    Statement * replaceWith(PabloAST * const expr, const bool rename = true, const bool recursively = false);
    211233
    212     inline const String * getName() const {
    213         return mName;
    214     }
    215     inline void setName(const String * const name) {
    216         mName = name;
    217     }
    218234    inline Statement * getNextNode() const {
    219235        return mNext;
     
    227243    virtual ~Statement() {}
    228244protected:
    229     explicit Statement(const ClassTypeId id, const PabloType * const type, std::initializer_list<PabloAST *> operands, const String * const name)
    230     : PabloAST(id, type)
    231     , mName(name)
     245    explicit Statement(const ClassTypeId id, Type * const type, std::initializer_list<PabloAST *> operands, const String * const name)
     246    : PabloAST(id, type, name)
    232247    , mNext(nullptr)
    233248    , mPrev(nullptr)
     
    243258        }
    244259    }
    245     explicit Statement(const ClassTypeId id, const PabloType * const type, const unsigned reserved, const String * const name)
    246     : PabloAST(id, type)
    247     , mName(name)
     260    explicit Statement(const ClassTypeId id, Type * const type, const unsigned reserved, const String * const name)
     261    : PabloAST(id, type, name)
    248262    , mNext(nullptr)
    249263    , mPrev(nullptr)
     
    254268    }
    255269    template<typename iterator>
    256     explicit Statement(const ClassTypeId id, const PabloType * const type, iterator begin, iterator end, const String * const name)
    257     : PabloAST(id, type)
    258     , mName(name)
     270    explicit Statement(const ClassTypeId id, Type * const type, iterator begin, iterator end, const String * const name)
     271    : PabloAST(id, type, name)
    259272    , mNext(nullptr)
    260273    , mPrev(nullptr)
     
    269282        }
    270283    }
    271 private:
    272     template <class ValueType, class ValueList>
    273     void checkEscapedValueList(Statement * branch, PabloAST * const from, PabloAST * const to, ValueList & list);
    274284protected:   
    275     const String *  mName;
    276285    Statement *     mNext;
    277286    Statement *     mPrev;
     
    343352
    344353protected:
    345     explicit Variadic(const ClassTypeId id, const PabloType * const type, std::initializer_list<PabloAST *> operands, const String * const name)
     354    explicit Variadic(const ClassTypeId id, Type * const type, std::initializer_list<PabloAST *> operands, const String * const name)
    346355    : Statement(id, type, operands, name)
    347356    , mCapacity(operands.size()) {
    348357
    349358    }
    350     explicit Variadic(const ClassTypeId id, const PabloType * const type, const unsigned reserved, String * name)
     359    explicit Variadic(const ClassTypeId id, Type * const type, const unsigned reserved, const String * name)
    351360    : Statement(id, type, reserved, name)
    352361    , mCapacity(reserved) {
     
    354363    }
    355364    template<typename iterator>
    356     explicit Variadic(const ClassTypeId id, const PabloType * const type, iterator begin, iterator end, String * name)
     365    explicit Variadic(const ClassTypeId id, Type * const type, iterator begin, iterator end, const String * name)
    357366    : Statement(id, type, begin, end, name)
    358367    , mCapacity(std::distance(begin, end)) {
     
    362371    unsigned        mCapacity;
    363372};
    364 
    365 bool escapes(const Statement * statement);
    366373
    367374class StatementList {
Note: See TracChangeset for help on using the changeset viewer.