[llvm] r234699 - DebugInfo: Make MDSubprogram::getFunction() return Constant
Duncan P. N. Exon Smith
dexonsmith at apple.com
Sat Apr 11 13:27:41 PDT 2015
Author: dexonsmith
Date: Sat Apr 11 15:27:40 2015
New Revision: 234699
URL: http://llvm.org/viewvc/llvm-project?rev=234699&view=rev
Log:
DebugInfo: Make MDSubprogram::getFunction() return Constant
Change `MDSubprogram::getFunction()` and
`MDGlobalVariable::getConstant()` to return a `Constant`. Previously,
both returned `ConstantAsMetadata`.
Modified:
llvm/trunk/include/llvm/IR/DebugInfo.h
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/trunk/lib/IR/DIBuilder.cpp
llvm/trunk/lib/IR/DebugInfo.cpp
llvm/trunk/lib/IR/DebugInfoMetadata.cpp
llvm/trunk/lib/IR/Verifier.cpp
llvm/trunk/unittests/IR/MetadataTest.cpp
Modified: llvm/trunk/include/llvm/IR/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfo.h Sat Apr 11 15:27:40 2015
@@ -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());
}
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Sat Apr 11 15:27:40 2015
@@ -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 MDVariab
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());
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Sat Apr 11 15:27:40 2015
@@ -970,7 +970,7 @@ static void WriteMDSubprogram(const MDSu
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
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);
Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Sat Apr 11 15:27:40 2015
@@ -594,8 +594,8 @@ DIGlobalVariable DIBuilder::createGlobal
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::createTempGl
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(D
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(DID
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(DID
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);
Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Sat Apr 11 15:27:40 2015
@@ -49,12 +49,6 @@ bool DIVariable::isInlinedFnArgument(con
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())
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Sat Apr 11 15:27:40 2015
@@ -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));
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Sat Apr 11 15:27:40 2015
@@ -964,11 +964,7 @@ void Verifier::visitMDSubprogram(const M
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;
Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=234699&r1=234698&r2=234699&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Sat Apr 11 15:27:40 2015
@@ -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,
More information about the llvm-commits
mailing list