[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-04-29 Thread Sergei Barannikov via cfe-commits


@@ -21,6 +21,12 @@ char f_int_4(char x) { return x; }
 // CHECK-LABEL: define{{.*}} fp128 @f_ld(fp128 noundef %x)
 long double f_ld(long double x) { return x; }
 
+// Empty struct is lowered as a placeholder word parameter.
+struct empty {};
+
+// CHECK-LABEL: define{{.*}} i64 @f_empty(i64 %x.coerce)
+struct empty f_empty(struct empty x) { return x; }
+

s-barannikov wrote:

There are corner cases like a struct with an empty base class or a struct with 
flexible array member (or a sturct containing such struct / array of 
structs...). These needs to be tested, too. See `isEmptyRecord` if it can help.
There are also functions with variadic arguments, they also need to be tested.


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


[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-04-29 Thread Sergei Barannikov via cfe-commits


@@ -263,7 +263,10 @@ SparcV9ABIInfo::classifyType(QualType Ty, unsigned 
SizeLimit) const {
 
   CoerceBuilder CB(getVMContext(), getDataLayout());
   CB.addStruct(0, StrTy);
-  CB.pad(llvm::alignTo(CB.DL.getTypeSizeInBits(StrTy), 64));
+  // All structs, even empty ones, should take up a register argument slot,
+  // so pin the minimum struct size to one bit.
+  CB.pad(llvm::alignTo(
+  std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(), 1UL), 64));

s-barannikov wrote:

A slightly more cleaner way of handling this would be to
`return ABIArgInfo::getDirect(llvm::Type::getInt64Ty(getVMContext()));`
early.


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


[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-05-07 Thread Sergei Barannikov via cfe-commits


@@ -21,6 +21,12 @@ char f_int_4(char x) { return x; }
 // CHECK-LABEL: define{{.*}} fp128 @f_ld(fp128 noundef %x)
 long double f_ld(long double x) { return x; }
 
+// Empty struct is lowered as a placeholder word parameter.
+struct empty {};
+
+// CHECK-LABEL: define{{.*}} i64 @f_empty(i64 %x.coerce)
+struct empty f_empty(struct empty x) { return x; }
+

s-barannikov wrote:

My concern is that gcc might have different rules for passing C++ classes with 
empty base class compared to empty C structs. Can you check that the clang C++ 
behavior matches gcc and possibly add a test if it is not there yet?


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


[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-05-13 Thread Sergei Barannikov via cfe-commits


@@ -21,6 +21,12 @@ char f_int_4(char x) { return x; }
 // CHECK-LABEL: define{{.*}} fp128 @f_ld(fp128 noundef %x)
 long double f_ld(long double x) { return x; }
 
+// Empty struct is lowered as a placeholder word parameter.
+struct empty {};
+
+// CHECK-LABEL: define{{.*}} i64 @f_empty(i64 %x.coerce)
+struct empty f_empty(struct empty x) { return x; }
+

s-barannikov wrote:

Yes, thank you

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


[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-05-13 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] [clang-tools-extra] [libcxx] [lldb] [llvm] Add clang basic module directory (PR #93388)

2024-05-26 Thread Sergei Barannikov via cfe-commits


@@ -11,7 +11,7 @@
 //

s-barannikov wrote:

I guess this file should've been removed.


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


[clang] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) (PR #75668)

2023-12-16 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] a7fbca4 - [NFC] Extract `CodeGenInstAlias` into its own *.h/*.cpp

2023-01-31 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-02-01T05:23:43+03:00
New Revision: a7fbca40805ca414a9dc37b91075e89e6a3b75d5

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

LOG: [NFC] Extract `CodeGenInstAlias` into its own *.h/*.cpp

Differential Revision: https://reviews.llvm.org/D142968

Added: 
llvm/utils/TableGen/CodeGenInstAlias.cpp
llvm/utils/TableGen/CodeGenInstAlias.h

Modified: 
clang/docs/tools/clang-formatted-files.txt
llvm/utils/TableGen/AsmMatcherEmitter.cpp
llvm/utils/TableGen/AsmWriterEmitter.cpp
llvm/utils/TableGen/CMakeLists.txt
llvm/utils/TableGen/CodeGenInstruction.cpp
llvm/utils/TableGen/CodeGenInstruction.h
llvm/utils/gn/secondary/llvm/utils/TableGen/BUILD.gn

Removed: 




diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index cbac961982e6a..aa9b871ea58cb 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -7418,6 +7418,8 @@ llvm/unittests/XRay/FDRRecordsTest.cpp
 llvm/unittests/XRay/FDRTraceWriterTest.cpp
 llvm/unittests/XRay/ProfileTest.cpp
 llvm/utils/not/not.cpp
+llvm/Utils/TableGen/CodeGenInstAlias.cpp
+llvm/Utils/TableGen/CodeGenInstAlias.h
 llvm/utils/TableGen/CodeBeadsGen.cpp
 llvm/utils/TableGen/CompressInstEmitter.cpp
 llvm/utils/TableGen/DFAEmitter.h

diff  --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp 
b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index c13e5b5deff6f..4b37347bbae62 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -95,6 +95,7 @@
 //
 
//===--===//
 
+#include "CodeGenInstAlias.h"
 #include "CodeGenInstruction.h"
 #include "CodeGenTarget.h"
 #include "SubtargetFeatureInfo.h"

diff  --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp 
b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index f2e4d15a2c755..e7c0604b8ec75 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "AsmWriterInst.h"
+#include "CodeGenInstAlias.h"
 #include "CodeGenInstruction.h"
 #include "CodeGenRegisters.h"
 #include "CodeGenTarget.h"

diff  --git a/llvm/utils/TableGen/CMakeLists.txt 
b/llvm/utils/TableGen/CMakeLists.txt
index aa16e7e894aca..44ed5549c8ea3 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -13,6 +13,7 @@ add_tablegen(llvm-tblgen LLVM
   CodeEmitterGen.cpp
   CodeGenDAGPatterns.cpp
   CodeGenHwModes.cpp
+  CodeGenInstAlias.cpp
   CodeGenInstruction.cpp
   CodeGenMapTable.cpp
   CodeGenRegisters.cpp

diff  --git a/llvm/utils/TableGen/CodeGenInstAlias.cpp 
b/llvm/utils/TableGen/CodeGenInstAlias.cpp
new file mode 100644
index 0..f3e722d17866a
--- /dev/null
+++ b/llvm/utils/TableGen/CodeGenInstAlias.cpp
@@ -0,0 +1,282 @@
+//===- CodeGenInstAlias.cpp - CodeGen InstAlias Class Wrapper 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements the CodeGenInstAlias class.
+//
+//===--===//
+
+#include "CodeGenInstAlias.h"
+#include "CodeGenInstruction.h"
+#include "CodeGenTarget.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+
+using namespace llvm;
+
+/// tryAliasOpMatch - This is a helper function for the CodeGenInstAlias
+/// constructor.  It checks if an argument in an InstAlias pattern matches
+/// the corresponding operand of the instruction.  It returns true on a
+/// successful match, with ResOp set to the result operand to be used.
+bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
+   Record *InstOpRec, bool hasSubOps,
+   ArrayRef Loc, CodeGenTarget &T,
+   ResultOperand &ResOp) {
+  Init *Arg = Result->getArg(AliasOpNo);
+  DefInit *ADI = dyn_cast(Arg);
+  Record *ResultRecord = ADI ? ADI->getDef() : nullptr;
+
+  if (ADI && ADI->getDef() == InstOpRec) {
+// If the operand is a record, it must have a name, and the record type
+// must match up with the instruction's argument type.
+if (!Result->getArgName(AliasOpNo))
+  PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
+   " must have a name!");
+ 

[clang] [DebugInfo][RemoveDIs] Use iterator-inserters in clang (PR #102006)

2024-08-09 Thread Sergei Barannikov via cfe-commits

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


[clang] [DebugInfo][RemoveDIs] Use iterator-inserters in clang (PR #102006)

2024-08-09 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov commented:

A couple of remarks in case this patch gets reverted.

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


[clang] [DebugInfo][RemoveDIs] Use iterator-inserters in clang (PR #102006)

2024-08-09 Thread Sergei Barannikov via cfe-commits


@@ -293,20 +293,26 @@ void 
CodeGenFunction::initFullExprCleanupWithFlag(RawAddress ActiveFlag) {
 void EHScopeStack::Cleanup::anchor() {}
 
 static void createStoreInstBefore(llvm::Value *value, Address addr,
-  llvm::Instruction *beforeInst,
+  llvm::BasicBlock::iterator beforeInst,
   CodeGenFunction &CGF) {
   auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), 
beforeInst);
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
 static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
-llvm::Instruction *beforeInst,
+llvm::BasicBlock::iterator 
beforeInst,

s-barannikov wrote:

Please capitalize variable names and apply clang-format, this line exceeds 80 
column limit.


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


[clang] [DebugInfo][RemoveDIs] Use iterator-inserters in clang (PR #102006)

2024-08-09 Thread Sergei Barannikov via cfe-commits


@@ -293,20 +293,26 @@ void 
CodeGenFunction::initFullExprCleanupWithFlag(RawAddress ActiveFlag) {
 void EHScopeStack::Cleanup::anchor() {}
 
 static void createStoreInstBefore(llvm::Value *value, Address addr,
-  llvm::Instruction *beforeInst,
+  llvm::BasicBlock::iterator beforeInst,
   CodeGenFunction &CGF) {
   auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), 
beforeInst);
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
 static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
-llvm::Instruction *beforeInst,
+llvm::BasicBlock::iterator 
beforeInst,
 CodeGenFunction &CGF) {
   return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
 name, false, addr.getAlignment().getAsAlign(),
 beforeInst);
 }
 
+static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,

s-barannikov wrote:

Insert before what?



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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-08-10 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] [SPARC][Driver] Add -m(no-)v8plus flags handling (PR #98713)

2024-08-10 Thread Sergei Barannikov via cfe-commits

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


[clang] [llvm] [DataLayout] Remove constructor accepting a pointer to Module (PR #102841)

2024-08-11 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov created 
https://github.com/llvm/llvm-project/pull/102841

The constructor initializes `*this` with `M->getDataLayout()`, which
is effectively the same as calling the copy constructor.
There does not seem to be a case where a copy would be necessary.

Note that the constructor is a part of public interface, but the fix
is trivial so I skipped the deprecation part.

Depends on #102839.


>From 8382e3ed0a5546fff4ed662a7abbaa39e2f0c22a Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Mon, 12 Aug 2024 04:08:54 +0300
Subject: [PATCH] [DataLayout] Remove constructor accepting a pointer to Module

The constructor initializes `*this` with `M->getDataLayout()`, which
is effectively the same as calling the copy constructor.
There does not seem to be a case where a copy would be necessary.
---
 clang/lib/CodeGen/CGObjCGNU.cpp   | 31 +--
 clang/lib/CodeGen/CodeGenTBAA.cpp |  2 +-
 llvm/include/llvm/IR/DataLayout.h |  6 
 llvm/lib/Analysis/InlineCost.cpp  |  3 +-
 .../CodeGen/AssignmentTrackingAnalysis.cpp|  3 +-
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   |  4 +--
 llvm/lib/IR/DataLayout.cpp|  7 -
 llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp  |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +--
 llvm/unittests/IR/IRBuilderTest.cpp   |  7 ++---
 llvm/unittests/SandboxIR/SandboxIRTest.cpp|  4 +--
 11 files changed, 28 insertions(+), 45 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index ca5804018227ea..adc7cdbfded880 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -278,9 +278,9 @@ class CGObjCGNU : public CGObjCRuntime {
   Fields.addInt(IntTy, count);
   // int size; (only in GNUstep v2 ABI.
   if (isRuntime(ObjCRuntime::GNUstep, 2)) {
-llvm::DataLayout td(&TheModule);
-Fields.addInt(IntTy, td.getTypeSizeInBits(PropertyMetadataTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+Fields.addInt(IntTy, DL.getTypeSizeInBits(PropertyMetadataTy) /
+ CGM.getContext().getCharWidth());
   }
   // struct objc_property_list *next;
   Fields.add(NULLPtr);
@@ -1190,9 +1190,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 // int count;
 MethodList.addInt(IntTy, Methods.size());
 // int size; // sizeof(struct objc_method_description)
-llvm::DataLayout td(&TheModule);
-MethodList.addInt(IntTy, td.getTypeSizeInBits(ObjCMethodDescTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+MethodList.addInt(IntTy, DL.getTypeSizeInBits(ObjCMethodDescTy) /
+ CGM.getContext().getCharWidth());
 // struct objc_method_description[]
 auto MethodArray = MethodList.beginArray(ObjCMethodDescTy);
 for (auto *M : Methods) {
@@ -1828,7 +1828,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   int ivar_count = 0;
   for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
IVD = IVD->getNextIvar()) ivar_count++;
-  llvm::DataLayout td(&TheModule);
+  const llvm::DataLayout &DL = TheModule.getDataLayout();
   // struct objc_ivar_list *ivars;
   ConstantInitBuilder b(CGM);
   auto ivarListBuilder = b.beginStruct();
@@ -1841,8 +1841,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 PtrToInt8Ty,
 Int32Ty,
 Int32Ty);
-  ivarListBuilder.addInt(SizeTy, td.getTypeSizeInBits(ObjCIvarTy) /
-  CGM.getContext().getCharWidth());
+  ivarListBuilder.addInt(SizeTy, DL.getTypeSizeInBits(ObjCIvarTy) /
+ CGM.getContext().getCharWidth());
   // struct objc_ivar ivars[]
   auto ivarArrayBuilder = ivarListBuilder.beginArray();
   for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
@@ -3019,9 +3019,9 @@ GenerateMethodList(StringRef ClassName,
   bool isV2ABI = isRuntime(ObjCRuntime::GNUstep, 2);
   if (isV2ABI) {
 // size_t size;
-llvm::DataLayout td(&TheModule);
-MethodList.addInt(SizeTy, td.getTypeSizeInBits(ObjCMethodTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+MethodList.addInt(SizeTy, DL.getTypeSizeInBits(ObjCMethodTy) /
+  CGM.getContext().getCharWidth());
 ObjCMethodTy =
   llvm::StructType::get(CGM.getLLVMContext(), {
 IMPTy,   // Method pointer
@@ -3161,10 +3161,9 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
   Elements.addInt(LongTy, info);
   // instance_size
   if (isMeta) {
-llvm::DataLayout td(&TheModule);
-Elements.addInt(LongTy,
-td.getTypeSizeInBits(ClassTy) /
-  CGM.getContext().getCharWidth(

[clang] [llvm] [DataLayout] Remove constructor accepting a pointer to Module (PR #102841)

2024-08-12 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov updated 
https://github.com/llvm/llvm-project/pull/102841

>From 8382e3ed0a5546fff4ed662a7abbaa39e2f0c22a Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Mon, 12 Aug 2024 04:08:54 +0300
Subject: [PATCH] [DataLayout] Remove constructor accepting a pointer to Module

The constructor initializes `*this` with `M->getDataLayout()`, which
is effectively the same as calling the copy constructor.
There does not seem to be a case where a copy would be necessary.
---
 clang/lib/CodeGen/CGObjCGNU.cpp   | 31 +--
 clang/lib/CodeGen/CodeGenTBAA.cpp |  2 +-
 llvm/include/llvm/IR/DataLayout.h |  6 
 llvm/lib/Analysis/InlineCost.cpp  |  3 +-
 .../CodeGen/AssignmentTrackingAnalysis.cpp|  3 +-
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   |  4 +--
 llvm/lib/IR/DataLayout.cpp|  7 -
 llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp  |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +--
 llvm/unittests/IR/IRBuilderTest.cpp   |  7 ++---
 llvm/unittests/SandboxIR/SandboxIRTest.cpp|  4 +--
 11 files changed, 28 insertions(+), 45 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index ca5804018227ea..adc7cdbfded880 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -278,9 +278,9 @@ class CGObjCGNU : public CGObjCRuntime {
   Fields.addInt(IntTy, count);
   // int size; (only in GNUstep v2 ABI.
   if (isRuntime(ObjCRuntime::GNUstep, 2)) {
-llvm::DataLayout td(&TheModule);
-Fields.addInt(IntTy, td.getTypeSizeInBits(PropertyMetadataTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+Fields.addInt(IntTy, DL.getTypeSizeInBits(PropertyMetadataTy) /
+ CGM.getContext().getCharWidth());
   }
   // struct objc_property_list *next;
   Fields.add(NULLPtr);
@@ -1190,9 +1190,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 // int count;
 MethodList.addInt(IntTy, Methods.size());
 // int size; // sizeof(struct objc_method_description)
-llvm::DataLayout td(&TheModule);
-MethodList.addInt(IntTy, td.getTypeSizeInBits(ObjCMethodDescTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+MethodList.addInt(IntTy, DL.getTypeSizeInBits(ObjCMethodDescTy) /
+ CGM.getContext().getCharWidth());
 // struct objc_method_description[]
 auto MethodArray = MethodList.beginArray(ObjCMethodDescTy);
 for (auto *M : Methods) {
@@ -1828,7 +1828,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   int ivar_count = 0;
   for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
IVD = IVD->getNextIvar()) ivar_count++;
-  llvm::DataLayout td(&TheModule);
+  const llvm::DataLayout &DL = TheModule.getDataLayout();
   // struct objc_ivar_list *ivars;
   ConstantInitBuilder b(CGM);
   auto ivarListBuilder = b.beginStruct();
@@ -1841,8 +1841,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 PtrToInt8Ty,
 Int32Ty,
 Int32Ty);
-  ivarListBuilder.addInt(SizeTy, td.getTypeSizeInBits(ObjCIvarTy) /
-  CGM.getContext().getCharWidth());
+  ivarListBuilder.addInt(SizeTy, DL.getTypeSizeInBits(ObjCIvarTy) /
+ CGM.getContext().getCharWidth());
   // struct objc_ivar ivars[]
   auto ivarArrayBuilder = ivarListBuilder.beginArray();
   for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
@@ -3019,9 +3019,9 @@ GenerateMethodList(StringRef ClassName,
   bool isV2ABI = isRuntime(ObjCRuntime::GNUstep, 2);
   if (isV2ABI) {
 // size_t size;
-llvm::DataLayout td(&TheModule);
-MethodList.addInt(SizeTy, td.getTypeSizeInBits(ObjCMethodTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+MethodList.addInt(SizeTy, DL.getTypeSizeInBits(ObjCMethodTy) /
+  CGM.getContext().getCharWidth());
 ObjCMethodTy =
   llvm::StructType::get(CGM.getLLVMContext(), {
 IMPTy,   // Method pointer
@@ -3161,10 +3161,9 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
   Elements.addInt(LongTy, info);
   // instance_size
   if (isMeta) {
-llvm::DataLayout td(&TheModule);
-Elements.addInt(LongTy,
-td.getTypeSizeInBits(ClassTy) /
-  CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+Elements.addInt(LongTy, DL.getTypeSizeInBits(ClassTy) /
+CGM.getContext().getCharWidth());
   } else
 Elements.add(InstanceSize);
   // ivars
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp

[clang] [llvm] [DataLayout] Remove constructor accepting a pointer to Module (PR #102841)

2024-08-12 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov updated 
https://github.com/llvm/llvm-project/pull/102841

>From 8382e3ed0a5546fff4ed662a7abbaa39e2f0c22a Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Mon, 12 Aug 2024 04:08:54 +0300
Subject: [PATCH] [DataLayout] Remove constructor accepting a pointer to Module

The constructor initializes `*this` with `M->getDataLayout()`, which
is effectively the same as calling the copy constructor.
There does not seem to be a case where a copy would be necessary.
---
 clang/lib/CodeGen/CGObjCGNU.cpp   | 31 +--
 clang/lib/CodeGen/CodeGenTBAA.cpp |  2 +-
 llvm/include/llvm/IR/DataLayout.h |  6 
 llvm/lib/Analysis/InlineCost.cpp  |  3 +-
 .../CodeGen/AssignmentTrackingAnalysis.cpp|  3 +-
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   |  4 +--
 llvm/lib/IR/DataLayout.cpp|  7 -
 llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp  |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +--
 llvm/unittests/IR/IRBuilderTest.cpp   |  7 ++---
 llvm/unittests/SandboxIR/SandboxIRTest.cpp|  4 +--
 11 files changed, 28 insertions(+), 45 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index ca5804018227ea..adc7cdbfded880 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -278,9 +278,9 @@ class CGObjCGNU : public CGObjCRuntime {
   Fields.addInt(IntTy, count);
   // int size; (only in GNUstep v2 ABI.
   if (isRuntime(ObjCRuntime::GNUstep, 2)) {
-llvm::DataLayout td(&TheModule);
-Fields.addInt(IntTy, td.getTypeSizeInBits(PropertyMetadataTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+Fields.addInt(IntTy, DL.getTypeSizeInBits(PropertyMetadataTy) /
+ CGM.getContext().getCharWidth());
   }
   // struct objc_property_list *next;
   Fields.add(NULLPtr);
@@ -1190,9 +1190,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 // int count;
 MethodList.addInt(IntTy, Methods.size());
 // int size; // sizeof(struct objc_method_description)
-llvm::DataLayout td(&TheModule);
-MethodList.addInt(IntTy, td.getTypeSizeInBits(ObjCMethodDescTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+MethodList.addInt(IntTy, DL.getTypeSizeInBits(ObjCMethodDescTy) /
+ CGM.getContext().getCharWidth());
 // struct objc_method_description[]
 auto MethodArray = MethodList.beginArray(ObjCMethodDescTy);
 for (auto *M : Methods) {
@@ -1828,7 +1828,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   int ivar_count = 0;
   for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
IVD = IVD->getNextIvar()) ivar_count++;
-  llvm::DataLayout td(&TheModule);
+  const llvm::DataLayout &DL = TheModule.getDataLayout();
   // struct objc_ivar_list *ivars;
   ConstantInitBuilder b(CGM);
   auto ivarListBuilder = b.beginStruct();
@@ -1841,8 +1841,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 PtrToInt8Ty,
 Int32Ty,
 Int32Ty);
-  ivarListBuilder.addInt(SizeTy, td.getTypeSizeInBits(ObjCIvarTy) /
-  CGM.getContext().getCharWidth());
+  ivarListBuilder.addInt(SizeTy, DL.getTypeSizeInBits(ObjCIvarTy) /
+ CGM.getContext().getCharWidth());
   // struct objc_ivar ivars[]
   auto ivarArrayBuilder = ivarListBuilder.beginArray();
   for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
@@ -3019,9 +3019,9 @@ GenerateMethodList(StringRef ClassName,
   bool isV2ABI = isRuntime(ObjCRuntime::GNUstep, 2);
   if (isV2ABI) {
 // size_t size;
-llvm::DataLayout td(&TheModule);
-MethodList.addInt(SizeTy, td.getTypeSizeInBits(ObjCMethodTy) /
-CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+MethodList.addInt(SizeTy, DL.getTypeSizeInBits(ObjCMethodTy) /
+  CGM.getContext().getCharWidth());
 ObjCMethodTy =
   llvm::StructType::get(CGM.getLLVMContext(), {
 IMPTy,   // Method pointer
@@ -3161,10 +3161,9 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
   Elements.addInt(LongTy, info);
   // instance_size
   if (isMeta) {
-llvm::DataLayout td(&TheModule);
-Elements.addInt(LongTy,
-td.getTypeSizeInBits(ClassTy) /
-  CGM.getContext().getCharWidth());
+const llvm::DataLayout &DL = TheModule.getDataLayout();
+Elements.addInt(LongTy, DL.getTypeSizeInBits(ClassTy) /
+CGM.getContext().getCharWidth());
   } else
 Elements.add(InstanceSize);
   // ivars
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp

[clang] [llvm] [DataLayout] Remove constructor accepting a pointer to Module (PR #102841)

2024-08-12 Thread Sergei Barannikov via cfe-commits

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


[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread Sergei Barannikov via cfe-commits


@@ -15567,12 +15567,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 HandleComplexComplexDiv(A, B, C, D, ResR, ResI);
   }
 } else {
-  if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0)
-return Error(E, diag::note_expr_divide_by_zero);
-
   ComplexValue LHS = Result;
   APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() +
 RHS.getComplexIntImag() * RHS.getComplexIntImag();
+  if ((RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) ||
+  Den.isZero())

s-barannikov wrote:

(nit) The first part of the check implies the second, why not just
```suggestion
  if (Den.isZero())
```


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


[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] Fix codegen for transparent_union function params (PR #104816)

2024-08-19 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

May it make sense to add tests with the argument passed in memory / by 
reference?


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


[clang] Fix codegen for transparent_union function params (PR #104816)

2024-08-19 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

I think the issue could be handled a different (more generic) way, by pulling 
`useFirstFieldIfTransparentUnion` to the caller and taking transparent unions 
into account when emitting LLVM IR for the formal / actual parameters somewhere 
in `CGCall.cpp`, so that ABIInfo implementations don't need to care about 
transparent unions at all.


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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-19 Thread Sergei Barannikov via cfe-commits


@@ -13,10 +13,12 @@
 #ifndef LLVM_SUPPORT_COMPRESSION_H
 #define LLVM_SUPPORT_COMPRESSION_H
 
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/ErrorHandling.h"
+#include 
+#include 

s-barannikov wrote:

Here and elsewhere
```suggestion
#include 
#include 
```

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-19 Thread Sergei Barannikov via cfe-commits


@@ -1,4 +1,4 @@
-//===- MachineCFGPrinter.cpp - DOT Printer for Machine Functions 
--===//
+//===-   - DOT Printer for Machine Functions --===//

s-barannikov wrote:

Looks unintended.


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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-19 Thread Sergei Barannikov via cfe-commits


@@ -39,7 +39,6 @@
 #ifndef LLVM_SUPPORT_BALANCED_PARTITIONING_H
 #define LLVM_SUPPORT_BALANCED_PARTITIONING_H
 
-#include "raw_ostream.h"
 #include "llvm/ADT/ArrayRef.h"
 
 #include 

s-barannikov wrote:

(nit)
```suggestion
#include "llvm/ADT/ArrayRef.h"
#include 
```

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-19 Thread Sergei Barannikov via cfe-commits


@@ -10,6 +10,7 @@
 #include "InputFiles.h"
 #include "InputSection.h"
 #include "OutputSegment.h"
+#include "llvm/ADT/StringSwitch.h"
 
 #include 

s-barannikov wrote:

(nit)
```suggestion
#include "llvm/ADT/StringSwitch.h"
#include 
```

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-19 Thread Sergei Barannikov via cfe-commits


@@ -19,6 +19,7 @@
 #include "llvm/IR/InstVisitor.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/Debug.h"
 using namespace llvm;

s-barannikov wrote:

```suggestion

using namespace llvm;
```

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-19 Thread Sergei Barannikov via cfe-commits


@@ -12,10 +12,8 @@
 
 #include "Unix.h"
 #include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/config.h"
-#include 
-#include 

s-barannikov wrote:

`` is used in this file


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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-19 Thread Sergei Barannikov via cfe-commits


@@ -9,17 +9,14 @@
 #ifndef LLVM_SUPPORT_CHRONO_H
 #define LLVM_SUPPORT_CHRONO_H
 
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/FormatProviders.h"
+#include "llvm/Support/FormatVariadicDetails.h"
 
 #include 

s-barannikov wrote:

(nit) extra newline

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Sergei Barannikov via cfe-commits


@@ -17,7 +17,7 @@
 #ifndef LLVM_SUPPORT_ATOMIC_H
 #define LLVM_SUPPORT_ATOMIC_H
 
-#include "llvm/Support/DataTypes.h"
+#include 

s-barannikov wrote:

```suggestion
#include 
```

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2024-08-20 Thread Sergei Barannikov via cfe-commits


@@ -13,7 +13,7 @@
 #ifndef LLVM_SUPPORT_CRC_H
 #define LLVM_SUPPORT_CRC_H
 
-#include "llvm/Support/DataTypes.h"
+#include 

s-barannikov wrote:

```suggestion
#include 
```

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


[clang] Fix codegen for transparent_union function params (PR #104816)

2024-08-21 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

> However I feel like it is out of scope for what I am trying to do right now. 
> Would this be better as a separate PR to change how this is handled?

Sure


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


[clang] [llvm] [NFC][SetTheory] Refactor to use const pointers and range loops (PR #105544)

2024-08-22 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] [llvm] [NFC] Use const members of `StringToOffsetTable` (PR #105824)

2024-08-23 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.

LGTM

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


[clang] [llvm] [SPARC] Align i128 to 16 bytes in SPARC datalayouts (PR #106951)

2024-09-04 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

I guess this is a breaking change?
Following the discussion in the linked revision it looks like this also needs 
some AutoUpgrade changes.


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


[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-07-26 Thread Sergei Barannikov via cfe-commits


@@ -137,6 +137,16 @@ bool isEmptyField(ASTContext &Context, const FieldDecl 
*FD, bool AllowArrays,
 bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
bool AsIfNoUniqueAddr = false);
 
+/// isEmptyFieldForLayout - Return true iff the field is "empty", that is,
+/// either a zero-width bit-field or an \ref isEmptyRecordForLayout.
+bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD);
+
+/// isEmptyRecordForLayout - Return true iff a structure contains only empty
+/// base classes (per \ref isEmptyRecordForLayout) and fields (per
+/// \ref isEmptyFieldForLayout). Note, C++ record fields are considered empty
+/// if the [[no_unique_address]] attribute would have made them empty.
+bool isEmptyRecordForLayout(const ASTContext &Context, QualType T);

s-barannikov wrote:

These functions don't belong here. This file contains helper functions for use 
in implementations of ABIInfo class.
I guess CGRecordLayout* could be a better place for them.


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

s-barannikov wrote:

This is quite confusing.
`-m[no]-v8plus` is an environment option, similar to X86's `-mx32`, but imposes 
more restrictions.
`-mcpu=v9 -mno-v8plus` should be equivalent to just `-mcpu=v9` because 64-bit 
environment is the default for 64-bit ISA.
`-mv8plus` enables 32-bit environment and therefore should restrict the 
compiler from using the whole set of V9 features. That is, I would expect it to 
disable something rather than to enable `v9`, which should already be set by 
`-mcpu=v9`.


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

s-barannikov wrote:

Either way, the order of `-m8plus` relative to `-mcpu` shouldn't matter (one 
sets the environment, the other sets an ISA).


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits

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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits

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


[clang] [clang][LoongArch] Align global symbol by size (PR #101309)

2024-07-31 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

This looks wrong. Preferred and ABI alignments should be set in Triple.


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

s-barannikov wrote:

> on GCC, `-m[no-]v8plus` also implies that V9 instructions are available (or 
> not, in case of `-mno-v8plus`)

Well, no. Not exactly. Whether or not V9 instructions are available is 
determined strictly by `-mcpu=v9` (which is the default). In both cases by the 
first godbolt link instructions are V9 instructions and operate on 64-bit 
registers.
The thing is, you can't use the upper half of these registers, which makes 
instructions such as MULX useless. There are, however, other instructions 
introduced in V9 that are useful -- 32-bit atomics for instance.

Also note that `-mno-v8plus` is the default and passing it explicitly won't 
change the behavior (unless you specified `-mv8plus` prior to it).


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


[clang] [clang][LoongArch] Align global symbol by size (PR #101309)

2024-07-31 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

> > This looks wrong. Preferred and ABI alignments should be set in ~Triple~. 
> > ADD: Sorry, I meant DataLayout, of course.
> 
> Thanks for pointing this out. How does data layout affect the alignment of 
> constant string global variable symbols?

They will be aligned to the preferred alignment specified as Y in the "-a:X:Y" 
part of the data layout, IIRC.

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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits

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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

s-barannikov wrote:

> In that case, would making these a no-op flag okay for now? As far as I 
> understand it that would still be a compliant implementation, no?

AFAIK it is an ABI affecting flag, although I don't know if it changes anything 
except for ELF header's e_machine field compared to 32-bit V8/V9. It can't 
safely be ignored if we claim support for V8+. If we don't, and V8+ is 
otherwise compatible with 32-bit ABI, I think ignoring it and generating  
instructions should be fine, probably with a warning.

> Codegen, etc. changes will happen in future patches but I can amend this one 
> to include a placeholder `v8plus` feature bit in the backend.
> 
> What do you think about it?

I have little experience in target feature bits. It could be helpful to have a 
draft that adds some V8+ support to the backend and the corresponding feature 
bits.


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


[clang] [clang][LoongArch] Align global symbol by size (PR #101309)

2024-07-31 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

> > > > This looks wrong. Preferred and ABI alignments should be set in 
> > > > ~Triple~. ADD: Sorry, I meant DataLayout, of course.
> > > 
> > > 
> > > Thanks for pointing this out. How does data layout affect the alignment 
> > > of constant string global variable symbols?
> > 
> > 
> > They will be aligned to the preferred alignment specified as Y in the 
> > "-a:X:Y" part of the data layout, IIRC.
> 
> Thanks for the explanation. I understand that data layout can set default and 
> preferred alignment for all globals. This patch chooses alignment based on 
> the size of global objects. Can data layout do that?

You can specify ABI and preferred alignments for "first class" types, and 
separately for aggregates. It is all documented 
[here](https://llvm.org/docs/LangRef.html#data-layout).


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -6077,6 +6077,10 @@ def mvis3 : Flag<["-"], "mvis3">, 
Group;
 def mno_vis3 : Flag<["-"], "mno-vis3">, Group;
 def mhard_quad_float : Flag<["-"], "mhard-quad-float">, 
Group;
 def msoft_quad_float : Flag<["-"], "msoft-quad-float">, 
Group;
+def mv8plus : Flag<["-"], "mv8plus">, Group,
+  HelpText<"Enable V8+ mode, allowing use of 64-bit V9 instructions in 32-bit 
code">;

s-barannikov wrote:

Maybe something like this would be more accurate?
```suggestion
  HelpText<"Enable V8+ mode, which allows using a limited set of V9 features in 
32-bit code">;
```


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -6077,6 +6077,10 @@ def mvis3 : Flag<["-"], "mvis3">, 
Group;
 def mno_vis3 : Flag<["-"], "mno-vis3">, Group;
 def mhard_quad_float : Flag<["-"], "mhard-quad-float">, 
Group;
 def msoft_quad_float : Flag<["-"], "msoft-quad-float">, 
Group;
+def mv8plus : Flag<["-"], "mv8plus">, Group,
+  HelpText<"Enable V8+ mode, allowing use of 64-bit V9 instructions in 32-bit 
code">;

s-barannikov wrote:

Never mind.

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


[clang] [NFC][Clang] Remove unused arg (PR #101650)

2024-08-02 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

IIRC there is a clang-tidy check that diagnoses uninitialized PODs, but 
probably making the constructor non-trivial is simpler.


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


[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

2024-07-10 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] [llvm] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits

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


[clang] [llvm] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -45,7 +45,8 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
 
 public:
   SparcSubtarget(const Triple &TT, const std::string &CPU,
- const std::string &FS, const TargetMachine &TM, bool is64bit);
+ const std::string &TuneCPU, const std::string &FS,

s-barannikov wrote:

While here, could change all `const std::string &` to `StringRef` and/or remove 
the `TT` parameter (it can be obtained as `TM.getTargetTriple()`.).


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


[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -5119,7 +5119,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

s-barannikov wrote:

Is this the only required change at the clang side?
Which component is responsible for emitting errors on invalid / incompatible 
-mtune options?
I guess we need some test for this.


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


[clang] [llvm] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+  if (!TRI->isReservedReg(MF, Reg))
+Reg = 0;

s-barannikov wrote:

> Becomes a nop function on clang unless `l0` is reserved.
> Other LLVM backends also do this (and differ from GCC behavior) so I don't 
> think the issue is localized to ours.
> 
> So I believe it is better for us to throw an error instead of silently 
> miscompiling code?

Reserving a register assigned to a global variable makes sense. Not sure about 
local variables.
llvm language reference manual says this about llvm.read_register / 
llvm.write_register intrinsics:

> The compiler doesn’t check for register availability or use of the used 
> register in surrounding code, including inline assembly. Because of that, 
> allocatable registers are not supported.
> 
> Warning: So far it only works with the stack pointer on selected 
> architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of work 
> is needed to support other registers and even more so, allocatable registers.

That said, I think we can go with the current implementation as long as it 
satisfies the need of the targeted software (Linux kernel I presume).


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


[clang] [llvm] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -5119,7 +5119,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

s-barannikov wrote:

I mean that something like `--target=sparc -mtune=i386` should fail and there 
should be a test for that.
Currently (without this patch) it succeeds on Sparc and fails on e.g. AArch64.
```
$ clang --target=aarch64 -mtune=i386 -xc - https://github.com/llvm/llvm-project/pull/77195
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -5119,7 +5119,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

s-barannikov wrote:

Never mind. I tested an older compiler. It seems to have been fixed in upstream.


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


[compiler-rt] [flang] [llvm] [clang] [lld] [GISel] Add RegState::Define to temporary defs in apply patterns (PR #77425)

2024-01-09 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov updated 
https://github.com/llvm/llvm-project/pull/77425

>From 13e6d0818659f0bb4c4f3a41796db2d1465cc82d Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Tue, 9 Jan 2024 11:44:41 +0300
Subject: [PATCH 1/2] [GISel] Add RegState::Define to temporary defs in apply
 patterns

Previously, registers created for temporary defs in apply patterns were
rendered as uses, resulting in machine verifier errors.
---
 .../match-table-temp-defs.td  | 56 +++
 .../TableGen/GlobalISelCombinerEmitter.cpp|  2 +-
 2 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-temp-defs.td

diff --git 
a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-temp-defs.td 
b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-temp-defs.td
new file mode 100644
index 00..4e473355e14c36
--- /dev/null
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-temp-defs.td
@@ -0,0 +1,56 @@
+// RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \
+// RUN: -combiners=MyCombiner %s | FileCheck %s
+
+// Checks that temporary registers defined in apply patterns
+// are emitted with RegState::Define.
+
+include "llvm/Target/Target.td"
+include "llvm/Target/GlobalISel/Combine.td"
+
+def MyTargetISA : InstrInfo;
+def MyTarget : Target { let InstructionSet = MyTargetISA; }
+
+def Test0 : GICombineRule<
+  (defs root:$dst),
+  (match (G_ADD $dst, $lhs, $rhs)),
+  (apply (G_UDIVREM $tmp, $dst, $lhs, $rhs))
+>;
+
+def Test1 : GICombineRule<
+  (defs root:$dst),
+  (match (G_ADD $dst, $lhs, $rhs)),
+  (apply (G_UDIVREM $dst, $tmp, $lhs, $rhs))
+>;
+
+def Test2 : GICombineRule<
+  (defs root:$dst),
+  (match (G_ADD $dst, $lhs, $rhs)),
+  (apply (G_ADD $tmp, 0, $lhs),
+ (G_ADD $dst, $tmp, $rhs))
+>;
+
+def MyCombiner: GICombiner<"GenMyCombiner", [
+  Test0,
+  Test1,
+  Test2,
+]>;
+
+// CHECK:   // Combiner Rule #0: Test0
+// CHECK-NEXT:  GIR_BuildMI, /*InsnID*/0, 
/*Opcode*/GIMT_Encode2(TargetOpcode::G_UDIVREM),
+// CHECK-NEXT:  GIR_AddTempRegister, /*InsnID*/0, /*TempRegID*/0, 
/*TempRegFlags*/GIMT_Encode2(RegState::Define),
+// CHECK-NEXT:  GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/0, // dst
+// CHECK-NEXT:  GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/1, // lhs
+// CHECK-NEXT:  GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/2, // rhs
+
+// CHECK:   // Combiner Rule #1: Test1
+// CHECK-NEXT:  GIR_BuildMI, /*InsnID*/0, 
/*Opcode*/GIMT_Encode2(TargetOpcode::G_UDIVREM),
+// CHECK-NEXT:  GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/0, // dst
+// CHECK-NEXT:  GIR_AddTempRegister, /*InsnID*/0, /*TempRegID*/0, 
/*TempRegFlags*/GIMT_Encode2(RegState::Define),
+// CHECK-NEXT:  GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/1, // lhs
+// CHECK-NEXT:  GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/2, // rhs
+
+// CHECK:   // Combiner Rule #2: Test2
+// CHECK-NEXT:  GIR_BuildMI, /*InsnID*/0, 
/*Opcode*/GIMT_Encode2(TargetOpcode::G_ADD),
+// CHECK-NEXT:  GIR_AddTempRegister, /*InsnID*/0, /*TempRegID*/0, 
/*TempRegFlags*/GIMT_Encode2(RegState::Define),
+// CHECK-NEXT:  GIR_AddSimpleTempRegister, /*InsnID*/0, /*TempRegID*/1,
+// CHECK-NEXT:  GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/1, // lhs
diff --git a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp 
b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
index 89aca87a28ec0d..d95f323d9d6b46 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
@@ -2316,7 +2316,7 @@ bool CombineRuleBuilder::emitInstructionApplyPattern(
   M.actions_begin(), getLLTCodeGenOrTempType(Ty, M), TempRegID);
 }
 
-DstMI.addRenderer(TempRegID);
+DstMI.addRenderer(TempRegID, /*IsDef=*/true);
   }
 
   // Render MIFlags

>From 3ebbbfed550bac7ed784d2501ded83c453d50e4d Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Tue, 9 Jan 2024 11:56:06 +0300
Subject: [PATCH 2/2] Update failing tests

---
 .../builtins/match-table-replacerreg.td   | 20 +--
 .../match-table-operand-types.td  |  8 
 .../match-table-typeof.td |  8 
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git 
a/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/match-table-replacerreg.td
 
b/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/match-table-replacerreg.td
index f4f1faf7cc6d9a..38ee0166b869d8 100644
--- 
a/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/match-table-replacerreg.td
+++ 
b/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/match-table-replacerreg.td
@@ -28,11 +28,11 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
 
 // CHECK:  const uint8_t *GenMyCombiner::getMatchTable() const {
 // CHECK-NEXT:   constexpr static uint8_t MatchTable0[] = {
-// CHECK-NEXT: GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(65), 
GIMT_Encode2(181)

[lld] [flang] [clang] [llvm] [compiler-rt] [GISel] Add RegState::Define to temporary defs in apply patterns (PR #77425)

2024-01-09 Thread Sergei Barannikov via cfe-commits

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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-19 Thread Sergei Barannikov via cfe-commits


@@ -1125,6 +1130,19 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *MRI = Subtarget->getRegisterInfo();
+  unsigned DwarfRegNum = MRI->getDwarfRegNum(Reg, false);

s-barannikov wrote:

It looks strange to check dwarf register numbers here. Why don't compare 
register ids directly? E.g.
`IsG = Reg >= SP::G0 && Reg <= SP::G7`.


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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-19 Thread Sergei Barannikov via cfe-commits


@@ -1125,6 +1130,19 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *MRI = Subtarget->getRegisterInfo();

s-barannikov wrote:

```suggestion
  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
```

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


[clang] [llvm] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-19 Thread Sergei Barannikov via cfe-commits


@@ -1125,6 +1130,19 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *MRI = Subtarget->getRegisterInfo();
+  unsigned DwarfRegNum = MRI->getDwarfRegNum(Reg, false);
+  if (!MRI->isReservedReg(MF, Reg)) {
+bool IsG = DwarfRegNum < 8, IsO = DwarfRegNum >= 8 && DwarfRegNum < 16,
+ IsL = DwarfRegNum >= 16 && DwarfRegNum < 24, IsI = DwarfRegNum >= 24;
+unsigned NumInBank = DwarfRegNum % 8;
+if ((IsG && !Subtarget->isGRegisterReserved(NumInBank)) ||

s-barannikov wrote:

All `is*RegisterReserved` methods return false here (because of isReservedReg 
returning false above).



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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-19 Thread Sergei Barannikov via cfe-commits


@@ -5730,6 +5730,18 @@ def mvis3 : Flag<["-"], "mvis3">, 
Group;
 def mno_vis3 : Flag<["-"], "mno-vis3">, Group;
 def mhard_quad_float : Flag<["-"], "mhard-quad-float">, 
Group;
 def msoft_quad_float : Flag<["-"], "msoft-quad-float">, 
Group;
+foreach i = {1-7} in

s-barannikov wrote:

The modern syntax is `foreach i = 1 ... 7 in`.

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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-19 Thread Sergei Barannikov via cfe-commits


@@ -98,9 +98,52 @@ BitVector SparcRegisterInfo::getReservedRegs(const 
MachineFunction &MF) const {
   for (unsigned n = 0; n < 31; n++)
 Reserved.set(SP::ASR1 + n);
 
+  for (size_t i = 0; i < SP::IntRegsRegClass.getNumRegs() / 4; ++i) {
+// Mark both single register and register pairs.
+if (MF.getSubtarget().isGRegisterReserved(i)) {
+  Reserved.set(SP::G0 + i);
+  Reserved.set(SP::G0_G1 + i / 2);
+}
+if (MF.getSubtarget().isORegisterReserved(i)) {
+  Reserved.set(SP::O0 + i);
+  Reserved.set(SP::O0_O1 + i / 2);
+}
+if (MF.getSubtarget().isLRegisterReserved(i)) {
+  Reserved.set(SP::L0 + i);
+  Reserved.set(SP::L0_L1 + i / 2);
+}
+if (MF.getSubtarget().isIRegisterReserved(i)) {
+  Reserved.set(SP::I0 + i);
+  Reserved.set(SP::I0_I1 + i / 2);
+}
+  }
+
   return Reserved;
 }
 
+bool SparcRegisterInfo::isReservedReg(const MachineFunction &MF,
+  MCRegister Reg) const {
+  return getReservedRegs(MF)[Reg];
+}
+
+bool SparcRegisterInfo::isAnyArgRegReserved(const MachineFunction &MF) const {
+  bool Outgoing =
+  llvm::any_of(*SP::GPROutgoingArgRegClass.MC,

s-barannikov wrote:

```suggestion
  llvm::any_of(SP::GPROutgoingArgRegClass,
```
MC is an internal field of TargetRegisterClass.

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


[clang] [clang] Allow __attribute__((swiftcall)) on all targets (PR #71986)

2023-12-19 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

I think the choice whether or not to support Swift calling convention should be 
made by individual targets without providing "safe" default. As pointed out in 
the linked PR, supporting Swift CC is not only about enabling the attribute 
support -- backend also needs modifications so that the calling convention is 
effective. This can only be done based on the ABI, which is target-dependent.


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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-12-19 Thread Sergei Barannikov via cfe-commits


@@ -274,20 +274,27 @@ class DefaultIntArgument : 
IntArgument {
 }
 
 // This argument is more complex, it includes the enumerator type name,
-// a list of strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// a list of possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,

s-barannikov wrote:

Sorry for late reply. All String arguments are already unevaluated as made by 
https://reviews.llvm.org/D156237.
This patch makes Enum arguments unevaluated too, but only those that are 
effectively strings
Consider:
`__attribute__((visibility("default" / "protected" /...)))`
`__attribute__((enum_extensibility(open / closed)))`).
Both attributes have enum arguments. The first one has a string enum argument 
(which should be parsed unevaluated), while the second has an identifier enum 
argument.


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


[clang] [llvm] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-21 Thread Sergei Barannikov via cfe-commits


@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+  if (!TRI->isReservedReg(MF, Reg))
+Reg = 0;

s-barannikov wrote:

I'm not sure I understand the logic here. Shouldn't the condition be reversed? 
Could you add a test case for this code path?


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


[clang] [llvm] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-21 Thread Sergei Barannikov via cfe-commits


@@ -98,9 +98,52 @@ BitVector SparcRegisterInfo::getReservedRegs(const 
MachineFunction &MF) const {
   for (unsigned n = 0; n < 31; n++)
 Reserved.set(SP::ASR1 + n);
 
+  for (size_t i = 0; i < SP::IntRegsRegClass.getNumRegs() / 4; ++i) {
+// Mark both single register and register pairs.
+if (MF.getSubtarget().isGRegisterReserved(i)) {
+  Reserved.set(SP::G0 + i);
+  Reserved.set(SP::G0_G1 + i / 2);
+}
+if (MF.getSubtarget().isORegisterReserved(i)) {
+  Reserved.set(SP::O0 + i);
+  Reserved.set(SP::O0_O1 + i / 2);
+}
+if (MF.getSubtarget().isLRegisterReserved(i)) {
+  Reserved.set(SP::L0 + i);
+  Reserved.set(SP::L0_L1 + i / 2);
+}
+if (MF.getSubtarget().isIRegisterReserved(i)) {
+  Reserved.set(SP::I0 + i);
+  Reserved.set(SP::I0_I1 + i / 2);
+}
+  }
+
   return Reserved;
 }
 
+bool SparcRegisterInfo::isReservedReg(const MachineFunction &MF,
+  MCRegister Reg) const {
+  return getReservedRegs(MF)[Reg];
+}
+
+bool SparcRegisterInfo::isAnyArgRegReserved(const MachineFunction &MF) const {
+  bool Outgoing =
+  llvm::any_of(SP::GPROutgoingArgRegClass,
+   [this, &MF](MCPhysReg r) { return isReservedReg(MF, r); });
+  bool Incoming =
+  llvm::any_of(SP::GPRIncomingArgRegClass,
+   [this, &MF](MCPhysReg r) { return isReservedReg(MF, r); });
+  return Outgoing || Incoming;
+}
+
+void SparcRegisterInfo::emitReservedArgRegCallError(
+const MachineFunction &MF) const {
+  const Function &F = MF.getFunction();
+  F.getContext().diagnose(DiagnosticInfoUnsupported{
+  F, ("SPARC doesn't support"
+  " function calls if any of the argument registers is reserved.")});
+}
+

s-barannikov wrote:

nit: The two methods above could be static functions in SparcISelLowering.cpp.


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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-12-21 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov updated 
https://github.com/llvm/llvm-project/pull/68550

>From 96dd0121b095f92cc66fcfc3ef08a19d0b2d6bec Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Mon, 9 Oct 2023 01:38:33 +0300
Subject: [PATCH] [clang] Differentiate between identifier and string
 EnumArgument

EnumArgument may be a string or an identifier. If it is a string, it
should be parsed as unevaluated string literal. Add IsString flag to
EnumArgument so that the parser can choose the correct parsing method.

Target-specific attributes that share spelling may have different
attribute "prototypes". For example, ARM's version of "interrupt"
attribute accepts a string enum, while MSP430's version accepts an
unsigned integer. Adjust ClangAttrEmitter so that the generated
`attributeStringLiteralListArg` returns the correct mask depending on
target triple.

It is worth noting that even after this change some string arguments are
still parsed as identifiers or, worse, as expressions. This is because
of some special logic in `ParseAttributeArgsCommon`. Fixing it is out of
scope of this patch.
---
 clang/include/clang/Basic/Attr.td| 82 +++-
 clang/lib/Parse/ParseDecl.cpp|  4 +-
 clang/test/Sema/attr-function-return.c   |  2 +-
 clang/test/Sema/callingconv-iamcu.c  |  2 +-
 clang/test/Sema/callingconv.c|  2 +-
 clang/test/Sema/zero_call_used_regs.c|  2 +-
 clang/test/SemaCXX/warn-consumed-parsing.cpp |  2 +-
 clang/test/SemaHLSL/shader_type_attr.hlsl|  4 +-
 clang/utils/TableGen/ClangAttrEmitter.cpp| 80 +++
 9 files changed, 119 insertions(+), 61 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..d9b55422d3a530 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -279,12 +279,15 @@ class DefaultIntArgument : 
IntArgument {
 
 // This argument is more complex, it includes the enumerator type
 // name, whether the enum type is externally defined, a list of
-// strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,
list enums, bit opt = 0, bit fake = 0,
bit isExternalType = 0>
 : Argument {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -292,10 +295,14 @@ class EnumArgument 
values,
 
 // FIXME: There should be a VariadicArgument type that takes any other type
 //of argument and generates the appropriate type.
-class VariadicEnumArgument values,
-   list enums, bit isExternalType = 0>
+class VariadicEnumArgument values, list enums,
+   bit isExternalType = 0>
 : Argument  {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -898,7 +905,7 @@ def ARMInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
   // must match.
   let Spellings = [GCC<"interrupt">];
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
1>];
@@ -1023,7 +1030,8 @@ def ExternalSourceSymbol : InheritableAttr {
 
 def Blocks : InheritableAttr {
   let Spellings = [Clang<"blocks">];
-  let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
+  let Args = [EnumArgument<"Type", "BlockType", /*is_string=*/true,
+   ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
 
@@ -1597,7 +1605,7 @@ def FlagEnum : InheritableAttr {
 def EnumExtensibility : InheritableAttr {
   let Spellings = [Clang<"enum_extensibility">];
   let Subjects = SubjectList<[Enum]>;
-  let Args = [EnumArgument<"Extensibility", "Kind",
+  let Args = [EnumArgument<"Extensibility", "Kind", /*is_string=*/false,
   ["closed", "open"], ["Closed", "Open"]>];
   let Documentation = [EnumExtensibilityDocs];
 }
@@ -1763,7 +1771,7 @@ def MipsInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // must match.
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
["vector=

[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-12-21 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

Rebased to resolve merge conflicts in Attr.td.

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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-22 Thread Sergei Barannikov via cfe-commits


@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+  if (!TRI->isReservedReg(MF, Reg))
+Reg = 0;

s-barannikov wrote:

I think we should follow gcc as much as possible. Some info can be found 
[here](https://gcc.gnu.org/onlinedocs/gcc/Global-Register-Variables.html).
In particular, gcc does not seem to require -ffixed-reg option for a register 
used in 'register asm' construct (global or local). Reserving an ABI register 
does not prohibit function calls either. I've been only able to get an error 
when trying to reserve the frame pointer.


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


[clang] [clang] Fix --entry command line option (PR #69114)

2023-12-25 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

We do use this option with gcc, this is why I filed the issue.


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


[clang] cc7dc90 - [test] Fix const-str-array-decay.cl failure on PowerPC

2023-05-15 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-15T19:56:28+03:00
New Revision: cc7dc90481d93734a56098470879189cb2e2c127

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

LOG: [test] Fix const-str-array-decay.cl failure on PowerPC

D150520 converted the test to use opaque pointers. The update version
fails on PowerPC because of different return type of the function.
This patch resolves the failure by removing the return type check;
it also makes the test look more like it was before the conversion to
prevent other potential issues caused by ABI differences across targets.

Added: 


Modified: 
clang/test/CodeGenOpenCL/const-str-array-decay.cl

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/const-str-array-decay.cl 
b/clang/test/CodeGenOpenCL/const-str-array-decay.cl
index c078b89622f5..0bffe92d6565 100644
--- a/clang/test/CodeGenOpenCL/const-str-array-decay.cl
+++ b/clang/test/CodeGenOpenCL/const-str-array-decay.cl
@@ -6,4 +6,5 @@ kernel void str_array_decy() {
   test_func("Test string literal");
 }
 
-// CHECK: call i32 @test_func(ptr addrspace(2) noundef @{{.*}})
+// CHECK: ptr addrspace(2) noundef
+// CHECK-NOT: addrspacecast



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


[clang] 25729c8 - [clang] Convert a couple of OpenMP tests to opaque pointers

2023-05-16 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-16T19:09:27+03:00
New Revision: 25729c87f4f93ab3902ed65dcdcbac824bda5385

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

LOG: [clang] Convert a couple of OpenMP tests to opaque pointers

This is a follow-up to D150608.

Added: 


Modified: 
clang/test/OpenMP/parallel_master_taskloop_private_codegen.cpp
clang/test/OpenMP/parallel_master_taskloop_simd_private_codegen.cpp
clang/test/OpenMP/taskloop_simd_lastprivate_codegen.cpp

Removed: 




diff  --git a/clang/test/OpenMP/parallel_master_taskloop_private_codegen.cpp 
b/clang/test/OpenMP/parallel_master_taskloop_private_codegen.cpp
index 47c2001c4f9b..6d5e7c121991 100644
--- a/clang/test/OpenMP/parallel_master_taskloop_private_codegen.cpp
+++ b/clang/test/OpenMP/parallel_master_taskloop_private_codegen.cpp
@@ -1,16 +1,16 @@
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s
-// RUN: %clang_cc1 -no-opaque-pointers -fopenmp -x c++ -std=c++11 -triple 
x86_64-apple-darwin10 -emit-pch -o %t %s
-// RUN: %clang_cc1 -no-opaque-pointers -fopenmp -x c++ -triple 
x86_64-apple-darwin10 -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -std=c++11 
-DLAMBDA -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck 
-check-prefix=LAMBDA %s
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -fblocks 
-DBLOCKS -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck 
-check-prefix=BLOCKS %s
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -std=c++11 
-DARRAY -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck 
-check-prefix=ARRAY %s
-
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
-// RUN: %clang_cc1 -no-opaque-pointers -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-apple-darwin10 -emit-pch -o %t %s
-// RUN: %clang_cc1 -no-opaque-pointers -fopenmp-simd -x c++ -triple 
x86_64-apple-darwin10 -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -std=c++11 
-DLAMBDA -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -fblocks 
-DBLOCKS -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp-simd -x c++ -std=c++11 
-DARRAY -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-apple-darwin10 
-emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-apple-darwin10 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -std=c++11 
-include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DLAMBDA -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=LAMBDA %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=BLOCKS %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DARRAY -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=ARRAY %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-apple-darwin10 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++11 -DLAMBDA -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -fblocks -DBLOCKS -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++11 -DARRAY -triple 
x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 
@@ -29,7 +29,7 @@ struct S {
 
 volatile double g;
 
-// CHECK-DAG: [[KMP_TASK_T_TY:%.+]] = type { i8*, i32 (i32, i8*)*, i32, 
%union{{.+}}, %union{{.+}}, i64, i64, i64, i32, i8* }
+// CHECK-DAG: [[KMP_TASK_T_TY:%.+]] = type { ptr, ptr, i32, %union{{.+}}, 
%unio

[clang] 7971d91 - [clang][CodeGen] Reformat ABIInfo.h (NFC)

2023-05-17 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-18T04:29:16+03:00
New Revision: 7971d91bbf903b894936e663e67e03ffc0c29004

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

LOG: [clang][CodeGen] Reformat ABIInfo.h (NFC)

Preparatory change for D148094.

Added: 


Modified: 
clang/lib/CodeGen/ABIInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index 1dffa41c57c5..5ce9eab7fc87 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -15,131 +15,128 @@
 #include "llvm/IR/Type.h"
 
 namespace llvm {
-  class Value;
-  class LLVMContext;
-  class DataLayout;
-  class Type;
-}
+class Value;
+class LLVMContext;
+class DataLayout;
+class Type;
+} // namespace llvm
 
 namespace clang {
-  class ASTContext;
-  class CodeGenOptions;
-  class TargetInfo;
+class ASTContext;
+class CodeGenOptions;
+class TargetInfo;
 
 namespace CodeGen {
-  class ABIArgInfo;
-  class Address;
-  class CGCXXABI;
-  class CGFunctionInfo;
-  class CodeGenFunction;
-  class CodeGenTypes;
-
-  // FIXME: All of this stuff should be part of the target interface
-  // somehow. It is currently here because it is not clear how to factor
-  // the targets to support this, since the Targets currently live in a
-  // layer below types n'stuff.
-
-
-  /// ABIInfo - Target specific hooks for defining how a type should be
-  /// passed or returned from functions.
-  class ABIInfo {
-  protected:
-CodeGen::CodeGenTypes &CGT;
-llvm::CallingConv::ID RuntimeCC;
-  public:
-ABIInfo(CodeGen::CodeGenTypes &cgt)
-: CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
-
-virtual ~ABIInfo();
-
-virtual bool allowBFloatArgsAndRet() const { return false; }
-
-CodeGen::CGCXXABI &getCXXABI() const;
-ASTContext &getContext() const;
-llvm::LLVMContext &getVMContext() const;
-const llvm::DataLayout &getDataLayout() const;
-const TargetInfo &getTarget() const;
-const CodeGenOptions &getCodeGenOpts() const;
-
-/// Return the calling convention to use for system runtime
-/// functions.
-llvm::CallingConv::ID getRuntimeCC() const {
-  return RuntimeCC;
-}
-
-virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
-
-/// EmitVAArg - Emit the target dependent code to load a value of
-/// \arg Ty from the va_list pointed to by \arg VAListAddr.
-
-// FIXME: This is a gaping layering violation if we wanted to drop
-// the ABI information any lower than CodeGen. Of course, for
-// VAArg handling it has to be at this level; there is no way to
-// abstract this out.
-virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
+class ABIArgInfo;
+class Address;
+class CGCXXABI;
+class CGFunctionInfo;
+class CodeGenFunction;
+class CodeGenTypes;
+
+// FIXME: All of this stuff should be part of the target interface
+// somehow. It is currently here because it is not clear how to factor
+// the targets to support this, since the Targets currently live in a
+// layer below types n'stuff.
+
+/// ABIInfo - Target specific hooks for defining how a type should be
+/// passed or returned from functions.
+class ABIInfo {
+protected:
+  CodeGen::CodeGenTypes &CGT;
+  llvm::CallingConv::ID RuntimeCC;
+
+public:
+  ABIInfo(CodeGen::CodeGenTypes &cgt)
+  : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
+
+  virtual ~ABIInfo();
+
+  virtual bool allowBFloatArgsAndRet() const { return false; }
+
+  CodeGen::CGCXXABI &getCXXABI() const;
+  ASTContext &getContext() const;
+  llvm::LLVMContext &getVMContext() const;
+  const llvm::DataLayout &getDataLayout() const;
+  const TargetInfo &getTarget() const;
+  const CodeGenOptions &getCodeGenOpts() const;
+
+  /// Return the calling convention to use for system runtime
+  /// functions.
+  llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
+
+  virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
+
+  /// EmitVAArg - Emit the target dependent code to load a value of
+  /// \arg Ty from the va_list pointed to by \arg VAListAddr.
+
+  // FIXME: This is a gaping layering violation if we wanted to drop
+  // the ABI information any lower than CodeGen. Of course, for
+  // VAArg handling it has to be at this level; there is no way to
+  // abstract this out.
+  virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
+ CodeGen::Address VAListAddr,
+ QualType Ty) const = 0;
+
+  bool isAndroid() const;
+  bool isOHOSFamily() const;
+
+  /// Emit the target dependent code to load a value of
+  /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
+  virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
  

[clang] 0bf5f63 - [clang] Convert several tests to opaque pointers

2023-05-18 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-18T17:01:11+03:00
New Revision: 0bf5f632ed53cb8c986d69168589228014522e1b

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

LOG: [clang] Convert several tests to opaque pointers

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D150829

Added: 


Modified: 
clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
clang/test/CodeGenCXX/address-space-cast-coerce.cpp
clang/test/CodeGenCXX/address-space-cast.cpp
clang/test/CodeGenCXX/aix-alignment.cpp
clang/test/CodeGenCXX/alignment.cpp
clang/test/CodeGenCXX/anonymous-union-member-initializer.cpp
clang/test/CodeGenCXX/arm-swiftcall.cpp
clang/test/CodeGenCXX/arm.cpp
clang/test/CodeGenCXX/arm64.cpp
clang/test/CodeGenCXX/armv7k.cpp
clang/test/CodeGenCXX/assign-operator.cpp
clang/test/CodeGenCXX/attr-musttail.cpp
clang/test/CodeGenCXX/attr-target-clones.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp 
b/clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
index 653c3d04972db..4033adc8f0390 100644
--- a/clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
+++ b/clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple 
x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s
 
 struct A {
   A(const char *);
@@ -18,9 +18,9 @@ struct S {
   { 2, "goodbye" }
 };
 
-// CHECK: store i32 0, i32* getelementptr inbounds ([3 x %struct.S], [3 x 
%struct.S]* @arr, i64 0, i64 0, i32 0)
-// CHECK: call void @_ZN1AC1EPKc(%struct.A* {{[^,]*}} getelementptr inbounds 
([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 0, i32 1), i8* noundef 
getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
-// CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.S], [3 x 
%struct.S]* @arr, i64 0, i64 1, i32 0)
-// CHECK: call void @_ZN1AC1EPKc(%struct.A* {{[^,]*}} getelementptr inbounds 
([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 1, i32 1), i8* noundef 
getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
-// CHECK: store i32 2, i32* getelementptr inbounds ([3 x %struct.S], [3 x 
%struct.S]* @arr, i64 0, i64 2, i32 0)
-// CHECK: call void @_ZN1AC1EPKc(%struct.A* {{[^,]*}} getelementptr inbounds 
([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 2, i32 1), i8* noundef 
getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
+// CHECK: store i32 0, ptr @arr
+// CHECK: call void @_ZN1AC1EPKc(ptr {{[^,]*}} getelementptr inbounds 
(%struct.S, ptr @arr, i32 0, i32 1), ptr noundef @.str)
+// CHECK: store i32 1, ptr getelementptr inbounds (%struct.S, ptr @arr, i64 1)
+// CHECK: call void @_ZN1AC1EPKc(ptr {{[^,]*}} getelementptr inbounds 
(%struct.S, ptr @arr, i64 1, i32 1), ptr noundef @.str.1)
+// CHECK: store i32 2, ptr getelementptr inbounds (%struct.S, ptr @arr, i64 2)
+// CHECK: call void @_ZN1AC1EPKc(ptr {{[^,]*}} getelementptr inbounds 
(%struct.S, ptr @arr, i64 2, i32 1), ptr noundef @.str.2)

diff  --git a/clang/test/CodeGenCXX/address-space-cast-coerce.cpp 
b/clang/test/CodeGenCXX/address-space-cast-coerce.cpp
index f131168f1c78a..7279b6c7f23a0 100644
--- a/clang/test/CodeGenCXX/address-space-cast-coerce.cpp
+++ b/clang/test/CodeGenCXX/address-space-cast-coerce.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers %s -triple=amdgcn-amd-amdhsa -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
 
 template struct my_vector_base;
 
@@ -46,8 +46,9 @@ int mane() {
 char1 f1{1};
 char1 f2{1};
 
-// CHECK: %[[a:[^ ]+]] = addrspacecast i16 addrspace(5)* %{{[^ ]+}} to i16*
-// CHECK: %[[a:[^ ]+]] = addrspacecast %{{[^ ]+}} addrspace(5)* %{{[^ ]+}} to 
%{{[^ ]+}} 
+// CHECK: [[TMP:%.+]] = alloca i16
+// CHECK: [[COERCE:%.+]] = addrspacecast ptr addrspace(5) [[TMP]] to ptr
+// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %{{.+}}, ptr align 2 
[[COERCE]], i64 1, i1 false)
 
 char1 f3 = f1 + f2;
 }

diff  --git a/clang/test/CodeGenCXX/address-space-cast.cpp 
b/clang/test/CodeGenCXX/address-space-cast.cpp
index 36a7904d6bfe8..0e3d179ee2d42 100644
--- a/clang/test/CodeGenCXX/address-space-cast.cpp
+++ b/clang/test/CodeGenCXX/address-space-cast.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers %s -triple=amdgcn-amd-amdhsa -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
 
 #define __private__ __attribute__((address_space(5)))
 
@@ -16,60 +16,61 @@ void fn(Derived *p) {
   __private__ Base *b = (__private__ Base *)p;
 }
 
+// CHECK-LABEL: test_cast
 void test_cast(char *gen_char_ptr, void *gen_void_ptr

[clang] f2492f7 - [clang][CodeGen] Break up TargetInfo.cpp [1/8]

2023-05-19 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-19T23:54:55+03:00
New Revision: f2492f7cf0b175d5d9403cbfc970a521adbde659

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

LOG: [clang][CodeGen] Break up TargetInfo.cpp [1/8]

`CCState` is a helper class originally used by the x86 implementation
but has since been abused by other implementations.
Remove this dependency by implementing customized versions of the class
for implementations that need such functionality.

Reviewed By: efriedma, MaskRay

Differential Revision: https://reviews.llvm.org/D148089

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 13c2a6b65f76..5514161da230 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -9056,13 +9056,17 @@ Address HexagonABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
 
 namespace {
 class LanaiABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   LanaiABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
 
   bool shouldUseInReg(QualType Ty, CCState &State) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // Lanai uses 4 registers to pass arguments unless the function has the
 // regparm attribute set.
 if (FI.getHasRegParm()) {
@@ -10074,6 +10078,10 @@ 
SparcV9TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
 namespace {
 
 class ARCABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   using DefaultABIInfo::DefaultABIInfo;
 
@@ -10096,7 +10104,7 @@ class ARCABIInfo : public DefaultABIInfo {
   }
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // ARC uses 8 registers to pass arguments.
 State.FreeRegs = 8;
 



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


[clang] 5a646ed - [clang][CodeGen] Break up TargetInfo.cpp [2/8]

2023-05-19 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-19T23:55:02+03:00
New Revision: 5a646ed6835f2686cc0574047ce3c9bbaf323ea3

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

LOG: [clang][CodeGen] Break up TargetInfo.cpp [2/8]

Move `ABIKind` enums out of `*ABIInfo` classes to break the dependency
between `getTargetCodeGenInfo` and the classes.
This will allow to move the classes to different cpp files.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D148090

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 5514161da230..078bd1087220 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -830,19 +830,18 @@ ABIArgInfo DefaultABIInfo::classifyReturnType(QualType 
RetTy) const {
 // This is a very simple ABI that relies a lot on DefaultABIInfo.
 
//===--===//
 
-class WebAssemblyABIInfo final : public ABIInfo {
-public:
-  enum ABIKind {
-MVP = 0,
-ExperimentalMV = 1,
-  };
+enum class WebAssemblyABIKind {
+  MVP = 0,
+  ExperimentalMV = 1,
+};
 
-private:
+class WebAssemblyABIInfo final : public ABIInfo {
   DefaultABIInfo defaultInfo;
-  ABIKind Kind;
+  WebAssemblyABIKind Kind;
 
 public:
-  explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind)
+  explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT,
+  WebAssemblyABIKind Kind)
   : ABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {}
 
 private:
@@ -866,7 +865,7 @@ class WebAssemblyABIInfo final : public ABIInfo {
 class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
 public:
   explicit WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
-WebAssemblyABIInfo::ABIKind K)
+WebAssemblyABIKind K)
   : TargetCodeGenInfo(std::make_unique(CGT, K)) {
 SwiftInfo =
 std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
@@ -931,7 +930,7 @@ ABIArgInfo 
WebAssemblyABIInfo::classifyArgumentType(QualType Ty) const {
 if (const Type *SeltTy = isSingleElementStruct(Ty, getContext()))
   return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
 // For the experimental multivalue ABI, fully expand all other aggregates
-if (Kind == ABIKind::ExperimentalMV) {
+if (Kind == WebAssemblyABIKind::ExperimentalMV) {
   const RecordType *RT = Ty->getAs();
   assert(RT);
   bool HasBitField = false;
@@ -964,7 +963,7 @@ ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType 
RetTy) const {
   if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext()))
 return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
   // For the experimental multivalue ABI, return all other aggregates
-  if (Kind == ABIKind::ExperimentalMV)
+  if (Kind == WebAssemblyABIKind::ExperimentalMV)
 return ABIArgInfo::getDirect();
 }
   }
@@ -4973,21 +4972,19 @@ 
PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
 // PowerPC-64
 
 namespace {
+enum class PPC64_SVR4_ABIKind {
+  ELFv1 = 0,
+  ELFv2,
+};
+
 /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
 class PPC64_SVR4_ABIInfo : public ABIInfo {
-public:
-  enum ABIKind {
-ELFv1 = 0,
-ELFv2
-  };
-
-private:
   static const unsigned GPRBits = 64;
-  ABIKind Kind;
+  PPC64_SVR4_ABIKind Kind;
   bool IsSoftFloatABI;
 
 public:
-  PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind,
+  PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
  bool SoftFloatABI)
   : ABIInfo(CGT), Kind(Kind), IsSoftFloatABI(SoftFloatABI) {}
 
@@ -5035,8 +5032,7 @@ class PPC64_SVR4_ABIInfo : public ABIInfo {
 class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {
 
 public:
-  PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT,
-   PPC64_SVR4_ABIInfo::ABIKind Kind,
+  PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
bool SoftFloatABI)
   : TargetCodeGenInfo(
 std::make_unique(CGT, Kind, SoftFloatABI)) {
@@ -5135,7 +5131,7 @@ CharUnits 
PPC64_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   // Likewise for ELFv2 homogeneous aggregates.
   const Type *Base = nullptr;
   uint64_t Members = 0;
-  if (!AlignAsType && Kind == ELFv2 &&
+  if (!AlignAsType && Kind == PPC64_SVR4_ABIKind::ELFv2 &&
   isAggregateTypeForABI(Ty) && isHomogeneousAggregate(Ty, Base, Members))
 AlignAsType = Base;
 
@@ -5329,7 +5325,7 @@ PPC64_SVR4_ABIInfo::classifyArgumentType(

[clang] 0a86e05 - [clang][CodeGen] Break up TargetInfo.cpp [4/8]

2023-05-19 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-19T23:55:15+03:00
New Revision: 0a86e05d1da0f544920b1eff6656c5577fb6562f

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

LOG: [clang][CodeGen] Break up TargetInfo.cpp [4/8]

Remove `getABIInfo` overrides returning references to target-specific
implementations of `ABIInfo`.
The methods may be convenient, but they are only used in one place and
prevent from `ABIInfo` implementations from being put into anonymous
namespaces in different cpp files.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D148092

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 4a4426528c37..7cd22bfb30a3 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -2476,10 +2476,6 @@ class X86_64TargetCodeGenInfo : public TargetCodeGenInfo 
{
 std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
   }
 
-  const X86_64ABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   /// Disable tail call on x86-64. The epilogue code before the tail jump 
blocks
   /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations.
   bool markARCOptimizedReturnCallsAsNoTail() const override { return true; }
@@ -2516,7 +2512,7 @@ class X86_64TargetCodeGenInfo : public TargetCodeGenInfo {
   bool HasAVXType = false;
   for (CallArgList::const_iterator
  it = args.begin(), ie = args.end(); it != ie; ++it) {
-if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
+if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
   HasAVXType = true;
   break;
 }
@@ -6388,10 +6384,6 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
 SwiftInfo = std::make_unique(CGT);
   }
 
-  const ARMABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 return 13;
   }
@@ -6410,7 +6402,8 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
   }
 
   unsigned getSizeOfUnwindException() const override {
-if (getABIInfo().isEABI()) return 88;
+if (getABIInfo().isEABI())
+  return 88;
 return TargetCodeGenInfo::getSizeOfUnwindException();
   }
 
@@ -6477,7 +6470,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
 
 Fn->addFnAttr("interrupt", Kind);
 
-ARMABIKind ABI = cast(getABIInfo()).getABIKind();
+ARMABIKind ABI = getABIInfo().getABIKind();
 if (ABI == ARMABIKind::APCS)
   return;
 
@@ -7415,10 +7408,6 @@ class SystemZABIInfo : public ABIInfo {
 class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
   ASTContext &Ctx;
 
-  const SystemZABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   // These are used for speeding up the search for a visible vector ABI.
   mutable bool HasVisibleVecABIFlag = false;
   mutable std::set SeenTypes;
@@ -7867,8 +7856,9 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const 
Type *Ty,
 // it will be passed in a vector register. A wide (>16 bytes) vector will
 // be passed via "hidden" pointer where any extra alignment is not
 // required (per GCC).
-const Type *SingleEltTy =
-  getABIInfo().GetSingleElementType(QualType(Ty, 0)).getTypePtr();
+const Type *SingleEltTy = getABIInfo()
+  .GetSingleElementType(QualType(Ty, 0))
+  .getTypePtr();
 bool SingleVecEltStruct = SingleEltTy != Ty && SingleEltTy->isVectorType() 
&&
   Ctx.getTypeSize(SingleEltTy) == Ctx.getTypeSize(Ty);
 if (Ty->isVectorType() || SingleVecEltStruct)
@@ -11841,10 +11831,6 @@ class BPFTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   BPFTargetCodeGenInfo(CodeGenTypes &CGT)
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
-
-  const BPFABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
 };
 
 }

diff  --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 7b5532eaf7b6..7637e55ccf41 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -52,6 +52,11 @@ class TargetCodeGenInfo {
   // by returning true from TargetInfo::checkCallingConvention for them.
   std::unique_ptr SwiftInfo;
 
+  // Returns ABI info helper for the target. This is for use by derived 
classes.
+  template  const T &getABIInfo() const {
+return static_cast(*Info);
+  }
+
 public:
   TargetCodeGenInfo(std::unique_ptr Info);
   virtual ~TargetCodeGenInfo();



___

[clang] f60cc01 - [clang][CodeGen] Break up TargetInfo.cpp [5/8]

2023-05-19 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-19T23:55:21+03:00
New Revision: f60cc01e9e75785dd2476c7e05da689be5a99839

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

LOG: [clang][CodeGen] Break up TargetInfo.cpp [5/8]

Make `occupiesMoreThan` a protected member of `SwiftABIInfo`.
This method is only used by implementations of `SwiftABIInfo`.
Making it protected will allow to use it after the implementations
are moved to dedicated cpp files.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D148093

Added: 


Modified: 
clang/lib/CodeGen/ABIInfo.h
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index 5ce9eab7fc87..3caad8fe9dea 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -117,6 +117,9 @@ class SwiftABIInfo {
   CodeGenTypes &CGT;
   bool SwiftErrorInRegister;
 
+  bool occupiesMoreThan(ArrayRef scalarTypes,
+unsigned maxAllRegisters) const;
+
 public:
   SwiftABIInfo(CodeGen::CodeGenTypes &CGT, bool SwiftErrorInRegister)
   : CGT(CGT), SwiftErrorInRegister(SwiftErrorInRegister) {}

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 7cd22bfb30a3..3d56d0e0b012 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -125,7 +125,7 @@ SwiftABIInfo::~SwiftABIInfo() = default;
 /// registers when expanded?
 ///
 /// This is intended to be the basis of a reasonable basic implementation
-/// of should{Pass,Return}IndirectlyForSwift.
+/// of should{Pass,Return}Indirectly.
 ///
 /// For most targets, a limit of four total registers is reasonable; this
 /// limits the amount of code required in order to move around the value
@@ -134,15 +134,14 @@ SwiftABIInfo::~SwiftABIInfo() = default;
 /// immediately within the callee.  But some targets may need to further
 /// limit the register count due to an inability to support that many
 /// return registers.
-static bool occupiesMoreThan(CodeGenTypes &cgt,
- ArrayRef scalarTypes,
- unsigned maxAllRegisters) {
+bool SwiftABIInfo::occupiesMoreThan(ArrayRef scalarTypes,
+unsigned maxAllRegisters) const {
   unsigned intCount = 0, fpCount = 0;
   for (llvm::Type *type : scalarTypes) {
 if (type->isPointerTy()) {
   intCount++;
 } else if (auto intTy = dyn_cast(type)) {
-  auto ptrWidth = cgt.getTarget().getPointerWidth(LangAS::Default);
+  auto ptrWidth = CGT.getTarget().getPointerWidth(LangAS::Default);
   intCount += (intTy->getBitWidth() + ptrWidth - 1) / ptrWidth;
 } else {
   assert(type->isVectorTy() || type->isFloatingPointTy());
@@ -155,7 +154,7 @@ static bool occupiesMoreThan(CodeGenTypes &cgt,
 
 bool SwiftABIInfo::shouldPassIndirectly(ArrayRef ComponentTys,
 bool AsReturnValue) const {
-  return occupiesMoreThan(CGT, ComponentTys, /*total=*/4);
+  return occupiesMoreThan(ComponentTys, /*total=*/4);
 }
 
 bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
@@ -1248,7 +1247,7 @@ class X86_32SwiftABIInfo : public SwiftABIInfo {
 // integer registers and three fp registers.  Oddly, it'll use up to
 // four vector registers for vectors, but those can overlap with the
 // scalar registers.
-return occupiesMoreThan(CGT, ComponentTys, /*total=*/3);
+return occupiesMoreThan(ComponentTys, /*total=*/3);
   }
 };
 



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


[clang] 940b020 - [clang][CodeGen] Break up TargetInfo.cpp [3/8]

2023-05-19 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-05-19T23:55:08+03:00
New Revision: 940b02095bf986b5bcc365dc97667a27176c3b13

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

LOG: [clang][CodeGen] Break up TargetInfo.cpp [3/8]

Don't derive from `DefaultTargetCodeGenInfo`.
This class is going to stay in `TargetInfo.cpp`, whereas its derivants
are going to be moved to separate translation units. Just derive from
the base `TargetCodeGenInfo` class instead.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D148091

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 078bd1087220..4a4426528c37 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -5049,9 +5049,10 @@ class PPC64_SVR4_TargetCodeGenInfo : public 
TargetCodeGenInfo {
llvm::Value *Address) const override;
 };
 
-class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  PPC64TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {}
+  PPC64TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 // This is recovered from gcc output.
@@ -5061,7 +5062,6 @@ class PPC64TargetCodeGenInfo : public 
DefaultTargetCodeGenInfo {
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const override;
 };
-
 }
 
 // Return true if the ABI requires Ty to be passed sign- or zero-
@@ -8584,10 +8584,10 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 
 namespace {
 
-class TCETargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class TCETargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   TCETargetCodeGenInfo(CodeGenTypes &CGT)
-: DefaultTargetCodeGenInfo(CGT) {}
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;



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


[clang] 2348902 - [clang][CodeGen] Remove no-op EmitCastToVoidPtr (NFC)

2023-06-29 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-06-29T20:29:38+03:00
New Revision: 2348902268613a2120bc2d7f3fc8b683d4c114d7

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

LOG: [clang][CodeGen] Remove no-op EmitCastToVoidPtr (NFC)

Reviewed By: JOE1994

Differential Revision: https://reviews.llvm.org/D153694

Added: 


Modified: 
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCXXABI.h
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index f191829b41552..222b0a192c85e 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -80,23 +80,23 @@ namespace {
 AtomicSizeInBits = C.toBits(
 C.toCharUnitsFromBits(Offset + OrigBFI.Size + C.getCharWidth() - 1)
 .alignTo(lvalue.getAlignment()));
-auto VoidPtrAddr = CGF.EmitCastToVoidPtr(lvalue.getBitFieldPointer());
+llvm::Value *BitFieldPtr = lvalue.getBitFieldPointer();
 auto OffsetInChars =
 (C.toCharUnitsFromBits(OrigBFI.Offset) / lvalue.getAlignment()) *
 lvalue.getAlignment();
-VoidPtrAddr = CGF.Builder.CreateConstGEP1_64(
-CGF.Int8Ty, VoidPtrAddr, OffsetInChars.getQuantity());
-llvm::Type *IntTy = CGF.Builder.getIntNTy(AtomicSizeInBits);
-auto Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-VoidPtrAddr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
+llvm::Value *StoragePtr = CGF.Builder.CreateConstGEP1_64(
+CGF.Int8Ty, BitFieldPtr, OffsetInChars.getQuantity());
+StoragePtr = CGF.Builder.CreateAddrSpaceCast(
+StoragePtr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
 "atomic_bitfield_base");
 BFI = OrigBFI;
 BFI.Offset = Offset;
 BFI.StorageSize = AtomicSizeInBits;
 BFI.StorageOffset += OffsetInChars;
-LVal = LValue::MakeBitfield(Address(Addr, IntTy, 
lvalue.getAlignment()),
-BFI, lvalue.getType(), 
lvalue.getBaseInfo(),
-lvalue.getTBAAInfo());
+llvm::Type *StorageTy = CGF.Builder.getIntNTy(AtomicSizeInBits);
+LVal = LValue::MakeBitfield(
+Address(StoragePtr, StorageTy, lvalue.getAlignment()), BFI,
+lvalue.getType(), lvalue.getBaseInfo(), lvalue.getTBAAInfo());
 AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
 if (AtomicTy.isNull()) {
   llvm::APInt Size(
@@ -805,8 +805,7 @@ AddDirectArgument(CodeGenFunction &CGF, CallArgList &Args,
 Args.add(RValue::get(Val), ValTy);
   } else {
 // Non-optimized functions always take a reference.
-Args.add(RValue::get(CGF.EmitCastToVoidPtr(Val)),
- CGF.getContext().VoidPtrTy);
+Args.add(RValue::get(Val), CGF.getContext().VoidPtrTy);
   }
 }
 
@@ -1103,8 +1102,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   *this, V, AS, LangAS::opencl_generic, DestType, false);
 };
 
-Args.add(RValue::get(CastToGenericAddrSpace(
- EmitCastToVoidPtr(Ptr.getPointer()), E->getPtr()->getType())),
+Args.add(RValue::get(CastToGenericAddrSpace(Ptr.getPointer(),
+E->getPtr()->getType())),
  getContext().VoidPtrTy);
 
 std::string LibCallName;
@@ -1137,10 +1136,9 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   LibCallName = "__atomic_compare_exchange";
   RetTy = getContext().BoolTy;
   HaveRetTy = true;
-  Args.add(
-  RValue::get(CastToGenericAddrSpace(
-  EmitCastToVoidPtr(Val1.getPointer()), E->getVal1()->getType())),
-  getContext().VoidPtrTy);
+  Args.add(RValue::get(CastToGenericAddrSpace(Val1.getPointer(),
+  E->getVal1()->getType())),
+   getContext().VoidPtrTy);
   AddDirectArgument(*this, Args, UseOptimizedLibcall, Val2.getPointer(),
 MemTy, E->getExprLoc(), TInfo.Width);
   Args.add(RValue::get(Order), getContext().IntTy);
@@ -1302,8 +1300,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   } else {
 // Value is returned through parameter before the order.
 RetTy = getContext().VoidTy;
-Args.add(RValue::get(EmitCastToVoidPtr(Dest.getPointer())),
-   

[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

Why don't just turn SLocEntry into a POD and use 
SmallVector::resize_for_overwrite? That way the vector will not be initialized 
and the OS will only allocate physical memory on the first access to a page.


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


[clang] Introduce paged vector (PR #66430)

2023-09-15 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

> Why don't just turn SLocEntry into a POD (if it is not yet already) and use 
> SmallVector::resize_for_overwrite? That way the vector will not be 
> initialized and the OS will only allocate physical memory on the first access 
> to a page.

Never mind, it isn't "just", the class is more complex than it looks, and there 
is also QualType.
Still, the introduced class partially repeats the work done by the operating 
system, that is allocating pages on first access.
I can't suggest how this fact can be used though.

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


[clang] [clang] Fix --entry command line option (PR #69114)

2023-10-26 Thread Sergei Barannikov via cfe-commits


@@ -5474,7 +5474,8 @@ def _dyld_prefix_EQ : Joined<["--"], "dyld-prefix=">;
 def _dyld_prefix : Separate<["--"], "dyld-prefix">, Alias<_dyld_prefix_EQ>;
 def _encoding_EQ : Joined<["--"], "encoding=">, Alias;
 def _encoding : Separate<["--"], "encoding">, Alias;
-def _entry : Flag<["--"], "entry">, Alias;
+def : Joined<["--"], "entry=">, Flags<[LinkerInput]>, Group, 
Alias;
+def _entry : Separate<["--"], "entry">, Flags<[LinkerInput]>, 
Group, Alias;

s-barannikov wrote:

This should also be unnamed, I guess?


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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-27 Thread Sergei Barannikov via cfe-commits


@@ -886,7 +893,7 @@ def ARMInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
   // must match.
   let Spellings = [GCC<"interrupt">];
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,

s-barannikov wrote:

It appears that named arguments can only be specified [after all positional 
arguments](https://github.com/llvm/llvm-project/commit/91ccbc6c1c4c121935ee4fbfa0db13ad86590a59#diff-059342ba8068cf430c4000171f8873858823c8fd473cc38aa1dc719bf0b8104aR3194-R3197).
If I move `is_string` before `opt`, this can break downstream code because 
values supplied for `opt` will now be passed to `is_string. The other option is 
to make `is_string` optional and to move it to the end of the list, but I 
really wouldn't want to do this because there is no valid default value for 
this argument.


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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-27 Thread Sergei Barannikov via cfe-commits

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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-27 Thread Sergei Barannikov via cfe-commits


@@ -274,20 +274,27 @@ class DefaultIntArgument : 
IntArgument {
 }
 
 // This argument is more complex, it includes the enumerator type name,
-// a list of strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// a list of possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,

s-barannikov wrote:

I'm not sure I understand, could you elaborate?


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


[clang] 79f87be - [clang] Fix several issues in the generated AttrHasAttributeImpl.inc

2023-10-09 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-10-10T09:03:55+03:00
New Revision: 79f87be6888d13a94661be9d8908c83dd2229c9b

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

LOG: [clang] Fix several issues in the generated AttrHasAttributeImpl.inc

1. The generated file contained a lot of duplicate switch cases, e.g.:
```
switch (Syntax) {
case AttributeCommonInfo::Syntax::AS_GNU:
  return llvm::StringSwitch(Name)
...
.Case("error", 1)
.Case("warning", 1)
.Case("error", 1)
.Case("warning", 1)
```

2. Some attributes were listed in wrong places, e.g.:
```
case AttributeCommonInfo::Syntax::AS_CXX11: {
if (ScopeName == "") {
  return llvm::StringSwitch(Name)
...
.Case("warn_unused_result", LangOpts.CPlusPlus11 ? 201907 : 0)
```

`warn_unused_result` is a non-standard attribute and should not be
available as [[warn_unused_result]].

3. Some attributes had the wrong version, e.g.:
```
case AttributeCommonInfo::Syntax::AS_CXX11: {
} else if (ScopeName == "gnu") {
  return llvm::StringSwitch(Name)
...
.Case("fallthrough", LangOpts.CPlusPlus11 ? 201603 : 0)
```

[[gnu::fallthrough]] is a non-standard spelling and should not have the
standard version. Instead, __has_cpp_attribute should return 1 for it.

There is another issue with attributes that share spellings, e.g.:
```
.Case("interrupt", true && (T.getArch() == llvm::Triple::arm || ...) ? 1 : 
0)
.Case("interrupt", true && (T.getArch() == llvm::Triple::avr) ? 1 : 0)
...
.Case("interrupt", true && (T.getArch() == llvm::Triple::riscv32 || ...) ? 
1 : 0)
```
As can be seen, __has_attribute(interrupt) would only return true for
ARM targets. This patch does not address this issue.

Differential Revision: https://reviews.llvm.org/D159393

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/Preprocessor/has_attribute.c
clang/test/Preprocessor/has_attribute.cpp
clang/test/Preprocessor/has_c_attribute.c
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d85db6f795c5274..c1db779cc86cb97 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -45,6 +45,24 @@ C/C++ Language Potentially Breaking Changes
   -xc++-header``) is now ``.pch`` instead of ``.gch``.
 - ``-include a.h`` probing ``a.h.gch`` is deprecated. Change the extension name
   to ``.pch`` or use ``-include-pch a.h.gch``.
+- Fixed a bug that caused ``__has_cpp_attribute`` and ``__has_c_attribute``
+  return incorrect values for some C++-11-style attributes. Below is a complete
+  list of behavior changes.
+
+  .. csv-table::
+:header: Test, Old value, New value
+
+``__has_cpp_attribute(unused)``,201603, 0
+``__has_cpp_attribute(gnu::unused)``,   201603, 1
+``__has_c_attribute(unused)``,  202106, 0
+``__has_cpp_attribute(clang::fallthrough)``,201603, 1
+``__has_cpp_attribute(gnu::fallthrough)``,  201603, 1
+``__has_c_attribute(gnu::fallthrough)``,201910, 1
+``__has_cpp_attribute(warn_unused_result)``,201907, 0
+``__has_cpp_attribute(clang::warn_unused_result)``, 201907, 1
+``__has_cpp_attribute(gnu::warn_unused_result)``,   201907, 1
+``__has_c_attribute(warn_unused_result)``,  202003, 0
+``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
 
 C++ Specific Potentially Breaking Changes
 -

diff  --git a/clang/test/Preprocessor/has_attribute.c 
b/clang/test/Preprocessor/has_attribute.c
index 77787c9b64edb53..0ba664a53e64962 100644
--- a/clang/test/Preprocessor/has_attribute.c
+++ b/clang/test/Preprocessor/has_attribute.c
@@ -10,6 +10,11 @@ int always_inline();
 int __always_inline__();
 #endif
 
+// CHECK: warn_unused_result
+#if __has_attribute(warn_unused_result)
+int warn_unused_result();
+#endif
+
 // CHECK: no_dummy_attribute
 #if !__has_attribute(dummy_attribute)
 int no_dummy_attribute();

diff  --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 3fb99eda699b3cf..33546dbb175f617 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -3,14 +3,14 @@
 
 #define CXX11(x) x: __has_cpp_attribute(x)
 
-// CHECK: clang::fallthrough: 201603L
+// CHECK: clang::fallthrough: 1
 CXX11(clang::fallthrough)
 
 // CHECK: selectany: 0
 CXX11(selectany)
 
 // The attribute name can be bracketed with double underscores.
-// CHECK: clang::__fallthrough__: 201603L
+// CHECK: clang::__fallthrough__: 1
 CXX11(clang::__fallthrough__)
 
 // The scope cannot be bracketed with double underscores unless it is
@@ -18,12 +18,21 @@ CXX11(clang::__fallthrough__)
 // CHEC

[clang] [clang] Fix --entry command line option (PR #69114)

2023-10-15 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.

Thanks, LGTM
(Please make sure to edit the description before merging so that `git log` does 
not contain irrelevant information.)

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


[clang] a7eaaba - [Parser] Parse string literal arguments of 'availability', 'external_source_symbol' and 'uuid' attributes as unevaluated

2023-08-30 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-08-30T11:46:54+03:00
New Revision: a7eaaba69906d3305752cb738332b9365e666def

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

LOG: [Parser] Parse string literal arguments of 'availability', 
'external_source_symbol' and 'uuid' attributes as unevaluated

This is a complementary to D156237.
These attributes have custom parsing logic.

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D159024

Added: 


Modified: 
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/attr-availability-xcore.c
clang/test/Parser/attr-availability.c
clang/test/Parser/attr-external-source-symbol.m
clang/test/Parser/ms-square-bracket-attributes.mm

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 8daa33a2a7b5b8..7c27a02ee4af62 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -1316,31 +1316,19 @@ void Parser::ParseAvailabilityAttribute(
 }
 ConsumeToken();
 if (Keyword == Ident_message || Keyword == Ident_replacement) {
-  if (Tok.isNot(tok::string_literal)) {
+  if (!isTokenStringLiteral()) {
 Diag(Tok, diag::err_expected_string_literal)
   << /*Source='availability attribute'*/2;
 SkipUntil(tok::r_paren, StopAtSemi);
 return;
   }
-  if (Keyword == Ident_message)
-MessageExpr = ParseStringLiteralExpression();
-  else
-ReplacementExpr = ParseStringLiteralExpression();
-  // Also reject wide string literals.
-  if (StringLiteral *MessageStringLiteral =
-  cast_or_null(MessageExpr.get())) {
-if (!MessageStringLiteral->isOrdinary()) {
-  Diag(MessageStringLiteral->getSourceRange().getBegin(),
-   diag::err_expected_string_literal)
-<< /*Source='availability attribute'*/ 2;
-  SkipUntil(tok::r_paren, StopAtSemi);
-  return;
-}
-  }
-  if (Keyword == Ident_message)
+  if (Keyword == Ident_message) {
+MessageExpr = ParseUnevaluatedStringLiteralExpression();
 break;
-  else
+  } else {
+ReplacementExpr = ParseUnevaluatedStringLiteralExpression();
 continue;
+  }
 }
 
 // Special handling of 'NA' only when applied to introduced or
@@ -1508,7 +1496,7 @@ void Parser::ParseExternalSourceSymbolAttribute(
 else
   HasDefinedIn = true;
 
-if (Tok.isNot(tok::string_literal)) {
+if (!isTokenStringLiteral()) {
   Diag(Tok, diag::err_expected_string_literal)
   << /*Source='external_source_symbol attribute'*/ 3
   << /*language | source container | USR*/ (
@@ -1522,27 +1510,27 @@ void Parser::ParseExternalSourceSymbolAttribute(
   if (HadLanguage) {
 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
 << Keyword;
-ParseStringLiteralExpression();
+ParseUnevaluatedStringLiteralExpression();
 continue;
   }
-  Language = ParseStringLiteralExpression();
+  Language = ParseUnevaluatedStringLiteralExpression();
 } else if (Keyword == Ident_USR) {
   if (HadUSR) {
 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
 << Keyword;
-ParseStringLiteralExpression();
+ParseUnevaluatedStringLiteralExpression();
 continue;
   }
-  USR = ParseStringLiteralExpression();
+  USR = ParseUnevaluatedStringLiteralExpression();
 } else {
   assert(Keyword == Ident_defined_in && "Invalid clause keyword!");
   if (HadDefinedIn) {
 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
 << Keyword;
-ParseStringLiteralExpression();
+ParseUnevaluatedStringLiteralExpression();
 continue;
   }
-  DefinedInExpr = ParseStringLiteralExpression();
+  DefinedInExpr = ParseUnevaluatedStringLiteralExpression();
 }
   } while (TryConsumeToken(tok::comma));
 

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 186a5e61a8fa32..730b6e55246d6b 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4715,9 +4715,9 @@ void 
Parser::ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs) {
   }
 
   ArgsVector ArgExprs;
-  if (Tok.is(tok::string_literal)) {
+  if (isTokenStringLiteral()) {
 // Easy case: uuid("...") -- quoted string.
-ExprResult StringResult = ParseStringLiteralExpression();
+ExprResult StringResult = ParseUnevaluatedStringLiteralExpression();
 if (StringResult.isInvalid())
   return;
 ArgExprs.push_back(StringResult.get());
@@ -4772,7 +4772,7 @@ void 
Parser::ParseMicrosoftUu

[clang] 18a628e - [AST] Use correct APSInt width when evaluating string literals

2023-09-05 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-09-05T19:14:09+03:00
New Revision: 18a628ec4ef72bcc005e2e9d5757445c31c6e2f8

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

LOG: [AST] Use correct APSInt width when evaluating string literals

The width of the APSInt values should be the width of an element.
getCharByteWidth returns the size of an element in _host_ bytes, which
makes the width N times greater, where N is the ratio between target's
CHAR_BIT and host's CHAR_BIT.
This is NFC for in-tree targets because all of them have CHAR_BIT == 8.

Reviewed By: cor3ntin, aaron.ballman

Differential Revision: https://reviews.llvm.org/D154773

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0f37bcf0d5c852..d8632f53bb1eef 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3463,8 +3463,7 @@ static APSInt extractStringLiteralCharacter(EvalInfo 
&Info, const Expr *Lit,
   assert(CAT && "string literal isn't an array");
   QualType CharType = CAT->getElementType();
   assert(CharType->isIntegerType() && "unexpected character type");
-
-  APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(),
+  APSInt Value(Info.Ctx.getTypeSize(CharType),
CharType->isUnsignedIntegerType());
   if (Index < S->getLength())
 Value = S->getCodeUnit(Index);
@@ -3487,7 +3486,7 @@ static void expandStringLiteral(EvalInfo &Info, const 
StringLiteral *S,
   unsigned Elts = CAT->getSize().getZExtValue();
   Result = APValue(APValue::UninitArray(),
std::min(S->getLength(), Elts), Elts);
-  APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(),
+  APSInt Value(Info.Ctx.getTypeSize(CharType),
CharType->isUnsignedIntegerType());
   if (Result.hasArrayFiller())
 Result.getArrayFiller() = APValue(Value);



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


[clang] 8a0e0c2 - [NFC] Use `llvm::enumerate` in llvm/unittests/Object

2023-01-16 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-01-16T15:59:31+03:00
New Revision: 8a0e0c226018a77ea148e128c97c2592e6f25416

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

LOG: [NFC] Use `llvm::enumerate` in llvm/unittests/Object

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D141788

Added: 


Modified: 
clang/docs/tools/clang-formatted-files.txt
llvm/unittests/Object/ELFObjectFileTest.cpp

Removed: 




diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 708501329238b..6730aacf43cd4 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -7310,6 +7310,7 @@ llvm/unittests/MC/AMDGPU/DwarfRegMappings.cpp
 llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
 llvm/unittests/ObjCopy/ObjCopyTest.cpp
 llvm/unittests/Object/ArchiveTest.cpp
+llvm/unittests/Object/ELFObjectFileTest.cpp
 llvm/unittests/Object/ELFTest.cpp
 llvm/unittests/Object/ELFTypesTest.cpp
 llvm/unittests/Object/MinidumpTest.cpp

diff  --git a/llvm/unittests/Object/ELFObjectFileTest.cpp 
b/llvm/unittests/Object/ELFObjectFileTest.cpp
index 577cec5152e5e..af8b300ddc21f 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -7,8 +7,9 @@
 
//===--===//
 
 #include "llvm/Object/ELFObjectFile.h"
-#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ObjectYAML/yaml2obj.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
@@ -86,38 +87,33 @@ std::array generateData(uint16_t Machine) {
 TEST(ELFObjectFileTest, MachineTestForNoneOrUnused) {
   std::array Formats = {"elf32-unknown", "elf32-unknown",
   "elf64-unknown", "elf64-unknown"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_NONE))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (auto [Idx, Data] : enumerate(generateData(ELF::EM_NONE)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 
   // Test an arbitrary unused EM_* value (255).
-  I = 0;
-  for (const DataForTest &D : generateData(255))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (auto [Idx, Data] : enumerate(generateData(255)))
+checkFormatAndArch(Data, Formats[Idx], Triple::UnknownArch);
 }
 
 TEST(ELFObjectFileTest, MachineTestForVE) {
   std::array Formats = {"elf32-unknown", "elf32-unknown",
   "elf64-ve", "elf64-ve"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_VE))
-checkFormatAndArch(D, Formats[I++], Triple::ve);
+  for (auto [Idx, Data] : enumerate(generateData(ELF::EM_VE)))
+checkFormatAndArch(Data, Formats[Idx], Triple::ve);
 }
 
 TEST(ELFObjectFileTest, MachineTestForX86_64) {
   std::array Formats = {"elf32-x86-64", "elf32-x86-64",
   "elf64-x86-64", "elf64-x86-64"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_X86_64))
-checkFormatAndArch(D, Formats[I++], Triple::x86_64);
+  for (auto [Idx, Data] : enumerate(generateData(ELF::EM_X86_64)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86_64);
 }
 
 TEST(ELFObjectFileTest, MachineTestFor386) {
   std::array Formats = {"elf32-i386", "elf32-i386", "elf64-i386",
   "elf64-i386"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_386))
-checkFormatAndArch(D, Formats[I++], Triple::x86);
+  for (auto [Idx, Data] : enumerate(generateData(ELF::EM_386)))
+checkFormatAndArch(Data, Formats[Idx], Triple::x86);
 }
 
 TEST(ELFObjectFileTest, MachineTestForMIPS) {
@@ -125,27 +121,22 @@ TEST(ELFObjectFileTest, MachineTestForMIPS) {
   "elf64-mips"};
   std::array Archs = {Triple::mipsel, Triple::mips,
Triple::mips64el, Triple::mips64};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_MIPS)) {
-checkFormatAndArch(D, Formats[I], Archs[I]);
-++I;
-  }
+  for (auto [Idx, Data] : enumerate(generateData(ELF::EM_MIPS)))
+checkFormatAndArch(Data, Formats[Idx], Archs[Idx]);
 }
 
 TEST(ELFObjectFileTest, MachineTestForAMDGPU) {
   std::array Formats = {"elf32-amdgpu", "elf32-amdgpu",
   "elf64-amdgpu", "elf64-amdgpu"};
-  size_t I = 0;
-  for (const DataForTest &D : generateData(ELF::EM_AMDGPU))
-checkFormatAndArch(D, Formats[I++], Triple::UnknownArch);
+  for (auto [Idx, Data] : enumerate(generateData(ELF::EM_AMDGPU)))
+checkFo

[clang] 0f4d48d - [clang] Replace use of Type::getPointerTo() (NFC)

2023-06-16 Thread Sergei Barannikov via cfe-commits

Author: Youngsuk Kim
Date: 2023-06-16T22:07:32+03:00
New Revision: 0f4d48d73d3941ed554ecd9d4bb285176ec01954

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

LOG: [clang] Replace use of Type::getPointerTo() (NFC)

Partial progress towards replacing in-tree uses of `Type::getPointerTo()`.
This needs to be done before deprecating the API.

Reviewed By: nikic, barannikov88

Differential Revision: https://reviews.llvm.org/D152321

Added: 


Modified: 
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGCXX.cpp
clang/lib/CodeGen/CGCXXABI.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CGException.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CGObjCRuntime.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 95f943d4bd67f..6740df8270b3d 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -88,7 +88,8 @@ namespace {
 CGF.Int8Ty, VoidPtrAddr, OffsetInChars.getQuantity());
 llvm::Type *IntTy = CGF.Builder.getIntNTy(AtomicSizeInBits);
 auto Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-VoidPtrAddr, IntTy->getPointerTo(), "atomic_bitfield_base");
+VoidPtrAddr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
+"atomic_bitfield_base");
 BFI = OrigBFI;
 BFI.Offset = Offset;
 BFI.StorageSize = AtomicSizeInBits;
@@ -796,8 +797,7 @@ AddDirectArgument(CodeGenFunction &CGF, CallArgList &Args,
 ValTy =
 CGF.getContext().getIntTypeForBitwidth(SizeInBits, /*Signed=*/false);
 llvm::Type *ITy = llvm::IntegerType::get(CGF.getLLVMContext(), SizeInBits);
-Address Ptr = Address(CGF.Builder.CreateBitCast(Val, ITy->getPointerTo()),
-  ITy, Align);
+Address Ptr = Address(Val, ITy, Align);
 Val = CGF.EmitLoadOfScalar(Ptr, false,
CGF.getContext().getPointerType(ValTy),
Loc);

diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 6e4a0dbf23357..100144cabbf48 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1427,7 +1427,8 @@ void CodeGenFunction::setBlockContextParameter(const 
ImplicitParamDecl *D,
   // directly as BlockPointer.
   BlockPointer = Builder.CreatePointerCast(
   arg,
-  BlockInfo->StructureType->getPointerTo(
+  llvm::PointerType::get(
+  getLLVMContext(),
   getContext().getLangOpts().OpenCL
   ? getContext().getTargetAddressSpace(LangAS::opencl_generic)
   : 0),

diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 902fd94570837..13049beec932b 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -159,9 +159,8 @@ class CGBuilderTy : public CGBuilderBaseTy {
   /// preserving information like the alignment and address space.
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,
const llvm::Twine &Name = "") {
-auto *PtrTy = Ty->getPointerTo(Addr.getAddressSpace());
-return Address(CreateBitCast(Addr.getPointer(), PtrTy, Name), Ty,
-   Addr.getAlignment(), Addr.isKnownNonNull());
+return Address(Addr.getPointer(), Ty, Addr.getAlignment(),
+   Addr.isKnownNonNull());
   }
 
   using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4939392f5d148..405ffe3837446 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -219,7 +219,8 @@ static Value *MakeBinaryAtomicValue(
   llvm::IntegerType *IntType =
 llvm::IntegerType::get(CGF.getLLVMContext(),
CGF.getContext().getTypeSize(T));
-  llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace);
+  llvm::Type *IntPtrType =
+  llvm::PointerType::get(CGF.getLLVMContext(), AddrSpace);
 
   llvm::Value *Args[2];
   Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType);
@@ -276,18 +277,15 @@ static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF,
   assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
 
   llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E);
-  unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace();
 
-  llvm::IntegerType *IntType =
-llvm::Inte

[clang] 6353477 - [clang][CodeGen] Break up TargetInfo.cpp [7/8]

2023-06-16 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-06-17T07:14:43+03:00
New Revision: 63534779b4ef1816e2961246011e2ec3be110d27

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

LOG: [clang][CodeGen] Break up TargetInfo.cpp [7/8]

Wrap calls to XXXTargetCodeGenInfo constructors into factory functions.
This allows moving implementations of TargetCodeGenInfo to dedicated cpp
files without a change.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D150215

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 81d6670840ddb..b28d20aca00e1 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -829,11 +829,6 @@ ABIArgInfo DefaultABIInfo::classifyReturnType(QualType 
RetTy) const {
 // This is a very simple ABI that relies a lot on DefaultABIInfo.
 
//===--===//
 
-enum class WebAssemblyABIKind {
-  MVP = 0,
-  ExperimentalMV = 1,
-};
-
 class WebAssemblyABIInfo final : public ABIInfo {
   DefaultABIInfo defaultInfo;
   WebAssemblyABIKind Kind;
@@ -2251,12 +2246,6 @@ bool X86_32TargetCodeGenInfo::initDwarfEHRegSizeTable(
 
 
 namespace {
-/// The AVX ABI level for X86 targets.
-enum class X86AVXABILevel {
-  None,
-  AVX,
-  AVX512
-};
 
 /// \p returns the size in bits of the largest (native) vector for \p AVXLevel.
 static unsigned getNativeVectorSizeForAVXABI(X86AVXABILevel AVXLevel) {
@@ -4983,10 +4972,6 @@ 
PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
 // PowerPC-64
 
 namespace {
-enum class PPC64_SVR4_ABIKind {
-  ELFv1 = 0,
-  ELFv2,
-};
 
 /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
 class PPC64_SVR4_ABIInfo : public ABIInfo {
@@ -5496,12 +5481,6 @@ 
PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
 
 namespace {
 
-enum class AArch64ABIKind {
-  AAPCS = 0,
-  DarwinPCS,
-  Win64,
-};
-
 class AArch64ABIInfo : public ABIInfo {
   AArch64ABIKind Kind;
 
@@ -6305,13 +6284,6 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction 
&CGF, Address VAListAddr,
 
 namespace {
 
-enum class ARMABIKind {
-  APCS = 0,
-  AAPCS = 1,
-  AAPCS_VFP = 2,
-  AAPCS16_VFP = 3,
-};
-
 class ARMABIInfo : public ABIInfo {
   ARMABIKind Kind;
   bool IsFloatABISoftFP;
@@ -12286,80 +12258,74 @@ class LoongArchTargetCodeGenInfo : public 
TargetCodeGenInfo {
 // Driver code
 
//===--===//
 
+// TODO: Move to CodeGenModule.cpp.
 bool CodeGenModule::supportsCOMDAT() const {
   return getTriple().supportsCOMDAT();
 }
 
-const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
-  if (TheTargetCodeGenInfo)
-return *TheTargetCodeGenInfo;
-
-  // Helper to set the unique_ptr while still keeping the return value.
-  auto SetCGInfo = [&](TargetCodeGenInfo *P) -> const TargetCodeGenInfo & {
-this->TheTargetCodeGenInfo.reset(P);
-return *P;
-  };
+// TODO: Move to CodeGenModule.cpp.
+static std::unique_ptr
+createTargetCodeGenInfo(CodeGenModule &CGM) {
+  const TargetInfo &Target = CGM.getTarget();
+  const llvm::Triple &Triple = Target.getTriple();
+  const CodeGenOptions &CodeGenOpts = CGM.getCodeGenOpts();
 
-  const llvm::Triple &Triple = getTarget().getTriple();
   switch (Triple.getArch()) {
   default:
-return SetCGInfo(new DefaultTargetCodeGenInfo(Types));
+return createDefaultTargetCodeGenInfo(CGM);
 
   case llvm::Triple::le32:
-return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
+return createPNaClTargetCodeGenInfo(CGM);
   case llvm::Triple::m68k:
-return SetCGInfo(new M68kTargetCodeGenInfo(Types));
+return createM68kTargetCodeGenInfo(CGM);
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 if (Triple.getOS() == llvm::Triple::NaCl)
-  return SetCGInfo(new PNaClTargetCodeGenInfo(Types));
-return SetCGInfo(new MIPSTargetCodeGenInfo(Types, true));
+  return createPNaClTargetCodeGenInfo(CGM);
+return createMIPSTargetCodeGenInfo(CGM, /*IsOS32=*/true);
 
   case llvm::Triple::mips64:
   case llvm::Triple::mips64el:
-return SetCGInfo(new MIPSTargetCodeGenInfo(Types, false));
+return createMIPSTargetCodeGenInfo(CGM, /*IsOS32=*/false);
 
   case llvm::Triple::avr: {
 // For passing parameters, R8~R25 are used on avr, and R18~R25 are used
 // on avrtiny. For passing return value, R18~R25 are used on avr, and
 // R22~R25 are used on avrtiny.
-unsigned NPR = getTarget().getABI() == "avrtiny" ? 6 : 18;
-unsigned NRR = getTarget().getABI() == "avrtiny" ? 4 : 8;
-return SetCGInfo(new AVRTargetCodeGenInfo(Types, 

[clang] 44e63ff - [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Sergei Barannikov via cfe-commits

Author: Youngsuk Kim
Date: 2023-06-18T04:13:15+03:00
New Revision: 44e63ffe2bf7e5c026b828054d67088239939e81

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

LOG: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

* Add `Address::withElementType()` as a replacement for
  `CGBuilderTy::CreateElementBitCast`.

* Partial progress towards replacing `CreateElementBitCast`, as it no
  longer does what its name suggests. Either replace its uses with
  `Address::withElementType()`, or remove them if no longer needed.

* Remove unused parameter 'Name' of `CreateElementBitCast`

Reviewed By: barannikov88, nikic

Differential Revision: https://reviews.llvm.org/D153196

Added: 


Modified: 
clang/lib/CodeGen/Address.h
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGException.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/CodeGen/Targets/Hexagon.cpp
clang/lib/CodeGen/Targets/Sparc.cpp
clang/lib/CodeGen/Targets/SystemZ.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/Address.h b/clang/lib/CodeGen/Address.h
index 899aceac88672..cf48df8f5e736 100644
--- a/clang/lib/CodeGen/Address.h
+++ b/clang/lib/CodeGen/Address.h
@@ -95,6 +95,12 @@ class Address {
isKnownNonNull());
   }
 
+  /// Return address with 
diff erent element type, but same pointer and
+  /// alignment.
+  Address withElementType(llvm::Type *ElemTy) const {
+return Address(getPointer(), ElemTy, getAlignment(), isKnownNonNull());
+  }
+
   /// Whether the pointer is known not to be null.
   KnownNonNull_t isKnownNonNull() const {
 assert(isValid());

diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 100144cabbf48..cfbe3272196e3 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1259,9 +1259,8 @@ Address CodeGenFunction::GetAddrOfBlockDecl(const VarDecl 
*variable) {
 // to byref*.
 
 auto &byrefInfo = getBlockByrefInfo(variable);
-addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment);
-
-addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr");
+addr = Address(Builder.CreateLoad(addr), byrefInfo.Type,
+   byrefInfo.ByrefAlignment);
 
 addr = emitBlockByrefAddress(addr, byrefInfo, /*follow*/ true,
  variable->getName());
@@ -1935,14 +1934,12 @@ CodeGenFunction::GenerateCopyHelperFunction(const 
CGBlockInfo &blockInfo) {
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar(&SrcDecl);
-  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
-  src = Builder.CreateElementBitCast(src, blockInfo.StructureType,
- "block.source");
+  src = Address(Builder.CreateLoad(src), blockInfo.StructureType,
+blockInfo.BlockAlign);
 
   Address dst = GetAddrOfLocalVar(&DstDecl);
-  dst = Address(Builder.CreateLoad(dst), Int8Ty, blockInfo.BlockAlign);
-  dst =
-  Builder.CreateElementBitCast(dst, blockInfo.StructureType, "block.dest");
+  dst = Address(Builder.CreateLoad(dst), blockInfo.StructureType,
+blockInfo.BlockAlign);
 
   for (auto &capture : blockInfo.SortedCaptures) {
 if (capture.isConstantOrTrivial())
@@ -2125,8 +2122,8 @@ CodeGenFunction::GenerateDestroyHelperFunction(const 
CGBlockInfo &blockInfo) {
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar(&SrcDecl);
-  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
-  src = Builder.CreateElementBitCast(src, blockInfo.StructureType, "block");
+  src = Address(Builder.CreateLoad(src), blockInfo.StructureType,
+blockInfo.BlockAlign);
 
   CodeGenFunction::RunCleanupsScope cleanups(*this);
 
@@ -2163,9 +2160,9 @@ class ObjectByrefHelpers final : public BlockByrefHelpers 
{
 
   void emitCopy(CodeGenFunction &CGF, Address destField,
 Address srcField) override {
-destField = CGF.Builder.CreateElementBitCast(destField, CGF.Int8Ty);
+destField = destField.withElementType(CGF.Int8Ty);
 
-srcField = CGF.Builder.CreateElementBitCast(srcField, CGF.Int8PtrTy);
+srcField = srcField.withElementType(CGF.Int8PtrTy);
 llvm::Value *srcValue = CGF.Builder.CreateLoad(srcField);
 
 unsigned flags = (Flags | BLOCK_BYREF_CALLER).getBitMask();
@@ -2178,7 +2175,7 @@ cl

[clang] 574e417 - [clang] Fix a bug that allowed some overflowing octal escape sequences

2023-02-16 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-02-16T15:19:24+03:00
New Revision: 574e417460cdfebb8157fbe61b6a015e44856f64

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

LOG: [clang] Fix a bug that allowed some overflowing octal escape sequences

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D144100

Added: 


Modified: 
clang/lib/Lex/LiteralSupport.cpp
clang/test/Lexer/char-escapes-delimited.c

Removed: 




diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 421a853360430..38b68bde4b516 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -263,7 +263,8 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
 ThisTokBuf++;
 continue;
   }
-  if (ResultChar & 0x02000)
+  // Check if one of the top three bits is set before shifting them out.
+  if (ResultChar & 0xE000)
 Overflow = true;
 
   ResultChar <<= 3;

diff  --git a/clang/test/Lexer/char-escapes-delimited.c 
b/clang/test/Lexer/char-escapes-delimited.c
index 8e7094bc2ca5d..3b1deffe936db 100644
--- a/clang/test/Lexer/char-escapes-delimited.c
+++ b/clang/test/Lexer/char-escapes-delimited.c
@@ -58,6 +58,8 @@ void octal(void) {
 #if __WCHAR_MAX__ > 0x
   unsigned d = L'\o{377}'; // ext-warning {{extension}} cxx2b-warning 
{{C++2b}}
   unsigned e = L'\o{400}'; // expected-error {{octal escape sequence 
out of range}}
+  unsigned f = L'\o{1000}'; // expected-error {{octal escape sequence 
out of range}}
+  unsigned g = L'\o{2000}'; // expected-error {{octal escape sequence 
out of range}}
 #else
   unsigned d = L'\o{17}'; // ext-warning {{extension}} cxx2b-warning 
{{C++2b}}
   unsigned e = L'\o{20}'; // expected-error {{octal escape sequence out of 
range}}



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


[clang] e8bd2a5 - [clang][CodeGen] Break up TargetInfo.cpp [6/8]

2023-06-04 Thread Sergei Barannikov via cfe-commits

Author: Sergei Barannikov
Date: 2023-06-04T14:35:32+03:00
New Revision: e8bd2a57849e1c193341db99186abb903eb9579d

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

LOG: [clang][CodeGen] Break up TargetInfo.cpp [6/8]

Make `qualifyWindowsLibrary` and `addStackProbeTargetAttributes`
protected members of `TargetCodeGenInfo`.
These are helper functions used by `getDependentLibraryOption` and
`setTargetAttributes` methods when targeting Windows. The change will
allow these functions to be reused after splitting `TargetInfo.cpp`.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D150178

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 3d56d0e0b0128..fb0a7158d1a39 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -2543,6 +2543,7 @@ class X86_64TargetCodeGenInfo : public TargetCodeGenInfo {
 const FunctionDecl *Callee,
 const CallArgList &Args) const override;
 };
+} // namespace
 
 static void initFeatureMaps(const ASTContext &Ctx,
 llvm::StringMap &CallerMap,
@@ -2641,7 +2642,7 @@ void X86_64TargetCodeGenInfo::checkFunctionCallABI(
   }
 }
 
-static std::string qualifyWindowsLibrary(llvm::StringRef Lib) {
+std::string TargetCodeGenInfo::qualifyWindowsLibrary(StringRef Lib) {
   // If the argument does not end in .lib, automatically add the suffix.
   // If the argument contains a space, enclose it in quotes.
   // This matches the behavior of MSVC.
@@ -2654,6 +2655,7 @@ static std::string qualifyWindowsLibrary(llvm::StringRef 
Lib) {
   return ArgStr;
 }
 
+namespace {
 class WinX86_32TargetCodeGenInfo : public X86_32TargetCodeGenInfo {
 public:
   WinX86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
@@ -2677,11 +2679,11 @@ class WinX86_32TargetCodeGenInfo : public 
X86_32TargetCodeGenInfo {
 Opt = "/FAILIFMISMATCH:\"" + Name.str() + "=" + Value.str() + "\"";
   }
 };
+} // namespace
 
-static void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
-  CodeGen::CodeGenModule &CGM) {
+void TargetCodeGenInfo::addStackProbeTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const {
   if (llvm::Function *Fn = dyn_cast_or_null(GV)) {
-
 if (CGM.getCodeGenOpts().StackProbeSize != 4096)
   Fn->addFnAttr("stack-probe-size",
 llvm::utostr(CGM.getCodeGenOpts().StackProbeSize));
@@ -2698,6 +2700,7 @@ void WinX86_32TargetCodeGenInfo::setTargetAttributes(
   addStackProbeTargetAttributes(D, GV, CGM);
 }
 
+namespace {
 class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   WinX86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
@@ -2736,6 +2739,7 @@ class WinX86_64TargetCodeGenInfo : public 
TargetCodeGenInfo {
 Opt = "/FAILIFMISMATCH:\"" + Name.str() + "=" + Value.str() + "\"";
   }
 };
+} // namespace
 
 void WinX86_64TargetCodeGenInfo::setTargetAttributes(
 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const {
@@ -2753,7 +2757,6 @@ void WinX86_64TargetCodeGenInfo::setTargetAttributes(
 
   addStackProbeTargetAttributes(D, GV, CGM);
 }
-}
 
 void X86_64ABIInfo::postMerge(unsigned AggregateSize, Class &Lo,
   Class &Hi) const {

diff  --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index 7637e55ccf410..933a352595120 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -398,6 +398,12 @@ class TargetCodeGenInfo {
   virtual llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const {
 return nullptr;
   }
+
+protected:
+  static std::string qualifyWindowsLibrary(StringRef Lib);
+
+  void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+ CodeGen::CodeGenModule &CGM) const;
 };
 
 } // namespace CodeGen



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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2024-02-18 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov updated 
https://github.com/llvm/llvm-project/pull/68550

>From 96dd0121b095f92cc66fcfc3ef08a19d0b2d6bec Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Mon, 9 Oct 2023 01:38:33 +0300
Subject: [PATCH 1/2] [clang] Differentiate between identifier and string
 EnumArgument

EnumArgument may be a string or an identifier. If it is a string, it
should be parsed as unevaluated string literal. Add IsString flag to
EnumArgument so that the parser can choose the correct parsing method.

Target-specific attributes that share spelling may have different
attribute "prototypes". For example, ARM's version of "interrupt"
attribute accepts a string enum, while MSP430's version accepts an
unsigned integer. Adjust ClangAttrEmitter so that the generated
`attributeStringLiteralListArg` returns the correct mask depending on
target triple.

It is worth noting that even after this change some string arguments are
still parsed as identifiers or, worse, as expressions. This is because
of some special logic in `ParseAttributeArgsCommon`. Fixing it is out of
scope of this patch.
---
 clang/include/clang/Basic/Attr.td| 82 +++-
 clang/lib/Parse/ParseDecl.cpp|  4 +-
 clang/test/Sema/attr-function-return.c   |  2 +-
 clang/test/Sema/callingconv-iamcu.c  |  2 +-
 clang/test/Sema/callingconv.c|  2 +-
 clang/test/Sema/zero_call_used_regs.c|  2 +-
 clang/test/SemaCXX/warn-consumed-parsing.cpp |  2 +-
 clang/test/SemaHLSL/shader_type_attr.hlsl|  4 +-
 clang/utils/TableGen/ClangAttrEmitter.cpp| 80 +++
 9 files changed, 119 insertions(+), 61 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..d9b55422d3a530 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -279,12 +279,15 @@ class DefaultIntArgument : 
IntArgument {
 
 // This argument is more complex, it includes the enumerator type
 // name, whether the enum type is externally defined, a list of
-// strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,
list enums, bit opt = 0, bit fake = 0,
bit isExternalType = 0>
 : Argument {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -292,10 +295,14 @@ class EnumArgument 
values,
 
 // FIXME: There should be a VariadicArgument type that takes any other type
 //of argument and generates the appropriate type.
-class VariadicEnumArgument values,
-   list enums, bit isExternalType = 0>
+class VariadicEnumArgument values, list enums,
+   bit isExternalType = 0>
 : Argument  {
   string Type = type;
+  // When true, the argument will be parsed as an unevaluated string literal
+  // and otherwise as an identifier.
+  bit IsString = is_string;
   list Values = values;
   list Enums = enums;
   bit IsExternalType = isExternalType;
@@ -898,7 +905,7 @@ def ARMInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
   // must match.
   let Spellings = [GCC<"interrupt">];
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
1>];
@@ -1023,7 +1030,8 @@ def ExternalSourceSymbol : InheritableAttr {
 
 def Blocks : InheritableAttr {
   let Spellings = [Clang<"blocks">];
-  let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
+  let Args = [EnumArgument<"Type", "BlockType", /*is_string=*/true,
+   ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
 
@@ -1597,7 +1605,7 @@ def FlagEnum : InheritableAttr {
 def EnumExtensibility : InheritableAttr {
   let Spellings = [Clang<"enum_extensibility">];
   let Subjects = SubjectList<[Enum]>;
-  let Args = [EnumArgument<"Extensibility", "Kind",
+  let Args = [EnumArgument<"Extensibility", "Kind", /*is_string=*/false,
   ["closed", "open"], ["Closed", "Open"]>];
   let Documentation = [EnumExtensibilityDocs];
 }
@@ -1763,7 +1771,7 @@ def MipsInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // must match.
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
["vec

  1   2   >