Compute the value types that are natively supported by a target.
authorChris Lattner <sabre@nondot.org>
Thu, 8 Sep 2005 21:43:21 +0000 (21:43 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 8 Sep 2005 21:43:21 +0000 (21:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23282 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/CodeGenRegisters.h
utils/TableGen/CodeGenTarget.cpp
utils/TableGen/CodeGenTarget.h

index e45311373498fd06b4c32e723003653dc01ca715..6a9b7907bd83fc3306142e088eb73fd5be82b0d6 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <string>
 #include <vector>
+#include "llvm/CodeGen/ValueTypes.h"
 
 namespace llvm {
   class Record;
@@ -36,6 +37,7 @@ namespace llvm {
     std::vector<Record*> Elements;
     unsigned SpillSize;
     unsigned SpillAlignment;
+    MVT::ValueType VT;
     std::string MethodProtos, MethodBodies;
 
     const std::string &getName() const;
index bd02ccdcef02488698cc1ecb2c7dcd157428e964..61e237f1bd9a2c6c99cd741dc2503783172e0171 100644 (file)
@@ -152,6 +152,7 @@ CodeGenRegisterClass::CodeGenRegisterClass(Record *R) : TheDef(R) {
   Namespace = R->getValueAsString("Namespace");
   SpillSize = R->getValueAsInt("Size");
   SpillAlignment = R->getValueAsInt("Alignment");
+  VT = getValueType(R->getValueAsDef("RegType"));
 
   if (CodeInit *CI = dynamic_cast<CodeInit*>(R->getValueInit("MethodBodies")))
     MethodBodies = CI->getValue();
@@ -182,6 +183,11 @@ const std::string &CodeGenRegisterClass::getName() const {
   return TheDef->getName();
 }
 
+void CodeGenTarget::ReadLegalValueTypes() const {
+  const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
+  for (unsigned i = 0, e = RCs.size(); i != e; ++i)
+    LegalValueTypes.push_back(RCs[i].VT);
+}
 
 
 void CodeGenTarget::ReadInstructions() const {
index 05d5cb2ddb7cc6174e9869804fe8f297bb390e26..1748e8ca8280d8a0ad216f3701041f7232ce376b 100644 (file)
@@ -47,9 +47,11 @@ class CodeGenTarget {
   mutable std::map<std::string, CodeGenInstruction> Instructions;
   mutable std::vector<CodeGenRegister> Registers;
   mutable std::vector<CodeGenRegisterClass> RegisterClasses;
+  mutable std::vector<MVT::ValueType> LegalValueTypes;
   void ReadRegisters() const;
   void ReadRegisterClasses() const;
   void ReadInstructions() const;
+  void ReadLegalValueTypes() const;
 public:
   CodeGenTarget();
 
@@ -70,16 +72,29 @@ public:
   ///
   Record *getAsmWriter() const;
 
-  const std::vector<CodeGenRegister> &getRegisters() {
+  const std::vector<CodeGenRegister> &getRegisters() const {
     if (Registers.empty()) ReadRegisters();
     return Registers;
   }
 
-  const std::vector<CodeGenRegisterClass> getRegisterClasses() {
+  const std::vector<CodeGenRegisterClass> &getRegisterClasses() const {
     if (RegisterClasses.empty()) ReadRegisterClasses();
     return RegisterClasses;
   }
 
+  const std::vector<MVT::ValueType> &getLegalValueTypes() const {
+    if (LegalValueTypes.empty()) ReadLegalValueTypes();
+    return LegalValueTypes;
+  }
+  
+  /// isLegalValueType - Return true if the specified value type is natively
+  /// supported by the target (i.e. there are registers that directly hold it).
+  bool isLegalValueType(MVT::ValueType VT) const {
+    const std::vector<MVT::ValueType> &LegalVTs = getLegalValueTypes();
+    for (unsigned i = 0, e = LegalVTs.size(); i != e; ++i)
+      if (LegalVTs[i] == VT) return true;
+    return false;    
+  }
 
   /// getInstructions - Return all of the instructions defined for this target.
   ///