[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-25 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> My guess here would have been that the issue is the cases where an 
> Instruction* or BasicBlock* is passed rather than BB+Iterator, because those 
> two cases go through an out-of-line constructor.

Seems like you're right - removing the extra dereference does 
little-to-nothing, but allowing the constructors to be inlined mitigates most 
of the cost. It still ends up being [a net negative for 
performance](http://llvm-compile-time-tracker.com/compare.php?from=d75f9dd1d29b332bdc51346de63cbc04646354d7=3acef100b23fb6fa616523dd0d1b85945adb7900=instructions%3Au)
 though, even after allowing the constructors to become inlined.

https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-24 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> Looks like using InsertPosition in IRBuilder has some overhead: 

Hm, we're adding an extra pointer chase when we give up passing a basicblock - 
I think then it makes sense to keep the option to pass BB+It, and do so when 
the caller already knows the BB (while removing the need to pass the BB around 
for functions that only need an insert point).

https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-24 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

Looks like I missed a spot - reverting for now, will wait for a bit to see if 
any other errors fall out from the various configurations on CI before 
reapplying.

https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-24 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-24 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-24 Thread Stephen Tozer via cfe-commits


@@ -44,15 +44,19 @@ template <> struct ilist_alloc_traits {
 iterator_range::iterator>
 getDbgRecordRange(DbgMarker *);
 
+/// Class used to generate an insert position (ultimately always a
+/// BasicBlock::iterator, which it will implicitly convert to) from either:
+/// - An Instruction, inserting immediately prior.

SLTozer wrote:

It isn't deprecated yet, but I can put a comment indicating the future intent.

https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-24 Thread Stephen Tozer via cfe-commits


@@ -637,8 +637,7 @@ void ARMParallelDSP::InsertParallelMACs(Reduction ) {
 Intrinsic::getDeclaration(M, Intrinsic::arm_smlad) :
 Intrinsic::getDeclaration(M, Intrinsic::arm_smlald);
 
-IRBuilder Builder(InsertAfter->getParent(),
-BasicBlock::iterator(InsertAfter));
+IRBuilder Builder((BasicBlock::iterator(InsertAfter)));

SLTozer wrote:

Funnily enough, that doesn't actually work:
```
./llvm/lib/Target/ARM/ARMParallelDSP.cpp:640:32: warning: parentheses were 
disambiguated as a function declaration [-Wvexing-parse]
  640 | IRBuilder Builder(BasicBlock::iterator(InsertAfter));
  |^~~
```
Hence the weird double parentheses - however having looked back at this I can 
see `InsertAfter` is always non-null, so `->getIterator()` is safe.

https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IR][NFC] Update IRBuilder to use InsertPosition (PR #96497)

2024-06-24 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/96497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-20 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/94226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> I think some of the overloads for constructing an instruction aren't quite 
> right:

That's reasonable - I defaulted to adding nullptr-defaults in the case where it 
didn't cause incorrect overloads, but it's easier to keep only the existing 
defaults and let any others be added later as appropriate; I've updated the 
patch accordingly.

https://github.com/llvm/llvm-project/pull/94226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

Alright, builds now working for LLVM, Clang, Flang, Polly, and MLIR; looks good 
to merge?

https://github.com/llvm/llvm-project/pull/94226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] (New) Add option to generate additional debug info for expression dereferencing pointer to pointers (PR #95298)

2024-06-14 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

Small recommendation that the 
[patch](https://github.com/llvm/llvm-project/pull/91724) @pogo59 mentioned 
above has now landed, so before merging this you should rebase and update the 
test accordingly.

https://github.com/llvm/llvm-project/pull/95298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [RemoveDIs] Print IR with debug records by default (PR #91724)

2024-06-14 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/91724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dc726c3 - Reapply#4 "[RemoveDIs] Load into new debug info format by default in LLVM (#89799)"

2024-06-14 Thread Stephen Tozer via cfe-commits

Author: Stephen Tozer
Date: 2024-06-14T09:54:56+01:00
New Revision: dc726c340392d4a0f3af9dde5f34c58d98198667

URL: 
https://github.com/llvm/llvm-project/commit/dc726c340392d4a0f3af9dde5f34c58d98198667
DIFF: 
https://github.com/llvm/llvm-project/commit/dc726c340392d4a0f3af9dde5f34c58d98198667.diff

LOG: Reapply#4 "[RemoveDIs] Load into new debug info format by default in LLVM 
(#89799)"

Reapplies commit c5aeca73 (and its followup commit 21396be8), which were
reverted due to missing functionality in MLIR and Flang regarding printing
debug records. This has now been added in commit 08aa511, along with support
for printing debug records in flang.

This reverts commit 2dc2290860355dd2bac3b655eea895fe30fde257.

Added: 


Modified: 
clang/test/CodeGen/instrument-objc-method.m
flang/test/Transforms/debug-local-var-2.f90
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/AsmParser/LLParser.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/IR/DebugProgramInstruction.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/Module.cpp
llvm/tools/llvm-as/llvm-as.cpp
llvm/tools/llvm-dis/llvm-dis.cpp
llvm/tools/llvm-link/llvm-link.cpp
llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
llvm/unittests/IR/DebugInfoTest.cpp
llvm/unittests/IR/IRBuilderTest.cpp
llvm/unittests/IR/InstructionsTest.cpp
llvm/unittests/IR/ValueTest.cpp
llvm/unittests/Transforms/Utils/CloningTest.cpp
llvm/unittests/Transforms/Utils/LocalTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/instrument-objc-method.m 
b/clang/test/CodeGen/instrument-objc-method.m
index cfc0a0a98bec6..2c9d1fc88554b 100644
--- a/clang/test/CodeGen/instrument-objc-method.m
+++ b/clang/test/CodeGen/instrument-objc-method.m
@@ -11,16 +11,16 @@ @implementation ObjCClass
 + (void)initialize {
 }
 
-// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
-// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #2
+// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #1
 + (void)load __attribute__((no_instrument_function)) {
 }
 
-// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
-// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
+// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
+// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
 - (void)dealloc __attribute__((no_instrument_function)) {
 }
 
+// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
 // PREINLINE: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter"
 // PREINLINE-NOT: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter_bare"
 // PREINLINE-NOT: attributes #2 = { {{.*}}"__cyg_profile_func_enter"

diff  --git a/flang/test/Transforms/debug-local-var-2.f90 
b/flang/test/Transforms/debug-local-var-2.f90
index 3b2873a1edaaf..ce78bfd005056 100644
--- a/flang/test/Transforms/debug-local-var-2.f90
+++ b/flang/test/Transforms/debug-local-var-2.f90
@@ -28,27 +28,27 @@
 
 ! BOTH-LABEL: define {{.*}}i64 @_QFPfn1
 ! BOTH-SAME: (ptr %[[ARG1:.*]], ptr %[[ARG2:.*]], ptr %[[ARG3:.*]])
-! INTRINSICS-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[ARG1]], 
metadata ![[A1:.*]], metadata !DIExpression())
-! INTRINSICS-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[ARG2]], 
metadata ![[B1:.*]], metadata !DIExpression())
-! INTRINSICS-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[ARG3]], 
metadata ![[C1:.*]], metadata !DIExpression())
+! INTRINSICS-DAG: call void @llvm.dbg.declare(metadata ptr %[[ARG1]], metadata 
![[A1:.*]], metadata !DIExpression())
+! INTRINSICS-DAG: call void @llvm.dbg.declare(metadata ptr %[[ARG2]], metadata 
![[B1:.*]], metadata !DIExpression())
+! INTRINSICS-DAG: call void @llvm.dbg.declare(metadata ptr %[[ARG3]], metadata 
![[C1:.*]], metadata !DIExpression())
 ! RECORDS-DAG: #dbg_declare(ptr %[[ARG1]], ![[A1:.*]], !DIExpression(), 
!{{.*}})
 ! RECORDS-DAG: #dbg_declare(ptr %[[ARG2]], ![[B1:.*]], !DIExpression(), 
!{{.*}})
 ! RECORDS-DAG: #dbg_declare(ptr %[[ARG3]], ![[C1:.*]], !DIExpression(), 
!{{.*}})
 ! BOTH-DAG: %[[AL2:.*]] = alloca i64
-! INTRINSICS-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[AL2]], 
metadata ![[RES1:.*]], metadata !DIExpression())
+! INTRINSICS-DAG: call void @llvm.dbg.declare(metadata ptr %[[AL2]], metadata 
![[RES1:.*]], metadata !DIExpression())
 ! RECORDS-DAG: #dbg_declare(ptr %[[AL2]], ![[RES1:.*]], !DIExpression(), 
!{{.*}})
 ! BOTH-LABEL: }
 
 ! BOTH-LABEL: define {{.*}}i32 @_QFPfn2
 ! BOTH-SAME: (ptr %[[FN2ARG1:.*]], ptr %[[FN2ARG2:.*]], ptr %[[FN2ARG3:.*]])
-! INTRINSICS-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[FN2ARG1]], 
metadata ![[A2:.*]], metadata !DIExpression())
-! INTRINSICS-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[FN2ARG2]], 
metadata ![[B2:.*]], metadata !DIExpression())
-! 

