[cfe-dev] [PATCH] Add preliminary Alpha support
Matt Turner
mattst88 at gmail.com
Wed May 11 13:40:02 PDT 2011
Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
So LLVM's Alpha backend works, somewhat. It generates code that segfaults at
any optimization level except -O0, but this is a start at reviving it.
Things I'm unsure about:
DescriptionString - I think everything is natually aligned, but the MIPS
desc string I looked at specified 32-bit alignment for 8 and 16-bit units.
getDefaultFeatures - This seems to be where ISA additions should be created,
or something, but I see 'FIXME: This should not be here.' in other arch's
code. So, what goes here?
getTargetDefines - I don't know what this function does. Sets what the
preprocessor is supposed to define? gcc defines __alpha__ and some other
things dependent on features supported. Should these things be defined here?
getTargetBuiltins - No idea what this is.
validateAsmConstraint - I think this is for validating inline assembly inputs
and outputs? If so, this shouldn't be a problem.
getClobbers - Must be for inline assembly. The only relevant comments I see
in other code is '// FIXME: Is this really right?', so not terribly helpful.
So, help on figuring out what to do for these would be fantastic. Other review
very much welcomed!
Thanks,
Matt
lib/Basic/Targets.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++
lib/Driver/ToolChains.cpp | 4 +-
lib/Driver/Tools.cpp | 5 ++-
3 files changed, 117 insertions(+), 2 deletions(-)
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index 09a2f56..de7e5ee 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -1785,6 +1785,113 @@ public:
} // end anonymous namespace
namespace {
+class AlphaTargetInfo : public TargetInfo {
+ std::string CPU;
+ static const TargetInfo::GCCRegAlias GCCRegAliases[];
+ static const char * const GCCRegNames[];
+public:
+ AlphaTargetInfo(const std::string& triple) : TargetInfo(triple) {
+ DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
+ "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n64";
+ }
+ virtual bool setCPU(const std::string &Name) {
+ CPU = Name;
+ return true;
+ }
+ void getDefaultFeatures(const std::string &CPU,
+ llvm::StringMap<bool> &Features) const {
+ Features[CPU] = true;
+ }
+ virtual void getTargetDefines(const LangOptions &Opts,
+ MacroBuilder &Builder) const {
+ DefineStd(Builder, "alpha", Opts);
+ Builder.defineMacro("_alpha");
+ DefineStd(Builder, "ALPHA", Opts);
+ Builder.defineMacro("_ALPHA");
+ Builder.defineMacro("__REGISTER_PREFIX__", "");
+ }
+ virtual void getTargetBuiltins(const Builtin::Info *&Records,
+ unsigned &NumRecords) const {
+ // FIXME: Implement!
+ }
+ virtual const char *getVAListDeclaration() const {
+ return "typedef void* __builtin_va_list;";
+ }
+ virtual void getGCCRegNames(const char * const *&Names,
+ unsigned &NumNames) const;
+ virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
+ unsigned &NumAliases) const;
+ virtual bool validateAsmConstraint(const char *&Name,
+ TargetInfo::ConstraintInfo &Info) const {
+ return false;
+ }
+
+ virtual const char *getClobbers() const {
+ // FIXME: Implement!
+ return "";
+ }
+};
+
+const char * const AlphaTargetInfo::GCCRegNames[] = {
+ "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
+ "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
+ "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
+ "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
+ "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
+ "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
+ "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
+ "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31"
+};
+
+void AlphaTargetInfo::getGCCRegNames(const char * const *&Names,
+ unsigned &NumNames) const {
+ Names = GCCRegNames;
+ NumNames = llvm::array_lengthof(GCCRegNames);
+}
+
+const TargetInfo::GCCRegAlias AlphaTargetInfo::GCCRegAliases[] = {
+ { { "v0" }, "$0" },
+ { { "t0" }, "$1" },
+ { { "t1" }, "$2" },
+ { { "t2" }, "$3" },
+ { { "t3" }, "$4" },
+ { { "t4" }, "$5" },
+ { { "t5" }, "$6" },
+ { { "t6" }, "$7" },
+ { { "t7" }, "$8" },
+ { { "s0" }, "$9" },
+ { { "s1" }, "$10" },
+ { { "s2" }, "$11" },
+ { { "s3" }, "$12" },
+ { { "s4" }, "$13" },
+ { { "s5" }, "$14" },
+ { { "s6", "fp" }, "$15" },
+ { { "a0" }, "$16" },
+ { { "a1" }, "$17" },
+ { { "a2" }, "$18" },
+ { { "a3" }, "$19" },
+ { { "a4" }, "$20" },
+ { { "a5" }, "$21" },
+ { { "t8" }, "$22" },
+ { { "t9" }, "$23" },
+ { { "t10" }, "$24" },
+ { { "t11" }, "$25" },
+ { { "ra" }, "$26" },
+ { { "t12", "pv" }, "$27" },
+ { { "at" }, "$28" },
+ { { "gp" }, "$29" },
+ { { "sp" }, "$30" },
+ { { "zero" }, "$31" }
+};
+
+void AlphaTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
+ unsigned &NumAliases) const {
+ Aliases = GCCRegAliases;
+ NumAliases = llvm::array_lengthof(GCCRegAliases);
+}
+} // end anonymous namespace.
+
+namespace {
class ARMTargetInfo : public TargetInfo {
// Possible FPU choices.
enum FPUMode {
@@ -2693,6 +2800,9 @@ static TargetInfo *AllocateTarget(const std::string &T) {
default:
return NULL;
+ case llvm::Triple::alpha:
+ return new LinuxTargetInfo<AlphaTargetInfo>(T);
+
case llvm::Triple::arm:
case llvm::Triple::thumb:
if (Triple.isOSDarwin())
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 4668d73..2ff58fb 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -1319,7 +1319,9 @@ Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
Lib64 = "lib64";
std::string GccTriple = "";
- if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
+ if (Arch == llvm::Triple::alpha) {
+ GccTriple = "alpha-unknown-linux-gnu";
+ } else if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) &&
Exists)
GccTriple = "arm-linux-gnueabi";
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index a8998c4..681b0ed 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -3819,6 +3819,8 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
else if (ToolChain.getArch() == llvm::Triple::arm
|| ToolChain.getArch() == llvm::Triple::thumb)
CmdArgs.push_back("armelf_linux_eabi");
+ else if (ToolChain.getArch() == llvm::Triple::alpha)
+ CmdArgs.push_back("elf64alpha");
else if (ToolChain.getArch() == llvm::Triple::ppc)
CmdArgs.push_back("elf32ppclinux");
else if (ToolChain.getArch() == llvm::Triple::ppc64)
@@ -3841,7 +3843,8 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
(!Args.hasArg(options::OPT_static) &&
!Args.hasArg(options::OPT_shared))) {
CmdArgs.push_back("-dynamic-linker");
- if (ToolChain.getArch() == llvm::Triple::x86)
+ if (ToolChain.getArch() == llvm::Triple::x86 ||
+ ToolChain.getArch() == llvm::Triple::alpha)
CmdArgs.push_back("/lib/ld-linux.so.2");
else if (ToolChain.getArch() == llvm::Triple::arm ||
ToolChain.getArch() == llvm::Triple::thumb)
--
1.7.3.4
More information about the cfe-dev
mailing list