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 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 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 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 return RTLCI.LibcallImplCallingConvs[Call];
65 }
66
67 /// Return a function impl compatible with RTLIB::MEMCPY, or
68 /// RTLIB::Unsupported if fully unsupported.
69 RTLIB::LibcallImpl getMemcpyImpl() const {
70 RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
71 if (Memcpy == RTLIB::Unsupported) {
72 // Fallback to memmove if memcpy isn't available.
73 return getLibcallImpl(RTLIB::MEMMOVE);
74 }
75
76 return Memcpy;
77 }
78};
79
80/// Record a mapping from subtarget to LibcallLoweringInfo.
82private:
83 using LibcallLoweringMap =
85 mutable LibcallLoweringMap LoweringMap;
86 const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;
87
88public:
92
93 void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }
94
95 void clear() {
96 RTLCI = nullptr;
97 LoweringMap.clear();
98 }
99
100 operator bool() const { return RTLCI != nullptr; }
101
103 ModuleAnalysisManager::Invalidator &);
104
105 const LibcallLoweringInfo &
106 getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
107 return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
108 }
109};
110
112 : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
113private:
115 LLVM_ABI static AnalysisKey Key;
116
117 LibcallLoweringModuleAnalysisResult LibcallLoweringMap;
118
119public:
121
123};
124
127 RuntimeLibraryInfoWrapper *RuntimeLibcallsWrapper = nullptr;
128
129public:
130 static char ID;
132
133 const LibcallLoweringInfo &
134 getLibcallLowering(const Module &M, const TargetSubtargetInfo &Subtarget) {
135 return getResult(M).getLibcallLowering(Subtarget);
136 }
137
139 if (!Result)
140 Result.init(&RuntimeLibcallsWrapper->getRTLCI(M));
141 return Result;
142 }
143
144 void initializePass() override;
145 void getAnalysisUsage(AnalysisUsage &AU) const override;
146 void releaseMemory() override;
147};
148
149} // end namespace llvm
150
151#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
CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const
Get the CallingConv that should be used for the specified libcall.
LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI, const TargetSubtargetInfo &Subtarget)
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Return the lowering's selection of implementation call for Call.
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl)
Rename the default 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.
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:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
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.
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.
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.