source: icGREP/icgrep-devel/icgrep/pablo/pablo_toolchain.cpp @ 5620

Last change on this file since 5620 was 5620, checked in by nmedfort, 22 months ago

Bug fixes for multigrep mode. Optional PabloKernel? branch hit counter added. Minor optimizations.

File size: 4.1 KB
Line 
1/*
2 *  Copyright (c) 2015 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "pablo_toolchain.h"
8#include <pablo/pablo_kernel.h>
9#include <pablo/optimizers/pablo_simplifier.hpp>
10#include <pablo/optimizers/codemotionpass.h>
11#include <pablo/optimizers/distributivepass.h>
12#include <pablo/optimizers/schedulingprepass.h>
13#include <pablo/passes/flattenif.hpp>
14#include <pablo/analysis/pabloverifier.hpp>
15#include <pablo/printer_pablos.h>
16#include <llvm/Support/CommandLine.h>
17#include <llvm/Support/FileSystem.h>
18#include <llvm/Support/raw_ostream.h>
19
20using namespace llvm;
21
22namespace pablo {
23
24static cl::OptionCategory PabloOptions("Pablo Options", "These options control printing, generation and instrumentation of Pablo intermediate code.");
25
26const cl::OptionCategory * pablo_toolchain_flags() {
27    return &PabloOptions;
28}
29   
30   
31static cl::bits<PabloDebugFlags> 
32DebugOptions(cl::values(clEnumVal(ShowPablo, "Print generated Pablo code"),
33                        clEnumVal(ShowOptimizedPablo, "Print optimizeed Pablo code"),
34                        clEnumVal(VerifyPablo, "Run the Pablo verifier"),
35                        clEnumVal(DumpTrace, "Generate dynamic traces of executed Pablo assignments."),                       
36                        clEnumValEnd), cl::cat(PabloOptions));
37   
38static cl::opt<std::string> PabloOutputFilename("print-pablo-output", cl::init(""), cl::desc("output Pablo filename"), cl::cat(PabloOptions));
39static cl::opt<bool> Flatten("flatten-if", cl::init(false), cl::desc("Flatten all the Ifs in the Pablo AST"), cl::cat(PabloOptions));
40
41static cl::bits<PabloCompilationFlags> 
42    PabloOptimizationsOptions(cl::values(clEnumVal(DisableSimplification, "Disable Pablo Simplification pass (not recommended)"),
43                                         clEnumVal(DisableCodeMotion, "Moves statements into the innermost legal If-scope and moves invariants out of While-loops."),
44                                         clEnumVal(EnableDistribution, "Apply distribution law optimization."),                                         
45                                         clEnumVal(EnableSchedulingPrePass, "Pablo Statement Scheduling Pre-Pass"),
46                                         clEnumVal(EnableProfiling, "Profile branch statistics."),
47                                         clEnumValEnd), cl::cat(PabloOptions));
48
49bool DebugOptionIsSet(const PabloDebugFlags flag) {return DebugOptions.isSet(flag);}
50   
51bool CompileOptionIsSet(const PabloCompilationFlags flag) {return PabloOptimizationsOptions.isSet(flag);}
52
53void pablo_function_passes(PabloKernel * kernel) {
54
55    if (DebugOptions.isSet(ShowPablo)) {
56        //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
57        errs() << "Initial Pablo AST:\n";
58        PabloPrinter::print(kernel, errs());
59    }
60
61#ifdef NDEBUG
62    if (DebugOptions.isSet(VerifyPablo)) {
63#endif
64        PabloVerifier::verify(kernel, "creation");
65#ifdef NDEBUG
66    }
67#endif
68
69    // Scan through the pablo code and perform DCE and CSE
70    if (Flatten){
71        FlattenIf::transform(kernel);
72    }
73    if (LLVM_LIKELY(!PabloOptimizationsOptions.isSet(DisableSimplification))) {
74        Simplifier::optimize(kernel);
75    }
76    if (PabloOptimizationsOptions.isSet(EnableDistribution)) {
77        DistributivePass::optimize(kernel);
78    }
79    if (LLVM_LIKELY(!PabloOptimizationsOptions.isSet(DisableCodeMotion))) {
80        CodeMotionPass::optimize(kernel);
81    }
82    if (PabloOptimizationsOptions.isSet(EnableSchedulingPrePass)) {
83        SchedulingPrePass::optimize(kernel);
84    }
85    if (DebugOptions.isSet(ShowOptimizedPablo)) {
86        if (PabloOutputFilename.empty()) {
87            //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
88            errs() << "Final Pablo AST:\n";
89            PabloPrinter::print(kernel, errs());
90        } else {
91            std::error_code error;
92            llvm::raw_fd_ostream out(PabloOutputFilename, error, sys::fs::OpenFlags::F_None);
93            PabloPrinter::print(kernel, out);
94        }
95    }
96}
97
98}
Note: See TracBrowser for help on using the repository browser.