[PATCH] D45736: [SimplifyLibcalls] Replace locked IO with unlocked IO

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 17 14:08:17 PDT 2018


xbolva00 created this revision.
xbolva00 added a reviewer: efriedma.
Herald added a subscriber: llvm-commits.
xbolva00 added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:122
 
+static bool isInThreadUnsafeFunction(CallInst *CI, IRBuilder<> &B) {
+  Function *F = CI->getFunction();
----------------
Maybe we could check for "main" function too and threat it as if it was a "static one"?


If we have a static function and there are IO function calls, we could replace them by inlocked io ("_unlocked" variants) to gain better speed, if we know, that there is no fork or pthread_create use in the current module.

Currently patch is just to present this my idea.  fwrite, fputs, fgetc, fputc are replaced with their unlocked variants, if possible.

Feedback especially for "isInThreadUnsafeFunction" is welcomed.

There are no test cases  in this patch. If there is possibility that this optimization would be acceptable, I would add them. Also I would add "replacements" for other IO calls missed in this patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D45736

Files:
  include/llvm/Analysis/TargetLibraryInfo.def
  include/llvm/Transforms/Utils/BuildLibCalls.h
  lib/Analysis/TargetLibraryInfo.cpp
  lib/Transforms/Utils/BuildLibCalls.cpp
  lib/Transforms/Utils/SimplifyLibCalls.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45736.142824.patch
Type: text/x-patch
Size: 19383 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180417/5bc41b4f/attachment.bin>


More information about the llvm-commits mailing list