Skip to content

Commit d1663b3

Browse files
committed
merge main into amd-staging
Reverts: - 1e70122 [ctx_prof] API to get the instrumentation of a BB (llvm#105468) Reason: dependent on earlier ctx_prof reverts - 0ca77f6 [RISCV] Add CSRs and an instruction for Smctr and Ssctr extensions. (llvm#105148) Reason: breaks clang LIT tests Change-Id: I70e13b326b66d5289d6643e75556bec759e58d53
2 parents 7c4ca1c + 0534c4f commit d1663b3

File tree

120 files changed

+3076
-874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+3076
-874
lines changed

clang/docs/StandardCPlusPlusModules.rst

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,74 +1297,6 @@ A high-level overview of support for standards features, including modules, can
12971297
be found on the `C++ Feature Status <https://clang.llvm.org/cxx_status.html>`_
12981298
page.
12991299

1300-
Missing VTables for classes attached to modules
1301-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1302-
1303-
Now the compiler may miss emitting the definition of vtables
1304-
for classes attached to modules, if the definition of the class
1305-
doesn't contain any key function in that module units
1306-
(The key function is the first non-pure virtual function that is
1307-
not inline at the point of class definition.)
1308-
1309-
(Note: technically, the key function is not a thing for modules.
1310-
We use the concept here for convinient.)
1311-
1312-
For example,
1313-
1314-
.. code-block:: c++
1315-
1316-
// layer1.cppm
1317-
export module foo:layer1;
1318-
struct Fruit {
1319-
virtual ~Fruit() = default;
1320-
virtual void eval() = 0;
1321-
};
1322-
struct Banana : public Fruit {
1323-
Banana() {}
1324-
void eval() override;
1325-
};
1326-
1327-
// layer2.cppm
1328-
export module foo:layer2;
1329-
import :layer1;
1330-
export void layer2_fun() {
1331-
Banana *b = new Banana();
1332-
b->eval();
1333-
}
1334-
void Banana::eval() {
1335-
}
1336-
1337-
For the above example, we can't find the definition for the vtable of
1338-
class ``Banana`` in any object files.
1339-
1340-
The expected behavior is, for dynamic classes attached to named modules,
1341-
the vtable should always be emitted to the module units the class attaches
1342-
to.
1343-
1344-
To workaround the problem, users can add the key function manually in the
1345-
corresponding module units. e.g.,
1346-
1347-
.. code-block:: c++
1348-
1349-
// layer1.cppm
1350-
export module foo:layer1;
1351-
struct Fruit {
1352-
virtual ~Fruit() = default;
1353-
virtual void eval() = 0;
1354-
};
1355-
struct Banana : public Fruit {
1356-
// Hack a key function to hint the compiler to emit the virtual table.
1357-
virtual void anchor();
1358-
1359-
Banana() {}
1360-
void eval() override;
1361-
};
1362-
1363-
void Banana::anchor() {}
1364-
1365-
This is tracked by
1366-
`#70585 <https://github.com/llvm/llvm-project/issues/70585>`_.
1367-
13681300
Including headers after import is not well-supported
13691301
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13701302

@@ -1436,7 +1368,7 @@ non-module unit depending on the definition of some macros. However, this usage
14361368
is forbidden by P1857R3 which is not yet implemented in Clang. This means that
14371369
is possible to write invalid modules which will no longer be accepted once
14381370
P1857R3 is implemented. This is tracked by
1439-
`#56917 <https://github.com/llvm/llvm-project/issues/56917>`_.
1371+
`#54047 <https://github.com/llvm/llvm-project/issues/54047>`_.
14401372

14411373
Until then, it is recommended not to mix macros with module declarations.
14421374

clang/include/clang/Basic/Attr.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,15 @@ def BTFTypeTag : TypeAttr {
22002200
let LangOpts = [COnly];
22012201
}
22022202

2203+
def BPFFastCall : InheritableAttr,
2204+
TargetSpecificAttr<TargetBPF> {
2205+
let Spellings = [Clang<"bpf_fastcall">];
2206+
let Subjects = SubjectList<[FunctionLike]>;
2207+
let Documentation = [BPFFastCallDocs];
2208+
let LangOpts = [COnly];
2209+
let SimpleHandler = 1;
2210+
}
2211+
22032212
def WebAssemblyExportName : InheritableAttr,
22042213
TargetSpecificAttr<TargetWebAssembly> {
22052214
let Spellings = [Clang<"export_name">];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,25 @@ section.
23452345
}];
23462346
}
23472347

