2017-09-14 16:56:21 +00:00
|
|
|
//===--- CodeGenHwModes.h ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-09-14 16:56:21 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Classes to parse and store HW mode information for instruction selection.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2024-08-10 07:35:03 -07:00
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_COMMON_CODEGENHWMODES_H
|
|
|
|
#define LLVM_UTILS_TABLEGEN_COMMON_CODEGENHWMODES_H
|
2017-09-14 16:56:21 +00:00
|
|
|
|
2023-02-27 22:33:41 -08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2023-02-17 00:28:07 +09:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2020-03-02 18:24:11 +01:00
|
|
|
#include <cassert>
|
2017-09-14 16:56:21 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2023-02-17 00:28:07 +09:00
|
|
|
#include <utility>
|
2017-09-14 16:56:21 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// HwModeId -> list of predicates (definition)
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Record;
|
|
|
|
class RecordKeeper;
|
|
|
|
|
|
|
|
struct CodeGenHwModes;
|
|
|
|
|
|
|
|
struct HwMode {
|
2024-09-09 13:09:53 -07:00
|
|
|
HwMode(const Record *R);
|
2017-09-14 16:56:21 +00:00
|
|
|
StringRef Name;
|
|
|
|
std::string Features;
|
2023-03-14 13:00:38 -07:00
|
|
|
std::string Predicates;
|
2017-09-14 16:56:21 +00:00
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HwModeSelect {
|
2024-09-09 13:09:53 -07:00
|
|
|
HwModeSelect(const Record *R, CodeGenHwModes &CGH);
|
|
|
|
typedef std::pair<unsigned, const Record *> PairType;
|
2017-09-14 16:56:21 +00:00
|
|
|
std::vector<PairType> Items;
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CodeGenHwModes {
|
|
|
|
enum : unsigned { DefaultMode = 0 };
|
|
|
|
static StringRef DefaultModeName;
|
|
|
|
|
2024-09-09 13:09:53 -07:00
|
|
|
CodeGenHwModes(const RecordKeeper &R);
|
|
|
|
unsigned getHwModeId(const Record *R) const;
|
2017-09-14 16:56:21 +00:00
|
|
|
const HwMode &getMode(unsigned Id) const {
|
|
|
|
assert(Id != 0 && "Mode id of 0 is reserved for the default mode");
|
|
|
|
return Modes[Id - 1];
|
|
|
|
}
|
2024-02-28 11:47:18 -06:00
|
|
|
StringRef getModeName(unsigned Id, bool IncludeDefault = false) const {
|
|
|
|
if (IncludeDefault && Id == CodeGenHwModes::DefaultMode)
|
|
|
|
return DefaultModeName;
|
|
|
|
return getMode(Id).Name;
|
|
|
|
}
|
2024-09-09 13:09:53 -07:00
|
|
|
const HwModeSelect &getHwModeSelect(const Record *R) const;
|
|
|
|
const std::map<const Record *, HwModeSelect> &getHwModeSelects() const {
|
2024-02-25 22:58:17 -06:00
|
|
|
return ModeSelects;
|
|
|
|
}
|
2017-09-14 16:56:21 +00:00
|
|
|
unsigned getNumModeIds() const { return Modes.size() + 1; }
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
private:
|
2024-09-09 13:09:53 -07:00
|
|
|
const RecordKeeper &Records;
|
|
|
|
DenseMap<const Record *, unsigned> ModeIds; // HwMode Record -> HwModeId
|
2017-09-14 16:56:21 +00:00
|
|
|
std::vector<HwMode> Modes;
|
2024-09-09 13:09:53 -07:00
|
|
|
std::map<const Record *, HwModeSelect> ModeSelects;
|
2017-09-14 16:56:21 +00:00
|
|
|
};
|
|
|
|
} // namespace llvm
|
|
|
|
|
2024-08-10 07:35:03 -07:00
|
|
|
#endif // LLVM_UTILS_TABLEGEN_COMMON_CODEGENHWMODES_H
|