Skip to content
Open
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
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/RuntimeLibcallInfo.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/BitcodeReader.h"
Expand Down Expand Up @@ -655,6 +656,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
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));

// Normal mode, emit a .s or .o file by running the code generator. Note,
// this also adds codegenerator level optimization passes.
CodeGenFileType CGFT = getCodeGenFileType(Action);
Expand Down
24 changes: 19 additions & 5 deletions llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ class LLVM_ABI RuntimeLibraryAnalysis
RuntimeLibraryAnalysis() = default;
RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl)
: LibcallsInfo(std::move(BaselineInfoImpl)) {}
explicit RuntimeLibraryAnalysis(const Triple &T) : LibcallsInfo(T) {}
RuntimeLibraryAnalysis(
const Triple &TT,
ExceptionHandling ExceptionModel = ExceptionHandling::None,
FloatABI::ABIType FloatABI = FloatABI::Default,
EABI EABIVersion = EABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);

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

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

private:
friend AnalysisInfoMixin<RuntimeLibraryAnalysis>;
LLVM_ABI static AnalysisKey Key;
Expand All @@ -41,12 +48,19 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
public:
static char ID;
RuntimeLibraryInfoWrapper();
explicit RuntimeLibraryInfoWrapper(const Triple &T);
explicit RuntimeLibraryInfoWrapper(const RTLIB::RuntimeLibcallsInfo &RTLCI);
RuntimeLibraryInfoWrapper(
const Triple &TT,
ExceptionHandling ExceptionModel = ExceptionHandling::None,
FloatABI::ABIType FloatABI = FloatABI::Default,
EABI EABIVersion = EABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);

const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
ModuleAnalysisManager DummyMAM;
RTLCI = RTLA.run(M, DummyMAM);
if (!RTLCI) {
ModuleAnalysisManager DummyMAM;
RTLCI = RTLA.run(M, DummyMAM);
}

return *RTLCI;
}

Expand Down
11 changes: 6 additions & 5 deletions llvm/include/llvm/CodeGen/GlobalISel/Legalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LegalizerInfo;
class MachineIRBuilder;
class MachineInstr;
class GISelChangeObserver;
class LibcallLoweringInfo;
class LostDebugLocObserver;

class LLVM_ABI Legalizer : public MachineFunctionPass {
Expand Down Expand Up @@ -70,11 +71,11 @@ class LLVM_ABI Legalizer : public MachineFunctionPass {

bool runOnMachineFunction(MachineFunction &MF) override;

static MFResult
legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
ArrayRef<GISelChangeObserver *> AuxObservers,
LostDebugLocObserver &LocObserver,
MachineIRBuilder &MIRBuilder, GISelValueTracking *VT);
static MFResult legalizeMachineFunction(
MachineFunction &MF, const LegalizerInfo &LI,
ArrayRef<GISelChangeObserver *> AuxObservers,
LostDebugLocObserver &LocObserver, MachineIRBuilder &MIRBuilder,
const LibcallLoweringInfo *Libcalls, GISelValueTracking *VT);
};
} // End namespace llvm.

