Skip to content

Commit ea5c9ea

Browse files
authored
Merge branch 'main' into codegenprepare-nosink-bigint
2 parents 5c8da1a + bba40ab commit ea5c9ea

File tree

15 files changed

+290
-123
lines changed

15 files changed

+290
-123
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/IR/Attributes.h"
3939
#include "llvm/IR/CallingConv.h"
4040
#include "llvm/IR/DataLayout.h"
41+
#include "llvm/IR/DebugInfoMetadata.h"
4142
#include "llvm/IR/InlineAsm.h"
4243
#include "llvm/IR/IntrinsicInst.h"
4344
#include "llvm/IR/Intrinsics.h"
@@ -6277,6 +6278,24 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
62776278
pushDestroy(QualType::DK_nontrivial_c_struct, Ret.getAggregateAddress(),
62786279
RetTy);
62796280

6281+
// Generate function declaration DISuprogram in order to be used
6282+
// in debug info about call sites.
6283+
if (CGDebugInfo *DI = getDebugInfo()) {
6284+
// Ensure call site info would actually be emitted before collecting
6285+
// further callee info.
6286+
if (CalleeDecl && !CalleeDecl->hasAttr<NoDebugAttr>() &&
6287+
DI->getCallSiteRelatedAttrs() != llvm::DINode::FlagZero) {
6288+
CodeGenFunction CalleeCGF(CGM);
6289+
const GlobalDecl &CalleeGlobalDecl =
6290+
Callee.getAbstractInfo().getCalleeDecl();
6291+
CalleeCGF.CurGD = CalleeGlobalDecl;
6292+
FunctionArgList Args;
6293+
QualType ResTy = CalleeCGF.BuildFunctionArgList(CalleeGlobalDecl, Args);
6294+
DI->EmitFuncDeclForCallSite(
6295+
CI, DI->getFunctionType(CalleeDecl, ResTy, Args), CalleeGlobalDecl);
6296+
}
6297+
}
6298+
62806299
return Ret;
62816300
}
62826301

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4957,7 +4957,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
49574957

49584958
void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
49594959
QualType CalleeType,
4960-
const FunctionDecl *CalleeDecl) {
4960+
GlobalDecl CalleeGlobalDecl) {
49614961
if (!CallOrInvoke)
49624962
return;
49634963
auto *Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
@@ -4966,6 +4966,9 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
49664966
if (Func->getSubprogram())
49674967
return;
49684968

4969+
const FunctionDecl *CalleeDecl =
4970+
cast<FunctionDecl>(CalleeGlobalDecl.getDecl());
4971+
49694972
// Do not emit a declaration subprogram for a function with nodebug
49704973
// attribute, or if call site info isn't required.
49714974
if (CalleeDecl->hasAttr<NoDebugAttr>() ||
@@ -4976,7 +4979,8 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
49764979
// create the one describing the function in order to have complete
49774980
// call site debug info.
49784981
if (!CalleeDecl->isStatic() && !CalleeDecl->isInlined())
4979-
EmitFunctionDecl(CalleeDecl, CalleeDecl->getLocation(), CalleeType, Func);
4982+
EmitFunctionDecl(CalleeGlobalDecl, CalleeDecl->getLocation(), CalleeType,
4983+
Func);
49804984
}
49814985

49824986
void CGDebugInfo::EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD) {

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class CGDebugInfo {
511511
/// This is needed for call site debug info.
512512
void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
513513
QualType CalleeType,
514-
const FunctionDecl *CalleeDecl);
514+
GlobalDecl CalleeGlobalDecl);
515515

