Commit e8f6a51d authored by Adéla Štěpková's avatar Adéla Štěpková
Browse files

move options to a separate class, cancel debug mode

parent c7f256e1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -57,6 +57,6 @@ public:
    void globalDCE();
    void fixIrreducible();
    void preprocessForCustomOpt();
    void finalPostprocessing(bool debugMode);
    void finalPostprocessing();
};
} // namespace llvm
 No newline at end of file
+4 −16
Original line number Diff line number Diff line
@@ -2,31 +2,19 @@

#include "passes.hpp"
#include "reversedModule.hpp"
#include "options.hpp"
#include <memory>

using namespace llvm;

class ModuleReverser {
    Module* origModule;
    bool debugMode;
    bool customSimplify;
    bool standardizeFunc;
    bool LLVMOpt;
    bool silentMode;
    bool svComp;
    bool status;
    Options& options;

public:
    ModuleReverser(Module* orig_module, bool debugMode, bool customSimplify, bool standardizeFunc,
                   bool LLVMOpt, bool silentMode, bool svComp, bool status)
    ModuleReverser(Module* orig_module, Options& options)
        : origModule{orig_module},
          debugMode{debugMode},
          customSimplify{customSimplify},
          standardizeFunc{standardizeFunc},
          LLVMOpt{LLVMOpt},
          silentMode{silentMode},
          svComp{svComp},
          status{status}
        options{options}
    {
    }

include/options.hpp

0 → 100644
+48 −0
Original line number Diff line number Diff line
#pragma once

struct Options {
    bool customSimplify = true;
    bool standardizeFunc = true;
    bool LLVMOptimize = true;
    bool silentMode = true;
    bool svComp = false;
    bool printStatus = true;

    Options(bool customSimpl, bool stdFunc, bool LLVMOpt, bool silent, bool svC,
            bool status)
        : customSimplify(customSimpl),
          standardizeFunc(stdFunc),
          LLVMOptimize(LLVMOpt),
          silentMode(silent),
          svComp(svC),
          printStatus(status)
    {
        if (svComp) {
            setSVComp();
        }

        // override if specified
        if (!customSimpl) {
            customSimplify = false;
        }
        if (!stdFunc) {
            standardizeFunc = false;
        }
        if (!LLVMOpt) {
            LLVMOptimize = false;
        }
        if (!silent) {
            silent = false;
        }
    }

private:
    void setSVComp()
    {
        silentMode = true;
        customSimplify = true;
        standardizeFunc = true;
        LLVMOptimize = true;
        printStatus = true;
    }
};
 No newline at end of file
+7 −21
Original line number Diff line number Diff line
#include "moduleReverser.hpp"
#include "options.hpp"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
@@ -12,12 +13,7 @@ using namespace llvm;

cl::OptionCategory ReverserCategory("Reverser Options");

enum ReturnValue {
    OK,
    CANNOT_REVERSE,
    CANNOT_OPEN_INPUT,
    CANNOT_OPEN_OUTPUT
};
enum ReturnValue { OK, CANNOT_REVERSE, CANNOT_OPEN_INPUT, CANNOT_OPEN_OUTPUT };

int main(int argc, char** argv)
{
@@ -53,11 +49,7 @@ int main(int argc, char** argv)
                            cl::desc("do not run LLVM optimizations in postprocessing"),
                            cl::init(false), cl::cat(ReverserCategory));

    cl::opt<bool> debugMode("debug",
                            cl::desc("debug mode: do not run postprocessing optimizations"),
                            cl::init(false), cl::cat(ReverserCategory));

    cl::opt<bool> silentMode("silent", cl::desc("silent mode: do not output to stdout"),
    cl::opt<bool> print("print", cl::desc("print result to stdout"),
                             cl::init(false), cl::cat(ReverserCategory));

    cl::opt<bool> status("status", cl::desc("show the current status during computation"),
@@ -75,17 +67,10 @@ int main(int argc, char** argv)
        return ReturnValue::CANNOT_OPEN_INPUT;
    }

    if (svComp) {
        silentMode = true;
        noCustomSimplify = false;
        noStdFunc = false;
        noLLVMOpt = false;
        debugMode = false;
    }
    Options options(!noCustomSimplify, !noStdFunc, !noLLVMOpt, !print, svComp, status);

    // Reverse
    auto reverser = ModuleReverser(module.get(), debugMode, !noCustomSimplify, !noStdFunc,!noLLVMOpt,
                                   silentMode, svComp, status);
    auto reverser = ModuleReverser(module.get(), options);
    auto rev_module = reverser.run();

    if (!rev_module) {
@@ -93,7 +78,8 @@ int main(int argc, char** argv)
        return ReturnValue::CANNOT_REVERSE;
    }

    if (!silentMode) {
    if (print) {
        // errs() << "------------------ OUTPUT FILE -----------------\n";
        outs() << *rev_module << "\n";
    }

+9 −12
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ void PassDriver::fixIrreducible()
    MPM.run(module, MAM);
}

void PassDriver::finalPostprocessing(bool debugMode)
void PassDriver::finalPostprocessing()
{
    PreservedAnalyses PA;
    MAM.invalidate(module, PA);
@@ -55,8 +55,6 @@ void PassDriver::finalPostprocessing(bool debugMode)
    auto preserveMain = [](const GlobalValue& GV) -> bool { return GV.getName() == "main"; };

    FPM.addPass(DCEPass());

    if (!debugMode) {
    // MPM.addPass(AttributorPass());
    MPM.addPass(GlobalDCEPass());
    FPM.addPass(SimplifyCFGPass());
@@ -65,7 +63,6 @@ void PassDriver::finalPostprocessing(bool debugMode)
    FPM.addPass(PromotePass());
    FPM.addPass(GVNPass());
    FPM.addPass(DSEPass());
    }

    MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
    MPM.run(module, MAM);
Loading