From fc1ed8d224d44dc40a9d30b7dbb27e4a7ec22120 Mon Sep 17 00:00:00 2001 From: Ruobing Han Date: Sat, 25 Jun 2022 14:44:50 -0400 Subject: [PATCH] remove optnone metadata --- compilation/HostTranslation.cpp | 3 +++ .../include/x86/RemoveMetadata.h | 9 +++++++ .../src/x86/RemoveMetadata.cpp | 26 +++++++++++++++++++ .../KernelTranslation/src/x86/init.cpp | 4 +++ 4 files changed, 42 insertions(+) create mode 100644 compilation/HostTranslation/include/x86/RemoveMetadata.h create mode 100644 compilation/HostTranslation/src/x86/RemoveMetadata.cpp diff --git a/compilation/HostTranslation.cpp b/compilation/HostTranslation.cpp index 7d25df1..4354e50 100644 --- a/compilation/HostTranslation.cpp +++ b/compilation/HostTranslation.cpp @@ -2,6 +2,7 @@ #include "ReplaceConstantMemory.h" #include "ReplaceCudaBuiltin.h" #include "ReplaceKernelArgs.h" +#include "RemoveMetadata.h" #include "tool.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" @@ -26,6 +27,8 @@ int main(int argc, char **argv) { // load LLVM module(s) llvm::Module *hostModule = LoadModuleFromFilr(input_host_path); VerifyModule(hostModule); + // remove metadata + RemoveMetadata(hostModule); // replace const memory ReplaceConstantMemory(hostModule, fin); // process host module diff --git a/compilation/HostTranslation/include/x86/RemoveMetadata.h b/compilation/HostTranslation/include/x86/RemoveMetadata.h new file mode 100644 index 0000000..e69f108 --- /dev/null +++ b/compilation/HostTranslation/include/x86/RemoveMetadata.h @@ -0,0 +1,9 @@ +#ifndef __NVVM2x86_REMOVE_METADATA__ +#define __NVVM2x86_REMOVE_METADATA__ + +#include "llvm/IR/Module.h" + +// remove metadata, e.g., optnone +void RemoveMetadata(llvm::Module *M); + +#endif diff --git a/compilation/HostTranslation/src/x86/RemoveMetadata.cpp b/compilation/HostTranslation/src/x86/RemoveMetadata.cpp new file mode 100644 index 0000000..93d748f --- /dev/null +++ b/compilation/HostTranslation/src/x86/RemoveMetadata.cpp @@ -0,0 +1,26 @@ +#include "RemoveMetadata.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/ToolOutputFile.h" +#include + +using namespace llvm; + +void RemoveMetadata(llvm::Module *M) { + SmallVector, 4> MDs; + for (Module::iterator i = M->begin(), e = M->end(); i != e; ++i) { + Function *F = &(*i); + F->getAllMetadata(MDs); + for (auto &MD : MDs) { + F->setMetadata(MD.first, NULL); + } + F->removeFnAttr(llvm::Attribute::NoInline); + F->removeFnAttr("min-legal-vector-width"); + F->removeFnAttr("no-trapping-math"); + F->removeFnAttr(llvm::Attribute::OptimizeNone); + } +} \ No newline at end of file diff --git a/compilation/KernelTranslation/src/x86/init.cpp b/compilation/KernelTranslation/src/x86/init.cpp index 541994a..988e0a5 100644 --- a/compilation/KernelTranslation/src/x86/init.cpp +++ b/compilation/KernelTranslation/src/x86/init.cpp @@ -173,6 +173,10 @@ void remove_metadata(llvm::Module *M) { } F->removeFnAttr("target-features"); F->removeFnAttr("target-cpu"); + F->removeFnAttr(llvm::Attribute::NoInline); + F->removeFnAttr("min-legal-vector-width"); + F->removeFnAttr("no-trapping-math"); + F->removeFnAttr(llvm::Attribute::OptimizeNone); } }