From d0adbb5b7da2d1238fdf1a30734a001a0103aab0 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 26 Jan 2009 07:41:49 +0000 Subject: Add data structure to define and track debug location during codegen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63008 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineFunction.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 8bae7bbb92..0d442af7ed 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -378,6 +378,33 @@ MachineFunction& MachineFunction::get(const Function *F) return *mc; } +/// lookUpDebugLocId - Look up the DebugLocTuple index with the given +/// filename, line, and column. It may add a new filename and / or +/// a new DebugLocTuple. +unsigned MachineFunction::lookUpDebugLocId(const char *Filename, unsigned Line, + unsigned Col) { + unsigned FileId; + StringMap::iterator I = + DebugLocInfo.DebugFilenamesMap.find(Filename); + if (I != DebugLocInfo.DebugFilenamesMap.end()) + FileId = I->second; + else { + // Add a new filename. + FileId = DebugLocInfo.NumFilenames++; + DebugLocInfo.DebugFilenames.push_back(Filename); + DebugLocInfo.DebugFilenamesMap[Filename] = FileId; + } + + struct DebugLocTuple Tuple(FileId, Line, Col); + DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple); + if (II != DebugLocInfo.DebugIdMap.end()) + return II->second; + // Add a new tuple. + DebugLocInfo.DebugLocations.push_back(Tuple); + DebugLocInfo.DebugIdMap[Tuple] = DebugLocInfo.NumDebugLocations; + return DebugLocInfo.NumDebugLocations++; +} + //===----------------------------------------------------------------------===// // MachineFrameInfo implementation //===----------------------------------------------------------------------===// -- cgit v1.2.3-70-g09d2 From c4b1abd81e4de314880110c5d58917d4747fb978 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 26 Jan 2009 07:53:42 +0000 Subject: Actually source file has already been uniquified into an id during isel. Eliminate the StringMap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63009 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/DebugLoc.h | 30 +++++++----------------------- include/llvm/CodeGen/MachineFunction.h | 4 ++-- lib/CodeGen/MachineFunction.cpp | 18 +++--------------- 3 files changed, 12 insertions(+), 40 deletions(-) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/include/llvm/CodeGen/DebugLoc.h b/include/llvm/CodeGen/DebugLoc.h index ad68839b05..b6097afe30 100644 --- a/include/llvm/CodeGen/DebugLoc.h +++ b/include/llvm/CodeGen/DebugLoc.h @@ -14,7 +14,6 @@ #define LLVM_CODEGEN_DEBUGLOC_H #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/StringMap.h" #include namespace llvm { @@ -22,10 +21,10 @@ namespace llvm { /// DebugLocTuple - Debug location tuple of filename id, line and column. /// struct DebugLocTuple { - unsigned FileId, Line, Col; + unsigned Src, Line, Col; - DebugLocTuple(unsigned fi, unsigned l, unsigned c) - : FileId(fi), Line(l), Col(c) {}; + DebugLocTuple(unsigned s, unsigned l, unsigned c) + : Src(s), Line(l), Col(c) {}; }; /// DebugLoc - Debug location id. This is carried by SDNode and @@ -51,14 +50,14 @@ namespace llvm { return DebugLocTuple(~1U, ~1U, ~1U); } static unsigned getHashValue(const DebugLocTuple &Val) { - return DenseMapInfo::getHashValue(Val.FileId) ^ + return DenseMapInfo::getHashValue(Val.Src) ^ DenseMapInfo::getHashValue(Val.Line) ^ DenseMapInfo::getHashValue(Val.Col); } static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) { - return LHS.FileId == RHS.FileId && + return LHS.Src == RHS.Src && LHS.Line == RHS.Line && - LHS.Col == RHS.Col; + LHS.Col == RHS.Col; } static bool isPod() { return true; } @@ -70,18 +69,6 @@ namespace llvm { /// DebugLocTracker - This class tracks debug location information. /// struct DebugLocTracker { - // NumFilenames - Size of the DebugFilenames vector. - // - unsigned NumFilenames; - - // DebugFilenames - A vector of unique file names. - // - std::vector DebugFilenames; - - // DebugFilenamesMap - File name to DebugFilenames index map. - // - StringMap DebugFilenamesMap; - // NumDebugLocations - Size of the DebugLocations vector. unsigned NumDebugLocations; @@ -93,12 +80,9 @@ namespace llvm { // DebugLocations vector. DebugIdMapType DebugIdMap; - DebugLocTracker() : NumFilenames(0), NumDebugLocations(0) {} + DebugLocTracker() : NumDebugLocations(0) {} ~DebugLocTracker() { - NumFilenames = 0; - DebugFilenames.clear(); - DebugFilenamesMap.clear(); DebugLocations.clear(); DebugIdMap.clear(); } diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index 1397b84677..4fa70fca6f 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -312,9 +312,9 @@ public: // /// lookUpDebugLocId - Look up the DebugLocTuple index with the given - /// filename, line, and column. It may add a new filename and / or + /// source file, line, and column. It may add a new filename and / or /// a new DebugLocTuple. - unsigned lookUpDebugLocId(const char *Filename, unsigned Line, unsigned Col); + unsigned lookUpDebugLocId(unsigned Src, unsigned Line, unsigned Col); }; //===--------------------------------------------------------------------===// diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 0d442af7ed..c1ab9afe9f 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -379,23 +379,11 @@ MachineFunction& MachineFunction::get(const Function *F) } /// lookUpDebugLocId - Look up the DebugLocTuple index with the given -/// filename, line, and column. It may add a new filename and / or +/// source file, line, and column. It may add a new filename and / or /// a new DebugLocTuple. -unsigned MachineFunction::lookUpDebugLocId(const char *Filename, unsigned Line, +unsigned MachineFunction::lookUpDebugLocId(unsigned Src, unsigned Line, unsigned Col) { - unsigned FileId; - StringMap::iterator I = - DebugLocInfo.DebugFilenamesMap.find(Filename); - if (I != DebugLocInfo.DebugFilenamesMap.end()) - FileId = I->second; - else { - // Add a new filename. - FileId = DebugLocInfo.NumFilenames++; - DebugLocInfo.DebugFilenames.push_back(Filename); - DebugLocInfo.DebugFilenamesMap[Filename] = FileId; - } - - struct DebugLocTuple Tuple(FileId, Line, Col); + struct DebugLocTuple Tuple(Src, Line, Col); DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple); if (II != DebugLocInfo.DebugIdMap.end()) return II->second; -- cgit v1.2.3-70-g09d2 From b9f66cfadf6b1551192ee4a6e9b70f564c5ed8be Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 26 Jan 2009 23:47:30 +0000 Subject: No need to keep size of DebugLocations vector separately. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63070 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/DebugLoc.h | 5 +---- lib/CodeGen/MachineFunction.cpp | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/include/llvm/CodeGen/DebugLoc.h b/include/llvm/CodeGen/DebugLoc.h index b6097afe30..baf6583a8b 100644 --- a/include/llvm/CodeGen/DebugLoc.h +++ b/include/llvm/CodeGen/DebugLoc.h @@ -69,9 +69,6 @@ namespace llvm { /// DebugLocTracker - This class tracks debug location information. /// struct DebugLocTracker { - // NumDebugLocations - Size of the DebugLocations vector. - unsigned NumDebugLocations; - // DebugLocations - A vector of unique DebugLocTuple's. // std::vector DebugLocations; @@ -80,7 +77,7 @@ namespace llvm { // DebugLocations vector. DebugIdMapType DebugIdMap; - DebugLocTracker() : NumDebugLocations(0) {} + DebugLocTracker() {} ~DebugLocTracker() { DebugLocations.clear(); diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index c1ab9afe9f..abd84ecbd5 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -388,9 +388,10 @@ unsigned MachineFunction::lookUpDebugLocId(unsigned Src, unsigned Line, if (II != DebugLocInfo.DebugIdMap.end()) return II->second; // Add a new tuple. + unsigned Id = DebugLocInfo.DebugLocations.size(); DebugLocInfo.DebugLocations.push_back(Tuple); - DebugLocInfo.DebugIdMap[Tuple] = DebugLocInfo.NumDebugLocations; - return DebugLocInfo.NumDebugLocations++; + DebugLocInfo.DebugIdMap[Tuple] = Id; + return Id; } //===----------------------------------------------------------------------===// -- cgit v1.2.3-70-g09d2 From aaeea9e64f7c0f45380d323a32501c4da59a2c4d Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 27 Jan 2009 21:15:07 +0000 Subject: Refine DebugLoc per review comments. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63132 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/DebugLoc.h | 20 +++++++++++--------- include/llvm/CodeGen/MachineFunction.h | 8 ++++---- lib/CodeGen/MachineFunction.cpp | 13 +++++++------ 3 files changed, 22 insertions(+), 19 deletions(-) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/include/llvm/CodeGen/DebugLoc.h b/include/llvm/CodeGen/DebugLoc.h index baf6583a8b..89c51c443b 100644 --- a/include/llvm/CodeGen/DebugLoc.h +++ b/include/llvm/CodeGen/DebugLoc.h @@ -33,16 +33,21 @@ namespace llvm { unsigned Idx; public: - DebugLoc() : Idx(~0U) {} + DebugLoc() : Idx(~0U) {} // Defaults to invalid. - static DebugLoc getNoDebugLoc() { DebugLoc L; L.Idx = 0; return L; } + static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = 0; return L; } static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; } - bool isInvalid() { return Idx == ~0U; } - bool isUnknown() { return Idx == 0; } + // isInvalid - Return true if the DebugLoc is invalid. + bool isInvalid() const { return Idx == ~0U; } + + // isUnknown - Return true if there is no debug info for the SDNode / + // MachineInstr. + bool isUnknown() const { return Idx == 0; } }; - struct DebugLocTupleDenseMapInfo { + // Partially specialize DenseMapInfo for DebugLocTyple. + template<> struct DenseMapInfo { static inline DebugLocTuple getEmptyKey() { return DebugLocTuple(~0U, ~0U, ~0U); } @@ -63,9 +68,6 @@ namespace llvm { static bool isPod() { return true; } }; - typedef DenseMap - DebugIdMapType; - /// DebugLocTracker - This class tracks debug location information. /// struct DebugLocTracker { @@ -75,7 +77,7 @@ namespace llvm { // DebugIdsMap - This maps DebugLocTuple's to indices into // DebugLocations vector. - DebugIdMapType DebugIdMap; + DenseMap DebugIdMap; DebugLocTracker() {} diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index 4fa70fca6f..0d5a71d142 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -311,10 +311,10 @@ public: // Debug location. // - /// lookUpDebugLocId - Look up the DebugLocTuple index with the given - /// source file, line, and column. It may add a new filename and / or - /// a new DebugLocTuple. - unsigned lookUpDebugLocId(unsigned Src, unsigned Line, unsigned Col); + /// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given + /// source file, line, and column. If none currently exists, create add a new + /// new DebugLocTuple and insert it into the DebugIdMap. + unsigned getOrCreateDebugLocID(unsigned Src, unsigned Line, unsigned Col); }; //===--------------------------------------------------------------------===// diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index abd84ecbd5..b303b1b58c 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -378,13 +378,14 @@ MachineFunction& MachineFunction::get(const Function *F) return *mc; } -/// lookUpDebugLocId - Look up the DebugLocTuple index with the given -/// source file, line, and column. It may add a new filename and / or -/// a new DebugLocTuple. -unsigned MachineFunction::lookUpDebugLocId(unsigned Src, unsigned Line, - unsigned Col) { +/// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given +/// source file, line, and column. If none currently exists, create add a new +/// new DebugLocTuple and insert it into the DebugIdMap. +unsigned MachineFunction::getOrCreateDebugLocID(unsigned Src, unsigned Line, + unsigned Col) { struct DebugLocTuple Tuple(Src, Line, Col); - DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple); + DenseMap::iterator II + = DebugLocInfo.DebugIdMap.find(Tuple); if (II != DebugLocInfo.DebugIdMap.end()) return II->second; // Add a new tuple. -- cgit v1.2.3-70-g09d2 From 9bc96a57206cbebaa9b0ba9979f949eb10c1592c Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 3 Feb 2009 00:55:04 +0000 Subject: Create DebugLoc information in FastISel. Several temporary methods were created. Specifically, those BuildMIs which use "DebugLoc::getUnknownLoc()". I'll remove them soon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63584 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/FastISel.h | 16 ++++--- include/llvm/CodeGen/MachineFunction.h | 1 + include/llvm/CodeGen/MachineInstrBuilder.h | 59 +++++++++++++++++++++++--- lib/CodeGen/MachineFunction.cpp | 5 ++- lib/CodeGen/SelectionDAG/FastISel.cpp | 57 ++++++++++++++----------- lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 6 ++- lib/Target/ARM/ARMInstrInfo.cpp | 2 +- lib/Target/X86/X86InstrInfo.cpp | 11 +++-- 8 files changed, 111 insertions(+), 46 deletions(-) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/include/llvm/CodeGen/FastISel.h b/include/llvm/CodeGen/FastISel.h index 8c04848069..1c26b3fd76 100644 --- a/include/llvm/CodeGen/FastISel.h +++ b/include/llvm/CodeGen/FastISel.h @@ -16,6 +16,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/CodeGen/DebugLoc.h" #include "llvm/CodeGen/SelectionDAGNodes.h" namespace llvm { @@ -55,28 +56,33 @@ protected: MachineRegisterInfo &MRI; MachineFrameInfo &MFI; MachineConstantPool &MCP; + DebugLoc DL; const TargetMachine &TM; const TargetData &TD; const TargetInstrInfo &TII; const TargetLowering &TLI; public: - /// startNewBlock - Set the current block, to which generated - /// machine instructions will be appended, and clear the local - /// CSE map. + /// startNewBlock - Set the current block to which generated machine + /// instructions will be appended, and clear the local CSE map. /// void startNewBlock(MachineBasicBlock *mbb) { setCurrentBlock(mbb); LocalValueMap.clear(); } - /// setCurrentBlock - Set the current block, to which generated - /// machine instructions will be appended. + /// setCurrentBlock - Set the current block to which generated machine + /// instructions will be appended. /// void setCurrentBlock(MachineBasicBlock *mbb) { MBB = mbb; } + /// setCurDebugLoc - Set the current debug location information, which is used + /// when creating a machine instruction. + /// + void setCurDebugLoc(DebugLoc dl) { DL = dl; } + /// SelectInstruction - Do "fast" instruction selection for the given /// LLVM IR instruction, and append generated machine instructions to /// the current block. Return true if selection was successful. diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index 0d5a71d142..6abedb50b3 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -286,6 +286,7 @@ public: /// of `new MachineInstr'. /// MachineInstr *CreateMachineInstr(const TargetInstrDesc &TID, + DebugLoc DL, bool NoImp = false); /// CloneMachineInstr - Create a new MachineInstr which is a copy of the diff --git a/include/llvm/CodeGen/MachineInstrBuilder.h b/include/llvm/CodeGen/MachineInstrBuilder.h index d097362a55..54fbe27eec 100644 --- a/include/llvm/CodeGen/MachineInstrBuilder.h +++ b/include/llvm/CodeGen/MachineInstrBuilder.h @@ -100,16 +100,31 @@ public: /// inline MachineInstrBuilder BuildMI(MachineFunction &MF, const TargetInstrDesc &TID) { - return MachineInstrBuilder(MF.CreateMachineInstr(TID)); + return MachineInstrBuilder(MF.CreateMachineInstr(TID, + DebugLoc::getUnknownLoc())); +} +inline MachineInstrBuilder BuildMI(MachineFunction &MF, + DebugLoc DL, + const TargetInstrDesc &TID) { + return MachineInstrBuilder(MF.CreateMachineInstr(TID, DL)); } /// BuildMI - This version of the builder sets up the first operand as a /// destination virtual register. /// -inline MachineInstrBuilder BuildMI(MachineFunction &MF, - const TargetInstrDesc &TID, - unsigned DestReg) { - return MachineInstrBuilder(MF.CreateMachineInstr(TID)).addReg(DestReg, true); +inline MachineInstrBuilder BuildMI(MachineFunction &MF, + const TargetInstrDesc &TID, + unsigned DestReg) { + return MachineInstrBuilder(MF.CreateMachineInstr(TID, + DebugLoc::getUnknownLoc())) + .addReg(DestReg, true); +} +inline MachineInstrBuilder BuildMI(MachineFunction &MF, + DebugLoc DL, + const TargetInstrDesc &TID, + unsigned DestReg) { + return MachineInstrBuilder(MF.CreateMachineInstr(TID, DL)) + .addReg(DestReg, true); } /// BuildMI - This version of the builder inserts the newly-built @@ -120,7 +135,17 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineBasicBlock::iterator I, const TargetInstrDesc &TID, unsigned DestReg) { - MachineInstr *MI = BB.getParent()->CreateMachineInstr(TID); + MachineInstr *MI = + BB.getParent()->CreateMachineInstr(TID, DebugLoc::getUnknownLoc()); + BB.insert(I, MI); + return MachineInstrBuilder(MI).addReg(DestReg, true); +} +inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, + MachineBasicBlock::iterator I, + DebugLoc DL, + const TargetInstrDesc &TID, + unsigned DestReg) { + MachineInstr *MI = BB.getParent()->CreateMachineInstr(TID, DL); BB.insert(I, MI); return MachineInstrBuilder(MI).addReg(DestReg, true); } @@ -132,7 +157,16 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineBasicBlock::iterator I, const TargetInstrDesc &TID) { - MachineInstr *MI = BB.getParent()->CreateMachineInstr(TID); + MachineInstr *MI = + BB.getParent()->CreateMachineInstr(TID, DebugLoc::getUnknownLoc()); + BB.insert(I, MI); + return MachineInstrBuilder(MI); +} +inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, + MachineBasicBlock::iterator I, + DebugLoc DL, + const TargetInstrDesc &TID) { + MachineInstr *MI = BB.getParent()->CreateMachineInstr(TID, DL); BB.insert(I, MI); return MachineInstrBuilder(MI); } @@ -145,6 +179,11 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, const TargetInstrDesc &TID) { return BuildMI(*BB, BB->end(), TID); } +inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, + DebugLoc DL, + const TargetInstrDesc &TID) { + return BuildMI(*BB, BB->end(), DL, TID); +} /// BuildMI - This version of the builder inserts the newly-built /// instruction at the end of the given MachineBasicBlock, and sets up the first @@ -155,6 +194,12 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, unsigned DestReg) { return BuildMI(*BB, BB->end(), TID, DestReg); } +inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, + DebugLoc DL, + const TargetInstrDesc &TID, + unsigned DestReg) { + return BuildMI(*BB, BB->end(), DL, TID, DestReg); +} } // End llvm namespace diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index b303b1b58c..434034b888 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -192,9 +192,10 @@ void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) { /// of `new MachineInstr'. /// MachineInstr * -MachineFunction::CreateMachineInstr(const TargetInstrDesc &TID, bool NoImp) { +MachineFunction::CreateMachineInstr(const TargetInstrDesc &TID, + DebugLoc DL, bool NoImp) { return new (InstructionRecycler.Allocate(Allocator)) - MachineInstr(TID, NoImp); + MachineInstr(TID, DL, NoImp); } /// CloneMachineInstr - Create a new MachineInstr which is a copy of the diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index 18cbfe4404..04e97212dd 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -114,7 +114,7 @@ unsigned FastISel::getRegForValue(Value *V) { Reg = LocalValueMap[CE]; } else if (isa(V)) { Reg = createResultReg(TLI.getRegClassFor(VT)); - BuildMI(MBB, TII.get(TargetInstrInfo::IMPLICIT_DEF), Reg); + BuildMI(MBB, DL, TII.get(TargetInstrInfo::IMPLICIT_DEF), Reg); } // If target-independent code couldn't handle the value, give target-specific @@ -324,8 +324,10 @@ bool FastISel::SelectCall(User *I) { unsigned Line = SPI->getLine(); unsigned Col = SPI->getColumn(); unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); + unsigned Idx = MF.getOrCreateDebugLocID(SrcFile, Line, Col); + setCurDebugLoc(DebugLoc::get(Idx)); const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); - BuildMI(MBB, II).addImm(ID); + BuildMI(MBB, DL, II).addImm(ID); } return true; } @@ -335,7 +337,7 @@ bool FastISel::SelectCall(User *I) { unsigned ID = DW->RecordRegionStart(cast(RSI->getContext())); const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); - BuildMI(MBB, II).addImm(ID); + BuildMI(MBB, DL, II).addImm(ID); } return true; } @@ -345,7 +347,7 @@ bool FastISel::SelectCall(User *I) { unsigned ID = DW->RecordRegionEnd(cast(REI->getContext())); const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); - BuildMI(MBB, II).addImm(ID); + BuildMI(MBB, DL, II).addImm(ID); } return true; } @@ -353,23 +355,28 @@ bool FastISel::SelectCall(User *I) { if (!DW) return true; DbgFuncStartInst *FSI = cast(I); Value *SP = FSI->getSubprogram(); + if (DW->ValidDebugInfo(SP)) { - // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is - // what (most?) gdb expects. + // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is what + // (most?) gdb expects. DISubprogram Subprogram(cast(SP)); DICompileUnit CompileUnit = Subprogram.getCompileUnit(); unsigned SrcFile = DW->RecordSource(CompileUnit.getDirectory(), CompileUnit.getFilename()); + // Record the source line but does not create a label for the normal // function start. It will be emitted at asm emission time. However, // create a label if this is a beginning of inlined function. - unsigned LabelID = - DW->RecordSourceLine(Subprogram.getLineNumber(), 0, SrcFile); + unsigned Line = Subprogram.getLineNumber(); + unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile); + setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0))); + if (DW->getRecordSourceLineCount() != 1) { const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); - BuildMI(MBB, II).addImm(LabelID); + BuildMI(MBB, DL, II).addImm(LabelID); } } + return true; } case Intrinsic::dbg_declare: { @@ -393,7 +400,7 @@ bool FastISel::SelectCall(User *I) { // Build the DECLARE instruction. const TargetInstrDesc &II = TII.get(TargetInstrInfo::DECLARE); - BuildMI(MBB, II).addFrameIndex(FI).addGlobalAddress(GV); + BuildMI(MBB, DL, II).addFrameIndex(FI).addGlobalAddress(GV); } return true; } @@ -830,7 +837,7 @@ unsigned FastISel::FastEmitInst_(unsigned MachineInstOpcode, unsigned ResultReg = createResultReg(RC); const TargetInstrDesc &II = TII.get(MachineInstOpcode); - BuildMI(MBB, II, ResultReg); + BuildMI(MBB, DL, II, ResultReg); return ResultReg; } @@ -841,9 +848,9 @@ unsigned FastISel::FastEmitInst_r(unsigned MachineInstOpcode, const TargetInstrDesc &II = TII.get(MachineInstOpcode); if (II.getNumDefs() >= 1) - BuildMI(MBB, II, ResultReg).addReg(Op0); + BuildMI(MBB, DL, II, ResultReg).addReg(Op0); else { - BuildMI(MBB, II).addReg(Op0); + BuildMI(MBB, DL, II).addReg(Op0); bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, II.ImplicitDefs[0], RC, RC); if (!InsertedCopy) @@ -860,9 +867,9 @@ unsigned FastISel::FastEmitInst_rr(unsigned MachineInstOpcode, const TargetInstrDesc &II = TII.get(MachineInstOpcode); if (II.getNumDefs() >= 1) - BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1); + BuildMI(MBB, DL, II, ResultReg).addReg(Op0).addReg(Op1); else { - BuildMI(MBB, II).addReg(Op0).addReg(Op1); + BuildMI(MBB, DL, II).addReg(Op0).addReg(Op1); bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, II.ImplicitDefs[0], RC, RC); if (!InsertedCopy) @@ -878,9 +885,9 @@ unsigned FastISel::FastEmitInst_ri(unsigned MachineInstOpcode, const TargetInstrDesc &II = TII.get(MachineInstOpcode); if (II.getNumDefs() >= 1) - BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Imm); + BuildMI(MBB, DL, II, ResultReg).addReg(Op0).addImm(Imm); else { - BuildMI(MBB, II).addReg(Op0).addImm(Imm); + BuildMI(MBB, DL, II).addReg(Op0).addImm(Imm); bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, II.ImplicitDefs[0], RC, RC); if (!InsertedCopy) @@ -896,9 +903,9 @@ unsigned FastISel::FastEmitInst_rf(unsigned MachineInstOpcode, const TargetInstrDesc &II = TII.get(MachineInstOpcode); if (II.getNumDefs() >= 1) - BuildMI(MBB, II, ResultReg).addReg(Op0).addFPImm(FPImm); + BuildMI(MBB, DL, II, ResultReg).addReg(Op0).addFPImm(FPImm); else { - BuildMI(MBB, II).addReg(Op0).addFPImm(FPImm); + BuildMI(MBB, DL, II).addReg(Op0).addFPImm(FPImm); bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, II.ImplicitDefs[0], RC, RC); if (!InsertedCopy) @@ -914,9 +921,9 @@ unsigned FastISel::FastEmitInst_rri(unsigned MachineInstOpcode, const TargetInstrDesc &II = TII.get(MachineInstOpcode); if (II.getNumDefs() >= 1) - BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1).addImm(Imm); + BuildMI(MBB, DL, II, ResultReg).addReg(Op0).addReg(Op1).addImm(Imm); else { - BuildMI(MBB, II).addReg(Op0).addReg(Op1).addImm(Imm); + BuildMI(MBB, DL, II).addReg(Op0).addReg(Op1).addImm(Imm); bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, II.ImplicitDefs[0], RC, RC); if (!InsertedCopy) @@ -932,9 +939,9 @@ unsigned FastISel::FastEmitInst_i(unsigned MachineInstOpcode, const TargetInstrDesc &II = TII.get(MachineInstOpcode); if (II.getNumDefs() >= 1) - BuildMI(MBB, II, ResultReg).addImm(Imm); + BuildMI(MBB, DL, II, ResultReg).addImm(Imm); else { - BuildMI(MBB, II).addImm(Imm); + BuildMI(MBB, DL, II).addImm(Imm); bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, II.ImplicitDefs[0], RC, RC); if (!InsertedCopy) @@ -951,9 +958,9 @@ unsigned FastISel::FastEmitInst_extractsubreg(MVT::SimpleValueType RetVT, const TargetInstrDesc &II = TII.get(TargetInstrInfo::EXTRACT_SUBREG); if (II.getNumDefs() >= 1) - BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Idx); + BuildMI(MBB, DL, II, ResultReg).addReg(Op0).addImm(Idx); else { - BuildMI(MBB, II).addReg(Op0).addImm(Idx); + BuildMI(MBB, DL, II).addReg(Op0).addImm(Idx); bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, II.ImplicitDefs[0], RC, RC); if (!InsertedCopy) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 9057775a5c..dd631af91f 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -3884,14 +3884,16 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { DICompileUnit CompileUnit = Subprogram.getCompileUnit(); unsigned SrcFile = DW->RecordSource(CompileUnit.getDirectory(), CompileUnit.getFilename()); + // Record the source line but does not create a label for the normal // function start. It will be emitted at asm emission time. However, // create a label if this is a beginning of inlined function. unsigned Line = Subprogram.getLineNumber(); - unsigned LabelID = - DW->RecordSourceLine(Line, 0, SrcFile); + unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile); + if (DW->getRecordSourceLineCount() != 1) DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID)); + setCurDebugLoc(DebugLoc::get(DAG.getMachineFunction(). getOrCreateDebugLocID(SrcFile, Line, 0))); } diff --git a/lib/Target/ARM/ARMInstrInfo.cpp b/lib/Target/ARM/ARMInstrInfo.cpp index 3d1e512319..c160714b54 100644 --- a/lib/Target/ARM/ARMInstrInfo.cpp +++ b/lib/Target/ARM/ARMInstrInfo.cpp @@ -649,7 +649,7 @@ bool ARMInstrInfo::restoreCalleeSavedRegisters(MachineBasicBlock &MBB, return false; bool isVarArg = AFI->getVarArgsRegSaveSize() > 0; - MachineInstr *PopMI = MF.CreateMachineInstr(get(ARM::tPOP)); + MachineInstr *PopMI = MF.CreateMachineInstr(get(ARM::tPOP),MI->getDebugLoc()); MBB.insert(MI, PopMI); for (unsigned i = CSI.size(); i != 0; --i) { unsigned Reg = CSI[i-1].getReg(); diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index 188d402087..21a11e3808 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -1938,9 +1938,11 @@ bool X86InstrInfo::restoreCalleeSavedRegisters(MachineBasicBlock &MBB, static MachineInstr *FuseTwoAddrInst(MachineFunction &MF, unsigned Opcode, const SmallVectorImpl &MOs, - MachineInstr *MI, const TargetInstrInfo &TII) { + MachineInstr *MI, + const TargetInstrInfo &TII) { // Create the base instruction with the memory operand as the first part. - MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode), true); + MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode), + MI->getDebugLoc(), true); MachineInstrBuilder MIB(NewMI); unsigned NumAddrOps = MOs.size(); for (unsigned i = 0; i != NumAddrOps; ++i) @@ -1965,7 +1967,8 @@ static MachineInstr *FuseInst(MachineFunction &MF, unsigned Opcode, unsigned OpNo, const SmallVectorImpl &MOs, MachineInstr *MI, const TargetInstrInfo &TII) { - MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode), true); + MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode), + MI->getDebugLoc(), true); MachineInstrBuilder MIB(NewMI); for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { @@ -2298,7 +2301,7 @@ bool X86InstrInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI, } // Emit the data processing instruction. - MachineInstr *DataMI = MF.CreateMachineInstr(TID, true); + MachineInstr *DataMI = MF.CreateMachineInstr(TID, MI->getDebugLoc(), true); MachineInstrBuilder MIB(DataMI); if (FoldedStore) -- cgit v1.2.3-70-g09d2