[LLVMdev] initial putback for implementing mips16/nomips16 attributes - please review

Reed Kotler rkotler at mips.com
Thu Mar 14 00:35:26 PDT 2013

I added one method which clears the list of register classes.

Then there is a change to mips16 code which simulates switching from 
mips32 to mips16 mode in the same module. It seems to work fine in that 
I can run this version of llvm for mips16 and it works identical to the 
one without this code. Beyond the "make check" I have run test-suite 
against this version.

We could just putback the change to include/llvm/Target/TargetLowering.h 
but by adding the change to
  which is a nop for the mips16 compiler, we are able to test that this 
feature works and that doing things this way allows one to change 
register sets on a per function basis.

The idea here is to add two of the mips32 register sets (including float 
point which should have a big effect on things) and then 
computeRegisterProperties() and then revert things to mips16 only 
registers and call
computeRegisterProperties() again.

I have several more patches I will need to complete this mips16/nomips16 
feature but it's easier to do this in pieces.

In the end I will remove this testing code from 
lib/Target/Mips/Mips16ISelLowering.cpp and create a real test case for 
this. For now this test code shows how this feature can work for other 
ports like Arm than have a similar need.
-------------- next part --------------
diff --git a/include/llvm/Target/TargetLowering.h b/include/llvm/Target/TargetLowering.h
index e3e5737..e45b792 100644
--- a/include/llvm/Target/TargetLowering.h
+++ b/include/llvm/Target/TargetLowering.h
@@ -958,6 +958,14 @@ protected:
     RegClassForVT[VT.SimpleTy] = RC;
+  /// clearRegisterClasses - remove all register classes
+  void clearRegisterClasses() {
+    for (unsigned i = 0 ; i<array_lengthof(RegClassForVT); i++)
+      RegClassForVT[i] = 0;
+    while (!AvailableRegClasses.empty())
+      AvailableRegClasses.pop_back();
+  }
   /// findRepresentativeClass - Return the largest legal super-reg register class
   /// of the register class for the specified type and its associated "cost".
   virtual std::pair<const TargetRegisterClass*, uint8_t>
diff --git a/lib/Target/Mips/Mips16ISelLowering.cpp b/lib/Target/Mips/Mips16ISelLowering.cpp
index 6de62cf..23eb537 100644
--- a/lib/Target/Mips/Mips16ISelLowering.cpp
+++ b/lib/Target/Mips/Mips16ISelLowering.cpp
@@ -39,6 +39,14 @@ namespace {
 Mips16TargetLowering::Mips16TargetLowering(MipsTargetMachine &TM)
   : MipsTargetLowering(TM) {
+  //
+  // set up as if mips32 and then revert so we can test the mechanism
+  // for switching
+  addRegisterClass(MVT::i32, &Mips::CPURegsRegClass);
+  addRegisterClass(MVT::f32, &Mips::FGR32RegClass);
+  computeRegisterProperties();
+  clearRegisterClasses();
   // Set up the register classes
   addRegisterClass(MVT::i32, &Mips::CPU16RegsRegClass);

More information about the llvm-dev mailing list