Skip to content

Commit 6451380

Browse files
committed
Use fast regalloc and codegen at OptLevel=0.
1 parent a6e188f commit 6451380

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/comp/back/link.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ mod write {
138138
let int LLVMAssemblyFile = 0;
139139
let int LLVMObjectFile = 1;
140140
let int LLVMNullFile = 2;
141+
let int LLVMOptNone = 0; // -O0
142+
let int LLVMOptLess = 1; // -O1
143+
let int LLVMOptDefault = 2; // -O2, -Os
144+
let int LLVMOptAggressive = 3; // -O3
145+
146+
auto CodeGenOptLevel;
147+
alt (opts.optimize) {
148+
case (0u) {
149+
CodeGenOptLevel = LLVMOptNone;
150+
}
151+
case (1u) {
152+
CodeGenOptLevel = LLVMOptLess;
153+
}
154+
case (2u) {
155+
CodeGenOptLevel = LLVMOptDefault;
156+
}
157+
case (3u) {
158+
CodeGenOptLevel = LLVMOptAggressive;
159+
}
160+
case (_) {
161+
fail;
162+
}
163+
}
164+
141165
auto FileType;
142166
if (opts.output_type == output_type_object ||
143167
opts.output_type == output_type_exe) {
@@ -159,7 +183,8 @@ mod write {
159183
llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
160184
str::buf(triple),
161185
str::buf(output),
162-
LLVMAssemblyFile);
186+
LLVMAssemblyFile,
187+
CodeGenOptLevel);
163188
}
164189

165190
// Save the object file for -c or --save-temps alone
@@ -170,7 +195,8 @@ mod write {
170195
llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
171196
str::buf(triple),
172197
str::buf(output),
173-
LLVMObjectFile);
198+
LLVMObjectFile,
199+
CodeGenOptLevel);
174200
}
175201
} else {
176202
// If we aren't saving temps then just output the file
@@ -179,7 +205,8 @@ mod write {
179205
auto triple = x86::get_target_triple();
180206
llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
181207
str::buf(triple),
182-
str::buf(output), FileType);
208+
str::buf(output), FileType,
209+
CodeGenOptLevel);
183210
}
184211
// Clean up and return
185212

src/comp/lib/llvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ native mod llvm = "rustllvm" {
856856
/* FIXME: The FileType is an enum.*/
857857
fn LLVMRustWriteOutputFile(PassManagerRef PM, ModuleRef M,
858858
sbuf Triple, sbuf Output,
859-
int FileType);
859+
int FileType, int OptLevel);
860860

861861
/** Returns a string describing the last error caused by an LLVMRust*
862862
call. */

src/rustllvm/RustWrapper.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ extern "C" void LLVMAddStandardModulePasses(LLVMPassManagerRef PM,
5353
int *RustHackToFetchPassesO = (int*)LLVMAddBasicAliasAnalysisPass;
5454
int *RustHackToFetchPasses2O = (int*)LLVMAddStandardModulePasses;
5555

56-
enum LLVMCodeGenFileType {
57-
LLVMAssemblyFile,
58-
LLVMObjectFile,
59-
LLVMNullFile // Do not emit any output.
60-
};
6156

6257
extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
6358
static std::string err;
@@ -77,7 +72,8 @@ extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
7772
LLVMModuleRef M,
7873
const char *triple,
7974
const char *path,
80-
LLVMCodeGenFileType FileType) {
75+
TargetMachine::CodeGenFileType FileType,
76+
CodeGenOpt::Level OptLevel) {
8177

8278
// Set compilation options.
8379
llvm::NoFramePointerElim = true;
@@ -91,16 +87,14 @@ extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
9187
std::string FeaturesStr;
9288
TargetMachine *Target = TheTarget->createTargetMachine(triple, FeaturesStr);
9389
bool NoVerify = false;
94-
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
9590
PassManager *PM = unwrap<PassManager>(PMR);
9691
std::string ErrorInfo;
9792
raw_fd_ostream OS(path, ErrorInfo,
9893
raw_fd_ostream::F_Binary);
9994
formatted_raw_ostream FOS(OS);
100-
TargetMachine::CodeGenFileType FileType2 =
101-
static_cast<TargetMachine::CodeGenFileType>(FileType);
10295

103-
bool foo = Target->addPassesToEmitFile(*PM, FOS, FileType2, OLvl, NoVerify);
96+
bool foo = Target->addPassesToEmitFile(*PM, FOS, FileType, OptLevel,
97+
NoVerify);
10498
assert(!foo);
10599
(void)foo;
106100
PM->run(*unwrap(M));

0 commit comments

Comments
 (0)