Skip to content

Commit ab47d36

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:e8a656376857 into amd-gfx:bc4e29b082d5
Local branch amd-gfx bc4e29b Merged main:c135f6ffe254 into amd-gfx:09b941d45305 Remote branch main e8a6563 Fix-forward RegAllocFast: Avoid using temporary DiagnosticInfo llvm#120184 (llvm#120268)
2 parents bc4e29b + e8a6563 commit ab47d36

File tree

49 files changed

+713
-179
lines changed

Some content is hidden

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

49 files changed

+713
-179
lines changed

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ foreach(target armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi;armv8.1m.
333333
foreach(lang C;CXX;ASM)
334334
# TODO: The preprocessor defines workaround various issues in libc and libc++ integration.
335335
# These should be addressed and removed over time.
336-
set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "--target=${target} -Wno-atomic-alignment \"-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" \"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1")
336+
set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "--target=${target} -Wno-atomic-alignment \"-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" -D_LIBCPP_PRINT=1")
337337
if(NOT ${target} STREQUAL "aarch64-none-elf")
338338
set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "${RUNTIMES_${target}_CMAKE_${lang}_local_flags} -mthumb")
339339
endif()
@@ -394,7 +394,7 @@ foreach(target riscv32-unknown-elf)
394394
foreach(lang C;CXX;ASM)
395395
# TODO: The preprocessor defines workaround various issues in libc and libc++ integration.
396396
# These should be addressed and removed over time.
397-
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -march=rv32imafc -mabi=ilp32f -Wno-atomic-alignment \"-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" \"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1" CACHE STRING "")
397+
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -march=rv32imafc -mabi=ilp32f -Wno-atomic-alignment \"-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" -D_LIBCPP_PRINT=1" CACHE STRING "")
398398
endforeach()
399399
foreach(type SHARED;MODULE;EXE)
400400
set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,9 @@ defm diagnostics_show_line_numbers : BoolFOption<"diagnostics-show-line-numbers"
34633463
NegFlag<SetFalse, [], [ClangOption, CC1Option],
34643464
"Show line numbers in diagnostic code snippets">,
34653465
PosFlag<SetTrue>>;
3466+
def fno_realloc_lhs : Flag<["-"], "fno-realloc-lhs">, Group<f_Group>,
3467+
HelpText<"An allocatable left-hand side of an intrinsic assignment is assumed to be allocated and match the shape/type of the right-hand side">,
3468+
Visibility<[FlangOption, FC1Option]>;
34663469
def fno_stack_protector : Flag<["-"], "fno-stack-protector">, Group<f_Group>,
34673470
HelpText<"Disable the use of stack protectors">;
34683471
def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group<f_Group>,
@@ -4296,6 +4299,9 @@ defm stack_size_section : BoolFOption<"stack-size-section",
42964299
PosFlag<SetTrue, [], [ClangOption, CC1Option],
42974300
"Emit section containing metadata on function stack sizes">,
42984301
NegFlag<SetFalse>>;
4302+
def frealloc_lhs : Flag<["-"], "frealloc-lhs">, Group<f_Group>,
4303+
Visibility<[FlangOption, FC1Option]>,
4304+
HelpText<"If an allocatable left-hand side of an intrinsic assignment is unallocated or its shape/type does not match the right-hand side, then it is automatically (re)allocated">;
42994305
def fstack_usage : Flag<["-"], "fstack-usage">, Group<f_Group>,
43004306
HelpText<"Emit .su file containing information on function stack sizes">;
43014307
def stack_usage_file : Separate<["-"], "stack-usage-file">,
@@ -6775,7 +6781,6 @@ defm real_4_real_8 : BooleanFFlag<"real-4-real-8">, Group<gfortran_Group>;
67756781
defm real_8_real_10 : BooleanFFlag<"real-8-real-10">, Group<gfortran_Group>;
67766782
defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, Group<gfortran_Group>;
67776783
defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group<gfortran_Group>;
6778-
defm realloc_lhs : BooleanFFlag<"realloc-lhs">, Group<gfortran_Group>;
67796784
defm recursive : BooleanFFlag<"recursive">, Group<gfortran_Group>;
67806785
defm repack_arrays : BooleanFFlag<"repack-arrays">, Group<gfortran_Group>;
67816786
defm second_underscore : BooleanFFlag<"second-underscore">, Group<gfortran_Group>;

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,20 +2995,21 @@ llvm::DIType *CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
29952995
if (!ID)
29962996
return nullptr;
29972997

2998+
auto RuntimeLang =
2999+
static_cast<llvm::dwarf::SourceLanguage>(TheCU->getSourceLanguage());
3000+
29983001
// Return a forward declaration if this type was imported from a clang module,
29993002
// and this is not the compile unit with the implementation of the type (which
30003003
// may contain hidden ivars).
30013004
if (DebugTypeExtRefs && ID->isFromASTFile() && ID->getDefinition() &&
30023005
!ID->getImplementation())
3003-
return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
3004-
ID->getName(),
3005-
getDeclContextDescriptor(ID), Unit, 0);
3006+
return DBuilder.createForwardDecl(
3007+
llvm::dwarf::DW_TAG_structure_type, ID->getName(),
3008+
getDeclContextDescriptor(ID), Unit, 0, RuntimeLang);
30063009

30073010
// Get overall information about the record type for the debug info.
30083011
llvm::DIFile *DefUnit = getOrCreateFile(ID->getLocation());
30093012
unsigned Line = getLineNumber(ID->getLocation());
3010-
auto RuntimeLang =
3011-
static_cast<llvm::dwarf::SourceLanguage>(TheCU->getSourceLanguage());
30123013

30133014
// If this is just a forward declaration return a special forward-declaration
30143015
// debug type since we won't be able to lay out the entire type.

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
5555
options::OPT_fdefault_double_8,
5656
options::OPT_flarge_sizes,
5757
options::OPT_fno_automatic,
58-
options::OPT_fhermetic_module_files});
58+
options::OPT_fhermetic_module_files,
59+
options::OPT_frealloc_lhs,
60+
options::OPT_fno_realloc_lhs});
5961
}
6062

6163
void Flang::addPreprocessingOptions(const ArgList &Args,

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
826826
for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) {
827827
if (Prev->is(TT_TemplateString) && Prev->opensScope())
828828
return true;
829-
if (Prev->is(TT_TemplateString) && Prev->closesScope())
829+
if (Prev->opensScope() ||
830+
(Prev->is(TT_TemplateString) && Prev->closesScope())) {
830831
break;
832+
}
831833
}
832834
return false;
833835
};

clang/test/Modules/ExtDebugInfo.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ int foo(ObjCClass *c) {
7575

7676
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass",
7777
// CHECK-SAME: scope: ![[MOD]],
78-
// CHECK-SAME: flags: DIFlagFwdDecl)
78+
// CHECK-SAME: flags: DIFlagFwdDecl,
79+
// CHECK-SAME: runtimeLang: DW_LANG_ObjC)
7980

8081
// CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type,
8182
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,

clang/test/Modules/ModuleDebugInfo.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDecl",
4141
// CHECK-SAME: scope: ![[MODULE]],
42+
// CHECK-SAME: runtimeLang: DW_LANG_ObjC
4243

4344
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass",
4445
// CHECK-SAME: scope: ![[MODULE]],

clang/unittests/Format/FormatTestJS.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,13 @@ TEST_F(FormatTestJS, TemplateStringMultiLineExpression) {
21612161
" aaaa: aaaaa,\n"
21622162
" bbbb: bbbbb,\n"
21632163
" })}`;");
2164+
2165+
verifyFormat("`${\n"
2166+
" (\n"
2167+
" FOOFOOFOOFOO____FOO_FOO_FO_FOO_FOOO -\n"
2168+
" (barbarbarbar____bar_bar_bar_bar_bar_bar +\n"
2169+
" bar_bar_bar_barbarbar___bar_bar_bar + 1),\n"
2170+
" )}`;");
21642171
}
21652172

21662173
TEST_F(FormatTestJS, TemplateStringASI) {

flang/include/flang/Lower/LoweringOptions.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,11 @@ ENUM_LOWERINGOPT(Underscoring, unsigned, 1, 1)
3838
/// (i.e. wraps around as two's complement). Off by default.
3939
ENUM_LOWERINGOPT(IntegerWrapAround, unsigned, 1, 0)
4040

41+
/// If true (default), follow Fortran 2003 rules for (re)allocating
42+
/// the allocatable on the left side of the intrinsic assignment,
43+
/// if LHS and RHS have mismatching shapes/types.
44+
/// If false, assume that the shapes/types/allocation-status match.
45+
ENUM_LOWERINGOPT(ReallocateLHS, unsigned, 1, 1)
46+
4147
#undef LOWERINGOPT
4248
#undef ENUM_LOWERINGOPT

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,11 @@ bool CompilerInvocation::createFromArgs(
13781378
invoc.getDiagnosticOpts().Remarks.push_back(a->getValue());
13791379
}
13801380

1381+
// -frealloc-lhs is the default.
1382+
if (!args.hasFlag(clang::driver::options::OPT_frealloc_lhs,
1383+
clang::driver::options::OPT_fno_realloc_lhs, true))
1384+
invoc.loweringOpts.setReallocateLHS(false);
1385+
13811386
success &= parseFrontendArgs(invoc.getFrontendOpts(), args, diags);
13821387
parseTargetArgs(invoc.getTargetOpts(), args);
13831388
parsePreprocessorArgs(invoc.getPreprocessorOpts(), args);

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4461,7 +4461,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
44614461
// lowered.
44624462
const bool isWholeAllocatableAssignment =
44634463
!userDefinedAssignment && !isInsideHlfirWhere() &&
4464-
Fortran::lower::isWholeAllocatable(assign.lhs);
4464+
Fortran::lower::isWholeAllocatable(assign.lhs) &&
4465+
bridge.getLoweringOptions().getReallocateLHS();
44654466
const bool isUserDefAssignToPointerOrAllocatable =
44664467
userDefinedAssignment &&
44674468
firstDummyIsPointerOrAllocatable(*userDefinedAssignment);

flang/test/Driver/frealloc-lhs.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! Check that the driver passes through -f[no-]realloc-lhs:
2+
! RUN: %flang -### -S -frealloc-lhs %s -o - 2>&1 | FileCheck %s --check-prefix=ON
3+
! RUN: %flang -### -S -fno-realloc-lhs %s -o - 2>&1 | FileCheck %s --check-prefix=OFF
4+
5+
! Check that the compiler accepts -f[no-]realloc-lhs:
6+
! RUN: %flang_fc1 -emit-hlfir -frealloc-lhs %s -o -
7+
! RUN: %flang_fc1 -emit-hlfir -fno-realloc-lhs %s -o -
8+
9+
! ON: "-fc1"{{.*}}"-frealloc-lhs"
10+
11+
! OFF: "-fc1"{{.*}}"-fno-realloc-lhs"

flang/test/Lower/reallocate-lhs.f90

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! RUN: bbc %s -o - -emit-hlfir | FileCheck %s --check-prefixes=ALL,REALLOCLHS
2+
! RUN: bbc %s -o - -emit-hlfir -frealloc-lhs | FileCheck %s --check-prefixes=ALL,REALLOCLHS
3+
! RUN: bbc %s -o - -emit-hlfir -frealloc-lhs=false | FileCheck %s --check-prefixes=ALL,NOREALLOCLHS
4+
! RUN: %flang_fc1 %s -o - -emit-hlfir | FileCheck %s --check-prefixes=ALL,REALLOCLHS
5+
! RUN: %flang_fc1 %s -o - -emit-hlfir -frealloc-lhs | FileCheck %s --check-prefixes=ALL,REALLOCLHS
6+
! RUN: %flang_fc1 %s -o - -emit-hlfir -fno-realloc-lhs | FileCheck %s --check-prefixes=ALL,NOREALLOCLHS
7+
8+
subroutine test1(a, b)
9+
integer, allocatable :: a(:), b(:)
10+
a = b + 1
11+
end
12+
13+
! ALL-LABEL: func.func @_QPtest1(
14+
! ALL: %[[VAL_3:.*]]:2 = hlfir.declare{{.*}}{fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest1Ea"}
15+
! REALLOCLHS: hlfir.assign %{{.*}} to %[[VAL_3]]#0 realloc : !hlfir.expr<?xi32>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
16+
17+
! NOREALLOCLHS: %[[VAL_20:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
18+
! NOREALLOCLHS: hlfir.assign %{{.*}} to %[[VAL_20]] : !hlfir.expr<?xi32>, !fir.box<!fir.heap<!fir.array<?xi32>>>
19+
20+
subroutine test2(a, b)
21+
character(len=*), allocatable :: a(:)
22+
character(len=*) :: b(:)
23+
a = b
24+
end subroutine test2
25+
26+
! ALL-LABEL: func.func @_QPtest2(
27+
! ALL: %[[VAL_3:.*]]:2 = hlfir.declare{{.*}}{fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest2Ea"}
28+
! REALLOCLHS: hlfir.assign %{{.*}} to %[[VAL_3]]#0 realloc keep_lhs_len : !fir.box<!fir.array<?x!fir.char<1,?>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
29+
30+
! NOREALLOCLHS: %[[VAL_7:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
31+
! NOREALLOCLHS: hlfir.assign %{{.*}} to %[[VAL_7]] : !fir.box<!fir.array<?x!fir.char<1,?>>>, !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
32+

flang/tools/bbc/bbc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ static llvm::cl::opt<bool> integerWrapAround(
234234
llvm::cl::desc("Treat signed integer overflow as two's complement"),
235235
llvm::cl::init(false));
236236

237+
static llvm::cl::opt<bool>
238+
reallocateLHS("frealloc-lhs",
239+
llvm::cl::desc("Follow Fortran 2003 rules for (re)allocating "
240+
"the LHS of the intrinsic assignment"),
241+
llvm::cl::init(true));
242+
237243
#define FLANG_EXCLUDE_CODEGEN
238244
#include "flang/Optimizer/Passes/CommandLineOpts.h"
239245
#include "flang/Optimizer/Passes/Pipelines.h"
@@ -375,6 +381,7 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
375381
loweringOptions.setNoPPCNativeVecElemOrder(enableNoPPCNativeVecElemOrder);
376382
loweringOptions.setLowerToHighLevelFIR(useHLFIR || emitHLFIR);
377383
loweringOptions.setIntegerWrapAround(integerWrapAround);
384+
loweringOptions.setReallocateLHS(reallocateLHS);
378385
std::vector<Fortran::lower::EnvironmentDefault> envDefaults = {};
379386
Fortran::frontend::TargetOptions targetOpts;
380387
Fortran::frontend::CodeGenOptions cgOpts;

libcxx/src/chrono.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
# include <sys/time.h> // for gettimeofday and timeval
3232
#endif
3333

34+
#if defined(__LLVM_LIBC__)
35+
# define _LIBCPP_HAS_TIMESPEC_GET
36+
#endif
37+
3438
// OpenBSD and GPU do not have a fully conformant suite of POSIX timers, but
3539
// it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
3640
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(__AMDGPU__) || \
@@ -115,6 +119,15 @@ static system_clock::time_point __libcpp_system_clock_now() {
115119
return system_clock::time_point(duration_cast<system_clock::duration>(d - nt_to_unix_epoch));
116120
}
117121

122+
#elif defined(_LIBCPP_HAS_TIMESPEC_GET)
123+
124+
static system_clock::time_point __libcpp_system_clock_now() {
125+
struct timespec ts;
126+
if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
127+
__throw_system_error(errno, "timespec_get(TIME_UTC) failed");
128+
return system_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000));
129+
}
130+
118131
#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
119132

120133
static system_clock::time_point __libcpp_system_clock_now() {
@@ -216,6 +229,15 @@ static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
216229
return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic()));
217230
}
218231

232+
# elif defined(_LIBCPP_HAS_TIMESPEC_GET)
233+
234+
static steady_clock::time_point __libcpp_steady_clock_now() {
235+
struct timespec ts;
236+
if (timespec_get(&ts, TIME_MONOTONIC) != TIME_MONOTONIC)
237+
__throw_system_error(errno, "timespec_get(TIME_MONOTONIC) failed");
238+
return steady_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000));
239+
}
240+
219241
# elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
220242

221243
static steady_clock::time_point __libcpp_steady_clock_now() {

libcxx/src/filesystem/filesystem_clock.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
# include <sys/time.h> // for gettimeofday and timeval
3131
#endif
3232

33+
#if defined(__LLVM_LIBC__)
34+
# define _LIBCPP_HAS_TIMESPEC_GET
35+
#endif
36+
3337
#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__AMDGPU__) || defined(__NVPTX__) || \
3438
(defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
3539
# define _LIBCPP_HAS_CLOCK_GETTIME
@@ -50,6 +54,12 @@ _FilesystemClock::time_point _FilesystemClock::now() noexcept {
5054
GetSystemTimeAsFileTime(&time);
5155
detail::TimeSpec tp = detail::filetime_to_timespec(time);
5256
return time_point(__secs(tp.tv_sec) + chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));
57+
#elif defined(_LIBCPP_HAS_TIMESPEC_GET)
58+
typedef chrono::duration<rep, nano> __nsecs;
59+
struct timespec ts;
60+
if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
61+
__throw_system_error(errno, "timespec_get(TIME_UTC) failed");
62+
return time_point(__secs(ts.tv_sec) + chrono::duration_cast<duration>(__nsecs(ts.tv_nsec)));
5363
#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
5464
typedef chrono::duration<rep, nano> __nsecs;
5565
struct timespec tp;

0 commit comments

Comments
 (0)