26 const char SpirVer[] =
"opencl.spir.version";
27 const char OCLVer[] =
"opencl.ocl.version";
28 const char UsedExt[] =
"opencl.used.extensions";
29 const char UsedOptCoreFeat[] =
"opencl.used.optional.core.features";
30 const char CompilerOptions[] =
"opencl.compiler.options";
31 const char LLVMIdent[] =
"llvm.ident";
36 class AMDGPUUnifyMetadata :
public ModulePass {
56 auto *NamedMD =
M.getNamedMetadata(
Name);
57 if (!NamedMD || NamedMD->getNumOperands() <= 1)
61 for (
auto *VersionMD : NamedMD->operands()) {
62 assert(VersionMD->getNumOperands() == 2);
63 auto *CMajor = mdconst::extract<ConstantInt>(VersionMD->getOperand(0));
65 auto *CMinor = mdconst::extract<ConstantInt>(VersionMD->getOperand(1));
75 NamedMD->eraseFromParent();
76 NamedMD =
M.getOrInsertNamedMetadata(
Name);
77 NamedMD->addOperand(MaxMD);
89 auto *NamedMD =
M.getNamedMetadata(
Name);
90 if (!NamedMD || NamedMD->getNumOperands() == 1)
94 for (
auto *MD : NamedMD->operands())
95 for (
const auto &
Op : MD->operands())
97 All.push_back(
Op.get());
99 NamedMD->eraseFromParent();
100 NamedMD =
M.getOrInsertNamedMetadata(
Name);
101 for (
const auto &MD :
All)
107 bool unifyMetadataImpl(
Module &M) {
108 const char *Vers[] = {kOCLMD::SpirVer, kOCLMD::OCLVer};
109 const char *Exts[] = {kOCLMD::UsedExt, kOCLMD::UsedOptCoreFeat,
110 kOCLMD::CompilerOptions, kOCLMD::LLVMIdent};
112 bool Changed =
false;
115 Changed |= unifyVersionMD(M,
I,
true);
118 Changed |= unifyExtensionMD(M,
I);
125 char AMDGPUUnifyMetadata::ID = 0;
130 "Unify multiple OpenCL metadata due to linking",
false,
false)
133 return new AMDGPUUnifyMetadata();
136 bool AMDGPUUnifyMetadata::runOnModule(
Module &M) {
137 return unifyMetadataImpl(M);
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A container for analyses that lazily runs them and caches their results.
This class represents an Operation in the Expression.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr uint32_t VersionMinor
HSA metadata minor version.
constexpr uint32_t VersionMajor
HSA metadata major version.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
ModulePass * createAMDGPUUnifyMetadataPass()
char & AMDGPUUnifyMetadataID
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.