Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/IR/Metadata.cpp
Show First 20 Lines • Show All 1,507 Lines • ▼ Show 20 Lines | void GlobalObject::addTypeMetadata(unsigned Offset, Metadata *TypeID) { | ||||
addMetadata( | addMetadata( | ||||
LLVMContext::MD_type, | LLVMContext::MD_type, | ||||
*MDTuple::get(getContext(), | *MDTuple::get(getContext(), | ||||
{ConstantAsMetadata::get(ConstantInt::get( | {ConstantAsMetadata::get(ConstantInt::get( | ||||
Type::getInt64Ty(getContext()), Offset)), | Type::getInt64Ty(getContext()), Offset)), | ||||
TypeID})); | TypeID})); | ||||
} | } | ||||
void GlobalObject::setVCallVisibilityMetadata(VCallVisibility Visibility) { | void GlobalObject::setVCallVisibility(VCallVisibilityList Visibility) { | ||||
// Remove any existing vcall visibility metadata first in case we are | // Remove any existing vcall visibility metadata first in case we are | ||||
// updating. | // updating. | ||||
eraseMetadata(LLVMContext::MD_vcall_visibility); | eraseMetadata(LLVMContext::MD_vcall_visibility); | ||||
addMetadata(LLVMContext::MD_vcall_visibility, | for (auto Entry : Visibility) { | ||||
addMetadata( | |||||
LLVMContext::MD_vcall_visibility, | |||||
*MDNode::get(getContext(), | *MDNode::get(getContext(), | ||||
{ConstantAsMetadata::get(ConstantInt::get( | { | ||||
Type::getInt64Ty(getContext()), Visibility))})); | ConstantAsMetadata::get(ConstantInt::get( | ||||
Type::getInt64Ty(getContext()), Entry.Visibility)), | |||||
ConstantAsMetadata::get(ConstantInt::get( | |||||
Type::getInt64Ty(getContext()), Entry.RangeStart)), | |||||
ConstantAsMetadata::get(ConstantInt::get( | |||||
Type::getInt64Ty(getContext()), Entry.RangeEnd)), | |||||
})); | |||||
} | |||||
} | } | ||||
GlobalObject::VCallVisibility GlobalObject::getVCallVisibility() const { | GlobalObject::VCallVisibilityList GlobalObject::getVCallVisibility() const { | ||||
if (MDNode *MD = getMetadata(LLVMContext::MD_vcall_visibility)) { | VCallVisibilityList Result; | ||||
SmallVector<MDNode *, 2> MDs; | |||||
getMetadata(LLVMContext::MD_vcall_visibility, MDs); | |||||
for (MDNode *MD : MDs) { | |||||
uint64_t Val = cast<ConstantInt>( | uint64_t Val = cast<ConstantInt>( | ||||
cast<ConstantAsMetadata>(MD->getOperand(0))->getValue()) | cast<ConstantAsMetadata>(MD->getOperand(0))->getValue()) | ||||
->getZExtValue(); | ->getZExtValue(); | ||||
assert(Val <= 2 && "unknown vcall visibility!"); | assert(Val <= 2 && "unknown vcall visibility!"); | ||||
return (VCallVisibility)Val; | |||||
} | |||||
return VCallVisibility::VCallVisibilityPublic; | |||||
} | |||||
std::pair<uint64_t, uint64_t> GlobalObject::getVTableOffsetRange() const { | uint64_t RangeStart = 0; | ||||
if (MDNode *MD = getMetadata(LLVMContext::MD_vcall_visibility)) { | uint64_t RangeEnd = std::numeric_limits<uint64_t>::max(); | ||||
if (MD->getNumOperands() >= 3) { | if (MD->getNumOperands() >= 3) { | ||||
uint64_t RangeStart = | RangeStart = cast<ConstantInt>( | ||||
cast<ConstantInt>( | |||||
cast<ConstantAsMetadata>(MD->getOperand(1))->getValue()) | cast<ConstantAsMetadata>(MD->getOperand(1))->getValue()) | ||||
->getZExtValue(); | ->getZExtValue(); | ||||
uint64_t RangeEnd = | RangeEnd = cast<ConstantInt>( | ||||
cast<ConstantInt>( | |||||
cast<ConstantAsMetadata>(MD->getOperand(2))->getValue()) | cast<ConstantAsMetadata>(MD->getOperand(2))->getValue()) | ||||
->getZExtValue(); | ->getZExtValue(); | ||||
return std::make_pair(RangeStart, RangeEnd); | |||||
} | } | ||||
Result.push_back({VCallVisibility(Val), RangeStart, RangeEnd}); | |||||
} | |||||
if (Result.empty()) { | |||||
Result.push_back({VCallVisibility::VCallVisibilityPublic, 0, | |||||
std::numeric_limits<uint64_t>::max()}); | |||||
} | } | ||||
return std::make_pair(0, std::numeric_limits<uint64_t>::max()); | |||||
return Result; | |||||
} | } | ||||
void Function::setSubprogram(DISubprogram *SP) { | void Function::setSubprogram(DISubprogram *SP) { | ||||
setMetadata(LLVMContext::MD_dbg, SP); | setMetadata(LLVMContext::MD_dbg, SP); | ||||
} | } | ||||
DISubprogram *Function::getSubprogram() const { | DISubprogram *Function::getSubprogram() const { | ||||
return cast_or_null<DISubprogram>(getMetadata(LLVMContext::MD_dbg)); | return cast_or_null<DISubprogram>(getMetadata(LLVMContext::MD_dbg)); | ||||
Show All 22 Lines |