llvm.org GIT mirror llvm / f5395ce
Added source file/line correspondence for dwarf (PowerPC only at this point.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24748 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Laskey 14 years ago
10 changed file(s) with 160 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
0 //===-- llvm/CodeGen/MachineDebugInfo.h -------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by James M. Laskey and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Collect debug information for a module. This information should be in a
10 // neutral form that can be used by different debugging schemes.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_MACHINEDEBUGINFO_H
15 #define LLVM_CODEGEN_MACHINEDEBUGINFO_H
16
17 #include
18 #include
19 #include
20
21 namespace llvm {
22 //===----------------------------------------------------------------------===//
23 /// MachineDebugInfo - This class contains debug information specific to a
24 /// module. Queries can be made by different debugging schemes and reformated
25 /// for specific use.
26 ///
27 class MachineDebugInfo {
28 private:
29 // convenience types
30 typedef std::map StrIntMap;
31 typedef StrIntMap::iterator StrIntMapIter;
32
33 StrIntMap SourceMap; // Map of source file path to id
34 unsigned SourceCount; // Number of source files (used to
35 // generate id)
36
37 public:
38 // Ctor.
39 MachineDebugInfo() : SourceMap(), SourceCount(0) {}
40
41 /// RecordSource - Register a source file with debug info. Returns an id.
42 ///
43 unsigned RecordSource(std::string fname, std::string dirname) {
44 // Compose a key
45 std::string path = dirname + "/" + fname;
46 // Check if the source file is already recorded
47 StrIntMapIter SMI = SourceMap.find(path);
48 // If already there return existing id
49 if (SMI != SourceMap.end()) return SMI->second;
50 // Bump up the count
51 ++SourceCount;
52 // Record the count
53 SourceMap[path] = SourceCount;
54 // Return id
55 return SourceCount;
56 }
57
58 /// getSourceFiles - Return a vector of files. Vector index + 1 equals id.
59 ///
60 std::vector getSourceFiles() {
61 std::vector Sources(SourceCount);
62
63 for (StrIntMapIter SMI = SourceMap.begin(), E = SourceMap.end(); SMI != E;
64 SMI++) {
65 unsigned Index = SMI->second - 1;
66 std::string Path = SMI->first;
67 Sources[Index] = Path;
68 }
69 return Sources;
70 }
71
72 }; // End class MachineDebugInfo
73 //===----------------------------------------------------------------------===//
74
75
76
77 } // End llvm namespace
78
79 #endif
1717 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
1818 #define LLVM_CODEGEN_MACHINEFUNCTION_H
1919
20 #include "llvm/CodeGen/MachineDebugInfo.h"
2021 #include "llvm/CodeGen/MachineBasicBlock.h"
2122 #include "llvm/Support/Annotation.h"
2223
111112 /// stored in the second element.
112113 std::vector > LiveIns;
113114 std::vector LiveOuts;
115
116 /// DebugInfo - Keep track of debug information for the function.
117 ///
118 MachineDebugInfo DebugInfo;
114119
115120 public:
116121 MachineFunction(const Function *Fn, const TargetMachine &TM);
211216 const MachineBasicBlock *getLastBlock() const {
212217 return MBBNumbering.back();
213218 }
219
220 /// getDebugInfo - Returns the DebugInfo.
221 MachineDebugInfo &getDebugInfo() {
222 return DebugInfo;
223 }
214224
215225 /// print - Print out the MachineFunction in a format suitable for debugging
216226 /// to the specified stream.
350350 // number, then a filename, then a working dir. It produces a token chain
351351 // as output.
352352 LOCATION,
353
354 // DEBUG_LOC - This node is used to represent source line information
355 // embedded in the code. It takes token chain as input, then a line number,
356 // then a column then a file id (provided by MachineDebugInfo. It produces
357 // a token chain as output.
358 DEBUG_LOC,
353359
354360 // BUILTIN_OP_END - This must be the last enum value in this list.
355361 BUILTIN_OP_END,
107107
108108 MachineFunction::MachineFunction(const Function *F,
109109 const TargetMachine &TM)
110 : Annotation(MF_AID), Fn(F), Target(TM), UsedPhysRegs(0) {
110 : Annotation(MF_AID), Fn(F), Target(TM), UsedPhysRegs(0), DebugInfo() {
111111 SSARegMapping = new SSARegMap();
112112 MFInfo = 0;
113113 FrameInfo = new MachineFrameInfo();
610610 switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) {
611611 case TargetLowering::Promote:
612612 default: assert(0 && "This action is not supported yet!");
613 case TargetLowering::Expand:
614 // If the target doesn't support line numbers, ignore this node.
615 Result = Tmp1;
613 case TargetLowering::Expand: {
614 MachineDebugInfo &DebugInfo = DAG.getMachineFunction().getDebugInfo();
615 std::vector Ops;
616 Ops.push_back(Tmp1); // chain
617 Ops.push_back(Node->getOperand(1)); // line #
618 Ops.push_back(Node->getOperand(2)); // col #
619 const std::string &fname = cast(Node->getOperand(3))->getValue();
620 const std::string &dirname=cast(Node->getOperand(4))->getValue();
621 unsigned id = DebugInfo.RecordSource(fname, dirname);
622 Ops.push_back(DAG.getConstant(id, MVT::i32)); // source file id
623 Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, Ops);
624 }
616625 break;
617626 case TargetLowering::Legal:
618627 if (Tmp1 != Node->getOperand(0) ||
634643 break;
635644 }
636645 break;
646
647 case ISD::DEBUG_LOC:
648 assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!");
649 switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) {
650 case TargetLowering::Promote:
651 case TargetLowering::Expand:
652 default: assert(0 && "This action is not supported yet!");
653 case TargetLowering::Legal:
654 Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
655 Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #.
656 Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #.
657 Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id.
658
659 if (Tmp1 != Node->getOperand(0) ||
660 Tmp2 != Node->getOperand(1) ||
661 Tmp3 != Node->getOperand(2) ||
662 Tmp4 != Node->getOperand(3)) {
663 Result = DAG.getNode(ISD::DEBUG_LOC,MVT::Other, Tmp1, Tmp2, Tmp3, Tmp4);
664 }
665 break;
666 }
667 break;
637668
638669 case ISD::Constant:
639670 // We know we don't need to expand constants here, constants only have one
19601960
19611961 // Debug info
19621962 case ISD::LOCATION: return "location";
1963 case ISD::DEBUG_LOC: return "debug_loc";
19631964
19641965 case ISD::CONDCODE:
19651966 switch (cast(this)->get()) {
917917 if (ConstantStruct *CS =
918918 dyn_cast(cunit->getInitializer())) {
919919 if (CS->getNumOperands() > 0) {
920 Ops.push_back(DAG.getString(getStringValue(CS->getOperand(3))));
920921 Ops.push_back(DAG.getString(getStringValue(CS->getOperand(4))));
921 Ops.push_back(DAG.getString(getStringValue(CS->getOperand(3))));
922922 }
923923 }
924924 }
2424 #include "llvm/Module.h"
2525 #include "llvm/Assembly/Writer.h"
2626 #include "llvm/CodeGen/AsmPrinter.h"
27 #include "llvm/CodeGen/MachineDebugInfo.h"
2728 #include "llvm/CodeGen/MachineFunctionPass.h"
2829 #include "llvm/CodeGen/MachineInstr.h"
2930 #include "llvm/Support/Mangler.h"
374375 bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
375376 SetupMachineFunction(MF);
376377 O << "\n\n";
378
379 // Print out dwarf file info
380 MachineDebugInfo &DebugInfo = MF.getDebugInfo();
381 std::vector Sources = DebugInfo.getSourceFiles();
382 for (unsigned i = 0, N = Sources.size(); i < N; i++) {
383 O << "\t; .file\t" << (i + 1) << "," << "\"" << Sources[i] << "\"" << "\n";
384 }
377385
378386 // Print out constants referenced by the function
379387 EmitConstantPool(MF.getConstantPool());
921921
922922
923923 //===----------------------------------------------------------------------===//
924 // DWARF Pseudo Instructions
925 //
926
927 def DWARF_LOC : Pseudo<(ops i32imm:$line, i32imm:$col, i32imm:$file),
928 "; .loc $file, $line, $col",
929 [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
930 (i32 imm:$file))]>;
931
932 //===----------------------------------------------------------------------===//
924933 // PowerPC Instruction Patterns
925934 //
926935
414414 string SelectFunc = fn;
415415 list RootNodes = roots;
416416 }
417
418 //===----------------------------------------------------------------------===//
419 // Dwarf support.
420 //
421 def SDT_dwarf_loc : SDTypeProfile<0, 3,
422 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
423 def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;
424
425
426