261 changes: 136 additions & 125 deletions llvm/include/llvm/IR/DebugInfoMetadata.h

Large diffs are not rendered by default.

93 changes: 46 additions & 47 deletions llvm/lib/Bitcode/Reader/MetadataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ class PlaceholderQueue {

public:
~PlaceholderQueue() {
assert(empty() && "PlaceholderQueue hasn't been flushed before being destroyed");
assert(empty() &&
"PlaceholderQueue hasn't been flushed before being destroyed");
}
bool empty() const { return PHs.empty(); }
DistinctMDOperandPlaceholder &getPlaceholderOp(unsigned ID);
Expand Down Expand Up @@ -603,7 +604,7 @@ class MetadataLoader::MetadataLoaderImpl {
// If the expression is malformed, make sure we don't
// copy more elements than we should.
HistoricSize = std::min(SubExpr.size(), HistoricSize);
ArrayRef<uint64_t> Args = SubExpr.slice(1, HistoricSize-1);
ArrayRef<uint64_t> Args = SubExpr.slice(1, HistoricSize - 1);

switch (SubExpr.front()) {
case dwarf::DW_OP_plus:
Expand Down Expand Up @@ -1408,8 +1409,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
return error("Invalid record");

IsDistinct = Record[0];
DINode::DIFlags Flags = (Record.size() > 6) ?
static_cast<DINode::DIFlags>(Record[6]) : DINode::FlagZero;
DINode::DIFlags Flags = (Record.size() > 6)
? static_cast<DINode::DIFlags>(Record[6])
: DINode::FlagZero;

MetadataList.assignValue(
GET_OR_DISTINCT(DIBasicType,
Expand Down Expand Up @@ -1670,9 +1672,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
SPFlags |= DISubprogram::SPFlagMainSubprogram;
else if (!HasSPFlags)
SPFlags = DISubprogram::toSPFlags(
/*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8],
/*IsOptimized=*/Record[14], /*Virtuality=*/Record[11],
/*DIFlagMainSubprogram*/HasOldMainSubprogramFlag);
/*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8],
/*IsOptimized=*/Record[14], /*Virtuality=*/Record[11],
/*DIFlagMainSubprogram=*/HasOldMainSubprogramFlag);

// All definitions should be distinct.
IsDistinct = (Record[0] & 1) || (SPFlags & DISubprogram::SPFlagDefinition);
Expand Down Expand Up @@ -1709,26 +1711,26 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
DISubprogram *SP = GET_OR_DISTINCT(
DISubprogram,
(Context,
getDITypeRefOrNull(Record[1]), // scope
getMDString(Record[2]), // name
getMDString(Record[3]), // linkageName
getMDOrNull(Record[4]), // file
Record[5], // line
getMDOrNull(Record[6]), // type
Record[7 + OffsetA], // scopeLine
getDITypeRefOrNull(Record[8 + OffsetA]), // containingType
Record[10 + OffsetA], // virtualIndex
HasThisAdj ? Record[16 + OffsetB] : 0, // thisAdjustment
Flags, // flags
SPFlags, // SPFlags
HasUnit ? CUorFn : nullptr, // unit
getMDOrNull(Record[13 + OffsetB]), // templateParams
getMDOrNull(Record[14 + OffsetB]), // declaration
getMDOrNull(Record[15 + OffsetB]), // retainedNodes
getDITypeRefOrNull(Record[1]), // scope
getMDString(Record[2]), // name
getMDString(Record[3]), // linkageName
getMDOrNull(Record[4]), // file
Record[5], // line
getMDOrNull(Record[6]), // type
Record[7 + OffsetA], // scopeLine
getDITypeRefOrNull(Record[8 + OffsetA]), // containingType
Record[10 + OffsetA], // virtualIndex
HasThisAdj ? Record[16 + OffsetB] : 0, // thisAdjustment
Flags, // flags
SPFlags, // SPFlags
HasUnit ? CUorFn : nullptr, // unit
getMDOrNull(Record[13 + OffsetB]), // templateParams
getMDOrNull(Record[14 + OffsetB]), // declaration
getMDOrNull(Record[15 + OffsetB]), // retainedNodes
HasThrownTypes ? getMDOrNull(Record[17 + OffsetB])
: nullptr, // thrownTypes
: nullptr, // thrownTypes
HasAnnotations ? getMDOrNull(Record[18 + OffsetB])
: nullptr // annotations
: nullptr // annotations
));
MetadataList.assignValue(SP, NextMetadataNo);
NextMetadataNo++;
Expand Down Expand Up @@ -1875,27 +1877,26 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Annotations = getMDOrNull(Record[12]);

MetadataList.assignValue(
GET_OR_DISTINCT(
DIGlobalVariable,
(Context, getMDOrNull(Record[1]), getMDString(Record[2]),
getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
getDITypeRefOrNull(Record[6]), Record[7], Record[8],
getMDOrNull(Record[9]), getMDOrNull(Record[10]), Record[11],
Annotations)),
GET_OR_DISTINCT(DIGlobalVariable,
(Context, getMDOrNull(Record[1]),
getMDString(Record[2]), getMDString(Record[3]),
getMDOrNull(Record[4]), Record[5],
getDITypeRefOrNull(Record[6]), Record[7], Record[8],
getMDOrNull(Record[9]), getMDOrNull(Record[10]),
Record[11], Annotations)),
NextMetadataNo);

NextMetadataNo++;
} else if (Version == 1) {
// No upgrade necessary. A null field will be introduced to indicate
// that no parameter information is available.
MetadataList.assignValue(
GET_OR_DISTINCT(DIGlobalVariable,
(Context, getMDOrNull(Record[1]),
getMDString(Record[2]), getMDString(Record[3]),
getMDOrNull(Record[4]), Record[5],
getDITypeRefOrNull(Record[6]), Record[7], Record[8],
getMDOrNull(Record[10]), nullptr, Record[11],
nullptr)),
GET_OR_DISTINCT(
DIGlobalVariable,
(Context, getMDOrNull(Record[1]), getMDString(Record[2]),
getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
getDITypeRefOrNull(Record[6]), Record[7], Record[8],
getMDOrNull(Record[10]), nullptr, Record[11], nullptr)),
NextMetadataNo);

NextMetadataNo++;
Expand Down Expand Up @@ -1973,8 +1974,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
getMDString(Record[2 + HasTag]),
getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag],
getDITypeRefOrNull(Record[5 + HasTag]),
Record[6 + HasTag], Flags, AlignInBits,
Annotations)),
Record[6 + HasTag], Flags, AlignInBits, Annotations)),
NextMetadataNo);
NextMetadataNo++;
break;
Expand All @@ -1985,10 +1985,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(

IsDistinct = Record[0] & 1;
MetadataList.assignValue(
GET_OR_DISTINCT(DILabel,
(Context, getMDOrNull(Record[1]),
getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4])),
GET_OR_DISTINCT(DILabel, (Context, getMDOrNull(Record[1]),
getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4])),
NextMetadataNo);
NextMetadataNo++;
break;
Expand All @@ -2005,8 +2004,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Error Err = upgradeDIExpression(Version, Elts, Buffer))
return Err;

