Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from llvm:main #1

Merged
merged 20 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
44ba43a
Revert "[Flang][Driver] Add a flag to control zero initialization of …
kiranchandramohan Jan 15, 2025
ff862d6
[flang] Modifications to ieee floating point environment procedures (…
vdonaldson Jan 15, 2025
3fd296e
[AST] Migrate away from PointerUnion::dyn_cast (NFC) (#123012)
kazutakahirata Jan 15, 2025
3a3a1e4
[CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (#123013)
kazutakahirata Jan 15, 2025
acdcdbc
[Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#123014)
kazutakahirata Jan 15, 2025
94e9813
[AsmParser] Avoid repeated map lookups (NFC) (#123015)
kazutakahirata Jan 15, 2025
ebb5856
[CodeGen] Avoid repeated hash lookups (NFC) (#123016)
kazutakahirata Jan 15, 2025
618ac90
[TableGen] Avoid repeated hash lookups (NFC) (#123018)
kazutakahirata Jan 15, 2025
8ac35bd
[CUDA][HIP] Support CUID in new driver (#122859)
yxsamliu Jan 15, 2025
3986cff
[lldb] Add OpenBSD signals (#123005)
brad0 Jan 15, 2025
7402521
[mlir-cpu-runner] Pass --exclude-libs to linker when building runner …
andfau-amd Jan 15, 2025
d0a3642
[gn build] Port 3986cffe8112
llvmgnsyncbot Jan 15, 2025
34d5072
[MLIR][test] Check for ml_dtypes before running tests (#123061)
kwk Jan 15, 2025
2570e35
[InstCombine] Handle trunc to i1 in align assume. (#122949)
andjo403 Jan 15, 2025
07a1847
[HLSL] Make bool in hlsl i32 (#122977)
spall Jan 15, 2025
2bfa7bc
[flang] Propagate fastmath flags to matmul_transpose. (#122842)
vzakhari Jan 15, 2025
3bb969f
[flang] Inline hlfir.matmul[_transpose]. (#122821)
vzakhari Jan 15, 2025
80084e9
[LLD][COFF] Pull _load_config_used symbol from both symbol tables on …
cjacek Jan 15, 2025
0360f81
[LLD][COFF] Infer subsystem from EC symbol table for ARM64X (#122838)
cjacek Jan 15, 2025
1c5f874
[Driver] Fix a warning
kazutakahirata Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ enum ModuleHeaderMode {
HeaderMode_System
};

/// Options for specifying CUID used by CUDA/HIP for uniquely identifying
/// compilation units.
class CUIDOptions {
public:
enum class Kind { Hash, Random, Fixed, None, Invalid };

CUIDOptions() = default;
CUIDOptions(llvm::opt::DerivedArgList &Args, const Driver &D);

// Get the CUID for an input string
std::string getCUID(StringRef InputFile,
llvm::opt::DerivedArgList &Args) const;

bool isEnabled() const {
return UseCUID != Kind::None && UseCUID != Kind::Invalid;
}

private:
Kind UseCUID = Kind::None;
StringRef FixedCUID;
};

/// Driver - Encapsulate logic for constructing compilation processes
/// from a set of gcc-driver-like command line arguments.
class Driver {
Expand Down Expand Up @@ -119,6 +141,9 @@ class Driver {
/// LTO mode selected via -f(no-offload-)?lto(=.*)? options.
LTOKind OffloadLTOMode;

/// Options for CUID
CUIDOptions CUIDOpts;

public:
enum OpenMPRuntimeKind {
/// An unknown OpenMP runtime. We can't generate effective OpenMP code
Expand Down Expand Up @@ -501,10 +526,11 @@ class Driver {
/// \param C - The compilation that is being built.
/// \param Args - The input arguments.
/// \param Input - The input type and arguments
/// \param CUID - The CUID for \p Input
/// \param HostAction - The host action used in the offloading toolchain.
Action *BuildOffloadingActions(Compilation &C,
llvm::opt::DerivedArgList &Args,
const InputTy &Input,
const InputTy &Input, StringRef CUID,
Action *HostAction) const;

/// Returns the set of bound architectures active for this offload kind.
Expand Down Expand Up @@ -728,6 +754,9 @@ class Driver {
/// Get the specific kind of offload LTO being performed.
LTOKind getOffloadLTOMode() const { return OffloadLTOMode; }

/// Get the CUID option.
const CUIDOptions &getCUIDOpts() const { return CUIDOpts; }

private:

/// Tries to load options from configuration files.
Expand Down
5 changes: 0 additions & 5 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3505,11 +3505,6 @@ def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group<f_Group>;
def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>,
Visibility<[ClangOption, FlangOption]>;
defm init_global_zero : BoolOptionWithoutMarshalling<"f", "init-global-zero",
PosFlag<SetTrue, [], [FlangOption, FC1Option],
"Zero initialize globals without default initialization (default)">,
NegFlag<SetFalse, [], [FlangOption, FC1Option],
"Do not zero initialize globals without default initialization">>;
def fno_pointer_tbaa : Flag<["-"], "fno-pointer-tbaa">, Group<f_Group>;
def fno_temp_file : Flag<["-"], "fno-temp-file">, Group<f_Group>,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, HelpText<
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6376,7 +6376,7 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());

if (auto P = D->getInstantiatedFrom()) {
if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
if (auto CTDorErr = import(CTD))
D2->setInstantiationOf(*CTDorErr);
} else {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
// HLSL explicitly defines the sizes and formats of some data types, and we
// need to conform to those regardless of what architecture you are targeting.
if (Opts.HLSL) {
BoolWidth = BoolAlign = 32;
LongWidth = LongAlign = 64;
if (!Opts.NativeHalfType) {
HalfFormat = &llvm::APFloat::IEEEsingle();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7768,7 +7768,7 @@ class MappableExprsHandler {
&Data : RecordLayout) {
if (Data.isNull())
continue;
if (const auto *Base = Data.dyn_cast<const CXXRecordDecl *>())
if (const auto *Base = dyn_cast<const CXXRecordDecl *>(Data))
getPlainLayout(Base, Layout, /*AsBase=*/true);
else
Layout.push_back(cast<const FieldDecl *>(Data));
Expand Down
116 changes: 65 additions & 51 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,50 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
return std::string(P);
}

CUIDOptions::CUIDOptions(llvm::opt::DerivedArgList &Args, const Driver &D)
: UseCUID(Kind::Hash) {
if (Arg *A = Args.getLastArg(options::OPT_fuse_cuid_EQ)) {
StringRef UseCUIDStr = A->getValue();
UseCUID = llvm::StringSwitch<Kind>(UseCUIDStr)
.Case("hash", Kind::Hash)
.Case("random", Kind::Random)
.Case("none", Kind::None)
.Default(Kind::Invalid);
if (UseCUID == Kind::Invalid)
D.Diag(clang::diag::err_drv_invalid_value)
<< A->getAsString(Args) << UseCUIDStr;
}

FixedCUID = Args.getLastArgValue(options::OPT_cuid_EQ);
if (!FixedCUID.empty())
UseCUID = Kind::Fixed;
}

std::string CUIDOptions::getCUID(StringRef InputFile,
llvm::opt::DerivedArgList &Args) const {
std::string CUID = FixedCUID.str();
if (CUID.empty()) {
if (UseCUID == Kind::Random)
CUID = llvm::utohexstr(llvm::sys::Process::GetRandomNumber(),
/*LowerCase=*/true);
else if (UseCUID == Kind::Hash) {
llvm::MD5 Hasher;
llvm::MD5::MD5Result Hash;
SmallString<256> RealPath;
llvm::sys::fs::real_path(InputFile, RealPath,
/*expand_tilde=*/true);
Hasher.update(RealPath);
for (auto *A : Args) {
if (A->getOption().matches(options::OPT_INPUT))
continue;
Hasher.update(A->getAsString(Args));
}
Hasher.final(Hash);
CUID = llvm::utohexstr(Hash.low(), /*LowerCase=*/true);
}
}
return CUID;
}
Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
DiagnosticsEngine &Diags, std::string Title,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
Expand Down Expand Up @@ -875,6 +919,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
C.addOffloadDeviceToolChain(HIPTC, OFK);
}

if (IsCuda || IsHIP)
CUIDOpts = CUIDOptions(C.getArgs(), *this);

//
// OpenMP
//
Expand Down Expand Up @@ -3161,19 +3208,15 @@ class OffloadingActionBuilder final {
/// Default GPU architecture if there's no one specified.
OffloadArch DefaultOffloadArch = OffloadArch::UNKNOWN;

/// Method to generate compilation unit ID specified by option
/// '-fuse-cuid='.
enum UseCUIDKind { CUID_Hash, CUID_Random, CUID_None, CUID_Invalid };
UseCUIDKind UseCUID = CUID_Hash;

/// Compilation unit ID specified by option '-cuid='.
StringRef FixedCUID;
/// Compilation unit ID specified by option '-fuse-cuid=' or'-cuid='.
const CUIDOptions &CUIDOpts;

public:
CudaActionBuilderBase(Compilation &C, DerivedArgList &Args,
const Driver::InputList &Inputs,
Action::OffloadKind OFKind)
: DeviceActionBuilder(C, Args, Inputs, OFKind) {
: DeviceActionBuilder(C, Args, Inputs, OFKind),
CUIDOpts(C.getDriver().getCUIDOpts()) {

CompileDeviceOnly = C.getDriver().offloadDeviceOnly();
Relocatable = Args.hasFlag(options::OPT_fgpu_rdc,
Expand Down Expand Up @@ -3204,28 +3247,8 @@ class OffloadingActionBuilder final {
// Set the flag to true, so that the builder acts on the current input.
IsActive = true;

std::string CUID = FixedCUID.str();
if (CUID.empty()) {
if (UseCUID == CUID_Random)
CUID = llvm::utohexstr(llvm::sys::Process::GetRandomNumber(),
/*LowerCase=*/true);
else if (UseCUID == CUID_Hash) {
llvm::MD5 Hasher;
llvm::MD5::MD5Result Hash;
SmallString<256> RealPath;
llvm::sys::fs::real_path(IA->getInputArg().getValue(), RealPath,
/*expand_tilde=*/true);
Hasher.update(RealPath);
for (auto *A : Args) {
if (A->getOption().matches(options::OPT_INPUT))
continue;
Hasher.update(A->getAsString(Args));
}
Hasher.final(Hash);
CUID = llvm::utohexstr(Hash.low(), /*LowerCase=*/true);
}
}
IA->setId(CUID);
if (CUIDOpts.isEnabled())
IA->setId(CUIDOpts.getCUID(IA->getInputArg().getValue(), Args));

if (CompileHostOnly)
return ABRT_Success;
Expand Down Expand Up @@ -3351,21 +3374,6 @@ class OffloadingActionBuilder final {
CompileHostOnly = C.getDriver().offloadHostOnly();
EmitLLVM = Args.getLastArg(options::OPT_emit_llvm);
EmitAsm = Args.getLastArg(options::OPT_S);
FixedCUID = Args.getLastArgValue(options::OPT_cuid_EQ);
if (Arg *A = Args.getLastArg(options::OPT_fuse_cuid_EQ)) {
StringRef UseCUIDStr = A->getValue();
UseCUID = llvm::StringSwitch<UseCUIDKind>(UseCUIDStr)
.Case("hash", CUID_Hash)
.Case("random", CUID_Random)
.Case("none", CUID_None)
.Default(CUID_Invalid);
if (UseCUID == CUID_Invalid) {
C.getDriver().Diag(diag::err_drv_invalid_value)
<< A->getAsString(Args) << UseCUIDStr;
C.setContainsError();
return true;
}
}

// --offload and --offload-arch options are mutually exclusive.
if (Args.hasArgNoClaim(options::OPT_offload_EQ) &&
Expand Down Expand Up @@ -4366,6 +4374,12 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
// Build the pipeline for this file.
Action *Current = C.MakeAction<InputAction>(*InputArg, InputType);

std::string CUID;
if (CUIDOpts.isEnabled() && types::isSrcFile(InputType)) {
CUID = CUIDOpts.getCUID(InputArg->getValue(), Args);
cast<InputAction>(Current)->setId(CUID);
}

// Use the current host action in any of the offloading actions, if
// required.
if (!UseNewOffloadingDriver)
Expand Down Expand Up @@ -4429,7 +4443,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
// Try to build the offloading actions and add the result as a dependency
// to the host.
if (UseNewOffloadingDriver)
Current = BuildOffloadingActions(C, Args, I, Current);
Current = BuildOffloadingActions(C, Args, I, CUID, Current);
// Use the current host action in any of the offloading actions, if
// required.
else if (OffloadBuilder->addHostDependenceToDeviceActions(Current,
Expand Down Expand Up @@ -4766,7 +4780,7 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,

Action *Driver::BuildOffloadingActions(Compilation &C,
llvm::opt::DerivedArgList &Args,
const InputTy &Input,
const InputTy &Input, StringRef CUID,
Action *HostAction) const {
// Don't build offloading actions if explicitly disabled or we do not have a
// valid source input and compile action to embed it in. If preprocessing only
Expand Down Expand Up @@ -4807,13 +4821,13 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
llvm::DenseSet<StringRef> Arches = getOffloadArchs(C, Args, Kind, TC);
SmallVector<StringRef, 0> Sorted(Arches.begin(), Arches.end());
llvm::sort(Sorted);
for (StringRef Arch : Sorted)
for (StringRef Arch : Sorted) {
TCAndArchs.push_back(std::make_pair(TC, Arch));
DeviceActions.push_back(
C.MakeAction<InputAction>(*InputArg, InputType, CUID));
}
}

for (unsigned I = 0, E = TCAndArchs.size(); I != E; ++I)
DeviceActions.push_back(C.MakeAction<InputAction>(*InputArg, InputType));

if (DeviceActions.empty())
return HostAction;

Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_flang_deprecated_no_hlfir,
options::OPT_fno_ppc_native_vec_elem_order,
options::OPT_fppc_native_vec_elem_order,
options::OPT_finit_global_zero,
options::OPT_fno_init_global_zero, options::OPT_ftime_report,
options::OPT_ftime_report_EQ});
options::OPT_ftime_report, options::OPT_ftime_report_EQ});
}

void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17310,7 +17310,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
return nullptr;
if (EnumUnderlying) {
EnumDecl *ED = cast<EnumDecl>(New);
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo *>())
if (TypeSourceInfo *TI = dyn_cast<TypeSourceInfo *>(EnumUnderlying))
ED->setIntegerTypeSourceInfo(TI);
else
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));
Expand Down Expand Up @@ -17943,7 +17943,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,

if (EnumUnderlying) {
EnumDecl *ED = cast<EnumDecl>(New);
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo*>())
if (TypeSourceInfo *TI = dyn_cast<TypeSourceInfo *>(EnumUnderlying))
ED->setIntegerTypeSourceInfo(TI);
else
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));
Expand Down
12 changes: 12 additions & 0 deletions clang/test/CodeGenHLSL/Bool.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s

// CHECK-LABEL: define noundef i1 {{.*}}fn{{.*}}(i1 noundef %x)
// CHECK: [[X:%.*]] = alloca i32, align 4
// CHECK-NEXT: [[Y:%.*]] = zext i1 {{%.*}} to i32
// CHECK-NEXT: store i32 [[Y]], ptr [[X]], align 4
// CHECK-NEXT: [[Z:%.*]] = load i32, ptr [[X]], align 4
// CHECK-NEXT: [[L:%.*]] = trunc i32 [[Z]] to i1
// CHECK-NEXT: ret i1 [[L]]
bool fn(bool x) {
return x;
}
37 changes: 29 additions & 8 deletions clang/test/Driver/hip-cuid.hip
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,53 @@
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
// RUN: 2>&1 | FileCheck -check-prefixes=DEVICE %s

// Check cuid is supported by the new driver.
// RUN: %clang -### -x hip \
// RUN: --target=x86_64-unknown-linux-gnu \
// RUN: --no-offload-new-driver \
// RUN: --offload-arch=gfx900 \
// RUN: --offload-arch=gfx906 \
// RUN: -c -nogpuinc -nogpulib --offload-new-driver \
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
// RUN: 2>&1 | FileCheck -check-prefixes=COMMON,HEX %s

// Check cuid is supported by CUDA by the default new driver.
// RUN: %clang -### -x cu \
// RUN: --target=x86_64-unknown-linux-gnu \
// RUN: --offload-arch=sm_60 \
// RUN: --offload-arch=sm_70 \
// RUN: -c -nogpuinc -nogpulib \
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
// RUN: 2>&1 | FileCheck -check-prefixes=COMMON,HEX %s

// INVALID: invalid value 'invalid' in '-fuse-cuid=invalid'

// COMMON: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
// COMMON-SAME: "-target-cpu" "gfx900"
// COMMON: "-cc1"{{.*}} "-triple" "[[TRIP:(amdgcn-amd-amdhsa|nvptx64-nvidia-cuda)]]"
// COMMON-SAME: "-target-cpu" "[[G1:(gfx900|sm_60)]]"
// HEX-SAME: "-cuid=[[CUID:[0-9a-f]+]]"
// FIXED-SAME: "-cuid=[[CUID:xyz_123]]"
// COMMON-SAME: "{{.*}}a.cu"

// COMMON: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
// COMMON-SAME: "-target-cpu" "gfx906"
// COMMON: "-cc1"{{.*}} "-triple" "[[TRIP]]"
// COMMON-SAME: "-target-cpu" "[[G2:(gfx906|sm_70)]]"
// COMMON-SAME: "-cuid=[[CUID]]"
// COMMON-SAME: "{{.*}}a.cu"

// COMMON: "-cc1"{{.*}} "-triple" "x86_64-unknown-linux-gnu"
// COMMON-SAME: "-cuid=[[CUID]]"
// COMMON-SAME: "{{.*}}a.cu"

// COMMON: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
// COMMON-SAME: "-target-cpu" "gfx900"
// COMMON: "-cc1"{{.*}} "-triple" "[[TRIP]]"
// COMMON-SAME: "-target-cpu" "[[G1]]"
// HEX-NOT: "-cuid=[[CUID]]"
// HEX-SAME: "-cuid=[[CUID2:[0-9a-f]+]]"
// FIXED-SAME: "-cuid=[[CUID2:xyz_123]]"
// COMMON-SAME: "{{.*}}b.hip"

// COMMON: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
// COMMON-SAME: "-target-cpu" "gfx906"
// COMMON: "-cc1"{{.*}} "-triple" "[[TRIP]]"
// COMMON-SAME: "-target-cpu" "[[G2]]"
// HEX-NOT: "-cuid=[[CUID]]"
// COMMON-SAME: "-cuid=[[CUID2]]"
// COMMON-SAME: "{{.*}}b.hip"
Expand Down
Loading