about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Craven <david@craven.ch>2018-07-24 12:03:28 +0200
committerDavid Craven <david@craven.ch>2018-08-01 15:32:22 +0200
commit2d5f62fb48536d69aa7de0d7504df278271ccf25 (patch)
tree15b42735137e3a28b827d6c5e7adff3c4dc9d458
parent8c069ceba81a0fffc1ce95aaf7e8339e11bf2796 (diff)
downloadrust-2d5f62fb48536d69aa7de0d7504df278271ccf25.tar.gz
rust-2d5f62fb48536d69aa7de0d7504df278271ccf25.zip
[RISCV] Enable LLVM backend.
-rw-r--r--config.toml.example2
-rw-r--r--src/librustc_llvm/build.rs4
-rw-r--r--src/librustc_llvm/lib.rs6
-rw-r--r--src/rustllvm/PassWrapper.cpp9
4 files changed, 19 insertions, 2 deletions
diff --git a/config.toml.example b/config.toml.example
index 99073416334..cc40e96b316 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -62,7 +62,7 @@
 # not built by default and the experimental Rust compilation targets that depend
 # on them will not work unless the user opts in to building them. By default the
 # `WebAssembly` target is enabled when compiling LLVM from scratch.
-#experimental-targets = "WebAssembly"
+#experimental-targets = "WebAssembly;RISCV"
 
 # Cap the number of parallel linker invocations when compiling LLVM.
 # This can be useful when building LLVM with debug info, which significantly
diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs
index 5910e55def3..4e24a26983d 100644
--- a/src/librustc_llvm/build.rs
+++ b/src/librustc_llvm/build.rs
@@ -100,6 +100,10 @@ fn main() {
         optional_components.push("hexagon");
     }
 
+    if major > 6 {
+        optional_components.push("riscv");
+    }
+
     // FIXME: surely we don't need all these components, right? Stuff like mcjit
     //        or interpreter the compiler itself never uses.
     let required_components = &["ipo",
diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs
index 05f6b5b5fbd..ffa97bd6fa5 100644
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
@@ -90,6 +90,12 @@ pub fn initialize_available_targets() {
                  LLVMInitializeMSP430Target,
                  LLVMInitializeMSP430TargetMC,
                  LLVMInitializeMSP430AsmPrinter);
+    init_target!(llvm_component = "riscv",
+                 LLVMInitializeRISCVTargetInfo,
+                 LLVMInitializeRISCVTarget,
+                 LLVMInitializeRISCVTargetMC,
+                 LLVMInitializeRISCVAsmPrinter,
+                 LLVMInitializeRISCVAsmParser);
     init_target!(llvm_component = "sparc",
                  LLVMInitializeSparcTargetInfo,
                  LLVMInitializeSparcTarget,
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp
index a13e4ffa8f8..7305dc71cbf 100644
--- a/src/rustllvm/PassWrapper.cpp
+++ b/src/rustllvm/PassWrapper.cpp
@@ -171,6 +171,12 @@ bool LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
 #define SUBTARGET_MSP430
 #endif
 
+#ifdef LLVM_COMPONENT_RISCV
+#define SUBTARGET_RISCV SUBTARGET(RISCV)
+#else
+#define SUBTARGET_RISCV
+#endif
+
 #ifdef LLVM_COMPONENT_SPARC
 #define SUBTARGET_SPARC SUBTARGET(Sparc)
 #else
@@ -192,7 +198,8 @@ bool LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
   SUBTARGET_SYSTEMZ                                                            \
   SUBTARGET_MSP430                                                             \
   SUBTARGET_SPARC                                                              \
-  SUBTARGET_HEXAGON
+  SUBTARGET_HEXAGON                                                            \
+  SUBTARGET_RISCV                                                              \
 
 #define SUBTARGET(x)                                                           \
   namespace llvm {                                                             \