Skip to content

Commit 78e7f03

Browse files
authored
Unrolled build for rust-lang#115638
Rollup merge of rust-lang#115638 - ldm0:ldm/llvm-args-fix, r=nikic `-Cllvm-args` usability improvement fixes: rust-lang#26338 fixes: rust-lang#115564 Two problems were found during playing with `-Cllvm-args` 1. When `llvm.link-shared` is set to `false` in `config.toml`, output of `rustc -C llvm-args='--help-list-hidden'` doesn't contain `--emit-dwarf-unwind` and `--emulated-tls`. When it is set to `true`, `rustc -C llvm-args='--help-list-hidden'` emits `--emit-dwarf-unwind`, but `--emulated-tls` is still missing. 2. Setting `-Cllvm-args=--emit-dwarf-unwind=always` doesn't take any effect, but `-Cllvm-args=-machine-outliner-reruns=3` does work. ### 1 Adding `RegisterCodeGenFlags` to register codegen flags fixed the first problem. `rustc -C llvm-args='--help-list-hidden'` emits full codegen flags including `--emit-dwarf-unwind` and `--emulated-tls`. ### 2 Constructing `TargetOptions` from `InitTargetOptionsFromCodeGenFlags` in `LLVMRustCreateTargetMachine` fixed the second problem. The `LLVMRustSetLLVMOptions` calls `ParseCommandLineOptions` which parses given `llvm-args`. For options like `machine-outliner-reruns`, it just works, since the codegen logic directly consumes the parsing result: [machine-outliner-reruns register](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/lib/CodeGen/MachineOutliner.cpp#L114) [machine-outliner-reruns consumption](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/lib/CodeGen/MachineOutliner.cpp#L1138) But for flags defined in `TargetOptions` and `MCTargetOptions` to take effect, constructing them with `InitTargetOptionsFromCodeGenFlags` is essential, or the parsing result is just not consumed. Similar patterns can be observed in [lli](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/tools/llc/llc.cpp#L494), [llc](https://github.com/rust-lang/llvm-project/blob/0537f6354cffe546cbf47f6dc9c7f82e49e86cfb/llvm/tools/lli/lli.cpp#L517), etc.
2 parents cd71a37 + 487766c commit 78e7f03

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/Analysis/AliasAnalysis.h"
1010
#include "llvm/Analysis/TargetLibraryInfo.h"
1111
#include "llvm/Analysis/TargetTransformInfo.h"
12+
#include "llvm/CodeGen/CommandFlags.h"
1213
#include "llvm/CodeGen/TargetSubtargetInfo.h"
1314
#include "llvm/IR/AutoUpgrade.h"
1415
#include "llvm/IR/AssemblyAnnotationWriter.h"
@@ -50,6 +51,8 @@
5051

5152
using namespace llvm;
5253

54+
static codegen::RegisterCodeGenFlags CGF;
55+
5356
typedef struct LLVMOpaquePass *LLVMPassRef;
5457
typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
5558

@@ -422,7 +425,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
422425
return nullptr;
423426
}
424427

425-
TargetOptions Options;
428+
TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip);
426429

427430
Options.FloatABIType = FloatABI::Default;
428431
if (UseSoftFloat) {

0 commit comments

Comments
 (0)