[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-13 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

Abandoned in favour of https://github.com/llvm/llvm-project/pull/94226.

https://github.com/llvm/llvm-project/pull/94226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] (New) Add option to generate additional debug info for expression dereferencing pointer to pointers (PR #95298)

2024-06-13 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/95298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] (New) Add option to generate additional debug info for expression dereferencing pointer to pointers (PR #95298)

2024-06-13 Thread Stephen Tozer via cfe-commits


@@ -5746,6 +5746,57 @@ void 
CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitPseudoVariable(CGBuilderTy ,
+ llvm::Instruction *Value, QualType Ty) {
+  // Only when -g2 or above is specified, debug info for variables will be
+  // generated.
+  if (CGM.getCodeGenOpts().getDebugInfo() <=
+  llvm::codegenoptions::DebugLineTablesOnly)
+return;
+
+  llvm::DILocation *DIL = Value->getDebugLoc().get();
+  if (!DIL)
+return;
+
+  llvm::DIFile *Unit = DIL->getFile();
+  llvm::DIType *Type = getOrCreateType(Ty, Unit);
+
+  // Check if Value is already a declared variable and has debug info, in this
+  // case we have nothing to do. Clang emits declared variable as alloca, and
+  // it is loaded upon use, so we identify such pattern here.
+  if (llvm::LoadInst *Load = dyn_cast(Value)) {
+llvm::Value *Var = Load->getPointerOperand();
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
+  return;
+  }
+
+  // Find the correct location to insert the debug value.
+  llvm::BasicBlock *InsertBB = Value->getParent();
+  llvm::Instruction *InsertBefore = Value->getIterator()->getNextNode();
+  if (llvm::InvokeInst *Invoke = dyn_cast(Value)) {
+InsertBB = Invoke->getNormalDest();
+InsertBefore = InsertBB->size() > 0 ? &(InsertBB->front()) : nullptr;
+  }

SLTozer wrote:

To add a little extra to this, it looks like what this code is trying to do is 
the same as `Instruction::getInsertionPointAfterDef` - would that be a suitable 
substitution?

https://github.com/llvm/llvm-project/pull/95298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-13 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer reopened 
https://github.com/llvm/llvm-project/pull/94226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-13 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/94226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2dc2290 - Revert new debug info format commits:

2024-06-11 Thread Stephen Tozer via cfe-commits

Author: Stephen Tozer
Date: 2024-06-11T12:19:06+01:00
New Revision: 2dc2290860355dd2bac3b655eea895fe30fde257

URL: 
https://github.com/llvm/llvm-project/commit/2dc2290860355dd2bac3b655eea895fe30fde257
DIFF: 
https://github.com/llvm/llvm-project/commit/2dc2290860355dd2bac3b655eea895fe30fde257.diff

LOG: Revert new debug info format commits:

"[Flang] Update test to not check for tail calls on debug intrinsics" &
"Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM 
(#89799)"

Recent updates to flang have added debug info generation via MLIR, a path
which currently does not support debug records. The patch that enables
debug records by default (and a small followup patch) are thus being
reverted until the MLIR path has been fixed.

This reverts commits:
  21396be865b4640abf6afa0b05de6708a1a996e0
  c5aeca732d1ff6769b0659efebd1cfb5f60487e4

Added: 


Modified: 
clang/test/CodeGen/instrument-objc-method.m
flang/test/Transforms/debug-local-var-2.f90
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/AsmParser/LLParser.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/IR/DebugProgramInstruction.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/Module.cpp
llvm/tools/llvm-as/llvm-as.cpp
llvm/tools/llvm-dis/llvm-dis.cpp
llvm/tools/llvm-link/llvm-link.cpp
llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
llvm/unittests/IR/DebugInfoTest.cpp
llvm/unittests/IR/IRBuilderTest.cpp
llvm/unittests/IR/InstructionsTest.cpp
llvm/unittests/IR/ValueTest.cpp
llvm/unittests/Transforms/Utils/CloningTest.cpp
llvm/unittests/Transforms/Utils/LocalTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/instrument-objc-method.m 
b/clang/test/CodeGen/instrument-objc-method.m
index 2c9d1fc88554b..cfc0a0a98bec6 100644
--- a/clang/test/CodeGen/instrument-objc-method.m
+++ b/clang/test/CodeGen/instrument-objc-method.m
@@ -11,16 +11,16 @@ @implementation ObjCClass
 + (void)initialize {
 }
 
-// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #1
+// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #2
 + (void)load __attribute__((no_instrument_function)) {
 }
 
-// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
-// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
+// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
+// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
 - (void)dealloc __attribute__((no_instrument_function)) {
 }
 
-// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
 // PREINLINE: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter"
 // PREINLINE-NOT: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter_bare"
 // PREINLINE-NOT: attributes #2 = { {{.*}}"__cyg_profile_func_enter"

diff  --git a/flang/test/Transforms/debug-local-var-2.f90 
b/flang/test/Transforms/debug-local-var-2.f90
index ee60a07cc4bee..0fe1b81c27e61 100644
--- a/flang/test/Transforms/debug-local-var-2.f90
+++ b/flang/test/Transforms/debug-local-var-2.f90
@@ -20,20 +20,20 @@
 
 ! CHECK-LABEL: define {{.*}}i64 @_QFPfn1
 ! CHECK-SAME: (ptr %[[ARG1:.*]], ptr %[[ARG2:.*]], ptr %[[ARG3:.*]])
-! CHECK-DAG: call void @llvm.dbg.declare(metadata ptr %[[ARG1]], metadata 
![[A1:.*]], metadata !DIExpression())
-! CHECK-DAG: call void @llvm.dbg.declare(metadata ptr %[[ARG2]], metadata 
![[B1:.*]], metadata !DIExpression())
-! CHECK-DAG: call void @llvm.dbg.declare(metadata ptr %[[ARG3]], metadata 
![[C1:.*]], metadata !DIExpression())
+! CHECK-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[ARG1]], metadata 
![[A1:.*]], metadata !DIExpression())
+! CHECK-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[ARG2]], metadata 
![[B1:.*]], metadata !DIExpression())
+! CHECK-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[ARG3]], metadata 
![[C1:.*]], metadata !DIExpression())
 ! CHECK-DAG: %[[AL2:.*]] = alloca i64
-! CHECK-DAG: call void @llvm.dbg.declare(metadata ptr %[[AL2]], metadata 
![[RES1:.*]], metadata !DIExpression())
+! CHECK-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[AL2]], metadata 
![[RES1:.*]], metadata !DIExpression())
 ! CHECK-LABEL: }
 
 ! CHECK-LABEL: define {{.*}}i32 @_QFPfn2
 ! CHECK-SAME: (ptr %[[FN2ARG1:.*]], ptr %[[FN2ARG2:.*]], ptr %[[FN2ARG3:.*]])
