Skip to content

Commit d7bb3c4

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6-beta.1
2 parents efa2833 + ab837f0 commit d7bb3c4

25 files changed

+358
-76
lines changed

llvm/include/llvm/IR/Module.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,14 @@ class LLVM_ABI Module {
471471

472472
/// Look up the specified global in the module symbol table.
473473
/// If it does not exist, invoke a callback to create a declaration of the
474-
/// global and return it. The global is constantexpr casted to the expected
475-
/// type if necessary.
476-
Constant *
474+
/// global and return it.
475+
GlobalVariable *
477476
getOrInsertGlobal(StringRef Name, Type *Ty,
478477
function_ref<GlobalVariable *()> CreateGlobalCallback);
479478

480479
/// Look up the specified global in the module symbol table. If required, this
481480
/// overload constructs the global variable using its constructor's defaults.
482-
Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
481+
GlobalVariable *getOrInsertGlobal(StringRef Name, Type *Ty);
483482

484483
/// @}
485484
/// @name Global Alias Accessors

llvm/include/llvm/Transforms/IPO/LowerTypeTests.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ class LowerTypeTestsPass : public PassInfoMixin<LowerTypeTestsPass> {
223223
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
224224
};
225225

226+
class SimplifyTypeTestsPass : public PassInfoMixin<SimplifyTypeTestsPass> {
227+
public:
228+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
229+
};
230+
226231
} // end namespace llvm
227232

228233
#endif // LLVM_TRANSFORMS_IPO_LOWERTYPETESTS_H

