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

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

Back up check-in. Should have no effect on current programs.

File size: 3.7 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(DumpTrace, "Generate dynamic traces of executed Pablo assignments."),
35                        clEnumValEnd), cl::cat(PabloOptions));
36   
37static cl::opt<std::string> PabloOutputFilename("print-pablo-output", cl::init(""), cl::desc("output Pablo filename"), cl::cat(PabloOptions));
38static cl::opt<bool> Flatten("flatten-if", cl::init(false), cl::desc("Flatten all the Ifs in the Pablo AST"), cl::cat(PabloOptions));
39
40static cl::bits<PabloCompilationFlags> 
41    PabloOptimizationsOptions(cl::values(clEnumVal(DisableSimplification, "Disable Pablo Simplification pass (not recommended)"),
42                                         clEnumVal(DisableCodeMotion, "Moves statements into the innermost legal If-scope and moves invariants out of While-loops."),
43                                         clEnumVal(EnableDistribution, "Apply distribution law optimization."),
44
45                                         clEnumVal(EnableSchedulingPrePass, "Pablo Statement Scheduling Pre-Pass"),
46                                         clEnumValEnd), cl::cat(PabloOptions));
47
48bool DebugOptionIsSet(PabloDebugFlags flag) {return DebugOptions.isSet(flag);}
49   
50
51void pablo_function_passes(PabloKernel * kernel) {
52
53    if (DebugOptions.isSet(ShowPablo)) {
54        //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
55        errs() << "Initial Pablo AST:\n";
56        PabloPrinter::print(kernel, errs());
57    }
58
59    #ifndef NDEBUG
60    PabloVerifier::verify(kernel, "creation");
61    #endif
62
63    // Scan through the pablo code and perform DCE and CSE
64    if (LLVM_LIKELY(!PabloOptimizationsOptions.isSet(DisableSimplification))) {
65        Simplifier::optimize(kernel);
66    }
67    if (Flatten){
68        FlattenIf::transform(kernel);
69    }
70    if (LLVM_LIKELY(!PabloOptimizationsOptions.isSet(DisableCodeMotion))) {
71        CodeMotionPass::optimize(kernel);
72    }
73    if (PabloOptimizationsOptions.isSet(EnableDistribution)) {
74        DistributivePass::optimize(kernel);
75    }
76    if (PabloOptimizationsOptions.isSet(EnableSchedulingPrePass)) {
77        SchedulingPrePass::optimize(kernel);
78    }
79    if (DebugOptions.isSet(ShowOptimizedPablo)) {
80        if (PabloOutputFilename.empty()) {
81            //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
82            errs() << "Final Pablo AST:\n";
83            PabloPrinter::print(kernel, errs());
84        } else {
85            std::error_code error;
86            llvm::raw_fd_ostream out(PabloOutputFilename, error, sys::fs::OpenFlags::F_None);
87            PabloPrinter::print(kernel, out);
88        }
89    }
90}
91
92}
Note: See TracBrowser for help on using the repository browser.