-! CHECK-DAG: call void @llvm.dbg.declare(metadata ptr %[[FN2ARG1]], metadata 
![[A2:.*]], metadata !DIExpression())
-! CHECK-DAG: call void @llvm.dbg.declare(metadata ptr %[[FN2ARG2]], metadata 
![[B2:.*]], metadata !DIExpression())
-! CHECK-DAG: call void @llvm.dbg.declare(metadata ptr %[[FN2ARG3]], metadata 
![[C2:.*]], metadata !DIExpression())
+! CHECK-DAG: tail call void @llvm.dbg.declare(metadata ptr %[[FN2ARG1]], 
metadata ![[A2:.*]], metadata 

[clang] [llvm] Add option to generate additional debug info for expression dereferencing pointer to pointers. (PR #94100)

2024-06-10 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

Yes, to my knowledge Swift emits dbg.values out of its front end, so there's 
probably no reason (on the LLVM side) that clang couldn't do so as well. There 
might be good reasons internal to clang that it doesn't use debug values atm, 
and it's not inconceivable that we'd hit some cases that LLVM handles poorly at 
the moment (right now assignment tracking depends on reading dbg.declares, for 
example), but that's something that could be tackled in a separate review.

https://github.com/llvm/llvm-project/pull/94100
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c5aeca7 - Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM (#89799)"

2024-06-10 Thread Stephen Tozer via cfe-commits

Author: Stephen Tozer
Date: 2024-06-10T13:04:40+01:00
New Revision: c5aeca732d1ff6769b0659efebd1cfb5f60487e4

URL: 
https://github.com/llvm/llvm-project/commit/c5aeca732d1ff6769b0659efebd1cfb5f60487e4
DIFF: 
https://github.com/llvm/llvm-project/commit/c5aeca732d1ff6769b0659efebd1cfb5f60487e4.diff

LOG: Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM 
(#89799)"

Reapplies commit 91446e2, which was reverted due to a downstream error,
discussed on the pull request. The error could not be reproduced
upstream, and cannot be reproduced downstream as-of current main, so
until the error can be confirmed to still exist this patch should
return.

This reverts commit 23f8fac745bdde70ed4f9c585d19c4913734f1b8.

Added: 


Modified: 
clang/test/CodeGen/instrument-objc-method.m
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/AsmParser/LLParser.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/IR/DebugProgramInstruction.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/Module.cpp
llvm/tools/llvm-as/llvm-as.cpp
llvm/tools/llvm-dis/llvm-dis.cpp
llvm/tools/llvm-link/llvm-link.cpp
llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
llvm/unittests/IR/DebugInfoTest.cpp
llvm/unittests/IR/IRBuilderTest.cpp
llvm/unittests/IR/InstructionsTest.cpp
llvm/unittests/IR/ValueTest.cpp
llvm/unittests/Transforms/Utils/CloningTest.cpp
llvm/unittests/Transforms/Utils/LocalTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/instrument-objc-method.m 
b/clang/test/CodeGen/instrument-objc-method.m
index cfc0a0a98bec6..2c9d1fc88554b 100644
--- a/clang/test/CodeGen/instrument-objc-method.m
+++ b/clang/test/CodeGen/instrument-objc-method.m
@@ -11,16 +11,16 @@ @implementation ObjCClass
 + (void)initialize {
 }
 
-// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
-// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #2
+// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #1
 + (void)load __attribute__((no_instrument_function)) {
 }
 
-// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
-// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
+// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
+// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
 - (void)dealloc __attribute__((no_instrument_function)) {
 }
 
+// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
 // PREINLINE: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter"
 // PREINLINE-NOT: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter_bare"
 // PREINLINE-NOT: attributes #2 = { {{.*}}"__cyg_profile_func_enter"

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index f86f9430201f8..8cdb9db087c77 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -225,6 +225,13 @@ Changes to the Metadata Info
 Changes to the Debug Info
 -
 
+* LLVM has switched from using debug intrinsics internally to using debug
+  records by default. This should happen transparently when using the DIBuilder
+  to construct debug variable information, but will require changes for any 
code
+  that interacts with debug intrinsics directly. Debug intrinsics will only be
+  supported on a best-effort basis from here onwards; for more information, see
+  the `migration docs `_.
+
 Changes to the LLVM tools
 -
 * llvm-nm and llvm-objdump can now print symbol information from linked

diff  --git a/llvm/include/llvm/AsmParser/LLParser.h 
b/llvm/include/llvm/AsmParser/LLParser.h
index b2dcdfad0a04b..e687254f6c4c7 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -337,7 +337,6 @@ namespace llvm {
 
 // Top-Level Entities
 bool parseTopLevelEntities();
-bool finalizeDebugInfoFormat(Module *M);
 void dropUnknownMetadataReferences();
 bool validateEndOfModule(bool UpgradeDebugInfo);
 bool validateEndOfIndex();

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f0fde9ae4df5c..eb1e3e494a42f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -74,23 +74,6 @@ static std::string getTypeString(Type *T) {
   return Tmp.str();
 }
 
-// Whatever debug info format we parsed, we should convert to the expected 
debug
-// info format immediately afterwards.
-bool LLParser::finalizeDebugInfoFormat(Module *M) {
-  // We should have already returned an error if we observed both intrinsics 
and
-  // records in this IR.
-  assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
- "Mixed debug intrinsics/records seen without a parsing error?");
-  if (PreserveInputDbgFormat == 

[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/94956
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/94956

>From 56109f5f411523967ffef5a32a507d6472eebdaf Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 10 Jun 2024 11:35:02 +0100
Subject: [PATCH 1/2] [Clang] Extend EmitPseudoVariable to support debug
 records

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly
collect llvm.dbg.declare users of an alloca. This patch replaces this
with an LLVM function for finding debug declares intrinsics and also adds
the same for debug records, simplifying the code and adding record
support.
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 32 ++-
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..d5676be0e8742 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to

>From d1fe1a5aa3d1b5d6eb6097ae8313d8620126c5a5 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 10 Jun 2024 11:55:36 +0100
Subject: [PATCH 2/2] Update lambda name

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index d5676be0e8742..11e2d549d8a45 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5773,8 +5773,8 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy ,
 auto DeclareTypeMatches = [&](auto *DbgDeclare) {
   return DbgDeclare->getVariable()->getType() == Type;
 };
-if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
-any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
   return;
   }
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits


@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||

SLTozer wrote:

Oops!

https://github.com/llvm/llvm-project/pull/94956
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer created 
https://github.com/llvm/llvm-project/pull/94956

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly 
collect llvm.dbg.declare users of an alloca. This patch replaces this with an 
LLVM function for finding debug declares intrinsics and also adds the same for 
debug records, simplifying the code and adding record support.

No tests added in this commit because it is NFC for intrinsics, and there is no 
way to make clang emit records directly yet - one of the existing tests however 
will switch to covering debug records once 
https://github.com/llvm/llvm-project/pull/89799 relands.

>From 56109f5f411523967ffef5a32a507d6472eebdaf Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 10 Jun 2024 11:35:02 +0100
Subject: [PATCH] [Clang] Extend EmitPseudoVariable to support debug records

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly
collect llvm.dbg.declare users of an alloca. This patch replaces this
with an LLVM function for finding debug declares intrinsics and also adds
the same for debug records, simplifying the code and adding record
support.
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 32 ++-
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..d5676be0e8742 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-03 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/94226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-28 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer approved this pull request.

> Yeah, seems I'm outvoted here. I'm a bit of a pedant for the C++ standard 
> language, which doesn't talk about "methods", only "member functions".

All I'd say is that if we went with members, it ought to be 
`-gomit-unreferenced-member-functions` rather than 
`-gomit-unreferenced-members`; I'm not strongly attached to "methods" over 
"member functions", but just "members" is misleading imo. In any case, the 
patch functionally LGTM.

https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-28 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-28 Thread Stephen Tozer via cfe-commits


@@ -4260,6 +4260,13 @@ defm strict_dwarf : BoolOption<"g", "strict-dwarf",
   "the specified version, avoiding features from later versions.">,
   NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
   Group;
+defm omit_unreferenced_members : BoolOption<"g", "omit-unreferenced-members",
+  CodeGenOpts<"DebugOmitUnreferencedMembers">, DefaultFalse,
+  PosFlag,
+  NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
+  Group;

SLTozer wrote:

It seems you're right - the marshalling stuff allows us to omit boilerplate in 
a few places, but `renderDebugOptions` isn't one of them; I'd missed that 
`BoolOption` was already covering that base as well, so carry on I think 
(though the `BoolGOption` change does seem sensible).

https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-21 Thread Stephen Tozer via cfe-commits


@@ -4260,6 +4260,13 @@ defm strict_dwarf : BoolOption<"g", "strict-dwarf",
   "the specified version, avoiding features from later versions.">,
   NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
   Group;
+defm omit_unreferenced_members : BoolOption<"g", "omit-unreferenced-members",
+  CodeGenOpts<"DebugOmitUnreferencedMembers">, DefaultFalse,
+  PosFlag,
+  NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
+  Group;

SLTozer wrote:

As a small matter of convenience, since this is just being passed straight 
through the driver I think this could be a marshalling flag, which iirc would 
allow us to omit the `renderDebugOptions` code?
```suggestion
defm omit_unreferenced_members : Flag<["-"], "gomit-unreferenced-members">,
  Group, Visibility<[ClangOption, CC1Option]>,
  HelpText<"Omit member function declarations from type descriptions if the "
"member is unreferenced.">,
  MarshallingInfoFlag>;
```

https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-21 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer commented:

I think the comment about `s/members/methods/` is still outstanding - I agree 
that methods is more descriptive than members.

I'm +1 on having this be non-default; adding it to SCE tuning is also not 
necessary (or desired) for now, because this is more aggressive than our 
private option (we keep entries for member functions that are called), and 
we're still working out whether we can/should adopt this instead. 

Otherwise, existing comments aside, this looks good: the size reduction is 
considerable, and likely becoming necessary for some.

https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-21 Thread Stephen Tozer via cfe-commits


@@ -2755,7 +2755,7 @@ CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
 
   // Collect data fields (including static variables and any initializers).
   CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
-  if (CXXDecl)
+  if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMembers)

SLTozer wrote:

>From the old review, there was a question about whether this should be 
>disabled by `-fstandalone-debug` - it seemed like there was a reasonable case 
>for (being able to call member functions from a different TU without debug 
>info), and a reasonable case against (inconsistency with non-member 
>functions), and it's not totally clear whether that was resolved.

https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-21 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-21 Thread Stephen Tozer via cfe-commits


@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gomit-unreferenced-members %s 
-emit-llvm -o - | FileCheck %s

SLTozer wrote:

Test needs renaming for the different flag name?

https://github.com/llvm/llvm-project/pull/87018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Store FPOptions earlier when parsing function (PR #92146)

2024-05-15 Thread Stephen Tozer via cfe-commits


@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-pch -DHEADER -x c++-header %s -o %t.pch
+// RUN: %clang_cc1 -emit-llvm -include-pch %t.pch %s -o /dev/null
+
+#ifdef HEADER
+__attribute__((optnone)) void foo() {}
+#endif

SLTozer wrote:

Ah, that makes sense since you're using a single file as the source and header 
- as does the resulting error. New test LGTM.

https://github.com/llvm/llvm-project/pull/92146
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Store FPOptions earlier when parsing function (PR #92146)

2024-05-14 Thread Stephen Tozer via cfe-commits


@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-pch -DHEADER -x c++-header %s -o %t.pch
+// RUN: %clang_cc1 -emit-llvm -include-pch %t.pch %s -o /dev/null
+
+#ifdef HEADER
+__attribute__((optnone)) void foo() {}
+#endif

SLTozer wrote:

It's not particularly important, but is there a reason for the use of the 
macros here?

https://github.com/llvm/llvm-project/pull/92146
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Store FPOptions earlier when parsing function (PR #92146)

2024-05-14 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer approved this pull request.

I'm not familiar with the surrounding code, but this fixes the issue and looks 
reasonable.

https://github.com/llvm/llvm-project/pull/92146
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Store FPOptions earlier when parsing function (PR #92146)

2024-05-14 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/92146
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RemoveDIs] Print IR with debug records by default (PR #91724)

2024-05-13 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> Thanks for clarifying the pre-script fixes. With that resolved, this looks 
> good to me.

TYVM for the LGTM! I'll leave the review up for a bit in case anyone has 
anything further to add.

https://github.com/llvm/llvm-project/pull/91724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RemoveDIs] Print IR with debug records by default (PR #91724)

2024-05-13 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/91724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RemoveDIs] Print IR with debug records by default (PR #91724)

2024-05-13 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/91724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RemoveDIs] Print IR with debug records by default (PR #91724)

2024-05-13 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> There's one part I did not fully understand. How did you identify the 
> "pre-script fixups"? What's the importance of those changes? I did not seen 
> any mention of that in your PR description.

Good question, I'll add my answer to the main description: The pre-script 
fixups were determined post-script; so I ran the script, looked at the tests 
that still failed, and examined why - in most cases this isn't hard, because 
the problem `CHECK` is the one that fails the test. The pre-script fixups 
change existing patterns so that the script can handle them correctly, while 
the post-script fixups cover cases that the script can't fix or otherwise 
mishandles. In both cases we need to run the script first to identify the 
problems and manually fixup the check lines, and for a downstream user it _may_ 
be easier to skip the pre-script stuff and just fix all broken checks manually 
after the script makes its best effort; my splitting of the pre-script 
modifications was more to ensure that as much of this review is automated as 
possible, rather than a necessary step.

https://github.com/llvm/llvm-project/pull/91724
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Set correct FPOptions if attribute 'optnone' presents (PR #85605)

2024-05-10 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

It looks like this is causing crashes when including precompiled headers that 
contain optnone functions; this can be reproduced with a very short header file 
and any source file, even a completely empty one. Reproducer follows:
```
$ cat header.h
__attribute__((optnone)) void foo() {}
$ cat src.cpp
// Empty file
$ ./build/bin/clang -x c++-header header.h -o header.pch
$ ./build/bin/clang -c -include-pch header.pch src.cpp
clang: 
/home/gbtozers/dev/upstream-llvm/clang/lib/Serialization/ASTReader.cpp:8316: 
void clang::ASTReader::UpdateSema(): Assertion `*FpPragmaCurrentValue == 
SemaObj->FpPragmaStack.DefaultValue && "Expected a default pragma float_control 
value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: ./build/bin/clang -c -include-pch header.pch src.cpp
1.   parser at end of file
 #0 0x55db95a49978 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(./build/bin/clang+0x7aa2978)
 #1 0x55db95a474ce llvm::sys::RunSignalHandlers() 
(./build/bin/clang+0x7aa04ce)
 #2 0x55db959ae1a6 CrashRecoverySignalHandler(int) 
CrashRecoveryContext.cpp:0:0
 #3 0x7f1c0f348520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x7f1c0f39c9fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x7f1c0f39c9fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x7f1c0f39c9fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x7f1c0f348476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x7f1c0f32e7f3 abort ./stdlib/abort.c:81:7
 #9 0x7f1c0f32e71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x7f1c0f33fe96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x55db967f68db clang::ASTReader::UpdateSema() 
(./build/bin/clang+0x884f8db)
#12 0x55db980be50c clang::Sema::Initialize() (./build/bin/clang+0xa11750c)
#13 0x55db97f7a4e3 clang::Parser::Initialize() (./build/bin/clang+0x9fd34e3)
#14 0x55db97f75373 clang::ParseAST(clang::Sema&, bool, bool) 
(./build/bin/clang+0x9fce373)
#15 0x55db966b20cf clang::FrontendAction::Execute() 
(./build/bin/clang+0x870b0cf)
#16 0x55db966212cd 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
(./build/bin/clang+0x867a2cd)
#17 0x55db9679971e 
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
(./build/bin/clang+0x87f271e)
#18 0x55db933468bc cc1_main(llvm::ArrayRef, char const*, 
void*) (./build/bin/clang+0x539f8bc)
#19 0x55db9334325d ExecuteCC1Tool(llvm::SmallVectorImpl&, 
llvm::ToolContext const&) driver.cpp:0:0
#20 0x55db96467159 void llvm::function_ref::callback_fn>,
 std::__cxx11::basic_string, 
std::allocator>*, bool*) const::$_0>(long) Job.cpp:0:0
#21 0x55db959adee6 
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) 
(./build/bin/clang+0x7a06ee6)
#22 0x55db96466892 
clang::driver::CC1Command::Execute(llvm::ArrayRef>,
 std::__cxx11::basic_string, 
std::allocator>*, bool*) const (./build/bin/clang+0x84bf892)
#23 0x55db9641e954 
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, 
clang::driver::Command const*&, bool) const (./build/bin/clang+0x8477954)
#24 0x55db9641ee87 
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, 
llvm::SmallVectorImpl>&, bool) 
const (./build/bin/clang+0x8477e87)
#25 0x55db9643fcb8 
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, 
llvm::SmallVectorImpl>&) 
(./build/bin/clang+0x8498cb8)
#26 0x55db93342790 clang_main(int, char**, llvm::ToolContext const&) 
(./build/bin/clang+0x539b790)
#27 0x55db93353047 main (./build/bin/clang+0x53ac047)
#28 0x7f1c0f32fd90 __libc_start_call_main 
./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#29 0x7f1c0f32fe40 call_init ./csu/../csu/libc-start.c:128:20
#30 0x7f1c0f32fe40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#31 0x55db93340c25 _start (./build/bin/clang+0x5399c25)
clang: error: clang frontend command failed with exit code 134 (use -v to see 
invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 
a04624206ddf03dc54d5c372e7eac13575b4124b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/gbtozers/dev/upstream-llvm/build/bin
Build config: +assertions
clang: note: diagnostic msg:


PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/src-520bcb.cpp
clang: note: diagnostic msg: /tmp/src-520bcb.sh
clang: note: diagnostic msg:


```

https://github.com/llvm/llvm-project/pull/85605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RemoveDIs][Clang] Resolve DILocalVariables used by DbgRecords (PR #90882)

2024-05-02 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/90882
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RemoveDIs][Clang] Resolve DILocalVariables used by DbgRecords (PR #90882)

2024-05-02 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer created 
https://github.com/llvm/llvm-project/pull/90882

This patch fixes debug records in clang, by adding support for debug records to 
the only remaining place that refers to DbgVariableIntrinsics directly and does 
not handle DbgVariableRecords.

>From d4e716205806b73366add260e4a580ae59bc0573 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Thu, 2 May 2024 18:40:15 +0100
Subject: [PATCH] [RemoveDIs][Clang] Resolve DILocalVariables used by
 DbgRecords

This patch fixes debug records in clang, by adding support for debug
records to the only remaining place that refers to DbgVariableIntrinsics
directly and does not handle DbgVariableRecords.
---
 clang/lib/CodeGen/CGVTables.cpp | 6 ++
 clang/test/CodeGenCXX/tmp-md-nodes2.cpp | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 862369ae009f48..8d9c22546b4208 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -131,6 +131,12 @@ static void resolveTopLevelMetadata(llvm::Function *Fn,
   // they are referencing.
   for (auto  : *Fn) {
 for (auto  : BB) {
+  for (llvm::DbgVariableRecord  :
+   llvm::filterDbgVars(I.getDbgRecordRange())) {
+auto *DILocal = DVR.getVariable();
+if (!DILocal->isResolved())
+  DILocal->resolve();
+  }
   if (auto *DII = dyn_cast()) {
 auto *DILocal = DII->getVariable();
 if (!DILocal->isResolved())
diff --git a/clang/test/CodeGenCXX/tmp-md-nodes2.cpp 
b/clang/test/CodeGenCXX/tmp-md-nodes2.cpp
index e50220cfb7c370..e88fb79b777ff6 100644
--- a/clang/test/CodeGenCXX/tmp-md-nodes2.cpp
+++ b/clang/test/CodeGenCXX/tmp-md-nodes2.cpp
@@ -1,6 +1,8 @@
 // REQUIRES: asserts
 // RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S 
-emit-llvm %s -o - | \
 // RUN: FileCheck %s
+// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -S 
-emit-llvm -mllvm --experimental-debuginfo-iterators=true %s -o - | \
+// RUN: FileCheck %s
 
 // This test simply checks that the varargs thunk is created. The failing test
 // case asserts.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove remaining uses of Instruction-constructors that insert before another Instruction (PR #85981)

2024-04-05 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/85981

>From b2f6d93d87082dd0ccc91a9a8094a4c3552b81a2 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 20 Mar 2024 17:43:10 +
Subject: [PATCH 1/3] Assorted fixes since rebase and outside core llvm

---
 clang/lib/CodeGen/CGCUDANV.cpp|  6 +-
 clang/lib/CodeGen/CGCall.cpp  |  4 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  8 ++-
 clang/lib/CodeGen/CGCoroutine.cpp |  5 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGObjC.cpp  |  3 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  4 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 10 +--
 llvm/examples/IRTransforms/SimplifyCFG.cpp|  7 +-
 llvm/include/llvm/IR/InstrTypes.h |  9 ---
 llvm/lib/FuzzMutate/IRMutator.cpp |  5 +-
 llvm/lib/FuzzMutate/Operations.cpp| 32 ++
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   | 17 ++---
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../deltas/ReduceOperandBundles.cpp   |  3 +-
 llvm/tools/llvm-stress/llvm-stress.cpp| 64 ++-
 16 files changed, 98 insertions(+), 85 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 0cb5b06a519c00..13660fcd69b465 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -484,9 +484,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
 }
 if (auto *I = dyn_cast(U)) {
   llvm::Value *OldV = Var;
-  llvm::Instruction *NewV =
-  new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+  llvm::Instruction *NewV = new llvm::LoadInst(
+  Var->getType(), ManagedVar, "ld.managed", false,
+  llvm::Align(Var->getAlignment()), I->getIterator());
   WorkItem.pop_back();
   // Replace constant expressions directly or indirectly using the managed
   // variable with instructions.
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index f12765b826935b..3c8c3fe9f5e6e8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5062,8 +5062,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
 llvm::AllocaInst *AI;
 if (IP) {
   IP = IP->getNextNode();
-  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
-"argmem", IP);
+  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
+IP->getIterator());
 } else {
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..3cd540c65d3b34 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -295,7 +295,8 @@ void EHScopeStack::Cleanup::anchor() {}
 static void createStoreInstBefore(llvm::Value *value, Address addr,
   llvm::Instruction *beforeInst,
   CodeGenFunction ) {
-  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), 
beforeInst);
+  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
+   beforeInst->getIterator());
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
@@ -304,7 +305,7 @@ static llvm::LoadInst *createLoadInstBefore(Address addr, 
const Twine ,
 CodeGenFunction ) {
   return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
 name, false, addr.getAlignment().getAsAlign(),
-beforeInst);
+beforeInst->getIterator());
 }
 
 /// All the branch fixups on the EH stack have propagated out past the
@@ -612,7 +613,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 llvm::SwitchInst *si = cast(use.getUser());
 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
   // Replace the switch with a branch.
-  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
+  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
+   si->getIterator());
 
   // The switch operand is a load from the cleanup-dest alloca.
   llvm::LoadInst *condition = cast(si->getCondition());
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..fcad59bb05c728 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -867,8 +867,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
 EmitStmt(S.getPromiseDeclStmt());
 
 Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
-auto *PromiseAddrVoidPtr = 

[clang] [llvm] Remove remaining uses of Instruction-constructors that insert before another Instruction (PR #85981)

2024-04-05 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/85981

>From b2f6d93d87082dd0ccc91a9a8094a4c3552b81a2 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 20 Mar 2024 17:43:10 +
Subject: [PATCH 1/2] Assorted fixes since rebase and outside core llvm

---
 clang/lib/CodeGen/CGCUDANV.cpp|  6 +-
 clang/lib/CodeGen/CGCall.cpp  |  4 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  8 ++-
 clang/lib/CodeGen/CGCoroutine.cpp |  5 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGObjC.cpp  |  3 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  4 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 10 +--
 llvm/examples/IRTransforms/SimplifyCFG.cpp|  7 +-
 llvm/include/llvm/IR/InstrTypes.h |  9 ---
 llvm/lib/FuzzMutate/IRMutator.cpp |  5 +-
 llvm/lib/FuzzMutate/Operations.cpp| 32 ++
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   | 17 ++---
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../deltas/ReduceOperandBundles.cpp   |  3 +-
 llvm/tools/llvm-stress/llvm-stress.cpp| 64 ++-
 16 files changed, 98 insertions(+), 85 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 0cb5b06a519c00..13660fcd69b465 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -484,9 +484,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
 }
 if (auto *I = dyn_cast(U)) {
   llvm::Value *OldV = Var;
-  llvm::Instruction *NewV =
-  new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+  llvm::Instruction *NewV = new llvm::LoadInst(
+  Var->getType(), ManagedVar, "ld.managed", false,
+  llvm::Align(Var->getAlignment()), I->getIterator());
   WorkItem.pop_back();
   // Replace constant expressions directly or indirectly using the managed
   // variable with instructions.
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index f12765b826935b..3c8c3fe9f5e6e8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5062,8 +5062,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
 llvm::AllocaInst *AI;
 if (IP) {
   IP = IP->getNextNode();
-  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
-"argmem", IP);
+  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
+IP->getIterator());
 } else {
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..3cd540c65d3b34 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -295,7 +295,8 @@ void EHScopeStack::Cleanup::anchor() {}
 static void createStoreInstBefore(llvm::Value *value, Address addr,
   llvm::Instruction *beforeInst,
   CodeGenFunction ) {
-  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), 
beforeInst);
+  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
+   beforeInst->getIterator());
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
@@ -304,7 +305,7 @@ static llvm::LoadInst *createLoadInstBefore(Address addr, 
const Twine ,
 CodeGenFunction ) {
   return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
 name, false, addr.getAlignment().getAsAlign(),
-beforeInst);
+beforeInst->getIterator());
 }
 
 /// All the branch fixups on the EH stack have propagated out past the
@@ -612,7 +613,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 llvm::SwitchInst *si = cast(use.getUser());
 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
   // Replace the switch with a branch.
-  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
+  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
+   si->getIterator());
 
   // The switch operand is a load from the cleanup-dest alloca.
   llvm::LoadInst *condition = cast(si->getCondition());
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..fcad59bb05c728 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -867,8 +867,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
 EmitStmt(S.getPromiseDeclStmt());
 
 Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
-auto *PromiseAddrVoidPtr = 

[clang] [llvm] Remove remaining uses of Instruction-constructors that insert before another Instruction (PR #85981)

2024-04-05 Thread Stephen Tozer via cfe-commits


@@ -1542,19 +1542,10 @@ class CallBase : public Instruction {
 OperandBundleDef OB,
 Instruction *InsertPt = nullptr);
 
-  /// Create a clone of \p CB with operand bundle \p OB added.
-  static CallBase *addOperandBundle(CallBase *CB, uint32_t ID,
-OperandBundleDef OB,
-BasicBlock::iterator InsertPt);
-
   /// Create a clone of \p CB with operand bundle \p ID removed.
   static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID,
Instruction *InsertPt = nullptr);
 
-  /// Create a clone of \p CB with operand bundle \p ID removed.
-  static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID,
-   BasicBlock::iterator InsertPt);

SLTozer wrote:

Looks like a change that accidentally snuck in while doing some git stuff, will 
reinstate.

https://github.com/llvm/llvm-project/pull/85981
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Remove remaining uses of Instruction-constructors that insert before another Instruction (PR #85981)

2024-04-05 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/85981

>From b2f6d93d87082dd0ccc91a9a8094a4c3552b81a2 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 20 Mar 2024 17:43:10 +
Subject: [PATCH] Assorted fixes since rebase and outside core llvm

---
 clang/lib/CodeGen/CGCUDANV.cpp|  6 +-
 clang/lib/CodeGen/CGCall.cpp  |  4 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  8 ++-
 clang/lib/CodeGen/CGCoroutine.cpp |  5 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGObjC.cpp  |  3 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  4 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 10 +--
 llvm/examples/IRTransforms/SimplifyCFG.cpp|  7 +-
 llvm/include/llvm/IR/InstrTypes.h |  9 ---
 llvm/lib/FuzzMutate/IRMutator.cpp |  5 +-
 llvm/lib/FuzzMutate/Operations.cpp| 32 ++
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   | 17 ++---
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../deltas/ReduceOperandBundles.cpp   |  3 +-
 llvm/tools/llvm-stress/llvm-stress.cpp| 64 ++-
 16 files changed, 98 insertions(+), 85 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 0cb5b06a519c00..13660fcd69b465 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -484,9 +484,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
 }
 if (auto *I = dyn_cast(U)) {
   llvm::Value *OldV = Var;
-  llvm::Instruction *NewV =
-  new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+  llvm::Instruction *NewV = new llvm::LoadInst(
+  Var->getType(), ManagedVar, "ld.managed", false,
+  llvm::Align(Var->getAlignment()), I->getIterator());
   WorkItem.pop_back();
   // Replace constant expressions directly or indirectly using the managed
   // variable with instructions.
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index f12765b826935b..3c8c3fe9f5e6e8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5062,8 +5062,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
 llvm::AllocaInst *AI;
 if (IP) {
   IP = IP->getNextNode();
-  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
-"argmem", IP);
+  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
+IP->getIterator());
 } else {
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..3cd540c65d3b34 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -295,7 +295,8 @@ void EHScopeStack::Cleanup::anchor() {}
 static void createStoreInstBefore(llvm::Value *value, Address addr,
   llvm::Instruction *beforeInst,
   CodeGenFunction ) {
-  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), 
beforeInst);
+  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
+   beforeInst->getIterator());
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
@@ -304,7 +305,7 @@ static llvm::LoadInst *createLoadInstBefore(Address addr, 
const Twine ,
 CodeGenFunction ) {
   return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
 name, false, addr.getAlignment().getAsAlign(),
-beforeInst);
+beforeInst->getIterator());
 }
 
 /// All the branch fixups on the EH stack have propagated out past the
@@ -612,7 +613,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 llvm::SwitchInst *si = cast(use.getUser());
 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
   // Replace the switch with a branch.
-  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
+  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
+   si->getIterator());
 
   // The switch operand is a load from the cleanup-dest alloca.
   llvm::LoadInst *condition = cast(si->getCondition());
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..fcad59bb05c728 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -867,8 +867,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
 EmitStmt(S.getPromiseDeclStmt());
 
 Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
-auto *PromiseAddrVoidPtr = new 

[clang] [llvm] Remove remaining uses of Instruction-constructors that insert before another Instruction (PR #85981)

2024-03-20 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer created 
https://github.com/llvm/llvm-project/pull/85981

Related to the work noted in 
[discourse](https://discourse.llvm.org/t/psa-instruction-constructors-changing-to-iterator-only-insertion/77845)
 and in [this](https://github.com/llvm/llvm-project/pull/85980) patch.

This removes the remaining set of callsites where instructions are created 
using constructors that take a `Instruction *InsertBefore` argument, in 
preparation for those constructors being removed. For an explanation on why we 
want to do this, see the discussions above; the short summary is that it is 
useful for ensuring that debug info placement is handled correctly, preventing 
potential errors from emerging following the RemoveDIs work. In almost all 
cases this should be NFC, except for a few cases where `getFirstNonPHI()` is 
replaced by `getFirstNonPHIIt()`, which may prevent a possible error from 
occurring. 

>From 4e532de826d9ad1e6c5bfbc43ae84242f663ac25 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 20 Mar 2024 17:43:10 +
Subject: [PATCH] Assorted fixes since rebase and outside core llvm

---
 clang/lib/CodeGen/CGCUDANV.cpp|  6 +-
 clang/lib/CodeGen/CGCall.cpp  |  4 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  8 ++-
 clang/lib/CodeGen/CGCoroutine.cpp |  4 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGObjC.cpp  |  3 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 10 +--
 llvm/examples/IRTransforms/SimplifyCFG.cpp|  7 +-
 llvm/include/llvm/IR/InstrTypes.h |  9 ---
 llvm/lib/FuzzMutate/IRMutator.cpp |  5 +-
 llvm/lib/FuzzMutate/Operations.cpp| 32 ++
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   | 17 ++---
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../deltas/ReduceOperandBundles.cpp   |  3 +-
 llvm/tools/llvm-stress/llvm-stress.cpp| 64 ++-
 16 files changed, 97 insertions(+), 84 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index d3f2573fd5e38a..810e259f62eb04 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -483,9 +483,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
 }
 if (auto *I = dyn_cast(U)) {
   llvm::Value *OldV = Var;
-  llvm::Instruction *NewV =
-  new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+  llvm::Instruction *NewV = new llvm::LoadInst(
+  Var->getType(), ManagedVar, "ld.managed", false,
+  llvm::Align(Var->getAlignment()), I->getIterator());
   WorkItem.pop_back();
   // Replace constant expressions directly or indirectly using the managed
   // variable with instructions.
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index a28d7888715d85..08ef4b335bf6b6 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5033,8 +5033,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
 llvm::AllocaInst *AI;
 if (IP) {
   IP = IP->getNextNode();
-  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
-"argmem", IP);
+  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
+IP->getIterator());
 } else {
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index f87caf050eeaa7..55ab497193acbe 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -323,7 +323,8 @@ void EHScopeStack::Cleanup::anchor() {}
 
 static void createStoreInstBefore(llvm::Value *value, Address addr,
   llvm::Instruction *beforeInst) {
-  auto store = new llvm::StoreInst(value, addr.getPointer(), beforeInst);
+  auto store =
+  new llvm::StoreInst(value, addr.getPointer(), beforeInst->getIterator());
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
@@ -331,7 +332,7 @@ static llvm::LoadInst *createLoadInstBefore(Address addr, 
const Twine ,
 llvm::Instruction *beforeInst) {
   return new llvm::LoadInst(addr.getElementType(), addr.getPointer(), name,
 false, addr.getAlignment().getAsAlign(),
-beforeInst);
+beforeInst->getIterator());
 }
 
 /// All the branch fixups on the EH stack have propagated out past the
@@ -639,7 +640,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 llvm::SwitchInst *si = cast(use.getUser());
 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
   // Replace the switch with a branch.
-  

[clang] [llvm] [RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (PR #85216)

2024-03-19 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/85216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9a96fb4 - Reapply "[NFC][RemoveDIs] Switch ConstantExpr::getAsInstruction to not insert (#84737)"

2024-03-19 Thread Stephen Tozer via cfe-commits

Author: Stephen Tozer
Date: 2024-03-19T15:49:10Z
New Revision: 9a96fb4445f4e9d9a7899189758ee6afbeb6510b

URL: 
https://github.com/llvm/llvm-project/commit/9a96fb4445f4e9d9a7899189758ee6afbeb6510b
DIFF: 
https://github.com/llvm/llvm-project/commit/9a96fb4445f4e9d9a7899189758ee6afbeb6510b.diff

LOG: Reapply "[NFC][RemoveDIs] Switch ConstantExpr::getAsInstruction to not 
insert (#84737)"

Fixes a build error caused by an unupdated getAsInstruction callsite in clang.

This reverts commit ab851f7fe946e7eed700ef9d82082eb721860189.

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
llvm/include/llvm/IR/Constants.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/IR/ReplaceConstant.cpp
llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 49f93451db7bbb..d3f2573fd5e38a 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -491,7 +491,8 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
   // variable with instructions.
   for (auto & : WorkItem) {
 auto *CE = cast(Op);
-auto *NewInst = CE->getAsInstruction(I);
+auto *NewInst = CE->getAsInstruction();
+NewInst->insertBefore(*I->getParent(), I->getIterator());
 NewInst->replaceUsesOfWith(OldV, NewV);
 OldV = CE;
 NewV = NewInst;

diff  --git a/llvm/include/llvm/IR/Constants.h 
b/llvm/include/llvm/IR/Constants.h
index c0ac9a4aa6750c..c5e1e19d649824 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -1289,14 +1289,13 @@ class ConstantExpr : public Constant {
 Type *SrcTy = nullptr) const;
 
   /// Returns an Instruction which implements the same operation as this
-  /// ConstantExpr. If \p InsertBefore is not null, the new instruction is
-  /// inserted before it, otherwise it is not inserted into any basic block.
+  /// ConstantExpr. It is not inserted into any basic block.
   ///
   /// A better approach to this could be to have a constructor for Instruction
   /// which would take a ConstantExpr parameter, but that would have spread
   /// implementation details of ConstantExpr outside of Constants.cpp, which
   /// would make it harder to remove ConstantExprs altogether.
-  Instruction *getAsInstruction(Instruction *InsertBefore = nullptr) const;
+  Instruction *getAsInstruction() const;
 
   /// Whether creating a constant expression for this binary operator is
   /// desirable.

diff  --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index c07ee34bfb7a6b..16507a69ea8502 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -5073,10 +5073,15 @@ FunctionCallee 
OpenMPIRBuilder::createDispatchFiniFunction(unsigned IVSize,
 
 static void replaceConstatExprUsesInFuncWithInstr(ConstantExpr *ConstExpr,
   Function *Func) {
-  for (User *User : make_early_inc_range(ConstExpr->users()))
-if (auto *Instr = dyn_cast(User))
-  if (Instr->getFunction() == Func)
-Instr->replaceUsesOfWith(ConstExpr, 
ConstExpr->getAsInstruction(Instr));
+  for (User *User : make_early_inc_range(ConstExpr->users())) {
+if (auto *Instr = dyn_cast(User)) {
+  if (Instr->getFunction() == Func) {
+Instruction *ConstInst = ConstExpr->getAsInstruction();
+ConstInst->insertBefore(*Instr->getParent(), Instr->getIterator());
+Instr->replaceUsesOfWith(ConstExpr, ConstInst);
+  }
+}
+  }
 }
 
 static void replaceConstantValueUsesInFuncWithInstr(llvm::Value *Input,

diff  --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index e6b92aad392f66..07b5bced96dae9 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -3303,7 +3303,7 @@ Value *ConstantExpr::handleOperandChangeImpl(Value *From, 
Value *ToV) {
   NewOps, this, From, To, NumUpdated, OperandNo);
 }
 
-Instruction *ConstantExpr::getAsInstruction(Instruction *InsertBefore) const {
+Instruction *ConstantExpr::getAsInstruction() const {
   SmallVector ValueOperands(operands());
   ArrayRef Ops(ValueOperands);
 
@@ -3322,32 +3322,31 @@ Instruction *ConstantExpr::getAsInstruction(Instruction 
*InsertBefore) const {
   case Instruction::BitCast:
   case Instruction::AddrSpaceCast:
 return CastInst::Create((Instruction::CastOps)getOpcode(), Ops[0],
-getType(), "", InsertBefore);
+getType(), "");
   case Instruction::InsertElement:
-return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "", InsertBefore);
+return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "");
   case Instruction::ExtractElement:
-return ExtractElementInst::Create(Ops[0], Ops[1], "", 

[clang] [RemoveDIs] Update Clang front end to handle DbgRecords (PR #84756)

2024-03-18 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer approved this pull request.

It's been a bit without any comments, probably safe now to land this.

https://github.com/llvm/llvm-project/pull/84756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RemoveDIs] Update Clang front end to handle DbgRecords (PR #84756)

2024-03-11 Thread Stephen Tozer via cfe-commits


@@ -4746,20 +4746,32 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
   if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
 (void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
 CGF.Builder, false);
-  llvm::Instruction  = CGF.Builder.GetInsertBlock()->back();
   // Get the call dbg.declare instruction we just created and update
   // its DIExpression to add offset to base address.
-  if (auto DDI = dyn_cast()) {
+  auto UpdateExpr = [](llvm::LLVMContext , auto *DDI,

SLTozer wrote:

Super nit, but in situations like this I prefer to change things like `DDI` to 
`Declare`; subjective, so non-blocking.

https://github.com/llvm/llvm-project/pull/84756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RemoveDIs] Update Clang front end to handle DbgRecords (PR #84756)

2024-03-11 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer commented:

Maybe wants someone with more frontend knowledge to chime in, but all SGTM.

https://github.com/llvm/llvm-project/pull/84756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RemoveDIs] Update Clang front end to handle DbgRecords (PR #84756)

2024-03-11 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/84756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)

2024-02-27 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/80480

>From 4d280199a9eb027127bdc9c31a266fa3e2fa6cea Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 22 Aug 2023 15:24:03 +
Subject: [PATCH 1/2] [CMAKE] Enable FatLTO as a build option for LLVM

---
 clang/cmake/caches/Fuchsia-stage2.cmake|  1 +
 llvm/cmake/modules/AddLLVM.cmake   | 11 +--
 llvm/cmake/modules/HandleLLVMOptions.cmake |  6 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index eee37c5e7901fa..d5a1662cbf4aa6 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
 set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
 set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 3bc78b0dc9355a..02107775904d48 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1621,8 +1621,15 @@ function(add_unittest test_suite test_name)
   # The runtime benefits of LTO don't outweight the compile time costs for 
tests.
   if(LLVM_ENABLE_LTO)
 if((UNIX OR MINGW) AND LINKER_IS_LLD)
-  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
-LINK_FLAGS " -Wl,--lto-O0")
+  if(LLVM_ENABLE_FATLTO)
+# When using FatLTO, just use relocatable linking.
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--no-fat-lto-objects")
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS 
" -fno-lto")
+  else()
+set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+  LINK_FLAGS " -Wl,--lto-O0")
+  endif()
 elseif(LINKER_IS_LLD_LINK)
   set_property(TARGET ${test_name} APPEND_STRING PROPERTY
 LINK_FLAGS " /opt:lldlto=0")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 08ff49ded57a14..27b3ebf9a3466f 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
 set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as 
Thin or Full to use a particular kind of LTO")
 string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
 
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
 # Ninja Job Pool support
 # The following only works with the Ninja generator in CMake >= 3.0.
 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1259,6 +1261,10 @@ elseif(LLVM_ENABLE_LTO)
   endif()
 endif()
 
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are
 # doing dynamic linking (see below).
 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

>From 84c61d94608c323e851202505f49d6a577c4f64d Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 2 Feb 2024 13:09:18 -0800
Subject: [PATCH 2/2] Add -ffat-lto-objects to CMAKE_C_FLAGS and
 CMAKE_CXX_FLAGS

---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 27b3ebf9a3466f..e23d8d46272c4b 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1262,7 +1262,10 @@ elseif(LLVM_ENABLE_LTO)
 endif()
 
 if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+  append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+  if(NOT LINKER_IS_LLD_LINK)
 append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+  endif()
 endif()
 
 # Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we 
are

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang-tools-extra] [DebugInfo][RemoveDIs] Don't allocate one DPMarker per instruction (PR #79345)

2024-02-06 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer approved this pull request.


https://github.com/llvm/llvm-project/pull/79345
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [DebugInfo][RemoveDIs] Add a DPValue implementation for instcombine sinking (PR #77930)

2024-01-25 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer approved this pull request.

LGTM with latest changes.

https://github.com/llvm/llvm-project/pull/77930
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [DebugInfo][RemoveDIs] Add a DPValue implementation for instcombine sinking (PR #77930)

2024-01-25 Thread Stephen Tozer via cfe-commits


@@ -4266,19 +4285,140 @@ bool 
InstCombinerImpl::tryToSinkInstruction(Instruction *I,
 
   // Perform salvaging without the clones, then sink the clones.
   if (!DIIClones.empty()) {
-// RemoveDIs: pass in empty vector of DPValues until we get to 
instrumenting
-// this pass.
-SmallVector DummyDPValues;
-salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, DummyDPValues);
+salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, {});
 // The clones are in reverse order of original appearance, reverse again to
 // maintain the original order.
 for (auto  : llvm::reverse(DIIClones)) {
   DIIClone->insertBefore(&*InsertPos);
   LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n');
 }
   }
+}
 
-  return true;
+void InstCombinerImpl::tryToSinkInstructionDPValues(
+Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
+BasicBlock *DestBlock, SmallVectorImpl ) {
+  // Implementation of tryToSinkInstructionDbgValues, but for the DPValue of
+  // variable assignments rather than dbg.values.
+
+  // Fetch all DPValues not already in the destination.
+  SmallVector DPValuesToSalvage;
+  for (auto  : DPValues)
+if (DPV->getParent() != DestBlock)
+  DPValuesToSalvage.push_back(DPV);
+
+  // Fetch a second collection, of DPValues in the source block that we're 
going
+  // to sink.
+  SmallVector DPValuesToSink;
+  for (DPValue *DPV : DPValuesToSalvage)
+if (DPV->getParent() == SrcBlock)
+  DPValuesToSink.push_back(DPV);
+
+  // Sort DPValues according to their position in the block. This is a partial

SLTozer wrote:

I actually thinking about the performance of removing all the 
filtermap/duplicate detection logic and just iterating over getDbgValueRange() 
to determine whether A or B comes first when they're attached to the same 
instruction - I submitted a quick test to the compile time tracker[0] though 
and it looks like it's neutral for most cases and a slowdown in the bad case 
(testing specifically with RemoveDIs enabled), so I'm happy with this approach.
[0] 
http://llvm-compile-time-tracker.com/compare.php?from=319280746b199b35c49798383b6dd4c01286c5ff=c29a7ff328a4148aabd7e147f2bfc04e9801fcb6=instructions:u

https://github.com/llvm/llvm-project/pull/77930
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-10-18 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer closed 
https://github.com/llvm/llvm-project/pull/66632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-10-18 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/66632

>From eccff5693ebcaac45a7ddf56cbb33a48de281041 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 18 Sep 2023 09:59:11 +0100
Subject: [PATCH 1/3] [LLVM] Add new attribute `optdebug` to optimize for
 debugging

This patch adds a new fn attribute, `optdebug`, that specifies that
optimizations should make decisions that prioritize debug info quality,
potentially at the cost of runtime performance.

This patch does not add any functional changes triggered by this attribute,
only the attribute itself.
---
 clang/lib/CodeGen/CodeGenModule.cpp | 1 +
 llvm/docs/BitCodeFormat.rst | 1 +
 llvm/docs/LangRef.rst   | 4 
 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 +
 llvm/include/llvm/IR/Attributes.td  | 3 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp   | 2 ++
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp   | 2 ++
 llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 +
 llvm/test/Bitcode/attributes.ll | 7 +++
 llvm/utils/emacs/llvm-mode.el   | 2 +-
 llvm/utils/kate/llvm.xml| 1 +
 llvm/utils/vim/syntax/llvm.vim  | 1 +
 12 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b1a6683a66bd052..875952232e24b86 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2347,6 +2347,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::Naked);
 
 // OptimizeNone wins over OptimizeForSize and MinSize.
+F->removeFnAttr(llvm::Attribute::OptimizeForDebugging);
 F->removeFnAttr(llvm::Attribute::OptimizeForSize);
 F->removeFnAttr(llvm::Attribute::MinSize);
   } else if (D->hasAttr()) {
diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index db913f59d691d71..5742f8594e99908 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1093,6 +1093,7 @@ The integer codes are mapped to well-known attributes as 
follows.
 * code 85: ``skipprofile``
 * code 86: ``memory``
 * code 87: ``nofpclass``
+* code 88: ``optdebug``
 
 .. note::
   The ``allocsize`` attribute has a special encoding for its arguments. Its two
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 798b0ab6c593ab4..b74c61d8a9aed9c 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2025,6 +2025,10 @@ example:
Note: Comparing address of a global variable to ``null`` may still
evaluate to false because of a limitation in querying this attribute inside
constant expressions.
+``optdebug``
+This attribute suggests that optimization passes and code generator passes
+should make choices that try to preserve debug info without significantly
+degrading runtime performance.
 ``optforfuzzing``
 This attribute indicates that this function should be optimized
 for maximum fuzzing signal.
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 52e76356a892e45..5d7be5ca936ad37 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -713,6 +713,7 @@ enum AttributeKindCodes {
   ATTR_KIND_SKIP_PROFILE = 85,
   ATTR_KIND_MEMORY = 86,
   ATTR_KIND_NOFPCLASS = 87,
+  ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88,
 };
 
 enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index aba1d718f7f72f9..fda79f5f24495fb 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", 
[FnAttr]>;
 /// Null pointer in address space zero is valid.
 def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>;
 
+/// Select optimizations that give decent debug info.
+def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>;
+
 /// Select optimizations for best fuzzing signal.
 def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>;
 
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1d1ec988a93d847..16eafa6e18f5d59 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) 
{
 return Attribute::NoSanitizeCoverage;
   case bitc::ATTR_KIND_NULL_POINTER_IS_VALID:
 return Attribute::NullPointerIsValid;
+  case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING:
+return Attribute::OptimizeForDebugging;
   case bitc::ATTR_KIND_OPT_FOR_FUZZING:
 return Attribute::OptForFuzzing;
   case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE:
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index e991d055f33474b..c427459508ecfc8 100644
--- 

[clang-tools-extra] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-10-18 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/66632

>From 18f494a4006b4c21b364a91107d4a07ceaf88213 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 18 Sep 2023 09:59:11 +0100
Subject: [PATCH 1/3] [LLVM] Add new attribute `optdebug` to optimize for
 debugging

This patch adds a new fn attribute, `optdebug`, that specifies that
optimizations should make decisions that prioritize debug info quality,
potentially at the cost of runtime performance.

This patch does not add any functional changes triggered by this attribute,
only the attribute itself.
---
 clang/lib/CodeGen/CodeGenModule.cpp | 1 +
 llvm/docs/BitCodeFormat.rst | 1 +
 llvm/docs/LangRef.rst   | 4 
 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 +
 llvm/include/llvm/IR/Attributes.td  | 3 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp   | 2 ++
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp   | 2 ++
 llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 +
 llvm/test/Bitcode/attributes.ll | 7 +++
 llvm/utils/emacs/llvm-mode.el   | 2 +-
 llvm/utils/kate/llvm.xml| 1 +
 llvm/utils/vim/syntax/llvm.vim  | 1 +
 12 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8b0c9340775cbe9..96d053a6aa8f9e5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2325,6 +2325,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::Naked);
 
 // OptimizeNone wins over OptimizeForSize and MinSize.
+F->removeFnAttr(llvm::Attribute::OptimizeForDebugging);
 F->removeFnAttr(llvm::Attribute::OptimizeForSize);
 F->removeFnAttr(llvm::Attribute::MinSize);
   } else if (D->hasAttr()) {
diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index 70be73abef19d6d..ce0e29fb6b928a7 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as 
follows.
 * code 77: ``elementtype``
 * code 78: ``disable_sanitizer_instrumentation``
 * code 79: ``nosanitize_bounds``
+* code 88: ``optdebug``
 
 .. note::
   The ``allocsize`` attribute has a special encoding for its arguments. Its two
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f542e70bcfee810..fa274fdb66a5047 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2024,6 +2024,10 @@ example:
Note: Comparing address of a global variable to ``null`` may still
evaluate to false because of a limitation in querying this attribute inside
constant expressions.
+``optdebug``
+This attribute suggests that optimization passes and code generator passes
+should make choices that try to preserve debug info without significantly
+degrading runtime performance.
 ``optforfuzzing``
 This attribute indicates that this function should be optimized
 for maximum fuzzing signal.
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 52e76356a892e45..5d7be5ca936ad37 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -713,6 +713,7 @@ enum AttributeKindCodes {
   ATTR_KIND_SKIP_PROFILE = 85,
   ATTR_KIND_MEMORY = 86,
   ATTR_KIND_NOFPCLASS = 87,
+  ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88,
 };
 
 enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index aba1d718f7f72f9..fda79f5f24495fb 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", 
[FnAttr]>;
 /// Null pointer in address space zero is valid.
 def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>;
 
+/// Select optimizations that give decent debug info.
+def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>;
+
 /// Select optimizations for best fuzzing signal.
 def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>;
 
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1d1ec988a93d847..16eafa6e18f5d59 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) 
{
 return Attribute::NoSanitizeCoverage;
   case bitc::ATTR_KIND_NULL_POINTER_IS_VALID:
 return Attribute::NullPointerIsValid;
+  case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING:
+return Attribute::OptimizeForDebugging;
   case bitc::ATTR_KIND_OPT_FOR_FUZZING:
 return Attribute::OptForFuzzing;
   case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE:
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 

[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-10-13 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> looks good - a few bits should be committed separately from this change, so 
> please do those first and then commit this change

Separate review opened up at: https://github.com/llvm/llvm-project/pull/68967

For simplicity's sake I'll keep this patch as-is, and rebase it when the other 
patch lands.

https://github.com/llvm/llvm-project/pull/66632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-10-12 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

Small ping - all comments have now been addressed now I think.

https://github.com/llvm/llvm-project/pull/66632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-10-12 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/66632

>From 18f494a4006b4c21b364a91107d4a07ceaf88213 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 18 Sep 2023 09:59:11 +0100
Subject: [PATCH 1/3] [LLVM] Add new attribute `optdebug` to optimize for
 debugging

This patch adds a new fn attribute, `optdebug`, that specifies that
optimizations should make decisions that prioritize debug info quality,
potentially at the cost of runtime performance.

This patch does not add any functional changes triggered by this attribute,
only the attribute itself.
---
 clang/lib/CodeGen/CodeGenModule.cpp | 1 +
 llvm/docs/BitCodeFormat.rst | 1 +
 llvm/docs/LangRef.rst   | 4 
 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 +
 llvm/include/llvm/IR/Attributes.td  | 3 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp   | 2 ++
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp   | 2 ++
 llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 +
 llvm/test/Bitcode/attributes.ll | 7 +++
 llvm/utils/emacs/llvm-mode.el   | 2 +-
 llvm/utils/kate/llvm.xml| 1 +
 llvm/utils/vim/syntax/llvm.vim  | 1 +
 12 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8b0c9340775cbe9..96d053a6aa8f9e5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2325,6 +2325,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::Naked);
 
 // OptimizeNone wins over OptimizeForSize and MinSize.
+F->removeFnAttr(llvm::Attribute::OptimizeForDebugging);
 F->removeFnAttr(llvm::Attribute::OptimizeForSize);
 F->removeFnAttr(llvm::Attribute::MinSize);
   } else if (D->hasAttr()) {
diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index 70be73abef19d6d..ce0e29fb6b928a7 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as 
follows.
 * code 77: ``elementtype``
 * code 78: ``disable_sanitizer_instrumentation``
 * code 79: ``nosanitize_bounds``
+* code 88: ``optdebug``
 
 .. note::
   The ``allocsize`` attribute has a special encoding for its arguments. Its two
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f542e70bcfee810..fa274fdb66a5047 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2024,6 +2024,10 @@ example:
Note: Comparing address of a global variable to ``null`` may still
evaluate to false because of a limitation in querying this attribute inside
constant expressions.
+``optdebug``
+This attribute suggests that optimization passes and code generator passes
+should make choices that try to preserve debug info without significantly
+degrading runtime performance.
 ``optforfuzzing``
 This attribute indicates that this function should be optimized
 for maximum fuzzing signal.
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 52e76356a892e45..5d7be5ca936ad37 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -713,6 +713,7 @@ enum AttributeKindCodes {
   ATTR_KIND_SKIP_PROFILE = 85,
   ATTR_KIND_MEMORY = 86,
   ATTR_KIND_NOFPCLASS = 87,
+  ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88,
 };
 
 enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index aba1d718f7f72f9..fda79f5f24495fb 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", 
[FnAttr]>;
 /// Null pointer in address space zero is valid.
 def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>;
 
+/// Select optimizations that give decent debug info.
+def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>;
+
 /// Select optimizations for best fuzzing signal.
 def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>;
 
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1d1ec988a93d847..16eafa6e18f5d59 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) 
{
 return Attribute::NoSanitizeCoverage;
   case bitc::ATTR_KIND_NULL_POINTER_IS_VALID:
 return Attribute::NullPointerIsValid;
+  case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING:
+return Attribute::OptimizeForDebugging;
   case bitc::ATTR_KIND_OPT_FOR_FUZZING:
 return Attribute::OptForFuzzing;
   case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE:
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 

[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-09-21 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/66632

>From 18f494a4006b4c21b364a91107d4a07ceaf88213 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 18 Sep 2023 09:59:11 +0100
Subject: [PATCH 1/2] [LLVM] Add new attribute `optdebug` to optimize for
 debugging

This patch adds a new fn attribute, `optdebug`, that specifies that
optimizations should make decisions that prioritize debug info quality,
potentially at the cost of runtime performance.

This patch does not add any functional changes triggered by this attribute,
only the attribute itself.
---
 clang/lib/CodeGen/CodeGenModule.cpp | 1 +
 llvm/docs/BitCodeFormat.rst | 1 +
 llvm/docs/LangRef.rst   | 4 
 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 +
 llvm/include/llvm/IR/Attributes.td  | 3 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp   | 2 ++
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp   | 2 ++
 llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 +
 llvm/test/Bitcode/attributes.ll | 7 +++
 llvm/utils/emacs/llvm-mode.el   | 2 +-
 llvm/utils/kate/llvm.xml| 1 +
 llvm/utils/vim/syntax/llvm.vim  | 1 +
 12 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8b0c9340775cbe9..96d053a6aa8f9e5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2325,6 +2325,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::Naked);
 
 // OptimizeNone wins over OptimizeForSize and MinSize.
+F->removeFnAttr(llvm::Attribute::OptimizeForDebugging);
 F->removeFnAttr(llvm::Attribute::OptimizeForSize);
 F->removeFnAttr(llvm::Attribute::MinSize);
   } else if (D->hasAttr()) {
diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index 70be73abef19d6d..ce0e29fb6b928a7 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as 
follows.
 * code 77: ``elementtype``
 * code 78: ``disable_sanitizer_instrumentation``
 * code 79: ``nosanitize_bounds``
+* code 88: ``optdebug``
 
 .. note::
   The ``allocsize`` attribute has a special encoding for its arguments. Its two
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f542e70bcfee810..fa274fdb66a5047 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2024,6 +2024,10 @@ example:
Note: Comparing address of a global variable to ``null`` may still
evaluate to false because of a limitation in querying this attribute inside
constant expressions.
+``optdebug``
+This attribute suggests that optimization passes and code generator passes
+should make choices that try to preserve debug info without significantly
+degrading runtime performance.
 ``optforfuzzing``
 This attribute indicates that this function should be optimized
 for maximum fuzzing signal.
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 52e76356a892e45..5d7be5ca936ad37 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -713,6 +713,7 @@ enum AttributeKindCodes {
   ATTR_KIND_SKIP_PROFILE = 85,
   ATTR_KIND_MEMORY = 86,
   ATTR_KIND_NOFPCLASS = 87,
+  ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88,
 };
 
 enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index aba1d718f7f72f9..fda79f5f24495fb 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", 
[FnAttr]>;
 /// Null pointer in address space zero is valid.
 def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>;
 
+/// Select optimizations that give decent debug info.
+def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>;
+
 /// Select optimizations for best fuzzing signal.
 def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>;
 
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1d1ec988a93d847..16eafa6e18f5d59 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) 
{
 return Attribute::NoSanitizeCoverage;
   case bitc::ATTR_KIND_NULL_POINTER_IS_VALID:
 return Attribute::NullPointerIsValid;
+  case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING:
+return Attribute::OptimizeForDebugging;
   case bitc::ATTR_KIND_OPT_FOR_FUZZING:
 return Attribute::OptForFuzzing;
   case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE:
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 

[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-09-20 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

Making this attribute mutually exclusive with `optdebug` and `optsize` is fine 
with me - as a question for the esteemed reviewers of this patch, would it be 
preferred to add this exclusivity and associated verifier checks in a separate 
patch, or as part of this patch?

https://github.com/llvm/llvm-project/pull/66632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-19 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/65699

>From f4271e03667b64c8d10d7e4de16e78b37e845229 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Fri, 8 Sep 2023 00:21:59 +0100
Subject: [PATCH 1/2] AS_cast the argument to `eh_typeid_for` iff typeinfo is
 not in the default AS.

---
 clang/lib/CodeGen/CGException.cpp |  5 +++-
 .../try-catch-with-address-space.cpp  | 25 +++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/try-catch-with-address-space.cpp

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 3996f2948349cb5..49cf4ec4b84307b 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction ,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;
diff --git a/clang/test/CodeGenCXX/try-catch-with-address-space.cpp 
b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
new file mode 100644
index 000..279d29f50fd4101
--- /dev/null
+++ b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+
+struct X { };
+
+const X g();
+
+void f() {
+  try {
+throw g();
+// CHECK: ptr addrspace(1) @_ZTI1X
+  } catch (const X x) {
+// CHECK: catch ptr addrspace(1) @_ZTI1X
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTI1X to ptr))
+  }
+}
+
+void h() {
+  try {
+throw "ABC";
+// CHECK: ptr addrspace(1) @_ZTIPKc
+  } catch (char const(&)[4]) {
+// CHECK: catch ptr addrspace(1) @_ZTIA4_c
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTIA4_c to ptr))
+  }
+}

>From 938c798b39be0fd03f1e6c57ce7dd39c93145acb Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Sun, 10 Sep 2023 15:45:10 +0100
Subject: [PATCH 2/2] Switch to using the target hook for the as-cast.

---
 clang/lib/CodeGen/CGException.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 49cf4ec4b84307b..87594f71b26ec53 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1136,6 +1136,8 @@ static void emitCatchDispatchBlock(CodeGenFunction ,
   // Select the right handler.
   llvm::Function *llvm_eh_typeid_for =
 CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
+  llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+  LangAS globAS = CGF.CGM.GetGlobalVarAddressSpace(nullptr);
 
   // Load the selector value.
   llvm::Value *selector = CGF.getSelectorFromSlot();
@@ -1149,10 +1151,11 @@ static void emitCatchDispatchBlock(CodeGenFunction ,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
 // With opaque ptrs, only the address space can be a mismatch.
 if (typeValue->getType() != argTy)
-  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
+  typeValue =
+CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue, globAS,
+  LangAS::Default, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-09-19 Thread Stephen Tozer via cfe-commits


@@ -2325,6 +2325,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::Naked);
 
 // OptimizeNone wins over OptimizeForSize and MinSize.
+F->removeFnAttr(llvm::Attribute::OptimizeForDebugging);

SLTozer wrote:

Topic posted: 
https://discourse.llvm.org/t/rfc-new-function-attribute-optdebug-for-prioritizing-debuggability-in-llvm-passes/73552

https://github.com/llvm/llvm-project/pull/66632
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)

2023-09-18 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer created 
https://github.com/llvm/llvm-project/pull/66632

This patch adds a new fn attribute, `optdebug`, that specifies that 
optimizations should make decisions that prioritize debug info quality, 
potentially at the cost of runtime performance.

This patch does not add any functional changes triggered by this attribute, 
only the attribute itself. A subsequent patch will use this flag to disable the 
post-RA scheduler.

I've added the reviewers of the original patch (D157615), i.e. debug info 
codeowners and the others who left comments; as far as I'm aware there isn't a 
codeowner for "attributes", but if there's some owned category that applies 
then lmk and I'll add the relevant reviewer.

>From 18f494a4006b4c21b364a91107d4a07ceaf88213 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 18 Sep 2023 09:59:11 +0100
Subject: [PATCH] [LLVM] Add new attribute `optdebug` to optimize for debugging

This patch adds a new fn attribute, `optdebug`, that specifies that
optimizations should make decisions that prioritize debug info quality,
potentially at the cost of runtime performance.

This patch does not add any functional changes triggered by this attribute,
only the attribute itself.
---
 clang/lib/CodeGen/CodeGenModule.cpp | 1 +
 llvm/docs/BitCodeFormat.rst | 1 +
 llvm/docs/LangRef.rst   | 4 
 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 +
 llvm/include/llvm/IR/Attributes.td  | 3 +++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp   | 2 ++
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp   | 2 ++
 llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 +
 llvm/test/Bitcode/attributes.ll | 7 +++
 llvm/utils/emacs/llvm-mode.el   | 2 +-
 llvm/utils/kate/llvm.xml| 1 +
 llvm/utils/vim/syntax/llvm.vim  | 1 +
 12 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8b0c9340775cbe9..96d053a6aa8f9e5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2325,6 +2325,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::Naked);
 
 // OptimizeNone wins over OptimizeForSize and MinSize.
+F->removeFnAttr(llvm::Attribute::OptimizeForDebugging);
 F->removeFnAttr(llvm::Attribute::OptimizeForSize);
 F->removeFnAttr(llvm::Attribute::MinSize);
   } else if (D->hasAttr()) {
diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst
index 70be73abef19d6d..ce0e29fb6b928a7 100644
--- a/llvm/docs/BitCodeFormat.rst
+++ b/llvm/docs/BitCodeFormat.rst
@@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as 
follows.
 * code 77: ``elementtype``
 * code 78: ``disable_sanitizer_instrumentation``
 * code 79: ``nosanitize_bounds``
+* code 88: ``optdebug``
 
 .. note::
   The ``allocsize`` attribute has a special encoding for its arguments. Its two
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f542e70bcfee810..fa274fdb66a5047 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2024,6 +2024,10 @@ example:
Note: Comparing address of a global variable to ``null`` may still
evaluate to false because of a limitation in querying this attribute inside
constant expressions.
+``optdebug``
+This attribute suggests that optimization passes and code generator passes
+should make choices that try to preserve debug info without significantly
+degrading runtime performance.
 ``optforfuzzing``
 This attribute indicates that this function should be optimized
 for maximum fuzzing signal.
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h 
b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index 52e76356a892e45..5d7be5ca936ad37 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -713,6 +713,7 @@ enum AttributeKindCodes {
   ATTR_KIND_SKIP_PROFILE = 85,
   ATTR_KIND_MEMORY = 86,
   ATTR_KIND_NOFPCLASS = 87,
+  ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88,
 };
 
 enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index aba1d718f7f72f9..fda79f5f24495fb 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", 
[FnAttr]>;
 /// Null pointer in address space zero is valid.
 def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>;
 
+/// Select optimizations that give decent debug info.
+def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>;
+
 /// Select optimizations for best fuzzing signal.
 def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>;
 
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1d1ec988a93d847..16eafa6e18f5d59 100644
---