Expand Down
73 changes: 43 additions & 30 deletions llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class LegalizerHelper {
MachineRegisterInfo &MRI;
const LegalizerInfo &LI;
const TargetLowering &TLI;
GISelValueTracking *VT;

// FIXME: Should probably make Libcalls mandatory
const LibcallLoweringInfo *Libcalls = nullptr;
GISelValueTracking *VT = nullptr;

public:
enum LegalizeResult {
Expand All @@ -78,12 +81,15 @@ class LegalizerHelper {
/// Expose LegalizerInfo so the clients can re-use.
const LegalizerInfo &getLegalizerInfo() const { return LI; }
const TargetLowering &getTargetLowering() const { return TLI; }
const LibcallLoweringInfo *getLibcallLoweringInfo() { return Libcalls; }
GISelValueTracking *getValueTracking() const { return VT; }

LLVM_ABI LegalizerHelper(MachineFunction &MF, GISelChangeObserver &Observer,
MachineIRBuilder &B);
MachineIRBuilder &B,
const LibcallLoweringInfo *Libcalls = nullptr);
LLVM_ABI LegalizerHelper(MachineFunction &MF, const LegalizerInfo &LI,
GISelChangeObserver &Observer, MachineIRBuilder &B,
const LibcallLoweringInfo *Libcalls = nullptr,
GISelValueTracking *VT = nullptr);

/// Replace \p MI by a sequence of legal instructions that can implement the
Expand Down Expand Up @@ -178,6 +184,37 @@ class LegalizerHelper {
/// def by inserting a G_BITCAST from \p CastTy
LLVM_ABI void bitcastDst(MachineInstr &MI, LLT CastTy, unsigned OpIdx);

// Useful for libcalls where all operands have the same type.
LLVM_ABI LegalizeResult
simpleLibcall(MachineInstr &MI, MachineIRBuilder &MIRBuilder, unsigned Size,
Type *OpType, LostDebugLocObserver &LocObserver) const;

LLVM_ABI LegalizeResult conversionLibcall(MachineInstr &MI, Type *ToType,
Type *FromType,
LostDebugLocObserver &LocObserver,
bool IsSigned = false) const;

/// Helper function that creates a libcall to the given \p Name using the
/// given calling convention \p CC.
LLVM_ABI LegalizeResult createLibcall(const char *Name,
const CallLowering::ArgInfo &Result,
ArrayRef<CallLowering::ArgInfo> Args,
CallingConv::ID CC,
LostDebugLocObserver &LocObserver,
MachineInstr *MI = nullptr) const;

/// Helper function that creates the given libcall.
LLVM_ABI LegalizeResult createLibcall(RTLIB::Libcall Libcall,
const CallLowering::ArgInfo &Result,
ArrayRef<CallLowering::ArgInfo> Args,
LostDebugLocObserver &LocObserver,
MachineInstr *MI = nullptr) const;

/// Create a libcall to memcpy et al.
LLVM_ABI LegalizeResult
createMemLibcall(MachineRegisterInfo &MRI, MachineInstr &MI,
LostDebugLocObserver &LocObserver) const;

private:
LegalizeResult
widenScalarMergeValues(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
Expand Down Expand Up @@ -278,17 +315,13 @@ class LegalizerHelper {
bool IsVolatile);

// Implements floating-point environment read/write via library function call.
LegalizeResult createGetStateLibcall(MachineIRBuilder &MIRBuilder,
MachineInstr &MI,
LegalizeResult createGetStateLibcall(MachineInstr &MI,
LostDebugLocObserver &LocObserver);
LegalizeResult createSetStateLibcall(MachineIRBuilder &MIRBuilder,
MachineInstr &MI,
LegalizeResult createSetStateLibcall(MachineInstr &MI,
LostDebugLocObserver &LocObserver);
LegalizeResult createResetStateLibcall(MachineIRBuilder &MIRBuilder,
MachineInstr &MI,
LegalizeResult createResetStateLibcall(MachineInstr &MI,
LostDebugLocObserver &LocObserver);
LegalizeResult createFCMPLibcall(MachineIRBuilder &MIRBuilder,
MachineInstr &MI,
LegalizeResult createFCMPLibcall(MachineInstr &MI,
LostDebugLocObserver &LocObserver);

MachineInstrBuilder
Expand Down Expand Up @@ -539,26 +572,6 @@ class LegalizerHelper {
LLVM_ABI LegalizeResult lowerVAArg(MachineInstr &MI);
};

/// Helper function that creates a libcall to the given \p Name using the given
/// calling convention \p CC.
LLVM_ABI LegalizerHelper::LegalizeResult
createLibcall(MachineIRBuilder &MIRBuilder, const char *Name,
const CallLowering::ArgInfo &Result,
ArrayRef<CallLowering::ArgInfo> Args, CallingConv::ID CC,
LostDebugLocObserver &LocObserver, MachineInstr *MI = nullptr);

/// Helper function that creates the given libcall.
LLVM_ABI LegalizerHelper::LegalizeResult
createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall,
const CallLowering::ArgInfo &Result,
ArrayRef<CallLowering::ArgInfo> Args,
LostDebugLocObserver &LocObserver, MachineInstr *MI = nullptr);

/// Create a libcall to memcpy et al.
LLVM_ABI LegalizerHelper::LegalizeResult
createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
MachineInstr &MI, LostDebugLocObserver &LocObserver);

} // End namespace llvm.

#endif
76 changes: 75 additions & 1 deletion llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
#ifndef LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
#define LLVM_CODEGEN_LIBCALLLOWERINGINFO_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/RuntimeLibcallInfo.h"
#include "llvm/IR/RuntimeLibcalls.h"
#include "llvm/Pass.h"

namespace llvm {

class RuntimeLibraryInfoWrapper;
class TargetSubtargetInfo;
class TargetMachine;

/// Tracks which library functions to use for a particular subtarget.
class LibcallLoweringInfo {
private:
const RTLIB::RuntimeLibcallsInfo &RTLCI;
Expand Down Expand Up @@ -73,6 +78,75 @@ class LibcallLoweringInfo {
}
};

/// Record a mapping from subtarget to LibcallLoweringInfo.
class LibcallLoweringModuleAnalysisResult {
private:
using LibcallLoweringMap =
DenseMap<const TargetSubtargetInfo *, LibcallLoweringInfo>;
mutable LibcallLoweringMap LoweringMap;
const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;

public:
LibcallLoweringModuleAnalysisResult() = default;
LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI)
: RTLCI(&RTLCI) {}

void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }

void clear() {
RTLCI = nullptr;
LoweringMap.clear();
}

operator bool() const { return RTLCI != nullptr; }

LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &,
ModuleAnalysisManager::Invalidator &);

const LibcallLoweringInfo &
getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
}
};

class LibcallLoweringModuleAnalysis
: public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
private:
friend AnalysisInfoMixin<LibcallLoweringModuleAnalysis>;
static AnalysisKey Key;

LibcallLoweringModuleAnalysisResult LibcallLoweringMap;

public:
using Result = LibcallLoweringModuleAnalysisResult;

LLVM_ABI Result run(Module &M, ModuleAnalysisManager &);
};

class LLVM_ABI LibcallLoweringInfoWrapper : public ImmutablePass {
LibcallLoweringModuleAnalysisResult Result;
RuntimeLibraryInfoWrapper *RuntimeLibcallsWrapper = nullptr;

public:
static char ID;
LibcallLoweringInfoWrapper();

const LibcallLoweringInfo &
getLibcallLowering(const Module &M, const TargetSubtargetInfo &Subtarget) {
return getResult(M).getLibcallLowering(Subtarget);
}

const LibcallLoweringModuleAnalysisResult &getResult(const Module &M) {
if (!Result)
Result.init(&RuntimeLibcallsWrapper->getRTLCI(M));
return Result;
}

void initializePass() override;
void getAnalysisUsage(AnalysisUsage &AU) const override;
void releaseMemory() override;
};

} // end namespace llvm

