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

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

Add -VerifyPablo? option

File size: 3.8 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
46                                         clEnumVal(EnableSchedulingPrePass, "Pablo Statement Scheduling Pre-Pass"),
47                                         clEnumValEnd), cl::cat(PabloOptions));
48
49bool DebugOptionIsSet(PabloDebugFlags flag) {return DebugOptions.isSet(flag);}
50   
51
52void pablo_function_passes(PabloKernel * kernel) {
53
54    if (DebugOptions.isSet(ShowPablo)) {
55        //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
56        errs() << "Initial Pablo AST:\n";
57        PabloPrinter::print(kernel, errs());
58    }
59
60#ifdef NDEBUG
61    if (DebugOptions.isSet(VerifyPablo)) {
62#endif
63        PabloVerifier::verify(kernel, "creation");
64#ifdef NDEBUG
65    }
66#endif
67
68    // Scan through the pablo code and perform DCE and CSE
69    if (LLVM_LIKELY(!PabloOptimizationsOptions.isSet(DisableSimplification))) {
70        Simplifier::optimize(kernel);
71    }
72    if (Flatten){
73        FlattenIf::transform(kernel);
74    }
75    if (LLVM_LIKELY(!PabloOptimizationsOptions.isSet(DisableCodeMotion))) {
76        CodeMotionPass::optimize(kernel);
77    }
78    if (PabloOptimizationsOptions.isSet(EnableDistribution)) {
79        DistributivePass::optimize(kernel);
80    }
81    if (PabloOptimizationsOptions.isSet(EnableSchedulingPrePass)) {
82        SchedulingPrePass::optimize(kernel);
83    }
84    if (DebugOptions.isSet(ShowOptimizedPablo)) {
85        if (PabloOutputFilename.empty()) {
86            //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
87            errs() << "Final Pablo AST:\n";
88            PabloPrinter::print(kernel, errs());
89        } else {
90            std::error_code error;
91            llvm::raw_fd_ostream out(PabloOutputFilename, error, sys::fs::OpenFlags::F_None);
92            PabloPrinter::print(kernel, out);
93        }
94    }
95}
96
97}
Note: See TracBrowser for help on using the repository browser.