mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 19:12:56 +02:00
Fix LLVM C API for DataLayout
We removed access to the DataLayout on the TargetMachine and deprecated the C API function LLVMGetTargetMachineData() in r243114. However the way I tried to be backward compatible was broken: I changed the wrapper of the TargetMachine to be a structure that includes the DataLayout as well. However the TargetMachine is also wrapped by the ExecutionEngine, in the more classic way. A client using the TargetMachine wrapped by the ExecutionEngine and trying to get the DataLayout would break. It seems tricky to solve the problem completely in the C API implementation. This patch tries to address this backward compatibility in a more lighter way in the C++ API. The C API is restored in its original state and the removed C++ API is reintroduced, but privately. The C API is friended to the TargetMachine and should be the only consumer for this API. Reviewers: ributzka Differential Revision: http://reviews.llvm.org/D12263 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 246052
This commit is contained in:
parent
7b48dec33f
commit
94298376a8
@ -23,6 +23,13 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
// This function from the C API is deprecated. We still supports it using a
|
||||||
|
// private method on the TargetMachine for now. But it needs to be friended and
|
||||||
|
// so we forward declare it here.
|
||||||
|
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
|
||||||
|
}
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class InstrItineraryData;
|
class InstrItineraryData;
|
||||||
@ -103,6 +110,12 @@ protected: // Can only create subclasses.
|
|||||||
|
|
||||||
unsigned RequireStructuredCFG : 1;
|
unsigned RequireStructuredCFG : 1;
|
||||||
|
|
||||||
|
/// This API is here to support the C API, deprecated in 3.7 release.
|
||||||
|
/// This should never be used outside of legacy existing client.
|
||||||
|
const DataLayout &getDataLayout() const { return DL; }
|
||||||
|
friend struct LLVMOpaqueTargetData * ::LLVMGetTargetMachineData(
|
||||||
|
LLVMTargetMachineRef T);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mutable TargetOptions Options;
|
mutable TargetOptions Options;
|
||||||
|
|
||||||
|
@ -32,25 +32,14 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
|
||||||
// The TargetMachine uses to offer access to a DataLayout member. This is reflected
|
|
||||||
// in the C API. For backward compatibility reason, this structure allows to keep
|
|
||||||
// a DataLayout member accessible to C client that have a handle to a
|
|
||||||
// LLVMTargetMachineRef.
|
|
||||||
struct LLVMOpaqueTargetMachine {
|
|
||||||
std::unique_ptr<TargetMachine> Machine;
|
|
||||||
DataLayout DL;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static TargetMachine *unwrap(LLVMTargetMachineRef P) {
|
static TargetMachine *unwrap(LLVMTargetMachineRef P) {
|
||||||
return P->Machine.get();
|
return reinterpret_cast<TargetMachine *>(P);
|
||||||
}
|
}
|
||||||
static Target *unwrap(LLVMTargetRef P) {
|
static Target *unwrap(LLVMTargetRef P) {
|
||||||
return reinterpret_cast<Target*>(P);
|
return reinterpret_cast<Target*>(P);
|
||||||
}
|
}
|
||||||
static LLVMTargetMachineRef wrap(const TargetMachine *P) {
|
static LLVMTargetMachineRef wrap(const TargetMachine *P) {
|
||||||
return new LLVMOpaqueTargetMachine{ std::unique_ptr<TargetMachine>(const_cast<TargetMachine*>(P)), P->createDataLayout() };
|
return reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine *>(P));
|
||||||
}
|
}
|
||||||
static LLVMTargetRef wrap(const Target * P) {
|
static LLVMTargetRef wrap(const Target * P) {
|
||||||
return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
|
return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
|
||||||
@ -79,16 +68,16 @@ LLVMTargetRef LLVMGetTargetFromName(const char *Name) {
|
|||||||
LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T,
|
LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T,
|
||||||
char **ErrorMessage) {
|
char **ErrorMessage) {
|
||||||
std::string Error;
|
std::string Error;
|
||||||
|
|
||||||
*T = wrap(TargetRegistry::lookupTarget(TripleStr, Error));
|
*T = wrap(TargetRegistry::lookupTarget(TripleStr, Error));
|
||||||
|
|
||||||
if (!*T) {
|
if (!*T) {
|
||||||
if (ErrorMessage)
|
if (ErrorMessage)
|
||||||
*ErrorMessage = strdup(Error.c_str());
|
*ErrorMessage = strdup(Error.c_str());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,10 +144,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
|
|||||||
CM, OL));
|
CM, OL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) { delete unwrap(T); }
|
||||||
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) {
|
|
||||||
delete T;
|
|
||||||
}
|
|
||||||
|
|
||||||
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) {
|
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) {
|
||||||
const Target* target = &(unwrap(T)->getTarget());
|
const Target* target = &(unwrap(T)->getTarget());
|
||||||
@ -180,9 +166,9 @@ char* LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T) {
|
|||||||
return strdup(StringRep.c_str());
|
return strdup(StringRep.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @deprecated: see "struct LLVMOpaqueTargetMachine" description above
|
/** Deprecated: use LLVMGetDataLayout(LLVMModuleRef M) instead. */
|
||||||
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
|
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
|
||||||
return wrap(&T->DL);
|
return wrap(&unwrap(T)->getDataLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
|
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
|
||||||
|
Loading…
Reference in New Issue
Block a user