#endif // LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ LLVM_ABI FunctionPass *createInterleavedLoadCombinePass();
///
LLVM_ABI ModulePass *createLowerEmuTLSPass();

LLVM_ABI ModulePass *createLibcallLoweringInfoWrapper();

/// This pass lowers the \@llvm.load.relative and \@llvm.objc.* intrinsics to
/// instructions. This is unsafe to do earlier because a pass may combine the
/// constant initializer into the load, which may result in an overflowing
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ LLVM_ABI void initializeGlobalMergeFuncPassWrapperPass(PassRegistry &);
LLVM_ABI void initializeGlobalMergePass(PassRegistry &);
LLVM_ABI void initializeGlobalsAAWrapperPassPass(PassRegistry &);
LLVM_ABI void initializeHardwareLoopsLegacyPass(PassRegistry &);
LLVM_ABI void initializeLibcallLoweringInfoWrapperPass(PassRegistry &);
LLVM_ABI void initializeMIRProfileLoaderPassPass(PassRegistry &);
LLVM_ABI void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &);
LLVM_ABI void initializeIRTranslatorPass(PassRegistry &);
Expand Down
16 changes: 16 additions & 0 deletions llvm/lib/Analysis/RuntimeLibcallInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ 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)
Expand All @@ -26,6 +35,13 @@ INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
: ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}

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

char RuntimeLibraryInfoWrapper::ID = 0;

ModulePass *llvm::createRuntimeLibraryInfoWrapperPass() {
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeInterleavedLoadCombinePass(Registry);
initializeInterleavedAccessPass(Registry);
initializeJMCInstrumenterPass(Registry);
initializeLibcallLoweringInfoWrapperPass(Registry);
initializeLiveDebugValuesLegacyPass(Registry);
initializeLiveDebugVariablesWrapperLegacyPass(Registry);
initializeLiveIntervalsWrapperPassPass(Registry);
Expand Down
Loading
Loading