24 const char SpirVer[] =
"opencl.spir.version";
25 const char OCLVer[] =
"opencl.ocl.version";
26 const char UsedExt[] =
"opencl.used.extensions";
27 const char UsedOptCoreFeat[] =
"opencl.used.optional.core.features";
28 const char CompilerOptions[] =
"opencl.compiler.options";
29 const char LLVMIdent[] =
"llvm.ident";
43 virtual bool runOnModule(
Module &M);
59 if (!NamedMD || NamedMD->getNumOperands() <= 1)
63 for (
const auto &VersionMD : NamedMD->operands()) {
64 assert(VersionMD->getNumOperands() == 2);
65 auto CMajor = mdconst::extract<ConstantInt>(VersionMD->getOperand(0));
66 auto VersionMajor = CMajor->getZExtValue();
67 auto CMinor = mdconst::extract<ConstantInt>(VersionMD->getOperand(1));
68 auto VersionMinor = CMinor->getZExtValue();
69 auto Ver = (VersionMajor * 100) + (VersionMinor * 10);
77 NamedMD->eraseFromParent();
92 if (!NamedMD || NamedMD->getNumOperands() == 1)
96 for (
const auto &MD : NamedMD->operands())
97 for (
const auto &
Op : MD->operands())
101 NamedMD->eraseFromParent();
103 for (
const auto &MD : All)
117 "Unify multiple OpenCL metadata due to linking",
121 return new AMDGPUUnifyMetadata();
124 bool AMDGPUUnifyMetadata::runOnModule(
Module &M) {
125 const char* Vers[] = {
129 const char* Exts[] = {
131 kOCLMD::UsedOptCoreFeat,
132 kOCLMD::CompilerOptions,
136 bool Changed =
false;
139 Changed |= unifyVersionMD(M,
I,
true);
142 Changed |= unifyExtensionMD(M,
I);
147 bool AMDGPUUnifyMetadata::runOnFunction(
Function &
F) {
void push_back(const T &Elt)
A Module instance is used to store all the information related to an LLVM module. ...
void addOperand(MDNode *M)
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
char & AMDGPUUnifyMetadataID
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
FunctionPass * createAMDGPUUnifyMetadataPass()
FunctionPass class - This class is used to implement most global optimizations.
auto find(R &&Range, const T &Val) -> decltype(std::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.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
StringRef - Represent a constant reference to a string, i.e.
LLVMContext & getContext() const
Get the global data context.