Changeset 5270


Ignore:
Timestamp:
Jan 21, 2017, 12:10:08 PM (10 months ago)
Author:
nmedfort
Message:

Bug fix for Mac OS compilation. Partial bug fix for CodeMotionPass?

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
8 edited

Legend:

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

    r5267 r5270  
    2323#include <pablo/ps_assign.h>
    2424#include <pablo/pablo_kernel.h>
     25#include <llvm/Support/raw_os_ostream.h>
    2526
    2627#define CHECK_SAME_TYPE(A, B) \
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/codemotionpass.cpp

    r5267 r5270  
    99#endif
    1010#include <boost/container/flat_set.hpp>
     11#include <vector>
     12
     13#include <pablo/printer_pablos.h>
     14#include <llvm/Support/raw_ostream.h>
    1115
    1216using namespace boost;
     
    2024 ** ------------------------------------------------------------------------------------------------------------- */
    2125bool CodeMotionPass::optimize(PabloKernel * kernel) {
     26//    errs() << "------------------------------------------------------------------------------\n";
     27//    errs() << "BEFORE:\n";
     28//    errs() << "------------------------------------------------------------------------------\n";
     29//    PabloPrinter::print(kernel, errs());
    2230    CodeMotionPass::movement(kernel->getEntryBlock());
    2331    #ifndef NDEBUG
     
    4755 * @brief depthTo
    4856 ** ------------------------------------------------------------------------------------------------------------- */
    49 inline static unsigned depthTo(const PabloBlock * scope, const PabloBlock * const root) {
    50     unsigned depth = 0;
     57inline static int depthTo(const PabloBlock * scope, const PabloBlock * const root) {
     58    int depth = 0;
     59    assert (scope && root);
    5160    while (scope != root) {
     61        assert (scope);
    5262        ++depth;
    53         assert (scope);
    5463        scope = scope->getPredecessor();
    5564    }
     
    5867
    5968/** ------------------------------------------------------------------------------------------------------------- *
     69 * @brief ScopeSet
     70 ** ------------------------------------------------------------------------------------------------------------- */
     71struct ScopeSet : public std::vector<PabloBlock *> {
     72    inline bool insert(PabloBlock * block) {
     73        const auto i = std::lower_bound(begin(), end(), block);
     74        if (i == end() || *i != block) {
     75            std::vector<PabloBlock *>::insert(i, block);
     76            return true;
     77        }
     78        return false;
     79    }
     80    inline bool count(PabloBlock * block) {
     81        const auto i = std::lower_bound(begin(), end(), block);
     82        return (i != end() && *i == block);
     83    }
     84};
     85
     86/** ------------------------------------------------------------------------------------------------------------- *
    6087 * @brief findScopeUsages
    6188 ** ------------------------------------------------------------------------------------------------------------- */
    62 template <class ScopeSet>
    63 inline bool findScopeUsages(PabloAST * expr, ScopeSet & scopeSet, const PabloBlock * const block, const PabloBlock * const blocker) {
     89inline bool findScopeUsages(PabloAST * expr, ScopeSet & scopeSet, const PabloBlock * const block, const PabloBlock * const blocker = nullptr) {
    6490    for (PabloAST * use : expr->users()) {
    6591        assert (isa<Statement>(use));
    6692        PabloBlock * const parent = cast<Statement>(use)->getParent();
     93        assert (parent);
    6794        if (LLVM_LIKELY(parent == block)) {
    6895            return false;
     
    78105 * @brief isAcceptableTarget
    79106 ** ------------------------------------------------------------------------------------------------------------- */
    80 inline bool CodeMotionPass::isAcceptableTarget(Statement * stmt, ScopeSet & scopeSet, const PabloBlock * const block) {
     107inline bool isAcceptableTarget(Statement * stmt, ScopeSet & scopeSet, const PabloBlock * const block) {
    81108    // Scan through this statement's users to see if they're all in a nested scope. If so,
    82109    // find the least common ancestor of the scope blocks. If it is not the current scope,
     
    84111    assert (scopeSet.empty());
    85112    if (isa<Branch>(stmt)) {
    86         for (Var * def : cast<Branch>(stmt)->getEscaped()) {
     113        const auto vars = cast<Branch>(stmt)->getEscaped();
     114        if (LLVM_UNLIKELY(vars.empty())) {
     115            return false;
     116        }
     117        for (Var * def : vars) {
    87118            if (!findScopeUsages(def, scopeSet, block, cast<Branch>(stmt)->getBody())) {
    88119                return false;
     
    93124        return false;
    94125    }
    95     return findScopeUsages(stmt, scopeSet, block, nullptr);
     126    return findScopeUsages(stmt, scopeSet, block);
    96127}
    97128
     
    105136        Statement * prevNode = stmt->getPrevNode();
    106137        if (isAcceptableTarget(stmt, scopes, block)) {
    107             assert (scopes.size() > 0);
    108138            while (scopes.size() > 1) {
     139
    109140                // Find the LCA of both scopes then add the LCA back to the list of scopes.
    110141                PabloBlock * scope1 = scopes.back(); scopes.pop_back();
    111                 unsigned depth1 = depthTo(scope1, block);
     142                int depth1 = depthTo(scope1, block);
    112143
    113144                PabloBlock * scope2 = scopes.back(); scopes.pop_back();
    114                 unsigned depth2 = depthTo(scope2, block);
     145                int depth2 = depthTo(scope2, block);
    115146
    116147                // If one of these scopes is nested deeper than the other, scan upwards through
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/codemotionpass.h

    r5267 r5270  
    11#ifndef PABLO_CODESINKING_HPP
    22#define PABLO_CODESINKING_HPP
    3 
    4 #include <vector>
    53
    64namespace pablo {
     
    1311
    1412class CodeMotionPass {
    15     struct ScopeSet : public std::vector<PabloBlock *> {
    16         inline bool insert(PabloBlock * block) {
    17             const auto i = std::lower_bound(begin(), end(), block);
    18             if (i == end() || *i != block) {
    19                 std::vector<PabloBlock *>::insert(i, block);
    20                 return true;
    21             }
    22             return false;
    23         }
    24         inline bool count(PabloBlock * block) {
    25             const auto i = std::lower_bound(begin(), end(), block);
    26             return (i != end() && *i == block);
    27         }
    28     };
    2913public:
    3014    static bool optimize(PabloKernel * kernel);
    3115protected:
    3216    static void movement(PabloBlock * const block);
    33     static bool isAcceptableTarget(Statement *stmt, ScopeSet & scopeSet, const PabloBlock * const block);
    3417    static void sink(PabloBlock * const block);
    3518    static void hoistLoopInvariants(While * loop);
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r5267 r5270  
    66
    77#include "pabloAST.h"
    8 #include <pablo/codegenstate.h>          // for PabloBlock
     8#include <pablo/codegenstate.h>
    99#include <pablo/pe_var.h>
    1010#include <pablo/boolean.h>
     
    1414#include <pablo/ps_assign.h>
    1515#include <pablo/branch.h>
    16 #include <pablo/printer_pablos.h>        // for PabloPrinter
     16#include <pablo/printer_pablos.h>
     17#include <llvm/Support/raw_os_ostream.h>
    1718
    1819using namespace boost::container;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5267 r5270  
    2727#include <IR_Gen/idisa_builder.h>
    2828#include <llvm/IR/Module.h>
     29#include <llvm/Support/raw_os_ostream.h>
    2930
    3031using namespace llvm;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5267 r5270  
    1313#include <llvm/IR/Verifier.h>
    1414#include <IR_Gen/idisa_builder.h>
     15#include <llvm/Support/raw_os_ostream.h>
    1516
    1617using namespace pablo;
  • icGREP/icgrep-devel/icgrep/pablo/pe_string.h

    r5267 r5270  
    44#include <pablo/pabloAST.h>
    55#include <llvm/ADT/StringRef.h>
    6 #include <llvm/Support/raw_os_ostream.h>
    76
    87namespace pablo {
     
    109class String : public PabloAST {
    1110    friend class SymbolGenerator;
    12     friend std::ostream & operator<< (std::ostream& stream, const String & string);
    1311public:
    1412    using StringAllocator = SlabAllocator<char>;
     
    4947};
    5048
    51 inline std::ostream & operator <<(std::ostream & stream, const String & string) {
    52     stream << string.value().data();
    53     return stream;
    54 }
    55 
    56 inline std::ostream & operator <<(std::ostream & stream, const String * string) {
    57     stream << string->value().data();
    58     return stream;
    59 }
    60 
    61 inline llvm::raw_ostream & operator <<(llvm::raw_ostream & stream, const String & string) {
    62     stream << string.value().data();
    63     return stream;
    64 }
    65 
    66 inline llvm::raw_ostream & operator <<(llvm::raw_ostream & stream, const String * string) {
    67     stream << string->value().data();
    68     return stream;
    69 }
    70 
    71 
    7249}
    7350
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r5267 r5270  
    144144        out << "1";
    145145    } else if (const Var * var = dyn_cast<Var>(expr)) {
    146         out << var->getName();
     146        out << var->getName()->value();
    147147    } else if (const If * ifstmt = dyn_cast<If>(expr)) {
    148148        out << "If ";
     
    188188        print(op->getRH(), out);
    189189    } else if (const Statement * stmt = dyn_cast<Statement>(expr)) {
    190         out << stmt->getName();
     190        out << stmt->getName()->value();
    191191    } else if (isa<Integer>(expr)) {
    192192        out << cast<Integer>(expr)->value();
Note: See TracChangeset for help on using the changeset viewer.