2348+
def BPFFastCallDocs : Documentation {
2349+
let Category = DocCatType;
2350+
let Content = [{
2351+
Functions annotated with this attribute are likely to be inlined by BPF JIT.
2352+
It is assumed that inlined implementation uses less caller saved registers,
2353+
than a regular function.
2354+
Specifically, the following registers are likely to be preserved:
2355+
- ``R0`` if function return value is ``void``;
2356+
- ``R2-R5` if function takes 1 argument;
2357+
- ``R3-R5` if function takes 2 arguments;
2358+
- ``R4-R5` if function takes 3 arguments;
2359+
- ``R5`` if function takes 4 arguments;
2360+
2361+
For such functions Clang generates code pattern that allows BPF JIT
2362+
to recognize and remove unnecessary spills and fills of the preserved
2363+
registers.
2364+
}];
2365+
}
2366+
23482367
def MipsInterruptDocs : Documentation {
23492368
let Category = DocCatFunction;
23502369
let Heading = "interrupt (MIPS)";

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,8 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
24222422
FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck);
24232423
if (TargetDecl->hasAttr<LeafAttr>())
24242424
FuncAttrs.addAttribute(llvm::Attribute::NoCallback);
2425+
if (TargetDecl->hasAttr<BPFFastCallAttr>())
2426+
FuncAttrs.addAttribute("bpf_fastcall");
24252427

24262428
HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>();
24272429
if (auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,15 @@ void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S,
11951195

11961196
unsigned Counter = (*RegionCounterMap)[S];
11971197

1198-
llvm::Value *Args[] = {FuncNameVar,
1199-
Builder.getInt64(FunctionHash),
1200-
Builder.getInt32(NumRegionCounters),
1201-
Builder.getInt32(Counter), StepV};
1198+
// Make sure that pointer to global is passed in with zero addrspace
1199+
// This is relevant during GPU profiling
1200+
auto *NormalizedFuncNameVarPtr =
1201+
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
1202+
FuncNameVar, llvm::PointerType::get(CGM.getLLVMContext(), 0));
1203+
1204+
llvm::Value *Args[] = {
1205+
NormalizedFuncNameVarPtr, Builder.getInt64(FunctionHash),
1206+
Builder.getInt32(NumRegionCounters), Builder.getInt32(Counter), StepV};
12021207

12031208
if (llvm::EnableSingleByteCoverage)
12041209
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_cover),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// REQUIRES: bpf-registered-target
2+
// RUN: %clang_cc1 -triple bpf -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
3+
4+
#define __bpf_fastcall __attribute__((bpf_fastcall))
5+
6+
void test(void) __bpf_fastcall;
7+
void (*ptr)(void) __bpf_fastcall;
8+
9+
void foo(void) {
10+
test();
11+
(*ptr)();
12+
}
13+
14+
// CHECK: @ptr = global ptr null
15+
// CHECK: define {{.*}} void @foo()
16+
// CHECK: entry:
17+
// CHECK: call void @test() #[[call_attr:[0-9]+]]
18+
// CHECK: %[[ptr:.*]] = load ptr, ptr @ptr, align 8
19+
// CHECK: call void %[[ptr]]() #[[call_attr]]
20+
// CHECK: ret void
21+
22+
// CHECK: declare void @test() #[[func_attr:[0-9]+]]
23+
// CHECK: attributes #[[func_attr]] = { {{.*}}"bpf_fastcall"{{.*}} }
24+
// CHECK: attributes #[[call_attr]] = { "bpf_fastcall" }

clang/test/Misc/pragma-attribute-supported-attributes-list.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// CHECK-NEXT: AssumeAligned (SubjectMatchRule_objc_method, SubjectMatchRule_function)
2323
// CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable))
2424
// CHECK-NEXT: AvailableOnlyInDefaultEvalMethod (SubjectMatchRule_type_alias)
25+
// CHECK-NEXT: BPFFastCall (SubjectMatchRule_hasType_functionType)
2526
// CHECK-NEXT: BPFPreserveAccessIndex (SubjectMatchRule_record)
2627
// CHECK-NEXT: BPFPreserveStaticOffset (SubjectMatchRule_record)
2728
// CHECK-NEXT: BTFDeclTag (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record, SubjectMatchRule_field, SubjectMatchRule_type_alias)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// REQUIRES: bpf-registered-target
2+
// RUN: %clang_cc1 %s -triple bpf -verify
3+
4+
__attribute__((bpf_fastcall)) int var; // expected-warning {{'bpf_fastcall' attribute only applies to functions and function pointers}}
5+
6+
__attribute__((bpf_fastcall)) void func();
7+
__attribute__((bpf_fastcall(1))) void func_invalid(); // expected-error {{'bpf_fastcall' attribute takes no arguments}}
8+
9+
void (*ptr1)(void) __attribute__((bpf_fastcall));
10+
void (*ptr2)(void);
11+
void foo(void) {
12+
ptr2 = ptr1; // not an error
13+
ptr1 = ptr2; // not an error
14+
}

compiler-rt/test/asan/TestCases/Darwin/cstring_section.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// Test that AddressSanitizer moves constant strings into a separate section.
22

33
// RUN: %clang_asan -c -o %t %s
4-
// RUN: llvm-objdump -s %t | FileCheck %s
4+
// RUN: llvm-objdump -s %t | FileCheck %s --implicit-check-not="Hello."
55

66
// Check that "Hello.\n" is in __asan_cstring and not in __cstring.
77
// CHECK: Contents of section {{.*}}__asan_cstring:
8-
// CHECK: 48656c6c {{.*}} Hello.
9-
// CHECK: Contents of section {{.*}}__cstring:
10-
// CHECK-NOT: 48656c6c {{.*}} Hello.
11-
// CHECK: Contents of section {{.*}}__const:
12-
// CHECK-NOT: 48656c6c {{.*}} Hello.
8+
// CHECK-NEXT: 48656c6c {{.*}} Hello.
139

1410
int main(int argc, char *argv[]) {
1511
argv[0] = "Hello.\n";

compiler-rt/test/fuzzer/features_dir.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Tests -features_dir=F
2-
# REQUIRES: linux
2+
# REQUIRES: linux, shell
33
RUN: %cpp_compiler %S/SimpleTest.cpp -o %t-SimpleTest
44
RUN: rm -rf %t-C %t-F
55
RUN: mkdir %t-C %t-F

flang/docs/OpenMP-declare-target.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ flang/lib/Lower/OpenMP.cpp function `genDeclareTargetIntGlobal`.
149149

150150
There are currently two passes within Flang that are related to the processing
151151
of `declare target`:
152-
* `OMPMarkDeclareTarget` - This pass is in charge of marking functions captured
152+
* `MarkDeclareTarget` - This pass is in charge of marking functions captured
153153
(called from) in `target` regions or other `declare target` marked functions as
154154
`declare target`. It does so recursively, i.e. nested calls will also be
155155
implicitly marked. It currently will try to mark things as conservatively as
156156
possible, e.g. if captured in a `target` region it will apply `nohost`, unless
157157
it encounters a `host` `declare target` in which case it will apply the `any`
158158
device type. Functions are handled similarly, except we utilise the parent's
159159
device type where possible.
160-
* `OMPFunctionFiltering` - This is executed after the `OMPMarkDeclareTarget`
160+
* `FunctionFiltering` - This is executed after the `MarkDeclareTarget`
161161
pass, and its job is to conservatively remove host functions from
162162
the module where possible when compiling for the device. This helps make
163163
sure that most incompatible code for the host is not lowered for the

flang/docs/OpenMP-descriptor-management.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Currently, Flang will lower these descriptor types in the OpenMP lowering (lower
4444
to all other map types, generating an omp.MapInfoOp containing relevant information required for lowering
4545
the OpenMP dialect to LLVM-IR during the final stages of the MLIR lowering. However, after
4646
the lowering to FIR/HLFIR has been performed an OpenMP dialect specific pass for Fortran,
47-
`OMPMapInfoFinalizationPass` (Optimizer/OMPMapInfoFinalization.cpp) will expand the
47+
`MapInfoFinalizationPass` (Optimizer/OpenMP/MapInfoFinalization.cpp) will expand the
4848
`omp.MapInfoOp`'s containing descriptors (which currently will be a `BoxType` or `BoxAddrOp`) into multiple
4949
mappings, with one extra per pointer member in the descriptor that is supported on top of the original
5050
descriptor map operation. These pointers members are linked to the parent descriptor by adding them to
@@ -53,7 +53,7 @@ owning operation's (`omp.TargetOp`, `omp.TargetDataOp` etc.) map operand list an
5353
operation is `IsolatedFromAbove`, it also inserts them as `BlockArgs` to canonicalize the mappings and
5454
simplify lowering.
5555
56-
An example transformation by the `OMPMapInfoFinalizationPass`:
56+
An example transformation by the `MapInfoFinalizationPass`:
5757
5858
```
5959

flang/include/flang/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_subdirectory(CodeGen)
22
add_subdirectory(Dialect)
33
add_subdirectory(HLFIR)
44
add_subdirectory(Transforms)
5+
add_subdirectory(OpenMP)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(LLVM_TARGET_DEFINITIONS Passes.td)
2+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name FlangOpenMP)
3+
4+
add_public_tablegen_target(FlangOpenMPPassesIncGen)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- Passes.h - OpenMP pass entry points ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This header declares the flang OpenMP passes.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef FORTRAN_OPTIMIZER_OPENMP_PASSES_H
14+
#define FORTRAN_OPTIMIZER_OPENMP_PASSES_H
15+
16+
#include "mlir/Dialect/Func/IR/FuncOps.h"
17+
#include "mlir/IR/BuiltinOps.h"
18+
#include "mlir/Pass/Pass.h"
19+
#include "mlir/Pass/PassRegistry.h"
20+
21+
#include <memory>
22+
23+
namespace flangomp {
24+
#define GEN_PASS_DECL
25+
#define GEN_PASS_REGISTRATION
26+
#include "flang/Optimizer/OpenMP/Passes.h.inc"
27+
28+
} // namespace flangomp
29+
30+
#endif // FORTRAN_OPTIMIZER_OPENMP_PASSES_H
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- Passes.td - flang OpenMP pass definition -----------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_OPTIMIZER_OPENMP_PASSES
10+
#define FORTRAN_OPTIMIZER_OPENMP_PASSES
11+
12+
include "mlir/Pass/PassBase.td"
13+
14+
def MapInfoFinalizationPass
15+
: Pass<"omp-map-info-finalization"> {
16+
let summary = "expands OpenMP MapInfo operations containing descriptors";
17+
let description = [{
18+
Expands MapInfo operations containing descriptor types into multiple
19+
MapInfo's for each pointer element in the descriptor that requires
20+
explicit individual mapping by the OpenMP runtime.
21+
}];
22+
let dependentDialects = ["mlir::omp::OpenMPDialect"];
23+
}
24+
25+
def MarkDeclareTargetPass
26+
: Pass<"omp-mark-declare-target", "mlir::ModuleOp"> {
27+
let summary = "Marks all functions called by an OpenMP declare target function as declare target";
28+
let dependentDialects = ["mlir::omp::OpenMPDialect"];
29+
}
30+
31+
def FunctionFiltering : Pass<"omp-function-filtering"> {
32+
let summary = "Filters out functions intended for the host when compiling "
33+
"for the target device.";
34+
let dependentDialects = [
35+
"mlir::func::FuncDialect",
36+
"fir::FIROpsDialect"
37+
];
38+
}
39+
40+
#endif //FORTRAN_OPTIMIZER_OPENMP_PASSES

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -358,32 +358,6 @@ def LoopVersioning : Pass<"loop-versioning", "mlir::func::FuncOp"> {
358358
let dependentDialects = [ "fir::FIROpsDialect" ];
359359
}
360360

361-
def OMPMapInfoFinalizationPass
362-
: Pass<"omp-map-info-finalization"> {
363-
let summary = "expands OpenMP MapInfo operations containing descriptors";
364-
let description = [{
365-
Expands MapInfo operations containing descriptor types into multiple
366-
MapInfo's for each pointer element in the descriptor that requires
367-
explicit individual mapping by the OpenMP runtime.
368-
}];
369-
let dependentDialects = ["mlir::omp::OpenMPDialect"];
370-
}
371-
372-
def OMPMarkDeclareTargetPass
373-
: Pass<"omp-mark-declare-target", "mlir::ModuleOp"> {
374-
let summary = "Marks all functions called by an OpenMP declare target function as declare target";
375-
let dependentDialects = ["mlir::omp::OpenMPDialect"];
376-
}
377-
378-
def OMPFunctionFiltering : Pass<"omp-function-filtering"> {
379-
let summary = "Filters out functions intended for the host when compiling "
380-
"for the target device.";
381-
let dependentDialects = [
382-
"mlir::func::FuncDialect",
383-
"fir::FIROpsDialect"
384-
];
385-
}
386-
387361
def VScaleAttr : Pass<"vscale-attr", "mlir::func::FuncOp"> {
388362
let summary = "Add vscale_range attribute to functions";
389363
let description = [{

0 commit comments

Comments
 (0)