[cfe-dev] Implementing blocks with try-finally semantics

João Paulo Labegalini de Carvalho via cfe-dev cfe-dev at lists.llvm.org
Thu Jun 21 09:25:40 PDT 2018


Hi,

I am working on a block annotation which should have a try-finally
semantics. For example, given a code like this:

*__speculate* *{*
  if (x > 2) {
    y = 0;
  }
*}*

clang should produce something like

__exec_mode = *__begin_spec*();
if (__exec_mode == SW) {
  if (__read_barrier(&x) > 2) {
    __write_barrier(&y, 0);
  }
  *__end_spec*();
} else {
  if (x > 2) {
    y = 0;
  }
  *__end_spec*();
}

such that __end_spec() is guaranteed to be called on every exit of the
__speculate {}  block.

It is my understanding that Clang implements try-finally statements as a
Microsoft Specific Extension. However, I would not like to have such
restriction, since such extension is only available for a reduced number of
targets.

My question is, how should I implement try-finally semantics? Through an IR
pass (fixing up every exit with a call to __end_spec()) or it is possible
to extend from CXXTryStmt (reusing some CodeGen code)?
-- 
João Paulo L. de Carvalho
Computer Science |  IC-UNICAMP | Campinas , SP - Brazil
jaopaulolc at gmail.com
joao.carvalho at ic.unicamp.br
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180621/a844b62b/attachment.html>


More information about the cfe-dev mailing list