source: icGREP/icgrep-devel/icgrep/pablo/arithmetic.h @ 5353

Last change on this file since 5353 was 5283, checked in by nmedfort, 2 years ago

Optimized Symbol Generation (and fixed potential bug that could allow duplicate names being constructed); made PabloKernel? extend PabloAST (temporarily removed PabloAST::getName() to avoid diamond problem); added an internal scalar to PabloKernel? struct for each Count to avoid InOut? output scalar variable problem; allowed CodeMotionPass? to move code within the same scope but across a branch statement. Began work on separating Kernels into either Block-Oriented or Segment-Oriented kernels.

File size: 2.0 KB
Line 
1#ifndef ARITHMETIC_H
2#define ARITHMETIC_H
3
4#include <pablo/pabloAST.h>
5
6namespace pablo {
7
8class Operator : public PabloAST {
9    friend class PabloBlock;
10public:
11    static inline bool classof(const PabloAST * e) {
12        switch (e->getClassTypeId()) {
13            case ClassTypeId::Add:
14            case ClassTypeId::Subtract:
15            case ClassTypeId::LessThan:
16            case ClassTypeId::LessThanEquals:
17            case ClassTypeId::Equals:
18            case ClassTypeId::GreaterThanEquals:
19            case ClassTypeId::GreaterThan:
20            case ClassTypeId::NotEquals:
21                return true;
22            default:
23                return false;
24        }
25    }
26    static inline bool classof(const void *) {
27        return false;
28    }
29    PabloAST * getLH() const {
30        return mLH;
31    }
32    PabloAST * getRH() const {
33        return mRH;
34    }
35    virtual ~Operator() { }
36protected:
37    Operator(const ClassTypeId typeId, llvm::Type * const type, PabloAST * const expr1, PabloAST * const expr2, Allocator & allocator)
38    : PabloAST(typeId, type, allocator)
39    , mLH(expr1)
40    , mRH(expr2) {
41        expr1->addUser(this);
42        expr2->addUser(this);
43    }
44private:
45    PabloAST *          mLH;
46    PabloAST *          mRH;
47};
48
49#define CREATE_OPERATOR_TYPE(Name) \
50class Name : public Operator { \
51    friend class PabloBlock; \
52public: \
53    static inline bool classof(const PabloAST * e) { \
54        return e->getClassTypeId() == ClassTypeId::Name; \
55    } \
56protected: \
57    Name(llvm::Type * const type, PabloAST * const expr1, PabloAST * const expr2, Allocator & allocator) \
58    : Operator(ClassTypeId::Name, type, expr1, expr2, allocator) { \
59    } \
60};
61
62CREATE_OPERATOR_TYPE(Add)
63CREATE_OPERATOR_TYPE(Subtract)
64CREATE_OPERATOR_TYPE(LessThan)
65CREATE_OPERATOR_TYPE(LessThanEquals)
66CREATE_OPERATOR_TYPE(Equals)
67CREATE_OPERATOR_TYPE(GreaterThanEquals)
68CREATE_OPERATOR_TYPE(GreaterThan)
69CREATE_OPERATOR_TYPE(NotEquals)
70
71#undef CREATE_OPERATOR_TYPE
72
73}
74
75#endif // ARITHMETIC_H
Note: See TracBrowser for help on using the repository browser.