[llvm-commits] [llvm] r58960 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp
Chris Lattner
sabre at nondot.org
Sun Nov 9 20:10:36 PST 2008
Author: lattner
Date: Sun Nov 9 22:10:34 2008
New Revision: 58960
URL: http://llvm.org/viewvc/llvm-project?rev=58960&view=rev
Log:
Move getCastToEmpty out of DIDescriptor into DIFactory. It is an
implementation detail of DIFactory anyway, and this allows it to avoid
recomputing the same type over and over.
Modified:
llvm/trunk/include/llvm/Analysis/DebugInfo.h
llvm/trunk/lib/Analysis/DebugInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=58960&r1=58959&r2=58960&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Sun Nov 9 22:10:34 2008
@@ -24,6 +24,7 @@
class Function;
class GlobalVariable;
class Module;
+ class Type;
class Value;
class DIDescriptor {
@@ -71,9 +72,6 @@
bool isNull() const { return GV == 0; }
GlobalVariable *getGV() const { return GV; }
-
- /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
- Constant *getCastToEmpty() const;
};
/// DIAnchor - A wrapper for various anchor descriptors.
@@ -259,6 +257,7 @@
Module &M;
// Cached values for uniquing and faster lookups.
DIAnchor CompileUnitAnchor, SubProgramAnchor, GlobalVariableAnchor;
+ const Type *EmptyStructPtr; // "{}*".
Function *StopPointFn; // llvm.dbg.stoppoint
Function *FuncStartFn; // llvm.dbg.func.start
Function *RegionStartFn; // llvm.dbg.region.start
@@ -270,9 +269,7 @@
DIFactory(const DIFactory &); // DO NOT IMPLEMENT
void operator=(const DIFactory&); // DO NOT IMPLEMENT
public:
- explicit DIFactory(Module &m) : M(m) {
- StopPointFn = FuncStartFn = RegionStartFn = RegionEndFn = DeclareFn = 0;
- }
+ explicit DIFactory(Module &m);
/// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
/// creating a new one if there isn't already one in the module.
@@ -386,6 +383,9 @@
Constant *GetTagConstant(unsigned TAG);
Constant *GetStringConstant(const std::string &String);
DIAnchor GetOrCreateAnchor(unsigned TAG, const char *Name);
+
+ /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
+ Constant *getCastToEmpty(DIDescriptor D);
};
Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=58960&r1=58959&r2=58960&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Sun Nov 9 22:10:34 2008
@@ -80,14 +80,6 @@
-/// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
-/// This is only valid when the descriptor is non-null.
-Constant *DIDescriptor::getCastToEmpty() const {
- const Type *DestTy = PointerType::getUnqual(StructType::get(NULL, NULL));
- if (isNull()) return Constant::getNullValue(DestTy);
- return ConstantExpr::getBitCast(GV, DestTy);
-}
-
//===----------------------------------------------------------------------===//
// Simple Descriptor Constructors and other Methods
//===----------------------------------------------------------------------===//
@@ -179,6 +171,18 @@
// DIFactory: Basic Helpers
//===----------------------------------------------------------------------===//
+DIFactory::DIFactory(Module &m) : M(m) {
+ StopPointFn = FuncStartFn = RegionStartFn = RegionEndFn = DeclareFn = 0;
+ EmptyStructPtr = PointerType::getUnqual(StructType::get(NULL, NULL));
+}
+
+/// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
+/// This is only valid when the descriptor is non-null.
+Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
+ if (D.isNull()) return Constant::getNullValue(EmptyStructPtr);
+ return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr);
+}
+
Constant *DIFactory::GetTagConstant(unsigned TAG) {
assert((TAG & DIDescriptor::VersionMask) == 0 &&
"Tag too large for debug encoding!");
@@ -212,7 +216,7 @@
/// GetOrCreateAnchor - Look up an anchor for the specified tag and name. If it
/// already exists, return it. If not, create a new one and return it.
DIAnchor DIFactory::GetOrCreateAnchor(unsigned TAG, const char *Name) {
- const Type *EltTy = StructType::get(Type::Int32Ty, Type::Int32Ty, NULL);
+ const Type *EltTy = StructType::get(Type::Int32Ty, Type::Int32Ty, NULL);
// Otherwise, create the global or return it if already in the module.
Constant *C = M.getOrInsertGlobal(Name, EltTy);
@@ -280,11 +284,10 @@
SmallVector<Constant*, 16> Elts;
for (unsigned i = 0; i != NumTys; ++i)
- Elts.push_back(Tys[i].getCastToEmpty());
-
- const Type *EltTy = PointerType::getUnqual(StructType::get(NULL,NULL));
+ Elts.push_back(getCastToEmpty(Tys[i]));
- Constant *Init = ConstantArray::get(ArrayType::get(EltTy, Elts.size()),
+ Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
+ Elts.size()),
&Elts[0], Elts.size());
// If we already have this array, just return the uniqued version.
DIDescriptor &Entry = SimpleConstantCache[Init];
@@ -333,7 +336,7 @@
const std::string &Producer) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_compile_unit),
- GetOrCreateCompileUnitAnchor().getCastToEmpty(),
+ getCastToEmpty(GetOrCreateCompileUnitAnchor()),
ConstantInt::get(Type::Int32Ty, LangID),
GetStringConstant(Filename),
GetStringConstant(Directory),
@@ -380,9 +383,9 @@
unsigned Encoding) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_base_type),
- Context.getCastToEmpty(),
+ getCastToEmpty(Context),
GetStringConstant(Name),
- CompileUnit.getCastToEmpty(),
+ getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNumber),
ConstantInt::get(Type::Int64Ty, SizeInBits),
ConstantInt::get(Type::Int64Ty, AlignInBits),
@@ -415,15 +418,15 @@
DIType DerivedFrom) {
Constant *Elts[] = {
GetTagConstant(Tag),
- Context.getCastToEmpty(),
+ getCastToEmpty(Context),
GetStringConstant(Name),
- CompileUnit.getCastToEmpty(),
+ getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNumber),
ConstantInt::get(Type::Int64Ty, SizeInBits),
ConstantInt::get(Type::Int64Ty, AlignInBits),
ConstantInt::get(Type::Int64Ty, OffsetInBits),
ConstantInt::get(Type::Int32Ty, Flags),
- DerivedFrom.getCastToEmpty()
+ getCastToEmpty(DerivedFrom)
};
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
@@ -450,16 +453,16 @@
DIArray Elements) {
Constant *Elts[] = {
GetTagConstant(Tag),
- Context.getCastToEmpty(),
+ getCastToEmpty(Context),
GetStringConstant(Name),
- CompileUnit.getCastToEmpty(),
+ getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNumber),
ConstantInt::get(Type::Int64Ty, SizeInBits),
ConstantInt::get(Type::Int64Ty, AlignInBits),
ConstantInt::get(Type::Int64Ty, OffsetInBits),
ConstantInt::get(Type::Int32Ty, Flags),
- DerivedFrom.getCastToEmpty(),
- Elements.getCastToEmpty()
+ getCastToEmpty(DerivedFrom),
+ getCastToEmpty(Elements)
};
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
@@ -486,14 +489,14 @@
bool isDefinition) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_subprogram),
- GetOrCreateSubprogramAnchor().getCastToEmpty(),
- Context.getCastToEmpty(),
+ getCastToEmpty(GetOrCreateSubprogramAnchor()),
+ getCastToEmpty(Context),
GetStringConstant(Name),
GetStringConstant(DisplayName),
GetStringConstant(LinkageName),
- CompileUnit.getCastToEmpty(),
+ getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNo),
- Type.getCastToEmpty(),
+ getCastToEmpty(Type),
ConstantInt::get(Type::Int1Ty, isLocalToUnit),
ConstantInt::get(Type::Int1Ty, isDefinition)
};
@@ -519,18 +522,17 @@
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_variable),
- GetOrCreateGlobalVariableAnchor().getCastToEmpty(),
- Context.getCastToEmpty(),
+ getCastToEmpty(GetOrCreateGlobalVariableAnchor()),
+ getCastToEmpty(Context),
GetStringConstant(Name),
GetStringConstant(DisplayName),
GetStringConstant(LinkageName),
- CompileUnit.getCastToEmpty(),
+ getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNo),
- Type.getCastToEmpty(),
+ getCastToEmpty(Type),
ConstantInt::get(Type::Int1Ty, isLocalToUnit),
ConstantInt::get(Type::Int1Ty, isDefinition),
- ConstantExpr::getBitCast(Val,
- PointerType::getUnqual(StructType::get(NULL,NULL)))
+ ConstantExpr::getBitCast(Val, EmptyStructPtr)
};
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
@@ -552,11 +554,11 @@
Constant *Elts[] = {
GetTagConstant(Tag),
- Context.getCastToEmpty(),
+ getCastToEmpty(Context),
GetStringConstant(Name),
- CompileUnit.getCastToEmpty(),
+ getCastToEmpty(CompileUnit),
ConstantInt::get(Type::Int32Ty, LineNo),
- Type.getCastToEmpty(),
+ getCastToEmpty(Type),
};
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
@@ -575,7 +577,7 @@
DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_lexical_block),
- Context.getCastToEmpty()
+ getCastToEmpty(Context)
};
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
@@ -607,7 +609,7 @@
Value *Args[] = {
llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo),
llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo),
- CU.getCastToEmpty()
+ getCastToEmpty(CU)
};
CallInst::Create(StopPointFn, Args, Args+3, "", BB);
}
@@ -621,7 +623,7 @@
llvm::Intrinsic::dbg_func_start);
// Call llvm.dbg.func.start which also implicitly sets a stoppoint.
- CallInst::Create(FuncStartFn, SP.getCastToEmpty(), "", BB);
+ CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB);
}
/// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
@@ -632,7 +634,7 @@
RegionStartFn = llvm::Intrinsic::getDeclaration(&M,
llvm::Intrinsic::dbg_region_start);
// Call llvm.dbg.func.start.
- CallInst::Create(RegionStartFn, D.getCastToEmpty(), "", BB);
+ CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB);
}
@@ -644,19 +646,18 @@
RegionEndFn = llvm::Intrinsic::getDeclaration(&M,
llvm::Intrinsic::dbg_region_end);
- CallInst::Create(RegionEndFn, D.getCastToEmpty(), "", BB);
+ CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB);
}
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
void DIFactory::InsertDeclare(llvm::Value *Storage, DIVariable D,
BasicBlock *BB) {
// Cast the storage to a {}* for the call to llvm.dbg.declare.
- const Type *DestTy = PointerType::getUnqual(StructType::get(NULL, NULL));
- Storage = new llvm::BitCastInst(Storage, DestTy, Storage->getName(), BB);
+ Storage = new llvm::BitCastInst(Storage, EmptyStructPtr, "", BB);
if (!DeclareFn)
DeclareFn = llvm::Intrinsic::getDeclaration(&M,
llvm::Intrinsic::dbg_declare);
- Value *Args[] = { Storage, D.getCastToEmpty() };
+ Value *Args[] = { Storage, getCastToEmpty(D) };
CallInst::Create(DeclareFn, Args, Args+2, "", BB);
}
More information about the llvm-commits
mailing list