LCOV - code coverage report
Current view: top level - src - llvm-remove-ni.cpp (source / functions) Hit Total Coverage
Test: [test only] commit 0f242327d2cc9bd130497f44b6350c924185606a Lines: 17 25 68.0 %
Date: 2022-07-16 23:42:53 Functions: 4 6 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 8 62.5 %

           Branch data     Line data    Source code
       1                 :            : // This file is a part of Julia. License is MIT: https://julialang.org/license
       2                 :            : 
       3                 :            : #include "llvm-version.h"
       4                 :            : #include "passes.h"
       5                 :            : 
       6                 :            : #include <llvm/Pass.h>
       7                 :            : #include <llvm/IR/Module.h>
       8                 :            : #include <llvm/IR/PassManager.h>
       9                 :            : #include <llvm/IR/LegacyPassManager.h>
      10                 :            : #include <llvm/Support/Debug.h>
      11                 :            : 
      12                 :            : #include "julia.h"
      13                 :            : 
      14                 :            : #define DEBUG_TYPE "remove_ni"
      15                 :            : 
      16                 :            : using namespace llvm;
      17                 :            : 
      18                 :            : namespace {
      19                 :            : 
      20                 :     334472 : static bool removeNI(Module &M)
      21                 :            : {
      22                 :     668944 :     auto dlstr = M.getDataLayoutStr();
      23                 :     334472 :     auto nistart = dlstr.find("-ni:");
      24         [ +  + ]:     334472 :     if (nistart == std::string::npos)
      25                 :          1 :         return false;
      26                 :     334471 :     auto len = dlstr.size();
      27                 :     334471 :     auto niend = nistart + 1;
      28         [ +  + ]:    5017060 :     for (; niend < len; niend++) {
      29         [ -  + ]:    4682590 :         if (dlstr[niend] == '-') {
      30                 :          0 :             break;
      31                 :            :         }
      32                 :            :     }
      33                 :     334471 :     dlstr.erase(nistart, niend - nistart);
      34                 :     334471 :     M.setDataLayout(dlstr);
      35                 :     334471 :     return true;
      36                 :            : }
      37                 :            : }
      38                 :            : 
      39                 :          0 : PreservedAnalyses RemoveNI::run(Module &M, ModuleAnalysisManager &AM)
      40                 :            : {
      41         [ #  # ]:          0 :     if (removeNI(M)) {
      42                 :          0 :         return PreservedAnalyses::allInSet<CFGAnalyses>();
      43                 :            :     }
      44                 :          0 :     return PreservedAnalyses::all();
      45                 :            : }
      46                 :            : 
      47                 :            : namespace {
      48                 :            : struct RemoveNILegacy : public ModulePass {
      49                 :            :     static char ID;
      50                 :       1052 :     RemoveNILegacy() : ModulePass(ID) {};
      51                 :            : 
      52                 :     334472 :     bool runOnModule(Module &M)
      53                 :            :     {
      54                 :     334472 :         return removeNI(M);
      55                 :            :     }
      56                 :            : };
      57                 :            : 
      58                 :            : char RemoveNILegacy::ID = 0;
      59                 :            : static RegisterPass<RemoveNILegacy>
      60                 :            :         Y("RemoveNI",
      61                 :            :           "Remove non-integral address space.",
      62                 :            :           false,
      63                 :            :           false);
      64                 :            : }
      65                 :            : 
      66                 :       1052 : Pass *createRemoveNIPass()
      67                 :            : {
      68                 :       1052 :     return new RemoveNILegacy();
      69                 :            : }
      70                 :            : 
      71                 :          0 : extern "C" JL_DLLEXPORT void LLVMExtraAddRemoveNIPass_impl(LLVMPassManagerRef PM)
      72                 :            : {
      73                 :          0 :     unwrap(PM)->add(createRemoveNIPass());
      74                 :          0 : }

Generated by: LCOV version 1.14