Skip to content

Commit 3592a6e

Browse files
committedFeb 18, 2016
[LLDB][MIPS] Provide CPU string to compiler for appropriate code generation for MIPS
SUMMARY: This patch implements ArchSpec::GetClangTargetCPU() that provides string representing current architecture as a target CPU. This string is then passed to tools like clang so that they generate correct code for that target. Reviewers: clayborg, zturner Subscribers: mohit.bhakkad, sagar, jaydeep, lldb-commits Differential Revision: http://reviews.llvm.org/D17022 llvm-svn: 261206
1 parent 6b63b14 commit 3592a6e

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed
 

Diff for: ‎lldb/include/lldb/Core/ArchSpec.h

+10
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ class ArchSpec
287287
const char *
288288
GetArchitectureName () const;
289289

290+
//------------------------------------------------------------------
291+
/// Returns a string representing current architecture as a target CPU
292+
/// for tools like compiler, disassembler etc.
293+
///
294+
/// @return A string representing target CPU for the current
295+
/// architecture.
296+
//------------------------------------------------------------------
297+
std::string
298+
GetClangTargetCPU ();
299+
290300
//------------------------------------------------------------------
291301
/// Clears the object state.
292302
///

Diff for: ‎lldb/source/Core/ArchSpec.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,56 @@ ArchSpec::GetArchitectureName () const
511511
return "unknown";
512512
}
513513

514+
std::string
515+
ArchSpec::GetClangTargetCPU ()
516+
{
517+
std::string cpu;
518+
const llvm::Triple::ArchType machine = GetMachine();
519+
520+
if (machine == llvm::Triple::mips ||
521+
machine == llvm::Triple::mipsel ||
522+
machine == llvm::Triple::mips64 ||
523+
machine == llvm::Triple::mips64el)
524+
{
525+
switch (m_core)
526+
{
527+
case ArchSpec::eCore_mips32:
528+
case ArchSpec::eCore_mips32el:
529+
cpu = "mips32"; break;
530+
case ArchSpec::eCore_mips32r2:
531+
case ArchSpec::eCore_mips32r2el:
532+
cpu = "mips32r2"; break;
533+
case ArchSpec::eCore_mips32r3:
534+
case ArchSpec::eCore_mips32r3el:
535+
cpu = "mips32r3"; break;
536+
case ArchSpec::eCore_mips32r5:
537+
case ArchSpec::eCore_mips32r5el:
538+
cpu = "mips32r5"; break;
539+
case ArchSpec::eCore_mips32r6:
540+
case ArchSpec::eCore_mips32r6el:
541+
cpu = "mips32r6"; break;
542+
case ArchSpec::eCore_mips64:
543+
case ArchSpec::eCore_mips64el:
544+
cpu = "mips64"; break;
545+
case ArchSpec::eCore_mips64r2:
546+
case ArchSpec::eCore_mips64r2el:
547+
cpu = "mips64r2"; break;
548+
case ArchSpec::eCore_mips64r3:
549+
case ArchSpec::eCore_mips64r3el:
550+
cpu = "mips64r3"; break;
551+
case ArchSpec::eCore_mips64r5:
552+
case ArchSpec::eCore_mips64r5el:
553+
cpu = "mips64r5"; break;
554+
case ArchSpec::eCore_mips64r6:
555+
case ArchSpec::eCore_mips64r6el:
556+
cpu = "mips64r6"; break;
557+
default:
558+
break;
559+
}
560+
}
561+
return cpu;
562+
}
563+
514564
uint32_t
515565
ArchSpec::GetMachOCPUType () const
516566
{

Diff for: ‎lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
179179
if (exe_scope)
180180
target_sp = exe_scope->CalculateTarget();
181181

182+
ArchSpec target_arch;
183+
if (target_sp)
184+
target_arch = target_sp->GetArchitecture();
185+
186+
const auto target_machine = target_arch.GetMachine();
187+
182188
// If the expression is being evaluated in the context of an existing
183189
// stack frame, we introspect to see if the language runtime is available.
184190
auto frame = exe_scope->CalculateStackFrame();
@@ -197,9 +203,9 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
197203

198204
// 2. Configure the compiler with a set of default options that are appropriate
199205
// for most situations.
200-
if (target_sp && target_sp->GetArchitecture().IsValid())
206+
if (target_sp && target_arch.IsValid())
201207
{
202-
std::string triple = target_sp->GetArchitecture().GetTriple().str();
208+
std::string triple = target_arch.GetTriple().str();
203209
m_compiler->getTargetOpts().Triple = triple;
204210
if (log)
205211
log->Printf("Using %s as the target triple", m_compiler->getTargetOpts().Triple.c_str());
@@ -224,13 +230,17 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
224230
m_compiler->getTargetOpts().ABI = "apcs-gnu";
225231
}
226232
// Supported subsets of x86
227-
if (target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86 ||
228-
target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86_64)
233+
if (target_machine == llvm::Triple::x86 ||
234+
target_machine == llvm::Triple::x86_64)
229235
{
230236
m_compiler->getTargetOpts().Features.push_back("+sse");
231237
m_compiler->getTargetOpts().Features.push_back("+sse2");
232238
}
233239

240+
// Set the target CPU to generate code for.
241+
// This will be empty for any CPU that doesn't really need to make a special CPU string.
242+
m_compiler->getTargetOpts().CPU = target_arch.GetClangTargetCPU();
243+
234244
// 3. Now allow the runtime to provide custom configuration options for the target.
235245
// In this case, a specialized language runtime is available and we can query it for extra options.
236246
// For 99% of use cases, this will not be needed and should be provided when basic platform detection is not enough.

0 commit comments

Comments
 (0)
Please sign in to comment.