Skip to content

Commit 27bee8d

Browse files
committed
good
1 parent 9e95cde commit 27bee8d

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// #ifndef LLVM_ANALYSIS_JUMPTABLEFINDERPASS_H
2+
// #define LLVM_ANALYSIS_JUMPTABLEFINDERPASS_H
3+
4+
// #include "llvm/IR/PassManager.h"
5+
// #include "llvm/IR/Module.h"
6+
// #include "llvm/Support/raw_ostream.h"
7+
// #include <set>
8+
9+
// namespace llvm {
10+
11+
// class JumptableFinderPass : public PassInfoMixin<JumptableFinderPass> {
12+
// public:
13+
// /// Main entry point for the pass. Analyzes the module to find and analyze jump tables.
14+
// PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
15+
// /// Implementation of the jump table finder.
16+
// void jumptableFinderImpl(Module &M);
17+
18+
// /// Analyze a SwitchInst for potential jump table patterns.
19+
// void findJumpTableFromSwitch(SwitchInst *SI);
20+
21+
// /// Analyze a GetElementPtrInst for jump table patterns.
22+
// void analyzeJumpTable(GetElementPtrInst *GEP);
23+
24+
// /// Analyze the index computation of a jump table.
25+
// void analyzeIndex(Value *Index);
26+
27+
// /// Find all potential targets for a jump table.
28+
// void findTargets(GetElementPtrInst *GEP, std::set<BasicBlock*> &Targets);
29+
30+
// /// Check the density of a SwitchInst's cases to determine if it forms a jump table.
31+
// bool checkDensity(SwitchInst *SI);
32+
33+
// /// Check if a GetElementPtrInst leads to an indirect branch.
34+
// bool leadsToIndirectBranch(GetElementPtrInst *GEP);
35+
// };
36+
37+
// } // namespace llvm
38+
39+
// #endif // LLVM_ANALYSIS_JUMPTABLEFINDERPASS_H
40+
41+
#ifndef LLVM_TRANSFORMS_IPO_JUMPTABLEFINDER_H
42+
#define LLVM_TRANSFORMS_IPO_JUMPTABLEFINDER_H
43+
44+
#include "llvm/IR/Module.h"
45+
#include "llvm/IR/PassManager.h" // For PassInfoMixin and PreservedAnalyses
46+
#include "llvm/IR/Function.h"
47+
#include "llvm/IR/Instructions.h"
48+
#include "llvm/IR/Constants.h"
49+
#include "llvm/Support/raw_ostream.h"
50+
#include <set>
51+
52+
namespace llvm {
53+
54+
class JumptableFinderPass : public PassInfoMixin<JumptableFinderPass> {
55+
public:
56+
// Entry point for the pass
57+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
58+
};
59+
60+
} // namespace llvm
61+
62+
#endif // LLVM_TRANSFORMS_IPO_JUMPTABLEFINDER_H

llvm/lib/Target/X86/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ tablegen(LLVM X86GenFoldTables.inc -gen-x86-fold-tables -asmwriternum=1)
2323
add_public_tablegen_target(X86CommonTableGen)
2424

2525
set(sources
26+
X86MatchJumptablePass.cpp
2627
X86ArgumentStackSlotRebase.cpp
2728
X86AsmPrinter.cpp
2829
X86AvoidTrailingCall.cpp

llvm/lib/Target/X86/X86MatchJumptablePass.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "llvm/CodeGen/MachineRegisterInfo.h"
55
#include "llvm/Support/Debug.h"
66
#include "llvm/Support/raw_ostream.h"
7+
#include "X86MatchJumptablePass.h"
78

9+
#define DEBUG_TYPE "x86-my-pass"
810

911
using namespace llvm;
1012

@@ -38,7 +40,12 @@ namespace {
3840

3941
char X86MatchJumptablePass::ID = 0;
4042

41-
// Register the pass
42-
FunctionPass *llvm::createX86MatchJumptablePass() {
43-
return new X86MatchJumptablePass();
44-
}
43+
// Ensure the function is in the llvm namespace
44+
namespace llvm {
45+
46+
// Define the pass
47+
FunctionPass *createX86MatchJumptablePass() {
48+
return new X86MatchJumptablePass();
49+
}
50+
51+
} // end llvm namespace
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef LLVM_LIB_TARGET_X86_X86MATCHJUMPTABLEPASS_H
2+
#define LLVM_LIB_TARGET_X86_X86MATCHJUMPTABLEPASS_H
3+
4+
5+
#pragma once
6+
#include "llvm/CodeGen/MachineFunctionPass.h"
7+
8+
namespace llvm {
9+
10+
FunctionPass *createX86MatchJumptablePass();
11+
12+
} // end namespace llvm
13+
14+
#endif // LLVM_LIB_TARGET_X86_X86MATCHJUMPTABLEPASS_H

llvm/lib/Target/X86/X86TargetMachine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "X86TargetMachine.h"
1414
#include "MCTargetDesc/X86MCTargetDesc.h"
15+
#include "X86MatchJumptablePass.h" // Include the header with the function declaration
1516
#include "TargetInfo/X86TargetInfo.h"
1617
#include "X86.h"
1718
#include "X86MachineFunctionInfo.h"
@@ -464,7 +465,7 @@ MachineFunctionInfo *X86TargetMachine::createMachineFunctionInfo(
464465

465466
void X86PassConfig::addIRPasses() {
466467
addPass(createAtomicExpandLegacyPass());
467-
468+
addPass(llvm::createX86MatchJumptablePass());
468469
// We add both pass anyway and when these two passes run, we skip the pass
469470
// based on the option level and option attribute.
470471
addPass(createX86LowerAMXIntrinsicsPass());

0 commit comments

Comments
 (0)