CuPBoP/compilation/HostTranslation.cpp

47 lines
1.1 KiB
C++
Raw Normal View History

2022-05-04 20:59:38 +08:00
#include "RemoveCudaBuiltin.h"
#include "ReplaceConstantMemory.h"
#include "ReplaceCudaBuiltin.h"
#include "ReplaceKernelArgs.h"
2022-06-26 02:44:50 +08:00
#include "RemoveMetadata.h"
#include "tool.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include <assert.h>
2022-05-04 20:59:38 +08:00
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace llvm;
2022-05-04 20:59:38 +08:00
std::string PATH = "kernel_meta.log";
int main(int argc, char **argv) {
assert(argc == 3 && "incorrect number of arguments\n");
char *input_host_path = argv[1];
char *output_host_path = argv[2];
2022-05-04 20:59:38 +08:00
std::ifstream fin;
fin.open(PATH);
// load LLVM module(s)
llvm::Module *hostModule = LoadModuleFromFilr(input_host_path);
VerifyModule(hostModule);
2022-06-26 02:44:50 +08:00
// remove metadata
RemoveMetadata(hostModule);
2022-05-04 20:59:38 +08:00
// replace const memory
ReplaceConstantMemory(hostModule, fin);
// process host module
2022-05-04 20:59:38 +08:00
ReplaceCudaBuiltin(hostModule);
// remove builtin unuse functions and variables
RemoveCudaBuiltin(hostModule);
// replace arguments in kernel_arg, from alloc to malloc
ReplaceKernelArg(hostModule);
VerifyModule(hostModule);
DumpModule(hostModule, output_host_path);
2022-05-04 20:59:38 +08:00
fin.close();
return 0;
}