Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 3 additions & 14 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
break;
}

// Set float ABI type.
assert((CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp" ||
CodeGenOpts.FloatABI == "hard" || CodeGenOpts.FloatABI.empty()) &&
"Invalid Floating Point ABI!");
Options.FloatABIType =
llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.FloatABI)
.Case("soft", llvm::FloatABI::Soft)
.Case("softfp", llvm::FloatABI::Soft)
.Case("hard", llvm::FloatABI::Hard)
.Default(llvm::FloatABI::Default);

// Set FP fusion mode.
switch (LangOpts.getDefaultFPContractMode()) {
case LangOptions::FPM_Off:
Expand Down Expand Up @@ -1281,9 +1270,9 @@ void EmitAssemblyHelper::RunCodegenPipelineLegacy(
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));

const llvm::TargetOptions &Options = TM->Options;
CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
TargetTriple, Options.ExceptionModel, Options.FloatABIType,
Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
CodeGenPasses.add(
new RuntimeLibraryInfoWrapper(Options.ExceptionModel, Options.EABIVersion,
Options.MCOptions.ABIName, Options.VecLib));

if (TM->addPassesToEmitFile(CodeGenPasses, *OS,
DwoOS ? &DwoOS->os() : nullptr, CGFT,
Expand Down
8 changes: 4 additions & 4 deletions flang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ static void generateMachineCodeOrAssemblyImpl(
llvm::driver::createTLII(triple, codeGenOpts.getVecLib());
codeGenPasses.add(new llvm::TargetLibraryInfoWrapperPass(*tlii));
codeGenPasses.add(new llvm::RuntimeLibraryInfoWrapper(
triple, tm.Options.ExceptionModel, tm.Options.FloatABIType,
tm.Options.EABIVersion, tm.Options.MCOptions.ABIName, tm.Options.VecLib));
tm.Options.ExceptionModel, tm.Options.EABIVersion,
tm.Options.MCOptions.ABIName, tm.Options.VecLib));

std::unique_ptr<llvm::ToolOutputFile> dwoOS;
if (!codeGenOpts.SplitDwarfOutput.empty()) {
Expand Down Expand Up @@ -1040,8 +1040,8 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
fam.registerPass([&] { return llvm::TargetLibraryAnalysis(*tlii); });
mam.registerPass([&] {
return llvm::RuntimeLibraryAnalysis(
triple, targetMachine->Options.ExceptionModel,
targetMachine->Options.FloatABIType, targetMachine->Options.EABIVersion,
targetMachine->Options.ExceptionModel,
targetMachine->Options.EABIVersion,
targetMachine->Options.MCOptions.ABIName,
targetMachine->Options.VecLib);
});
Expand Down
3 changes: 3 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Makes programs 10x faster by doing Special New Thing.

### Changes to LLVM infrastructure

* Removed `TargetOptions::FloatABIType`. The soft float ABI should be
controlled by setting the `"float-abi"` module flag.

### Changes to building LLVM

### Changes to TableGen
Expand Down
36 changes: 19 additions & 17 deletions llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "llvm/IR/RuntimeLibcalls.h"
#include "llvm/Pass.h"
#include <optional>
#include <string>

namespace llvm {

Expand All @@ -20,24 +22,26 @@ class LLVM_ABI RuntimeLibraryAnalysis
using Result = RTLIB::RuntimeLibcallsInfo;

RuntimeLibraryAnalysis() = default;
RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl)
: LibcallsInfo(std::move(BaselineInfoImpl)) {}
RuntimeLibraryAnalysis(
const Triple &TT,
ExceptionHandling ExceptionModel = ExceptionHandling::None,
FloatABI::ABIType FloatABI = FloatABI::Default,
EABI EABIVersion = EABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);
RuntimeLibraryAnalysis(ExceptionHandling ExceptionModel,
EABI EABIVersion = EABI::Default,
StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary)
: ExceptionModel(ExceptionModel), EABIVersion(EABIVersion),
ABIName(ABIName.str()), VecLib(VecLib) {}

RTLIB::RuntimeLibcallsInfo run(const Module &M, ModuleAnalysisManager &);

operator bool() const { return LibcallsInfo.has_value(); }

private:
friend AnalysisInfoMixin<RuntimeLibraryAnalysis>;
static AnalysisKey Key;

std::optional<RTLIB::RuntimeLibcallsInfo> LibcallsInfo;
// FIXME: These are TargetOptions values that are not yet represented in the
// IR, copied here so run() can forward them to the RuntimeLibcallsInfo Module
// constructor. Delete each one as they are migrated to module flags.
ExceptionHandling ExceptionModel = ExceptionHandling::None;
EABI EABIVersion = EABI::Default;
std::string ABIName;
VectorLibrary VecLib = VectorLibrary::NoLibrary;
};

class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
Expand All @@ -47,12 +51,10 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
public:
static char ID;
RuntimeLibraryInfoWrapper();
RuntimeLibraryInfoWrapper(
const Triple &TT,
ExceptionHandling ExceptionModel = ExceptionHandling::None,
FloatABI::ABIType FloatABI = FloatABI::Default,
EABI EABIVersion = EABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);
RuntimeLibraryInfoWrapper(ExceptionHandling ExceptionModel,
EABI EABIVersion = EABI::Default,
StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);

const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
if (!RTLCI) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ class LLVM_ABI Module {
/// @{

/// Returns the floating-point ABI recorded by the "float-abi" module flag, or
/// FloatABI::Default when the flag is absent (meaning the target default).
/// the ABI implied by the target triple when the flag is absent.
FloatABI::ABIType getFloatABI() const;
/// @}

Expand Down
11 changes: 10 additions & 1 deletion llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ struct RuntimeLibcallsInfo {
EABI EABIVersion = EABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);

LLVM_ABI explicit RuntimeLibcallsInfo(const Module &M);
// FIXME: The floating-point ABI is read from the "float-abi" module flag, but
// the ExceptionModel/EABIVersion/ABIName/VecLib parameters are still
// TargetOptions values that are not yet represented in the IR. Delete these
// parameters (and build everything from the Module) once those fields are
// migrated to module flags.
LLVM_ABI explicit RuntimeLibcallsInfo(
const Module &M,
ExceptionHandling ExceptionModel = ExceptionHandling::None,
EABI EABIVersion = EABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);

LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
ModuleAnalysisManager::Invalidator &);
Expand Down
8 changes: 0 additions & 8 deletions llvm/include/llvm/Target/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,6 @@ class TargetOptions {
/// If greater than 0, override TargetLoweringBase::PrefLoopAlignment.
unsigned LoopAlignment = 0;

/// FloatABIType - This setting is set by -float-abi=xxx option is specfied
/// on the command line. This setting may either be Default, Soft, or Hard.
/// Default selects the target's default behavior. Soft selects the ABI for
/// software floating point, but does not indicate that FP hardware may not
/// be used. Such a combination is unfortunately popular (e.g.
/// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
FloatABI::ABIType FloatABIType = FloatABI::Default;

/// AllowFPOpFusion - This flag is set by the -fp-contract=xxx option.
/// This controls the creation of fused FP ops that store intermediate
/// results in higher precision than IEEE allows (E.g. FMAs).
Expand Down
23 changes: 5 additions & 18 deletions llvm/lib/Analysis/RuntimeLibcallInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,21 @@ using namespace llvm;

AnalysisKey RuntimeLibraryAnalysis::Key;

RuntimeLibraryAnalysis::RuntimeLibraryAnalysis(const Triple &TT,
ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI,
EABI EABIVersion,
StringRef ABIName,
VectorLibrary VecLib)
: LibcallsInfo(std::in_place, TT, ExceptionModel, FloatABI, EABIVersion,
ABIName, VecLib) {}

RTLIB::RuntimeLibcallsInfo
RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
if (!LibcallsInfo)
LibcallsInfo = RTLIB::RuntimeLibcallsInfo(M);
return *LibcallsInfo;
return RTLIB::RuntimeLibcallsInfo(M, ExceptionModel, EABIVersion, ABIName,
VecLib);
}

INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
"Runtime Library Function Analysis", false, true)

RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
: ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}
RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper() : ImmutablePass(ID) {}

RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
const Triple &TT, ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName,
ExceptionHandling ExceptionModel, EABI EABIVersion, StringRef ABIName,
VectorLibrary VecLib)
: ImmutablePass(ID), RTLCI(std::in_place, TT, ExceptionModel, FloatABI,
EABIVersion, ABIName, VecLib) {}
: ImmutablePass(ID), RTLA(ExceptionModel, EABIVersion, ABIName, VecLib) {}

char RuntimeLibraryInfoWrapper::ID = 0;

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ addPassesToGenerateCode(CodeGenTargetMachineImpl &TM, PassManagerBase &PM,
const TargetOptions &Options = TM.Options;
TargetLibraryInfoImpl TLII(TM.getTargetTriple(), Options.VecLib);
PM.add(new TargetLibraryInfoWrapperPass(TLII));
PM.add(new RuntimeLibraryInfoWrapper(
TM.getTargetTriple(), Options.ExceptionModel, Options.FloatABIType,
Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
PM.add(
new RuntimeLibraryInfoWrapper(Options.ExceptionModel, Options.EABIVersion,
Options.MCOptions.ABIName, Options.VecLib));

invokeGlobalTargetPassConfigCallbacks(TM, PM, PassConfig);

Expand Down
22 changes: 20 additions & 2 deletions llvm/lib/CodeGen/CommandFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/MC/MCTargetOptionsCommandFlags.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -588,8 +589,6 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {

Options.HonorSignDependentRoundingFPMathOption =
getEnableHonorSignDependentRoundingFPMath();
if (getFloatABIForCalls() != FloatABI::Default)
Options.FloatABIType = getFloatABIForCalls();
Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI();
Options.NoZerosInBSS = getDontPlaceZerosInBSS();
Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
Expand Down Expand Up @@ -774,6 +773,25 @@ void codegen::setFunctionAttributes(Function &F, StringRef CPU,

void codegen::setFunctionAttributes(Module &M, StringRef CPU,
StringRef Features, StringRef TuneCPU) {
// Synthesize the "float-abi" module flag from the -float-abi option.
FloatABI::ABIType ABI = getFloatABIForCalls();
if (ABI != FloatABI::Default) {
if (auto *Existing =
dyn_cast_or_null<MDString>(M.getModuleFlag("float-abi"))) {
// The module already records a float ABI; -float-abi must not contradict
// it.
if (Existing->getString() != FloatABI::getABITypeName(ABI))
reportFatalUsageError(
"-float-abi=" + FloatABI::getABITypeName(ABI) +
" conflicts with the \"float-abi\" module flag \"" +
Existing->getString() + "\"");
} else {
M.addModuleFlag(
Module::Error, "float-abi",
MDString::get(M.getContext(), FloatABI::getABITypeName(ABI)));
}
}

for (Function &F : M)
setFunctionAttributes(F, CPU, Features, TuneCPU);
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,8 @@ TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
const TargetSubtargetInfo &STI)
: TM(tm),
RuntimeLibcallInfo(TM.getTargetTriple(), TM.Options.ExceptionModel,
TM.Options.FloatABIType, TM.Options.EABIVersion,
TM.getTargetTriple().getDefaultFloatABI(),
TM.Options.EABIVersion,
TM.Options.MCOptions.getABIName(), TM.Options.VecLib),
Libcalls(RuntimeLibcallInfo, STI) {
initActions();
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/IR/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,10 @@ void Module::setLongDoubleFormat(LongDoubleFormat Format) {

FloatABI::ABIType Module::getFloatABI() const {
if (auto *Val = dyn_cast_or_null<MDString>(getModuleFlag("float-abi")))
return FloatABI::parseABIType(Val->getString()).value_or(FloatABI::Default);
return FloatABI::Default;
return *FloatABI::parseABIType(Val->getString());
// Without an explicit flag, fall back to the ABI implied by the target
// triple.
return getTargetTriple().getDefaultFloatABI();
}

std::optional<uint64_t> Module::getLargeDataThreshold() const {
Expand Down
13 changes: 7 additions & 6 deletions llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
}
}

RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M) {
// TODO: Consider the remaining module flags.
const Triple &TT = M.getTargetTriple();
initLibcalls(TT, TT.getDefaultExceptionHandling(), FloatABI::Default,
EABI::Default, /*ABIName=*/"", M.getLongDoubleFormat());
}
// TODO: Consider the remaining module flags.
RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M,
ExceptionHandling ExceptionModel,
EABI EABIVersion, StringRef ABIName,
VectorLibrary VecLib)
: RuntimeLibcallsInfo(M.getTargetTriple(), ExceptionModel, M.getFloatABI(),
EABIVersion, ABIName, VecLib) {}

/// Set default libcall names. If a target wants to opt-out of a libcall it
/// should be placed here.
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/LTO/LTOBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
TargetLibraryInfoImpl TLII(Mod.getTargetTriple(), TM->Options.VecLib);
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
Mod.getTargetTriple(), TM->Options.ExceptionModel,
TM->Options.FloatABIType, TM->Options.EABIVersion,
TM->Options.ExceptionModel, TM->Options.EABIVersion,
TM->Options.MCOptions.ABIName, TM->Options.VecLib));

// No need to make index available if the module is empty.
Expand Down
6 changes: 1 addition & 5 deletions llvm/lib/Target/ARM/ARMAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,7 @@ void ARMAsmPrinter::emitAttributes() {
}
const ARMBaseTargetMachine &ATM =
static_cast<const ARMBaseTargetMachine &>(TM);
// The float ABI comes from the "float-abi" module flag if present, otherwise
// from the legacy -float-abi target option.
FloatABI::ABIType FloatABI = MMI->getModule()->getFloatABI();
if (FloatABI == FloatABI::Default)
FloatABI = ATM.Options.FloatABIType;
FloatABI::ABIType FloatABI = ATM.getFloatABI(*MMI->getModule());
const ARMSubtarget STI(TT, std::string(CPU), ArchFS, ATM,
ATM.isLittleEndian(), FloatABI);

Expand Down
35 changes: 15 additions & 20 deletions llvm/lib/Target/ARM/ARMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@ ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT,
TargetABI(ARM::computeTargetABI(TT, Options.MCOptions.ABIName)),
TLOF(createTLOF(getTargetTriple())), isLittle(TT.isLittleEndian()) {

// Default to triple-appropriate float ABI. -target-abi=aapcs16 forces hard
// float regardless of the triple default.
if (Options.FloatABIType == FloatABI::Default) {
if (TargetABI == ARM::ARM_ABI_AAPCS16 ||
TT.getDefaultFloatABI() == FloatABI::Hard)
this->Options.FloatABIType = FloatABI::Hard;
else
this->Options.FloatABIType = FloatABI::Soft;
}

// Default to triple-appropriate EABI
if (Options.EABIVersion == EABI::Default ||
Options.EABIVersion == EABI::Unknown) {
Expand Down Expand Up @@ -207,6 +197,20 @@ MachineFunctionInfo *ARMBaseTargetMachine::createMachineFunctionInfo(
Allocator, F, static_cast<const ARMSubtarget *>(STI));
}

FloatABI::ABIType ARMBaseTargetMachine::getFloatABI(const Module &M) const {
// An explicit "float-abi" module flag always wins, even for AAPCS16.
if (auto *Val = dyn_cast_or_null<MDString>(M.getModuleFlag("float-abi")))
return *FloatABI::parseABIType(Val->getString());

// With no explicit ABI, an explicit -target-abi=aapcs16 forces hard float
// even on triples whose default float ABI is soft (the triple default only
// detects AAPCS16 when it is the triple's own default ABI).
if (TargetABI == ARM::ARM_ABI_AAPCS16)
return FloatABI::Hard;
// Otherwise fall back to the ABI implied by the target triple.
return M.getTargetTriple().getDefaultFloatABI();
}

const ARMSubtarget *
ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
Attribute CPUAttr = F.getFnAttribute("target-cpu");
Expand Down Expand Up @@ -238,16 +242,7 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
if (DM != DenormalMode::getIEEE())
Key += "denormal-fp-math=" + DM.str();

// The float ABI comes from the "float-abi" module flag if present, otherwise
// from the legacy -float-abi target option (which the constructor seeded from
// the target triple).
FloatABI::ABIType FloatABI = F.getParent()->getFloatABI();
if (FloatABI == FloatABI::Default) {
FloatABI = Options.FloatABIType;
assert(FloatABI != FloatABI::Default &&
"expected TargetMachine constructor to overwrite default float abi");
}

FloatABI::ABIType FloatABI = getFloatABI(*F.getParent());
// It is legal to have FloatABI::Hard with +soft-float for targets with SIMD
// registers, but no floating-point hardware (mve+nofp)
Key += FloatABI == FloatABI::Hard ? "+hard-float-abi" : "+soft-float-abi";
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/ARM/ARMTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class ARMBaseTargetMachine : public CodeGenTargetMachineImpl {
const ARMSubtarget *getSubtargetImpl() const = delete;
bool isLittleEndian() const { return isLittle; }

/// Returns the floating-point ABI in effect for \p M: the "float-abi" module
/// flag if present, otherwise the ABI implied by the target triple. An
/// explicit -target-abi=aapcs16 forces the hard-float ABI.
FloatABI::ABIType getFloatABI(const Module &M) const;

TargetTransformInfo getTargetTransformInfo(const Function &F) const override;

// Pass Pipeline Configuration
Expand Down
Loading
Loading