llvm/include/llvm/Transforms/Scalar/GVN.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class NonLocalDepResult;
5353
class OptimizationRemarkEmitter;
5454
class PHINode;
5555
class TargetLibraryInfo;
56+
class TargetTransformInfo;
5657
class Value;
5758
/// A private "module" namespace for types and utilities used by GVN. These
5859
/// are implementation details and should not be used by clients.
@@ -226,6 +227,7 @@ class GVNPass : public PassInfoMixin<GVNPass> {
226227
MemoryDependenceResults *MD = nullptr;
227228
DominatorTree *DT = nullptr;
228229
const TargetLibraryInfo *TLI = nullptr;
230+
const TargetTransformInfo *TTI = nullptr;
229231
AssumptionCache *AC = nullptr;
230232
SetVector<BasicBlock *> DeadBlocks;
231233
OptimizationRemarkEmitter *ORE = nullptr;
@@ -318,7 +320,8 @@ class GVNPass : public PassInfoMixin<GVNPass> {
318320
using UnavailBlkVect = SmallVector<BasicBlock *, 64>;
319321

320322
bool runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
321-
const TargetLibraryInfo &RunTLI, AAResults &RunAA,
323+
const TargetLibraryInfo &RunTLI,
324+
const TargetTransformInfo &RunTTI, AAResults &RunAA,
322325
MemoryDependenceResults *RunMD, LoopInfo &LI,
323326
OptimizationRemarkEmitter *ORE, MemorySSA *MSSA = nullptr);
324327

llvm/include/llvm/Transforms/Utils/LoopUtils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ bool sinkRegionForLoopNest(DomTreeNode *, AAResults *, LoopInfo *,
175175
/// \p AllowSpeculation is whether values should be hoisted even if they are not
176176
/// guaranteed to execute in the loop, but are safe to speculatively execute.
177177
bool hoistRegion(DomTreeNode *, AAResults *, LoopInfo *, DominatorTree *,
178-
AssumptionCache *, TargetLibraryInfo *, Loop *,
179-
MemorySSAUpdater &, ScalarEvolution *, ICFLoopSafetyInfo *,
180-
SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *, bool,
181-
bool AllowSpeculation);
178+
AssumptionCache *, TargetLibraryInfo *, TargetTransformInfo *,
179+
Loop *, MemorySSAUpdater &, ScalarEvolution *,
180+
ICFLoopSafetyInfo *, SinkAndHoistLICMFlags &,
181+
OptimizationRemarkEmitter *, bool, bool AllowSpeculation);
182182

183183
/// Return true if the induction variable \p IV in a Loop whose latch is
184184
/// \p LatchBlock would become dead if the exit test \p Cond were removed.

llvm/lib/CodeGen/LowerEmuTLS.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ bool addEmuTlsVar(Module &M, const GlobalVariable *GV) {
140140
PointerType *InitPtrType = PointerType::getUnqual(C);
141141
Type *ElementTypes[4] = {WordType, WordType, VoidPtrType, InitPtrType};
142142
StructType *EmuTlsVarType = StructType::create(ElementTypes);
143-
EmuTlsVar = cast<GlobalVariable>(
144-
M.getOrInsertGlobal(EmuTlsVarName, EmuTlsVarType));
143+
EmuTlsVar = M.getOrInsertGlobal(EmuTlsVarName, EmuTlsVarType);
145144
copyLinkageVisibility(M, GV, EmuTlsVar);
146145

147146
// Define "__emutls_t.*" and "__emutls_v.*" only if GV is defined.
@@ -155,8 +154,7 @@ bool addEmuTlsVar(Module &M, const GlobalVariable *GV) {
155154
GlobalVariable *EmuTlsTmplVar = nullptr;
156155
if (InitValue) {
157156
std::string EmuTlsTmplName = ("__emutls_t." + GV->getName()).str();
158-
EmuTlsTmplVar = dyn_cast_or_null<GlobalVariable>(
159-
M.getOrInsertGlobal(EmuTlsTmplName, GVType));
157+
EmuTlsTmplVar = M.getOrInsertGlobal(EmuTlsTmplName, GVType);
160158
assert(EmuTlsTmplVar && "Failed to create emualted TLS initializer");
161159
EmuTlsTmplVar->setConstant(true);
162160
EmuTlsTmplVar->setInitializer(const_cast<Constant*>(InitValue));

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,10 +1975,9 @@ Value *TargetLoweringBase::getIRStackGuard(IRBuilderBase &IRB) const {
19751975
if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
19761976
Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
19771977
PointerType *PtrTy = PointerType::getUnqual(M.getContext());
1978-
Constant *C = M.getOrInsertGlobal("__guard_local", PtrTy);
1979-
if (GlobalVariable *G = dyn_cast_or_null<GlobalVariable>(C))
1980-
G->setVisibility(GlobalValue::HiddenVisibility);
1981-
return C;
1978+
GlobalVariable *G = M.getOrInsertGlobal("__guard_local", PtrTy);
1979+
G->setVisibility(GlobalValue::HiddenVisibility);
1980+
return G;
19821981
}
19831982
return nullptr;
19841983
}

llvm/lib/CodeGen/WasmEHPrepare.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ bool WasmEHPrepareImpl::prepareEHPads(Function &F) {
247247
// we depend on CoalesceFeaturesAndStripAtomics to downgrade it to
248248
// non-thread-local ones, in which case we don't allow this object to be
249249
// linked with other objects using shared memory.
250-
LPadContextGV = cast<GlobalVariable>(
251-
M.getOrInsertGlobal("__wasm_lpad_context", LPadContextTy));
250+
LPadContextGV = M.getOrInsertGlobal("__wasm_lpad_context", LPadContextTy);
252251
LPadContextGV->setThreadLocalMode(GlobalValue::GeneralDynamicTLSModel);
253252

254253
LPadIndexField = LPadContextGV;

llvm/lib/IR/Module.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,9 @@ GlobalVariable *Module::getGlobalVariable(StringRef Name,
250250
}
251251

252252
/// getOrInsertGlobal - Look up the specified global in the module symbol table.
253-
/// 1. If it does not exist, add a declaration of the global and return it.
254-
/// 2. Else, the global exists but has the wrong type: return the function
255-
/// with a constantexpr cast to the right type.
256-
/// 3. Finally, if the existing global is the correct declaration, return the
257-
/// existing global.
258-
Constant *Module::getOrInsertGlobal(
253+
/// If it does not exist, add a declaration of the global and return it.
254+
/// Otherwise, return the existing global.
255+
GlobalVariable *Module::getOrInsertGlobal(
259256
StringRef Name, Type *Ty,
260257
function_ref<GlobalVariable *()> CreateGlobalCallback) {
261258
// See if we have a definition for the specified global already.
@@ -269,7 +266,7 @@ Constant *Module::getOrInsertGlobal(
269266
}
270267

271268
// Overload to construct a global variable using its constructor's defaults.
272-
Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {
269+
GlobalVariable *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {
273270
return getOrInsertGlobal(Name, Ty, [&] {
274271
return new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
275272
nullptr, Name);

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,8 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
14641464
if (!LTOPreLink)
14651465
MPM.addPass(EliminateAvailableExternallyPass());
14661466

1467+
MPM.addPass(SimplifyTypeTestsPass());
1468+
14671469
// Do RPO function attribute inference across the module to forward-propagate
14681470
// attributes where applicable.
14691471
// FIXME: Is this really an optimization rather than a canonicalization?

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
100100
MODULE_PASS("lower-emutls", LowerEmuTLSPass())
101101
MODULE_PASS("lower-global-dtors", LowerGlobalDtorsPass())
102102
MODULE_PASS("lower-ifunc", LowerIFuncPass())
103+
MODULE_PASS("simplify-type-tests", SimplifyTypeTestsPass())
103104
MODULE_PASS("lowertypetests", LowerTypeTestsPass())
104105
MODULE_PASS("fatlto-cleanup", FatLtoCleanup())
105106
MODULE_PASS("pgo-force-function-attrs", PGOForceFunctionAttrsPass(PGOOpt ? PGOOpt->ColdOptType : PGOOptions::ColdFuncOpt::Default))

0 commit comments

Comments
 (0)