Add command-line option to specify position-independent codegen
This commit is contained in:
9
ispc.cpp
9
ispc.cpp
@@ -72,7 +72,7 @@ Module *m;
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Target::GetTarget(const char *arch, const char *cpu, const char *isa,
|
Target::GetTarget(const char *arch, const char *cpu, const char *isa,
|
||||||
Target *t) {
|
bool pic, Target *t) {
|
||||||
if (cpu == NULL) {
|
if (cpu == NULL) {
|
||||||
std::string hostCPU = llvm::sys::getHostCPUName();
|
std::string hostCPU = llvm::sys::getHostCPUName();
|
||||||
if (hostCPU.size() > 0)
|
if (hostCPU.size() > 0)
|
||||||
@@ -100,6 +100,8 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa,
|
|||||||
|
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
|
t->generatePIC = pic;
|
||||||
|
|
||||||
// Make sure the target architecture is a known one; print an error
|
// Make sure the target architecture is a known one; print an error
|
||||||
// with the valid ones otherwise.
|
// with the valid ones otherwise.
|
||||||
t->target = NULL;
|
t->target = NULL;
|
||||||
@@ -228,14 +230,17 @@ llvm::TargetMachine *
|
|||||||
Target::GetTargetMachine() const {
|
Target::GetTargetMachine() const {
|
||||||
std::string triple = GetTripleString();
|
std::string triple = GetTripleString();
|
||||||
|
|
||||||
|
llvm::Reloc::Model relocModel = generatePIC ? llvm::Reloc::PIC_ :
|
||||||
|
llvm::Reloc::Default;
|
||||||
#if defined(LLVM_3_0svn) || defined(LLVM_3_0)
|
#if defined(LLVM_3_0svn) || defined(LLVM_3_0)
|
||||||
std::string featuresString = attributes;
|
std::string featuresString = attributes;
|
||||||
llvm::TargetMachine *targetMachine =
|
llvm::TargetMachine *targetMachine =
|
||||||
target->createTargetMachine(triple, cpu, featuresString);
|
target->createTargetMachine(triple, cpu, featuresString, relocModel);
|
||||||
#else
|
#else
|
||||||
std::string featuresString = cpu + std::string(",") + attributes;
|
std::string featuresString = cpu + std::string(",") + attributes;
|
||||||
llvm::TargetMachine *targetMachine =
|
llvm::TargetMachine *targetMachine =
|
||||||
target->createTargetMachine(triple, featuresString);
|
target->createTargetMachine(triple, featuresString);
|
||||||
|
targetMachine->setRelocationModel(relocModel);
|
||||||
#endif
|
#endif
|
||||||
assert(targetMachine != NULL);
|
assert(targetMachine != NULL);
|
||||||
|
|
||||||
|
|||||||
6
ispc.h
6
ispc.h
@@ -162,7 +162,7 @@ struct Target {
|
|||||||
name, if the name is a known target. Returns true if the
|
name, if the name is a known target. Returns true if the
|
||||||
target was initialized and false if the name is unknown. */
|
target was initialized and false if the name is unknown. */
|
||||||
static bool GetTarget(const char *arch, const char *cpu, const char *isa,
|
static bool GetTarget(const char *arch, const char *cpu, const char *isa,
|
||||||
Target *);
|
bool pic, Target *);
|
||||||
|
|
||||||
/** Returns a comma-delimited string giving the names of the currently
|
/** Returns a comma-delimited string giving the names of the currently
|
||||||
supported target ISAs. */
|
supported target ISAs. */
|
||||||
@@ -215,8 +215,12 @@ struct Target {
|
|||||||
integer multiple of the native vector width, for example if we're
|
integer multiple of the native vector width, for example if we're
|
||||||
"doubling up" and compiling 8-wide on a 4-wide SSE system. */
|
"doubling up" and compiling 8-wide on a 4-wide SSE system. */
|
||||||
int vectorWidth;
|
int vectorWidth;
|
||||||
|
|
||||||
|
/** Indicates whether position independent code should be generated. */
|
||||||
|
bool generatePIC;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @brief Structure that collects optimization options
|
/** @brief Structure that collects optimization options
|
||||||
|
|
||||||
This structure collects all of the options related to optimization of
|
This structure collects all of the options related to optimization of
|
||||||
|
|||||||
8
main.cpp
8
main.cpp
@@ -98,6 +98,7 @@ static void usage(int ret) {
|
|||||||
printf(" disable-uniform-memory-optimizations\tDisable uniform-based coherent memory access\n");
|
printf(" disable-uniform-memory-optimizations\tDisable uniform-based coherent memory access\n");
|
||||||
printf(" disable-masked-store-optimizations\tDisable lowering to regular stores when possible\n");
|
printf(" disable-masked-store-optimizations\tDisable lowering to regular stores when possible\n");
|
||||||
#endif
|
#endif
|
||||||
|
printf(" [--pic]\t\t\t\tGenerate position-independent code\n");
|
||||||
printf(" [--target=<isa>]\t\t\tSelect target ISA. <isa>={%s}\n", Target::SupportedTargetISAs());
|
printf(" [--target=<isa>]\t\t\tSelect target ISA. <isa>={%s}\n", Target::SupportedTargetISAs());
|
||||||
printf(" [--version]\t\t\t\tPrint ispc version\n");
|
printf(" [--version]\t\t\t\tPrint ispc version\n");
|
||||||
printf(" [--woff]\t\t\t\tDisable warnings\n");
|
printf(" [--woff]\t\t\t\tDisable warnings\n");
|
||||||
@@ -184,8 +185,9 @@ int main(int Argc, char *Argv[]) {
|
|||||||
|
|
||||||
bool debugSet = false, optSet = false;
|
bool debugSet = false, optSet = false;
|
||||||
Module::OutputType ot = Module::Object;
|
Module::OutputType ot = Module::Object;
|
||||||
|
bool generatePIC = false;
|
||||||
const char *arch = NULL, *cpu = NULL, *target = NULL;
|
const char *arch = NULL, *cpu = NULL, *target = NULL;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (!strcmp(argv[i], "--help"))
|
if (!strcmp(argv[i], "--help"))
|
||||||
usage(0);
|
usage(0);
|
||||||
@@ -286,6 +288,8 @@ int main(int Argc, char *Argv[]) {
|
|||||||
g->includeStdlib = false;
|
g->includeStdlib = false;
|
||||||
else if (!strcmp(argv[i], "--nocpp"))
|
else if (!strcmp(argv[i], "--nocpp"))
|
||||||
g->runCPP = false;
|
g->runCPP = false;
|
||||||
|
else if (!strcmp(argv[i], "--pic"))
|
||||||
|
generatePIC = true;
|
||||||
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
|
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
|
||||||
printf("Intel(r) SPMD Program Compiler (ispc) build %s (%s)\n",
|
printf("Intel(r) SPMD Program Compiler (ispc) build %s (%s)\n",
|
||||||
BUILD_DATE, BUILD_VERSION);
|
BUILD_DATE, BUILD_VERSION);
|
||||||
@@ -307,7 +311,7 @@ int main(int Argc, char *Argv[]) {
|
|||||||
if (debugSet && !optSet)
|
if (debugSet && !optSet)
|
||||||
g->opt.level = 0;
|
g->opt.level = 0;
|
||||||
|
|
||||||
if (!Target::GetTarget(arch, cpu, target, &g->target))
|
if (!Target::GetTarget(arch, cpu, target, generatePIC, &g->target))
|
||||||
usage(1);
|
usage(1);
|
||||||
|
|
||||||
m = new Module(file);
|
m = new Module(file);
|
||||||
|
|||||||
Reference in New Issue
Block a user