Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
35290 views
//===- CodeGenIntrinsics.h - Intrinsic Class Wrapper -----------*- C++ -*--===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines a wrapper class for the 'Intrinsic' TableGen class.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H13#define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H1415#include "SDNodeProperties.h"16#include "llvm/ADT/ArrayRef.h"17#include "llvm/ADT/SmallVector.h"18#include "llvm/Support/ModRef.h"19#include <string>20#include <tuple>21#include <vector>2223namespace llvm {24class Record;25class RecordKeeper;2627struct CodeGenIntrinsic {28Record *TheDef; // The actual record defining this intrinsic.29std::string Name; // The name of the LLVM function "llvm.bswap.i32"30std::string EnumName; // The name of the enum "bswap_i32"31std::string ClangBuiltinName; // Name of the corresponding GCC builtin, or "".32std::string MSBuiltinName; // Name of the corresponding MS builtin, or "".33std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.3435/// This structure holds the return values and parameter values of an36/// intrinsic. If the number of return values is > 1, then the intrinsic37/// implicitly returns a first-class aggregate. The numbering of the types38/// starts at 0 with the first return value and continues from there through39/// the parameter list. This is useful for "matching" types.40struct IntrinsicSignature {41/// The MVT::SimpleValueType for each return type. Note that this list is42/// only populated when in the context of a target .td file. When building43/// Intrinsics.td, this isn't available, because we don't know the target44/// pointer size.45std::vector<Record *> RetTys;4647/// The MVT::SimpleValueType for each parameter type. Note that this list is48/// only populated when in the context of a target .td file. When building49/// Intrinsics.td, this isn't available, because we don't know the target50/// pointer size.51std::vector<Record *> ParamTys;52};5354IntrinsicSignature IS;5556/// Memory effects of the intrinsic.57MemoryEffects ME = MemoryEffects::unknown();5859/// SDPatternOperator Properties applied to the intrinsic.60unsigned Properties;6162/// This is set to true if the intrinsic is overloaded by its argument63/// types.64bool isOverloaded;6566/// True if the intrinsic is commutative.67bool isCommutative;6869/// True if the intrinsic can throw.70bool canThrow;7172/// True if the intrinsic is marked as noduplicate.73bool isNoDuplicate;7475/// True if the intrinsic is marked as nomerge.76bool isNoMerge;7778/// True if the intrinsic is no-return.79bool isNoReturn;8081/// True if the intrinsic is no-callback.82bool isNoCallback;8384/// True if the intrinsic is no-sync.85bool isNoSync;8687/// True if the intrinsic is no-free.88bool isNoFree;8990/// True if the intrinsic is will-return.91bool isWillReturn;9293/// True if the intrinsic is cold.94bool isCold;9596/// True if the intrinsic is marked as convergent.97bool isConvergent;9899/// True if the intrinsic has side effects that aren't captured by any100/// of the other flags.101bool hasSideEffects;102103// True if the intrinsic is marked as speculatable.104bool isSpeculatable;105106// True if the intrinsic is marked as strictfp.107bool isStrictFP;108109enum ArgAttrKind {110NoCapture,111NoAlias,112NoUndef,113NonNull,114Returned,115ReadOnly,116WriteOnly,117ReadNone,118ImmArg,119Alignment,120Dereferenceable121};122123struct ArgAttribute {124ArgAttrKind Kind;125uint64_t Value;126127ArgAttribute(ArgAttrKind K, uint64_t V) : Kind(K), Value(V) {}128129bool operator<(const ArgAttribute &Other) const {130return std::tie(Kind, Value) < std::tie(Other.Kind, Other.Value);131}132};133134/// Vector of attributes for each argument.135SmallVector<SmallVector<ArgAttribute, 0>> ArgumentAttributes;136137void addArgAttribute(unsigned Idx, ArgAttrKind AK, uint64_t V = 0);138139bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }140141/// Goes through all IntrProperties that have IsDefault142/// value set and sets the property.143void setDefaultProperties(Record *R, ArrayRef<Record *> DefaultProperties);144145/// Helper function to set property \p Name to true;146void setProperty(Record *R);147148/// Returns true if the parameter at \p ParamIdx is a pointer type. Returns149/// false if the parameter is not a pointer, or \p ParamIdx is greater than150/// the size of \p IS.ParamVTs.151///152/// Note that this requires that \p IS.ParamVTs is available.153bool isParamAPointer(unsigned ParamIdx) const;154155bool isParamImmArg(unsigned ParamIdx) const;156157CodeGenIntrinsic(Record *R, ArrayRef<Record *> DefaultProperties);158};159160class CodeGenIntrinsicTable {161std::vector<CodeGenIntrinsic> Intrinsics;162163public:164struct TargetSet {165std::string Name;166size_t Offset;167size_t Count;168};169std::vector<TargetSet> Targets;170171explicit CodeGenIntrinsicTable(const RecordKeeper &RC);172CodeGenIntrinsicTable() = default;173174bool empty() const { return Intrinsics.empty(); }175size_t size() const { return Intrinsics.size(); }176auto begin() const { return Intrinsics.begin(); }177auto end() const { return Intrinsics.end(); }178CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; }179const CodeGenIntrinsic &operator[](size_t Pos) const {180return Intrinsics[Pos];181}182};183} // namespace llvm184185#endif186187188