[llvm-commits] [dragonegg] r159022 - in /dragonegg/trunk: include/x86/dragonegg/Target.h src/Backend.cpp
Duncan Sands
baldrick at free.fr
Fri Jun 22 12:54:01 PDT 2012
Author: baldrick
Date: Fri Jun 22 14:54:01 2012
New Revision: 159022
URL: http://llvm.org/viewvc/llvm-project?rev=159022&view=rev
Log:
Make it possible to easily override any part of the target triple.
Use it to use gnux32 for the final component if using the X32 ABI.
Inspired by a patch by Michael Liao.
Modified:
dragonegg/trunk/include/x86/dragonegg/Target.h
dragonegg/trunk/src/Backend.cpp
Modified: dragonegg/trunk/include/x86/dragonegg/Target.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/x86/dragonegg/Target.h?rev=159022&r1=159021&r2=159022&view=diff
==============================================================================
--- dragonegg/trunk/include/x86/dragonegg/Target.h (original)
+++ dragonegg/trunk/include/x86/dragonegg/Target.h Fri Jun 22 14:54:01 2012
@@ -374,6 +374,11 @@
#define LLVM_OVERRIDE_TARGET_ARCH() \
(TARGET_64BIT ? "x86_64" : "i386")
+#if (GCC_MINOR > 6)
+#define LLVM_OVERRIDE_TARGET_ENVIRONMENT() \
+ (TARGET_X32 ? "gnux32" : "")
+#endif
+
#define LLVM_ASM_EXTENSIONS(ESCAPED_CHAR, ASM, RESULT) \
else if ((ESCAPED_CHAR) == 'v') { \
/* %v means to use the AVX prefix 'v' if TARGET_AVX is true. */ \
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=159022&r1=159021&r2=159022&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Fri Jun 22 14:54:01 2012
@@ -32,6 +32,7 @@
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Assembly/PrintModulePass.h"
@@ -377,22 +378,43 @@
// If the target wants to override the architecture, e.g. turning
// powerpc-darwin-... into powerpc64-darwin-... when -m64 is enabled, do so
// now.
- std::string TargetTriple = TARGET_NAME;
+ std::string TargetTriple = Triple::normalize(TARGET_NAME);
+ std::string Components[4]; // Arch-Vendor-OS-Environment
#ifdef LLVM_OVERRIDE_TARGET_ARCH
- std::string Arch = LLVM_OVERRIDE_TARGET_ARCH();
- if (!Arch.empty()) {
- std::string::size_type DashPos = TargetTriple.find('-');
- if (DashPos != std::string::npos)// If we have a sane t-t, replace the arch.
- TargetTriple = Arch + TargetTriple.substr(DashPos);
- }
+ Components[0] = LLVM_OVERRIDE_TARGET_ARCH();
+#endif
+#ifdef LLVM_OVERRIDE_TARGET_VENDOR
+ Components[1] = LLVM_OVERRIDE_TARGET_VENDOR();
#endif
-#ifdef LLVM_OVERRIDE_TARGET_VERSION
- char *NewTriple;
- bool OverRidden = LLVM_OVERRIDE_TARGET_VERSION(TargetTriple.c_str(),
- &NewTriple);
- if (OverRidden)
- TargetTriple = std::string(NewTriple);
+#ifdef LLVM_OVERRIDE_TARGET_OS
+ Components[2] = LLVM_OVERRIDE_TARGET_OS();
#endif
+#ifdef LLVM_OVERRIDE_TARGET_ENVIRONMENT
+ Components[3] = LLVM_OVERRIDE_TARGET_ENVIRONMENT();
+#endif
+ bool Override = false;
+ for (unsigned i = 0; i != array_lengthof(Components); ++i)
+ if (!Components[i].empty()) {
+ Override = true;
+ break;
+ }
+ if (!Override)
+ return TargetTriple;
+
+ SmallVector<StringRef, 4> Parts;
+ StringRef(TargetTriple).split(Parts, "-");
+ for (unsigned i = 0; i != array_lengthof(Components); ++i)
+ if (!Components[i].empty()) {
+ if (Parts.size() <= i)
+ Parts.append(i - Parts.size() + 1, "");
+ Parts[i] = Components[i];
+ }
+
+ if (Parts.size() == 0)
+ return "";
+ TargetTriple = Parts[0];
+ for (unsigned i = 1; i != Parts.size(); ++i)
+ TargetTriple += (Twine("-") + Parts[i]).str();
return TargetTriple;
}
More information about the llvm-commits
mailing list