remove optnone metadata

This commit is contained in:
Ruobing Han 2022-06-25 14:44:50 -04:00
parent 57367c8348
commit fc1ed8d224
4 changed files with 42 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <iostream>
using namespace llvm;
void RemoveMetadata(llvm::Module *M) {
SmallVector<std::pair<unsigned, MDNode *>, 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);
}
}

View File

@ -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);
}
}