mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-14 07:09:08 +00:00
Give full control of subtarget features over to table generated code.
llvm-svn: 24013
This commit is contained in:
parent
22e578cd95
commit
9ce53d8411
@ -19,10 +19,7 @@ using namespace llvm;
|
||||
AlphaSubtarget::AlphaSubtarget(const Module &M, const std::string &FS)
|
||||
: HasF2I(false), HasCT(false) {
|
||||
std::string CPU = "generic";
|
||||
SubtargetFeatures Features(FS);
|
||||
Features.setCPUIfNone(CPU);
|
||||
uint32_t Bits =Features.getBits(SubTypeKV, SubTypeKVSize,
|
||||
FeatureKV, FeatureKVSize);
|
||||
HasF2I = (Bits & FeatureFIX) != 0;
|
||||
HasCT = (Bits & FeatureCIX) != 0;
|
||||
|
||||
// Parse features string.
|
||||
ParseSubtargetFeatures(FS, CPU);
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ public:
|
||||
/// of the specified module.
|
||||
///
|
||||
AlphaSubtarget(const Module &M, const std::string &FS);
|
||||
|
||||
/// ParseSubtargetFeatures - Parses features string setting specified
|
||||
/// subtarget options. Definition of function is usto generated by tblgen.
|
||||
void ParseSubtargetFeatures(const std::string &FS, const std::string &CPU);
|
||||
|
||||
bool hasF2I() const { return HasF2I; }
|
||||
bool hasCT() const { return HasCT; }
|
||||
|
@ -68,22 +68,25 @@ static const char *GetCurrentPowerPCCPU() {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
|
||||
: StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
|
||||
: StackAlignment(16)
|
||||
, IsGigaProcessor(false)
|
||||
, Is64Bit(false)
|
||||
, Has64BitRegs(false)
|
||||
, HasAltivec(false)
|
||||
, HasFSQRT(false)
|
||||
, IsAIX(false)
|
||||
, IsDarwin(false) {
|
||||
|
||||
// Determine default and user specified characteristics
|
||||
std::string CPU = "generic";
|
||||
#if defined(__APPLE__)
|
||||
CPU = GetCurrentPowerPCCPU();
|
||||
#endif
|
||||
SubtargetFeatures Features(FS);
|
||||
Features.setCPUIfNone(CPU);
|
||||
uint32_t Bits = Features.getBits(SubTypeKV, SubTypeKVSize,
|
||||
FeatureKV, FeatureKVSize);
|
||||
IsGigaProcessor = (Bits & FeatureGPUL ) != 0;
|
||||
Is64Bit = (Bits & Feature64Bit) != 0;
|
||||
HasFSQRT = (Bits & FeatureFSqrt) != 0;
|
||||
Has64BitRegs = (Bits & Feature64BitRegs) != 0;
|
||||
|
||||
// Parse features string.
|
||||
ParseSubtargetFeatures(FS, CPU);
|
||||
|
||||
// Set the boolean corresponding to the current target triple, or the default
|
||||
// if one cannot be determined, to true.
|
||||
|
@ -31,6 +31,7 @@ protected:
|
||||
bool IsGigaProcessor;
|
||||
bool Is64Bit;
|
||||
bool Has64BitRegs;
|
||||
bool HasAltivec;
|
||||
bool HasFSQRT;
|
||||
bool IsAIX;
|
||||
bool IsDarwin;
|
||||
@ -39,6 +40,10 @@ public:
|
||||
/// of the specified module.
|
||||
///
|
||||
PPCSubtarget(const Module &M, const std::string &FS);
|
||||
|
||||
/// ParseSubtargetFeatures - Parses features string setting specified
|
||||
/// subtarget options. Definition of function is usto generated by tblgen.
|
||||
void ParseSubtargetFeatures(const std::string &FS, const std::string &CPU);
|
||||
|
||||
/// getStackAlignment - Returns the minimum alignment known to hold of the
|
||||
/// stack frame on entry to the function and which must be maintained by every
|
||||
@ -46,11 +51,12 @@ public:
|
||||
unsigned getStackAlignment() const { return StackAlignment; }
|
||||
|
||||
bool hasFSQRT() const { return HasFSQRT; }
|
||||
bool has64BitRegs() const { return Has64BitRegs; }
|
||||
bool hasAltivec() const { return HasAltivec; }
|
||||
|
||||
bool isAIX() const { return IsAIX; }
|
||||
bool isDarwin() const { return IsDarwin; }
|
||||
bool is64Bit() const { return Is64Bit; }
|
||||
bool has64BitRegs() const { return Has64BitRegs; }
|
||||
bool isGigaProcessor() const { return IsGigaProcessor; }
|
||||
};
|
||||
} // End llvm namespace
|
||||
|
@ -45,24 +45,28 @@ struct LessRecordFieldName {
|
||||
};
|
||||
|
||||
//
|
||||
// FeatureEnumeration - Emit an enumeration of all the subtarget features.
|
||||
// Enumeration - Emit the specified class as an enumeration.
|
||||
//
|
||||
void SubtargetEmitter::FeatureEnumeration(std::ostream &OS) {
|
||||
RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
|
||||
sort(Features.begin(), Features.end(), LessRecord());
|
||||
void SubtargetEmitter::Enumeration(std::ostream &OS,
|
||||
const char *ClassName,
|
||||
bool isBits) {
|
||||
RecordList Defs = Records.getAllDerivedDefinitions(ClassName);
|
||||
sort(Defs.begin(), Defs.end(), LessRecord());
|
||||
|
||||
int i = 0;
|
||||
|
||||
OS << "enum {\n";
|
||||
|
||||
for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;){
|
||||
for (RecordListIter RI = Defs.begin(), E = Defs.end(); RI != E;) {
|
||||
Record *R = *RI++;
|
||||
std::string Instance = R->getName();
|
||||
OS << " "
|
||||
<< Instance
|
||||
<< " = "
|
||||
<< " 1 << " << i++
|
||||
<< ((RI != E) ? ",\n" : "\n");
|
||||
<< Instance;
|
||||
if (isBits) {
|
||||
OS << " = "
|
||||
<< " 1 << " << i++;
|
||||
}
|
||||
OS << ((RI != E) ? ",\n" : "\n");
|
||||
}
|
||||
|
||||
OS << "};\n";
|
||||
@ -76,8 +80,7 @@ void SubtargetEmitter::FeatureKeyValues(std::ostream &OS) {
|
||||
RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
|
||||
sort(Features.begin(), Features.end(), LessRecord());
|
||||
|
||||
OS << "\n"
|
||||
<< "// Sorted (by key) array of values for CPU features.\n"
|
||||
OS << "// Sorted (by key) array of values for CPU features.\n"
|
||||
<< "static llvm::SubtargetFeatureKV FeatureKV[] = {\n";
|
||||
for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;) {
|
||||
Record *R = *RI++;
|
||||
@ -105,8 +108,7 @@ void SubtargetEmitter::CPUKeyValues(std::ostream &OS) {
|
||||
RecordList Processors = Records.getAllDerivedDefinitions("Processor");
|
||||
sort(Processors.begin(), Processors.end(), LessRecordFieldName());
|
||||
|
||||
OS << "\n"
|
||||
<< "// Sorted (by key) array of values for CPU subtype.\n"
|
||||
OS << "// Sorted (by key) array of values for CPU subtype.\n"
|
||||
<< "static const llvm::SubtargetFeatureKV SubTypeKV[] = {\n";
|
||||
for (RecordListIter RI = Processors.begin(), E = Processors.end();
|
||||
RI != E;) {
|
||||
@ -145,15 +147,61 @@ void SubtargetEmitter::CPUKeyValues(std::ostream &OS) {
|
||||
OS<<"};\n";
|
||||
}
|
||||
|
||||
//
|
||||
// ParseFeaturesFunction - Produces a subtarget specific function for parsing
|
||||
// the subtarget features string.
|
||||
//
|
||||
void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS) {
|
||||
RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
|
||||
sort(Features.begin(), Features.end(), LessRecord());
|
||||
|
||||
OS << "// ParseSubtargetFeatures - Parses features string setting specified\n"
|
||||
"// subtarget options.\n"
|
||||
"void llvm::";
|
||||
OS << Target;
|
||||
OS << "Subtarget::ParseSubtargetFeatures(const std::string &FS,\n"
|
||||
" const std::string &CPU) {\n"
|
||||
" SubtargetFeatures Features(FS);\n"
|
||||
" Features.setCPUIfNone(CPU);\n"
|
||||
" uint32_t Bits = Features.getBits(SubTypeKV, SubTypeKVSize,\n"
|
||||
" FeatureKV, FeatureKVSize);\n";
|
||||
|
||||
for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;) {
|
||||
Record *R = *RI++;
|
||||
std::string Instance = R->getName();
|
||||
std::string Name = R->getValueAsString("Name");
|
||||
std::string Type = R->getValueAsString("Type");
|
||||
std::string Attribute = R->getValueAsString("Attribute");
|
||||
|
||||
OS << " " << Attribute << " = (Bits & " << Instance << ") != 0;\n";
|
||||
}
|
||||
OS << "}\n";
|
||||
}
|
||||
|
||||
//
|
||||
// SubtargetEmitter::run - Main subtarget enumeration emitter.
|
||||
//
|
||||
void SubtargetEmitter::run(std::ostream &OS) {
|
||||
std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
|
||||
if (Targets.size() == 0)
|
||||
throw std::string("ERROR: No 'Target' subclasses defined!");
|
||||
if (Targets.size() != 1)
|
||||
throw std::string("ERROR: Multiple subclasses of Target defined!");
|
||||
Target = Targets[0]->getName();
|
||||
|
||||
EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
|
||||
|
||||
OS << "#include \"llvm/Target/SubtargetFeature.h\"\n\n";
|
||||
|
||||
FeatureEnumeration(OS);
|
||||
Enumeration(OS, "FuncUnit", true);
|
||||
OS<<"\n";
|
||||
Enumeration(OS, "InstrItinClass", false);
|
||||
OS<<"\n";
|
||||
Enumeration(OS, "SubtargetFeature", true);
|
||||
OS<<"\n";
|
||||
FeatureKeyValues(OS);
|
||||
OS<<"\n";
|
||||
CPUKeyValues(OS);
|
||||
OS<<"\n";
|
||||
ParseFeaturesFunction(OS);
|
||||
}
|
||||
|
@ -20,10 +20,12 @@ namespace llvm {
|
||||
|
||||
class SubtargetEmitter : public TableGenBackend {
|
||||
RecordKeeper &Records;
|
||||
std::string Target;
|
||||
|
||||
void FeatureEnumeration(std::ostream &OS);
|
||||
void Enumeration(std::ostream &OS, const char *ClassName, bool isBits);
|
||||
void FeatureKeyValues(std::ostream &OS);
|
||||
void CPUKeyValues(std::ostream &OS);
|
||||
void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS);
|
||||
|
||||
public:
|
||||
SubtargetEmitter(RecordKeeper &R) : Records(R) {}
|
||||
|
Loading…
Reference in New Issue
Block a user