[PATCH] D50482: Added another optimization pass to make vectorizing possible
Emmett Neyman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 8 16:54:25 PDT 2018
emmettneyman created this revision.
emmettneyman added reviewers: morehouse, kcc.
Herald added a subscriber: cfe-commits.
I noticed that my code wasn't going deep into the loop vectorizer code so added another pass that makes it go further.
Repository:
rC Clang
https://reviews.llvm.org/D50482
Files:
clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
Index: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
===================================================================
--- clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -77,6 +77,18 @@
std::exit(1);
}
+// Helper function that returns a *TargetMachine, used by OptLLVM
+static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr,
+ StringRef FeaturesStr,
+ const TargetOptions &Options,
+ CodeGenOpt::Level OLvl) {
+ std::string E;
+ const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple, E);
+ return TheTarget->createTargetMachine(TheTriple.getTriple(), CPUStr,
+ FeaturesStr, Options, getRelocModel(),
+ getCodeModel(), OLvl);
+}
+
// Helper function to add optimization passes to the TargetMachine at the
// specified optimization level, OptLevel
static void AddOptimizationPasses(legacy::PassManagerBase &MPM,
@@ -100,17 +112,24 @@
if (!M || verifyModule(*M, &errs()))
ErrorAndExit("Could not parse IR");
+ Triple ModuleTriple(M->getTargetTriple());
+ const TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
+ std::unique_ptr<TargetMachine> TM(GetTargetMachine(ModuleTriple, getCPUStr(),
+ getFeaturesStr(), Options, OLvl));
setFunctionAttributes(getCPUStr(), getFeaturesStr(), *M);
-
+
legacy::PassManager Passes;
- Triple ModuleTriple(M->getTargetTriple());
Passes.add(new TargetLibraryInfoWrapperPass(ModuleTriple));
- Passes.add(createTargetTransformInfoWrapperPass(TargetIRAnalysis()));
+ Passes.add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
+
+ auto <M = static_cast<LLVMTargetMachine &>(*TM);
+ Passes.add(LTM.createPassConfig(Passes));
+
Passes.add(createVerifierPass());
AddOptimizationPasses(Passes, OLvl, 0);
-
+
// Add a pass that writes the optimized IR to an output stream
std::string outString;
raw_string_ostream OS(outString);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50482.159830.patch
Type: text/x-patch
Size: 2186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180808/40d38734/attachment.bin>
More information about the cfe-commits
mailing list