aboutsummaryrefslogtreecommitdiff
path: root/tools/opt
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2013-04-15 07:07:21 +0000
committerEric Christopher <echristo@gmail.com>2013-04-15 07:07:21 +0000
commitfdf9624f3c20a24345a543979e1cb5c94a9d6715 (patch)
tree6ec5cecd545b9e184656b368a027a5c0d169ef2b /tools/opt
parent2f7ce4522d3d5a6cf484f7f4eb51d559aff37090 (diff)
Recommit r179497 after fixing uninitialized variable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179512 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r--tools/opt/opt.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index e385d7f577..de8bd41d11 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -403,7 +403,7 @@ struct BreakpointPrinter : public ModulePass {
AU.setPreservesAll();
}
};
-
+
} // anonymous namespace
char BreakpointPrinter::ID = 0;
@@ -446,7 +446,7 @@ static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
Builder.DisableUnitAtATime = !UnitAtATime;
Builder.DisableUnrollLoops = OptLevel == 0;
Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
-
+
Builder.populateFunctionPassManager(FPM);
Builder.populateModulePassManager(MPM);
}
@@ -529,9 +529,8 @@ static TargetMachine* GetTargetMachine(Triple TheTriple) {
const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
Error);
// Some modules don't specify a triple, and this is okay.
- if (!TheTarget) {
+ if (!TheTarget)
return 0;
- }
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
@@ -598,8 +597,11 @@ int main(int argc, char **argv) {
}
// If we are supposed to override the target triple, do so now.
- if (!TargetTriple.empty())
+ const DataLayout *TD = 0;
+ if (!TargetTriple.empty()) {
M->setTargetTriple(Triple::normalize(TargetTriple));
+ TD = GetTargetMachine(Triple(TargetTriple))->getDataLayout();
+ }
// Figure out what stream we are supposed to write to...
OwningPtr<tool_output_file> Out;
@@ -641,16 +643,16 @@ int main(int argc, char **argv) {
TLI->disableAllFunctions();
Passes.add(TLI);
- // Add an appropriate DataLayout instance for this module.
- DataLayout *TD = 0;
- const std::string &ModuleDataLayout = M.get()->getDataLayout();
- if (!ModuleDataLayout.empty())
- TD = new DataLayout(ModuleDataLayout);
- else if (!DefaultDataLayout.empty())
- TD = new DataLayout(DefaultDataLayout);
-
+ // If we don't have a data layout by now go ahead and set it if we can.
+ if (!TD) {
+ const std::string &ModuleDataLayout = M.get()->getDataLayout();
+ if (!ModuleDataLayout.empty())
+ TD = new DataLayout(ModuleDataLayout);
+ else if (!DefaultDataLayout.empty())
+ TD = new DataLayout(DefaultDataLayout);
+ }
if (TD)
- Passes.add(TD);
+ Passes.add(new DataLayout(*TD));
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = 0;