[clang] [clang-repl][CodeGen] Add setOptLevel, #pragma clang repl optimize(N) (PR #214793)
Aaron Jomy via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 22 15:25:11 PDT 2026
================
@@ -533,6 +617,21 @@ llvm::Expected<IncrementalExecutor &> Interpreter::getExecutionEngine() {
return *IncrExecutor.get();
}
+void Interpreter::setOptLevel(unsigned OptLevel, unsigned OptSize) {
+ CodeGenerator *CG = Act->getCodeGen();
+ if (!CG)
+ return;
+
+ CodeGenOptions CGO = getCompilerInstance()->getCodeGenOpts();
+ CGO.OptimizationLevel = OptLevel;
+ CGO.OptimizeSize = OptSize;
+
+ // The next (empty) module was already staged with the old options; re-stage
+ // it so the new options apply to the next parsed input.
+ std::unique_ptr<llvm::Module> Empty(CG->ReleaseModule());
+ CG->StartModule("incr_module_opt", Empty->getContext(), CGO);
----------------
aaronj0 wrote:
This has been dropped. setOptLevel just updates the CodeGenOptions in the CompilerInvocation, so nothing gets pushed or discarded, and whatever CodeGen emits after the pragma picks up the new level. Which is the same as the cling pragma.
https://github.com/llvm/llvm-project/pull/214793
More information about the cfe-commits
mailing list