Skip to content

Commit

Permalink
Revert D157750 "[Driver][CodeGen] Properly handle -fsplit-machine-fun…
Browse files Browse the repository at this point in the history
…ctions for fatbinary compilation."

This reverts commit 317a0fe.
This reverts commit 30c4b97.

See post-commit discussions on https://reviews.llvm.org/D157750 that
we should use a different mechanism to handle the error with --cuda-gpu-arch=

The IR/DiagnosticInfo.cpp, warn_drv_for_elf_only, codegne tests in
clang/test/Driver, and the following driver behavior (downgrading error
to warning) changes are undesired.
```
% clang --target=riscv64 -fsplit-machine-functions -c a.c
warning: -fsplit-machine-functions is not valid for riscv64 [-Wbackend-plugin]
```
  • Loading branch information
MaskRay committed Aug 21, 2023
1 parent 446abb5 commit 77596e6
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 141 deletions.
4 changes: 0 additions & 4 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,6 @@ def warn_drv_fjmc_for_elf_only : Warning<
"-fjmc works only for ELF; option ignored">,
InGroup<OptionIgnored>;

def warn_drv_for_elf_only : Warning<
"'%0' works only for ELF; option ignored">,
InGroup<OptionIgnored>;

def warn_target_override_arm64ec : Warning<
"/arm64EC has been overridden by specified target: %0; option ignored">,
InGroup<OptionIgnored>;
Expand Down
13 changes: 6 additions & 7 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5872,15 +5872,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,

if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
options::OPT_fno_split_machine_functions)) {
if (A->getOption().matches(options::OPT_fsplit_machine_functions)) {
// This codegen pass is only available on elf targets.
if (Triple.isOSBinFormatELF())
// This codegen pass is only available on x86-elf targets.
if (Triple.isX86() && Triple.isOSBinFormatELF()) {
if (A->getOption().matches(options::OPT_fsplit_machine_functions))
A->render(Args, CmdArgs);
else
D.Diag(diag::warn_drv_for_elf_only) << A->getAsString(Args);
} else {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << TripleStr;
}
// Do not issue warnings for -fno-split-machine-functions even it is not
// on ELF.
}

Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
Expand Down
68 changes: 0 additions & 68 deletions clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c

This file was deleted.

10 changes: 5 additions & 5 deletions clang/test/Driver/fsplit-machine-functions.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// REQUIRES: arm-registered-target

// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
// RUN: %clang -c -target arm-unknown-linux-gnueabi -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
// RUN: not %clang -c -target arm-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s

// CHECK-OPT: "-fsplit-machine-functions"
// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
// CHECK-TRIPLE: warning: -fsplit-machine-functions is not valid for arm
// CHECK-TRIPLE: error: unsupported option '-fsplit-machine-functions' for target
11 changes: 4 additions & 7 deletions clang/test/Driver/fsplit-machine-functions2.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// Test -fsplit-machine-functions option pass-through with lto
// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS

// Test no pass-through to ld without lto
// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS

// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s -o %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
// RUN: %clang -### -target x86_64-unknown-linux -flto -fno-split-machine-functions -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
// Check that for non-X86, passing no-split-machine-functions does not cause error.
// RUN: %clang -### -target aarch64-unknown-linux-gnu -flto -fsplit-machine-functions -fno-split-machine-functions %s -o %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS2
// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
// RUN: %clang -### -target x86_64-unknown-linux -flto -fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS

// CHECK-PASS: "-plugin-opt=-split-machine-functions"
// CHECK-NOPASS-NOT: "-plugin-opt=-split-machine-functions"
// CHECK-NOPASS2-NOT: "-plugin-opt=-split-machine-functions"
15 changes: 0 additions & 15 deletions llvm/include/llvm/IR/DiagnosticInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ enum DiagnosticKind {
DK_SrcMgr,
DK_DontCall,
DK_MisExpect,
DK_MachineFunctionSplit,
DK_FirstPluginKind // Must be last value to work with
// getNextAvailablePluginDiagnosticKind
};
Expand Down Expand Up @@ -1118,20 +1117,6 @@ class DiagnosticInfoDontCall : public DiagnosticInfo {
}
};

