30#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN, \
31 FAST_VECTOR_UNALIGN, MVENDORID, MARCHID, MIMPID) \
33#define TUNE_PROC(ENUM, NAME) CK_##ENUM,
34#include "llvm/TargetParser/RISCVTargetParserDef.inc"
38#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN, \
39 FAST_VECTOR_UNALIGN, MVENDORID, MARCHID, MIMPID) \
43 FAST_SCALAR_UNALIGN, \
44 FAST_VECTOR_UNALIGN, \
45 {MVENDORID, MARCHID, MIMPID}, \
47#include "llvm/TargetParser/RISCVTargetParserDef.inc"
59 return Info && Info->FastScalarUnalignedAccess;
64 return Info && Info->FastVectorUnalignedAccess;
91 return Info->is64Bit() == IsRV64;
95 std::optional<CPUKind> Kind =
98 #include "llvm/TargetParser/RISCVTargetParserDef.inc"
101 if (Kind.has_value())
112 return Info->DefaultMarch;
117 if (IsRV64 ==
C.is64Bit())
127 if (IsRV64 ==
C.is64Bit())
130#define TUNE_PROC(ENUM, NAME) Values.emplace_back(StringRef(NAME));
131#include "llvm/TargetParser/RISCVTargetParserDef.inc"
142 if (MarchFromCPU ==
"")
145 EnabledFeatures.
clear();
152 std::vector<std::string> FeatStrings =
153 (*RII)->toFeatures(
false);
154 for (
const auto &
F : FeatStrings)
162class RISCVTuneFeatureLookupTable {
163 struct RISCVTuneFeature {
169 struct RISCVImpliedTuneFeature {
171 unsigned ImpliedFeatureIdx;
174 struct RISCVConfigurableTuneFeatures {
176 unsigned DirectiveIdx;
178 bool operator<(
const RISCVConfigurableTuneFeatures &
RHS)
const {
179 return Processor <
RHS.Processor;
183#define GET_TUNE_FEATURES
184#define GET_CONFIGURABLE_TUNE_FEATURES
185#include "llvm/TargetParser/RISCVTargetParserDef.inc"
188 StringMap<StringRef> PositiveMap;
190 StringMap<StringRef> NegativeMap;
192 StringMap<SmallVector<StringRef>> ImpliedFeatureMap;
193 StringMap<SmallVector<StringRef>> InvImpliedFeatureMap;
196 using SmallStringSet = SmallSet<StringRef, 4>;
199 for (
const auto &TuneFeature : TuneFeatures)
200 Features.push_back(TuneFeatureStrings[TuneFeature.FeatureIdx]);
203 static void getConfigurableFeatures(StringRef ProcName,
204 SmallStringSet &Directives) {
206 auto [ItFirst, ItEnd] =
207 std::equal_range(std::begin(ConfigurableTuneFeatures),
208 std::end(ConfigurableTuneFeatures),
209 RISCVConfigurableTuneFeatures{ProcName, 0});
210 for (; ItFirst != ItEnd; ++ItFirst)
211 Directives.insert(TuneFeatureStrings[ItFirst->DirectiveIdx]);
214 RISCVTuneFeatureLookupTable() {
215 for (
const auto &TuneFeature : TuneFeatures) {
216 StringRef PosDirective = TuneFeatureStrings[TuneFeature.PosIdx];
217 StringRef NegDirective = TuneFeatureStrings[TuneFeature.NegIdx];
218 StringRef FeatureName = TuneFeatureStrings[TuneFeature.FeatureIdx];
219 PositiveMap[PosDirective] = FeatureName;
220 NegativeMap[NegDirective] = FeatureName;
223 for (
const auto &Imp : ImpliedTuneFeatures) {
224 StringRef Feature = TuneFeatureStrings[Imp.FeatureIdx];
225 StringRef ImpliedFeature = TuneFeatureStrings[Imp.ImpliedFeatureIdx];
226 ImpliedFeatureMap[Feature].push_back(ImpliedFeature);
227 InvImpliedFeatureMap[ImpliedFeature].push_back(Feature);
233 std::pair<StringRef, bool> getFeature(StringRef DirectiveName)
const {
234 auto It = PositiveMap.find(DirectiveName);
235 if (It != PositiveMap.end())
236 return {It->getValue(),
true};
238 return {NegativeMap.lookup(DirectiveName),
false};
245 bool Inverse =
false)
const {
246 const auto &
Map = Inverse ? InvImpliedFeatureMap : ImpliedFeatureMap;
247 auto It =
Map.find(FeatureName);
256 RISCVTuneFeatureLookupTable::getAllTuneFeatures(Features);
261 RISCVTuneFeatureLookupTable TFLookup;
262 using SmallStringSet = RISCVTuneFeatureLookupTable::SmallStringSet;
266 std::string WarningMsg;
268 TFString = TFString.
trim();
269 if (TFString.
empty())
273 SmallStringSet PositiveFeatures;
274 SmallStringSet NegativeFeatures;
275 SmallStringSet PerProcDirectives;
276 RISCVTuneFeatureLookupTable::getConfigurableFeatures(ProcName,
278 if (PerProcDirectives.empty() && !ProcName.
empty())
281 "configurable tuning features");
286 std::tie(DirectiveStr, TFString) = TFString.
split(
",");
287 auto [FeatureName, IsPositive] = TFLookup.getFeature(DirectiveStr);
288 if (FeatureName.empty()) {
290 SS <<
"unrecognized tune feature directive '" << DirectiveStr <<
"'";
294 auto &Features = IsPositive ? PositiveFeatures : NegativeFeatures;
295 if (!Features.insert(FeatureName).second)
297 "cannot specify more than one instance of '" +
Twine(DirectiveStr) +
300 if (!PerProcDirectives.count(DirectiveStr) && !ProcName.
empty())
303 "allowed to be used with processor '" +
304 Twine(ProcName) +
"'");
305 }
while (!TFString.
empty());
309 if (!Intersection.empty()) {
310 std::string IntersectedStr =
join(Intersection,
"', '");
312 "' cannot appear in both "
313 "positive and negative directives");
317 SmallStringSet DerivedPosFeatures;
318 SmallStringSet DerivedNegFeatures;
320 if (
auto FeatureList = TFLookup.featureImplies(PF); !FeatureList.empty())
321 DerivedPosFeatures.insert_range(FeatureList);
324 if (
auto FeatureList = TFLookup.featureImplies(NF,
true);
325 !FeatureList.empty())
326 DerivedNegFeatures.insert_range(FeatureList);
328 PositiveFeatures.insert_range(DerivedPosFeatures);
329 NegativeFeatures.insert_range(DerivedNegFeatures);
332 if (!Intersection.empty()) {
333 std::string IntersectedStr =
join(Intersection,
"', '");
335 "' were implied by both "
336 "positive and negative directives");
340 const std::string PosPrefix(
"+");
341 const std::string NegPrefix(
"-");
347 if (WarningMsg.empty())
355 RISCVTuneFeatureLookupTable::SmallStringSet DirectiveSet;
356 RISCVTuneFeatureLookupTable::getConfigurableFeatures(CPU, DirectiveSet);
357 Directives.assign(DirectiveSet.
begin(), DirectiveSet.
end());
361namespace RISCVVType {
373 bool MaskAgnostic,
bool AltFmt) {
375 unsigned VLMulBits =
static_cast<unsigned>(VLMul);
377 unsigned VTypeI = (VSEWBits << 3) | (VLMulBits & 0x7);
393 unsigned VTypeI = (VSEWBits << 3) | AltFmt << 8 | TWiden << 9;
399 assert((XLen == 32 || XLen == 64) &&
"Invalid XLEN");
430 assert(Encoding < 8 &&
"Invalid IME lambda encoding");
433 return 1U << (Encoding - 1);
443 bool AltFmtB,
bool BlockSize16) {
456 bool AltFmtA,
bool AltFmtB,
bool BlockSize16) {
494 return std::make_pair(1 <<
static_cast<unsigned>(VLMul),
false);
498 return std::make_pair(1 << (8 -
static_cast<unsigned>(VLMul)),
true);
503 unsigned Sew =
getSEW(VType);
541 LMul = Fractional ? (8 / LMul) : (LMul * 8);
543 assert(SEW >= 8 &&
"Unexpected SEW value");
544 return (SEW * 8) / LMul;
548 unsigned EMULFixedPoint = (EEW * 8) / Ratio;
549 bool Fractional = EMULFixedPoint < 8;
550 unsigned EMUL = Fractional ? 8 / EMULFixedPoint : EMULFixedPoint / 8;
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const RISCVInstrInfo * RII
#define TUNE_PROC(ENUM, NAME)
This file defines generic set operations that may be used on set's of different types,...
This file defines the SmallSet class.
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true)
Parse RISC-V ISA info from arch string.
const_iterator begin() const
const_iterator end() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
Check if the string is empty.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned getAltFmtBShift(unsigned XLen)
LLVM_ABI bool isAltFmtB(uint64_t VType, unsigned XLen)
LLVM_ABI std::optional< unsigned > getLambda(uint64_t VType, unsigned XLen)
LLVM_ABI bool isBlockSize16(uint64_t VType, unsigned XLen)
static bool isValidLambda(unsigned Lambda)
static unsigned getBSShift(unsigned XLen)
LLVM_ABI uint64_t addVTypeFields(uint64_t VType, unsigned XLen, unsigned Lambda, bool AltFmtA, bool AltFmtB, bool BlockSize16)
LLVM_ABI bool isAltFmtA(uint64_t VType, unsigned XLen)
LLVM_ABI unsigned getLambdaEncoding(uint64_t VType, unsigned XLen)
LLVM_ABI std::optional< unsigned > decodeLambda(unsigned Encoding)
LLVM_ABI uint64_t getVTypeFieldsMask(unsigned XLen)
LLVM_ABI uint64_t encodeVTypeFields(unsigned XLen, unsigned Lambda, bool AltFmtA, bool AltFmtB, bool BlockSize16)
static void assertValidXLenForVType(unsigned XLen)
static unsigned getLambdaShift(unsigned XLen)
static unsigned getAltFmtAShift(unsigned XLen)
LLVM_ABI unsigned encodeLambda(unsigned Lambda)
static bool isTailAgnostic(unsigned VType)
static VLMUL encodeLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI void printXSfmmVType(unsigned VType, raw_ostream &OS)
LLVM_ABI unsigned encodeXSfmmVType(unsigned SEW, unsigned Widen, bool AltFmt)
static unsigned getXSfmmWiden(unsigned VType)
static bool isValidLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI std::optional< VLMUL > getSameRatioLMUL(unsigned Ratio, unsigned EEW)
static bool isMaskAgnostic(unsigned VType)
LLVM_ABI std::pair< unsigned, bool > decodeVLMUL(VLMUL VLMul)
static unsigned encodeSEW(unsigned SEW)
LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul)
static bool isValidSEW(unsigned SEW)
LLVM_ABI void printVType(unsigned VType, raw_ostream &OS)
static bool isAltFmt(unsigned VType)
LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic, bool MaskAgnostic, bool AltFmt=false)
static unsigned getSEW(unsigned VType)
static VLMUL getVLMUL(unsigned VType)
LLVM_ABI bool hasFastVectorUnalignedAccess(StringRef CPU)
LLVM_ABI void getFeaturesForCPU(StringRef CPU, SmallVectorImpl< std::string > &EnabledFeatures, bool NeedPlus=false)
LLVM_ABI void fillValidTuneCPUArchList(SmallVectorImpl< StringRef > &Values, bool IsRV64)
static const CPUInfo * getCPUInfoByName(StringRef CPU)
constexpr CPUInfo RISCVCPUInfo[]
LLVM_ABI CPUModel getCPUModel(StringRef CPU)
LLVM_ABI Error parseTuneFeatureString(StringRef ProcName, StringRef TFString, SmallVectorImpl< std::string > &TuneFeatures)
Parse the tune feature string with the respective processor.
LLVM_ABI void getAllTuneFeatures(SmallVectorImpl< StringRef > &TuneFeatures)
LLVM_ABI StringRef getMArchFromMcpu(StringRef CPU)
LLVM_ABI bool parseCPU(StringRef CPU, bool IsRV64)
LLVM_ABI bool hasFastScalarUnalignedAccess(StringRef CPU)
LLVM_ABI bool hasValidCPUModel(StringRef CPU)
LLVM_ABI StringRef getCPUNameFromCPUModel(const CPUModel &Model)
LLVM_ABI bool parseTuneCPU(StringRef CPU, bool IsRV64)
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values, bool IsRV64)
LLVM_ABI void getCPUConfigurableTuneFeatures(StringRef CPU, SmallVectorImpl< StringRef > &Directives)
EnumSet< Directive > Directives
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
bool operator<(int64_t V1, const APSInt &V2)
RelativeUniformCounterPtr Values
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
void sort(IteratorTy Start, IteratorTy End)
S1Ty set_intersection(const S1Ty &S1, const S2Ty &S2)
set_intersection(A, B) - Return A ^ B
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
ArrayRef(const T &OneElt) -> ArrayRef< T >