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

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

Restructuring work for the Driver classes. Start of work to eliminate the memory leaks with the ExecutionEngine?. Replaced custom AlignedMalloc? with backend call to std::aligned_malloc. Salvaged some work on DistributionPass? for reevaluation.

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