MetadataList.assignValue(
GET_OR_DISTINCT(DIExpression, (Context, Elts)), NextMetadataNo);
MetadataList.assignValue(GET_OR_DISTINCT(DIExpression, (Context, Elts)),
NextMetadataNo);
NextMetadataNo++;
break;
}
Expand Down
116 changes: 57 additions & 59 deletions llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static cl::opt<bool>
cl::init(false), cl::Hidden);

DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
: M(m), VMContext(M.getContext()), CUNode(CU),
DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr),
: M(m), VMContext(M.getContext()), CUNode(CU), DeclareFn(nullptr),
ValueFn(nullptr), LabelFn(nullptr),
AllowUnresolvedNodes(AllowUnresolvedNodes) {}

void DIBuilder::trackIfUnresolved(MDNode *N) {
Expand Down Expand Up @@ -309,11 +309,10 @@ DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
AlignInBits, 0, None, Flags, Base);
}

DIDerivedType *DIBuilder::createReferenceType(
unsigned Tag, DIType *RTy,
uint64_t SizeInBits,
uint32_t AlignInBits,
Optional<unsigned> DWARFAddressSpace) {
DIDerivedType *
DIBuilder::createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits,
uint32_t AlignInBits,
Optional<unsigned> DWARFAddressSpace) {
assert(RTy && "Unable to create reference type");
return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
SizeInBits, AlignInBits, 0, DWARFAddressSpace,
Expand All @@ -322,8 +321,7 @@ DIDerivedType *DIBuilder::createReferenceType(

DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
DIFile *File, unsigned LineNo,
DIScope *Context,
uint32_t AlignInBits,
DIScope *Context, uint32_t AlignInBits,
DINodeArray Annotations) {
return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
LineNo, getNonCompileUnitScope(Context), Ty, 0,
Expand All @@ -346,8 +344,8 @@ DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
Metadata *ExtraData = ConstantAsMetadata::get(
ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset));
return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
0, Ty, BaseTy, 0, 0, BaseOffset, None,
Flags, ExtraData);
0, Ty, BaseTy, 0, 0, BaseOffset, None, Flags,
ExtraData);
}

