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

Last change on this file since 5751 was 5732, checked in by cameron, 2 years ago

More changes in preparation for LLVM 3.9, 4.0

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