Skip to content

Commit c5ce24a

Browse files
committed
Update
1 parent 75d7385 commit c5ce24a

2 files changed

Lines changed: 120 additions & 22 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,9 @@ include(AddLLVM)
1919
include_directories(${LLVM_INCLUDE_DIRS})
2020
include_directories(pcg-cpp/include)
2121
set(LLVM_LINK_COMPONENTS core support irreader irprinter analysis instcombine passes targetparser)
22-
add_llvm_executable(strcmp PARTIAL_SOURCES_INTENDED strcmp.cpp)
23-
add_llvm_executable(vectorizer PARTIAL_SOURCES_INTENDED vectorizer.cpp)
24-
add_llvm_executable(instcombine-gen PARTIAL_SOURCES_INTENDED instcombine-gen.cpp)
25-
add_llvm_executable(deadcode PARTIAL_SOURCES_INTENDED deadcode.cpp)
26-
add_llvm_executable(upgrade-constexpr PARTIAL_SOURCES_INTENDED upgrade-constexpr.cpp)
27-
add_llvm_executable(scan96625 PARTIAL_SOURCES_INTENDED scan96625.cpp)
28-
add_llvm_executable(daggrep PARTIAL_SOURCES_INTENDED daggrep.cpp)
29-
add_llvm_executable(normalizer PARTIAL_SOURCES_INTENDED normalizer.cpp)
30-
add_llvm_executable(lutscan PARTIAL_SOURCES_INTENDED lutscan.cpp)
31-
add_llvm_executable(strchr PARTIAL_SOURCES_INTENDED strchr.cpp)
32-
add_llvm_executable(libcall PARTIAL_SOURCES_INTENDED libcall.cpp)
33-
add_llvm_executable(state PARTIAL_SOURCES_INTENDED state.cpp)
34-
add_llvm_executable(alloca PARTIAL_SOURCES_INTENDED alloca.cpp)
35-
add_llvm_executable(empty-alloca PARTIAL_SOURCES_INTENDED empty-alloca.cpp)
36-
add_llvm_executable(overflow PARTIAL_SOURCES_INTENDED overflow.cpp)
37-
add_llvm_executable(pr104696 PARTIAL_SOURCES_INTENDED pr104696.cpp)
38-
add_llvm_executable(ub PARTIAL_SOURCES_INTENDED ub.cpp)
39-
add_llvm_executable(cmpdistrib PARTIAL_SOURCES_INTENDED cmpdistrib.cpp)
40-
add_llvm_executable(switchsinglebackedge PARTIAL_SOURCES_INTENDED switchsinglebackedge.cpp)
41-
add_llvm_executable(invokenothrow PARTIAL_SOURCES_INTENDED invokenothrow.cpp)
42-
add_llvm_executable(assumes PARTIAL_SOURCES_INTENDED assumes.cpp)
43-
add_llvm_executable(issue108449 PARTIAL_SOURCES_INTENDED issue108449.cpp)
22+
23+
file(GLOB SOURCES *.cpp)
24+
foreach(SOURCE ${SOURCES})
25+
get_filename_component(FILENAME ${SOURCE} NAME_WE)
26+
add_llvm_executable(${FILENAME} PARTIAL_SOURCES_INTENDED ${SOURCE})
27+
endforeach()

