LLVM 23.0.0git
LibcallLoweringInfo.h
Go to the documentation of this file.
1//===- LibcallLoweringInfo.h ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
10#define LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
11
12#include "llvm/ADT/DenseMap.h"
15#include "llvm/Pass.h"
16
17namespace llvm {
20class TargetMachine;
21
22/// Tracks which library functions to use for a particular subtarget.
24private:
25 const RTLIB::RuntimeLibcallsInfo &RTLCI;
26 /// Stores the implementation choice for each each libcall.
27 RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
28 RTLIB::Unsupported};
29
30public:
32 const TargetSubtargetInfo &Subtarget);
33
35 return RTLCI;
36 }
37
38 /// Get the libcall routine name for the specified libcall.
39 // FIXME: This should be removed. Only LibcallImpl should have a name.
40 LLVM_ABI const char *getLibcallName(RTLIB::Libcall Call) const {
41 // FIXME: Return StringRef
43 .data();
44 }
45
46 /// Return the lowering's selection of implementation call for \p Call
47 LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
48 return LibcallImpls[Call];
49 }
50
51 /// Rename the default libcall routine name for the specified libcall.
52 LLVM_ABI void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
53 LibcallImpls[Call] = Impl;
54 }
55
56 // FIXME: Remove this wrapper in favor of directly using
57 // getLibcallImplCallingConv
59 return RTLCI.LibcallImplCallingConvs[LibcallImpls[Call]];
60 }
61
62 /// Get the CallingConv that should be used for the specified libcall.
64 getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const {
65 return RTLCI.LibcallImplCallingConvs[Call];
66 }
67
68 /// Return a function impl compatible with RTLIB::MEMCPY, or
69 /// RTLIB::Unsupported if fully unsupported.
70 RTLIB::LibcallImpl getMemcpyImpl() const {
71 RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
72 if (Memcpy == RTLIB::Unsupported) {
73 // Fallback to memmove if memcpy isn't available.
74 return getLibcallImpl(RTLIB::MEMMOVE);
75 }
76
77 return Memcpy;
78 }
79};
80
81/// Record a mapping from subtarget to LibcallLoweringInfo.
83private:
84 using LibcallLoweringMap =
86 mutable LibcallLoweringMap LoweringMap;
87 const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;
88
89public:
93
94 void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }
95
96 void clear() {
97 RTLCI = nullptr;
98 LoweringMap.clear();
99 }
100
101 operator bool() const { return RTLCI != nullptr; }
102
104 ModuleAnalysisManager::Invalidator &);
105
106 const LibcallLoweringInfo &
107 getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
108 return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
109 }
110};
111
113 : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
114private:
116 LLVM_ABI static AnalysisKey Key;
117
118 LibcallLoweringModuleAnalysisResult LibcallLoweringMap;
119
120public:
122
124};
125
128 RuntimeLibraryInfoWrapper *RuntimeLibcallsWrapper = nullptr;
129
130public:
131 static char ID;
133
134 const LibcallLoweringInfo &
135 getLibcallLowering(const Module &M, const TargetSubtargetInfo &Subtarget) {
136 return getResult(M).getLibcallLowering(Subtarget);
137 }
138
140 if (!Result)
141 Result.init(&RuntimeLibcallsWrapper->getRTLCI(M));
142 return Result;
143 }
144
145 void initializePass() override;
146 void getAnalysisUsage(AnalysisUsage &AU) const override;
147 void releaseMemory() override;
148};
149
150} // end namespace llvm
151
152#endif // LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
Represent the analysis usage information of a pass.
ImmutablePass(char &pid)
Definition Pass.h:287
const LibcallLoweringModuleAnalysisResult & getResult(const Module &M)
const LibcallLoweringInfo & getLibcallLowering(const Module &M, const TargetSubtargetInfo &Subtarget)
Tracks which library functions to use for a particular subtarget.
const RTLIB::RuntimeLibcallsInfo & getRuntimeLibcallsInfo() const
LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI, const TargetSubtargetInfo &Subtarget)
LLVM_ABI void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl)
Rename the default libcall routine name for the specified libcall.
LLVM_ABI CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const
Get the CallingConv that should be used for the specified libcall.
LLVM_ABI const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
RTLIB::LibcallImpl getMemcpyImpl() const
Return a function impl compatible with RTLIB::MEMCPY, or RTLIB::Unsupported if fully unsupported.
LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Return the lowering's selection of implementation call for Call.
LLVM_ABI CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const
Record a mapping from subtarget to LibcallLoweringInfo.
void init(const RTLIB::RuntimeLibcallsInfo *RT)
const LibcallLoweringInfo & getLibcallLowering(const TargetSubtargetInfo &Subtarget) const
LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI)
LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
LibcallLoweringModuleAnalysisResult Result
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:140
Primary interface to the complete machine description for the target machine.
TargetSubtargetInfo - Generic base class for all target subtargets.
CallInst * Call
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A simple container for information about the supported runtime calls.
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl)
Get the libcall routine name for the specified libcall implementation.