2006-03-03 10:32:46 +08:00
|
|
|
//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
2006-03-03 10:32:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits information about intrinsic functions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-11 23:37:55 +08:00
|
|
|
#include "CodeGenIntrinsics.h"
|
2007-08-04 09:51:18 +08:00
|
|
|
#include "CodeGenTarget.h"
|
2012-05-17 23:55:41 +08:00
|
|
|
#include "SequenceToOffsetTable.h"
|
2014-04-21 04:26:39 +08:00
|
|
|
#include "TableGenBackends.h"
|
2012-06-11 23:37:55 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2019-12-11 23:55:26 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-10-26 04:33:17 +08:00
|
|
|
#include "llvm/TableGen/Error.h"
|
2011-10-02 00:41:13 +08:00
|
|
|
#include "llvm/TableGen/Record.h"
|
2012-05-03 01:32:48 +08:00
|
|
|
#include "llvm/TableGen/StringMatcher.h"
|
2016-01-27 09:43:12 +08:00
|
|
|
#include "llvm/TableGen/StringToOffsetTable.h"
|
2019-12-11 23:55:26 +08:00
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
2006-03-15 10:51:05 +08:00
|
|
|
#include <algorithm>
|
2006-03-03 10:32:46 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2019-12-11 23:55:26 +08:00
|
|
|
cl::OptionCategory GenIntrinsicCat("Options for -gen-intrinsic-enums");
|
|
|
|
cl::opt<std::string>
|
|
|
|
IntrinsicPrefix("intrinsic-prefix",
|
|
|
|
cl::desc("Generate intrinsics with this target prefix"),
|
|
|
|
cl::value_desc("target prefix"), cl::cat(GenIntrinsicCat));
|
|
|
|
|
2012-06-11 23:37:55 +08:00
|
|
|
namespace {
|
|
|
|
class IntrinsicEmitter {
|
|
|
|
RecordKeeper &Records;
|
|
|
|
|
|
|
|
public:
|
2019-12-11 23:37:16 +08:00
|
|
|
IntrinsicEmitter(RecordKeeper &R) : Records(R) {}
|
2012-06-11 23:37:55 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
void run(raw_ostream &OS, bool Enums);
|
2012-06-11 23:37:55 +08:00
|
|
|
|
2016-07-16 00:31:37 +08:00
|
|
|
void EmitEnumInfo(const CodeGenIntrinsicTable &Ints, raw_ostream &OS);
|
|
|
|
void EmitTargetInfo(const CodeGenIntrinsicTable &Ints, raw_ostream &OS);
|
|
|
|
void EmitIntrinsicToNameTable(const CodeGenIntrinsicTable &Ints,
|
2012-06-11 23:37:55 +08:00
|
|
|
raw_ostream &OS);
|
2016-07-16 00:31:37 +08:00
|
|
|
void EmitIntrinsicToOverloadTable(const CodeGenIntrinsicTable &Ints,
|
2012-06-11 23:37:55 +08:00
|
|
|
raw_ostream &OS);
|
2016-07-16 00:31:37 +08:00
|
|
|
void EmitGenerator(const CodeGenIntrinsicTable &Ints, raw_ostream &OS);
|
|
|
|
void EmitAttributes(const CodeGenIntrinsicTable &Ints, raw_ostream &OS);
|
|
|
|
void EmitIntrinsicToBuiltinMap(const CodeGenIntrinsicTable &Ints, bool IsGCC,
|
|
|
|
raw_ostream &OS);
|
2012-06-11 23:37:55 +08:00
|
|
|
};
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
2006-03-03 10:32:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IntrinsicEmitter Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
void IntrinsicEmitter::run(raw_ostream &OS, bool Enums) {
|
2012-06-11 23:37:55 +08:00
|
|
|
emitSourceFileHeader("Intrinsic Function Source Fragment", OS);
|
|
|
|
|
2019-12-11 23:37:16 +08:00
|
|
|
CodeGenIntrinsicTable Ints(Records);
|
2006-03-03 10:32:46 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
if (Enums) {
|
|
|
|
// Emit the enum information.
|
|
|
|
EmitEnumInfo(Ints, OS);
|
|
|
|
} else {
|
|
|
|
// Emit the target metadata.
|
|
|
|
EmitTargetInfo(Ints, OS);
|
2016-07-16 00:31:37 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
// Emit the intrinsic ID -> name table.
|
|
|
|
EmitIntrinsicToNameTable(Ints, OS);
|
2009-02-25 07:17:49 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
// Emit the intrinsic ID -> overload table.
|
|
|
|
EmitIntrinsicToOverloadTable(Ints, OS);
|
2009-02-25 07:17:49 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
// Emit the intrinsic declaration generator.
|
|
|
|
EmitGenerator(Ints, OS);
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
// Emit the intrinsic parameter attributes.
|
|
|
|
EmitAttributes(Ints, OS);
|
2006-03-14 07:08:44 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
// Emit code to translate GCC builtins into LLVM intrinsics.
|
|
|
|
EmitIntrinsicToBuiltinMap(Ints, true, OS);
|
2010-05-11 14:17:44 +08:00
|
|
|
|
2018-06-23 10:02:38 +08:00
|
|
|
// Emit code to translate MS builtins into LLVM intrinsics.
|
|
|
|
EmitIntrinsicToBuiltinMap(Ints, false, OS);
|
2019-12-11 23:55:26 +08:00
|
|
|
}
|
2010-05-11 14:17:44 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 00:31:37 +08:00
|
|
|
void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2019-12-11 23:55:26 +08:00
|
|
|
// Find the TargetSet for which to generate enums. There will be an initial
|
|
|
|
// set with an empty target prefix which will include target independent
|
|
|
|
// intrinsics like dbg.value.
|
|
|
|
const CodeGenIntrinsicTable::TargetSet *Set = nullptr;
|
|
|
|
for (const auto &Target : Ints.Targets) {
|
|
|
|
if (Target.Name == IntrinsicPrefix) {
|
|
|
|
Set = &Target;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Set) {
|
|
|
|
std::vector<std::string> KnownTargets;
|
|
|
|
for (const auto &Target : Ints.Targets)
|
|
|
|
if (!Target.Name.empty())
|
|
|
|
KnownTargets.push_back(Target.Name);
|
|
|
|
PrintFatalError("tried to generate intrinsics for unknown target " +
|
|
|
|
IntrinsicPrefix +
|
|
|
|
"\nKnown targets are: " + join(KnownTargets, ", ") + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a complete header for target specific intrinsics.
|
|
|
|
if (!IntrinsicPrefix.empty()) {
|
|
|
|
std::string UpperPrefix = StringRef(IntrinsicPrefix).upper();
|
|
|
|
OS << "#ifndef LLVM_IR_INTRINSIC_" << UpperPrefix << "_ENUMS_H\n";
|
|
|
|
OS << "#define LLVM_IR_INTRINSIC_" << UpperPrefix << "_ENUMS_H\n\n";
|
|
|
|
OS << "namespace llvm {\n";
|
|
|
|
OS << "namespace Intrinsic {\n";
|
|
|
|
OS << "enum " << UpperPrefix << "Intrinsics : unsigned {\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "// Enum values for intrinsics\n";
|
|
|
|
for (unsigned i = Set->Offset, e = Set->Offset + Set->Count; i != e; ++i) {
|
2006-03-03 10:32:46 +08:00
|
|
|
OS << " " << Ints[i].EnumName;
|
2019-12-11 23:55:26 +08:00
|
|
|
|
|
|
|
// Assign a value to the first intrinsic in this target set so that all
|
|
|
|
// intrinsic ids are distinct.
|
|
|
|
if (i == Set->Offset)
|
|
|
|
OS << " = " << (Set->Offset + 1);
|
|
|
|
|
|
|
|
OS << ", ";
|
2014-07-17 19:23:29 +08:00
|
|
|
if (Ints[i].EnumName.size() < 40)
|
2019-12-11 23:55:26 +08:00
|
|
|
OS.indent(40 - Ints[i].EnumName.size());
|
2014-07-17 19:23:29 +08:00
|
|
|
OS << " // " << Ints[i].Name << "\n";
|
2006-03-03 10:32:46 +08:00
|
|
|
}
|
2019-12-11 23:55:26 +08:00
|
|
|
|
|
|
|
// Emit num_intrinsics into the target neutral enum.
|
|
|
|
if (IntrinsicPrefix.empty()) {
|
|
|
|
OS << " num_intrinsics = " << (Ints.size() + 1) << "\n";
|
|
|
|
} else {
|
|
|
|
OS << "}; // enum\n";
|
|
|
|
OS << "} // namespace Intrinsic\n";
|
|
|
|
OS << "} // namespace llvm\n\n";
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
2006-03-03 10:32:46 +08:00
|
|
|
}
|
2006-03-10 04:34:19 +08:00
|
|
|
|
2016-07-16 00:31:37 +08:00
|
|
|
void IntrinsicEmitter::EmitTargetInfo(const CodeGenIntrinsicTable &Ints,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
OS << "// Target mapping\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_TARGET_DATA\n";
|
|
|
|
OS << "struct IntrinsicTargetInfo {\n"
|
2017-01-31 08:45:01 +08:00
|
|
|
<< " llvm::StringLiteral Name;\n"
|
2016-07-16 00:31:37 +08:00
|
|
|
<< " size_t Offset;\n"
|
|
|
|
<< " size_t Count;\n"
|
|
|
|
<< "};\n";
|
2017-01-31 02:49:24 +08:00
|
|
|
OS << "static constexpr IntrinsicTargetInfo TargetInfos[] = {\n";
|
2016-07-16 00:31:37 +08:00
|
|
|
for (auto Target : Ints.Targets)
|
2017-01-31 08:45:01 +08:00
|
|
|
OS << " {llvm::StringLiteral(\"" << Target.Name << "\"), " << Target.Offset
|
2017-01-31 03:05:09 +08:00
|
|
|
<< ", " << Target.Count << "},\n";
|
2016-07-16 00:31:37 +08:00
|
|
|
OS << "};\n";
|
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitIntrinsicToNameTable(
|
|
|
|
const CodeGenIntrinsicTable &Ints, raw_ostream &OS) {
|
2006-03-15 09:55:21 +08:00
|
|
|
OS << "// Intrinsic ID to name table\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
|
|
|
|
OS << " // Note that entry #0 is the invalid intrinsic!\n";
|
2006-03-29 06:25:56 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
|
|
|
OS << " \"" << Ints[i].Name << "\",\n";
|
2006-03-15 09:55:21 +08:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2016-07-16 00:31:37 +08:00
|
|
|
void IntrinsicEmitter::EmitIntrinsicToOverloadTable(
|
|
|
|
const CodeGenIntrinsicTable &Ints, raw_ostream &OS) {
|
2012-03-01 10:16:57 +08:00
|
|
|
OS << "// Intrinsic ID to overload bitset\n";
|
2009-02-25 07:17:49 +08:00
|
|
|
OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
|
2012-03-01 10:16:57 +08:00
|
|
|
OS << "static const uint8_t OTable[] = {\n";
|
|
|
|
OS << " 0";
|
2009-02-25 07:17:49 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2012-03-01 10:16:57 +08:00
|
|
|
// Add one to the index so we emit a null bit for the invalid #0 intrinsic.
|
|
|
|
if ((i+1)%8 == 0)
|
|
|
|
OS << ",\n 0";
|
2009-02-25 07:17:49 +08:00
|
|
|
if (Ints[i].isOverloaded)
|
2012-03-01 10:16:57 +08:00
|
|
|
OS << " | (1<<" << (i+1)%8 << ')';
|
2009-02-25 07:17:49 +08:00
|
|
|
}
|
2012-03-01 10:16:57 +08:00
|
|
|
OS << "\n};\n\n";
|
|
|
|
// OTable contains a true bit at the position if the intrinsic is overloaded.
|
|
|
|
OS << "return (OTable[id/8] & (1 << (id%8))) != 0;\n";
|
2009-02-25 07:17:49 +08:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
|
2018-04-30 18:18:11 +08:00
|
|
|
// NOTE: This must be kept in synch with the copy in lib/IR/Function.cpp!
|
2012-05-16 14:34:44 +08:00
|
|
|
enum IIT_Info {
|
2014-10-21 03:25:05 +08:00
|
|
|
// Common values should be encoded with 0-15.
|
2012-05-16 14:34:44 +08:00
|
|
|
IIT_Done = 0,
|
|
|
|
IIT_I1 = 1,
|
|
|
|
IIT_I8 = 2,
|
|
|
|
IIT_I16 = 3,
|
|
|
|
IIT_I32 = 4,
|
|
|
|
IIT_I64 = 5,
|
2013-01-11 09:45:05 +08:00
|
|
|
IIT_F16 = 6,
|
|
|
|
IIT_F32 = 7,
|
|
|
|
IIT_F64 = 8,
|
|
|
|
IIT_V2 = 9,
|
|
|
|
IIT_V4 = 10,
|
|
|
|
IIT_V8 = 11,
|
|
|
|
IIT_V16 = 12,
|
|
|
|
IIT_V32 = 13,
|
2014-10-21 03:25:05 +08:00
|
|
|
IIT_PTR = 14,
|
|
|
|
IIT_ARG = 15,
|
2014-09-30 19:32:22 +08:00
|
|
|
|
2014-10-21 03:25:05 +08:00
|
|
|
// Values from 16+ are only encodable with the inefficient encoding.
|
|
|
|
IIT_V64 = 16,
|
2014-09-30 19:32:22 +08:00
|
|
|
IIT_MMX = 17,
|
2015-09-02 21:36:25 +08:00
|
|
|
IIT_TOKEN = 18,
|
|
|
|
IIT_METADATA = 19,
|
|
|
|
IIT_EMPTYSTRUCT = 20,
|
|
|
|
IIT_STRUCT2 = 21,
|
|
|
|
IIT_STRUCT3 = 22,
|
|
|
|
IIT_STRUCT4 = 23,
|
|
|
|
IIT_STRUCT5 = 24,
|
|
|
|
IIT_EXTEND_ARG = 25,
|
|
|
|
IIT_TRUNC_ARG = 26,
|
|
|
|
IIT_ANYPTR = 27,
|
|
|
|
IIT_V1 = 28,
|
|
|
|
IIT_VARARG = 29,
|
|
|
|
IIT_HALF_VEC_ARG = 30,
|
|
|
|
IIT_SAME_VEC_WIDTH_ARG = 31,
|
|
|
|
IIT_PTR_TO_ARG = 32,
|
2016-11-03 11:23:55 +08:00
|
|
|
IIT_PTR_TO_ELT = 33,
|
2017-05-03 20:28:54 +08:00
|
|
|
IIT_VEC_OF_ANYPTRS_TO_ELT = 34,
|
2016-11-03 11:23:55 +08:00
|
|
|
IIT_I128 = 35,
|
|
|
|
IIT_V512 = 36,
|
2017-10-13 01:40:00 +08:00
|
|
|
IIT_V1024 = 37,
|
|
|
|
IIT_STRUCT6 = 38,
|
|
|
|
IIT_STRUCT7 = 39,
|
2018-07-10 02:50:06 +08:00
|
|
|
IIT_STRUCT8 = 40,
|
2019-06-13 17:37:38 +08:00
|
|
|
IIT_F128 = 41,
|
2019-08-27 20:57:09 +08:00
|
|
|
IIT_VEC_ELEMENT = 42,
|
2019-09-20 17:48:21 +08:00
|
|
|
IIT_SCALABLE_VEC = 43,
|
|
|
|
IIT_SUBDIVIDE2_ARG = 44,
|
2019-10-02 17:25:02 +08:00
|
|
|
IIT_SUBDIVIDE4_ARG = 45,
|
2020-02-07 23:30:31 +08:00
|
|
|
IIT_VEC_OF_BITCASTS_TO_INT = 46,
|
[IR][BFloat] add BFloat IR intrinsics support
Summary:
This patch is part of a series that adds support for the Bfloat16 extension of
the Armv8.6-a architecture, as detailed here:
https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/arm-architecture-developments-armv8-6-a
The bfloat type, and its properties are specified in the Arm Architecture
Reference Manual:
https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
Reviewers: scanon, fpetrogalli, sdesmalen, craig.topper, LukeGeeson
Reviewed By: fpetrogalli
Subscribers: LukeGeeson, pbarrio, kristof.beyls, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79707
2020-05-27 21:00:33 +08:00
|
|
|
IIT_V128 = 47,
|
2020-09-30 18:01:15 +08:00
|
|
|
IIT_BF16 = 48,
|
2020-10-02 22:47:43 +08:00
|
|
|
IIT_STRUCT9 = 49,
|
2020-11-20 15:19:34 +08:00
|
|
|
IIT_V256 = 50,
|
|
|
|
IIT_AMX = 51
|
2012-05-16 14:34:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void EncodeFixedValueType(MVT::SimpleValueType VT,
|
2012-05-17 23:55:41 +08:00
|
|
|
std::vector<unsigned char> &Sig) {
|
2014-01-25 04:50:47 +08:00
|
|
|
if (MVT(VT).isInteger()) {
|
2020-10-07 15:26:17 +08:00
|
|
|
unsigned BitWidth = MVT(VT).getFixedSizeInBits();
|
2012-05-16 14:34:44 +08:00
|
|
|
switch (BitWidth) {
|
2012-10-26 04:33:17 +08:00
|
|
|
default: PrintFatalError("unhandled integer type width in intrinsic!");
|
2012-05-16 14:34:44 +08:00
|
|
|
case 1: return Sig.push_back(IIT_I1);
|
|
|
|
case 8: return Sig.push_back(IIT_I8);
|
|
|
|
case 16: return Sig.push_back(IIT_I16);
|
|
|
|
case 32: return Sig.push_back(IIT_I32);
|
|
|
|
case 64: return Sig.push_back(IIT_I64);
|
2015-05-25 23:49:26 +08:00
|
|
|
case 128: return Sig.push_back(IIT_I128);
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 12:30:58 +08:00
|
|
|
switch (VT) {
|
2012-10-26 04:33:17 +08:00
|
|
|
default: PrintFatalError("unhandled MVT in intrinsic!");
|
2013-01-11 09:45:05 +08:00
|
|
|
case MVT::f16: return Sig.push_back(IIT_F16);
|
[IR][BFloat] add BFloat IR intrinsics support
Summary:
This patch is part of a series that adds support for the Bfloat16 extension of
the Armv8.6-a architecture, as detailed here:
https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/arm-architecture-developments-armv8-6-a
The bfloat type, and its properties are specified in the Arm Architecture
Reference Manual:
https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
Reviewers: scanon, fpetrogalli, sdesmalen, craig.topper, LukeGeeson
Reviewed By: fpetrogalli
Subscribers: LukeGeeson, pbarrio, kristof.beyls, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79707
2020-05-27 21:00:33 +08:00
|
|
|
case MVT::bf16: return Sig.push_back(IIT_BF16);
|
2012-05-17 12:30:58 +08:00
|
|
|
case MVT::f32: return Sig.push_back(IIT_F32);
|
|
|
|
case MVT::f64: return Sig.push_back(IIT_F64);
|
2018-07-10 02:50:06 +08:00
|
|
|
case MVT::f128: return Sig.push_back(IIT_F128);
|
2015-09-02 21:36:25 +08:00
|
|
|
case MVT::token: return Sig.push_back(IIT_TOKEN);
|
2012-05-17 12:30:58 +08:00
|
|
|
case MVT::Metadata: return Sig.push_back(IIT_METADATA);
|
|
|
|
case MVT::x86mmx: return Sig.push_back(IIT_MMX);
|
2020-11-20 15:19:34 +08:00
|
|
|
case MVT::x86amx: return Sig.push_back(IIT_AMX);
|
2012-05-17 12:30:58 +08:00
|
|
|
// MVT::OtherVT is used to mean the empty struct type here.
|
|
|
|
case MVT::Other: return Sig.push_back(IIT_EMPTYSTRUCT);
|
2013-11-01 01:18:11 +08:00
|
|
|
// MVT::isVoid is used to represent varargs here.
|
|
|
|
case MVT::isVoid: return Sig.push_back(IIT_VARARG);
|
2012-05-17 12:30:58 +08:00
|
|
|
}
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
2016-10-26 01:46:29 +08:00
|
|
|
#if defined(_MSC_VER) && !defined(__clang__)
|
|
|
|
#pragma optimize("",off) // MSVC 2015 optimizer can't deal with this function.
|
|
|
|
#endif
|
|
|
|
|
2012-05-28 00:39:08 +08:00
|
|
|
static void EncodeFixedType(Record *R, std::vector<unsigned char> &ArgCodes,
|
2019-06-13 16:19:33 +08:00
|
|
|
unsigned &NextArgCode,
|
|
|
|
std::vector<unsigned char> &Sig,
|
|
|
|
ArrayRef<unsigned char> Mapping) {
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
if (R->isSubClassOf("LLVMMatchType")) {
|
2019-06-13 16:19:33 +08:00
|
|
|
unsigned Number = Mapping[R->getValueAsInt("Number")];
|
2012-05-28 00:39:08 +08:00
|
|
|
assert(Number < ArgCodes.size() && "Invalid matching number!");
|
2014-03-28 20:31:39 +08:00
|
|
|
if (R->isSubClassOf("LLVMExtendedType"))
|
|
|
|
Sig.push_back(IIT_EXTEND_ARG);
|
|
|
|
else if (R->isSubClassOf("LLVMTruncatedType"))
|
|
|
|
Sig.push_back(IIT_TRUNC_ARG);
|
2014-03-29 15:04:54 +08:00
|
|
|
else if (R->isSubClassOf("LLVMHalfElementsVectorType"))
|
|
|
|
Sig.push_back(IIT_HALF_VEC_ARG);
|
2019-01-24 00:00:22 +08:00
|
|
|
else if (R->isSubClassOf("LLVMScalarOrSameVectorWidth")) {
|
2014-12-04 17:40:44 +08:00
|
|
|
Sig.push_back(IIT_SAME_VEC_WIDTH_ARG);
|
2015-01-23 04:14:38 +08:00
|
|
|
Sig.push_back((Number << 3) | ArgCodes[Number]);
|
2014-12-04 17:40:44 +08:00
|
|
|
MVT::SimpleValueType VT = getValueType(R->getValueAsDef("ElTy"));
|
|
|
|
EncodeFixedValueType(VT, Sig);
|
|
|
|
return;
|
|
|
|
}
|
Masked Gather and Scatter Intrinsics.
Gather and Scatter are new introduced intrinsics, comming after recently implemented masked load and store.
This is the first patch for Gather and Scatter intrinsics. It includes only the syntax, parsing and verification.
Gather and Scatter intrinsics allow to perform multiple memory accesses (read/write) in one vector instruction.
The intrinsics are not target specific and will have the following syntax:
Gather:
declare <16 x i32> @llvm.masked.gather.v16i32(<16 x i32*> <vector of ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x i32> <passthru>)
declare <8 x float> @llvm.masked.gather.v8f32(<8 x float*><vector of ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float><passthru>)
Scatter:
declare void @llvm.masked.scatter.v8i32(<8 x i32><vector value to be stored> , <8 x i32*><vector of ptrs> , i32 <alignment>, <8 x i1> <mask>)
declare void @llvm.masked.scatter.v16i32(<16 x i32> <vector value to be stored> , <16 x i32*> <vector of ptrs>, i32 <alignment>, <16 x i1><mask> )
Vector of ptrs - a set of source/destination addresses, to load/store the value.
Mask - switches on/off vector lanes to prevent memory access for switched-off lanes
vector of ptrs, value and mask should have the same vector width.
These are code examples where gather / scatter should be used and will allow function vectorization
;void foo1(int * restrict A, int * restrict B, int * restrict C) {
; for (int i=0; i<SIZE; i++) {
; A[i] = B[C[i]];
; }
;}
;void foo3(int * restrict A, int * restrict B) {
; for (int i=0; i<SIZE; i++) {
; A[B[i]] = i+5;
; }
;}
Tests will come in the following patches, with CodeGen and Vectorizer.
http://reviews.llvm.org/D7433
llvm-svn: 228521
2015-02-08 16:27:19 +08:00
|
|
|
else if (R->isSubClassOf("LLVMPointerTo"))
|
2014-12-25 15:49:20 +08:00
|
|
|
Sig.push_back(IIT_PTR_TO_ARG);
|
2017-05-03 20:28:54 +08:00
|
|
|
else if (R->isSubClassOf("LLVMVectorOfAnyPointersToElt")) {
|
|
|
|
Sig.push_back(IIT_VEC_OF_ANYPTRS_TO_ELT);
|
|
|
|
// Encode overloaded ArgNo
|
2019-06-13 16:19:33 +08:00
|
|
|
Sig.push_back(NextArgCode++);
|
2017-05-03 20:28:54 +08:00
|
|
|
// Encode LLVMMatchType<Number> ArgNo
|
|
|
|
Sig.push_back(Number);
|
|
|
|
return;
|
|
|
|
} else if (R->isSubClassOf("LLVMPointerToElt"))
|
2016-11-03 11:23:55 +08:00
|
|
|
Sig.push_back(IIT_PTR_TO_ELT);
|
2019-06-13 17:37:38 +08:00
|
|
|
else if (R->isSubClassOf("LLVMVectorElementType"))
|
|
|
|
Sig.push_back(IIT_VEC_ELEMENT);
|
2019-09-20 17:48:21 +08:00
|
|
|
else if (R->isSubClassOf("LLVMSubdivide2VectorType"))
|
|
|
|
Sig.push_back(IIT_SUBDIVIDE2_ARG);
|
|
|
|
else if (R->isSubClassOf("LLVMSubdivide4VectorType"))
|
|
|
|
Sig.push_back(IIT_SUBDIVIDE4_ARG);
|
2019-10-02 17:25:02 +08:00
|
|
|
else if (R->isSubClassOf("LLVMVectorOfBitcastsToInt"))
|
|
|
|
Sig.push_back(IIT_VEC_OF_BITCASTS_TO_INT);
|
2012-05-17 13:03:24 +08:00
|
|
|
else
|
|
|
|
Sig.push_back(IIT_ARG);
|
2019-06-13 16:19:33 +08:00
|
|
|
return Sig.push_back((Number << 3) | 7 /*IITDescriptor::AK_MatchType*/);
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
MVT::SimpleValueType VT = getValueType(R->getValueAsDef("VT"));
|
2012-05-17 12:30:58 +08:00
|
|
|
|
2012-05-28 00:39:08 +08:00
|
|
|
unsigned Tmp = 0;
|
2012-05-27 07:03:52 +08:00
|
|
|
switch (VT) {
|
|
|
|
default: break;
|
2016-08-18 04:30:52 +08:00
|
|
|
case MVT::iPTRAny: ++Tmp; LLVM_FALLTHROUGH;
|
|
|
|
case MVT::vAny: ++Tmp; LLVM_FALLTHROUGH;
|
|
|
|
case MVT::fAny: ++Tmp; LLVM_FALLTHROUGH;
|
|
|
|
case MVT::iAny: ++Tmp; LLVM_FALLTHROUGH;
|
2015-01-23 04:14:38 +08:00
|
|
|
case MVT::Any: {
|
2012-05-27 07:03:52 +08:00
|
|
|
// If this is an "any" valuetype, then the type is the type of the next
|
2013-11-01 01:18:07 +08:00
|
|
|
// type in the list specified to getIntrinsic().
|
2012-05-17 12:30:58 +08:00
|
|
|
Sig.push_back(IIT_ARG);
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-28 00:39:08 +08:00
|
|
|
// Figure out what arg # this is consuming, and remember what kind it was.
|
2019-06-13 16:19:33 +08:00
|
|
|
assert(NextArgCode < ArgCodes.size() && ArgCodes[NextArgCode] == Tmp &&
|
|
|
|
"Invalid or no ArgCode associated with overloaded VT!");
|
|
|
|
unsigned ArgNo = NextArgCode++;
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2015-01-23 04:14:38 +08:00
|
|
|
// Encode what sort of argument it must be in the low 3 bits of the ArgNo.
|
|
|
|
return Sig.push_back((ArgNo << 3) | Tmp);
|
2012-05-28 00:39:08 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-27 07:03:52 +08:00
|
|
|
case MVT::iPTR: {
|
|
|
|
unsigned AddrSpace = 0;
|
|
|
|
if (R->isSubClassOf("LLVMQualPointerType")) {
|
|
|
|
AddrSpace = R->getValueAsInt("AddrSpace");
|
|
|
|
assert(AddrSpace < 256 && "Address space exceeds 255");
|
|
|
|
}
|
|
|
|
if (AddrSpace) {
|
|
|
|
Sig.push_back(IIT_ANYPTR);
|
|
|
|
Sig.push_back(AddrSpace);
|
|
|
|
} else {
|
|
|
|
Sig.push_back(IIT_PTR);
|
|
|
|
}
|
2019-06-13 16:19:33 +08:00
|
|
|
return EncodeFixedType(R->getValueAsDef("ElTy"), ArgCodes, NextArgCode, Sig,
|
|
|
|
Mapping);
|
2012-05-27 07:03:52 +08:00
|
|
|
}
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2014-01-25 04:50:47 +08:00
|
|
|
if (MVT(VT).isVector()) {
|
|
|
|
MVT VVT = VT;
|
2019-08-27 20:57:09 +08:00
|
|
|
if (VVT.isScalableVector())
|
|
|
|
Sig.push_back(IIT_SCALABLE_VEC);
|
2012-05-16 14:34:44 +08:00
|
|
|
switch (VVT.getVectorNumElements()) {
|
2012-10-26 04:33:17 +08:00
|
|
|
default: PrintFatalError("unhandled vector type width in intrinsic!");
|
2013-09-24 10:47:27 +08:00
|
|
|
case 1: Sig.push_back(IIT_V1); break;
|
2012-05-16 14:34:44 +08:00
|
|
|
case 2: Sig.push_back(IIT_V2); break;
|
|
|
|
case 4: Sig.push_back(IIT_V4); break;
|
|
|
|
case 8: Sig.push_back(IIT_V8); break;
|
|
|
|
case 16: Sig.push_back(IIT_V16); break;
|
2012-05-17 12:30:58 +08:00
|
|
|
case 32: Sig.push_back(IIT_V32); break;
|
2014-09-30 19:32:22 +08:00
|
|
|
case 64: Sig.push_back(IIT_V64); break;
|
2020-02-07 23:30:31 +08:00
|
|
|
case 128: Sig.push_back(IIT_V128); break;
|
2020-10-02 22:47:43 +08:00
|
|
|
case 256: Sig.push_back(IIT_V256); break;
|
2015-11-25 00:28:14 +08:00
|
|
|
case 512: Sig.push_back(IIT_V512); break;
|
|
|
|
case 1024: Sig.push_back(IIT_V1024); break;
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2014-01-25 04:50:47 +08:00
|
|
|
return EncodeFixedValueType(VVT.getVectorElementType().SimpleTy, Sig);
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
2012-05-27 07:03:52 +08:00
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
EncodeFixedValueType(VT, Sig);
|
|
|
|
}
|
2012-05-17 12:00:03 +08:00
|
|
|
|
2019-06-13 16:19:33 +08:00
|
|
|
static void UpdateArgCodes(Record *R, std::vector<unsigned char> &ArgCodes,
|
|
|
|
unsigned int &NumInserted,
|
|
|
|
SmallVectorImpl<unsigned char> &Mapping) {
|
|
|
|
if (R->isSubClassOf("LLVMMatchType")) {
|
|
|
|
if (R->isSubClassOf("LLVMVectorOfAnyPointersToElt")) {
|
|
|
|
ArgCodes.push_back(3 /*vAny*/);
|
|
|
|
++NumInserted;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Tmp = 0;
|
|
|
|
switch (getValueType(R->getValueAsDef("VT"))) {
|
|
|
|
default: break;
|
2019-06-26 08:08:22 +08:00
|
|
|
case MVT::iPTR:
|
|
|
|
UpdateArgCodes(R->getValueAsDef("ElTy"), ArgCodes, NumInserted, Mapping);
|
|
|
|
break;
|
2019-06-13 16:19:33 +08:00
|
|
|
case MVT::iPTRAny:
|
|
|
|
++Tmp;
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case MVT::vAny:
|
|
|
|
++Tmp;
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case MVT::fAny:
|
|
|
|
++Tmp;
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case MVT::iAny:
|
|
|
|
++Tmp;
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case MVT::Any:
|
|
|
|
unsigned OriginalIdx = ArgCodes.size() - NumInserted;
|
|
|
|
assert(OriginalIdx >= Mapping.size());
|
|
|
|
Mapping.resize(OriginalIdx+1);
|
|
|
|
Mapping[OriginalIdx] = ArgCodes.size();
|
|
|
|
ArgCodes.push_back(Tmp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 01:46:29 +08:00
|
|
|
#if defined(_MSC_VER) && !defined(__clang__)
|
|
|
|
#pragma optimize("",on)
|
|
|
|
#endif
|
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
/// ComputeFixedEncoding - If we can encode the type signature for this
|
|
|
|
/// intrinsic into 32 bits, return it. If not, return ~0U.
|
2012-05-17 23:55:41 +08:00
|
|
|
static void ComputeFixedEncoding(const CodeGenIntrinsic &Int,
|
|
|
|
std::vector<unsigned char> &TypeSig) {
|
2012-05-28 00:39:08 +08:00
|
|
|
std::vector<unsigned char> ArgCodes;
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2019-06-13 16:19:33 +08:00
|
|
|
// Add codes for any overloaded result VTs.
|
|
|
|
unsigned int NumInserted = 0;
|
|
|
|
SmallVector<unsigned char, 8> ArgMapping;
|
|
|
|
for (unsigned i = 0, e = Int.IS.RetVTs.size(); i != e; ++i)
|
|
|
|
UpdateArgCodes(Int.IS.RetTypeDefs[i], ArgCodes, NumInserted, ArgMapping);
|
|
|
|
|
|
|
|
// Add codes for any overloaded operand VTs.
|
|
|
|
for (unsigned i = 0, e = Int.IS.ParamTypeDefs.size(); i != e; ++i)
|
|
|
|
UpdateArgCodes(Int.IS.ParamTypeDefs[i], ArgCodes, NumInserted, ArgMapping);
|
|
|
|
|
|
|
|
unsigned NextArgCode = 0;
|
2012-05-16 14:34:44 +08:00
|
|
|
if (Int.IS.RetVTs.empty())
|
|
|
|
TypeSig.push_back(IIT_Done);
|
|
|
|
else if (Int.IS.RetVTs.size() == 1 &&
|
|
|
|
Int.IS.RetVTs[0] == MVT::isVoid)
|
|
|
|
TypeSig.push_back(IIT_Done);
|
2012-05-17 13:03:24 +08:00
|
|
|
else {
|
|
|
|
switch (Int.IS.RetVTs.size()) {
|
2012-05-17 23:55:41 +08:00
|
|
|
case 1: break;
|
|
|
|
case 2: TypeSig.push_back(IIT_STRUCT2); break;
|
|
|
|
case 3: TypeSig.push_back(IIT_STRUCT3); break;
|
|
|
|
case 4: TypeSig.push_back(IIT_STRUCT4); break;
|
|
|
|
case 5: TypeSig.push_back(IIT_STRUCT5); break;
|
2017-10-13 01:40:00 +08:00
|
|
|
case 6: TypeSig.push_back(IIT_STRUCT6); break;
|
|
|
|
case 7: TypeSig.push_back(IIT_STRUCT7); break;
|
|
|
|
case 8: TypeSig.push_back(IIT_STRUCT8); break;
|
2020-09-30 18:01:15 +08:00
|
|
|
case 9: TypeSig.push_back(IIT_STRUCT9); break;
|
2014-06-18 13:05:13 +08:00
|
|
|
default: llvm_unreachable("Unhandled case in struct");
|
2012-05-17 13:03:24 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 13:03:24 +08:00
|
|
|
for (unsigned i = 0, e = Int.IS.RetVTs.size(); i != e; ++i)
|
2019-06-13 16:19:33 +08:00
|
|
|
EncodeFixedType(Int.IS.RetTypeDefs[i], ArgCodes, NextArgCode, TypeSig,
|
|
|
|
ArgMapping);
|
2012-05-17 13:03:24 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
for (unsigned i = 0, e = Int.IS.ParamTypeDefs.size(); i != e; ++i)
|
2019-06-13 16:19:33 +08:00
|
|
|
EncodeFixedType(Int.IS.ParamTypeDefs[i], ArgCodes, NextArgCode, TypeSig,
|
|
|
|
ArgMapping);
|
2012-05-17 23:55:41 +08:00
|
|
|
}
|
|
|
|
|
2012-06-11 23:37:55 +08:00
|
|
|
static void printIITEntry(raw_ostream &OS, unsigned char X) {
|
2012-05-17 23:55:41 +08:00
|
|
|
OS << (unsigned)X;
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 00:31:37 +08:00
|
|
|
void IntrinsicEmitter::EmitGenerator(const CodeGenIntrinsicTable &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2012-05-16 14:34:44 +08:00
|
|
|
// If we can compute a 32-bit fixed encoding for this intrinsic, do so and
|
|
|
|
// capture it in this vector, otherwise store a ~0U.
|
|
|
|
std::vector<unsigned> FixedEncodings;
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
SequenceToOffsetTable<std::vector<unsigned char> > LongEncodingTable;
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
std::vector<unsigned char> TypeSig;
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
// Compute the unique argument type info.
|
2012-05-16 14:34:44 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2012-05-17 23:55:41 +08:00
|
|
|
// Get the signature for the intrinsic.
|
|
|
|
TypeSig.clear();
|
|
|
|
ComputeFixedEncoding(Ints[i], TypeSig);
|
|
|
|
|
|
|
|
// Check to see if we can encode it into a 32-bit word. We can only encode
|
|
|
|
// 8 nibbles into a 32-bit word.
|
|
|
|
if (TypeSig.size() <= 8) {
|
|
|
|
bool Failed = false;
|
|
|
|
unsigned Result = 0;
|
|
|
|
for (unsigned i = 0, e = TypeSig.size(); i != e; ++i) {
|
|
|
|
// If we had an unencodable argument, bail out.
|
|
|
|
if (TypeSig[i] > 15) {
|
|
|
|
Failed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Result = (Result << 4) | TypeSig[e-i-1];
|
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
// If this could be encoded into a 31-bit word, return it.
|
|
|
|
if (!Failed && (Result >> 31) == 0) {
|
|
|
|
FixedEncodings.push_back(Result);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we're going to unique the sequence into the
|
|
|
|
// LongEncodingTable, and use its offset in the 32-bit table instead.
|
|
|
|
LongEncodingTable.add(TypeSig);
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
// This is a placehold that we'll replace after the table is laid out.
|
|
|
|
FixedEncodings.push_back(~0U);
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
LongEncodingTable.layout();
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-28 02:28:35 +08:00
|
|
|
OS << "// Global intrinsic function declaration type table.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_GENERATOR_GLOBAL\n";
|
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
OS << "static const unsigned IIT_Table[] = {\n ";
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
for (unsigned i = 0, e = FixedEncodings.size(); i != e; ++i) {
|
|
|
|
if ((i & 7) == 7)
|
|
|
|
OS << "\n ";
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
// If the entry fit in the table, just emit it.
|
|
|
|
if (FixedEncodings[i] != ~0U) {
|
2017-12-29 00:58:54 +08:00
|
|
|
OS << "0x" << Twine::utohexstr(FixedEncodings[i]) << ", ";
|
2012-05-17 23:55:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
TypeSig.clear();
|
|
|
|
ComputeFixedEncoding(Ints[i], TypeSig);
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
// Otherwise, emit the offset into the long encoding table. We emit it this
|
|
|
|
// way so that it is easier to read the offset in the .def file.
|
|
|
|
OS << "(1U<<31) | " << LongEncodingTable.get(TypeSig) << ", ";
|
2007-02-08 04:38:26 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
OS << "0\n};\n\n";
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
// Emit the shared table of register lists.
|
|
|
|
OS << "static const unsigned char IIT_LongEncodingTable[] = {\n";
|
|
|
|
if (!LongEncodingTable.empty())
|
|
|
|
LongEncodingTable.emit(OS, printIITEntry);
|
|
|
|
OS << " 255\n};\n\n";
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-05-23 20:34:56 +08:00
|
|
|
OS << "#endif\n\n"; // End of GET_INTRINSIC_GENERATOR_GLOBAL
|
2007-02-08 04:38:26 +08:00
|
|
|
}
|
|
|
|
|
2012-06-11 23:37:55 +08:00
|
|
|
namespace {
|
|
|
|
struct AttributeComparator {
|
|
|
|
bool operator()(const CodeGenIntrinsic *L, const CodeGenIntrinsic *R) const {
|
|
|
|
// Sort throwing intrinsics after non-throwing intrinsics.
|
|
|
|
if (L->canThrow != R->canThrow)
|
|
|
|
return R->canThrow;
|
|
|
|
|
2014-03-19 07:51:07 +08:00
|
|
|
if (L->isNoDuplicate != R->isNoDuplicate)
|
|
|
|
return R->isNoDuplicate;
|
|
|
|
|
2021-03-02 22:16:26 +08:00
|
|
|
if (L->isNoMerge != R->isNoMerge)
|
|
|
|
return R->isNoMerge;
|
|
|
|
|
2012-06-11 23:37:55 +08:00
|
|
|
if (L->isNoReturn != R->isNoReturn)
|
|
|
|
return R->isNoReturn;
|
|
|
|
|
2020-03-17 21:52:06 +08:00
|
|
|
if (L->isNoSync != R->isNoSync)
|
|
|
|
return R->isNoSync;
|
|
|
|
|
2020-06-30 17:04:54 +08:00
|
|
|
if (L->isNoFree != R->isNoFree)
|
|
|
|
return R->isNoFree;
|
|
|
|
|
2019-07-17 23:15:43 +08:00
|
|
|
if (L->isWillReturn != R->isWillReturn)
|
|
|
|
return R->isWillReturn;
|
|
|
|
|
2018-11-15 03:53:41 +08:00
|
|
|
if (L->isCold != R->isCold)
|
|
|
|
return R->isCold;
|
|
|
|
|
2015-05-27 07:48:40 +08:00
|
|
|
if (L->isConvergent != R->isConvergent)
|
|
|
|
return R->isConvergent;
|
|
|
|
|
2017-04-29 04:25:27 +08:00
|
|
|
if (L->isSpeculatable != R->isSpeculatable)
|
|
|
|
return R->isSpeculatable;
|
|
|
|
|
2017-04-29 05:01:46 +08:00
|
|
|
if (L->hasSideEffects != R->hasSideEffects)
|
|
|
|
return R->hasSideEffects;
|
|
|
|
|
2012-06-11 23:37:55 +08:00
|
|
|
// Try to order by readonly/readnone attribute.
|
2016-04-20 05:58:33 +08:00
|
|
|
CodeGenIntrinsic::ModRefBehavior LK = L->ModRef;
|
|
|
|
CodeGenIntrinsic::ModRefBehavior RK = R->ModRef;
|
2012-06-11 23:37:55 +08:00
|
|
|
if (LK != RK) return (LK > RK);
|
|
|
|
// Order by argument attributes.
|
|
|
|
// This is reliable because each side is already sorted internally.
|
|
|
|
return (L->ArgumentAttributes < R->ArgumentAttributes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
2009-01-12 09:18:58 +08:00
|
|
|
/// EmitAttributes - This emits the Intrinsic::getAttributes method.
|
2016-07-16 00:31:37 +08:00
|
|
|
void IntrinsicEmitter::EmitAttributes(const CodeGenIntrinsicTable &Ints,
|
|
|
|
raw_ostream &OS) {
|
2007-12-04 04:06:50 +08:00
|
|
|
OS << "// Add parameter attributes that are not common to all intrinsics.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
|
2019-12-11 23:37:16 +08:00
|
|
|
OS << "AttributeList Intrinsic::getAttributes(LLVMContext &C, ID id) {\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
|
2012-02-28 14:32:00 +08:00
|
|
|
// Compute the maximum number of attribute arguments and the map
|
|
|
|
typedef std::map<const CodeGenIntrinsic*, unsigned,
|
|
|
|
AttributeComparator> UniqAttrMapTy;
|
|
|
|
UniqAttrMapTy UniqAttributes;
|
2011-05-28 14:31:34 +08:00
|
|
|
unsigned maxArgAttrs = 0;
|
2012-02-28 14:32:00 +08:00
|
|
|
unsigned AttrNum = 0;
|
2006-03-10 06:37:52 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2011-05-28 14:31:34 +08:00
|
|
|
const CodeGenIntrinsic &intrinsic = Ints[i];
|
|
|
|
maxArgAttrs =
|
|
|
|
std::max(maxArgAttrs, unsigned(intrinsic.ArgumentAttributes.size()));
|
2012-02-28 14:32:00 +08:00
|
|
|
unsigned &N = UniqAttributes[&intrinsic];
|
|
|
|
if (N) continue;
|
|
|
|
N = ++AttrNum;
|
2021-01-28 12:34:35 +08:00
|
|
|
assert(N < 65536 && "Too many unique attributes for table!");
|
2006-03-10 06:37:52 +08:00
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
// Emit an array of AttributeList. Most intrinsics will have at least one
|
2013-01-27 11:25:05 +08:00
|
|
|
// entry, for the function itself (index ~1), which is usually nounwind.
|
2021-01-28 12:34:35 +08:00
|
|
|
OS << " static const uint16_t IntrinsicsToAttributesMap[] = {\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
|
2012-02-28 14:32:00 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
const CodeGenIntrinsic &intrinsic = Ints[i];
|
2011-05-28 14:31:34 +08:00
|
|
|
|
2012-02-28 14:32:00 +08:00
|
|
|
OS << " " << UniqAttributes[&intrinsic] << ", // "
|
|
|
|
<< intrinsic.Name << "\n";
|
|
|
|
}
|
|
|
|
OS << " };\n\n";
|
2009-01-12 09:27:55 +08:00
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
OS << " AttributeList AS[" << maxArgAttrs + 1 << "];\n";
|
2012-02-28 14:32:00 +08:00
|
|
|
OS << " unsigned NumAttrs = 0;\n";
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " if (id != 0) {\n";
|
2019-12-11 23:37:16 +08:00
|
|
|
OS << " switch(IntrinsicsToAttributesMap[id - 1]) {\n";
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " default: llvm_unreachable(\"Invalid attribute number\");\n";
|
2012-02-28 14:32:00 +08:00
|
|
|
for (UniqAttrMapTy::const_iterator I = UniqAttributes.begin(),
|
|
|
|
E = UniqAttributes.end(); I != E; ++I) {
|
2013-11-16 08:20:01 +08:00
|
|
|
OS << " case " << I->second << ": {\n";
|
2009-01-12 09:27:55 +08:00
|
|
|
|
2012-02-28 14:32:00 +08:00
|
|
|
const CodeGenIntrinsic &intrinsic = *(I->first);
|
2011-05-28 14:31:34 +08:00
|
|
|
|
|
|
|
// Keep track of the number of attributes we're writing out.
|
|
|
|
unsigned numAttrs = 0;
|
2009-01-12 09:27:55 +08:00
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
// The argument attributes are alreadys sorted by argument index.
|
2012-10-10 14:13:42 +08:00
|
|
|
unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size();
|
|
|
|
if (ae) {
|
|
|
|
while (ai != ae) {
|
2020-05-28 03:58:07 +08:00
|
|
|
unsigned attrIdx = intrinsic.ArgumentAttributes[ai].Index;
|
2012-02-28 14:32:00 +08:00
|
|
|
|
2017-05-04 02:17:31 +08:00
|
|
|
OS << " const Attribute::AttrKind AttrParam" << attrIdx << "[]= {";
|
2021-02-07 03:17:08 +08:00
|
|
|
ListSeparator LS(",");
|
2011-05-28 14:31:34 +08:00
|
|
|
|
2020-05-28 04:02:15 +08:00
|
|
|
bool AllValuesAreZero = true;
|
|
|
|
SmallVector<uint64_t, 8> Values;
|
2012-10-10 14:13:42 +08:00
|
|
|
do {
|
2020-05-28 03:58:07 +08:00
|
|
|
switch (intrinsic.ArgumentAttributes[ai].Kind) {
|
2012-10-10 14:13:42 +08:00
|
|
|
case CodeGenIntrinsic::NoCapture:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::NoCapture";
|
2012-10-10 14:13:42 +08:00
|
|
|
break;
|
2019-08-14 16:33:07 +08:00
|
|
|
case CodeGenIntrinsic::NoAlias:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::NoAlias";
|
2019-08-14 16:33:07 +08:00
|
|
|
break;
|
2020-08-26 03:50:29 +08:00
|
|
|
case CodeGenIntrinsic::NoUndef:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::NoUndef";
|
2020-08-26 03:50:29 +08:00
|
|
|
break;
|
2016-07-11 09:28:42 +08:00
|
|
|
case CodeGenIntrinsic::Returned:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::Returned";
|
2016-07-11 09:28:42 +08:00
|
|
|
break;
|
2013-07-06 08:29:58 +08:00
|
|
|
case CodeGenIntrinsic::ReadOnly:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::ReadOnly";
|
2013-07-06 08:29:58 +08:00
|
|
|
break;
|
2016-07-04 16:01:29 +08:00
|
|
|
case CodeGenIntrinsic::WriteOnly:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::WriteOnly";
|
2016-07-04 16:01:29 +08:00
|
|
|
break;
|
2013-07-06 08:29:58 +08:00
|
|
|
case CodeGenIntrinsic::ReadNone:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::ReadNone";
|
2013-07-06 08:29:58 +08:00
|
|
|
break;
|
2019-03-13 05:02:54 +08:00
|
|
|
case CodeGenIntrinsic::ImmArg:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::ImmArg";
|
2019-03-13 05:02:54 +08:00
|
|
|
break;
|
2020-05-28 04:02:15 +08:00
|
|
|
case CodeGenIntrinsic::Alignment:
|
2021-02-07 03:17:08 +08:00
|
|
|
OS << LS << "Attribute::Alignment";
|
2020-05-28 04:02:15 +08:00
|
|
|
break;
|
2012-10-10 14:13:42 +08:00
|
|
|
}
|
2020-05-28 04:02:15 +08:00
|
|
|
uint64_t V = intrinsic.ArgumentAttributes[ai].Value;
|
|
|
|
Values.push_back(V);
|
|
|
|
AllValuesAreZero &= (V == 0);
|
2009-01-12 10:41:37 +08:00
|
|
|
|
2012-10-10 14:13:42 +08:00
|
|
|
++ai;
|
2020-05-28 03:58:07 +08:00
|
|
|
} while (ai != ae && intrinsic.ArgumentAttributes[ai].Index == attrIdx);
|
2013-11-16 08:20:01 +08:00
|
|
|
OS << "};\n";
|
2020-05-28 04:02:15 +08:00
|
|
|
|
|
|
|
// Generate attribute value array if not all attribute values are zero.
|
|
|
|
if (!AllValuesAreZero) {
|
|
|
|
OS << " const uint64_t AttrValParam" << attrIdx << "[]= {";
|
2021-02-07 03:17:08 +08:00
|
|
|
ListSeparator LSV(",");
|
|
|
|
for (const auto V : Values)
|
|
|
|
OS << LSV << V;
|
2020-05-28 04:02:15 +08:00
|
|
|
OS << "};\n";
|
|
|
|
}
|
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
OS << " AS[" << numAttrs++ << "] = AttributeList::get(C, "
|
2020-05-28 04:02:15 +08:00
|
|
|
<< attrIdx << ", AttrParam" << attrIdx;
|
|
|
|
if (!AllValuesAreZero)
|
|
|
|
OS << ", AttrValParam" << attrIdx;
|
|
|
|
OS << ");\n";
|
2012-10-10 14:13:42 +08:00
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
}
|
|
|
|
|
2015-08-14 01:40:04 +08:00
|
|
|
if (!intrinsic.canThrow ||
|
2020-06-30 17:04:54 +08:00
|
|
|
(intrinsic.ModRef != CodeGenIntrinsic::ReadWriteMem &&
|
|
|
|
!intrinsic.hasSideEffects) ||
|
|
|
|
intrinsic.isNoReturn || intrinsic.isNoSync || intrinsic.isNoFree ||
|
|
|
|
intrinsic.isWillReturn || intrinsic.isCold || intrinsic.isNoDuplicate ||
|
2021-03-02 22:16:26 +08:00
|
|
|
intrinsic.isNoMerge || intrinsic.isConvergent ||
|
|
|
|
intrinsic.isSpeculatable) {
|
2013-11-16 08:20:01 +08:00
|
|
|
OS << " const Attribute::AttrKind Atts[] = {";
|
2021-02-08 01:49:34 +08:00
|
|
|
ListSeparator LS(",");
|
|
|
|
if (!intrinsic.canThrow)
|
|
|
|
OS << LS << "Attribute::NoUnwind";
|
|
|
|
if (intrinsic.isNoReturn)
|
|
|
|
OS << LS << "Attribute::NoReturn";
|
|
|
|
if (intrinsic.isNoSync)
|
|
|
|
OS << LS << "Attribute::NoSync";
|
|
|
|
if (intrinsic.isNoFree)
|
|
|
|
OS << LS << "Attribute::NoFree";
|
|
|
|
if (intrinsic.isWillReturn)
|
|
|
|
OS << LS << "Attribute::WillReturn";
|
|
|
|
if (intrinsic.isCold)
|
|
|
|
OS << LS << "Attribute::Cold";
|
|
|
|
if (intrinsic.isNoDuplicate)
|
|
|
|
OS << LS << "Attribute::NoDuplicate";
|
2021-03-02 22:16:26 +08:00
|
|
|
if (intrinsic.isNoMerge)
|
|
|
|
OS << LS << "Attribute::NoMerge";
|
2021-02-08 01:49:34 +08:00
|
|
|
if (intrinsic.isConvergent)
|
|
|
|
OS << LS << "Attribute::Convergent";
|
|
|
|
if (intrinsic.isSpeculatable)
|
|
|
|
OS << LS << "Attribute::Speculatable";
|
2012-05-28 07:20:41 +08:00
|
|
|
|
2015-08-14 01:40:04 +08:00
|
|
|
switch (intrinsic.ModRef) {
|
|
|
|
case CodeGenIntrinsic::NoMem:
|
2019-07-17 18:53:13 +08:00
|
|
|
if (intrinsic.hasSideEffects)
|
|
|
|
break;
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2015-08-14 01:40:04 +08:00
|
|
|
OS << "Attribute::ReadNone";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadArgMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2015-08-14 01:40:04 +08:00
|
|
|
OS << "Attribute::ReadOnly,";
|
|
|
|
OS << "Attribute::ArgMemOnly";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2013-11-16 08:20:01 +08:00
|
|
|
OS << "Attribute::ReadOnly";
|
2012-05-28 07:20:41 +08:00
|
|
|
break;
|
2016-11-23 03:16:04 +08:00
|
|
|
case CodeGenIntrinsic::ReadInaccessibleMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-11-23 03:16:04 +08:00
|
|
|
OS << "Attribute::ReadOnly,";
|
|
|
|
OS << "Attribute::InaccessibleMemOnly";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadInaccessibleMemOrArgMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-11-23 03:16:04 +08:00
|
|
|
OS << "Attribute::ReadOnly,";
|
|
|
|
OS << "Attribute::InaccessibleMemOrArgMemOnly";
|
|
|
|
break;
|
2016-04-20 05:58:33 +08:00
|
|
|
case CodeGenIntrinsic::WriteArgMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-07-04 16:01:29 +08:00
|
|
|
OS << "Attribute::WriteOnly,";
|
2015-08-14 01:40:04 +08:00
|
|
|
OS << "Attribute::ArgMemOnly";
|
|
|
|
break;
|
2016-04-20 05:58:33 +08:00
|
|
|
case CodeGenIntrinsic::WriteMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-07-04 16:01:29 +08:00
|
|
|
OS << "Attribute::WriteOnly";
|
|
|
|
break;
|
2016-11-23 03:16:04 +08:00
|
|
|
case CodeGenIntrinsic::WriteInaccessibleMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-11-23 03:16:04 +08:00
|
|
|
OS << "Attribute::WriteOnly,";
|
|
|
|
OS << "Attribute::InaccessibleMemOnly";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::WriteInaccessibleMemOrArgMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-11-23 03:16:04 +08:00
|
|
|
OS << "Attribute::WriteOnly,";
|
2017-12-03 08:03:01 +08:00
|
|
|
OS << "Attribute::InaccessibleMemOrArgMemOnly";
|
2016-11-23 03:16:04 +08:00
|
|
|
break;
|
2016-07-04 16:01:29 +08:00
|
|
|
case CodeGenIntrinsic::ReadWriteArgMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-07-04 16:01:29 +08:00
|
|
|
OS << "Attribute::ArgMemOnly";
|
|
|
|
break;
|
2016-11-23 03:16:04 +08:00
|
|
|
case CodeGenIntrinsic::ReadWriteInaccessibleMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-11-23 03:16:04 +08:00
|
|
|
OS << "Attribute::InaccessibleMemOnly";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadWriteInaccessibleMemOrArgMem:
|
2021-02-08 01:49:34 +08:00
|
|
|
OS << LS;
|
2016-11-23 03:16:04 +08:00
|
|
|
OS << "Attribute::InaccessibleMemOrArgMemOnly";
|
2017-12-20 06:05:25 +08:00
|
|
|
break;
|
2015-08-14 01:40:04 +08:00
|
|
|
case CodeGenIntrinsic::ReadWriteMem:
|
2012-05-28 07:20:41 +08:00
|
|
|
break;
|
2009-01-12 10:41:37 +08:00
|
|
|
}
|
2013-11-16 08:20:01 +08:00
|
|
|
OS << "};\n";
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
OS << " AS[" << numAttrs++ << "] = AttributeList::get(C, "
|
|
|
|
<< "AttributeList::FunctionIndex, Atts);\n";
|
2009-01-12 10:41:37 +08:00
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
|
|
|
|
if (numAttrs) {
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " NumAttrs = " << numAttrs << ";\n";
|
|
|
|
OS << " break;\n";
|
2013-11-16 08:20:01 +08:00
|
|
|
OS << " }\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
} else {
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
OS << " return AttributeList();\n";
|
2014-02-21 07:57:31 +08:00
|
|
|
OS << " }\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
}
|
2009-01-12 09:27:55 +08:00
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " }\n";
|
2009-01-12 09:27:55 +08:00
|
|
|
OS << " }\n";
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
OS << " return AttributeList::get(C, makeArrayRef(AS, NumAttrs));\n";
|
2009-01-12 09:18:58 +08:00
|
|
|
OS << "}\n";
|
2009-01-12 10:41:37 +08:00
|
|
|
OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
|
2006-03-10 06:37:52 +08:00
|
|
|
}
|
2006-03-14 07:08:44 +08:00
|
|
|
|
2016-01-27 09:43:12 +08:00
|
|
|
void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(
|
2016-07-16 00:31:37 +08:00
|
|
|
const CodeGenIntrinsicTable &Ints, bool IsGCC, raw_ostream &OS) {
|
2016-01-27 09:43:12 +08:00
|
|
|
StringRef CompilerName = (IsGCC ? "GCC" : "MS");
|
|
|
|
typedef std::map<std::string, std::map<std::string, std::string>> BIMTy;
|
2006-03-15 09:33:26 +08:00
|
|
|
BIMTy BuiltinMap;
|
2016-01-27 09:43:12 +08:00
|
|
|
StringToOffsetTable Table;
|
2006-03-15 09:33:26 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2016-01-27 09:43:12 +08:00
|
|
|
const std::string &BuiltinName =
|
|
|
|
IsGCC ? Ints[i].GCCBuiltinName : Ints[i].MSBuiltinName;
|
|
|
|
if (!BuiltinName.empty()) {
|
2008-01-03 05:24:22 +08:00
|
|
|
// Get the map for this target prefix.
|
2016-01-27 09:43:12 +08:00
|
|
|
std::map<std::string, std::string> &BIM =
|
|
|
|
BuiltinMap[Ints[i].TargetPrefix];
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2016-01-27 09:43:12 +08:00
|
|
|
if (!BIM.insert(std::make_pair(BuiltinName, Ints[i].EnumName)).second)
|
[tablegen] Add locations to many PrintFatalError() calls
Summary:
While working on the GISel Combiner, I noticed I was producing location-less
error messages fairly often and set about fixing this. In the process, I
noticed quite a few places elsewhere in TableGen that also neglected to include
a relevant location.
This patch adds locations to errors that relate to a specific record (or a
field within it) and also have easy access to the relevant location. This is
particularly useful when multiclasses are involved as many of these errors
refer to the full name of a record and it's difficult to guess which substring
is grep-able.
Unfortunately, tablegen currently only supports Record granularity so it's not
currently possible to point at a specific Init so these sometimes point at the
record that caused the error rather than the precise origin of the error.
Reviewers: bogner, aditya_nandakumar, volkan, aemerson, paquette, nhaehnle
Reviewed By: nhaehnle
Subscribers: jdoerfert, nhaehnle, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58077
llvm-svn: 353862
2019-02-13 01:36:57 +08:00
|
|
|
PrintFatalError(Ints[i].TheDef->getLoc(),
|
|
|
|
"Intrinsic '" + Ints[i].TheDef->getName() +
|
|
|
|
"': duplicate " + CompilerName + " builtin name!");
|
2016-01-27 09:43:12 +08:00
|
|
|
Table.GetOrAddStringOffset(BuiltinName);
|
2006-03-15 09:33:26 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2016-01-27 09:43:12 +08:00
|
|
|
OS << "// Get the LLVM intrinsic that corresponds to a builtin.\n";
|
|
|
|
OS << "// This is used by the C front-end. The builtin name is passed\n";
|
2006-03-15 09:33:26 +08:00
|
|
|
OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
|
|
|
|
OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
|
2016-01-27 09:43:12 +08:00
|
|
|
OS << "#ifdef GET_LLVM_INTRINSIC_FOR_" << CompilerName << "_BUILTIN\n";
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2019-12-11 23:37:16 +08:00
|
|
|
OS << "Intrinsic::ID Intrinsic::getIntrinsicFor" << CompilerName
|
|
|
|
<< "Builtin(const char "
|
|
|
|
<< "*TargetPrefixStr, StringRef BuiltinNameStr) {\n";
|
2017-04-20 03:14:20 +08:00
|
|
|
|
|
|
|
if (Table.Empty()) {
|
2019-12-11 23:37:16 +08:00
|
|
|
OS << " return Intrinsic::not_intrinsic;\n";
|
2017-04-20 03:14:20 +08:00
|
|
|
OS << "}\n";
|
|
|
|
OS << "#endif\n\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-27 09:43:12 +08:00
|
|
|
OS << " static const char BuiltinNames[] = {\n";
|
|
|
|
Table.EmitCharArray(OS);
|
|
|
|
OS << " };\n\n";
|
|
|
|
|
|
|
|
OS << " struct BuiltinEntry {\n";
|
|
|
|
OS << " Intrinsic::ID IntrinID;\n";
|
|
|
|
OS << " unsigned StrTabOffset;\n";
|
|
|
|
OS << " const char *getName() const {\n";
|
|
|
|
OS << " return &BuiltinNames[StrTabOffset];\n";
|
|
|
|
OS << " }\n";
|
2016-10-11 03:31:09 +08:00
|
|
|
OS << " bool operator<(StringRef RHS) const {\n";
|
|
|
|
OS << " return strncmp(getName(), RHS.data(), RHS.size()) < 0;\n";
|
2016-01-27 09:43:12 +08:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " };\n";
|
|
|
|
|
2010-09-06 11:14:45 +08:00
|
|
|
OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2006-03-15 09:33:26 +08:00
|
|
|
// Note: this could emit significantly better code if we cared.
|
|
|
|
for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
|
2008-01-03 05:24:22 +08:00
|
|
|
OS << " ";
|
|
|
|
if (!I->first.empty())
|
2010-09-06 11:14:45 +08:00
|
|
|
OS << "if (TargetPrefix == \"" << I->first << "\") ";
|
2008-01-03 05:24:22 +08:00
|
|
|
else
|
|
|
|
OS << "/* Target Independent Builtins */ ";
|
|
|
|
OS << "{\n";
|
|
|
|
|
|
|
|
// Emit the comparisons for this target prefix.
|
2016-01-27 09:43:12 +08:00
|
|
|
OS << " static const BuiltinEntry " << I->first << "Names[] = {\n";
|
|
|
|
for (const auto &P : I->second) {
|
|
|
|
OS << " {Intrinsic::" << P.second << ", "
|
|
|
|
<< Table.GetOrAddStringOffset(P.first) << "}, // " << P.first << "\n";
|
|
|
|
}
|
|
|
|
OS << " };\n";
|
|
|
|
OS << " auto I = std::lower_bound(std::begin(" << I->first << "Names),\n";
|
|
|
|
OS << " std::end(" << I->first << "Names),\n";
|
|
|
|
OS << " BuiltinNameStr);\n";
|
|
|
|
OS << " if (I != std::end(" << I->first << "Names) &&\n";
|
2016-10-11 03:31:09 +08:00
|
|
|
OS << " I->getName() == BuiltinNameStr)\n";
|
2016-01-27 09:43:12 +08:00
|
|
|
OS << " return I->IntrinID;\n";
|
2008-01-03 05:24:22 +08:00
|
|
|
OS << " }\n";
|
2006-03-15 09:33:26 +08:00
|
|
|
}
|
2010-09-06 11:14:45 +08:00
|
|
|
OS << " return ";
|
|
|
|
OS << "Intrinsic::not_intrinsic;\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
OS << "}\n";
|
2006-03-15 09:33:26 +08:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
2012-06-11 23:37:55 +08:00
|
|
|
|
2019-12-11 23:37:16 +08:00
|
|
|
void llvm::EmitIntrinsicEnums(RecordKeeper &RK, raw_ostream &OS) {
|
|
|
|
IntrinsicEmitter(RK).run(OS, /*Enums=*/true);
|
2018-06-23 10:02:38 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 23:37:16 +08:00
|
|
|
void llvm::EmitIntrinsicImpl(RecordKeeper &RK, raw_ostream &OS) {
|
|
|
|
IntrinsicEmitter(RK).run(OS, /*Enums=*/false);
|
2012-06-11 23:37:55 +08:00
|
|
|
}
|