lifetime.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// SPDX-License-Identifier: MIT License
2+
// Copyright (c) 2024 Yingwei Zheng
3+
// This file is licensed under the MIT License.
4+
// See the LICENSE file for more information.
5+
6+
#include "llvm/IR/Argument.h"
7+
#include "llvm/IR/IntrinsicInst.h"
8+
#include <llvm/ADT/DenseMap.h>
9+
#include <llvm/Analysis/TargetLibraryInfo.h>
10+
#include <llvm/IR/BasicBlock.h>
11+
#include <llvm/IR/Constants.h>
12+
#include <llvm/IR/DataLayout.h>
13+
#include <llvm/IR/DerivedTypes.h>
14+
#include <llvm/IR/Function.h>
15+
#include <llvm/IR/GlobalVariable.h>
16+
#include <llvm/IR/IRBuilder.h>
17+
#include <llvm/IR/InstVisitor.h>
18+
#include <llvm/IR/Instruction.h>
19+
#include <llvm/IR/Instructions.h>
20+
#include <llvm/IR/Intrinsics.h>
21+
#include <llvm/IR/LLVMContext.h>
22+
#include <llvm/IR/Module.h>
23+
#include <llvm/IR/Operator.h>
24+
#include <llvm/IR/Type.h>
25+
#include <llvm/IR/Value.h>
26+
#include <llvm/IR/Verifier.h>
27+
#include <llvm/IRPrinter/IRPrintingPasses.h>
28+
#include <llvm/IRReader/IRReader.h>
29+
#include <llvm/Support/CommandLine.h>
30+
#include <llvm/Support/Error.h>
31+
#include <llvm/Support/ErrorHandling.h>
32+
#include <llvm/Support/FileSystem.h>
33+
#include <llvm/Support/FormattedStream.h>
34+
#include <llvm/Support/InitLLVM.h>
35+
#include <llvm/Support/MemoryBuffer.h>
36+
#include <llvm/Support/SourceMgr.h>
37+
#include <llvm/Support/ToolOutputFile.h>
38+
#include <llvm/Support/raw_ostream.h>
39+
#include <llvm/TargetParser/Triple.h>
40+
#include <cstdint>
41+
#include <cstdlib>
42+
#include <filesystem>
43+
#include <map>
44+
#include <memory>
45+
#include <unordered_map>
46+
47+
using namespace llvm;
48+
namespace fs = std::filesystem;
49+
50+
static cl::opt<std::string>
51+
InputDir(cl::Positional, cl::desc("<directory for input LLVM IR files>"),
52+
cl::Required, cl::value_desc("inputdir"));
53+
54+
int main(int argc, char **argv) {
55+
InitLLVM Init{argc, argv};
56+
cl::ParseCommandLineOptions(argc, argv, "scanner\n");
57+
58+
std::vector<std::string> BlockList{
59+
"ruby/optimized/vm.ll",
60+
"/regexec.ll",
61+
"quickjs/optimized/quickjs.ll",
62+
};
63+
64+
std::vector<fs::path> InputFiles;
65+
for (auto &Entry : fs::recursive_directory_iterator(std::string(InputDir))) {
66+
if (Entry.is_regular_file()) {
67+
auto &Path = Entry.path();
68+
if (Path.extension() == ".ll" &&
69+
Path.string().find("/optimized/") != std::string::npos) {
70+
auto Str = Path.string();
71+
bool Blocked = false;
72+
for (auto &Pattern : BlockList)
73+
if (Str.find(Pattern) != std::string::npos) {
74+
Blocked = true;
75+
break;
76+
}
77+
if (!Blocked)
78+
InputFiles.push_back(Path);
79+
}
80+
}
81+
}
82+
errs() << "Input files: " << InputFiles.size() << '\n';
83+
LLVMContext Context;
84+
uint32_t Count = 0;
85+
86+
for (auto &Path : InputFiles) {
87+
SMDiagnostic Err;
88+
auto M = parseIRFile(Path.string(), Err, Context);
89+
if (!M)
90+
continue;
91+
92+
for (auto &F : *M) {
93+
if (F.empty())
94+
continue;
95+
96+
for (auto &BB : F) {
97+
for (auto &I : BB) {
98+
if (auto *LI = dyn_cast<LifetimeIntrinsic>(&I)) {
99+
auto *Arg = LI->getArgOperand(1);
100+
if (!isa<AllocaInst>(Arg) && !isa<Argument>(Arg)) {
101+
errs() << *Arg << '\n';
102+
std::abort();
103+
}
104+
}
105+
}
106+
}
107+
}
108+
109+
errs() << "\rProgress: " << ++Count;
110+
}
111+
errs() << '\n';
112+
113+
return EXIT_SUCCESS;
114+
}

0 commit comments

Comments
 (0)