1 //===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/CodeGen/MachineDebugInfo.h"
12 #include "llvm/Constants.h"
13 #include "llvm/CodeGen/MachineLocation.h"
14 #include "llvm/DerivedTypes.h"
15 #include "llvm/GlobalVariable.h"
16 #include "llvm/Intrinsics.h"
17 #include "llvm/Instructions.h"
18 #include "llvm/Module.h"
19 #include "llvm/Support/Dwarf.h"
24 using namespace llvm::dwarf;
26 // Handle the Pass registration stuff necessary to use TargetData's.
28 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
31 //===----------------------------------------------------------------------===//
33 /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the
34 /// specified value in their initializer somewhere.
36 getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) {
37 // Scan though value users.
38 for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
39 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) {
40 // If the user is a GlobalVariable then add to result.
42 } else if (Constant *C = dyn_cast<Constant>(*I)) {
43 // If the user is a constant variable then scan its users
44 getGlobalVariablesUsing(C, Result);
49 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
50 /// named GlobalVariable.
51 static std::vector<GlobalVariable*>
52 getGlobalVariablesUsing(Module &M, const std::string &RootName) {
53 std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria.
55 std::vector<const Type*> FieldTypes;
56 FieldTypes.push_back(Type::UIntTy);
57 FieldTypes.push_back(Type::UIntTy);
59 // Get the GlobalVariable root.
60 GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
61 StructType::get(FieldTypes));
63 // If present and linkonce then scan for users.
64 if (UseRoot && UseRoot->hasLinkOnceLinkage()) {
65 getGlobalVariablesUsing(UseRoot, Result);
71 /// isStringValue - Return true if the given value can be coerced to a string.
73 static bool isStringValue(Value *V) {
74 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
75 if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
76 ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
77 return Init->isString();
79 } else if (Constant *C = dyn_cast<Constant>(V)) {
80 if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
81 return isStringValue(GV);
82 else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
83 if (CE->getOpcode() == Instruction::GetElementPtr) {
84 if (CE->getNumOperands() == 3 &&
85 cast<Constant>(CE->getOperand(1))->isNullValue() &&
86 isa<ConstantInt>(CE->getOperand(2))) {
87 return isStringValue(CE->getOperand(0));
95 /// getGlobalVariable - Return either a direct or cast Global value.
97 static GlobalVariable *getGlobalVariable(Value *V) {
98 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
100 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
101 if (CE->getOpcode() == Instruction::Cast) {
102 return dyn_cast<GlobalVariable>(CE->getOperand(0));
108 /// isGlobalVariable - Return true if the given value can be coerced to a
110 static bool isGlobalVariable(Value *V) {
111 if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) {
113 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
114 if (CE->getOpcode() == Instruction::Cast) {
115 return isa<GlobalVariable>(CE->getOperand(0));
121 /// getUIntOperand - Return ith operand if it is an unsigned integer.
123 static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) {
124 // Make sure the GlobalVariable has an initializer.
125 if (!GV->hasInitializer()) return NULL;
127 // Get the initializer constant.
128 ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer());
129 if (!CI) return NULL;
131 // Check if there is at least i + 1 operands.
132 unsigned N = CI->getNumOperands();
133 if (i >= N) return NULL;
136 return dyn_cast<ConstantUInt>(CI->getOperand(i));
138 //===----------------------------------------------------------------------===//
140 /// ApplyToFields - Target the visitor to each field of the debug information
142 void DIVisitor::ApplyToFields(DebugInfoDesc *DD) {
143 DD->ApplyToFields(this);
146 //===----------------------------------------------------------------------===//
147 /// DICountVisitor - This DIVisitor counts all the fields in the supplied debug
148 /// the supplied DebugInfoDesc.
149 class DICountVisitor : public DIVisitor {
151 unsigned Count; // Running count of fields.
154 DICountVisitor() : DIVisitor(), Count(0) {}
157 unsigned getCount() const { return Count; }
159 /// Apply - Count each of the fields.
161 virtual void Apply(int &Field) { ++Count; }
162 virtual void Apply(unsigned &Field) { ++Count; }
163 virtual void Apply(int64_t &Field) { ++Count; }
164 virtual void Apply(uint64_t &Field) { ++Count; }
165 virtual void Apply(bool &Field) { ++Count; }
166 virtual void Apply(std::string &Field) { ++Count; }
167 virtual void Apply(DebugInfoDesc *&Field) { ++Count; }
168 virtual void Apply(GlobalVariable *&Field) { ++Count; }
169 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
174 //===----------------------------------------------------------------------===//
175 /// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the
176 /// supplied DebugInfoDesc.
177 class DIDeserializeVisitor : public DIVisitor {
179 DIDeserializer &DR; // Active deserializer.
180 unsigned I; // Current operand index.
181 ConstantStruct *CI; // GlobalVariable constant initializer.
184 DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV)
188 , CI(cast<ConstantStruct>(GV->getInitializer()))
191 /// Apply - Set the value of each of the fields.
193 virtual void Apply(int &Field) {
194 Constant *C = CI->getOperand(I++);
195 Field = cast<ConstantSInt>(C)->getValue();
197 virtual void Apply(unsigned &Field) {
198 Constant *C = CI->getOperand(I++);
199 Field = cast<ConstantUInt>(C)->getValue();
201 virtual void Apply(int64_t &Field) {
202 Constant *C = CI->getOperand(I++);
203 Field = cast<ConstantSInt>(C)->getValue();
205 virtual void Apply(uint64_t &Field) {
206 Constant *C = CI->getOperand(I++);
207 Field = cast<ConstantUInt>(C)->getValue();
209 virtual void Apply(bool &Field) {
210 Constant *C = CI->getOperand(I++);
211 Field = cast<ConstantBool>(C)->getValue();
213 virtual void Apply(std::string &Field) {
214 Constant *C = CI->getOperand(I++);
215 Field = C->getStringValue();
217 virtual void Apply(DebugInfoDesc *&Field) {
218 Constant *C = CI->getOperand(I++);
219 Field = DR.Deserialize(C);
221 virtual void Apply(GlobalVariable *&Field) {
222 Constant *C = CI->getOperand(I++);
223 Field = getGlobalVariable(C);
225 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
227 Constant *C = CI->getOperand(I++);
228 GlobalVariable *GV = getGlobalVariable(C);
229 if (GV->hasInitializer()) {
230 if (ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer())) {
231 for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) {
232 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
233 DebugInfoDesc *DE = DR.Deserialize(GVE);
236 } else if (GV->getInitializer()->isNullValue()) {
237 if (const ArrayType *T =
238 dyn_cast<ArrayType>(GV->getType()->getElementType())) {
239 Field.resize(T->getNumElements());
246 //===----------------------------------------------------------------------===//
247 /// DISerializeVisitor - This DIVisitor serializes all the fields in
248 /// the supplied DebugInfoDesc.
249 class DISerializeVisitor : public DIVisitor {
251 DISerializer &SR; // Active serializer.
252 std::vector<Constant*> &Elements; // Element accumulator.
255 DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E)
261 /// Apply - Set the value of each of the fields.
263 virtual void Apply(int &Field) {
264 Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
266 virtual void Apply(unsigned &Field) {
267 Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
269 virtual void Apply(int64_t &Field) {
270 Elements.push_back(ConstantSInt::get(Type::LongTy, Field));
272 virtual void Apply(uint64_t &Field) {
273 Elements.push_back(ConstantUInt::get(Type::ULongTy, Field));
275 virtual void Apply(bool &Field) {
276 Elements.push_back(ConstantBool::get(Field));
278 virtual void Apply(std::string &Field) {
279 Elements.push_back(SR.getString(Field));
281 virtual void Apply(DebugInfoDesc *&Field) {
282 GlobalVariable *GV = NULL;
284 // If non-NULL then convert to global.
285 if (Field) GV = SR.Serialize(Field);
287 // FIXME - At some point should use specific type.
288 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
291 // Set to pointer to global.
292 Elements.push_back(ConstantExpr::getCast(GV, EmptyTy));
295 Elements.push_back(ConstantPointerNull::get(EmptyTy));
298 virtual void Apply(GlobalVariable *&Field) {
299 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
301 Elements.push_back(ConstantExpr::getCast(Field, EmptyTy));
303 Elements.push_back(ConstantPointerNull::get(EmptyTy));
306 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
307 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
308 unsigned N = Field.size();
309 ArrayType *AT = ArrayType::get(EmptyTy, N);
310 std::vector<Constant *> ArrayElements;
312 for (unsigned i = 0, N = Field.size(); i < N; ++i) {
313 if (DebugInfoDesc *Element = Field[i]) {
314 GlobalVariable *GVE = SR.Serialize(Element);
315 Constant *CE = ConstantExpr::getCast(GVE, EmptyTy);
316 ArrayElements.push_back(cast<Constant>(CE));
318 ArrayElements.push_back(ConstantPointerNull::get(EmptyTy));
322 Constant *CA = ConstantArray::get(AT, ArrayElements);
323 GlobalVariable *CAGV = new GlobalVariable(AT, true,
324 GlobalValue::InternalLinkage,
325 CA, "llvm.dbg.array",
327 CAGV->setSection("llvm.metadata");
328 Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy);
329 Elements.push_back(CAE);
333 //===----------------------------------------------------------------------===//
334 /// DIGetTypesVisitor - This DIVisitor gathers all the field types in
335 /// the supplied DebugInfoDesc.
336 class DIGetTypesVisitor : public DIVisitor {
338 DISerializer &SR; // Active serializer.
339 std::vector<const Type*> &Fields; // Type accumulator.
342 DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F)
348 /// Apply - Set the value of each of the fields.
350 virtual void Apply(int &Field) {
351 Fields.push_back(Type::IntTy);
353 virtual void Apply(unsigned &Field) {
354 Fields.push_back(Type::UIntTy);
356 virtual void Apply(int64_t &Field) {
357 Fields.push_back(Type::LongTy);
359 virtual void Apply(uint64_t &Field) {
360 Fields.push_back(Type::ULongTy);
362 virtual void Apply(bool &Field) {
363 Fields.push_back(Type::BoolTy);
365 virtual void Apply(std::string &Field) {
366 Fields.push_back(SR.getStrPtrType());
368 virtual void Apply(DebugInfoDesc *&Field) {
369 // FIXME - At some point should use specific type.
370 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
371 Fields.push_back(EmptyTy);
373 virtual void Apply(GlobalVariable *&Field) {
374 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
375 Fields.push_back(EmptyTy);
377 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
378 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
379 Fields.push_back(EmptyTy);
383 //===----------------------------------------------------------------------===//
384 /// DIVerifyVisitor - This DIVisitor verifies all the field types against
385 /// a constant initializer.
386 class DIVerifyVisitor : public DIVisitor {
388 DIVerifier &VR; // Active verifier.
389 bool IsValid; // Validity status.
390 unsigned I; // Current operand index.
391 ConstantStruct *CI; // GlobalVariable constant initializer.
394 DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV)
399 , CI(cast<ConstantStruct>(GV->getInitializer()))
404 bool isValid() const { return IsValid; }
406 /// Apply - Set the value of each of the fields.
408 virtual void Apply(int &Field) {
409 Constant *C = CI->getOperand(I++);
410 IsValid = IsValid && isa<ConstantInt>(C);
412 virtual void Apply(unsigned &Field) {
413 Constant *C = CI->getOperand(I++);
414 IsValid = IsValid && isa<ConstantInt>(C);
416 virtual void Apply(int64_t &Field) {
417 Constant *C = CI->getOperand(I++);
418 IsValid = IsValid && isa<ConstantInt>(C);
420 virtual void Apply(uint64_t &Field) {
421 Constant *C = CI->getOperand(I++);
422 IsValid = IsValid && isa<ConstantInt>(C);
424 virtual void Apply(bool &Field) {
425 Constant *C = CI->getOperand(I++);
426 IsValid = IsValid && isa<ConstantBool>(C);
428 virtual void Apply(std::string &Field) {
429 Constant *C = CI->getOperand(I++);
430 IsValid = IsValid && (!C || isStringValue(C));
432 virtual void Apply(DebugInfoDesc *&Field) {
433 // FIXME - Prepare the correct descriptor.
434 Constant *C = CI->getOperand(I++);
435 IsValid = IsValid && isGlobalVariable(C);
437 virtual void Apply(GlobalVariable *&Field) {
438 Constant *C = CI->getOperand(I++);
439 IsValid = IsValid && isGlobalVariable(C);
441 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
442 Constant *C = CI->getOperand(I++);
443 IsValid = IsValid && isGlobalVariable(C);
444 if (!IsValid) return;
446 GlobalVariable *GV = getGlobalVariable(C);
447 IsValid = IsValid && GV && GV->hasInitializer();
448 if (!IsValid) return;
450 ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer());
451 IsValid = IsValid && CA;
452 if (!IsValid) return;
454 for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) {
455 IsValid = IsValid && isGlobalVariable(CA->getOperand(i));
456 if (!IsValid) return;
458 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
465 //===----------------------------------------------------------------------===//
467 /// TagFromGlobal - Returns the tag number from a debug info descriptor
468 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
469 unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) {
470 ConstantUInt *C = getUIntOperand(GV, 0);
471 return C ? ((unsigned)C->getValue() & ~LLVMDebugVersionMask) :
472 (unsigned)DW_TAG_invalid;
475 /// VersionFromGlobal - Returns the version number from a debug info
476 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
478 unsigned DebugInfoDesc::VersionFromGlobal(GlobalVariable *GV) {
479 ConstantUInt *C = getUIntOperand(GV, 0);
480 return C ? ((unsigned)C->getValue() & LLVMDebugVersionMask) :
481 (unsigned)DW_TAG_invalid;
484 /// DescFactory - Create an instance of debug info descriptor based on Tag.
485 /// Return NULL if not a recognized Tag.
486 DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
488 case DW_TAG_anchor: return new AnchorDesc();
489 case DW_TAG_compile_unit: return new CompileUnitDesc();
490 case DW_TAG_variable: return new GlobalVariableDesc();
491 case DW_TAG_subprogram: return new SubprogramDesc();
492 case DW_TAG_lexical_block: return new BlockDesc();
493 case DW_TAG_base_type: return new BasicTypeDesc();
495 case DW_TAG_pointer_type:
496 case DW_TAG_reference_type:
497 case DW_TAG_const_type:
498 case DW_TAG_volatile_type:
499 case DW_TAG_restrict_type:
501 case DW_TAG_inheritance: return new DerivedTypeDesc(Tag);
502 case DW_TAG_array_type:
503 case DW_TAG_structure_type:
504 case DW_TAG_union_type:
505 case DW_TAG_enumeration_type:
506 case DW_TAG_vector_type:
507 case DW_TAG_subroutine_type: return new CompositeTypeDesc(Tag);
508 case DW_TAG_subrange_type: return new SubrangeDesc();
509 case DW_TAG_enumerator: return new EnumeratorDesc();
510 case DW_TAG_return_variable:
511 case DW_TAG_arg_variable:
512 case DW_TAG_auto_variable: return new VariableDesc(Tag);
518 /// getLinkage - get linkage appropriate for this type of descriptor.
520 GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const {
521 return GlobalValue::InternalLinkage;
524 /// ApplyToFields - Target the vistor to the fields of the descriptor.
526 void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) {
530 //===----------------------------------------------------------------------===//
532 AnchorDesc::AnchorDesc()
533 : DebugInfoDesc(DW_TAG_anchor)
536 AnchorDesc::AnchorDesc(AnchoredDesc *D)
537 : DebugInfoDesc(DW_TAG_anchor)
538 , AnchorTag(D->getTag())
541 // Implement isa/cast/dyncast.
542 bool AnchorDesc::classof(const DebugInfoDesc *D) {
543 return D->getTag() == DW_TAG_anchor;
546 /// getLinkage - get linkage appropriate for this type of descriptor.
548 GlobalValue::LinkageTypes AnchorDesc::getLinkage() const {
549 return GlobalValue::LinkOnceLinkage;
552 /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc.
554 void AnchorDesc::ApplyToFields(DIVisitor *Visitor) {
555 DebugInfoDesc::ApplyToFields(Visitor);
557 Visitor->Apply(AnchorTag);
560 /// getDescString - Return a string used to compose global names and labels. A
561 /// A global variable name needs to be defined for each debug descriptor that is
562 /// anchored. NOTE: that each global variable named here also needs to be added
563 /// to the list of names left external in the internalizer.
564 /// ExternalNames.insert("llvm.dbg.compile_units");
565 /// ExternalNames.insert("llvm.dbg.global_variables");
566 /// ExternalNames.insert("llvm.dbg.subprograms");
567 const char *AnchorDesc::getDescString() const {
569 case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString;
570 case DW_TAG_variable: return GlobalVariableDesc::AnchorString;
571 case DW_TAG_subprogram: return SubprogramDesc::AnchorString;
575 assert(0 && "Tag does not have a case for anchor string");
579 /// getTypeString - Return a string used to label this descriptors type.
581 const char *AnchorDesc::getTypeString() const {
582 return "llvm.dbg.anchor.type";
586 void AnchorDesc::dump() {
587 std::cerr << getDescString() << " "
588 << "Version(" << getVersion() << "), "
589 << "Tag(" << getTag() << "), "
590 << "AnchorTag(" << AnchorTag << ")\n";
594 //===----------------------------------------------------------------------===//
596 AnchoredDesc::AnchoredDesc(unsigned T)
601 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
603 void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) {
604 DebugInfoDesc::ApplyToFields(Visitor);
606 Visitor->Apply(Anchor);
609 //===----------------------------------------------------------------------===//
611 CompileUnitDesc::CompileUnitDesc()
612 : AnchoredDesc(DW_TAG_compile_unit)
619 // Implement isa/cast/dyncast.
620 bool CompileUnitDesc::classof(const DebugInfoDesc *D) {
621 return D->getTag() == DW_TAG_compile_unit;
624 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
626 void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) {
627 AnchoredDesc::ApplyToFields(Visitor);
629 // Handle cases out of sync with compiler.
630 if (getVersion() == 0) {
631 unsigned DebugVersion;
632 Visitor->Apply(DebugVersion);
635 Visitor->Apply(Language);
636 Visitor->Apply(FileName);
637 Visitor->Apply(Directory);
638 Visitor->Apply(Producer);
641 /// getDescString - Return a string used to compose global names and labels.
643 const char *CompileUnitDesc::getDescString() const {
644 return "llvm.dbg.compile_unit";
647 /// getTypeString - Return a string used to label this descriptors type.
649 const char *CompileUnitDesc::getTypeString() const {
650 return "llvm.dbg.compile_unit.type";
653 /// getAnchorString - Return a string used to label this descriptor's anchor.
655 const char *CompileUnitDesc::AnchorString = "llvm.dbg.compile_units";
656 const char *CompileUnitDesc::getAnchorString() const {
661 void CompileUnitDesc::dump() {
662 std::cerr << getDescString() << " "
663 << "Version(" << getVersion() << "), "
664 << "Tag(" << getTag() << "), "
665 << "Anchor(" << getAnchor() << "), "
666 << "Language(" << Language << "), "
667 << "FileName(\"" << FileName << "\"), "
668 << "Directory(\"" << Directory << "\"), "
669 << "Producer(\"" << Producer << "\")\n";
673 //===----------------------------------------------------------------------===//
675 TypeDesc::TypeDesc(unsigned T)
687 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
689 void TypeDesc::ApplyToFields(DIVisitor *Visitor) {
690 DebugInfoDesc::ApplyToFields(Visitor);
692 Visitor->Apply(Context);
693 Visitor->Apply(Name);
694 Visitor->Apply(File);
695 Visitor->Apply(Line);
696 Visitor->Apply(Size);
697 Visitor->Apply(Align);
698 Visitor->Apply(Offset);
699 if (getVersion() > LLVMDebugVersion4) Visitor->Apply(Flags);
702 /// getDescString - Return a string used to compose global names and labels.
704 const char *TypeDesc::getDescString() const {
705 return "llvm.dbg.type";
708 /// getTypeString - Return a string used to label this descriptor's type.
710 const char *TypeDesc::getTypeString() const {
711 return "llvm.dbg.type.type";
715 void TypeDesc::dump() {
716 std::cerr << getDescString() << " "
717 << "Version(" << getVersion() << "), "
718 << "Tag(" << getTag() << "), "
719 << "Context(" << Context << "), "
720 << "Name(\"" << Name << "\"), "
721 << "File(" << File << "), "
722 << "Line(" << Line << "), "
723 << "Size(" << Size << "), "
724 << "Align(" << Align << "), "
725 << "Offset(" << Offset << "), "
726 << "Flags(" << Flags << ")\n";
730 //===----------------------------------------------------------------------===//
732 BasicTypeDesc::BasicTypeDesc()
733 : TypeDesc(DW_TAG_base_type)
737 // Implement isa/cast/dyncast.
738 bool BasicTypeDesc::classof(const DebugInfoDesc *D) {
739 return D->getTag() == DW_TAG_base_type;
742 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
744 void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) {
745 TypeDesc::ApplyToFields(Visitor);
747 Visitor->Apply(Encoding);
750 /// getDescString - Return a string used to compose global names and labels.
752 const char *BasicTypeDesc::getDescString() const {
753 return "llvm.dbg.basictype";
756 /// getTypeString - Return a string used to label this descriptor's type.
758 const char *BasicTypeDesc::getTypeString() const {
759 return "llvm.dbg.basictype.type";
763 void BasicTypeDesc::dump() {
764 std::cerr << getDescString() << " "
765 << "Version(" << getVersion() << "), "
766 << "Tag(" << getTag() << "), "
767 << "Context(" << getContext() << "), "
768 << "Name(\"" << getName() << "\"), "
769 << "Size(" << getSize() << "), "
770 << "Encoding(" << Encoding << ")\n";
774 //===----------------------------------------------------------------------===//
776 DerivedTypeDesc::DerivedTypeDesc(unsigned T)
781 // Implement isa/cast/dyncast.
782 bool DerivedTypeDesc::classof(const DebugInfoDesc *D) {
783 unsigned T = D->getTag();
786 case DW_TAG_pointer_type:
787 case DW_TAG_reference_type:
788 case DW_TAG_const_type:
789 case DW_TAG_volatile_type:
790 case DW_TAG_restrict_type:
792 case DW_TAG_inheritance:
799 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
801 void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) {
802 TypeDesc::ApplyToFields(Visitor);
804 Visitor->Apply(FromType);
807 /// getDescString - Return a string used to compose global names and labels.
809 const char *DerivedTypeDesc::getDescString() const {
810 return "llvm.dbg.derivedtype";
813 /// getTypeString - Return a string used to label this descriptor's type.
815 const char *DerivedTypeDesc::getTypeString() const {
816 return "llvm.dbg.derivedtype.type";
820 void DerivedTypeDesc::dump() {
821 std::cerr << getDescString() << " "
822 << "Version(" << getVersion() << "), "
823 << "Tag(" << getTag() << "), "
824 << "Context(" << getContext() << "), "
825 << "Name(\"" << getName() << "\"), "
826 << "Size(" << getSize() << "), "
827 << "File(" << getFile() << "), "
828 << "Line(" << getLine() << "), "
829 << "FromType(" << FromType << ")\n";
833 //===----------------------------------------------------------------------===//
835 CompositeTypeDesc::CompositeTypeDesc(unsigned T)
840 // Implement isa/cast/dyncast.
841 bool CompositeTypeDesc::classof(const DebugInfoDesc *D) {
842 unsigned T = D->getTag();
844 case DW_TAG_array_type:
845 case DW_TAG_structure_type:
846 case DW_TAG_union_type:
847 case DW_TAG_enumeration_type:
848 case DW_TAG_vector_type:
849 case DW_TAG_subroutine_type:
856 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
858 void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) {
859 DerivedTypeDesc::ApplyToFields(Visitor);
861 Visitor->Apply(Elements);
864 /// getDescString - Return a string used to compose global names and labels.
866 const char *CompositeTypeDesc::getDescString() const {
867 return "llvm.dbg.compositetype";
870 /// getTypeString - Return a string used to label this descriptor's type.
872 const char *CompositeTypeDesc::getTypeString() const {
873 return "llvm.dbg.compositetype.type";
877 void CompositeTypeDesc::dump() {
878 std::cerr << getDescString() << " "
879 << "Version(" << getVersion() << "), "
880 << "Tag(" << getTag() << "), "
881 << "Context(" << getContext() << "), "
882 << "Name(\"" << getName() << "\"), "
883 << "Size(" << getSize() << "), "
884 << "File(" << getFile() << "), "
885 << "Line(" << getLine() << "), "
886 << "FromType(" << getFromType() << "), "
887 << "Elements.size(" << Elements.size() << ")\n";
891 //===----------------------------------------------------------------------===//
893 SubrangeDesc::SubrangeDesc()
894 : DebugInfoDesc(DW_TAG_subrange_type)
899 // Implement isa/cast/dyncast.
900 bool SubrangeDesc::classof(const DebugInfoDesc *D) {
901 return D->getTag() == DW_TAG_subrange_type;
904 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
906 void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) {
907 DebugInfoDesc::ApplyToFields(Visitor);
913 /// getDescString - Return a string used to compose global names and labels.
915 const char *SubrangeDesc::getDescString() const {
916 return "llvm.dbg.subrange";
919 /// getTypeString - Return a string used to label this descriptor's type.
921 const char *SubrangeDesc::getTypeString() const {
922 return "llvm.dbg.subrange.type";
926 void SubrangeDesc::dump() {
927 std::cerr << getDescString() << " "
928 << "Version(" << getVersion() << "), "
929 << "Tag(" << getTag() << "), "
930 << "Lo(" << Lo << "), "
931 << "Hi(" << Hi << ")\n";
935 //===----------------------------------------------------------------------===//
937 EnumeratorDesc::EnumeratorDesc()
938 : DebugInfoDesc(DW_TAG_enumerator)
943 // Implement isa/cast/dyncast.
944 bool EnumeratorDesc::classof(const DebugInfoDesc *D) {
945 return D->getTag() == DW_TAG_enumerator;
948 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
950 void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) {
951 DebugInfoDesc::ApplyToFields(Visitor);
953 Visitor->Apply(Name);
954 Visitor->Apply(Value);
957 /// getDescString - Return a string used to compose global names and labels.
959 const char *EnumeratorDesc::getDescString() const {
960 return "llvm.dbg.enumerator";
963 /// getTypeString - Return a string used to label this descriptor's type.
965 const char *EnumeratorDesc::getTypeString() const {
966 return "llvm.dbg.enumerator.type";
970 void EnumeratorDesc::dump() {
971 std::cerr << getDescString() << " "
972 << "Version(" << getVersion() << "), "
973 << "Tag(" << getTag() << "), "
974 << "Name(" << Name << "), "
975 << "Value(" << Value << ")\n";
979 //===----------------------------------------------------------------------===//
981 VariableDesc::VariableDesc(unsigned T)
990 // Implement isa/cast/dyncast.
991 bool VariableDesc::classof(const DebugInfoDesc *D) {
992 unsigned T = D->getTag();
994 case DW_TAG_auto_variable:
995 case DW_TAG_arg_variable:
996 case DW_TAG_return_variable:
1003 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
1005 void VariableDesc::ApplyToFields(DIVisitor *Visitor) {
1006 DebugInfoDesc::ApplyToFields(Visitor);
1008 Visitor->Apply(Context);
1009 Visitor->Apply(Name);
1010 Visitor->Apply(File);
1011 Visitor->Apply(Line);
1012 Visitor->Apply(TyDesc);
1015 /// getDescString - Return a string used to compose global names and labels.
1017 const char *VariableDesc::getDescString() const {
1018 return "llvm.dbg.variable";
1021 /// getTypeString - Return a string used to label this descriptor's type.
1023 const char *VariableDesc::getTypeString() const {
1024 return "llvm.dbg.variable.type";
1028 void VariableDesc::dump() {
1029 std::cerr << getDescString() << " "
1030 << "Version(" << getVersion() << "), "
1031 << "Tag(" << getTag() << "), "
1032 << "Context(" << Context << "), "
1033 << "Name(\"" << Name << "\"), "
1034 << "File(" << File << "), "
1035 << "Line(" << Line << "), "
1036 << "TyDesc(" << TyDesc << ")\n";
1040 //===----------------------------------------------------------------------===//
1042 GlobalDesc::GlobalDesc(unsigned T)
1051 , IsDefinition(false)
1054 /// ApplyToFields - Target the visitor to the fields of the global.
1056 void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
1057 AnchoredDesc::ApplyToFields(Visitor);
1059 Visitor->Apply(Context);
1060 Visitor->Apply(Name);
1061 if (getVersion() > LLVMDebugVersion4) Visitor->Apply(DisplayName);
1062 Visitor->Apply(File);
1063 Visitor->Apply(Line);
1064 Visitor->Apply(TyDesc);
1065 Visitor->Apply(IsStatic);
1066 Visitor->Apply(IsDefinition);
1069 //===----------------------------------------------------------------------===//
1071 GlobalVariableDesc::GlobalVariableDesc()
1072 : GlobalDesc(DW_TAG_variable)
1076 // Implement isa/cast/dyncast.
1077 bool GlobalVariableDesc::classof(const DebugInfoDesc *D) {
1078 return D->getTag() == DW_TAG_variable;
1081 /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc.
1083 void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
1084 GlobalDesc::ApplyToFields(Visitor);
1086 Visitor->Apply(Global);
1089 /// getDescString - Return a string used to compose global names and labels.
1091 const char *GlobalVariableDesc::getDescString() const {
1092 return "llvm.dbg.global_variable";
1095 /// getTypeString - Return a string used to label this descriptors type.
1097 const char *GlobalVariableDesc::getTypeString() const {
1098 return "llvm.dbg.global_variable.type";
1101 /// getAnchorString - Return a string used to label this descriptor's anchor.
1103 const char *GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables";
1104 const char *GlobalVariableDesc::getAnchorString() const {
1105 return AnchorString;
1109 void GlobalVariableDesc::dump() {
1110 std::cerr << getDescString() << " "
1111 << "Version(" << getVersion() << "), "
1112 << "Tag(" << getTag() << "), "
1113 << "Anchor(" << getAnchor() << "), "
1114 << "Name(\"" << getName() << "\"), "
1115 << "DisplayName(\"" << getDisplayName() << "\"), "
1116 << "File(" << getFile() << "),"
1117 << "Line(" << getLine() << "),"
1118 << "Type(" << getType() << "), "
1119 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1120 << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
1121 << "Global(" << Global << ")\n";
1125 //===----------------------------------------------------------------------===//
1127 SubprogramDesc::SubprogramDesc()
1128 : GlobalDesc(DW_TAG_subprogram)
1131 // Implement isa/cast/dyncast.
1132 bool SubprogramDesc::classof(const DebugInfoDesc *D) {
1133 return D->getTag() == DW_TAG_subprogram;
1136 /// ApplyToFields - Target the visitor to the fields of the
1138 void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
1139 GlobalDesc::ApplyToFields(Visitor);
1142 /// getDescString - Return a string used to compose global names and labels.
1144 const char *SubprogramDesc::getDescString() const {
1145 return "llvm.dbg.subprogram";
1148 /// getTypeString - Return a string used to label this descriptors type.
1150 const char *SubprogramDesc::getTypeString() const {
1151 return "llvm.dbg.subprogram.type";
1154 /// getAnchorString - Return a string used to label this descriptor's anchor.
1156 const char *SubprogramDesc::AnchorString = "llvm.dbg.subprograms";
1157 const char *SubprogramDesc::getAnchorString() const {
1158 return AnchorString;
1162 void SubprogramDesc::dump() {
1163 std::cerr << getDescString() << " "
1164 << "Version(" << getVersion() << "), "
1165 << "Tag(" << getTag() << "), "
1166 << "Anchor(" << getAnchor() << "), "
1167 << "Name(\"" << getName() << "\"), "
1168 << "DisplayName(\"" << getDisplayName() << "\"), "
1169 << "File(" << getFile() << "),"
1170 << "Line(" << getLine() << "),"
1171 << "Type(" << getType() << "), "
1172 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1173 << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
1177 //===----------------------------------------------------------------------===//
1179 BlockDesc::BlockDesc()
1180 : DebugInfoDesc(DW_TAG_lexical_block)
1184 // Implement isa/cast/dyncast.
1185 bool BlockDesc::classof(const DebugInfoDesc *D) {
1186 return D->getTag() == DW_TAG_lexical_block;
1189 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
1191 void BlockDesc::ApplyToFields(DIVisitor *Visitor) {
1192 DebugInfoDesc::ApplyToFields(Visitor);
1194 Visitor->Apply(Context);
1197 /// getDescString - Return a string used to compose global names and labels.
1199 const char *BlockDesc::getDescString() const {
1200 return "llvm.dbg.block";
1203 /// getTypeString - Return a string used to label this descriptors type.
1205 const char *BlockDesc::getTypeString() const {
1206 return "llvm.dbg.block.type";
1210 void BlockDesc::dump() {
1211 std::cerr << getDescString() << " "
1212 << "Version(" << getVersion() << "), "
1213 << "Tag(" << getTag() << "),"
1214 << "Context(" << Context << ")\n";
1218 //===----------------------------------------------------------------------===//
1220 DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
1221 return Deserialize(getGlobalVariable(V));
1223 DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
1225 if (!GV) return NULL;
1227 // Check to see if it has been already deserialized.
1228 DebugInfoDesc *&Slot = GlobalDescs[GV];
1229 if (Slot) return Slot;
1231 // Get the Tag from the global.
1232 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1234 // Create an empty instance of the correct sort.
1235 Slot = DebugInfoDesc::DescFactory(Tag);
1237 // If not a user defined descriptor.
1239 // Deserialize the fields.
1240 DIDeserializeVisitor DRAM(*this, GV);
1241 DRAM.ApplyToFields(Slot);
1247 //===----------------------------------------------------------------------===//
1249 /// getStrPtrType - Return a "sbyte *" type.
1251 const PointerType *DISerializer::getStrPtrType() {
1252 // If not already defined.
1254 // Construct the pointer to signed bytes.
1255 StrPtrTy = PointerType::get(Type::SByteTy);
1261 /// getEmptyStructPtrType - Return a "{ }*" type.
1263 const PointerType *DISerializer::getEmptyStructPtrType() {
1264 // If not already defined.
1265 if (!EmptyStructPtrTy) {
1266 // Construct the empty structure type.
1267 const StructType *EmptyStructTy =
1268 StructType::get(std::vector<const Type*>());
1269 // Construct the pointer to empty structure type.
1270 EmptyStructPtrTy = PointerType::get(EmptyStructTy);
1273 return EmptyStructPtrTy;
1276 /// getTagType - Return the type describing the specified descriptor (via tag.)
1278 const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
1279 // Attempt to get the previously defined type.
1280 StructType *&Ty = TagTypes[DD->getTag()];
1282 // If not already defined.
1284 // Set up fields vector.
1285 std::vector<const Type*> Fields;
1286 // Get types of fields.
1287 DIGetTypesVisitor GTAM(*this, Fields);
1288 GTAM.ApplyToFields(DD);
1290 // Construct structured type.
1291 Ty = StructType::get(Fields);
1293 // Register type name with module.
1294 M->addTypeName(DD->getTypeString(), Ty);
1300 /// getString - Construct the string as constant string global.
1302 Constant *DISerializer::getString(const std::string &String) {
1303 // Check string cache for previous edition.
1304 Constant *&Slot = StringCache[String];
1305 // Return Constant if previously defined.
1306 if (Slot) return Slot;
1307 // If empty string then use a sbyte* null instead.
1308 if (String.empty()) {
1309 Slot = ConstantPointerNull::get(getStrPtrType());
1311 // Construct string as an llvm constant.
1312 Constant *ConstStr = ConstantArray::get(String);
1313 // Otherwise create and return a new string global.
1314 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
1315 GlobalVariable::InternalLinkage,
1316 ConstStr, "str", M);
1317 StrGV->setSection("llvm.metadata");
1318 // Convert to generic string pointer.
1319 Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
1325 /// Serialize - Recursively cast the specified descriptor into a GlobalVariable
1326 /// so that it can be serialized to a .bc or .ll file.
1327 GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
1328 // Check if the DebugInfoDesc is already in the map.
1329 GlobalVariable *&Slot = DescGlobals[DD];
1331 // See if DebugInfoDesc exists, if so return prior GlobalVariable.
1332 if (Slot) return Slot;
1334 // Get the type associated with the Tag.
1335 const StructType *Ty = getTagType(DD);
1337 // Create the GlobalVariable early to prevent infinite recursion.
1338 GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(),
1339 NULL, DD->getDescString(), M);
1340 GV->setSection("llvm.metadata");
1342 // Insert new GlobalVariable in DescGlobals map.
1345 // Set up elements vector
1346 std::vector<Constant*> Elements;
1348 DISerializeVisitor SRAM(*this, Elements);
1349 SRAM.ApplyToFields(DD);
1351 // Set the globals initializer.
1352 GV->setInitializer(ConstantStruct::get(Ty, Elements));
1357 //===----------------------------------------------------------------------===//
1359 /// Verify - Return true if the GlobalVariable appears to be a valid
1360 /// serialization of a DebugInfoDesc.
1361 bool DIVerifier::Verify(Value *V) {
1362 return !V || Verify(getGlobalVariable(V));
1364 bool DIVerifier::Verify(GlobalVariable *GV) {
1366 if (!GV) return true;
1368 // Check prior validity.
1369 unsigned &ValiditySlot = Validity[GV];
1371 // If visited before then use old state.
1372 if (ValiditySlot) return ValiditySlot == Valid;
1374 // Assume validity for the time being (recursion.)
1375 ValiditySlot = Valid;
1377 // Make sure the global is internal or link once (anchor.)
1378 if (GV->getLinkage() != GlobalValue::InternalLinkage &&
1379 GV->getLinkage() != GlobalValue::LinkOnceLinkage) {
1380 ValiditySlot = Invalid;
1385 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1387 // Check for user defined descriptors.
1388 if (Tag == DW_TAG_invalid) return true;
1390 // Construct an empty DebugInfoDesc.
1391 DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag);
1393 // Allow for user defined descriptors.
1394 if (!DD) return true;
1396 // Get the initializer constant.
1397 ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer());
1399 // Get the operand count.
1400 unsigned N = CI->getNumOperands();
1402 // Get the field count.
1403 unsigned &CountSlot = Counts[Tag];
1405 // Check the operand count to the field count
1406 DICountVisitor CTAM;
1407 CTAM.ApplyToFields(DD);
1408 CountSlot = CTAM.getCount();
1411 // Field count must be at most equal operand count.
1412 if (CountSlot > N) {
1414 ValiditySlot = Invalid;
1418 // Check each field for valid type.
1419 DIVerifyVisitor VRAM(*this, GV);
1420 VRAM.ApplyToFields(DD);
1422 // Release empty DebugInfoDesc.
1425 // If fields are not valid.
1426 if (!VRAM.isValid()) {
1427 ValiditySlot = Invalid;
1434 //===----------------------------------------------------------------------===//
1436 DebugScope::~DebugScope() {
1437 for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i];
1438 for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j];
1441 //===----------------------------------------------------------------------===//
1443 MachineDebugInfo::MachineDebugInfo()
1455 MachineDebugInfo::~MachineDebugInfo() {
1459 /// doInitialization - Initialize the debug state for a new module.
1461 bool MachineDebugInfo::doInitialization() {
1465 /// doFinalization - Tear down the debug state after completion of a module.
1467 bool MachineDebugInfo::doFinalization() {
1471 /// BeginFunction - Begin gathering function debug information.
1473 void MachineDebugInfo::BeginFunction(MachineFunction *MF) {
1477 /// MachineDebugInfo::EndFunction - Discard function debug information.
1479 void MachineDebugInfo::EndFunction() {
1480 // Clean up scope information.
1487 // Clean up frame info.
1488 for (unsigned i = 0, N = FrameMoves.size(); i < N; ++i) delete FrameMoves[i];
1492 /// getDescFor - Convert a Value to a debug information descriptor.
1494 // FIXME - use new Value type when available.
1495 DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) {
1496 return DR.Deserialize(V);
1499 /// Verify - Verify that a Value is debug information descriptor.
1501 bool MachineDebugInfo::Verify(Value *V) {
1502 return VR.Verify(V);
1505 /// AnalyzeModule - Scan the module for global debug information.
1507 void MachineDebugInfo::AnalyzeModule(Module &M) {
1508 SetupCompileUnits(M);
1511 /// SetupCompileUnits - Set up the unique vector of compile units.
1513 void MachineDebugInfo::SetupCompileUnits(Module &M) {
1514 std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M);
1516 for (unsigned i = 0, N = CU.size(); i < N; i++) {
1517 CompileUnits.insert(CU[i]);
1521 /// getCompileUnits - Return a vector of debug compile units.
1523 const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{
1524 return CompileUnits;
1527 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1528 /// named GlobalVariable.
1529 std::vector<GlobalVariable*>
1530 MachineDebugInfo::getGlobalVariablesUsing(Module &M,
1531 const std::string &RootName) {
1532 return ::getGlobalVariablesUsing(M, RootName);
1535 /// RecordLabel - Records location information and associates it with a
1536 /// debug label. Returns a unique label ID used to generate a label and
1537 /// provide correspondence to the source line list.
1538 unsigned MachineDebugInfo::RecordLabel(unsigned Line, unsigned Column,
1540 unsigned ID = NextLabelID();
1541 Lines.push_back(SourceLineInfo(Line, Column, Source, ID));
1545 static bool LabelUIDComparison(const SourceLineInfo &LI, unsigned UID) {
1546 return LI.getLabelID() < UID;
1549 /// RemoveLabelInfo - Remove the specified label # from MachineDebugInfo, for
1550 /// example because the code was deleted.
1551 void MachineDebugInfo::RemoveLabelInfo(unsigned LabelUID) {
1552 std::vector<SourceLineInfo>::iterator I =
1553 std::lower_bound(Lines.begin(), Lines.end(), LabelUID, LabelUIDComparison);
1554 assert(I != Lines.end() && "Didn't find label UID in MachineDebugInfo!");
1559 /// RecordSource - Register a source file with debug info. Returns an source
1561 unsigned MachineDebugInfo::RecordSource(const std::string &Directory,
1562 const std::string &Source) {
1563 unsigned DirectoryID = Directories.insert(Directory);
1564 return SourceFiles.insert(SourceFileInfo(DirectoryID, Source));
1566 unsigned MachineDebugInfo::RecordSource(const CompileUnitDesc *CompileUnit) {
1567 return RecordSource(CompileUnit->getDirectory(),
1568 CompileUnit->getFileName());
1571 /// RecordRegionStart - Indicate the start of a region.
1573 unsigned MachineDebugInfo::RecordRegionStart(Value *V) {
1574 // FIXME - need to be able to handle split scopes because of bb cloning.
1575 DebugInfoDesc *ScopeDesc = DR.Deserialize(V);
1576 DebugScope *Scope = getOrCreateScope(ScopeDesc);
1577 unsigned ID = NextLabelID();
1578 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
1582 /// RecordRegionEnd - Indicate the end of a region.
1584 unsigned MachineDebugInfo::RecordRegionEnd(Value *V) {
1585 // FIXME - need to be able to handle split scopes because of bb cloning.
1586 DebugInfoDesc *ScopeDesc = DR.Deserialize(V);
1587 DebugScope *Scope = getOrCreateScope(ScopeDesc);
1588 unsigned ID = NextLabelID();
1589 Scope->setEndLabelID(ID);
1593 /// RecordVariable - Indicate the declaration of a local variable.
1595 void MachineDebugInfo::RecordVariable(Value *V, unsigned FrameIndex) {
1596 VariableDesc *VD = cast<VariableDesc>(DR.Deserialize(V));
1597 DebugScope *Scope = getOrCreateScope(VD->getContext());
1598 DebugVariable *DV = new DebugVariable(VD, FrameIndex);
1599 Scope->AddVariable(DV);
1602 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1604 DebugScope *MachineDebugInfo::getOrCreateScope(DebugInfoDesc *ScopeDesc) {
1605 DebugScope *&Slot = ScopeMap[ScopeDesc];
1607 // FIXME - breaks down when the context is an inlined function.
1608 DebugInfoDesc *ParentDesc = NULL;
1609 if (BlockDesc *Block = dyn_cast<BlockDesc>(ScopeDesc)) {
1610 ParentDesc = Block->getContext();
1612 DebugScope *Parent = ParentDesc ? getOrCreateScope(ParentDesc) : NULL;
1613 Slot = new DebugScope(Parent, ScopeDesc);
1615 Parent->AddScope(Slot);
1616 } else if (RootScope) {
1617 // FIXME - Add inlined function scopes to the root so we can delete
1618 // them later. Long term, handle inlined functions properly.
1619 RootScope->AddScope(Slot);
1621 // First function is top level function.