File: main.cpp

package info (click to toggle)
intel-graphics-compiler2 2.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 106,644 kB
  • sloc: cpp: 805,640; lisp: 287,672; ansic: 16,414; python: 3,952; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 35
file content (86 lines) | stat: -rw-r--r-- 3,101 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*========================== begin_copyright_notice ============================

Copyright (C) 2024 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#include "common/LLVMWarningsPush.hpp"
#include <llvm/Pass.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/IRPrintingPasses.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Function.h>
#include <llvm/IRReader/IRReader.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/ManagedStatic.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Bitcode/BitcodeReader.h>
#include <llvm/Bitcode/BitcodeWriterPass.h>
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/CommandLine.h>
#include <llvmWrapper/IR/Instructions.h>
#include <llvmWrapper/IR/Module.h>
#include <llvmWrapper/ADT/STLExtras.h>
#include "common/LLVMWarningsPop.hpp"
#include "BiFManagerTool.hpp"

#include <string>
#include <list>
#include <fstream>

using namespace std;
using namespace llvm;

static cl::opt<std::string> InputBCFilename(cl::Positional, cl::desc("<input .bc file>"), cl::init("-"));
static cl::opt<std::string> InputBC32Filename(cl::Positional, cl::desc("<input .bc file>"), cl::init("-"));
static cl::opt<std::string> InputBC64Filename(cl::Positional, cl::desc("<input .bc file>"), cl::init("-"));
static cl::opt<std::string> OutputPath(cl::Positional, cl::desc("<output .bifbc file>"), cl::init("-"));
static cl::opt<std::string> OutputPathH(cl::Positional, cl::desc("<output .h file>"), cl::init("-"));

int main(int argc, char *argv[]) {
  LLVMContext Context;
#if LLVM_VERSION_MAJOR >= 16
  bool enableOpaquePointers = __IGC_OPAQUE_POINTERS_API_ENABLED;

  if (enableOpaquePointers) {
    printf("[BiFManager] - Enabling Opaque Pointers\n");
  } else {
    printf("[BiFManager] - Disabling Opaque Pointers\n");
  }

  Context.setOpaquePointers(enableOpaquePointers);
#endif

  cl::ParseCommandLineOptions(argc, argv);

  auto LoadModule = [&](std::string *PathToModule) {
    SMDiagnostic Err;
    ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = MemoryBuffer::getFileOrSTDIN(*PathToModule);
    std::unique_ptr<llvm::MemoryBuffer> genericBufferPtr(FileOrErr.get().release());
    Expected<std::unique_ptr<Module>> M = llvm::parseBitcodeFile(genericBufferPtr->getMemBufferRef(), Context);
    if (llvm::Error EC = M.takeError()) {
      Err.print("Unable to Parse bitcode", errs());
    }
    return M;
  };
  printf("[BiFManager] - Start loading modules\n");

  auto ModuleMain = LoadModule(&InputBCFilename);
  printf("[BiFManager] - Loaded Main module\n");
  auto Module32 = LoadModule(&InputBC32Filename);
  printf("[BiFManager] - Loaded Size32 module\n");
  auto Module64 = LoadModule(&InputBC64Filename);
  printf("[BiFManager] - Loaded Size64 module\n");

  IGC::BiFManager::BiFManagerTool bif(Context);
  bif.MakeBiFPackage(&(*ModuleMain.get()), &(*Module32.get()), &(*Module64.get()));

  bif.WriteHeader(OutputPathH.c_str());
  bif.WriteBitcode(OutputPath.c_str());

  return 0;
}