2006-03-03 10:32:46 +08:00
|
|
|
//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:37:13 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-03-03 10:32:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits information about intrinsic functions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-08-04 09:51:18 +08:00
|
|
|
#include "CodeGenTarget.h"
|
2006-03-03 10:32:46 +08:00
|
|
|
#include "IntrinsicEmitter.h"
|
2012-05-17 23:55:41 +08:00
|
|
|
#include "SequenceToOffsetTable.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"
|
2006-03-14 06:38:57 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2006-03-15 10:51:05 +08:00
|
|
|
#include <algorithm>
|
2006-03-03 10:32:46 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IntrinsicEmitter Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-03 08:10:29 +08:00
|
|
|
void IntrinsicEmitter::run(raw_ostream &OS) {
|
2006-03-03 10:32:46 +08:00
|
|
|
EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
|
|
|
|
|
2009-02-05 09:49:45 +08:00
|
|
|
std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
|
|
|
|
|
|
|
|
if (TargetOnly && !Ints.empty())
|
|
|
|
TargetPrefix = Ints[0].TargetPrefix;
|
2006-03-03 10:32:46 +08:00
|
|
|
|
2010-05-11 14:17:44 +08:00
|
|
|
EmitPrefix(OS);
|
|
|
|
|
2006-03-03 10:32:46 +08:00
|
|
|
// Emit the enum information.
|
|
|
|
EmitEnumInfo(Ints, OS);
|
2006-03-15 09:55:21 +08:00
|
|
|
|
|
|
|
// Emit the intrinsic ID -> name table.
|
|
|
|
EmitIntrinsicToNameTable(Ints, OS);
|
2009-02-25 07:17:49 +08:00
|
|
|
|
|
|
|
// Emit the intrinsic ID -> overload table.
|
|
|
|
EmitIntrinsicToOverloadTable(Ints, OS);
|
|
|
|
|
2006-03-10 04:34:19 +08:00
|
|
|
// Emit the function name recognizer.
|
|
|
|
EmitFnNameRecognizer(Ints, OS);
|
2006-03-15 09:55:21 +08:00
|
|
|
|
2006-03-10 06:05:04 +08:00
|
|
|
// Emit the intrinsic verifier.
|
|
|
|
EmitVerifier(Ints, OS);
|
2006-03-10 06:30:49 +08:00
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
// Emit the intrinsic declaration generator.
|
|
|
|
EmitGenerator(Ints, OS);
|
|
|
|
|
2007-12-04 04:06:50 +08:00
|
|
|
// Emit the intrinsic parameter attributes.
|
|
|
|
EmitAttributes(Ints, OS);
|
2006-03-14 07:08:44 +08:00
|
|
|
|
2009-02-14 18:56:35 +08:00
|
|
|
// Emit intrinsic alias analysis mod/ref behavior.
|
|
|
|
EmitModRefBehavior(Ints, OS);
|
|
|
|
|
2006-03-15 09:33:26 +08:00
|
|
|
// Emit code to translate GCC builtins into LLVM intrinsics.
|
|
|
|
EmitIntrinsicToGCCBuiltinMap(Ints, OS);
|
2010-05-11 14:17:44 +08:00
|
|
|
|
|
|
|
EmitSuffix(OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitPrefix(raw_ostream &OS) {
|
|
|
|
OS << "// VisualStudio defines setjmp as _setjmp\n"
|
2010-09-25 03:48:47 +08:00
|
|
|
"#if defined(_MSC_VER) && defined(setjmp) && \\\n"
|
|
|
|
" !defined(setjmp_undefined_for_msvc)\n"
|
2010-09-14 12:27:38 +08:00
|
|
|
"# pragma push_macro(\"setjmp\")\n"
|
|
|
|
"# undef setjmp\n"
|
2010-09-25 03:48:47 +08:00
|
|
|
"# define setjmp_undefined_for_msvc\n"
|
2010-05-11 14:17:44 +08:00
|
|
|
"#endif\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) {
|
2010-09-25 03:48:47 +08:00
|
|
|
OS << "#if defined(_MSC_VER) && defined(setjmp_undefined_for_msvc)\n"
|
2010-05-11 14:17:44 +08:00
|
|
|
"// let's return it to _setjmp state\n"
|
2010-09-14 12:27:38 +08:00
|
|
|
"# pragma pop_macro(\"setjmp\")\n"
|
2010-09-25 03:48:47 +08:00
|
|
|
"# undef setjmp_undefined_for_msvc\n"
|
2010-05-11 14:17:44 +08:00
|
|
|
"#endif\n\n";
|
2006-03-03 10:32:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2006-03-10 04:34:19 +08:00
|
|
|
OS << "// Enum values for Intrinsics.h\n";
|
2006-03-03 10:32:46 +08:00
|
|
|
OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
OS << " " << Ints[i].EnumName;
|
|
|
|
OS << ((i != e-1) ? ", " : " ");
|
|
|
|
OS << std::string(40-Ints[i].EnumName.size(), ' ')
|
|
|
|
<< "// " << Ints[i].Name << "\n";
|
|
|
|
}
|
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
2006-03-10 04:34:19 +08:00
|
|
|
|
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2010-09-06 11:58:45 +08:00
|
|
|
// Build a 'first character of function name' -> intrinsic # mapping.
|
|
|
|
std::map<char, std::vector<unsigned> > IntMapping;
|
2006-03-10 04:34:19 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
2010-09-06 11:58:45 +08:00
|
|
|
IntMapping[Ints[i].Name[5]].push_back(i);
|
|
|
|
|
2006-03-10 04:34:19 +08:00
|
|
|
OS << "// Function name -> enum value recognizer code.\n";
|
|
|
|
OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
|
2010-09-06 11:58:45 +08:00
|
|
|
OS << " StringRef NameR(Name+6, Len-6); // Skip over 'llvm.'\n";
|
|
|
|
OS << " switch (Name[5]) { // Dispatch on first letter.\n";
|
|
|
|
OS << " default: break;\n";
|
|
|
|
// Emit the intrinsic matching stuff by first letter.
|
|
|
|
for (std::map<char, std::vector<unsigned> >::iterator I = IntMapping.begin(),
|
2006-03-10 04:34:19 +08:00
|
|
|
E = IntMapping.end(); I != E; ++I) {
|
2010-09-06 11:58:45 +08:00
|
|
|
OS << " case '" << I->first << "':\n";
|
|
|
|
std::vector<unsigned> &IntList = I->second;
|
|
|
|
|
|
|
|
// Emit all the overloaded intrinsics first, build a table of the
|
|
|
|
// non-overloaded ones.
|
|
|
|
std::vector<StringMatcher::StringPair> MatchTable;
|
2006-03-10 04:34:19 +08:00
|
|
|
|
2010-09-06 11:58:45 +08:00
|
|
|
for (unsigned i = 0, e = IntList.size(); i != e; ++i) {
|
|
|
|
unsigned IntNo = IntList[i];
|
|
|
|
std::string Result = "return " + TargetPrefix + "Intrinsic::" +
|
|
|
|
Ints[IntNo].EnumName + ";";
|
|
|
|
|
|
|
|
if (!Ints[IntNo].isOverloaded) {
|
|
|
|
MatchTable.push_back(std::make_pair(Ints[IntNo].Name.substr(6),Result));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For overloaded intrinsics, only the prefix needs to match
|
|
|
|
std::string TheStr = Ints[IntNo].Name.substr(6);
|
2010-09-06 09:44:44 +08:00
|
|
|
TheStr += '.'; // Require "bswap." instead of bswap.
|
2010-09-06 11:58:45 +08:00
|
|
|
OS << " if (NameR.startswith(\"" << TheStr << "\")) "
|
|
|
|
<< Result << '\n';
|
2010-09-06 09:44:44 +08:00
|
|
|
}
|
2010-09-06 11:58:45 +08:00
|
|
|
|
|
|
|
// Emit the matcher logic for the fixed length strings.
|
|
|
|
StringMatcher("NameR", MatchTable, OS).Emit(1);
|
|
|
|
OS << " break; // end of '" << I->first << "' case.\n";
|
2006-03-10 04:34:19 +08:00
|
|
|
}
|
2010-09-06 11:58:45 +08:00
|
|
|
|
2006-03-10 04:34:19 +08:00
|
|
|
OS << " }\n";
|
2006-03-10 06:05:04 +08:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2006-03-15 09:55:21 +08:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2009-02-25 07:17:49 +08:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2009-03-27 00:17:51 +08:00
|
|
|
/// RecordListComparator - Provide a deterministic comparator for lists of
|
2006-03-31 12:24:58 +08:00
|
|
|
/// records.
|
|
|
|
namespace {
|
2008-11-13 17:08:33 +08:00
|
|
|
typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
|
2006-03-31 12:24:58 +08:00
|
|
|
struct RecordListComparator {
|
2008-11-13 17:08:33 +08:00
|
|
|
bool operator()(const RecPair &LHS,
|
|
|
|
const RecPair &RHS) const {
|
2006-03-31 12:24:58 +08:00
|
|
|
unsigned i = 0;
|
2008-11-13 17:08:33 +08:00
|
|
|
const std::vector<Record*> *LHSVec = &LHS.first;
|
|
|
|
const std::vector<Record*> *RHSVec = &RHS.first;
|
|
|
|
unsigned RHSSize = RHSVec->size();
|
|
|
|
unsigned LHSSize = LHSVec->size();
|
|
|
|
|
2010-03-23 04:56:36 +08:00
|
|
|
for (; i != LHSSize; ++i) {
|
2008-11-13 17:08:33 +08:00
|
|
|
if (i == RHSSize) return false; // RHS is shorter than LHS.
|
|
|
|
if ((*LHSVec)[i] != (*RHSVec)[i])
|
|
|
|
return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
|
2010-03-23 04:56:36 +08:00
|
|
|
}
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2008-11-13 20:03:00 +08:00
|
|
|
if (i != RHSSize) return true;
|
2008-11-13 17:08:33 +08:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
LHSVec = &LHS.second;
|
|
|
|
RHSVec = &RHS.second;
|
|
|
|
RHSSize = RHSVec->size();
|
|
|
|
LHSSize = LHSVec->size();
|
|
|
|
|
|
|
|
for (i = 0; i != LHSSize; ++i) {
|
|
|
|
if (i == RHSSize) return false; // RHS is shorter than LHS.
|
|
|
|
if ((*LHSVec)[i] != (*RHSVec)[i])
|
|
|
|
return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return i != RHSSize;
|
2006-03-31 12:24:58 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2006-03-10 06:05:04 +08:00
|
|
|
void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2006-03-10 06:05:04 +08:00
|
|
|
OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
|
|
|
|
OS << " switch (ID) {\n";
|
2012-02-05 15:21:30 +08:00
|
|
|
OS << " default: llvm_unreachable(\"Invalid intrinsic!\");\n";
|
2006-03-31 12:24:58 +08:00
|
|
|
|
|
|
|
// This checking can emit a lot of very common code. To reduce the amount of
|
|
|
|
// code that we emit, batch up cases that have identical types. This avoids
|
|
|
|
// problems where GCC can run out of memory compiling Verifier.cpp.
|
2008-11-13 17:08:33 +08:00
|
|
|
typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
|
2006-03-31 12:24:58 +08:00
|
|
|
MapTy UniqueArgInfos;
|
|
|
|
|
|
|
|
// Compute the unique argument type info.
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
2008-11-13 17:08:33 +08:00
|
|
|
UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
|
|
|
|
Ints[i].IS.ParamTypeDefs)].push_back(i);
|
2006-03-31 12:24:58 +08:00
|
|
|
|
|
|
|
// Loop through the array, emitting one comparison for each batch.
|
|
|
|
for (MapTy::iterator I = UniqueArgInfos.begin(),
|
|
|
|
E = UniqueArgInfos.end(); I != E; ++I) {
|
2008-11-13 17:08:33 +08:00
|
|
|
for (unsigned i = 0, e = I->second.size(); i != e; ++i)
|
2006-03-31 12:24:58 +08:00
|
|
|
OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
|
|
|
|
<< Ints[I->second[i]].Name << "\n";
|
2006-03-31 12:48:26 +08:00
|
|
|
|
2008-11-13 17:08:33 +08:00
|
|
|
const RecPair &ArgTypes = I->first;
|
|
|
|
const std::vector<Record*> &RetTys = ArgTypes.first;
|
|
|
|
const std::vector<Record*> &ParamTys = ArgTypes.second;
|
2009-07-30 00:35:59 +08:00
|
|
|
std::vector<unsigned> OverloadedTypeIndices;
|
2008-11-13 17:08:33 +08:00
|
|
|
|
|
|
|
OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
|
|
|
|
<< ParamTys.size();
|
|
|
|
|
|
|
|
// Emit return types.
|
|
|
|
for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
|
|
|
|
Record *ArgType = RetTys[j];
|
|
|
|
OS << ", ";
|
|
|
|
|
2007-08-04 09:51:18 +08:00
|
|
|
if (ArgType->isSubClassOf("LLVMMatchType")) {
|
|
|
|
unsigned Number = ArgType->getValueAsInt("Number");
|
2009-07-30 00:35:59 +08:00
|
|
|
assert(Number < OverloadedTypeIndices.size() &&
|
|
|
|
"Invalid matching number!");
|
|
|
|
Number = OverloadedTypeIndices[Number];
|
2009-01-07 08:09:01 +08:00
|
|
|
if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
|
|
|
|
OS << "~(ExtendedElementVectorType | " << Number << ")";
|
|
|
|
else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
|
|
|
|
OS << "~(TruncatedElementVectorType | " << Number << ")";
|
|
|
|
else
|
|
|
|
OS << "~" << Number;
|
2007-08-04 09:51:18 +08:00
|
|
|
} else {
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
|
2007-08-04 09:51:18 +08:00
|
|
|
OS << getEnumName(VT);
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2009-08-11 09:14:02 +08:00
|
|
|
if (EVT(VT).isOverloaded())
|
2009-07-30 00:35:59 +08:00
|
|
|
OverloadedTypeIndices.push_back(j);
|
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
if (VT == MVT::isVoid && j != 0 && j != je - 1)
|
2008-11-13 17:08:33 +08:00
|
|
|
throw "Var arg type not last argument";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the parameter types.
|
|
|
|
for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
|
|
|
|
Record *ArgType = ParamTys[j];
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
if (ArgType->isSubClassOf("LLVMMatchType")) {
|
|
|
|
unsigned Number = ArgType->getValueAsInt("Number");
|
2009-07-30 00:35:59 +08:00
|
|
|
assert(Number < OverloadedTypeIndices.size() &&
|
|
|
|
"Invalid matching number!");
|
|
|
|
Number = OverloadedTypeIndices[Number];
|
2009-01-07 08:09:01 +08:00
|
|
|
if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
|
|
|
|
OS << "~(ExtendedElementVectorType | " << Number << ")";
|
|
|
|
else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
|
|
|
|
OS << "~(TruncatedElementVectorType | " << Number << ")";
|
|
|
|
else
|
|
|
|
OS << "~" << Number;
|
2008-11-13 17:08:33 +08:00
|
|
|
} else {
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
|
2008-11-13 17:08:33 +08:00
|
|
|
OS << getEnumName(VT);
|
|
|
|
|
2009-08-11 09:14:02 +08:00
|
|
|
if (EVT(VT).isOverloaded())
|
2009-07-30 00:35:59 +08:00
|
|
|
OverloadedTypeIndices.push_back(j + RetTys.size());
|
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
if (VT == MVT::isVoid && j != 0 && j != je - 1)
|
2007-02-07 02:30:58 +08:00
|
|
|
throw "Var arg type not last argument";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-04 09:51:18 +08:00
|
|
|
OS << ");\n";
|
2006-03-10 06:05:04 +08:00
|
|
|
OS << " break;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "#endif\n\n";
|
2006-03-10 04:34:19 +08:00
|
|
|
}
|
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
|
|
|
|
// NOTE: This must be kept in synch with the version emitted to the .gen file!
|
|
|
|
enum IIT_Info {
|
2012-05-17 12:30:58 +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,
|
|
|
|
IIT_F32 = 6,
|
|
|
|
IIT_F64 = 7,
|
|
|
|
IIT_V2 = 8,
|
|
|
|
IIT_V4 = 9,
|
|
|
|
IIT_V8 = 10,
|
|
|
|
IIT_V16 = 11,
|
2012-05-17 13:03:24 +08:00
|
|
|
IIT_V32 = 12,
|
|
|
|
IIT_MMX = 13,
|
|
|
|
IIT_PTR = 14,
|
|
|
|
IIT_ARG = 15,
|
2012-05-17 12:30:58 +08:00
|
|
|
|
|
|
|
// Values from 16+ are only encodable with the inefficient encoding.
|
2012-05-17 13:03:24 +08:00
|
|
|
IIT_METADATA = 16,
|
|
|
|
IIT_EMPTYSTRUCT = 17,
|
|
|
|
IIT_STRUCT2 = 18,
|
|
|
|
IIT_STRUCT3 = 19,
|
|
|
|
IIT_STRUCT4 = 20,
|
|
|
|
IIT_STRUCT5 = 21,
|
|
|
|
IIT_EXTEND_VEC_ARG = 22,
|
|
|
|
IIT_TRUNC_VEC_ARG = 23
|
2012-05-16 14:34:44 +08:00
|
|
|
};
|
|
|
|
|
2012-05-17 12:30:58 +08:00
|
|
|
|
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) {
|
2012-05-16 14:34:44 +08:00
|
|
|
if (EVT(VT).isInteger()) {
|
|
|
|
unsigned BitWidth = EVT(VT).getSizeInBits();
|
|
|
|
switch (BitWidth) {
|
2012-05-17 13:03:24 +08:00
|
|
|
default: throw "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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-17 12:30:58 +08:00
|
|
|
switch (VT) {
|
2012-05-17 13:03:24 +08:00
|
|
|
default: throw "unhandled MVT in intrinsic!";
|
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);
|
|
|
|
case MVT::Metadata: return Sig.push_back(IIT_METADATA);
|
|
|
|
case MVT::x86mmx: return Sig.push_back(IIT_MMX);
|
|
|
|
// MVT::OtherVT is used to mean the empty struct type here.
|
|
|
|
case MVT::Other: return Sig.push_back(IIT_EMPTYSTRUCT);
|
|
|
|
}
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
2012-05-17 12:00:03 +08:00
|
|
|
#ifdef _MSC_VER
|
2012-05-17 11:38:19 +08:00
|
|
|
#pragma optimize("",off) // MSVC 2010 optimizer can't deal with this function.
|
2012-05-17 12:00:03 +08:00
|
|
|
#endif
|
2012-05-16 14:34:44 +08:00
|
|
|
|
2012-05-17 12:30:58 +08:00
|
|
|
static void EncodeFixedType(Record *R, unsigned &NextArgNo,
|
2012-05-17 23:55:41 +08:00
|
|
|
std::vector<unsigned char> &Sig) {
|
2012-05-16 14:34:44 +08:00
|
|
|
|
|
|
|
if (R->isSubClassOf("LLVMMatchType")) {
|
2012-05-17 12:30:58 +08:00
|
|
|
unsigned Number = R->getValueAsInt("Number");
|
|
|
|
assert(Number < NextArgNo && "Invalid matching number!");
|
|
|
|
if (R->isSubClassOf("LLVMExtendedElementVectorType"))
|
2012-05-17 13:03:24 +08:00
|
|
|
Sig.push_back(IIT_EXTEND_VEC_ARG);
|
|
|
|
else if (R->isSubClassOf("LLVMTruncatedElementVectorType"))
|
|
|
|
Sig.push_back(IIT_TRUNC_VEC_ARG);
|
|
|
|
else
|
|
|
|
Sig.push_back(IIT_ARG);
|
2012-05-17 12:30:58 +08:00
|
|
|
return Sig.push_back(Number);
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MVT::SimpleValueType VT = getValueType(R->getValueAsDef("VT"));
|
2012-05-17 12:30:58 +08:00
|
|
|
|
|
|
|
// If this is an "any" valuetype, then the type is the type of the next
|
|
|
|
// type in the list specified to getIntrinsic().
|
|
|
|
if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny ||
|
2012-05-17 12:07:48 +08:00
|
|
|
VT == MVT::iPTRAny) {
|
2012-05-17 12:30:58 +08:00
|
|
|
Sig.push_back(IIT_ARG);
|
|
|
|
return Sig.push_back(NextArgNo++);
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EVT(VT).isVector()) {
|
|
|
|
EVT VVT = VT;
|
|
|
|
switch (VVT.getVectorNumElements()) {
|
2012-05-17 13:03:24 +08:00
|
|
|
default: throw "unhandled vector type width in intrinsic!";
|
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;
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return EncodeFixedValueType(VVT.getVectorElementType().
|
|
|
|
getSimpleVT().SimpleTy, Sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VT == MVT::iPTR) {
|
|
|
|
Sig.push_back(IIT_PTR);
|
2012-05-22 07:21:28 +08:00
|
|
|
unsigned AddrSpace = 0;
|
|
|
|
if (R->isSubClassOf("LLVMQualPointerType")) {
|
|
|
|
AddrSpace = R->getValueAsInt("AddrSpace");
|
|
|
|
assert(AddrSpace < 256 && "Address space exceeds 255");
|
|
|
|
}
|
|
|
|
Sig.push_back(AddrSpace);
|
2012-05-17 12:30:58 +08:00
|
|
|
return EncodeFixedType(R->getValueAsDef("ElTy"), NextArgNo, Sig);
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EncodeFixedValueType(VT, Sig);
|
|
|
|
}
|
2012-05-17 12:00:03 +08:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2012-05-17 11:38:19 +08:00
|
|
|
#pragma optimize("",on)
|
2012-05-17 12:00:03 +08:00
|
|
|
#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-17 12:30:58 +08:00
|
|
|
unsigned NextArgNo = 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;
|
|
|
|
default: assert(0 && "Unhandled case in struct");
|
2012-05-17 13:03:24 +08:00
|
|
|
}
|
2012-05-17 23:55:41 +08:00
|
|
|
|
2012-05-17 13:03:24 +08:00
|
|
|
for (unsigned i = 0, e = Int.IS.RetVTs.size(); i != e; ++i)
|
|
|
|
EncodeFixedType(Int.IS.RetTypeDefs[i], NextArgNo, TypeSig);
|
|
|
|
}
|
2012-05-16 14:34:44 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = Int.IS.ParamTypeDefs.size(); i != e; ++i)
|
2012-05-17 12:30:58 +08:00
|
|
|
EncodeFixedType(Int.IS.ParamTypeDefs[i], NextArgNo, TypeSig);
|
2012-05-17 23:55:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void printIITEntry(raw_ostream &OS, unsigned char X) {
|
|
|
|
OS << (unsigned)X;
|
2012-05-16 14:34:44 +08:00
|
|
|
}
|
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2012-05-16 14:34:44 +08:00
|
|
|
OS << "// Global intrinsic function declaration type table.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSTIC_GENERATOR_GLOBAL\n";
|
|
|
|
// NOTE: These enums must be kept in sync with the ones above!
|
|
|
|
OS << "enum IIT_Info {\n";
|
|
|
|
OS << " IIT_Done = 0,\n";
|
|
|
|
OS << " IIT_I1 = 1,\n";
|
|
|
|
OS << " IIT_I8 = 2,\n";
|
|
|
|
OS << " IIT_I16 = 3,\n";
|
|
|
|
OS << " IIT_I32 = 4,\n";
|
|
|
|
OS << " IIT_I64 = 5,\n";
|
|
|
|
OS << " IIT_F32 = 6,\n";
|
|
|
|
OS << " IIT_F64 = 7,\n";
|
|
|
|
OS << " IIT_V2 = 8,\n";
|
|
|
|
OS << " IIT_V4 = 9,\n";
|
|
|
|
OS << " IIT_V8 = 10,\n";
|
|
|
|
OS << " IIT_V16 = 11,\n";
|
2012-05-17 13:03:24 +08:00
|
|
|
OS << " IIT_V32 = 12,\n";
|
|
|
|
OS << " IIT_MMX = 13,\n";
|
|
|
|
OS << " IIT_PTR = 14,\n";
|
|
|
|
OS << " IIT_ARG = 15,\n";
|
|
|
|
OS << " IIT_METADATA = 16,\n";
|
|
|
|
OS << " IIT_EMPTYSTRUCT = 17,\n";
|
|
|
|
OS << " IIT_STRUCT2 = 18,\n";
|
|
|
|
OS << " IIT_STRUCT3 = 19,\n";
|
|
|
|
OS << " IIT_STRUCT4 = 20,\n";
|
|
|
|
OS << " IIT_STRUCT5 = 21,\n";
|
|
|
|
OS << " IIT_EXTEND_VEC_ARG = 22,\n";
|
|
|
|
OS << " IIT_TRUNC_VEC_ARG = 23\n";
|
2012-05-16 14:34:44 +08:00
|
|
|
OS << "};\n\n";
|
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
|
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;
|
2007-02-08 04:38:26 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
SequenceToOffsetTable<std::vector<unsigned char> > LongEncodingTable;
|
|
|
|
|
|
|
|
std::vector<unsigned char> TypeSig;
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
LongEncodingTable.layout();
|
|
|
|
|
2012-05-16 14:34:44 +08:00
|
|
|
OS << "static const unsigned IIT_Table[] = {\n ";
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = FixedEncodings.size(); i != e; ++i) {
|
|
|
|
if ((i & 7) == 7)
|
|
|
|
OS << "\n ";
|
2012-05-17 23:55:41 +08:00
|
|
|
|
|
|
|
// If the entry fit in the table, just emit it.
|
|
|
|
if (FixedEncodings[i] != ~0U) {
|
2012-05-16 14:34:44 +08:00
|
|
|
OS << "0x" << utohexstr(FixedEncodings[i]) << ", ";
|
2012-05-17 23:55:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
2007-02-08 04:38:26 +08:00
|
|
|
|
2012-05-17 23:55:41 +08:00
|
|
|
TypeSig.clear();
|
|
|
|
ComputeFixedEncoding(Ints[i], TypeSig);
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2007-02-08 04:38:26 +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
|
|
|
}
|
2012-05-17 23:55:41 +08:00
|
|
|
|
|
|
|
OS << "0\n};\n\n";
|
|
|
|
|
|
|
|
// 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";
|
|
|
|
|
|
|
|
OS << "#endif\n\n"; // End of GET_INTRINSTIC_GENERATOR_GLOBAL
|
2007-02-08 04:38:26 +08:00
|
|
|
}
|
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
namespace {
|
|
|
|
enum ModRefKind {
|
|
|
|
MRK_none,
|
|
|
|
MRK_readonly,
|
|
|
|
MRK_readnone
|
|
|
|
};
|
|
|
|
|
|
|
|
ModRefKind getModRefKind(const CodeGenIntrinsic &intrinsic) {
|
|
|
|
switch (intrinsic.ModRef) {
|
|
|
|
case CodeGenIntrinsic::NoMem:
|
|
|
|
return MRK_readnone;
|
|
|
|
case CodeGenIntrinsic::ReadArgMem:
|
|
|
|
case CodeGenIntrinsic::ReadMem:
|
|
|
|
return MRK_readonly;
|
|
|
|
case CodeGenIntrinsic::ReadWriteArgMem:
|
|
|
|
case CodeGenIntrinsic::ReadWriteMem:
|
|
|
|
return MRK_none;
|
|
|
|
}
|
2012-02-05 15:21:30 +08:00
|
|
|
llvm_unreachable("bad mod-ref kind");
|
2011-05-28 14:31:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Try to order by readonly/readnone attribute.
|
|
|
|
ModRefKind LK = getModRefKind(*L);
|
|
|
|
ModRefKind RK = getModRefKind(*R);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-01-12 09:18:58 +08:00
|
|
|
/// EmitAttributes - This emits the Intrinsic::getAttributes method.
|
2006-03-24 09:13:55 +08:00
|
|
|
void IntrinsicEmitter::
|
2009-07-03 08:10:29 +08:00
|
|
|
EmitAttributes(const std::vector<CodeGenIntrinsic> &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";
|
2009-02-05 09:49:45 +08:00
|
|
|
if (TargetOnly)
|
|
|
|
OS << "static AttrListPtr getAttributes(" << TargetPrefix
|
2011-05-28 14:31:34 +08:00
|
|
|
<< "Intrinsic::ID id) {\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
else
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << "AttrListPtr Intrinsic::getAttributes(ID id) {\n";
|
|
|
|
|
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;
|
|
|
|
assert(AttrNum < 256 && "Too many unique attributes for table!");
|
|
|
|
N = ++AttrNum;
|
2006-03-10 06:37:52 +08:00
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
|
|
|
|
// Emit an array of AttributeWithIndex. Most intrinsics will have
|
|
|
|
// at least one entry, for the function itself (index ~1), which is
|
|
|
|
// usually nounwind.
|
2012-02-28 14:32:00 +08:00
|
|
|
OS << " static const uint8_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
|
|
|
|
2012-02-28 14:32:00 +08:00
|
|
|
OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n";
|
|
|
|
OS << " unsigned NumAttrs = 0;\n";
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " if (id != 0) {\n";
|
|
|
|
OS << " switch(IntrinsicsToAttributesMap[id - ";
|
|
|
|
if (TargetOnly)
|
|
|
|
OS << "Intrinsic::num_intrinsics";
|
|
|
|
else
|
|
|
|
OS << "1";
|
|
|
|
OS << "]) {\n";
|
|
|
|
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) {
|
2012-04-13 14:14:57 +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.
|
|
|
|
for (unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); ai != ae;) {
|
|
|
|
unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
|
2012-02-28 14:32:00 +08:00
|
|
|
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get("
|
2011-05-28 14:31:34 +08:00
|
|
|
<< argNo+1 << ", ";
|
|
|
|
|
|
|
|
bool moreThanOne = false;
|
2009-01-12 10:41:37 +08:00
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
do {
|
|
|
|
if (moreThanOne) OS << '|';
|
|
|
|
|
|
|
|
switch (intrinsic.ArgumentAttributes[ai].second) {
|
2009-01-12 10:41:37 +08:00
|
|
|
case CodeGenIntrinsic::NoCapture:
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << "Attribute::NoCapture";
|
2009-01-12 10:41:37 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
|
|
|
|
++ai;
|
|
|
|
moreThanOne = true;
|
|
|
|
} while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
|
|
|
|
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
ModRefKind modRef = getModRefKind(intrinsic);
|
|
|
|
|
|
|
|
if (!intrinsic.canThrow || modRef) {
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, ";
|
2011-05-28 14:31:34 +08:00
|
|
|
if (!intrinsic.canThrow) {
|
|
|
|
OS << "Attribute::NoUnwind";
|
|
|
|
if (modRef) OS << '|';
|
|
|
|
}
|
|
|
|
switch (modRef) {
|
|
|
|
case MRK_none: break;
|
|
|
|
case MRK_readonly: OS << "Attribute::ReadOnly"; break;
|
|
|
|
case MRK_readnone: OS << "Attribute::ReadNone"; break;
|
2009-01-12 10:41:37 +08:00
|
|
|
}
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
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";
|
2011-05-28 14:31:34 +08:00
|
|
|
} else {
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " return AttrListPtr();\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
}
|
2009-01-12 09:27:55 +08:00
|
|
|
}
|
|
|
|
|
2012-04-13 14:14:57 +08:00
|
|
|
OS << " }\n";
|
2009-01-12 09:27:55 +08:00
|
|
|
OS << " }\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << " return AttrListPtr::get(AWI, 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
|
|
|
|
2009-02-14 18:56:35 +08:00
|
|
|
/// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
|
|
|
|
void IntrinsicEmitter::
|
2009-07-03 08:10:29 +08:00
|
|
|
EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
|
2012-03-01 09:18:32 +08:00
|
|
|
OS << "// Determine intrinsic alias analysis mod/ref behavior.\n"
|
|
|
|
<< "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n"
|
|
|
|
<< "assert(iid <= Intrinsic::" << Ints.back().EnumName << " && "
|
|
|
|
<< "\"Unknown intrinsic.\");\n\n";
|
|
|
|
|
|
|
|
OS << "static const uint8_t IntrinsicModRefBehavior[] = {\n"
|
|
|
|
<< " /* invalid */ UnknownModRefBehavior,\n";
|
2009-02-14 18:56:35 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2012-03-01 09:18:32 +08:00
|
|
|
OS << " /* " << TargetPrefix << Ints[i].EnumName << " */ ";
|
2009-02-14 18:56:35 +08:00
|
|
|
switch (Ints[i].ModRef) {
|
|
|
|
case CodeGenIntrinsic::NoMem:
|
2012-03-01 09:18:32 +08:00
|
|
|
OS << "DoesNotAccessMemory,\n";
|
2009-02-14 18:56:35 +08:00
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadArgMem:
|
2012-03-01 09:18:32 +08:00
|
|
|
OS << "OnlyReadsArgumentPointees,\n";
|
2010-11-10 04:07:20 +08:00
|
|
|
break;
|
2009-02-14 18:56:35 +08:00
|
|
|
case CodeGenIntrinsic::ReadMem:
|
2012-03-01 09:18:32 +08:00
|
|
|
OS << "OnlyReadsMemory,\n";
|
2009-02-14 18:56:35 +08:00
|
|
|
break;
|
2010-08-06 07:36:21 +08:00
|
|
|
case CodeGenIntrinsic::ReadWriteArgMem:
|
2012-03-01 09:18:32 +08:00
|
|
|
OS << "OnlyAccessesArgumentPointees,\n";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadWriteMem:
|
|
|
|
OS << "UnknownModRefBehavior,\n";
|
2009-02-14 18:56:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 09:18:32 +08:00
|
|
|
OS << "};\n\n"
|
|
|
|
<< "return static_cast<ModRefBehavior>(IntrinsicModRefBehavior[iid]);\n"
|
|
|
|
<< "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
|
2009-02-14 18:56:35 +08:00
|
|
|
}
|
|
|
|
|
2008-01-04 12:38:35 +08:00
|
|
|
/// EmitTargetBuiltins - All of the builtins in the specified map are for the
|
|
|
|
/// same target, and we already checked it.
|
|
|
|
static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
|
2009-02-05 09:49:45 +08:00
|
|
|
const std::string &TargetPrefix,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2008-01-04 12:38:35 +08:00
|
|
|
|
2010-09-06 11:14:45 +08:00
|
|
|
std::vector<StringMatcher::StringPair> Results;
|
2008-01-04 12:38:35 +08:00
|
|
|
|
2010-09-06 11:14:45 +08:00
|
|
|
for (std::map<std::string, std::string>::const_iterator I = BIM.begin(),
|
|
|
|
E = BIM.end(); I != E; ++I) {
|
|
|
|
std::string ResultCode =
|
|
|
|
"return " + TargetPrefix + "Intrinsic::" + I->second + ";";
|
|
|
|
Results.push_back(StringMatcher::StringPair(I->first, ResultCode));
|
2008-01-04 12:38:35 +08:00
|
|
|
}
|
2010-09-06 11:14:45 +08:00
|
|
|
|
|
|
|
StringMatcher("BuiltinName", Results, OS).Emit();
|
2008-01-04 12:38:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-15 09:33:26 +08:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2008-01-03 05:24:22 +08:00
|
|
|
typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
|
2006-03-15 09:33:26 +08:00
|
|
|
BIMTy BuiltinMap;
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
if (!Ints[i].GCCBuiltinName.empty()) {
|
2008-01-03 05:24:22 +08:00
|
|
|
// Get the map for this target prefix.
|
|
|
|
std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
|
|
|
|
|
|
|
|
if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
|
|
|
|
Ints[i].EnumName)).second)
|
2006-03-15 09:33:26 +08:00
|
|
|
throw "Intrinsic '" + Ints[i].TheDef->getName() +
|
|
|
|
"': duplicate GCC builtin name!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
|
|
|
|
OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
|
|
|
|
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";
|
|
|
|
OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
|
|
|
|
if (TargetOnly) {
|
|
|
|
OS << "static " << TargetPrefix << "Intrinsic::ID "
|
|
|
|
<< "getIntrinsicForGCCBuiltin(const char "
|
2010-09-06 11:14:45 +08:00
|
|
|
<< "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
} else {
|
|
|
|
OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
|
2010-09-06 11:14:45 +08:00
|
|
|
<< "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
}
|
|
|
|
|
2010-09-06 11:14:45 +08:00
|
|
|
OS << " StringRef BuiltinName(BuiltinNameStr);\n";
|
|
|
|
OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
|
2008-01-04 12:38:35 +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.
|
2009-02-05 09:49:45 +08:00
|
|
|
EmitTargetBuiltins(I->second, TargetPrefix, OS);
|
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 ";
|
|
|
|
if (!TargetPrefix.empty())
|
|
|
|
OS << "(" << TargetPrefix << "Intrinsic::ID)";
|
|
|
|
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";
|
|
|
|
}
|