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