516516
/// Constructs the debug code for exiting a function.
517517
void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn);
@@ -678,6 +678,10 @@ class CGDebugInfo {
678678
/// Emit symbol for debugger that holds the pointer to the vtable.
679679
void emitVTableSymbol(llvm::GlobalVariable *VTable, const CXXRecordDecl *RD);
680680

681+
/// Return flags which enable debug info emission for call sites, provided
682+
/// that it is supported and enabled.
683+
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
684+
681685
private:
682686
/// Amend \p I's DebugLoc with \p Group (its source atom group) and \p
683687
/// Rank (lower nonzero rank is higher precedence). Does nothing if \p I
@@ -827,11 +831,6 @@ class CGDebugInfo {
827831
unsigned LineNo, StringRef LinkageName,
828832
llvm::GlobalVariable *Var, llvm::DIScope *DContext);
829833

830-
831-
/// Return flags which enable debug info emission for call sites, provided
832-
/// that it is supported and enabled.
833-
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
834-
835834
/// Get the printing policy for producing names for debug info.
836835
PrintingPolicy getPrintingPolicy() const;
837836

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6632,15 +6632,6 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
66326632
E == MustTailCall, E->getExprLoc());
66336633

66346634
if (auto *CalleeDecl = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
6635-
// Generate function declaration DISuprogram in order to be used
6636-
// in debug info about call sites.
6637-
if (CGDebugInfo *DI = getDebugInfo()) {
6638-
FunctionArgList Args;
6639-
QualType ResTy = BuildFunctionArgList(CalleeDecl, Args);
6640-
DI->EmitFuncDeclForCallSite(LocalCallOrInvoke,
6641-
DI->getFunctionType(CalleeDecl, ResTy, Args),
6642-
CalleeDecl);
6643-
}
66446635
if (CalleeDecl->hasAttr<RestrictAttr>() ||
66456636
CalleeDecl->hasAttr<AllocSizeAttr>()) {
66466637
// Function has 'malloc' (aka. 'restrict') or 'alloc_size' attribute.

clang/test/C/C2y/n3348.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
2+
3+
/* WG14 N3348: No
4+
* Matching of Multi-Dimensional Arrays in Generic Selection Expressions
5+
*
6+
* This allows use of * in a _Generic association as a placeholder for any size
7+
* value.
8+
*
9+
* FIXME: Clang doesn't yet implement this paper. When we do implement it, we
10+
* should expose the functionality in earlier language modes (C89) for
11+
* compatibility with GCC.
12+
*/
13+
14+
void test(int n, int m) {
15+
static_assert(1 == _Generic(int[3][2], int[3][*]: 1, int[2][*]: 0)); /* expected-error {{star modifier used outside of function prototype}}
16+
expected-error {{array has incomplete element type 'int[]'}}
17+
*/
18+
static_assert(1 == _Generic(int[3][2], int[*][2]: 1, int[*][3]: 0)); // expected-error {{star modifier used outside of function prototype}}
19+
static_assert(1 == _Generic(int[3][n], int[3][*]: 1, int[2][*]: 0)); /* expected-error {{star modifier used outside of function prototype}}
20+
expected-error {{array has incomplete element type 'int[]'}}
21+
*/
22+
static_assert(1 == _Generic(int[n][m], int[*][*]: 1, char[*][*]: 0)); /* expected-error 2 {{star modifier used outside of function prototype}}
23+
expected-error {{array has incomplete element type 'int[]'}}
24+
*/
25+
static_assert(1 == _Generic(int(*)[2], int(*)[*]: 1)); // expected-error {{star modifier used outside of function prototype}}
26+
}
27+
28+
void questionable() {
29+
// GCC accepts this despite the * appearing outside of a generic association,
30+
// but it's not clear whether that's intentionally supported or an oversight.
31+
// It gives a warning about * being used outside of a declaration, but not
32+
// with an associated warning group.
33+
static_assert(1 == _Generic(int[*][*], int[2][100]: 1)); /* expected-error 2 {{star modifier used outside of function prototype}}
34+
expected-error {{array has incomplete element type 'int[]'}}
35+
*/
36+
// GCC claims this matches multiple associations, so the functionality seems
37+
// like it may be intended to work?
38+
(void)_Generic(int[*][*], /* expected-error 2 {{star modifier used outside of function prototype}}
39+
expected-error {{array has incomplete element type 'int[]'}}
40+
*/
41+
int[2][100]: 1,
42+
int[3][1000]: 2,
43+
);
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 -O1 -triple x86_64-unknown_unknown -emit-llvm \
2+
// RUN: -debug-info-kind=standalone -dwarf-version=5 %s -o - | FileCheck %s
3+
4+
// Ensure both nonmember and member calls to declared function
5+
// have attached `DISubprogram`s.
6+
7+
int nonmember(int n);
8+
9+
struct S {
10+
int x;
11+
int member(int n);
12+
};
13+
14+
int main(int argc, char** argv) {
15+
struct S s = {};
16+
int a = s.member(argc);
17+
int b = nonmember(argc);
18+
return a + b;
19+
}
20+
21+
// CHECK: declare !dbg ![[SP1:[0-9]+]] noundef i32 @_ZN1S6memberEi(
22+
// CHECK: declare !dbg ![[SP2:[0-9]+]] noundef i32 @_Z9nonmemberi(
23+
24+
// CHECK: ![[SP1]] = !DISubprogram(name: "member", linkageName: "_ZN1S6memberEi"
25+
// CHECK: ![[SP2]] = !DISubprogram(name: "nonmember", linkageName: "_Z9nonmemberi"

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ <h2 id="c2y">C2y implementation status</h2>
324324
<tr>
325325
<td>Matching of Multi-Dimensional Arrays in Generic Selection Expressions</td>
326326
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3348.pdf">N3348</a></td>
327-
<td class="unknown" align="center">Unknown</td>
327+
<td class="none" align="center">No</td>
328328
</tr>
329329
<tr>
330330
<td>The __COUNTER__ predefined macro</td>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
2+
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
3+
4+
; CHECK: LLVM ERROR: %5:vfid(<2 x s64>) = nnan ninf nsz arcp afn reassoc G_INTRINSIC intrinsic(@llvm.spv.unpackhalf2x16), %0:iid(s64) is only supported with the GLSL extended instruction set.
5+
6+
define hidden spir_func noundef nofpclass(nan inf) float @_Z9test_funcj(i32 noundef %0) local_unnamed_addr #0 {
7+
%2 = tail call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.spv.unpackhalf2x16.v2f32(i32 %0)
8+
%3 = extractelement <2 x float> %2, i64 0
9+
ret float %3
10+
}
11+

mlir/include/mlir/Dialect/XeGPU/IR/XeGPUAttrs.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,17 @@ def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [DistributeLayoutAttr]> {
379379
);
380380

381381
let builders = [
382+
AttrBuilder<(ins "llvm::ArrayRef<int32_t>": $inst_data),
383+
[{
384+
auto sg_layout = DenseI32ArrayAttr();
385+
auto sg_data = DenseI32ArrayAttr();
386+
auto order = DenseI32ArrayAttr();
387+
auto lane_layout = DenseI32ArrayAttr();
388+
auto lane_data = DenseI32ArrayAttr();
389+
return $_get($_ctxt, sg_layout, sg_data,
390+
DenseI32ArrayAttr::get($_ctxt, inst_data),
391+
lane_layout, lane_data, order);
392+
}]>,
382393
AttrBuilder<(ins "llvm::ArrayRef<int32_t>": $inst_data,
383394
"llvm::ArrayRef<int32_t>": $lane_layout,
384395
"llvm::ArrayRef<int32_t>": $lane_data),

mlir/include/mlir/Dialect/XeGPU/Transforms/Passes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def XeGPUPropagateLayout : Pass<"xegpu-propagate-layout"> {
4747
Option<
4848
"layoutKind", "layout-kind", "std::string",
4949
/*default=*/"\"lane\"",
50-
"Propagate a `sg` / `inst` / `lane` level of xegpu layouts.">
50+
"Propagate `inst` / `lane` level of xegpu layouts.">
5151
];
5252
}
5353

0 commit comments

Comments
 (0)