forked from OSchip/llvm-project
[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
This commit is contained in:
parent
6b63b14851
commit
3592a6ec6b
|
@ -287,6 +287,16 @@ public:
|
|||
const char *
|
||||
GetArchitectureName () const;
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// Returns a string representing current architecture as a target CPU
|
||||
/// for tools like compiler, disassembler etc.
|
||||
///
|
||||
/// @return A string representing target CPU for the current
|
||||
/// architecture.
|
||||
//------------------------------------------------------------------
|
||||
std::string
|
||||
GetClangTargetCPU ();
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// Clears the object state.
|
||||
///
|
||||
|
|
|
@ -511,6 +511,56 @@ ArchSpec::GetArchitectureName () const
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
std::string
|
||||
ArchSpec::GetClangTargetCPU ()
|
||||
{
|
||||
std::string cpu;
|
||||
const llvm::Triple::ArchType machine = GetMachine();
|
||||
|
||||
if (machine == llvm::Triple::mips ||
|
||||
machine == llvm::Triple::mipsel ||
|
||||
machine == llvm::Triple::mips64 ||
|
||||
machine == llvm::Triple::mips64el)
|
||||
{
|
||||
switch (m_core)
|
||||
{
|
||||
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:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return cpu;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ArchSpec::GetMachOCPUType () const
|
||||
{
|
||||
|
|
|
@ -179,6 +179,12 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
|
|||
if (exe_scope)
|
||||
target_sp = exe_scope->CalculateTarget();
|
||||
|
||||
ArchSpec target_arch;
|
||||
if (target_sp)
|
||||
target_arch = target_sp->GetArchitecture();
|
||||
|
||||
const auto target_machine = target_arch.GetMachine();
|
||||
|
||||
// If the expression is being evaluated in the context of an existing
|
||||
// stack frame, we introspect to see if the language runtime is available.
|
||||
auto frame = exe_scope->CalculateStackFrame();
|
||||
|
@ -197,9 +203,9 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
|
|||
|
||||
// 2. Configure the compiler with a set of default options that are appropriate
|
||||
// for most situations.
|
||||
if (target_sp && target_sp->GetArchitecture().IsValid())
|
||||
if (target_sp && target_arch.IsValid())
|
||||
{
|
||||
std::string triple = target_sp->GetArchitecture().GetTriple().str();
|
||||
std::string triple = target_arch.GetTriple().str();
|
||||
m_compiler->getTargetOpts().Triple = triple;
|
||||
if (log)
|
||||
log->Printf("Using %s as the target triple", m_compiler->getTargetOpts().Triple.c_str());
|
||||
|
@ -224,13 +230,17 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
|
|||
m_compiler->getTargetOpts().ABI = "apcs-gnu";
|
||||
}
|
||||
// Supported subsets of x86
|
||||
if (target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86 ||
|
||||
target_sp->GetArchitecture().GetMachine() == llvm::Triple::x86_64)
|
||||
if (target_machine == llvm::Triple::x86 ||
|
||||
target_machine == llvm::Triple::x86_64)
|
||||
{
|
||||
m_compiler->getTargetOpts().Features.push_back("+sse");
|
||||
m_compiler->getTargetOpts().Features.push_back("+sse2");
|
||||
}
|
||||
|
||||
// Set the target CPU to generate code for.
|
||||
// This will be empty for any CPU that doesn't really need to make a special CPU string.
|
||||
m_compiler->getTargetOpts().CPU = target_arch.GetClangTargetCPU();
|
||||
|
||||
// 3. Now allow the runtime to provide custom configuration options for the target.
|
||||
// In this case, a specialized language runtime is available and we can query it for extra options.
|
||||
// For 99% of use cases, this will not be needed and should be provided when basic platform detection is not enough.
|
||||
|
|
Loading…
Reference in New Issue