mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-02 16:56:50 +00:00
DebugInfo: Make MDSubprogram::getFunction() return Constant
Change `MDSubprogram::getFunction()` and `MDGlobalVariable::getConstant()` to return a `Constant`. Previously, both returned `ConstantAsMetadata`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234699 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3ec16b419f
commit
e2e641234f
@ -522,7 +522,7 @@ public:
|
||||
/// \brief Check if this provides debugging information for the function F.
|
||||
bool describes(const Function *F);
|
||||
|
||||
Function *getFunction() const;
|
||||
Function *getFunction() const { return get()->getFunction(); }
|
||||
|
||||
void replaceFunction(Function *F) {
|
||||
if (auto *N = get())
|
||||
@ -689,12 +689,7 @@ public:
|
||||
DITypeRef getType() const { return get()->getType(); }
|
||||
|
||||
GlobalVariable *getGlobal() const;
|
||||
Constant *getConstant() const {
|
||||
if (auto *N = get())
|
||||
if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getVariable()))
|
||||
return C->getValue();
|
||||
return nullptr;
|
||||
}
|
||||
Constant *getConstant() const { return get()->getVariable(); }
|
||||
DIDerivedType getStaticDataMemberDeclaration() const {
|
||||
return DIDerivedType(get()->getStaticDataMemberDeclaration());
|
||||
}
|
||||
|
@ -1232,13 +1232,14 @@ class MDSubprogram : public MDLocalScope {
|
||||
MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
|
||||
unsigned ScopeLine, MDTypeRef ContainingType, unsigned Virtuality,
|
||||
unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
|
||||
ConstantAsMetadata *Function, MDTemplateParameterArray TemplateParams,
|
||||
Constant *Function, MDTemplateParameterArray TemplateParams,
|
||||
MDSubprogram *Declaration, MDLocalVariableArray Variables,
|
||||
StorageType Storage, bool ShouldCreate = true) {
|
||||
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
|
||||
getCanonicalMDString(Context, LinkageName), File, Line, Type,
|
||||
IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
|
||||
Virtuality, VirtualIndex, Flags, IsOptimized, Function,
|
||||
Virtuality, VirtualIndex, Flags, IsOptimized,
|
||||
Function ? ConstantAsMetadata::get(Function) : nullptr,
|
||||
TemplateParams.get(), Declaration, Variables.get(), Storage,
|
||||
ShouldCreate);
|
||||
}
|
||||
@ -1256,8 +1257,8 @@ class MDSubprogram : public MDLocalScope {
|
||||
getFile(), getLine(), getType(), isLocalToUnit(),
|
||||
isDefinition(), getScopeLine(), getContainingType(),
|
||||
getVirtuality(), getVirtualIndex(), getFlags(),
|
||||
isOptimized(), getFunction(), getTemplateParams(),
|
||||
getDeclaration(), getVariables());
|
||||
isOptimized(), getFunctionConstant(),
|
||||
getTemplateParams(), getDeclaration(), getVariables());
|
||||
}
|
||||
|
||||
public:
|
||||
@ -1267,7 +1268,7 @@ public:
|
||||
bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
|
||||
MDTypeRef ContainingType, unsigned Virtuality,
|
||||
unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
|
||||
ConstantAsMetadata *Function = nullptr,
|
||||
Constant *Function = nullptr,
|
||||
MDTemplateParameterArray TemplateParams = nullptr,
|
||||
MDSubprogram *Declaration = nullptr,
|
||||
MDLocalVariableArray Variables = nullptr),
|
||||
@ -1344,8 +1345,10 @@ public:
|
||||
return MDTypeRef(getRawContainingType());
|
||||
}
|
||||
|
||||
ConstantAsMetadata *getFunction() const {
|
||||
return cast_or_null<ConstantAsMetadata>(getRawFunction());
|
||||
Constant *getFunctionConstant() const {
|
||||
if (auto *C = cast_or_null<ConstantAsMetadata>(getRawFunction()))
|
||||
return C->getValue();
|
||||
return nullptr;
|
||||
}
|
||||
MDTemplateParameterArray getTemplateParams() const {
|
||||
return cast_or_null<MDTuple>(getRawTemplateParams());
|
||||
@ -1365,6 +1368,13 @@ public:
|
||||
Metadata *getRawDeclaration() const { return getOperand(9); }
|
||||
Metadata *getRawVariables() const { return getOperand(10); }
|
||||
|
||||
/// \brief Get a pointer to the function this subprogram describes.
|
||||
///
|
||||
/// This dyn_casts \a getFunctionConstant() to \a Function.
|
||||
///
|
||||
/// FIXME: Should this be looking through bitcasts?
|
||||
Function *getFunction() const;
|
||||
|
||||
/// \brief Replace the function.
|
||||
///
|
||||
/// If \a isUniqued() and not \a isResolved(), this could node will be
|
||||
@ -1710,12 +1720,13 @@ class MDGlobalVariable : public MDVariable {
|
||||
static MDGlobalVariable *
|
||||
getImpl(LLVMContext &Context, MDScope *Scope, StringRef Name,
|
||||
StringRef LinkageName, MDFile *File, unsigned Line, MDTypeRef Type,
|
||||
bool IsLocalToUnit, bool IsDefinition, ConstantAsMetadata *Variable,
|
||||
bool IsLocalToUnit, bool IsDefinition, Constant *Variable,
|
||||
MDDerivedType *StaticDataMemberDeclaration, StorageType Storage,
|
||||
bool ShouldCreate = true) {
|
||||
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
|
||||
getCanonicalMDString(Context, LinkageName), File, Line, Type,
|
||||
IsLocalToUnit, IsDefinition, Variable,
|
||||
IsLocalToUnit, IsDefinition,
|
||||
Variable ? ConstantAsMetadata::get(Variable) : nullptr,
|
||||
StaticDataMemberDeclaration, Storage, ShouldCreate);
|
||||
}
|
||||
static MDGlobalVariable *
|
||||
@ -1736,8 +1747,7 @@ public:
|
||||
DEFINE_MDNODE_GET(MDGlobalVariable,
|
||||
(MDScope * Scope, StringRef Name, StringRef LinkageName,
|
||||
MDFile *File, unsigned Line, MDTypeRef Type,
|
||||
bool IsLocalToUnit, bool IsDefinition,
|
||||
ConstantAsMetadata *Variable,
|
||||
bool IsLocalToUnit, bool IsDefinition, Constant *Variable,
|
||||
MDDerivedType *StaticDataMemberDeclaration),
|
||||
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
|
||||
IsDefinition, Variable, StaticDataMemberDeclaration))
|
||||
@ -1755,8 +1765,10 @@ public:
|
||||
bool isDefinition() const { return IsDefinition; }
|
||||
StringRef getDisplayName() const { return getStringOperand(4); }
|
||||
StringRef getLinkageName() const { return getStringOperand(5); }
|
||||
ConstantAsMetadata *getVariable() const {
|
||||
return cast_or_null<ConstantAsMetadata>(getRawVariable());
|
||||
Constant *getVariable() const {
|
||||
if (auto *C = cast_or_null<ConstantAsMetadata>(getRawVariable()))
|
||||
return dyn_cast<Constant>(C->getValue());
|
||||
return nullptr;
|
||||
}
|
||||
MDDerivedType *getStaticDataMemberDeclaration() const {
|
||||
return cast_or_null<MDDerivedType>(getRawStaticDataMemberDeclaration());
|
||||
|
@ -970,7 +970,7 @@ static void WriteMDSubprogram(const MDSubprogram *N,
|
||||
Record.push_back(N->getVirtualIndex());
|
||||
Record.push_back(N->getFlags());
|
||||
Record.push_back(N->isOptimized());
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getFunction()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getRawFunction()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getDeclaration()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getVariables().get()));
|
||||
@ -1064,7 +1064,7 @@ static void WriteMDGlobalVariable(const MDGlobalVariable *N,
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getType()));
|
||||
Record.push_back(N->isLocalToUnit());
|
||||
Record.push_back(N->isDefinition());
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getVariable()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getRawVariable()));
|
||||
Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration()));
|
||||
|
||||
Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR, Record, Abbrev);
|
||||
|
@ -594,8 +594,8 @@ DIGlobalVariable DIBuilder::createGlobalVariable(
|
||||
|
||||
auto *N = MDGlobalVariable::get(
|
||||
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, F,
|
||||
LineNumber, MDTypeRef::get(Ty), isLocalToUnit, true,
|
||||
getConstantOrNull(Val), cast_or_null<MDDerivedType>(Decl));
|
||||
LineNumber, MDTypeRef::get(Ty), isLocalToUnit, true, Val,
|
||||
cast_or_null<MDDerivedType>(Decl));
|
||||
AllGVs.push_back(N);
|
||||
return N;
|
||||
}
|
||||
@ -608,7 +608,7 @@ DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl(
|
||||
|
||||
return MDGlobalVariable::getTemporary(
|
||||
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName,
|
||||
F, LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, getConstantOrNull(Val),
|
||||
F, LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, Val,
|
||||
cast_or_null<MDDerivedType>(Decl)).release();
|
||||
}
|
||||
|
||||
@ -681,7 +681,7 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
|
||||
VMContext, MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
|
||||
Name, LinkageName, File.get(), LineNo,
|
||||
cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit, isDefinition,
|
||||
ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn),
|
||||
ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
|
||||
cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
|
||||
MDTuple::getTemporary(VMContext, None).release());
|
||||
|
||||
@ -704,10 +704,9 @@ DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
|
||||
MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), Name,
|
||||
LinkageName, File.get(), LineNo,
|
||||
cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
|
||||
isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
|
||||
getConstantOrNull(Fn), cast_or_null<MDTuple>(TParams),
|
||||
cast_or_null<MDSubprogram>(Decl), nullptr)
|
||||
.release();
|
||||
isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
|
||||
cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
|
||||
nullptr).release();
|
||||
}
|
||||
|
||||
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
|
||||
@ -728,8 +727,7 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
|
||||
VMContext, MDScopeRef::get(cast<MDScope>(Context)), Name, LinkageName,
|
||||
F.get(), LineNo, cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
|
||||
isDefinition, LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags,
|
||||
isOptimized, getConstantOrNull(Fn), cast_or_null<MDTuple>(TParam),
|
||||
nullptr, nullptr);
|
||||
isOptimized, Fn, cast_or_null<MDTuple>(TParam), nullptr, nullptr);
|
||||
|
||||
if (isDefinition)
|
||||
AllSubprograms.push_back(SP);
|
||||
|
@ -49,12 +49,6 @@ bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
|
||||
return !SP.describes(CurFn);
|
||||
}
|
||||
|
||||
Function *DISubprogram::getFunction() const {
|
||||
if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(get()->getFunction()))
|
||||
return dyn_cast<Function>(C->getValue());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool DISubprogram::describes(const Function *F) {
|
||||
assert(F && "Invalid function");
|
||||
if (F == getFunction())
|
||||
|
@ -343,6 +343,11 @@ MDSubprogram *MDSubprogram::getImpl(
|
||||
Ops);
|
||||
}
|
||||
|
||||
Function *MDSubprogram::getFunction() const {
|
||||
// FIXME: Should this be looking through bitcasts?
|
||||
return dyn_cast_or_null<Function>(getFunctionConstant());
|
||||
}
|
||||
|
||||
void MDSubprogram::replaceFunction(Function *F) {
|
||||
replaceFunction(F ? ConstantAsMetadata::get(F)
|
||||
: static_cast<ConstantAsMetadata *>(nullptr));
|
||||
|
@ -964,11 +964,7 @@ void Verifier::visitMDSubprogram(const MDSubprogram &N) {
|
||||
Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",
|
||||
&N);
|
||||
|
||||
if (!N.getFunction())
|
||||
return;
|
||||
|
||||
// FIXME: Should this be looking through bitcasts?
|
||||
auto *F = dyn_cast<Function>(N.getFunction()->getValue());
|
||||
auto *F = N.getFunction();
|
||||
if (!F)
|
||||
return;
|
||||
|
||||
|
@ -99,9 +99,11 @@ protected:
|
||||
getBasicType("basictype"), 1, 2, 0, 0)
|
||||
->getRef();
|
||||
}
|
||||
Constant *getConstant() {
|
||||
return ConstantInt::get(Type::getInt32Ty(Context), Counter++);
|
||||
}
|
||||
ConstantAsMetadata *getConstantAsMetadata() {
|
||||
return ConstantAsMetadata::get(
|
||||
ConstantInt::get(Type::getInt32Ty(Context), Counter++));
|
||||
return ConstantAsMetadata::get(getConstant());
|
||||
}
|
||||
MDTypeRef getCompositeType() {
|
||||
return MDCompositeType::getDistinct(
|
||||
@ -109,8 +111,8 @@ protected:
|
||||
nullptr, 32, 32, 0, 0, nullptr, 0, nullptr, nullptr, "")
|
||||
->getRef();
|
||||
}
|
||||
ConstantAsMetadata *getFunctionAsMetadata(StringRef Name) {
|
||||
return ConstantAsMetadata::get(M.getOrInsertFunction(
|
||||
Function *getFunction(StringRef Name) {
|
||||
return cast<Function>(M.getOrInsertFunction(
|
||||
Name, FunctionType::get(Type::getVoidTy(Context), None, false)));
|
||||
}
|
||||
};
|
||||
@ -1431,7 +1433,7 @@ TEST_F(MDSubprogramTest, get) {
|
||||
unsigned VirtualIndex = 5;
|
||||
unsigned Flags = 6;
|
||||
bool IsOptimized = false;
|
||||
ConstantAsMetadata *Function = getFunctionAsMetadata("foo");
|
||||
llvm::Function *Function = getFunction("foo");
|
||||
MDTuple *TemplateParams = getTuple();
|
||||
MDSubprogram *Declaration = getSubprogram();
|
||||
MDTuple *Variables = getTuple();
|
||||
@ -1536,12 +1538,11 @@ TEST_F(MDSubprogramTest, get) {
|
||||
ContainingType, Virtuality, VirtualIndex,
|
||||
Flags, !IsOptimized, Function, TemplateParams,
|
||||
Declaration, Variables));
|
||||
EXPECT_NE(N,
|
||||
MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
|
||||
Type, IsLocalToUnit, IsDefinition, ScopeLine,
|
||||
ContainingType, Virtuality, VirtualIndex, Flags,
|
||||
IsOptimized, getFunctionAsMetadata("bar"),
|
||||
TemplateParams, Declaration, Variables));
|
||||
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
|
||||
Type, IsLocalToUnit, IsDefinition, ScopeLine,
|
||||
ContainingType, Virtuality, VirtualIndex,
|
||||
Flags, IsOptimized, getFunction("bar"),
|
||||
TemplateParams, Declaration, Variables));
|
||||
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
|
||||
Type, IsLocalToUnit, IsDefinition, ScopeLine,
|
||||
ContainingType, Virtuality, VirtualIndex,
|
||||
@ -1592,7 +1593,7 @@ TEST_F(MDSubprogramTest, replaceFunction) {
|
||||
Function::Create(FunctionType::get(Type::getVoidTy(Context), false),
|
||||
GlobalValue::ExternalLinkage));
|
||||
N->replaceFunction(F.get());
|
||||
EXPECT_EQ(ConstantAsMetadata::get(F.get()), N->getFunction());
|
||||
EXPECT_EQ(F.get(), N->getFunction());
|
||||
|
||||
N->replaceFunction(nullptr);
|
||||
EXPECT_EQ(nullptr, N->getFunction());
|
||||
@ -1738,7 +1739,7 @@ TEST_F(MDGlobalVariableTest, get) {
|
||||
MDTypeRef Type = getDerivedType();
|
||||
bool IsLocalToUnit = false;
|
||||
bool IsDefinition = true;
|
||||
ConstantAsMetadata *Variable = getConstantAsMetadata();
|
||||
Constant *Variable = getConstant();
|
||||
MDDerivedType *StaticDataMemberDeclaration =
|
||||
cast<MDDerivedType>(getDerivedType());
|
||||
|
||||
@ -1788,10 +1789,10 @@ TEST_F(MDGlobalVariableTest, get) {
|
||||
EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
|
||||
Line, Type, IsLocalToUnit, !IsDefinition,
|
||||
Variable, StaticDataMemberDeclaration));
|
||||
EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
|
||||
Line, Type, IsLocalToUnit, IsDefinition,
|
||||
getConstantAsMetadata(),
|
||||
StaticDataMemberDeclaration));
|
||||
EXPECT_NE(N,
|
||||
MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
|
||||
Type, IsLocalToUnit, IsDefinition,
|
||||
getConstant(), StaticDataMemberDeclaration));
|
||||
EXPECT_NE(N,
|
||||
MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
|
||||
Type, IsLocalToUnit, IsDefinition, Variable,
|
||||
|
Loading…
Reference in New Issue
Block a user