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"
|
2022-01-12 00:01:42 +08:00
|
|
|
#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>
|
2022-01-12 00:01:42 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2022-05-04 20:59:38 +08:00
|
|
|
std::string PATH = "kernel_meta.log";
|
|
|
|
|
2022-01-12 00:01:42 +08:00
|
|
|
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);
|
|
|
|
|
2022-01-12 00:01:42 +08:00
|
|
|
// 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);
|
2022-01-12 00:01:42 +08:00
|
|
|
// 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);
|
|
|
|
|
2022-01-12 00:01:42 +08:00
|
|
|
VerifyModule(hostModule);
|
|
|
|
DumpModule(hostModule, output_host_path);
|
2022-05-04 20:59:38 +08:00
|
|
|
|
|
|
|
fin.close();
|
2022-01-12 00:01:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|