}
#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.
bool IsGigaProcessor;
bool Is64Bit;
bool Has64BitRegs;
+ bool HasAltivec;
bool HasFSQRT;
bool IsAIX;
bool IsDarwin;
/// 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
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
};
//
-// 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";
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++;
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;) {
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);
}