Skip to content

Commit 4253723

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:efad561890ad3584c38adae913f9939384eb804c into amd-gfx:4b0f66167c79
Local branch amd-gfx 4b0f661 Merged main:8f96be921c1a97594ee94c2789cee9b131525f63 into amd-gfx:c7b3b9d8ffb4 Remote branch main efad561 [LLD][COFF] Add support for range extension thunks for ARM64EC targets. (llvm#106289)
2 parents 4b0f661 + efad561 commit 4253723

29 files changed

+653
-87
lines changed

clang/include/clang/CodeGen/CodeGenAction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class CodeGenAction : public ASTFrontendAction {
5757
bool loadLinkModules(CompilerInstance &CI);
5858

5959
protected:
60-
bool BeginSourceFileAction(CompilerInstance &CI) override;
60+
bool BeginInvocation(CompilerInstance &CI) override;
6161

6262
/// Create a new code generation action. If the optional \p _VMContext
6363
/// parameter is supplied, the action uses it without taking ownership,

clang/include/clang/Frontend/FrontendActions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
152152
CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
153153
};
154154

155+
bool BeginInvocationForModules(CompilerInstance &CI);
156+
155157
/// Generates full BMI (which contains full information to generate the object
156158
/// files) for C++20 Named Modules.
157159
class GenerateModuleInterfaceAction : public GenerateModuleAction {
158160
protected:
159-
bool BeginSourceFileAction(CompilerInstance &CI) override;
161+
bool BeginInvocation(CompilerInstance &CI) override;
160162

161163
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
162164
StringRef InFile) override;

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ class ASTWriter : public ASTDeserializationListener,
500500
std::vector<SourceRange> NonAffectingRanges;
501501
std::vector<SourceLocation::UIntTy> NonAffectingOffsetAdjustments;
502502

503-
/// A list of classes which need to emit the VTable in the corresponding
504-
/// object file.
503+
/// A list of classes in named modules which need to emit the VTable in
504+
/// the corresponding object file.
505505
llvm::SmallVector<CXXRecordDecl *> PendingEmittingVTables;
506506

507507
/// Computes input files that didn't affect compilation of the current module,

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ class InputFile {
8888

8989
InputFile(FileEntryRef File, bool isOverridden = false,
9090
bool isOutOfDate = false) {
91-
assert(!(isOverridden && isOutOfDate) &&
92-
"an overridden cannot be out-of-date");
9391
unsigned intVal = 0;
94-
if (isOverridden)
95-
intVal = Overridden;
96-
else if (isOutOfDate)
92+
// Make isOutOfDate with higher priority than isOverridden.
93+
// It is possible if the recorded hash value mismatches.
94+
if (isOutOfDate)
9795
intVal = OutOfDate;
96+
else if (isOverridden)
97+
intVal = Overridden;
9898
Val.setPointerAndInt(&File.getMapEntry(), intVal);
9999
}
100100

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,10 @@ CodeGenerator *CodeGenAction::getCodeGenerator() const {
969969
return BEConsumer->getCodeGenerator();
970970
}
971971

972-
bool CodeGenAction::BeginSourceFileAction(CompilerInstance &CI) {
972+
bool CodeGenAction::BeginInvocation(CompilerInstance &CI) {
973973
if (CI.getFrontendOpts().GenReducedBMI)
974-
CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
974+
return BeginInvocationForModules(CI);
975+
975976
return true;
976977
}
977978

clang/lib/Driver/ToolChain.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ static void getAArch64MultilibFlags(const Driver &D,
221221
assert(!ArchName.empty() && "at least one architecture should be found");
222222
MArch.insert(MArch.begin(), ("-march=" + ArchName).str());
223223
Result.push_back(llvm::join(MArch, "+"));
224+
225+
const Arg *BranchProtectionArg =
226+
Args.getLastArgNoClaim(options::OPT_mbranch_protection_EQ);
227+
if (BranchProtectionArg) {
228+
Result.push_back(BranchProtectionArg->getAsString(Args));
229+
}
224230
}
225231

226232
static void getARMMultilibFlags(const Driver &D,
@@ -268,6 +274,12 @@ static void getARMMultilibFlags(const Driver &D,
268274
case arm::FloatABI::Invalid:
269275
llvm_unreachable("Invalid float ABI");
270276
}
277+
278+
const Arg *BranchProtectionArg =
279+
Args.getLastArgNoClaim(options::OPT_mbranch_protection_EQ);
280+
if (BranchProtectionArg) {
281+
Result.push_back(BranchProtectionArg->getAsString(Args));
282+
}
271283
}
272284

273285
static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,20 @@ GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI,
262262
/*ForceUseTemporary=*/true);
263263
}
264264

265-
bool GenerateModuleInterfaceAction::BeginSourceFileAction(
266-
CompilerInstance &CI) {
265+
bool clang::BeginInvocationForModules(CompilerInstance &CI) {
266+
// Embed all module files for named modules.
267+
// See https://github.com/llvm/llvm-project/issues/72383 for discussion.
268+
CI.getFrontendOpts().ModulesEmbedAllFiles = true;
267269
CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
270+
return true;
271+
}
268272

269-
return GenerateModuleAction::BeginSourceFileAction(CI);
273+
bool GenerateModuleInterfaceAction::BeginInvocation(
274+
CompilerInstance &CI) {
275+
if (!BeginInvocationForModules(CI))
276+
return false;
277+
278+
return GenerateModuleAction::BeginInvocation(CI);
270279
}
271280

272281
std::unique_ptr<ASTConsumer>

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,6 +3963,9 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
39633963
}
39643964

39653965
void ASTWriter::handleVTable(CXXRecordDecl *RD) {
3966+
if (!RD->isInNamedModule())
3967+
return;
3968+
39663969
PendingEmittingVTables.push_back(RD);
39673970
}
39683971

clang/test/Driver/print-multi-selection-flags.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
// CHECK-SVE2: --target=aarch64-unknown-none-elf
6060
// CHECK-SVE2: -march=armv{{.*}}-a{{.*}}+simd{{.*}}+sve{{.*}}+sve2{{.*}}
6161

62+
// RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi -mbranch-protection=standard | FileCheck --check-prefix=CHECK-BRANCH-PROTECTION %s
63+
// RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -mbranch-protection=standard | FileCheck --check-prefix=CHECK-BRANCH-PROTECTION %s
64+
// CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
65+
6266
// RUN: %clang -print-multi-flags-experimental --target=riscv32-none-elf -march=rv32g | FileCheck --check-prefix=CHECK-RV32 %s
6367
// CHECK-RV32: --target=riscv32-unknown-none-elf
6468
// CHECK-RV32: -mabi=ilp32d

clang/test/Modules/no-local-decl-in-reduced-bmi.cppm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//
77
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
88
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/a.pcm > %t/a.dump
9-
// RUN: cat %t/a.dump | FileCheck %t/a.cppm
9+
// RUN: cat %t/a.dump | FileCheck %t/a.check
1010
//
1111
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -o %t/b.pcm
1212
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/b.pcm > %t/b.dump
13-
// RUN: cat %t/b.dump | FileCheck %t/b.cppm
13+
// RUN: cat %t/b.dump | FileCheck %t/b.check
1414

1515
//--- a.cppm
1616
export module a;
@@ -19,6 +19,9 @@ export int func() {
1919
return 43;
2020
}
2121

22+
//--- a.check
23+
// Use a standalone check file since now we're going to embed all source files in the BMI
24+
// so we will check the `CHECK-NOT: <DECL_VAR` in the source file otherwise.
2225
// Test that the variable declaration is not recorded completely.
2326
// CHECK-NOT: <DECL_VAR
2427

@@ -29,5 +32,6 @@ export inline int func() {
2932
return v;
3033
}
3134

35+
//--- b.check
3236
// Check that we still records the declaration from inline functions.
3337
// CHECK: <DECL_VAR

clang/test/Modules/pr106483.cppm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++23 %t/a.cppm -emit-module-interface -o %t/a.pcm
6+
// RUN: %clang_cc1 -std=c++23 %t/b.cppm -emit-module-interface -o %t/b.pcm \
7+
// RUN: -fprebuilt-module-path=%t
8+
// RUN: %clang_cc1 -std=c++23 -fprebuilt-module-path=%t %t/b.pcm -emit-llvm \
9+
// RUN: -disable-llvm-passes -o - | FileCheck %t/b.cppm
10+
11+
//--- a.cppm
12+
module;
13+
14+
struct base {
15+
virtual void f() const;
16+
};
17+
18+
inline void base::f() const {
19+
}
20+
21+
export module a;
22+
export using ::base;
23+
24+
//--- b.cppm
25+
module;
26+
27+
struct base {
28+
virtual void f() const;
29+
};
30+
31+
inline void base::f() const {
32+
}
33+
34+
export module b;
35+
import a;
36+
export using ::base;
37+
38+
export extern "C" void func() {}
39+
40+
// We only need to check that the IR are successfully emitted instead of crash.
41+
// CHECK: func

clang/test/Modules/reduced-bmi-empty-module-purview-std.cppm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm
99
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A.pcm > %t/A.dump
10-
// RUN: cat %t/A.dump | FileCheck %t/A.cppm
10+
// RUN: cat %t/A.dump | FileCheck %t/A.check
1111

1212
//--- std.h
1313
namespace std {
@@ -22,6 +22,8 @@ module;
2222
#include "std.h"
2323
export module A;
2424

25+
26+
//--- A.check
2527
// CHECK-NOT: <DECL_NAMESPACE
2628
// CHECK-NOT: <DECL_CONTEXT_LEXICAL
2729
// CHECK-NOT: <DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD

clang/test/Modules/reduced-bmi-empty-module-purview.cppm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm \
1010
// RUN: -fmodule-file=M=%t/M.pcm
1111
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A.pcm > %t/A.dump
12-
// RUN: cat %t/A.dump | FileCheck %t/A.cppm
12+
// RUN: cat %t/A.dump | FileCheck %t/A.check
1313
//
1414
// RUN: %clang_cc1 -std=c++20 %t/A1.cppm -emit-reduced-module-interface -o %t/A1.pcm \
1515
// RUN: -fmodule-file=M=%t/M.pcm
1616
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A1.pcm > %t/A1.dump
17-
// RUN: cat %t/A1.dump | FileCheck %t/A1.cppm
17+
// RUN: cat %t/A1.dump | FileCheck %t/A1.check
1818

1919
//--- foo.h
2020
namespace ns {
@@ -82,6 +82,7 @@ module;
8282
export module A;
8383
import M;
8484

85+
//--- A.check
8586
// CHECK-NOT: <DECL_CXX_RECORD
8687
// CHECK-NOT: <DECL_UPDATE_OFFSETS
8788

@@ -91,6 +92,7 @@ import M;
9192
#include "foo.h"
9293
export module A;
9394

95+
//--- A1.check
9496
// CHECK-NOT: <DECL_CXX_RECORD
9597
// CHECK-NOT: <DECL_UPDATE_OFFSETS
9698

clang/test/Modules/unreached-static-entities.cppm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
//
44
// RUN: rm -rf %t
55
// RUN: mkdir -p %t
6+
// RUN: split-file %s %t
67
//
7-
// RUN: %clang_cc1 -std=c++20 %s -emit-reduced-module-interface -o %t/S.pcm
8+
// RUN: %clang_cc1 -std=c++20 %t/S.cppm -emit-reduced-module-interface -o %t/S.pcm
89
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/S.pcm > %t/S.dump
9-
// RUN: cat %t/S.dump | FileCheck %s
10+
// RUN: cat %t/S.dump | FileCheck %t/S.check
1011

12+
//--- S.cppm
1113
export module S;
1214
static int static_func() {
1315
return 43;
@@ -17,6 +19,7 @@ export int func() {
1719
return static_func();
1820
}
1921

22+
//--- S.check
2023
// CHECK: <DECL_FUNCTION
2124
// Checks that we won't see a second function
2225
// CHECK-NOT: <DECL_FUNCTION

clang/tools/clang-repl/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ set( LLVM_LINK_COMPONENTS
99

1010
add_clang_tool(clang-repl
1111
ClangRepl.cpp
12+
13+
EXPORT_SYMBOLS
1214
)
1315

1416
if(MSVC)
@@ -61,8 +63,6 @@ clang_target_link_libraries(clang-repl PRIVATE
6163
clangInterpreter
6264
)
6365

64-
export_executable_symbols_for_plugins(clang-repl)
65-
6666
# The clang-repl binary can get huge with static linking in debug mode.
6767
# Some 32-bit targets use PLT slots with limited branch range by default and we
6868
# start to exceed this limit, e.g. when linking for arm-linux-gnueabihf with

lld/COFF/Chunks.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,14 +842,9 @@ const uint8_t arm64Thunk[] = {
842842
0x00, 0x02, 0x1f, 0xd6, // br x16
843843
};
844844

845-
size_t RangeExtensionThunkARM64::getSize() const {
846-
assert(ctx.config.machine == ARM64);
847-
(void)&ctx;
848-
return sizeof(arm64Thunk);
849-
}
845+
size_t RangeExtensionThunkARM64::getSize() const { return sizeof(arm64Thunk); }
850846

851847
void RangeExtensionThunkARM64::writeTo(uint8_t *buf) const {
852-
assert(ctx.config.machine == ARM64);
853848
memcpy(buf, arm64Thunk, sizeof(arm64Thunk));
854849
applyArm64Addr(buf + 0, target->getRVA(), rva, 12);
855850
applyArm64Imm(buf + 4, target->getRVA() & 0xfff, 0);

lld/COFF/Chunks.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,20 +615,22 @@ class RangeExtensionThunkARM : public NonSectionCodeChunk {
615615
COFFLinkerContext &ctx;
616616
};
617617

618+
// A ragnge extension thunk used for both ARM64EC and ARM64 machine types.
618619
class RangeExtensionThunkARM64 : public NonSectionCodeChunk {
619620
public:
620-
explicit RangeExtensionThunkARM64(COFFLinkerContext &ctx, Defined *t)
621-
: target(t), ctx(ctx) {
621+
explicit RangeExtensionThunkARM64(MachineTypes machine, Defined *t)
622+
: target(t), machine(machine) {
622623
setAlignment(4);
624+
assert(llvm::COFF::isAnyArm64(machine));
623625
}
624626
size_t getSize() const override;
625627
void writeTo(uint8_t *buf) const override;
626-
MachineTypes getMachine() const override { return ARM64; }
628+
MachineTypes getMachine() const override { return machine; }
627629

628630
Defined *target;
629631

630632
private:
631-
COFFLinkerContext &ctx;
633+
MachineTypes machine;
632634
};
633635

634636
// Windows-specific.

0 commit comments

Comments
 (0)