[llvm-commits] [llvm] r168198 - in /llvm/trunk: lib/Target/NVPTX/NVPTXAsmPrinter.cpp test/CodeGen/NVPTX/global-ordering.ll

NAKAMURA Takumi geek4civic at gmail.com
Mon Nov 19 20:43:13 PST 2012


Hal, r168197 should unbreak it.

2012/11/20 Hal Finkel <hfinkel at anl.gov>:
> Joe, Justin,
>
> I think something is wrong with this patch. Running make check from the 3.2 release on a PPC64 system now yields only one failure:
> Failing Tests (1):
>     LLVM :: CodeGen/NVPTX/global-ordering.ll
>
> llc: /release_32/lib/VMCore/Globals.cpp:168: void llvm::GlobalVariable::setInitializer(llvm::Constant*): Assertion `InitVal->getType() == getType()->getElementType() && "Initializer type must match GlobalVariable type"' failed.
> 0  llc       0x0000000010cd86fc
> 1  llc       0x0000000010cd9504
> 2            0x00000fff82480418 __kernel_sigtramp_rt64 + 0
> 3  libc.so.6 0x0000008026676ed8 abort + 18446744073708064136
> 4  libc.so.6 0x000000802666b96c
> 5  libc.so.6 0x000000802666ba84 __assert_fail + 18446744073708021780
> 6  llc       0x0000000010c22fc0 llvm::GlobalVariable::setInitializer(llvm::Constant*) + 18446744073702595016
> 7  llc       0x000000001013fd5c llvm::LLParser::ParseGlobal(std::string const&, llvm::SMLoc, unsigned int, bool, unsigned int) + 18446744073691421044
> 8  llc       0x0000000010140208 llvm::LLParser::ParseNamedGlobal() + 18446744073691422224
> 9  llc       0x0000000010142958 llvm::LLParser::ParseTopLevelEntities() + 18446744073691432176
> 10 llc       0x0000000010142cfc llvm::LLParser::Run() + 18446744073691433092
> 11 llc       0x0000000010124bb0 llvm::ParseAssembly(llvm::MemoryBuffer*, llvm::Module*, llvm::SMDiagnostic&, llvm::LLVMContext&) + 18446744073691313144
> 12 llc       0x000000001011b654 main + 18446744073691275004
> 13 libc.so.6 0x000000802665bcd8
> 14 libc.so.6 0x000000802665bed0 __libc_start_main + 18446744073707958784
> Stack dump:
> 0.      Program arguments: /release_32-build/Release+Asserts/bin/llc -march=nvptx -mcpu=sm_20
> FileCheck error: '-' is empty.
> --
>
>  -Hal
>
> ----- Original Message -----
>> From: "Joe Abbey" <jabbey at arxan.com>
>> To: "Justin Holewinski" <justin.holewinski at gmail.com>
>> Cc: "Pawel Wodnicki" <pawel at 32bitmicro.com>, "llvm-commits" <llvm-commits at cs.uiuc.edu>, "Justin Holewinski"
>> <jholewinski at nvidia.com>
>> Sent: Monday, November 19, 2012 4:30:52 PM
>> Subject: Re: [llvm-commits] [llvm] r168198 - in /llvm/trunk: lib/Target/NVPTX/NVPTXAsmPrinter.cpp
>> test/CodeGen/NVPTX/global-ordering.ll
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> I am the code owner for NVPTX and I approve this patch.
>>
>>
>>
>> On Fri, Nov 16, 2012 at 10:27 PM, Pawel Wodnicki <
>> pawel at 32bitmicro.com > wrote:
>>
>>
>> Justin,
>>
>>
>> > One more for 3.2. :)
>>
>> I will queue it up but merging into the 3.2 is for now suspended
>> as per:
>>
>> http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-November/055895.html
>>
>> Pawel
>>
>>
>>
>>
>> >
>> >
>> > On Fri, Nov 16, 2012 at 4:03 PM, Justin Holewinski
>> > < jholewinski at nvidia.com >wrote:
>> >
>> >> Author: jholewinski
>> >> Date: Fri Nov 16 15:03:51 2012
>> >> New Revision: 168198
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=168198&view=rev
>> >> Log:
>> >> [NVPTX] Order global variables in def-use order before emiting
>> >> them in the
>> >> final assembly
>> >>
>> >> Added:
>> >> llvm/trunk/test/CodeGen/NVPTX/global-ordering.ll
>> >> Modified:
>> >> llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
>> >>
>> >> Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=168198&r1=168197&r2=168198&view=diff
>> >>
>> >> ==============================================================================
>> >> --- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
>> >> +++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Fri Nov 16
>> >> 15:03:51
>> >> 2012
>> >> @@ -68,7 +68,54 @@
>> >>
>> >> cl::location(llvm::InterleaveSrcInPtx));
>> >>
>> >>
>> >> +namespace {
>> >> +/// DiscoverDependentGlobals - Return a set of GlobalVariables on
>> >> which
>> >> \p V
>> >> +/// depends.
>> >> +void DiscoverDependentGlobals(Value *V,
>> >> + DenseSet<GlobalVariable*> &Globals) {
>> >> + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
>> >> + Globals.insert(GV);
>> >> + else {
>> >> + if (User *U = dyn_cast<User>(V)) {
>> >> + for (unsigned i = 0, e = U->getNumOperands(); i != e; ++i) {
>> >> + DiscoverDependentGlobals(U->getOperand(i), Globals);
>> >> + }
>> >> + }
>> >> + }
>> >> +}
>> >>
>> >> +/// VisitGlobalVariableForEmission - Add \p GV to the list of
>> >> GlobalVariable
>> >> +/// instances to be emitted, but only after any dependents have
>> >> been added
>> >> +/// first.
>> >> +void VisitGlobalVariableForEmission(GlobalVariable *GV,
>> >> + SmallVectorImpl<GlobalVariable*>
>> >> &Order,
>> >> + DenseSet<GlobalVariable*> &Visited,
>> >> + DenseSet<GlobalVariable*> &Visiting) {
>> >> + // Have we already visited this one?
>> >> + if (Visited.count(GV)) return;
>> >> +
>> >> + // Do we have a circular dependency?
>> >> + if (Visiting.count(GV))
>> >> + report_fatal_error("Circular dependency found in global variable
>> >> set");
>> >> +
>> >> + // Start visiting this global
>> >> + Visiting.insert(GV);
>> >> +
>> >> + // Make sure we visit all dependents first
>> >> + DenseSet<GlobalVariable*> Others;
>> >> + for (unsigned i = 0, e = GV->getNumOperands(); i != e; ++i)
>> >> + DiscoverDependentGlobals(GV->getOperand(i), Others);
>> >> +
>> >> + for (DenseSet<GlobalVariable*>::iterator I = Others.begin(),
>> >> + E = Others.end(); I != E; ++I)
>> >> + VisitGlobalVariableForEmission(*I, Order, Visited, Visiting);
>> >> +
>> >> + // Now we can visit ourself
>> >> + Order.push_back(GV);
>> >> + Visited.insert(GV);
>> >> + Visiting.erase(GV);
>> >> +}
>> >> +}
>> >>
>> >> // @TODO: This is a copy from AsmPrinter.cpp. The function is
>> >> static, so
>> >> we
>> >> // cannot just link to the existing version.
>> >> @@ -893,10 +940,27 @@
>> >>
>> >> emitDeclarations(M, OS2);
>> >>
>> >> - // Print out module-level global variables here.
>> >> + // As ptxas does not support forward references of globals, we
>> >> need to
>> >> first
>> >> + // sort the list of module-level globals in def-use order. We
>> >> visit each
>> >> + // global variable in order, and ensure that we emit it *after*
>> >> its
>> >> dependent
>> >> + // globals. We use a little extra memory maintaining both a set
>> >> and a
>> >> list to
>> >> + // have fast searches while maintaining a strict ordering.
>> >> + SmallVector<GlobalVariable*,8> Globals;
>> >> + DenseSet<GlobalVariable*> GVVisited;
>> >> + DenseSet<GlobalVariable*> GVVisiting;
>> >> +
>> >> + // Visit each global variable, in order
>> >> for (Module::global_iterator I = M.global_begin(), E =
>> >> M.global_end();
>> >> - I != E; ++I)
>> >> - printModuleLevelGV(I, OS2);
>> >> + I != E; ++I)
>> >> + VisitGlobalVariableForEmission(I, Globals, GVVisited,
>> >> GVVisiting);
>> >> +
>> >> + assert(GVVisited.size() == M.getGlobalList().size() &&
>> >> + "Missed a global variable");
>> >> + assert(GVVisiting.size() == 0 && "Did not fully process a global
>> >> variable");
>> >> +
>> >> + // Print out module-level global variables in proper order
>> >> + for (unsigned i = 0, e = Globals.size(); i != e; ++i)
>> >> + printModuleLevelGV(Globals[i], OS2);
>> >>
>> >> OS2 << '\n';
>> >>
>> >>
>> >> Added: llvm/trunk/test/CodeGen/NVPTX/global-ordering.ll
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/global-ordering.ll?rev=168198&view=auto
>> >>
>> >> ==============================================================================
>> >> --- llvm/trunk/test/CodeGen/NVPTX/global-ordering.ll (added)
>> >> +++ llvm/trunk/test/CodeGen/NVPTX/global-ordering.ll Fri Nov 16
>> >> 15:03:51
>> >> 2012
>> >> @@ -0,0 +1,20 @@
>> >> +; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
>> >> --check-prefix=PTX32
>> >> +; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
>> >> --check-prefix=PTX64
>> >> +
>> >> +; Make sure we emit these globals in def-use order
>> >> +
>> >> +
>> >> +; PTX32: .visible .global .align 1 .u8 a = 2;
>> >> +; PTX32-NEXT: .visible .global .align 4 .u32 a2 = a;
>> >> +; PTX64: .visible .global .align 1 .u8 a = 2;
>> >> +; PTX64-NEXT: .visible .global .align 8 .u64 a2 = a;
>> >> + at a2 = addrspace(1) global i8 addrspace(1)* @a
>> >> + at a = addrspace(1) global i8 2
>> >> +
>> >> +
>> >> +; PTX32: .visible .global .align 1 .u8 b = 1;
>> >> +; PTX32-NEXT: .visible .global .align 4 .u32 b2[2] = {b, b};
>> >> +; PTX64: .visible .global .align 1 .u8 b = 1;
>> >> +; PTX64-NEXT: .visible .global .align 8 .u64 b2[2] = {b, b};
>> >> + at b2 = addrspace(1) global [2 x i8 addrspace(1)*] [i8
>> >> addrspace(1)* @b, i8
>> >> addrspace(1)* @b]
>> >> + at b = addrspace(1) global i8 1
>> >>
>> >>
>> >> _______________________________________________
>> >> llvm-commits mailing list
>> >> llvm-commits at cs.uiuc.edu
>> >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>> >>
>> >
>> >
>> >
>>
>>
>>
>>
>>
>> --
>>
>>
>> Thanks,
>>
>>
>> Justin Holewinski
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
> --
> Hal Finkel
> Postdoctoral Appointee
> Leadership Computing Facility
> Argonne National Laboratory
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list