- Timestamp:
- Jan 15, 2018, 4:07:07 PM (13 months ago)
- Location:
- icGREP/icgrep-devel/icgrep/pablo
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
icGREP/icgrep-devel/icgrep/pablo/boolean.h
r5454 r5834 6 6 namespace pablo { 7 7 8 class And final : public Variadic{8 class And final : public Statement { 9 9 friend class PabloBlock; 10 10 public: … … 18 18 protected: 19 19 And(llvm::Type * const type, PabloAST * expr1, PabloAST * expr2, const String * name, Allocator & allocator) 20 : Variadic(ClassTypeId::And, type, {expr1, expr2}, name, allocator)20 : Statement(ClassTypeId::And, type, {expr1, expr2}, name, allocator) 21 21 { 22 23 }24 And(llvm::Type * const type, const unsigned reserved, const String * name, Allocator & allocator)25 : Variadic(ClassTypeId::And, type, reserved, name, allocator)26 {27 28 }29 template<typename iterator>30 And(llvm::Type * const type, iterator begin, iterator end, const String * name, Allocator & allocator)31 : Variadic(ClassTypeId::And, type, begin, end, name, allocator) {32 22 33 23 } 34 24 }; 35 25 36 class Or final : public Variadic{26 class Or final : public Statement { 37 27 friend class PabloBlock; 38 28 public: … … 46 36 protected: 47 37 Or(llvm::Type * const type, PabloAST * expr1, PabloAST * expr2, const String * name, Allocator & allocator) 48 : Variadic(ClassTypeId::Or, type, {expr1, expr2}, name, allocator)38 : Statement(ClassTypeId::Or, type, {expr1, expr2}, name, allocator) 49 39 { 50 51 }52 Or(llvm::Type * const type, const unsigned reserved, const String * name, Allocator & allocator)53 : Variadic(ClassTypeId::Or, type, reserved, name, allocator)54 {55 56 }57 template<typename iterator>58 Or(llvm::Type * const type, iterator begin, iterator end, const String * name, Allocator & allocator)59 : Variadic(ClassTypeId::Or, type, begin, end, name, allocator) {60 40 61 41 } 62 42 }; 63 43 64 class Xor final : public Variadic{44 class Xor final : public Statement { 65 45 friend class PabloBlock; 66 46 public: … … 73 53 protected: 74 54 Xor(llvm::Type * const type, PabloAST * expr1, PabloAST * expr2, const String * name, Allocator & allocator) 75 : Variadic(ClassTypeId::Xor, type, {expr1, expr2}, name, allocator)55 : Statement(ClassTypeId::Xor, type, {expr1, expr2}, name, allocator) 76 56 { 77 78 }79 Xor(llvm::Type * const type, const unsigned reserved, const String * name, Allocator & allocator)80 : Variadic(ClassTypeId::Xor, type, reserved, name, allocator)81 {82 83 }84 template<typename iterator>85 Xor(llvm::Type * const type, iterator begin, iterator end, const String * name, Allocator & allocator)86 : Variadic(ClassTypeId::Xor, type, begin, end, name, allocator) {87 57 88 58 } -
icGREP/icgrep-devel/icgrep/pablo/builder.cpp
r5828 r5834 206 206 207 207 PabloAST * PabloBuilder::createRepeat(not_null<Integer *> fieldWidth, PabloAST * value) { 208 MAKE_BINARY(createRepeat, TypeId:: Fill, fieldWidth.get(), value);208 MAKE_BINARY(createRepeat, TypeId::Repeat, fieldWidth.get(), value); 209 209 return result; 210 210 } 211 211 212 212 PabloAST * PabloBuilder::createRepeat(not_null<Integer *> fieldWidth, PabloAST * value, const llvm::StringRef & prefix) { 213 MAKE_NAMED_BINARY(createRepeat, TypeId:: Fill, prefix, fieldWidth.get(), value);213 MAKE_NAMED_BINARY(createRepeat, TypeId::Repeat, prefix, fieldWidth.get(), value); 214 214 return result; 215 215 } -
icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp
r5828 r5834 49 49 /// 50 50 51 Count * PabloBlock::createCount(PabloAST * expr) {51 Count * PabloBlock::createCount(PabloAST * const expr) { 52 52 IntegerType * const type = getParent()->getSizeTy(); 53 53 return insertAtInsertionPoint(new (mAllocator) Count(expr, makeName("count"), type, mAllocator)); … … 61 61 Not * PabloBlock::createNot(PabloAST * expr, String * name) { 62 62 assert (expr); 63 if (name == nullptr) {64 name = makeName("not");65 }66 63 return insertAtInsertionPoint(new (mAllocator) Not(expr, name, mAllocator)); 67 64 } 68 65 69 Var * PabloBlock::createVar( PabloAST* name, Type * type) {66 Var * PabloBlock::createVar(String * name, Type * type) { 70 67 if (type == nullptr) { 71 68 type = getParent()->getStreamTy(); 72 69 } 73 if (LLVM_UNLIKELY(name == nullptr || !isa<String>(name))) {70 if (LLVM_UNLIKELY(name == nullptr)) { 74 71 throw std::runtime_error("Var objects must have a String name"); 75 72 } … … 79 76 InFile * PabloBlock::createInFile(PabloAST * expr, String * name) { 80 77 assert (expr); 81 if (name == nullptr) {82 name = makeName("inFile");83 }84 78 return insertAtInsertionPoint(new (mAllocator) InFile(expr, name, mAllocator)); 85 79 } … … 87 81 AtEOF * PabloBlock::createAtEOF(PabloAST * expr, String * name) { 88 82 assert (expr); 89 if (name == nullptr) {90 name = makeName("atEOF");91 }92 83 return insertAtInsertionPoint(new (mAllocator) AtEOF(expr, name, mAllocator)); 93 84 } … … 96 87 97 88 Advance * PabloBlock::createAdvance(PabloAST * expr, Integer * shiftAmount, String * name) { 98 if (name == nullptr) {99 name = makeName("advance");100 }101 89 return insertAtInsertionPoint(new (mAllocator) Advance(expr, shiftAmount, name, mAllocator)); 102 90 } 103 91 104 92 Lookahead * PabloBlock::createLookahead(PabloAST * expr, Integer * shiftAmount, String * name) { 105 if (name == nullptr) {106 name = makeName("lookahead");107 }108 93 return insertAtInsertionPoint(new (mAllocator) Lookahead(expr, shiftAmount, name, mAllocator)); 109 94 } … … 129 114 And * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2, String * name) { 130 115 CHECK_SAME_TYPE(expr1, expr2); 131 if (name == nullptr) {132 name = makeName("and");133 }134 116 return insertAtInsertionPoint(new (mAllocator) And(expr1->getType(), expr1, expr2, name, mAllocator)); 135 117 } 136 118 137 And * PabloBlock::createAnd(Type * const type, const unsigned reserved, String * name) {138 if (name == nullptr) {139 name = makeName("and");140 }141 return insertAtInsertionPoint(new (mAllocator) And(type, reserved, name, mAllocator));142 }143 144 119 Or * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2, String * name) { 145 120 CHECK_SAME_TYPE(expr1, expr2); 146 if (name == nullptr) {147 name = makeName("or");148 }149 121 return insertAtInsertionPoint(new (mAllocator) Or(expr1->getType(), expr1, expr2, name, mAllocator)); 150 122 } 151 123 152 Or * PabloBlock::createOr(Type * const type, const unsigned reserved, String * name) {153 if (name == nullptr) {154 name = makeName("or");155 }156 return insertAtInsertionPoint(new (mAllocator) Or(type, reserved, name, mAllocator));157 }158 159 124 Xor * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2, String * name) { 160 125 CHECK_SAME_TYPE(expr1, expr2); 161 if (name == nullptr) {162 name = makeName("xor");163 }164 126 return insertAtInsertionPoint(new (mAllocator) Xor(expr1->getType(), expr1, expr2, name, mAllocator)); 165 }166 167 Xor * PabloBlock::createXor(Type * const type, const unsigned reserved, String * name) {168 if (name == nullptr) {169 name = makeName("xor");170 }171 return insertAtInsertionPoint(new (mAllocator) Xor(type, reserved, name, mAllocator));172 127 } 173 128 … … 233 188 MatchStar * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass, String * name) { 234 189 CHECK_SAME_TYPE(marker, charclass); 235 if (name == nullptr) {236 name = makeName("matchstar");237 }238 190 return insertAtInsertionPoint(new (mAllocator) MatchStar(marker, charclass, name, mAllocator)); 239 191 } … … 241 193 ScanThru * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru, String * name) { 242 194 CHECK_SAME_TYPE(from, thru); 243 if (name == nullptr) {244 name = makeName("scanthru");245 }246 195 return insertAtInsertionPoint(new (mAllocator) ScanThru(from, thru, name, mAllocator)); 247 196 } … … 249 198 ScanTo * PabloBlock::createScanTo(PabloAST * from, PabloAST * to, String * name) { 250 199 CHECK_SAME_TYPE(from, to); 251 if (name == nullptr) {252 name = makeName("scanto");253 }254 200 return insertAtInsertionPoint(new (mAllocator) ScanTo(from, to, name, mAllocator)); 255 201 } … … 257 203 AdvanceThenScanThru * PabloBlock::createAdvanceThenScanThru(PabloAST * from, PabloAST * thru, String * name) { 258 204 CHECK_SAME_TYPE(from, thru); 259 if (name == nullptr) {260 name = makeName("advscanthru");261 }262 205 return insertAtInsertionPoint(new (mAllocator) AdvanceThenScanThru(from, thru, name, mAllocator)); 263 206 } … … 265 208 AdvanceThenScanTo * PabloBlock::createAdvanceThenScanTo(PabloAST * from, PabloAST * to, String * name) { 266 209 CHECK_SAME_TYPE(from, to); 267 if (name == nullptr) {268 name = makeName("advscanto");269 }270 210 return insertAtInsertionPoint(new (mAllocator) AdvanceThenScanTo(from, to, name, mAllocator)); 271 211 } … … 287 227 Repeat * PabloBlock::createRepeat(Integer * fieldWidth, PabloAST * value, String * name) { 288 228 assert (fieldWidth && value); 289 if (name == nullptr) {290 name = makeName("fill");291 }292 229 Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0); 293 230 return insertAtInsertionPoint(new (mAllocator) Repeat(fieldWidth, value, type, name, mAllocator)); … … 296 233 PackH * PabloBlock::createPackH(Integer * fieldWidth, PabloAST * value, String * name) { 297 234 assert (fieldWidth && value); 298 if (name == nullptr) {299 name = makeName("packh");300 }301 235 Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0); 302 236 return insertAtInsertionPoint(new (mAllocator) PackH(fieldWidth, value, name, type, mAllocator)); … … 305 239 PackL * PabloBlock::createPackL(Integer * fieldWidth, PabloAST * value, String * name) { 306 240 assert (fieldWidth && value); 307 if (name == nullptr) {308 name = makeName("packl");309 }310 241 Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0); 311 242 return insertAtInsertionPoint(new (mAllocator) PackL(fieldWidth, value, name, type, mAllocator)); … … 316 247 Sel * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, String * name) { 317 248 CHECK_SAME_TYPE(trueExpr, falseExpr); 318 if (name == nullptr) {319 name = makeName("sel");320 }321 249 return insertAtInsertionPoint(new (mAllocator) Sel(condition, trueExpr, falseExpr, name, mAllocator)); 322 250 } 323 251 324 252 IndexedAdvance * PabloBlock::createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, Integer * shiftAmount, String * name) { 325 if (name == nullptr) {326 name = makeName("indexed_advance");327 }328 253 return insertAtInsertionPoint(new (mAllocator) IndexedAdvance(expr, indexStream, shiftAmount, name, mAllocator)); 329 254 } -
icGREP/icgrep-devel/icgrep/pablo/codegenstate.h
r5828 r5834 123 123 } 124 124 125 inline Var * createVar(String * name, llvm::Type * const type = nullptr) { 126 return createVar(reinterpret_cast<PabloAST *>(name), type); 127 } 125 Var * createVar(String * name, llvm::Type * const type = nullptr); 128 126 129 127 Count * createCount(PabloAST * expr); … … 165 163 And * createAnd(PabloAST * expr1, PabloAST * expr2, String * name); 166 164 167 And * createAnd(llvm::Type * const type, const unsigned reserved) {168 return createAnd(type, reserved, nullptr);169 }170 171 And * createAnd(llvm::Type * const type, const unsigned reserved, String * name);172 173 165 Or * createOr(PabloAST * expr1, PabloAST * expr2) { 174 166 return createOr(expr1, expr2, nullptr); … … 181 173 Or * createOr(PabloAST * expr1, PabloAST * expr2, String * name); 182 174 183 Or * createOr(llvm::Type * const type, const unsigned reserved) {184 return createOr(type, reserved, nullptr);185 }186 187 Or * createOr(llvm::Type * const type, const unsigned reserved, String * name);188 189 175 Xor * createXor(PabloAST * expr1, PabloAST * expr2) { 190 176 return createXor(expr1, expr2, nullptr); … … 196 182 197 183 Xor * createXor(PabloAST * expr1, PabloAST * expr2, String * name); 198 199 Xor * createXor(llvm::Type * const type, const unsigned reserved) {200 return createXor(type, reserved, nullptr);201 }202 203 Xor * createXor(llvm::Type * const type, const unsigned reserved, String * name);204 184 205 185 Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) { … … 357 337 } 358 338 359 Var * createVar(PabloAST * name, llvm::Type * const type);360 361 339 private: 362 340 PabloKernel * const mParent; -
icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp
r5828 r5834 152 152 case PabloAST::ClassTypeId::Extract: 153 153 return mBinary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1)); 154 case PabloAST::ClassTypeId:: Fill:154 case PabloAST::ClassTypeId::Repeat: 155 155 return mBinary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getType()); 156 156 case PabloAST::ClassTypeId::Sel: -
icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp
r5821 r5834 20 20 #include <llvm/IR/Type.h> 21 21 22 #include <llvm/Support/raw_ostream.h> 23 22 24 using namespace boost; 23 25 using namespace boost::container; … … 271 273 return block->createZeroes(stmt->getType()); // ¬1 â 0 272 274 } 273 } else if (isa<Variadic>(stmt)) { 274 std::sort(cast<Variadic>(stmt)->begin(), cast<Variadic>(stmt)->end()); 275 for (unsigned i = 1; i < stmt->getNumOperands(); ) { 276 if (LLVM_UNLIKELY(stmt->getOperand(i - 1) == stmt->getOperand(i))) { 277 if (LLVM_UNLIKELY(isa<Xor>(stmt))) { 278 if (LLVM_LIKELY(stmt->getNumOperands() == 2)) { 275 } else if (isa<And>(stmt) || isa<Or>(stmt)) { 276 PabloAST * op[2]; 277 op[0] = stmt->getOperand(0); 278 op[1] = stmt->getOperand(1); 279 for (unsigned i = 0; i < 2; ++i) { 280 if (const Not * const n = dyn_cast<Not>(op[i])) { 281 if (LLVM_UNLIKELY(n->getExpr() == op[1 - i])) { 282 if (isa<And>(stmt)) { 279 283 return block->createZeroes(stmt->getType()); 280 284 } else { 281 cast<Variadic>(stmt)->removeOperand(i); 282 cast<Variadic>(stmt)->removeOperand(i - 1); 283 continue; 284 } 285 return block->createOnes(stmt->getType()); 286 } 287 } 288 } else if (LLVM_UNLIKELY(isa<Zeroes>(op[i]) || isa<Ones>(op[i]))) { 289 if (isa<And>(stmt) ^ isa<Zeroes>(op)) { 290 return op[1 - i]; 285 291 } else { 286 if (LLVM_LIKELY(stmt->getNumOperands() == 2)) { 287 return stmt->getOperand(1 - i); 288 } else { 289 cast<Variadic>(stmt)->removeOperand(i); 290 continue; 291 } 292 } 293 } 294 ++i; 295 } 296 if (LLVM_UNLIKELY(stmt->getNumOperands() < 2)) { 297 if (LLVM_LIKELY(stmt->getNumOperands() == 1)) { 298 return stmt->getOperand(0); 292 return op[i]; 293 } 294 } 295 } 296 if (LLVM_UNLIKELY(op[0] == op[1])) { 297 return op[0]; 298 } else { 299 if (op[1] < op[0]) { 300 stmt->setOperand(0, op[1]); 301 stmt->setOperand(1, op[0]); 302 } 303 return nullptr; 304 } 305 } else if (isa<Xor>(stmt)) { 306 PabloAST * op[2]; 307 op[0] = stmt->getOperand(0); 308 op[1] = stmt->getOperand(1); 309 bool negated = false; 310 PabloAST * expr = nullptr; 311 for (unsigned i = 0; i < 2; ++i) { 312 if (Not * const n = dyn_cast<Not>(op[i])) { 313 negated ^= true; 314 op[i] = n->getExpr(); 315 } else if (LLVM_UNLIKELY(isa<Zeroes>(op[i]) || isa<Ones>(op[i]))) { 316 negated ^= isa<Ones>(op); 317 expr = op[1 - i]; 318 } 319 } 320 if (LLVM_LIKELY(expr == nullptr)) { 321 if (LLVM_UNLIKELY(op[0] == op[1])) { 322 if (LLVM_UNLIKELY(negated)) { 323 return block->createOnes(stmt->getType()); 324 } else { 325 return block->createZeroes(stmt->getType()); 326 } 299 327 } else { 300 return block->createZeroes(stmt->getType()); 301 } 302 } 303 if (LLVM_UNLIKELY(isa<Xor>(stmt))) { 304 bool negated = false; 305 PabloAST * expr = nullptr; 306 for (unsigned i = 0; i < stmt->getNumOperands(); ) { 307 const PabloAST * const op = stmt->getOperand(i); 308 if (isa<Not>(op)) { 309 negated ^= true; 310 stmt->setOperand(i, cast<Not>(op)->getExpr()); 311 } else if (LLVM_UNLIKELY(isa<Zeroes>(op) || isa<Ones>(op))) { 312 negated ^= isa<Ones>(op); 313 if (LLVM_LIKELY(stmt->getNumOperands() == 2)) { 314 expr = stmt->getOperand(1 - i); 315 break; 316 } else { 317 cast<Variadic>(stmt)->removeOperand(i); 318 continue; 319 } 320 } 321 ++i; 322 } 323 if (LLVM_UNLIKELY(negated)) { 324 block->setInsertPoint(stmt); 325 expr = triviallyFold(block->createNot(expr ? expr : stmt), block); 326 } 327 return expr; 328 } else { // if (isa<And>(stmt) || isa<Or>(stmt)) 329 for (unsigned i = 0; i < stmt->getNumOperands(); ++i) { 330 const PabloAST * const op = stmt->getOperand(i); 331 if (LLVM_UNLIKELY(isa<Zeroes>(op) || isa<Ones>(op))) { 332 if (isa<And>(stmt) ^ isa<Zeroes>(op)) { 333 if (LLVM_LIKELY(stmt->getNumOperands() == 2)) { 334 return stmt->getOperand(1 - i); 335 } else { 336 cast<Variadic>(stmt)->removeOperand(i); 337 continue; 338 } 339 } else { 340 return stmt->getOperand(i); 341 } 342 } 343 ++i; 344 } 345 } 328 if (op[1] < op[0]) { 329 std::swap(op[0], op[1]); 330 } 331 stmt->setOperand(0, op[0]); 332 stmt->setOperand(1, op[1]); 333 } 334 } 335 if (LLVM_UNLIKELY(negated)) { 336 block->setInsertPoint(stmt); 337 expr = triviallyFold(block->createNot(expr ? expr : stmt), block); 338 } 339 return expr; 346 340 } else if (isa<Advance>(stmt)) { 347 341 Advance * const adv = cast<Advance>(stmt); -
icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp
r5828 r5834 24 24 25 25 using TypeId = PabloAST::ClassTypeId; 26 27 size_t constexpr __length(const char * const str) { 28 return *str ? 1 + __length(str + 1) : 0; 29 } 26 30 27 31 /** ------------------------------------------------------------------------------------------------------------- * … … 47 51 } else if (isa<AtEOF>(expr1)) { 48 52 return equals(cast<AtEOF>(expr1)->getOperand(0), cast<AtEOF>(expr2)->getOperand(0)); 49 } else if (isa<Variadic>(expr1)) { 50 const Variadic * const var1 = cast<Variadic>(expr1); 51 const Variadic * const var2 = cast<Variadic>(expr2); 52 if (var1->getNumOperands() == var2->getNumOperands()) { 53 const unsigned operands = var1->getNumOperands(); 54 for (unsigned i = 0; i != operands; ++i) { 55 bool missing = true; 56 for (unsigned j = 0; j != operands; ++j) { 57 // odds are both variadics will be sorted; optimize towards testing them in order. 58 unsigned k = i + j; 59 if (LLVM_UNLIKELY(k >= operands)) { 60 k -= operands; 61 } 62 if (equals(var1->getOperand(i), var2->getOperand(k))) { 63 missing = false; 64 break; 65 } 66 } 67 if (missing) { 68 return false; 69 } 70 } 71 return true; 53 } else if (isa<And>(expr1) || isa<Or>(expr1) || isa<Xor>(expr1)) { 54 PabloAST * op1[2]; 55 PabloAST * op2[2]; 56 op1[0] = cast<Statement>(expr1)->getOperand(0); 57 op1[1] = cast<Statement>(expr1)->getOperand(1); 58 if (op1[1] < op1[0]) { 59 std::swap(op1[0], op1[1]); 72 60 } 61 op2[0] = cast<Statement>(expr2)->getOperand(0); 62 op2[1] = cast<Statement>(expr2)->getOperand(1); 63 if (op2[1] < op2[0]) { 64 std::swap(op2[0], op2[1]); 65 } 66 return (op1[0] == op2[0]) && (op1[1] == op2[1]); 73 67 } else if (isa<Statement>(expr1)) { 74 68 const Statement * stmt1 = cast<Statement>(expr1); … … 305 299 306 300 /** ------------------------------------------------------------------------------------------------------------- * 301 * @brief getName 302 ** ------------------------------------------------------------------------------------------------------------- */ 303 const String & Statement::getName() const { 304 if (mName == nullptr) { 305 if (LLVM_UNLIKELY(mParent == nullptr)) { 306 llvm::report_fatal_error("cannot assign a default name to a statement that is not within a PabloBlock"); 307 } 308 const char * prefix = nullptr; 309 size_t length = 0; 310 #define MAKE_PREFIX(type_id, name) \ 311 case ClassTypeId:: type_id : prefix = name; length = __length(name); break 312 switch (mClassTypeId) { 313 // Boolean operations 314 MAKE_PREFIX(And, "and"); 315 MAKE_PREFIX(Or, "or"); 316 MAKE_PREFIX(Xor, "xor"); 317 MAKE_PREFIX(Not, "not"); 318 MAKE_PREFIX(Sel, "sel"); 319 // Stream operations 320 MAKE_PREFIX(Advance, "advance"); 321 MAKE_PREFIX(IndexedAdvance, "indexed_advance"); 322 MAKE_PREFIX(ScanThru, "scanthru"); 323 MAKE_PREFIX(AdvanceThenScanThru, "advscanthru"); 324 MAKE_PREFIX(ScanTo, "scanto"); 325 MAKE_PREFIX(AdvanceThenScanTo, "advscanto"); 326 MAKE_PREFIX(Lookahead, "lookahead"); 327 MAKE_PREFIX(MatchStar, "matchstar"); 328 MAKE_PREFIX(InFile, "inFile"); 329 MAKE_PREFIX(AtEOF, "atEOF"); 330 // Statistics operations 331 MAKE_PREFIX(Count, "count"); 332 // Misc. operations 333 MAKE_PREFIX(Repeat, "repeat"); 334 MAKE_PREFIX(PackH, "packh"); 335 MAKE_PREFIX(PackL, "packl"); 336 default: llvm_unreachable("invalid statement type"); 337 } 338 #undef MAKE_PREFIX 339 const StringRef __prefix(prefix, length); 340 mName = mParent->makeName(__prefix); 341 } 342 return *mName; 343 } 344 345 /** ------------------------------------------------------------------------------------------------------------- * 307 346 * @brief setName 308 347 ** ------------------------------------------------------------------------------------------------------------- */ 309 void Statement::setName(const String * const name) noexcept{348 void Statement::setName(const String * const name) { 310 349 if (LLVM_UNLIKELY(name == nullptr)) { 311 350 llvm::report_fatal_error("Statement name cannot be null!"); 312 351 } 313 352 mName = name; 314 }315 316 /** ------------------------------------------------------------------------------------------------------------- *317 * @brief addOperand318 ** ------------------------------------------------------------------------------------------------------------- */319 void Variadic::addOperand(PabloAST * const expr) noexcept {320 if (LLVM_UNLIKELY(mOperands == mCapacity)) {321 mCapacity = std::max<unsigned>(mCapacity * 2, 2);322 PabloAST ** expandedOperandSpace = mAllocator.allocate(mCapacity);323 for (unsigned i = 0; i != mOperands; ++i) {324 expandedOperandSpace[i] = mOperand[i];325 }326 mAllocator.deallocate(mOperand);327 mOperand = expandedOperandSpace;328 }329 mOperand[mOperands++] = expr;330 expr->addUser(this);331 }332 333 /** ------------------------------------------------------------------------------------------------------------- *334 * @brief removeOperand335 ** ------------------------------------------------------------------------------------------------------------- */336 PabloAST * Variadic::removeOperand(const unsigned index) noexcept {337 assert (index < mOperands);338 PabloAST * const expr = mOperand[index];339 assert (expr);340 --mOperands;341 for (unsigned i = index; i != mOperands; ++i) {342 mOperand[i] = mOperand[i + 1];343 }344 mOperand[mOperands] = nullptr;345 expr->removeUser(this);346 return expr;347 353 } 348 354 -
icGREP/icgrep-devel/icgrep/pablo/pabloAST.h
r5828 r5834 23 23 class PabloAST { 24 24 friend class Statement; 25 friend class Variadic;26 25 friend class StatementList; 27 26 friend class Branch; … … 45 44 } 46 45 46 // NOTE: when adding new statement types, update Statement::getName() to generate 47 // a default name for the class. 47 48 enum class ClassTypeId : unsigned { 48 49 /** Expressions and Constants **/ … … 93 94 , While 94 95 // Misc. operations 95 , Fill96 , Repeat 96 97 , PackH 97 98 , PackL … … 206 207 void replaceUsesOfWith(PabloAST * const from, PabloAST * const to); 207 208 208 const String & getName() const noexcept { 209 return *mName; 210 } 211 212 void setName(const String * const name) noexcept; 209 // NOTE: getName() can generate a default name if one is does not exist for it 210 const String & getName() const; 213 211 214 212 inline PabloAST * getOperand(const unsigned index) const noexcept { … … 238 236 return mParent; 239 237 } 238 240 239 virtual ~Statement() = default; 240 241 void setName(const String * const name); 241 242 242 243 protected: … … 259 260 } 260 261 261 explicit Statement(const ClassTypeId id, llvm::Type * const type, const unsigned reserved, const String * const name, Allocator & allocator)262 : PabloAST(id, type, allocator)263 , mOperands(0)264 , mOperand(allocator.allocate(reserved))265 , mNext(nullptr)266 , mPrev(nullptr)267 , mName(name)268 , mParent(nullptr) {269 std::memset(mOperand, 0, reserved * sizeof(PabloAST *));270 }271 272 template<typename iterator>273 explicit Statement(const ClassTypeId id, llvm::Type * const type, iterator begin, iterator end, const String * const name, Allocator & allocator)274 : PabloAST(id, type, allocator)275 , mOperands(std::distance(begin, end))276 , mOperand(allocator.allocate(mOperands))277 , mNext(nullptr)278 , mPrev(nullptr)279 , mName(name)280 , mParent(nullptr) {281 unsigned i = 0;282 for (auto value = begin; value != end; ++value, ++i) {283 assert (*value);284 mOperand[i] = *value;285 (*value)->addUser(this);286 }287 }288 289 262 protected: 290 unsigned mOperands;291 PabloAST ** mOperand;292 Statement * mNext;293 Statement * mPrev;294 const String * mName;295 PabloBlock * mParent;263 unsigned mOperands; 264 PabloAST ** mOperand; 265 Statement * mNext; 266 Statement * mPrev; 267 mutable const String * mName; 268 PabloBlock * mParent; 296 269 }; 297 270 … … 346 319 } 347 320 348 explicit CarryProducingStatement(const ClassTypeId id, llvm::Type * const type, const unsigned reserved, const String * name, Allocator & allocator)349 : Statement(id, type, reserved, name, allocator)350 , mCarryGroup(0)351 , mCarryWidth(0) {352 353 }354 355 template<typename iterator>356 explicit CarryProducingStatement(const ClassTypeId id, llvm::Type * const type, iterator begin, iterator end, const String * name, Allocator & allocator)357 : Statement(id, type, begin, end, name, allocator)358 , mCarryGroup(0)359 , mCarryWidth(0) {360 361 }362 363 321 private: 364 322 365 323 unsigned mCarryGroup; 366 324 unsigned mCarryWidth; 367 };368 369 370 class Variadic : public Statement {371 public:372 373 static inline bool classof(const PabloAST * e) {374 switch (e->getClassTypeId()) {375 case PabloAST::ClassTypeId::And:376 case PabloAST::ClassTypeId::Or:377 case PabloAST::ClassTypeId::Xor:378 return true;379 default: return false;380 }381 }382 static inline bool classof(const Variadic *) {383 return true;384 }385 static inline bool classof(const void *) {386 return false;387 }388 389 class iterator : public boost::iterator_facade<iterator, PabloAST *, boost::random_access_traversal_tag> {390 friend class Variadic;391 friend class boost::iterator_core_access;392 protected:393 394 iterator(PabloAST ** pointer) : mCurrent(pointer) { }395 inline void increment() { ++mCurrent; }396 inline void decrement() { --mCurrent; }397 inline void advance(const std::ptrdiff_t n) { mCurrent += n; }398 inline std::ptrdiff_t distance_to(const iterator & other) const { return other.mCurrent - mCurrent; }399 inline PabloAST *& dereference() const { return *mCurrent; }400 401 inline bool equal(const iterator & other) const { return (mCurrent == other.mCurrent); }402 403 private:404 PabloAST ** mCurrent;405 };406 407 using const_iterator = iterator;408 409 void addOperand(PabloAST * const expr) noexcept;410 411 PabloAST * removeOperand(const unsigned index) noexcept;412 413 bool deleteOperand(const PabloAST * const expr) noexcept;414 415 iterator begin() {416 return iterator(mOperand);417 }418 419 const_iterator begin() const {420 return iterator(mOperand);421 }422 423 iterator end() {424 return iterator(mOperand + mOperands);425 }426 427 const_iterator end() const {428 return iterator(mOperand + mOperands);429 }430 431 virtual ~Variadic() = default;432 433 protected:434 explicit Variadic(const ClassTypeId id, llvm::Type * const type, std::initializer_list<PabloAST *> operands, const String * const name, Allocator & allocator)435 : Statement(id, type, operands, name, allocator)436 , mCapacity(operands.size())437 , mAllocator(allocator) {438 439 }440 explicit Variadic(const ClassTypeId id, llvm::Type * const type, const unsigned reserved, const String * name, Allocator & allocator)441 : Statement(id, type, reserved, name, allocator)442 , mCapacity(reserved)443 , mAllocator(allocator) {444 445 }446 template<typename iterator>447 explicit Variadic(const ClassTypeId id, llvm::Type * const type, iterator begin, iterator end, const String * name, Allocator & allocator)448 : Statement(id, type, begin, end, name, allocator)449 , mCapacity(std::distance(begin, end))450 , mAllocator(allocator) {451 452 }453 private:454 unsigned mCapacity;455 Allocator & mAllocator;456 325 }; 457 326 … … 713 582 }; 714 583 715 /** ------------------------------------------------------------------------------------------------------------- *716 * @brief deleteOperand717 ** ------------------------------------------------------------------------------------------------------------- */718 inline bool Variadic::deleteOperand(const PabloAST * const expr) noexcept {719 for (unsigned i = 0; i != getNumOperands(); ++i) {720 if (LLVM_UNLIKELY(getOperand(i) == expr)) {721 removeOperand(i);722 return true;723 }724 }725 return false;726 584 } 727 585 728 }729 730 586 #endif // PE_PabloAST_H -
icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp
r5832 r5834 423 423 Value * value = nullptr; 424 424 if (isa<And>(stmt)) { 425 value = compileExpression(b, stmt->getOperand(0)); 426 for (unsigned i = 1; i < stmt->getNumOperands(); ++i) { 427 value = b->simd_and(value, compileExpression(b, stmt->getOperand(1))); 428 } 425 Value * const op0 = compileExpression(b, stmt->getOperand(0)); 426 Value * const op1 = compileExpression(b, stmt->getOperand(1)); 427 value = b->simd_and(op0, op1); 429 428 } else if (isa<Or>(stmt)) { 430 value = compileExpression(b, stmt->getOperand(0)); 431 for (unsigned i = 1; i < stmt->getNumOperands(); ++i) { 432 value = b->simd_or(value, compileExpression(b, stmt->getOperand(1))); 433 } 429 Value * const op0 = compileExpression(b, stmt->getOperand(0)); 430 Value * const op1 = compileExpression(b, stmt->getOperand(1)); 431 value = b->simd_or(op0, op1); 434 432 } else if (isa<Xor>(stmt)) { 435 value = compileExpression(b, stmt->getOperand(0)); 436 for (unsigned i = 1; i < stmt->getNumOperands(); ++i) { 437 value = b->simd_xor(value, compileExpression(b, stmt->getOperand(1))); 438 } 433 Value * const op0 = compileExpression(b, stmt->getOperand(0)); 434 Value * const op1 = compileExpression(b, stmt->getOperand(1)); 435 value = b->simd_xor(op0, op1); 439 436 } else if (const Sel * sel = dyn_cast<Sel>(stmt)) { 440 437 Value* ifMask = compileExpression(b, sel->getCondition()); -
icGREP/icgrep-devel/icgrep/pablo/pe_repeat.h
r5829 r5834 12 12 public: 13 13 static bool classof(const PabloAST * e) { 14 return e->getClassTypeId() == ClassTypeId:: Fill;14 return e->getClassTypeId() == ClassTypeId::Repeat; 15 15 } 16 16 static bool classof(const void *) { … … 27 27 protected: 28 28 Repeat(Integer * const fieldWidth, PabloAST * const value, llvm::Type * type, const String * name, Allocator & allocator) 29 : Statement(ClassTypeId:: Fill, type, { fieldWidth, value }, name, allocator) {29 : Statement(ClassTypeId::Repeat, type, { fieldWidth, value }, name, allocator) { 30 30 31 31 } -
icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp
r5828 r5834 57 57 } 58 58 } else { 59 59 60 print(cast<PabloAST>(stmt), out); 60 61
Note: See TracChangeset
for help on using the changeset viewer.