llvm2alive: add support for a few more libcalls
MODIFY
ir/attrs.cpp
ir/attrs.cpp
@@ -53,6 +53,8 @@ ostream& operator<<(ostream &os, const FnAttrs &attr) {
os << " align(" << attr.align << ')';
if (attr.has(FnAttrs::NoThrow))
os << " nothrow";
+ if (attr.has(FnAttrs::NoAlias))
+ os << " noalias";
return os;
}

MODIFY
ir/attrs.h
ir/attrs.h
@@ -47,7 +47,7 @@ public:
ArgMemOnly = 1 << 2, NNaN = 1 << 3, NoReturn = 1 << 4,
Dereferenceable = 1 << 5, NonNull = 1 << 6,
NoFree = 1 << 7, NoUndef = 1 << 8, Align = 1 << 9,
- NoThrow = 1 << 10 };
+ NoThrow = 1 << 10, NoAlias = 1 << 11 };
FnAttrs(unsigned bits = None) : bits(bits) {}

MODIFY
llvm_util/known_fns.cpp
llvm_util/known_fns.cpp
@@ -147,6 +147,10 @@ known_call(llvm::CallInst &i, const llvm::TargetLibraryInfo &TLI,
RETURN_KNOWN(
make_unique<UnaryOp>(*ty, value_name(i), *args[0], UnaryOp::Trunc));
+ case llvm::LibFunc_sqrt:
+ case llvm::LibFunc_sqrtf:
+ RETURN_KNOWN(
+ make_unique<UnaryOp>(*ty, value_name(i), *args[0], UnaryOp::Sqrt));
case llvm::LibFunc_fwrite: {
auto size = getInt(*args[1]);
@@ -186,6 +190,31 @@ known_call(llvm::CallInst &i, const llvm::TargetLibraryInfo &TLI,
RETURN_KNOWN_ATTRS();
}
+ case llvm::LibFunc_strchr:
+ case llvm::LibFunc_strrchr:
+ attrs.set(FnAttrs::NoThrow);
+ attrs.set(FnAttrs::ArgMemOnly);
+ attrs.set(FnAttrs::NoWrite);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_fopen:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ attrs.set(FnAttrs::NoAlias);
+ set_param(0, ParamAttrs::NoCapture);
+ set_param(0, ParamAttrs::ReadOnly);
+ set_param(1, ParamAttrs::NoCapture);
+ set_param(1, ParamAttrs::ReadOnly);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_fdopen:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ attrs.set(FnAttrs::NoAlias);
+ set_param(1, ParamAttrs::NoCapture);
+ set_param(1, ParamAttrs::ReadOnly);
+ RETURN_KNOWN_ATTRS();
+
case llvm::LibFunc_fputc:
case llvm::LibFunc_fputc_unlocked:
case llvm::LibFunc_fstat:
@@ -224,6 +253,60 @@ known_call(llvm::CallInst &i, const llvm::TargetLibraryInfo &TLI,
set_param(3, ParamAttrs::NoCapture);
RETURN_KNOWN_ATTRS();
+ case llvm::LibFunc_open:
+ ret_and_args_no_undef();
+ set_param(0, ParamAttrs::NoCapture);
+ set_param(0, ParamAttrs::ReadOnly);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_read:
+ ret_and_args_no_undef();
+ set_param(1, ParamAttrs::NoCapture);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_write:
+ ret_and_args_no_undef();
+ set_param(1, ParamAttrs::NoCapture);
+ set_param(1, ParamAttrs::ReadOnly);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_stat:
+ case llvm::LibFunc_lstat:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ set_param(0, ParamAttrs::NoCapture);
+ set_param(0, ParamAttrs::ReadOnly);
+ set_param(1, ParamAttrs::NoCapture);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_mkdir:
+ case llvm::LibFunc_rmdir:
+ case llvm::LibFunc_remove:
+ case llvm::LibFunc_realpath:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ set_param(0, ParamAttrs::NoCapture);
+ set_param(0, ParamAttrs::ReadOnly);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_clearerr:
+ case llvm::LibFunc_closedir:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ set_param(0, ParamAttrs::NoCapture);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_rename:
+ case llvm::LibFunc_utime:
+ case llvm::LibFunc_utimes:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ set_param(0, ParamAttrs::NoCapture);
+ set_param(0, ParamAttrs::ReadOnly);
+ set_param(1, ParamAttrs::NoCapture);
+ set_param(1, ParamAttrs::ReadOnly);
+ RETURN_KNOWN_ATTRS();
+
case llvm::LibFunc_gettimeofday:
ret_and_args_no_undef();
attrs.set(FnAttrs::NoThrow);
@@ -232,6 +315,8 @@ known_call(llvm::CallInst &i, const llvm::TargetLibraryInfo &TLI,
set_param(1, ParamAttrs::NoCapture);
RETURN_KNOWN_ATTRS();
+ case llvm::LibFunc_chmod:
+ case llvm::LibFunc_chown:
case llvm::LibFunc_perror:
ret_and_args_no_undef();
attrs.set(FnAttrs::NoThrow);
@@ -239,6 +324,31 @@ known_call(llvm::CallInst &i, const llvm::TargetLibraryInfo &TLI,
set_param(0, ParamAttrs::ReadOnly);
RETURN_KNOWN_ATTRS();
+ case llvm::LibFunc_dunder_isoc99_sscanf:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ set_param(0, ParamAttrs::NoCapture);
+ set_param(0, ParamAttrs::ReadOnly);
+ set_param(1, ParamAttrs::NoCapture);
+ set_param(1, ParamAttrs::ReadOnly);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_getenv:
+ case llvm::LibFunc_atof:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ attrs.set(FnAttrs::NoWrite);
+ set_param(0, ParamAttrs::NoCapture);
+ RETURN_KNOWN_ATTRS();
+
+ case llvm::LibFunc_frexp:
+ case llvm::LibFunc_frexpf:
+ case llvm::LibFunc_frexpl:
+ ret_and_args_no_undef();
+ attrs.set(FnAttrs::NoThrow);
+ set_param(1, ParamAttrs::NoCapture);
+ RETURN_KNOWN_ATTRS();
+
default:
RETURN_UNKNOWN_KNOWN();
}

llvm2alive: add support for a few more libcalls