LLVM 22.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"
14#include "llvm/Pass.h"
15
16namespace llvm {
17
19class TargetMachine;
20
21/// Tracks which library functions to use for a particular subtarget.
23private:
24 const RTLIB::RuntimeLibcallsInfo &RTLCI;
25 /// Stores the implementation choice for each each libcall.
26 RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
27 RTLIB::Unsupported};
28
29public:
31 const TargetSubtargetInfo &Subtarget);
32
34 return RTLCI;
35 }
36
37 /// Get the libcall routine name for the specified libcall.
38 // FIXME: This should be removed. Only LibcallImpl should have a name.
39 LLVM_ABI const char *getLibcallName(RTLIB::Libcall Call) const {
40 // FIXME: Return StringRef
42 .data();
43 }
44
45 /// Return the lowering's selection of implementation call for \p Call
46 LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
47 return LibcallImpls[Call];
48 }
49
50 /// Rename the default libcall routine name for the specified libcall.
51 LLVM_ABI void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
52 LibcallImpls[Call] = Impl;
53 }
54
55 // FIXME: Remove this wrapper in favor of directly using
56 // getLibcallImplCallingConv
58 return RTLCI.LibcallImplCallingConvs[LibcallImpls[Call]];
59 }
60
61 /// Get the CallingConv that should be used for the specified libcall.
63 getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const {
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
101 ModuleAnalysisManager::Invalidator &);
102
103 const LibcallLoweringInfo &
104 getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
105 return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
106 }
107};
108
110 : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
111private:
113 static AnalysisKey Key;
114
115 LibcallLoweringModuleAnalysisResult LibcallLoweringMap;
116
117public:
119
121};
122
125
126public:
127 static char ID;
129
130 const LibcallLoweringInfo &
131 getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
132 return Result.getLibcallLowering(Subtarget);
133 }
134
136 return Result;
137 }
138
139 bool doInitialization(Module &M) override;
140 void getAnalysisUsage(AnalysisUsage &AU) const override;
141 void releaseMemory() override;
142};
143
144} // end namespace llvm
145
146#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 LibcallLoweringInfo & getLibcallLowering(const TargetSubtargetInfo &Subtarget) const
const LibcallLoweringModuleAnalysisResult & getResult() const
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.
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:92
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.