class DiagnosticInfoMachineFunctionSplit : public DiagnosticInfo {
StringRef TargetTriple;

public:
DiagnosticInfoMachineFunctionSplit(StringRef TargetTriple,
DiagnosticSeverity DS)
: DiagnosticInfo(DK_MachineFunctionSplit, DS),
TargetTriple(TargetTriple) {}
void print(DiagnosticPrinter &DP) const override;
static bool classof(const DiagnosticInfo *DI) {
return DI->getKind() == DK_MachineFunctionSplit;
}
};

} // end namespace llvm

#endif // LLVM_IR_DIAGNOSTICINFO_H
22 changes: 0 additions & 22 deletions llvm/lib/CodeGen/MachineFunctionSplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/TargetParser/Triple.h"
#include <optional>

using namespace llvm;
Expand Down Expand Up @@ -84,13 +82,6 @@ class MachineFunctionSplitter : public MachineFunctionPass {
void getAnalysisUsage(AnalysisUsage &AU) const override;

bool runOnMachineFunction(MachineFunction &F) override;

bool doInitialization(Module &) override;

static bool isSupportedTriple(const Triple &T) { return T.isX86(); }

private:
bool UnsupportedTriple = false;
};
} // end anonymous namespace

Expand Down Expand Up @@ -136,20 +127,7 @@ static bool isColdBlock(const MachineBasicBlock &MBB,
return (*Count < ColdCountThreshold);
}

bool MachineFunctionSplitter::doInitialization(Module &M) {
StringRef T = M.getTargetTriple();
if (!isSupportedTriple(Triple(T))) {
UnsupportedTriple = true;
M.getContext().diagnose(
DiagnosticInfoMachineFunctionSplit(T, DS_Warning));
return false;
}
return MachineFunctionPass::doInitialization(M);
}

bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) {
if (UnsupportedTriple)
return false;
// We target functions with profile data. Static information in the form
// of exception handling code may be split to cold if user passes the
// mfs-split-ehcode flag.
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/IR/DiagnosticInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,3 @@ void DiagnosticInfoDontCall::print(DiagnosticPrinter &DP) const {
if (!getNote().empty())
DP << ": " << getNote();
}

void DiagnosticInfoMachineFunctionSplit::print(DiagnosticPrinter &DP) const {
DP << "-fsplit-machine-functions is not valid for " << TargetTriple;
}
Binary file removed llvm/test/CodeGen/Generic/Inputs/fsloader-mfs.afdo
Binary file not shown.
9 changes: 0 additions & 9 deletions llvm/test/CodeGen/Generic/machine-function-splitter.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
; RUN: sed 's/InstrProf/SampleProfile/g' %s > %t.ll
; RUN: llc < %t.ll -mtriple=x86_64-unknown-linux-gnu -split-machine-functions | FileCheck %s --check-prefix=FSAFDO-MFS
; RUN: llc < %t.ll -mtriple=x86_64-unknown-linux-gnu -split-machine-functions | FileCheck %s --check-prefix=FSAFDO-MFS2
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -debug-pass=Structure -fs-profile-file=%S/Inputs/fsloader-mfs.afdo -enable-fs-discriminator=true -improved-fs-discriminator=true -split-machine-functions 2>&1 | FileCheck %s --check-prefix=MFS_ON
; RUN: llc < %s -mtriple=aarch64-unknown-linux-gnu -debug-pass=Structure -fs-profile-file=%S/Inputs/fsloader-mfs.afdo -enable-fs-discriminator=true -improved-fs-discriminator=true -split-machine-functions 2>&1 | FileCheck %s --check-prefix=MFS_OFF

;; Check that MFS is on for X86 targets.
; MFS_ON: Machine Function Splitter Transformation
; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
;; Check that MFS is not on for non-X86 targets.
; MFS_OFF: warning: -fsplit-machine-functions is not valid for
; MFS_OFF_NO: Machine Function Splitter Transformation

define void @foo1(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
;; Check that cold block is moved to .text.split.
Expand Down

0 comments on commit 77596e6

Please sign in to comment.