Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion flang/tools/tco/tco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ static cl::opt<bool> emitFir("emit-fir",
cl::desc("Parse and pretty-print the input"),
cl::init(false));

static cl::opt<unsigned>
OptLevel("O",
cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "
"(default = '-O2')"),
cl::Prefix, cl::init(2));

static cl::opt<std::string> targetTriple("target",
cl::desc("specify a target triple"),
cl::init("native"));
Expand Down Expand Up @@ -96,6 +102,22 @@ static void printModule(mlir::ModuleOp mod, raw_ostream &output) {
output << mod << '\n';
}

static std::optional<llvm::OptimizationLevel>
getOptimizationLevel(unsigned level) {
switch (level) {
default:
return std::nullopt;
case 0:
return llvm::OptimizationLevel::O0;
case 1:
return llvm::OptimizationLevel::O1;
case 2:
return llvm::OptimizationLevel::O2;
case 3:
return llvm::OptimizationLevel::O3;
}
}

// compile a .fir file
static llvm::LogicalResult
compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
Expand Down Expand Up @@ -157,9 +179,17 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
if (mlir::failed(passPipeline.addToPipeline(pm, errorHandler)))
return mlir::failure();
} else {
MLIRToLLVMPassPipelineConfig config(llvm::OptimizationLevel::O2);
std::optional<llvm::OptimizationLevel> level =
getOptimizationLevel(OptLevel);
if (!level) {
errs() << "Error invalid optimization level\n";
return mlir::failure();
}
MLIRToLLVMPassPipelineConfig config(*level);
// TODO: config.StackArrays should be set here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack arrays isn't enabled at -O3 (only -Ofast). I think it is okay to leave this as TODO for another patch if anyone wants a flag for it.

config.EnableOpenMP = true; // assume the input contains OpenMP
config.AliasAnalysis = enableAliasAnalysis && !testGeneratorMode;
config.LoopVersioning = OptLevel > 2;
if (codeGenLLVM) {
// Run only CodeGen passes.
fir::createDefaultFIRCodeGenPassPipeline(pm, config);
Expand Down