[PATCH] [mips] [IAS] Refactor the function which checks for the availability of AT. NFC.

Toma Tabacu toma.tabacu at imgtec.com
Fri Mar 20 03:36:18 PDT 2015


Hi dsanders,

Refactor MipsAsmParser::getATReg to only check if AT is set to $0 and rename it to isATAvailable.

I think doing this will make the code clearer semantically.
Also, isATAvailable will be a less deceptive name with regards to what the function actually should be doing and
MipsAssemblerOptions::getATRegNum() is more deserving of the name getATReg() anyway.

I also changed all the int's to unsigned, seeing as AT is stored as an unsigned in MipsAssemblerOptions.

http://reviews.llvm.org/D8478

Files:
  lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -271,8 +271,6 @@
 
   unsigned getGPR(int RegNo);
 
-  int getATReg(SMLoc Loc);
-
   bool processInstruction(MCInst &Inst, SMLoc IDLoc,
                           SmallVectorImpl<MCInst> &Instructions);
 
@@ -431,6 +429,10 @@
 
   /// Warn if RegNo is the current assembler temporary.
   void warnIfAssemblerTemporary(int RegNo, SMLoc Loc);
+
+  /// Error if AT is set to $0 (i.e. is unavailable).
+  /// This should be used in pseudo-instruction expansions which need AT.
+  bool isATAvailable(SMLoc IDLoc);
 };
 }
 
@@ -2047,11 +2049,12 @@
   if (isLoad && IsGPR && (BaseRegNum != RegOpNum))
     TmpRegNum = RegOpNum;
   else {
-    int AT = getATReg(IDLoc);
-    // At this point we need AT to perform the expansions and we exit if it is
-    // not available.
-    if (!AT)
+    // At this point we need AT to perform the expansions.
+    // If it is not available, an error is given and then we exit.
+    if (!isATAvailable(IDLoc))
       return;
+
+    unsigned AT = AssemblerOptions.back()->getATRegNum();
     TmpRegNum = getReg(
         (isGP64bit()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, AT);
   }
@@ -2200,6 +2203,16 @@
   llvm_unreachable("Implement any new match types added!");
 }
 
+bool MipsAsmParser::isATAvailable(SMLoc IDLoc) {
+  // If AT is not available, give an error.
+  if (AssemblerOptions.back()->getATRegNum() == 0) {
+    reportParseError(
+        IDLoc, "pseudo-instruction requires $at, which is not available");
+    return false;
+  }
+  return true;
+}
+
 void MipsAsmParser::warnIfAssemblerTemporary(int RegIndex, SMLoc Loc) {
   if ((RegIndex != 0) && 
       ((int)AssemblerOptions.back()->getATRegNum() == RegIndex)) {
@@ -2382,14 +2395,6 @@
   return CC;
 }
 
-int MipsAsmParser::getATReg(SMLoc Loc) {
-  int AT = AssemblerOptions.back()->getATRegNum();
-  if (AT == 0)
-    reportParseError(Loc,
-                     "pseudo-instruction requires $at, which is not available");
-  return AT;
-}
-
 unsigned MipsAsmParser::getReg(int RC, int RegNo) {
   return *(getContext().getRegisterInfo()->getRegClass(RC).begin() + RegNo);
 }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8478.22338.patch
Type: text/x-patch
Size: 2304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150320/d25c18df/attachment.bin>


More information about the llvm-commits mailing list