31 const char SpirVer[] =
"opencl.spir.version";
32 const char OCLVer[] =
"opencl.ocl.version";
33 const char UsedExt[] =
"opencl.used.extensions";
34 const char UsedOptCoreFeat[] =
"opencl.used.optional.core.features";
35 const char CompilerOptions[] =
"opencl.compiler.options";
36 const char LLVMIdent[] =
"llvm.ident";
41 class AMDGPUUnifyMetadata :
public ModulePass {
45 explicit AMDGPUUnifyMetadata() :
ModulePass(ID) {}
48 bool runOnModule(
Module &M)
override;
61 if (!NamedMD || NamedMD->getNumOperands() <= 1)
65 for (
const auto &VersionMD : NamedMD->operands()) {
66 assert(VersionMD->getNumOperands() == 2);
67 auto CMajor = mdconst::extract<ConstantInt>(VersionMD->getOperand(0));
69 auto CMinor = mdconst::extract<ConstantInt>(VersionMD->getOperand(1));
71 auto Ver = (VersionMajor * 100) + (VersionMinor * 10);
79 NamedMD->eraseFromParent();
94 if (!NamedMD || NamedMD->getNumOperands() == 1)
98 for (
const auto &MD : NamedMD->operands())
99 for (
const auto &
Op : MD->operands())
103 NamedMD->eraseFromParent();
105 for (
const auto &MD : All)
119 "Unify multiple OpenCL metadata due to linking",
123 return new AMDGPUUnifyMetadata();
126 bool AMDGPUUnifyMetadata::runOnModule(
Module &M) {
127 const char* Vers[] = {
131 const char* Exts[] = {
133 kOCLMD::UsedOptCoreFeat,
134 kOCLMD::CompilerOptions,
138 bool Changed =
false;
141 Changed |= unifyVersionMD(M,
I,
true);
144 Changed |= unifyExtensionMD(M,
I);
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
void addOperand(MDNode *M)
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
LLVMContext & getContext() const
Get the global data context.
char & AMDGPUUnifyMetadataID
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
constexpr uint32_t VersionMinor
HSA metadata minor version.
ModulePass * createAMDGPUUnifyMetadataPass()
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
constexpr uint32_t VersionMajor
HSA metadata major version.