Skip to content

Commit ce50bed

Browse files
committed
Pass -DLLVM_RUSTLLVM to compile against rust llvm fork.
If using system llvm don't try use modifications made in the fork.
1 parent 6aee1e2 commit ce50bed

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

mk/rustllvm.mk

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ RUSTLLVM_INCS_$(1) = $$(LLVM_EXTRA_INCDIRS_$(1)) \
3232
$$(call CFG_CC_INCLUDE_$(1),$$(S)src/rustllvm/include)
3333
RUSTLLVM_OBJS_OBJS_$(1) := $$(RUSTLLVM_OBJS_CS_$(1):rustllvm/%.cpp=$(1)/rustllvm/%.o)
3434

35+
# Flag that we are building with Rust's llvm fork
36+
ifeq ($(CFG_LLVM_ROOT),)
37+
RUSTLLVM_CXXFLAGS_$(1) := -DLLVM_RUSTLLVM
38+
endif
39+
3540
# Note that we appease `cl.exe` and its need for some sort of exception
3641
# handling flag with the `EHsc` argument here as well.
3742
ifeq ($$(findstring msvc,$(1)),msvc)
@@ -55,6 +60,7 @@ $(1)/rustllvm/%.o: $(S)src/rustllvm/%.cpp $$(MKFILE_DEPS) $$(LLVM_CONFIG_$(1))
5560
$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@,) \
5661
$$(subst /,//,$$(LLVM_CXXFLAGS_$(1))) \
5762
$$(RUSTLLVM_COMPONENTS_$(1)) \
63+
$$(RUSTLLVM_CXXFLAGS_$(1)) \
5864
$$(EXTRA_RUSTLLVM_CXXFLAGS_$(1)) \
5965
$$(RUSTLLVM_INCS_$(1)) \
6066
$$<

src/rustllvm/PassWrapper.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ LLVMRustHasFeature(LLVMTargetMachineRef TM,
162162
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
163163
}
164164

165+
#if LLVM_RUSTLLVM
165166
/// getLongestEntryLength - Return the length of the longest entry in the table.
166167
///
167168
static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
@@ -178,7 +179,7 @@ LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
178179
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
179180
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
180181

181-
printf("Available CPUs for this target:\n\n");
182+
printf("Available CPUs for this target:\n");
182183
for (auto &CPU : CPUTable)
183184
printf(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc);
184185
printf("\n");
@@ -191,15 +192,28 @@ LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
191192
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
192193
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
193194

194-
printf("Available features for this target:\n\n");
195+
printf("Available features for this target:\n");
195196
for (auto &Feature : FeatTable)
196197
printf(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
197198
printf("\n");
198199

199200
printf("Use +feature to enable a feature, or -feature to disable it.\n"
200-
"For example, rustc -C -target-cpu=mycpu -C target-feature=+feature1,-feature2\n");
201+
"For example, rustc -C -target-cpu=mycpu -C target-feature=+feature1,-feature2\n\n");
201202
}
202203

204+
#else
205+
206+
extern "C" void
207+
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
208+
printf("Target CPU help is not supported by this LLVM version.\n\n");
209+
}
210+
211+
extern "C" void
212+
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
213+
printf("Target features help is not supported by this LLVM version.\n\n");
214+
}
215+
#endif
216+
203217
extern "C" LLVMTargetMachineRef
204218
LLVMRustCreateTargetMachine(const char *triple,
205219
const char *cpu,

0 commit comments

Comments
 (0)