[llvm-commits] [dragonegg] r103385 - in /dragonegg/trunk: llvm-convert.cpp x86/llvm-target.h

Duncan Sands baldrick at free.fr
Sun May 9 11:19:18 PDT 2010


Author: baldrick
Date: Sun May  9 13:19:18 2010
New Revision: 103385

URL: http://llvm.org/viewvc/llvm-project?rev=103385&view=rev
Log:
Port commit 98165 (bwilson) from llvm-gcc:
pr6552: Have llvm-gcc canonicalize register names in inline assembly and
asm register attributes to use the names known to llvm.  For ARM some of the
registers have different names depending on the target for which llvm-gcc is
configured.  Also use the new LLVM_GET_REG_NAME hook to replace the
LLVM_DO_NOT_USE_REG_NAMES macro.

Modified:
    dragonegg/trunk/llvm-convert.cpp
    dragonegg/trunk/x86/llvm-target.h

Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=103385&r1=103384&r2=103385&view=diff
==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Sun May  9 13:19:18 2010
@@ -2927,6 +2927,11 @@
 //               ... Inline Assembly and Register Variables ...
 //===----------------------------------------------------------------------===//
 
+// LLVM_GET_REG_NAME - Default to use GCC's register names.  Targets may
+// override this to use different names for some registers.
+#ifndef LLVM_GET_REG_NAME
+#define LLVM_GET_REG_NAME(REG_NAME, REG_NUM) reg_names[REG_NUM]
+#endif
 
 /// Reads from register variables are handled by emitting an inline asm node
 /// that copies the value out of the specified register.
@@ -2941,7 +2946,8 @@
   // Turn this into a 'tmp = call Ty asm "", "={reg}"()'.
   FunctionType *FTy = FunctionType::get(MemTy, std::vector<const Type*>(),false);
 
-  const char *Name = reg_names[decode_reg_name(extractRegisterName(decl))];
+  const char *Name = extractRegisterName(decl);
+  Name = LLVM_GET_REG_NAME(Name, decode_reg_name(Name));
 
   InlineAsm *IA = InlineAsm::get(FTy, "", "={"+std::string(Name)+"}", false);
   CallInst *Call = Builder.CreateCall(IA);
@@ -2967,7 +2973,8 @@
   FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), ArgTys,
                                         false);
 
-  const char *Name = reg_names[decode_reg_name(extractRegisterName(decl))];
+  const char *Name = extractRegisterName(decl);
+  Name = LLVM_GET_REG_NAME(Name, decode_reg_name(Name));
 
   InlineAsm *IA = InlineAsm::get(FTy, "", "{"+std::string(Name)+"}", true);
   CallInst *Call = Builder.CreateCall(IA, RHS);
@@ -3340,23 +3347,6 @@
     free(const_cast<char *>(ReplacementStrings[i]));
 }
 
-// When extracting a register name from a DECL_HARD_REGISTER variable,
-// we normally want to look up RegNum in reg_names.  This works on most
-// targets, where ADDITIONAL_REGISTER_NAMES are true synonyms.  It does not
-// work on x86, where ADDITIONAL_REGISTER_NAMES are overlapping subregisters;
-// in particular AH and AL can't be distinguished if we go through reg_names.
-static const char* getConstraintRegNameFromGccTables(const char *RegName,
-                                                     unsigned int RegNum) {
-#ifdef LLVM_DO_NOT_USE_REG_NAMES
-  (void)RegNum;
-  if (*RegName == '%')
-    RegName++;
-  return RegName;
-#else
-  return reg_names[RegNum];
-#endif
-}
-
 
 //===----------------------------------------------------------------------===//
 //               ... Helpers for Builtin Function Expansion ...
@@ -6766,7 +6756,7 @@
       const char* RegName = extractRegisterName(Operand);
       int RegNum = decode_reg_name(RegName);
       if (RegNum >= 0) {
-        RegName = getConstraintRegNameFromGccTables(RegName, RegNum);
+        RegName = LLVM_GET_REG_NAME(RegName, RegNum);
         unsigned RegNameLen = strlen(RegName);
         char *NewConstraint = (char*)alloca(RegNameLen+4);
         NewConstraint[0] = '=';
@@ -6949,7 +6939,7 @@
       const char *RegName = extractRegisterName(Val);
       int RegNum = decode_reg_name(RegName);
       if (RegNum >= 0) {
-        RegName = getConstraintRegNameFromGccTables(RegName, RegNum);
+        RegName = LLVM_GET_REG_NAME(RegName, RegNum);
         ConstraintStr += '{';
         ConstraintStr += RegName;
         ConstraintStr += '}';
@@ -6985,7 +6975,7 @@
       ConstraintStr += ",~{memory}";
       break;
     default:     // Normal register name.
-      RegName = getConstraintRegNameFromGccTables(RegName, RegCode);
+      RegName = LLVM_GET_REG_NAME(RegName, RegCode);
       ConstraintStr += ",~{";
       ConstraintStr += RegName;
       ConstraintStr += "}";

Modified: dragonegg/trunk/x86/llvm-target.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/x86/llvm-target.h?rev=103385&r1=103384&r2=103385&view=diff
==============================================================================
--- dragonegg/trunk/x86/llvm-target.h (original)
+++ dragonegg/trunk/x86/llvm-target.h Sun May  9 13:19:18 2010
@@ -356,11 +356,12 @@
 #define LLVM_TARGET_INTRINSIC_LOWER(STMT, FNDECL, DESTLOC, RESULT, DESTTY, OPS)	\
         TargetIntrinsicLower(STMT, FNDECL, DESTLOC, RESULT, DESTTY, OPS);
 
-/* When extracting a register name for a constraint, use the string extracted
-   from the magic symbol built for that register, rather than reg_names.
-   The latter maps both AH and AL to the same thing, which means we can't
-   distinguish them. */
-#define LLVM_DO_NOT_USE_REG_NAMES
+/* LLVM_GET_REG_NAME - When extracting a register name for a constraint, use
+   the string extracted from the magic symbol built for that register, rather
+   than reg_names.  The latter maps both AH and AL to the same thing, which
+   means we can't distinguish them. */
+#define LLVM_GET_REG_NAME(REG_NAME, REG_NUM) \
+  ((REG_NAME) + (*(REG_NAME) == '%' ? 1 : 0))
 
 /* Propagate code model setting to backend */
 #define LLVM_SET_MACHINE_OPTIONS(argvec)           \





More information about the llvm-commits mailing list