mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 19:06:02 +03:00
LLVMContext::setDiscardValueNames(true) when not compiling to textual IR.
Resolves #1749
This commit is contained in:
parent
b17e1485ed
commit
b70042a85e
4 changed files with 67 additions and 0 deletions
|
@ -84,6 +84,13 @@ CodeGenerator::CodeGenerator(llvm::LLVMContext &context, bool singleObj)
|
||||||
"configured properly");
|
"configured properly");
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 309
|
||||||
|
// Set the context to discard value names when not generating textual IR.
|
||||||
|
if (!global.params.output_ll) {
|
||||||
|
context_.setDiscardValueNames(true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeGenerator::~CodeGenerator() {
|
CodeGenerator::~CodeGenerator() {
|
||||||
|
|
|
@ -16,6 +16,24 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
/// Sets LLVMContext::setDiscardValueNames(false) upon construction and restores
|
||||||
|
/// the previous value upon destruction.
|
||||||
|
struct TempDisableDiscardValueNames {
|
||||||
|
#if LDC_LLVM_VER >= 309
|
||||||
|
llvm::LLVMContext &ctx;
|
||||||
|
bool previousValue;
|
||||||
|
|
||||||
|
TempDisableDiscardValueNames(llvm::LLVMContext &context)
|
||||||
|
: ctx(context), previousValue(context.shouldDiscardValueNames()) {
|
||||||
|
ctx.setDiscardValueNames(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
~TempDisableDiscardValueNames() { ctx.setDiscardValueNames(previousValue); }
|
||||||
|
#else
|
||||||
|
TempDisableDiscardValueNames(llvm::LLVMContext &context) {}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
/// Adds the idol's function attributes to the wannabe
|
/// Adds the idol's function attributes to the wannabe
|
||||||
void copyFnAttributes(llvm::Function *wannabe, llvm::Function *idol) {
|
void copyFnAttributes(llvm::Function *wannabe, llvm::Function *idol) {
|
||||||
auto attrSet = idol->getAttributes();
|
auto attrSet = idol->getAttributes();
|
||||||
|
@ -29,6 +47,10 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
|
||||||
IF_LOG Logger::println("DtoInlineIRExpr @ %s", loc.toChars());
|
IF_LOG Logger::println("DtoInlineIRExpr @ %s", loc.toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
|
// LLVM can't read textual IR with a Context that discards named Values, so
|
||||||
|
// temporarily disable value name discarding.
|
||||||
|
TempDisableDiscardValueNames tempDisable(gIR->context());
|
||||||
|
|
||||||
// Generate a random new function name. Because the inlineIR function is
|
// Generate a random new function name. Because the inlineIR function is
|
||||||
// always inlined, this name does not escape the current compiled module; not
|
// always inlined, this name does not escape the current compiled module; not
|
||||||
// even at -O0.
|
// even at -O0.
|
||||||
|
|
24
tests/codegen/discard_value_names_gh1749.d
Normal file
24
tests/codegen/discard_value_names_gh1749.d
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// Test value name discarding when creating non-textual IR.
|
||||||
|
|
||||||
|
// REQUIRES: atleast_llvm309
|
||||||
|
|
||||||
|
// RUN: %ldc %S/inputs/input_discard_valuename.d -c -output-ll -of=%t.bar.ll && FileCheck %S/inputs/input_discard_valuename.d < %t.bar.ll
|
||||||
|
|
||||||
|
// Output a bitcode file (i.e. with discarded names) and input it into a second LDC command that outputs textual IR.
|
||||||
|
// RUN: %ldc %S/inputs/input_discard_valuename.d -g -c -output-bc -of=%t.bar.bc \
|
||||||
|
// RUN: && %ldc %s %t.bar.bc -g -c -output-ll -of=%t.ll && FileCheck %s < %t.ll
|
||||||
|
|
||||||
|
// IR imported from the bitcode file should not have local value names:
|
||||||
|
// CHECK-LABEL: define{{.*}} @foo
|
||||||
|
// CHECK: %localfoovar
|
||||||
|
// CHECK-LABEL: define{{.*}} @bar
|
||||||
|
// CHECK-NOT: %localbarvar
|
||||||
|
|
||||||
|
// But the imported IR should still have debug names:
|
||||||
|
// CHECK: DILocalVariable{{.*}}"localfoovar"
|
||||||
|
// CHECK: DILocalVariable{{.*}}"localbarvar"
|
||||||
|
|
||||||
|
extern(C) void foo()
|
||||||
|
{
|
||||||
|
int localfoovar;
|
||||||
|
}
|
14
tests/codegen/inputs/input_discard_valuename.d
Normal file
14
tests/codegen/inputs/input_discard_valuename.d
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// CHECK-LABEL: define{{.*}} @bar(
|
||||||
|
extern(C) void bar()
|
||||||
|
{
|
||||||
|
// CHECK: localbarvar
|
||||||
|
int localbarvar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we can use inline IR in non-textual IR compiles:
|
||||||
|
pragma(LDC_inline_ir) R __ir(string s, R, P...)(P);
|
||||||
|
double inlineIR(double a)
|
||||||
|
{
|
||||||
|
auto s = __ir!(`ret double %0`, double)(a);
|
||||||
|
return s;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue