Skip to content

Commit e6f2ede

Browse files
authored
merge main into amd-staging (#464)
2 parents c76e69a + f45745e commit e6f2ede

File tree

58 files changed

+385
-178
lines changed

Some content is hidden

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

58 files changed

+385
-178
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ DataAggregator::writeAggregatedFile(StringRef OutputFilename) const {
22152215
OutFile << "boltedcollection\n";
22162216
if (opts::BasicAggregation) {
22172217
OutFile << "no_lbr";
2218-
for (const StringMapEntry<std::nullopt_t> &Entry : EventNames)
2218+
for (const StringMapEntry<EmptyStringSetTag> &Entry : EventNames)
22192219
OutFile << " " << Entry.getKey();
22202220
OutFile << "\n";
22212221

@@ -2291,7 +2291,7 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
22912291

22922292
ListSeparator LS(",");
22932293
raw_string_ostream EventNamesOS(BP.Header.EventNames);
2294-
for (const StringMapEntry<std::nullopt_t> &EventEntry : EventNames)
2294+
for (const StringMapEntry<EmptyStringSetTag> &EventEntry : EventNames)
22952295
EventNamesOS << LS << EventEntry.first().str();
22962296

22972297
BP.Header.Flags = opts::BasicAggregation ? BinaryFunction::PF_BASIC

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ std::error_code YAMLProfileWriter::writeProfile(const RewriteInstance &RI) {
382382
StringSet<> EventNames = RI.getProfileReader()->getEventNames();
383383
if (!EventNames.empty()) {
384384
std::string Sep;
385-
for (const StringMapEntry<std::nullopt_t> &EventEntry : EventNames) {
385+
for (const StringMapEntry<EmptyStringSetTag> &EventEntry : EventNames) {
386386
BP.Header.EventNames += Sep + EventEntry.first().str();
387387
Sep = ",";
388388
}

clang/lib/CodeGen/TargetBuiltins/NVPTX.cpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -375,28 +375,28 @@ static Value *MakeCpAsync(unsigned IntrinsicID, unsigned IntrinsicIDS,
375375
CGF.EmitScalarExpr(E->getArg(1))});
376376
}
377377

378-
static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID,
379-
const CallExpr *E, CodeGenFunction &CGF) {
378+
static bool EnsureNativeHalfSupport(unsigned BuiltinID, const CallExpr *E,
379+
CodeGenFunction &CGF) {
380380
auto &C = CGF.CGM.getContext();
381-
if (!(C.getLangOpts().NativeHalfType ||
382-
!C.getTargetInfo().useFP16ConversionIntrinsics())) {
381+
if (!C.getLangOpts().NativeHalfType &&
382+
C.getTargetInfo().useFP16ConversionIntrinsics()) {
383383
CGF.CGM.Error(E->getExprLoc(), C.BuiltinInfo.getQuotedName(BuiltinID) +
384384
" requires native half type support.");
385-
return nullptr;
385+
return false;
386386
}
387+
return true;
388+
}
387389

388-
if (BuiltinID == NVPTX::BI__nvvm_ldg_h || BuiltinID == NVPTX::BI__nvvm_ldg_h2)
389-
return MakeLdg(CGF, E);
390-
391-
if (IntrinsicID == Intrinsic::nvvm_ldu_global_f)
392-
return MakeLdu(IntrinsicID, CGF, E);
390+
static Value *MakeHalfType(Function *Intrinsic, unsigned BuiltinID,
391+
const CallExpr *E, CodeGenFunction &CGF) {
392+
if (!EnsureNativeHalfSupport(BuiltinID, E, CGF))
393+
return nullptr;
393394

394395
SmallVector<Value *, 16> Args;
395-
auto *F = CGF.CGM.getIntrinsic(IntrinsicID);
396-
auto *FTy = F->getFunctionType();
396+
auto *FTy = Intrinsic->getFunctionType();
397397
unsigned ICEArguments = 0;
398398
ASTContext::GetBuiltinTypeError Error;
399-
C.GetBuiltinType(BuiltinID, Error, &ICEArguments);
399+
CGF.CGM.getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
400400
assert(Error == ASTContext::GE_None && "Should not codegen an error");
401401
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
402402
assert((ICEArguments & (1 << i)) == 0);
@@ -407,8 +407,14 @@ static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID,
407407
Args.push_back(ArgValue);
408408
}
409409

410-
return CGF.Builder.CreateCall(F, Args);
410+
return CGF.Builder.CreateCall(Intrinsic, Args);
411411
}
412+
413+
static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID,
414+
const CallExpr *E, CodeGenFunction &CGF) {
415+
return MakeHalfType(CGF.CGM.getIntrinsic(IntrinsicID), BuiltinID, E, CGF);
416+
}
417+
412418
} // namespace
413419

414420
Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
@@ -913,9 +919,14 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
913919
}
914920
// The following builtins require half type support
915921
case NVPTX::BI__nvvm_ex2_approx_f16:
916-
return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16, BuiltinID, E, *this);
922+
return MakeHalfType(
923+
CGM.getIntrinsic(Intrinsic::nvvm_ex2_approx, Builder.getHalfTy()),
924+
BuiltinID, E, *this);
917925
case NVPTX::BI__nvvm_ex2_approx_f16x2:
918-
return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16x2, BuiltinID, E, *this);
926+
return MakeHalfType(
927+
CGM.getIntrinsic(Intrinsic::nvvm_ex2_approx,
928+
FixedVectorType::get(Builder.getHalfTy(), 2)),
929+
BuiltinID, E, *this);
919930
case NVPTX::BI__nvvm_ff2f16x2_rn:
920931
return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn, BuiltinID, E, *this);
921932
case NVPTX::BI__nvvm_ff2f16x2_rn_relu:
@@ -1049,12 +1060,22 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
10491060
case NVPTX::BI__nvvm_fabs_d:
10501061
return Builder.CreateUnaryIntrinsic(Intrinsic::fabs,
10511062
EmitScalarExpr(E->getArg(0)));
1063+
case NVPTX::BI__nvvm_ex2_approx_d:
1064+
case NVPTX::BI__nvvm_ex2_approx_f:
1065+
return Builder.CreateUnaryIntrinsic(Intrinsic::nvvm_ex2_approx,
1066+
EmitScalarExpr(E->getArg(0)));
1067+
case NVPTX::BI__nvvm_ex2_approx_ftz_f:
1068+
return Builder.CreateUnaryIntrinsic(Intrinsic::nvvm_ex2_approx_ftz,
1069+
EmitScalarExpr(E->getArg(0)));
10521070
case NVPTX::BI__nvvm_ldg_h:
10531071
case NVPTX::BI__nvvm_ldg_h2:
1054-
return MakeHalfType(Intrinsic::not_intrinsic, BuiltinID, E, *this);
1072+
return EnsureNativeHalfSupport(BuiltinID, E, *this) ? MakeLdg(*this, E)
1073+
: nullptr;
10551074
case NVPTX::BI__nvvm_ldu_h:
10561075
case NVPTX::BI__nvvm_ldu_h2:
1057-
return MakeHalfType(Intrinsic::nvvm_ldu_global_f, BuiltinID, E, *this);
1076+
return EnsureNativeHalfSupport(BuiltinID, E, *this)
1077+
? MakeLdu(Intrinsic::nvvm_ldu_global_f, *this, E)
1078+
: nullptr;
10581079
case NVPTX::BI__nvvm_cp_async_ca_shared_global_4:
10591080
return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_4,
10601081
Intrinsic::nvvm_cp_async_ca_shared_global_4_s, *this, E,

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,10 +2550,14 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
25502550
}
25512551

