[Lldb-commits] [PATCH] D17022: [LLDB][MIPS] Provide CPU string to compiler for appropriate code generation for MIPS
Bhushan Attarde via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 9 01:54:17 PST 2016
bhushan created this revision.
bhushan added reviewers: clayborg, spyffe.
bhushan added subscribers: lldb-commits, nitesh.jain, jaydeep, sagar, mohit.bhakkad.
bhushan set the repository for this revision to rL LLVM.
Currently, LLDB (ClangExpressionParser) does not pass `clang::TargetOptions::CPU` to clang which is supposed to contain the name of the target CPU to generate code for.
So, compiler generates the code for its default CPU (mips32r2 and mips64r2 for MIPS32 and MIPS64 respectively).
This causes problems in evaluating expressions in some cases.
For example, if we are debugging MIPS revision 6 (R6) application, as we do not pass CPU information to the compiler so compiler chooses default target and generates code for mips32r2/mips64r2.
The code generated for expression then fails to run on R6 because instruction set differs for R2 and R6 (few instructions in R2 are not available in R6).
The causes expression to fail.
This patch sets `clang::TargetOptions::CPU` with appropriate string so that compiler can generate correct code for that target.
Repository:
rL LLVM
http://reviews.llvm.org/D17022
Files:
source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -175,6 +175,10 @@
if (exe_scope)
target_sp = exe_scope->CalculateTarget();
+ ArchSpec arch;
+ if (target_sp)
+ arch = target_sp->GetArchitecture();
+
// TODO: figure out what to really do when we don't have a valid target.
// Sometimes this will be ok to just use the host target triple (when we
// evaluate say "2+3", but other expressions like breakpoint conditions
@@ -197,6 +201,50 @@
m_compiler->getTargetOpts().Features.push_back("+sse2");
}
+ if (arch.GetMachine() == llvm::Triple::mips ||
+ arch.GetMachine() == llvm::Triple::mipsel ||
+ arch.GetMachine() == llvm::Triple::mips64 ||
+ arch.GetMachine() == llvm::Triple::mips64el)
+ {
+ std::string cpu;
+ switch (arch.GetCore())
+ {
+ case ArchSpec::eCore_mips32:
+ case ArchSpec::eCore_mips32el:
+ cpu = "mips32"; break;
+ case ArchSpec::eCore_mips32r2:
+ case ArchSpec::eCore_mips32r2el:
+ cpu = "mips32r2"; break;
+ case ArchSpec::eCore_mips32r3:
+ case ArchSpec::eCore_mips32r3el:
+ cpu = "mips32r3"; break;
+ case ArchSpec::eCore_mips32r5:
+ case ArchSpec::eCore_mips32r5el:
+ cpu = "mips32r5"; break;
+ case ArchSpec::eCore_mips32r6:
+ case ArchSpec::eCore_mips32r6el:
+ cpu = "mips32r6"; break;
+ case ArchSpec::eCore_mips64:
+ case ArchSpec::eCore_mips64el:
+ cpu = "mips64"; break;
+ case ArchSpec::eCore_mips64r2:
+ case ArchSpec::eCore_mips64r2el:
+ cpu = "mips64r2"; break;
+ case ArchSpec::eCore_mips64r3:
+ case ArchSpec::eCore_mips64r3el:
+ cpu = "mips64r3"; break;
+ case ArchSpec::eCore_mips64r5:
+ case ArchSpec::eCore_mips64r5el:
+ cpu = "mips64r5"; break;
+ case ArchSpec::eCore_mips64r6:
+ case ArchSpec::eCore_mips64r6el:
+ cpu = "mips64r6"; break;
+ default:
+ cpu = "generic"; break;
+ }
+ m_compiler->getTargetOpts().CPU = cpu;
+ }
+
// Any arm32 iOS environment, but not on arm64
if (m_compiler->getTargetOpts().Triple.find("arm64") == std::string::npos &&
m_compiler->getTargetOpts().Triple.find("arm") != std::string::npos &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17022.47305.patch
Type: text/x-patch
Size: 2602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160209/da75e407/attachment-0001.bin>
More information about the lldb-commits
mailing list