Skip to content

Commit 763131b

Browse files
authored
opt: Add -enable-builtin flag (#145808)
Currently TargetLibraryInfo assumes ~everything is available, and specific triples (or the -disable-builtin) flag, opt-out. This is a backwards system, where features should only be positively be enabled when known. Add this flag to help migrate tests with no triple.
1 parent 37f8719 commit 763131b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: opt -S -mtriple=amdgcn-- -passes=inferattrs %s | FileCheck -check-prefix=NOBUILTIN %s
2+
; RUN: opt -S -enable-builtin=malloc -mtriple=amdgcn-- -passes=inferattrs %s | FileCheck -check-prefix=WITHBUILTIN %s
3+
4+
; Test that the -enable-builtin flag works and forces recognition of
5+
; malloc despite the target's default TargetLibraryInfo.
6+
7+
; NOBUILTIN: declare ptr @malloc(i64)
8+
9+
; WITHBUILTIN: declare noalias noundef ptr @malloc(i64 noundef) #0
10+
; WITHBUILTIN: attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
11+
12+
declare ptr @malloc(i64)
13+

llvm/tools/opt/optdriver.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ static cl::list<std::string> DisableBuiltins(
203203
"disable-builtin",
204204
cl::desc("Disable specific target library builtin function"));
205205

206+
static cl::list<std::string> EnableBuiltins(
207+
"enable-builtin",
208+
cl::desc("Enable specific target library builtin functions"));
209+
206210
static cl::opt<bool> EnableDebugify(
207211
"enable-debugify",
208212
cl::desc(
@@ -670,14 +674,25 @@ extern "C" int optMain(
670674
else {
671675
// Disable individual builtin functions in TargetLibraryInfo.
672676
LibFunc F;
673-
for (auto &FuncName : DisableBuiltins)
677+
for (auto &FuncName : DisableBuiltins) {
674678
if (TLII.getLibFunc(FuncName, F))
675679
TLII.setUnavailable(F);
676680
else {
677681
errs() << argv[0] << ": cannot disable nonexistent builtin function "
678682
<< FuncName << '\n';
679683
return 1;
680684
}
685+
}
686+
687+
for (auto &FuncName : EnableBuiltins) {
688+
if (TLII.getLibFunc(FuncName, F))
689+
TLII.setAvailable(F);
690+
else {
691+
errs() << argv[0] << ": cannot enable nonexistent builtin function "
692+
<< FuncName << '\n';
693+
return 1;
694+
}
695+
}
681696
}
682697

683698
if (UseNPM) {

0 commit comments

Comments
 (0)