DIDerivedType *DIBuilder::createMemberType(
Expand Down Expand Up @@ -383,7 +381,7 @@ DIDerivedType *DIBuilder::createBitFieldMemberType(
Flags |= DINode::FlagBitField;
return DIDerivedType::get(
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0,
OffsetInBits, None, Flags,
ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
StorageOffsetInBits)),
Expand Down Expand Up @@ -503,10 +501,12 @@ DICompositeType *DIBuilder::createUnionType(
return R;
}

DICompositeType *DIBuilder::createVariantPart(
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) {
DICompositeType *
DIBuilder::createVariantPart(DIScope *Scope, StringRef Name, DIFile *File,
unsigned LineNumber, uint64_t SizeInBits,
uint32_t AlignInBits, DINode::DIFlags Flags,
DIDerivedType *Discriminator, DINodeArray Elements,
StringRef UniqueIdentifier) {
auto *R = DICompositeType::get(
VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
Expand Down Expand Up @@ -547,16 +547,17 @@ DIDerivedType *DIBuilder::createSetType(DIScope *Scope, StringRef Name,
return R;
}

DICompositeType *DIBuilder::createArrayType(
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
PointerUnion<DIExpression *, DIVariable *> DL,
PointerUnion<DIExpression *, DIVariable *> AS,
PointerUnion<DIExpression *, DIVariable *> AL,
PointerUnion<DIExpression *, DIVariable *> RK) {
DICompositeType *
DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty,
DINodeArray Subscripts,
PointerUnion<DIExpression *, DIVariable *> DL,
PointerUnion<DIExpression *, DIVariable *> AS,
PointerUnion<DIExpression *, DIVariable *> AL,
PointerUnion<DIExpression *, DIVariable *> RK) {
auto *R = DICompositeType::get(
VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
nullptr, Ty, Size, AlignInBits, 0, DINode::FlagZero,
Subscripts, 0, nullptr, nullptr, "", nullptr,
VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty, Size,
AlignInBits, 0, DINode::FlagZero, Subscripts, 0, nullptr, nullptr, "",
nullptr,
DL.is<DIExpression *>() ? (Metadata *)DL.get<DIExpression *>()
: (Metadata *)DL.get<DIVariable *>(),
AS.is<DIExpression *>() ? (Metadata *)AS.get<DIExpression *>()
Expand Down Expand Up @@ -639,8 +640,8 @@ DICompositeType *DIBuilder::createReplaceableCompositeType(
DICompositeType::getTemporary(
VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
Annotations)
nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr,
nullptr, Annotations)
.release();
trackIfUnresolved(RetTy);
return RetTy;
Expand Down Expand Up @@ -708,16 +709,16 @@ static void checkGlobalVariableScope(DIScope *Context) {

DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression(
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
unsigned LineNumber, DIType *Ty, bool IsLocalToUnit,
bool isDefined, DIExpression *Expr,
MDNode *Decl, MDTuple *TemplateParams, uint32_t AlignInBits,
DINodeArray Annotations) {
unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, bool isDefined,
DIExpression *Expr, MDNode *Decl, MDTuple *TemplateParams,
uint32_t AlignInBits, DINodeArray Annotations) {
checkGlobalVariableScope(Context);

auto *GV = DIGlobalVariable::getDistinct(
VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
LineNumber, Ty, IsLocalToUnit, isDefined, cast_or_null<DIDerivedType>(Decl),
TemplateParams, AlignInBits, Annotations);
LineNumber, Ty, IsLocalToUnit, isDefined,
cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
Annotations);
if (!Expr)
Expr = createExpression();
auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
Expand Down Expand Up @@ -751,10 +752,9 @@ static DILocalVariable *createLocalVariable(
// the only valid scopes)?
DIScope *Context = getNonCompileUnitScope(Scope);

auto *Node =
DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
File, LineNo, Ty, ArgNo, Flags, AlignInBits,
Annotations);
auto *Node = DILocalVariable::get(
VMContext, cast_or_null<DILocalScope>(Context), Name, File, LineNo, Ty,
ArgNo, Flags, AlignInBits, Annotations);
if (AlwaysPreserve) {
// The optimizer may remove local variables. If there is an interest
// to preserve variable info in such situation then stash it in a
Expand Down Expand Up @@ -783,17 +783,15 @@ DILocalVariable *DIBuilder::createParameterVariable(
assert(ArgNo && "Expected non-zero argument number for parameter");
return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
File, LineNo, Ty, AlwaysPreserve, Flags,
/* AlignInBits */0, Annotations);
/*AlignInBits=*/0, Annotations);
}

DILabel *DIBuilder::createLabel(
DIScope *Scope, StringRef Name, DIFile *File,
unsigned LineNo, bool AlwaysPreserve) {
DILabel *DIBuilder::createLabel(DIScope *Scope, StringRef Name, DIFile *File,
unsigned LineNo, bool AlwaysPreserve) {
DIScope *Context = getNonCompileUnitScope(Scope);

auto *Node =
DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
File, LineNo);
auto *Node = DILabel::get(VMContext, cast_or_null<DILocalScope>(Context),
Name, File, LineNo);

if (AlwaysPreserve) {
/// The optimizer may remove labels. If there is an interest
Expand All @@ -817,7 +815,7 @@ DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
}

template <class... Ts>
static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
static DISubprogram *getSubprogram(bool IsDistinct, Ts &&...Args) {
if (IsDistinct)
return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
return DISubprogram::get(std::forward<Ts>(Args)...);
Expand Down Expand Up @@ -881,11 +879,11 @@ DISubprogram *DIBuilder::createMethod(
return SP;
}

DICommonBlock *DIBuilder::createCommonBlock(
DIScope *Scope, DIGlobalVariable *Decl, StringRef Name, DIFile *File,
unsigned LineNo) {
return DICommonBlock::get(
VMContext, Scope, Decl, Name, File, LineNo);
DICommonBlock *DIBuilder::createCommonBlock(DIScope *Scope,
DIGlobalVariable *Decl,
StringRef Name, DIFile *File,
unsigned LineNo) {
return DICommonBlock::get(VMContext, Scope, Decl, Name, File, LineNo);
}

DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
Expand Down Expand Up @@ -941,9 +939,9 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,

Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
Instruction *InsertBefore) {
return insertLabel(
LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
InsertBefore);
return insertLabel(LabelInfo, DL,
InsertBefore ? InsertBefore->getParent() : nullptr,
InsertBefore);
}

Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
Expand Down Expand Up @@ -992,7 +990,8 @@ static Function *getDeclareIntrin(Module &M) {

Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
BasicBlock *InsertBB, Instruction *InsertBefore) {
BasicBlock *InsertBB,
Instruction *InsertBefore) {
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
Expand Down Expand Up @@ -1035,9 +1034,9 @@ Instruction *DIBuilder::insertDbgValueIntrinsic(
return B.CreateCall(ValueFn, Args);
}

Instruction *DIBuilder::insertLabel(
DILabel *LabelInfo, const DILocation *DL,
BasicBlock *InsertBB, Instruction *InsertBefore) {
Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
BasicBlock *InsertBB,
Instruction *InsertBefore) {
assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
Expand All @@ -1054,8 +1053,7 @@ Instruction *DIBuilder::insertLabel(
return B.CreateCall(LabelFn, Args);
}

void DIBuilder::replaceVTableHolder(DICompositeType *&T,
DIType *VTableHolder) {
void DIBuilder::replaceVTableHolder(DICompositeType *&T, DIType *VTableHolder) {
{
TypedTrackingMDRef<DICompositeType> N(T);
N->replaceVTableHolder(VTableHolder);
Expand Down
111 changes: 56 additions & 55 deletions llvm/lib/IR/DebugInfoMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
Storage, Context.pImpl->DILocations);
}

const
DILocation *DILocation::getMergedLocations(ArrayRef<const DILocation *> Locs) {
const DILocation *
DILocation::getMergedLocations(ArrayRef<const DILocation *> Locs) {
if (Locs.empty())
return nullptr;
if (Locs.size() == 1)
Expand Down Expand Up @@ -139,15 +139,17 @@ const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
return DILocation::get(Result->getContext(), 0, 0, S, L);
}

Optional<unsigned> DILocation::encodeDiscriminator(unsigned BD, unsigned DF, unsigned CI) {
Optional<unsigned> DILocation::encodeDiscriminator(unsigned BD, unsigned DF,
unsigned CI) {
std::array<unsigned, 3> Components = {BD, DF, CI};
uint64_t RemainingWork = 0U;
// We use RemainingWork to figure out if we have no remaining components to
// encode. For example: if BD != 0 but DF == 0 && CI == 0, we don't need to
// encode anything for the latter 2.
// Since any of the input components is at most 32 bits, their sum will be
// less than 34 bits, and thus RemainingWork won't overflow.
RemainingWork = std::accumulate(Components.begin(), Components.end(), RemainingWork);
RemainingWork =
std::accumulate(Components.begin(), Components.end(), RemainingWork);

int I = 0;
unsigned Ret = 0;
Expand Down Expand Up @@ -179,7 +181,6 @@ void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF,
getNextComponentInDiscriminator(getNextComponentInDiscriminator(D)));
}


DINode::DIFlags DINode::getFlag(StringRef Flag) {
return StringSwitch<DIFlags>(Flag)
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
Expand Down Expand Up @@ -546,8 +547,8 @@ DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
DEFINE_GETIMPL_LOOKUP(DIBasicType,
(Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
Metadata *Ops[] = {nullptr, nullptr, Name};
DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,
Flags), Ops);
DEFINE_GETIMPL_STORE(DIBasicType,
(Tag, SizeInBits, AlignInBits, Encoding, Flags), Ops);
}

Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
Expand Down Expand Up @@ -589,9 +590,10 @@ DIDerivedType *DIDerivedType::getImpl(
AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
ExtraData, Annotations));
Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData, Annotations};
DEFINE_GETIMPL_STORE(
DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
DWARFAddressSpace, Flags), Ops);
DEFINE_GETIMPL_STORE(DIDerivedType,
(Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
DWARFAddressSpace, Flags),
Ops);
}

DICompositeType *DICompositeType::getImpl(
Expand All @@ -616,9 +618,10 @@ DICompositeType *DICompositeType::getImpl(
Elements, VTableHolder, TemplateParams, Identifier,
Discriminator, DataLocation, Associated, Allocated,
Rank, Annotations};
DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
AlignInBits, OffsetInBits, Flags),
Ops);
DEFINE_GETIMPL_STORE(
DICompositeType,
(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, Flags),
Ops);
}

DICompositeType *DICompositeType::buildODRType(
Expand Down Expand Up @@ -798,10 +801,14 @@ DICompileUnit::getNameTableKind(StringRef Str) {

const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
switch (EK) {
case NoDebug: return "NoDebug";
case FullDebug: return "FullDebug";
case LineTablesOnly: return "LineTablesOnly";
case DebugDirectivesOnly: return "DebugDirectivesOnly";
case NoDebug:
return "NoDebug";
case FullDebug:
return "FullDebug";
case LineTablesOnly:
return "LineTablesOnly";
case DebugDirectivesOnly:
return "DebugDirectivesOnly";
}
return nullptr;
}
Expand Down Expand Up @@ -881,9 +888,9 @@ DISubprogram *DISubprogram::getImpl(
SPFlags, Unit, TemplateParams, Declaration,
RetainedNodes, ThrownTypes, Annotations));
SmallVector<Metadata *, 12> Ops = {
File, Scope, Name, LinkageName, Type, Unit,
Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes,
Annotations};
File, Scope, Name, LinkageName,
Type, Unit, Declaration, RetainedNodes,
ContainingType, TemplateParams, ThrownTypes, Annotations};
if (!Annotations) {
Ops.pop_back();
if (!ThrownTypes) {
Expand Down Expand Up @@ -995,11 +1002,10 @@ DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");
assert(isCanonical(LinkageName) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, (Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition,
StaticDataMemberDeclaration,
TemplateParams, AlignInBits,
Annotations));
DEFINE_GETIMPL_LOOKUP(
DIGlobalVariable,
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
StaticDataMemberDeclaration, TemplateParams, AlignInBits, Annotations));
Metadata *Ops[] = {Scope,
Name,
File,
Expand All @@ -1013,22 +1019,19 @@ DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
(Line, IsLocalToUnit, IsDefinition, AlignInBits), Ops);
}

DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, Metadata *File,
unsigned Line, Metadata *Type,
unsigned Arg, DIFlags Flags,
uint32_t AlignInBits,
Metadata *Annotations,
StorageType Storage,
bool ShouldCreate) {
DILocalVariable *
DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
Metadata *File, unsigned Line, Metadata *Type,
unsigned Arg, DIFlags Flags, uint32_t AlignInBits,
Metadata *Annotations, StorageType Storage,
bool ShouldCreate) {
// 64K ought to be enough for any frontend.
assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");

assert(Scope && "Expected scope");
assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(DILocalVariable,
(Scope, Name, File, Line, Type, Arg, Flags,
AlignInBits, Annotations));
DEFINE_GETIMPL_LOOKUP(DILocalVariable, (Scope, Name, File, Line, Type, Arg,
Flags, AlignInBits, Annotations));
Metadata *Ops[] = {Scope, Name, File, Type, Annotations};
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
}
Expand Down Expand Up @@ -1056,14 +1059,12 @@ Optional<uint64_t> DIVariable::getSizeInBits() const {
return None;
}

DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, Metadata *File, unsigned Line,
StorageType Storage,
DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
Metadata *File, unsigned Line, StorageType Storage,
bool ShouldCreate) {
assert(Scope && "Expected scope");
assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(DILabel,
(Scope, Name, File, Line));
DEFINE_GETIMPL_LOOKUP(DILabel, (Scope, Name, File, Line));
Metadata *Ops[] = {Scope, Name, File};
DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
}
Expand Down Expand Up @@ -1212,10 +1213,11 @@ bool DIExpression::isComplex() const {
// kind of complex computation occurs.
for (const auto &It : expr_ops()) {
switch (It.getOp()) {
case dwarf::DW_OP_LLVM_tag_offset:
case dwarf::DW_OP_LLVM_fragment:
continue;
default: return true;
case dwarf::DW_OP_LLVM_tag_offset:
case dwarf::DW_OP_LLVM_fragment:
continue;
default:
return true;
}
}

Expand Down Expand Up @@ -1364,8 +1366,7 @@ DIExpression *DIExpression::replaceArg(const DIExpression *Expr,

DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
SmallVectorImpl<uint64_t> &Ops,
bool StackValue,
bool EntryValue) {
bool StackValue, bool EntryValue) {
assert(Expr && "Can't prepend ops to this expression");

if (EntryValue) {
Expand Down Expand Up @@ -1460,7 +1461,8 @@ Optional<DIExpression *> DIExpression::createFragmentExpression(
if (Expr) {
for (auto Op : Expr->expr_ops()) {
switch (Op.getOp()) {
default: break;
default:
break;
case dwarf::DW_OP_shr:
case dwarf::DW_OP_shra:
case dwarf::DW_OP_shl:
Expand Down Expand Up @@ -1619,22 +1621,21 @@ DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
}

DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
unsigned Line, MDString *Name, MDString *Value,
StorageType Storage, bool ShouldCreate) {
DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
MDString *Name, MDString *Value, StorageType Storage,
bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
Metadata *Ops[] = { Name, Value };
Metadata *Ops[] = {Name, Value};
DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
}

DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
unsigned Line, Metadata *File,
Metadata *Elements, StorageType Storage,
bool ShouldCreate) {
DEFINE_GETIMPL_LOOKUP(DIMacroFile,
(MIType, Line, File, Elements));
Metadata *Ops[] = { File, Elements };
DEFINE_GETIMPL_LOOKUP(DIMacroFile, (MIType, Line, File, Elements));
Metadata *Ops[] = {File, Elements};
DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
}

Expand Down
121 changes: 56 additions & 65 deletions llvm/lib/IR/LLVMContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ using DenseMapAPIntKeyInfo = DenseMapInfo<APInt>;

struct DenseMapAPFloatKeyInfo {
static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
static inline APFloat getTombstoneKey() {
return APFloat(APFloat::Bogus(), 2);
}

static unsigned getHashValue(const APFloat &Key) {
return static_cast<unsigned>(hash_value(Key));
Expand All @@ -74,46 +76,42 @@ struct DenseMapAPFloatKeyInfo {

struct AnonStructTypeKeyInfo {
struct KeyTy {
ArrayRef<Type*> ETypes;
ArrayRef<Type *> ETypes;
bool isPacked;

KeyTy(const ArrayRef<Type*>& E, bool P) :
ETypes(E), isPacked(P) {}
KeyTy(const ArrayRef<Type *> &E, bool P) : ETypes(E), isPacked(P) {}

KeyTy(const StructType *ST)
: ETypes(ST->elements()), isPacked(ST->isPacked()) {}

bool operator==(const KeyTy& that) const {
bool operator==(const KeyTy &that) const {
if (isPacked != that.isPacked)
return false;
if (ETypes != that.ETypes)
return false;
return true;
}
bool operator!=(const KeyTy& that) const {
return !this->operator==(that);
}
bool operator!=(const KeyTy &that) const { return !this->operator==(that); }
};

static inline StructType* getEmptyKey() {
return DenseMapInfo<StructType*>::getEmptyKey();
static inline StructType *getEmptyKey() {
return DenseMapInfo<StructType *>::getEmptyKey();
}

static inline StructType* getTombstoneKey() {
return DenseMapInfo<StructType*>::getTombstoneKey();
static inline StructType *getTombstoneKey() {
return DenseMapInfo<StructType *>::getTombstoneKey();
}

static unsigned getHashValue(const KeyTy& Key) {
return hash_combine(hash_combine_range(Key.ETypes.begin(),
Key.ETypes.end()),
Key.isPacked);
static unsigned getHashValue(const KeyTy &Key) {
return hash_combine(
hash_combine_range(Key.ETypes.begin(), Key.ETypes.end()), Key.isPacked);
}

static unsigned getHashValue(const StructType *ST) {
return getHashValue(KeyTy(ST));
}

static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
static bool isEqual(const KeyTy &LHS, const StructType *RHS) {
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
return false;
return LHS == KeyTy(RHS);
Expand All @@ -127,16 +125,16 @@ struct AnonStructTypeKeyInfo {
struct FunctionTypeKeyInfo {
struct KeyTy {
const Type *ReturnType;
ArrayRef<Type*> Params;
ArrayRef<Type *> Params;
bool isVarArg;

KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
ReturnType(R), Params(P), isVarArg(V) {}
KeyTy(const Type *R, const ArrayRef<Type *> &P, bool V)
: ReturnType(R), Params(P), isVarArg(V) {}
KeyTy(const FunctionType *FT)
: ReturnType(FT->getReturnType()), Params(FT->params()),
isVarArg(FT->isVarArg()) {}

bool operator==(const KeyTy& that) const {
bool operator==(const KeyTy &that) const {
if (ReturnType != that.ReturnType)
return false;
if (isVarArg != that.isVarArg)
Expand All @@ -145,31 +143,28 @@ struct FunctionTypeKeyInfo {
return false;
return true;
}
bool operator!=(const KeyTy& that) const {
return !this->operator==(that);
}
bool operator!=(const KeyTy &that) const { return !this->operator==(that); }
};

static inline FunctionType* getEmptyKey() {
return DenseMapInfo<FunctionType*>::getEmptyKey();
static inline FunctionType *getEmptyKey() {
return DenseMapInfo<FunctionType *>::getEmptyKey();
}

static inline FunctionType* getTombstoneKey() {
return DenseMapInfo<FunctionType*>::getTombstoneKey();
static inline FunctionType *getTombstoneKey() {
return DenseMapInfo<FunctionType *>::getTombstoneKey();
}

static unsigned getHashValue(const KeyTy& Key) {
return hash_combine(Key.ReturnType,
hash_combine_range(Key.Params.begin(),
Key.Params.end()),
Key.isVarArg);
static unsigned getHashValue(const KeyTy &Key) {
return hash_combine(
Key.ReturnType,
hash_combine_range(Key.Params.begin(), Key.Params.end()), Key.isVarArg);
}

static unsigned getHashValue(const FunctionType *FT) {
return getHashValue(KeyTy(FT));
}

static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
static bool isEqual(const KeyTy &LHS, const FunctionType *RHS) {
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
return false;
return LHS == KeyTy(RHS);
Expand Down Expand Up @@ -412,14 +407,14 @@ template <> struct MDNodeKeyImpl<DIBasicType> {
Encoding(Encoding), Flags(Flags) {}
MDNodeKeyImpl(const DIBasicType *N)
: Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {}
AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()),
Flags(N->getFlags()) {}

bool isKeyOf(const DIBasicType *RHS) const {
return Tag == RHS->getTag() && Name == RHS->getRawName() &&
SizeInBits == RHS->getSizeInBits() &&
AlignInBits == RHS->getAlignInBits() &&
Encoding == RHS->getEncoding() &&
Flags == RHS->getFlags();
Encoding == RHS->getEncoding() && Flags == RHS->getFlags();
}

unsigned getHashValue() const {
Expand Down Expand Up @@ -526,7 +521,8 @@ template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
}

static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
static bool isSubsetEqual(const DIDerivedType *LHS,
const DIDerivedType *RHS) {
return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
RHS);
}
Expand Down Expand Up @@ -667,14 +663,13 @@ template <> struct MDNodeKeyImpl<DIFile> {
bool isKeyOf(const DIFile *RHS) const {
return Filename == RHS->getRawFilename() &&
Directory == RHS->getRawDirectory() &&
Checksum == RHS->getRawChecksum() &&
Source == RHS->getRawSource();
Checksum == RHS->getRawChecksum() && Source == RHS->getRawSource();
}

unsigned getHashValue() const {
return hash_combine(
Filename, Directory, Checksum ? Checksum->Kind : 0,
Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr));
return hash_combine(Filename, Directory, Checksum ? Checksum->Kind : 0,
Checksum ? Checksum->Value : nullptr,
Source.getValueOr(nullptr));
}
};

Expand Down Expand Up @@ -723,8 +718,8 @@ template <> struct MDNodeKeyImpl<DISubprogram> {
TemplateParams(N->getRawTemplateParams()),
Declaration(N->getRawDeclaration()),
RetainedNodes(N->getRawRetainedNodes()),
ThrownTypes(N->getRawThrownTypes()), Annotations(N->getRawAnnotations())
{}
ThrownTypes(N->getRawThrownTypes()),
Annotations(N->getRawAnnotations()) {}

bool isKeyOf(const DISubprogram *RHS) const {
return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Expand Down Expand Up @@ -861,9 +856,7 @@ template <> struct MDNodeKeyImpl<DINamespace> {
ExportSymbols == RHS->getExportSymbols();
}

unsigned getHashValue() const {
return hash_combine(Scope, Name);
}
unsigned getHashValue() const { return hash_combine(Scope, Name); }
};

template <> struct MDNodeKeyImpl<DICommonBlock> {
Expand All @@ -873,17 +866,17 @@ template <> struct MDNodeKeyImpl<DICommonBlock> {
Metadata *File;
unsigned LineNo;

MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name,
Metadata *File, unsigned LineNo)
MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name, Metadata *File,
unsigned LineNo)
: Scope(Scope), Decl(Decl), Name(Name), File(File), LineNo(LineNo) {}
MDNodeKeyImpl(const DICommonBlock *N)
: Scope(N->getRawScope()), Decl(N->getRawDecl()), Name(N->getRawName()),
File(N->getRawFile()), LineNo(N->getLineNo()) {}

bool isKeyOf(const DICommonBlock *RHS) const {
return Scope == RHS->getRawScope() && Decl == RHS->getRawDecl() &&
Name == RHS->getRawName() && File == RHS->getRawFile() &&
LineNo == RHS->getLineNo();
Name == RHS->getRawName() && File == RHS->getRawFile() &&
LineNo == RHS->getLineNo();
}

unsigned getHashValue() const {
Expand Down Expand Up @@ -1093,9 +1086,7 @@ template <> struct MDNodeKeyImpl<DILabel> {
}

/// Using name and line to get hash value. It should already be mostly unique.
unsigned getHashValue() const {
return hash_combine(Scope, Name, Line);
}
unsigned getHashValue() const { return hash_combine(Scope, Name, Line); }
};

template <> struct MDNodeKeyImpl<DIExpression> {
Expand Down Expand Up @@ -1342,7 +1333,7 @@ class LLVMContextImpl {
public:
/// OwnedModules - The set of modules instantiated in this context, and which
/// will be automatically deleted if this context is deleted.
SmallPtrSet<Module*, 4> OwnedModules;
SmallPtrSet<Module *, 4> OwnedModules;

/// The main remark streamer used by all the other streamers (e.g. IR, MIR,
/// frontends, etc.). This should only be used by the specific streamers, and
Expand Down Expand Up @@ -1394,7 +1385,7 @@ class LLVMContextImpl {
DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;

DenseMap<const Value*, ValueName*> ValueNames;
DenseMap<const Value *, ValueName *> ValueNames;

#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
DenseSet<CLASS *, CLASS##Info> CLASS##s;
Expand Down Expand Up @@ -1429,7 +1420,7 @@ class LLVMContextImpl {
StringMap<std::unique_ptr<ConstantDataSequential>> CDSConstants;

DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
BlockAddresses;
BlockAddresses;

DenseMap<const GlobalValue *, DSOLocalEquivalent *> DSOLocalEquivalents;

Expand All @@ -1451,19 +1442,19 @@ class LLVMContextImpl {
BumpPtrAllocator Alloc;
UniqueStringSaver Saver{Alloc};

DenseMap<unsigned, IntegerType*> IntegerTypes;
DenseMap<unsigned, IntegerType *> IntegerTypes;

using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
FunctionTypeSet FunctionTypes;
using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
StructTypeSet AnonStructTypes;
StringMap<StructType*> NamedStructTypes;
StringMap<StructType *> NamedStructTypes;
unsigned NamedStructTypesUniqueID = 0;

DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
DenseMap<std::pair<Type *, uint64_t>, ArrayType *> ArrayTypes;
DenseMap<std::pair<Type *, ElementCount>, VectorType *> VectorTypes;
DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
DenseMap<Type *, PointerType *> PointerTypes; // Pointers in AddrSpace = 0
DenseMap<std::pair<Type *, unsigned>, PointerType *> ASPointerTypes;

/// ValueHandles - This map keeps track of all of the value handles that are
/// watching a Value*. The Value::HasValueHandle bit is used to know
Expand Down Expand Up @@ -1517,7 +1508,7 @@ class LLVMContextImpl {
/// This saves allocating an additional word in Function for programs which
/// do not use GC (i.e., most programs) at the cost of increased overhead for
/// clients which do use GC.
DenseMap<const Function*, std::string> GCNames;
DenseMap<const Function *, std::string> GCNames;

/// Flag to indicate if Value (other than GlobalValue) retains their name or
/// not.
Expand All @@ -1540,7 +1531,7 @@ class LLVMContextImpl {
///
/// The lifetime of the object must be guaranteed to extend as long as the
/// LLVMContext is used by compilation.
void setOptPassGate(OptPassGate&);
void setOptPassGate(OptPassGate &);

// TODO: clean up the following after we no longer support non-opaque pointer
// types.
Expand Down