@@ -77,6 +77,14 @@ class KernelInfo {
7777
7878} // end anonymous namespace
7979
80+ static DiagnosticLocation getRemarkLocation (const Instruction &I) {
81+ if (DebugLoc DL = I.getDebugLoc ())
82+ return DiagnosticLocation (DL);
83+ if (auto *SP = I.getFunction ()->getSubprogram ())
84+ return DiagnosticLocation (SP);
85+ return DiagnosticLocation ();
86+ }
87+
8088static void identifyCallee (OptimizationRemark &R, const Module *M,
8189 const Value *V, StringRef Kind = " " ) {
8290 SmallString<100 > Name; // might be function name or asm expression
@@ -105,16 +113,19 @@ static void remarkAlloca(OptimizationRemarkEmitter &ORE, const Function &Caller,
105113 TypeSize::ScalarTy StaticSize) {
106114 ORE.emit ([&] {
107115 StringRef DbgName;
108- DebugLoc Loc ;
116+ DebugLoc DL ;
109117 bool Artificial = false ;
110118 auto DVRs = findDVRDeclares (&const_cast <AllocaInst &>(Alloca));
111119 if (!DVRs.empty ()) {
112120 const DbgVariableRecord &DVR = **DVRs.begin ();
113121 DbgName = DVR.getVariable ()->getName ();
114- Loc = DVR.getDebugLoc ();
122+ DL = DVR.getDebugLoc ();
115123 Artificial = DVR.Variable ->isArtificial ();
116124 }
117- OptimizationRemark R (DEBUG_TYPE, " Alloca" , DiagnosticLocation (Loc),
125+
126+ OptimizationRemark R (DEBUG_TYPE, " Alloca" ,
127+ DL ? DiagnosticLocation (DL)
128+ : getRemarkLocation (Alloca),
118129 Alloca.getParent ());
119130 R << " in " ;
120131 identifyFunction (R, Caller);
@@ -142,7 +153,8 @@ static void remarkCall(OptimizationRemarkEmitter &ORE, const Function &Caller,
142153 const CallBase &Call, StringRef CallKind,
143154 StringRef RemarkKind) {
144155 ORE.emit ([&] {
145- OptimizationRemark R (DEBUG_TYPE, RemarkKind, &Call);
156+ OptimizationRemark R (DEBUG_TYPE, RemarkKind, getRemarkLocation (Call),
157+ Call.getParent ());
146158 R << " in " ;
147159 identifyFunction (R, Caller);
148160 R << " , " << CallKind << " , callee is " ;
@@ -155,7 +167,8 @@ static void remarkFlatAddrspaceAccess(OptimizationRemarkEmitter &ORE,
155167 const Function &Caller,
156168 const Instruction &Inst) {
157169 ORE.emit ([&] {
158- OptimizationRemark R (DEBUG_TYPE, " FlatAddrspaceAccess" , &Inst);
170+ OptimizationRemark R (DEBUG_TYPE, " FlatAddrspaceAccess" ,
171+ getRemarkLocation (Inst), Inst.getParent ());
159172 R << " in " ;
160173 identifyFunction (R, Caller);
161174 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(&Inst)) {
@@ -265,7 +278,11 @@ void KernelInfo::updateForBB(const BasicBlock &BB,
265278static void remarkProperty (OptimizationRemarkEmitter &ORE, const Function &F,
266279 StringRef Name, int64_t Value) {
267280 ORE.emit ([&] {
268- OptimizationRemark R (DEBUG_TYPE, Name, &F);
281+ DiagnosticLocation DL = F.getSubprogram ()
282+ ? DiagnosticLocation (F.getSubprogram ())
283+ : DiagnosticLocation ();
284+ OptimizationRemark R (DEBUG_TYPE, Name, DL,
285+ !F.empty () ? &F.front () : nullptr );
269286 R << " in " ;
270287 identifyFunction (R, F);
271288 R << " , " << Name << " = " << itostr (Value);
0 commit comments