25522552
if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
2553-
if (std::optional<std::string> RuntimePath = TC.getRuntimePath())
2554-
llvm::outs() << *RuntimePath << '\n';
2555-
else
2556-
llvm::outs() << TC.getCompilerRTPath() << '\n';
2553+
for (auto RuntimePath :
2554+
{TC.getRuntimePath(), std::make_optional(TC.getCompilerRTPath())}) {
2555+
if (RuntimePath && getVFS().exists(*RuntimePath)) {
2556+
llvm::outs() << *RuntimePath << '\n';
2557+
return false;
2558+
}
2559+
}
2560+
llvm::outs() << "(runtime dir is not present)" << '\n';
25572561
return false;
25582562
}
25592563

clang/lib/Headers/hlsl/hlsl_compat_overloads.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#ifndef _HLSL_COMPAT_OVERLOADS_H_
10-
#define _HLSl_COMPAT_OVERLOADS_H_
10+
#define _HLSL_COMPAT_OVERLOADS_H_
1111

1212
namespace hlsl {
1313

clang/test/CodeGen/builtins-nvptx-native-half-type-native.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
typedef __fp16 __fp16v2 __attribute__((ext_vector_type(2)));
99

1010
// CHECK: call half @llvm.nvvm.ex2.approx.f16(half {{.*}})
11-
// CHECK: call <2 x half> @llvm.nvvm.ex2.approx.f16x2(<2 x half> {{.*}})
11+
// CHECK: call <2 x half> @llvm.nvvm.ex2.approx.v2f16(<2 x half> {{.*}})
1212
// CHECK: call half @llvm.nvvm.fma.rn.relu.f16(half {{.*}}, half {{.*}}, half {{.*}})
1313
// CHECK: call half @llvm.nvvm.fma.rn.ftz.relu.f16(half {{.*}}, half {{.*}}, half {{.*}})
1414
// CHECK: call <2 x half> @llvm.nvvm.fma.rn.relu.f16x2(<2 x half> {{.*}}, <2 x half> {{.*}}, <2 x half> {{.*}})

clang/test/CodeGen/builtins-nvptx-native-half-type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ __device__ void nvvm_ex2_sm75() {
4141
#if __CUDA_ARCH__ >= 750
4242
// CHECK_PTX70_SM75: call half @llvm.nvvm.ex2.approx.f16
4343
__nvvm_ex2_approx_f16(0.1f16);
44-
// CHECK_PTX70_SM75: call <2 x half> @llvm.nvvm.ex2.approx.f16x2
44+
// CHECK_PTX70_SM75: call <2 x half> @llvm.nvvm.ex2.approx.v2f16
4545
__nvvm_ex2_approx_f16x2({0.1f16, 0.7f16});
4646
#endif
4747
// CHECK: ret void

lld/MachO/Arch/X86_64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int64_t X86_64::getEmbeddedAddend(MemoryBufferRef mb, uint64_t offset,
104104
void X86_64::relocateOne(uint8_t *loc, const Reloc &r, uint64_t value,
105105
uint64_t relocVA) const {
106106
if (r.pcrel) {
107-
uint64_t pc = relocVA + (1 << r.length) + pcrelOffset(r.type);
107+
uint64_t pc = relocVA + (1ull << r.length) + pcrelOffset(r.type);
108108
value -= pc;
109109
}
110110

lld/MachO/InputSection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ WordLiteralInputSection::WordLiteralInputSection(const Section &section,
348348
}
349349

350350
uint64_t WordLiteralInputSection::getOffset(uint64_t off) const {
351+
if (off >= data.size())
352+
fatal(toString(this) + ": offset is outside the section");
353+
351354
auto *osec = cast<WordLiteralSection>(parent);
352355
const uintptr_t buf = reinterpret_cast<uintptr_t>(data.data());
353356
switch (sectionType(getFlags())) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Test that we properly detect and report out-of-bounds offsets in literal sections.
2+
## We're intentionally testing fatal errors (for malformed input files), and
3+
## fatal errors aren't supported for testing when main is run twice.
4+
# XFAIL: main-run-twice
5+
6+
# REQUIRES: x86
7+
# RUN: rm -rf %t; split-file %s %t
8+
9+
## Test WordLiteralInputSection bounds checking
10+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/word-literal.s -o %t/word-literal.o
11+
# RUN: not %lld -dylib %t/word-literal.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=WORD
12+
13+
## Test CStringInputSection bounds checking
14+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/cstring.s -o %t/cstring.o
15+
# RUN: not %lld -dylib %t/cstring.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CSTRING
16+
17+
# WORD: error: {{.*}}word-literal.o:(__literal4): offset is outside the section
18+
# CSTRING: error: {{.*}}cstring.o:(__cstring): offset is outside the section
19+
20+
#--- word-literal.s
21+
.section __TEXT,__literal4,4byte_literals
22+
L_literal:
23+
.long 0x01020304
24+
25+
.text
26+
.globl _main
27+
_main:
28+
# We use a subtractor expression to force a section relocation. Symbol relocations
29+
# don't trigger the error.
30+
.long L_literal - _main + 4
31+
32+
.subsections_via_symbols
33+
34+
#--- cstring.s
35+
## Create a cstring section with a reference that points past the end
36+
.cstring
37+
L_str:
38+
.asciz "foo"
39+
40+
.text
41+
.globl _main
42+
_main:
43+
.long L_str - _main + 4
44+
45+
.subsections_via_symbols

0 commit comments

Comments
 (0)