2008-11-07 10:59:00 +00:00
|
|
|
//===-- XCoreTargetMachine.cpp - Define TargetMachine for XCore -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "XCoreTargetMachine.h"
|
2014-11-13 09:26:31 +00:00
|
|
|
#include "XCoreTargetObjectFile.h"
|
2015-01-31 11:17:59 +00:00
|
|
|
#include "XCoreTargetTransformInfo.h"
|
2008-11-07 10:59:00 +00:00
|
|
|
#include "XCore.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2008-11-07 10:59:00 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2008-11-07 10:59:00 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
/// XCoreTargetMachine ctor - Create an ILP32 architecture model
|
|
|
|
///
|
2011-07-19 06:37:02 +00:00
|
|
|
XCoreTargetMachine::XCoreTargetMachine(const Target &T, StringRef TT,
|
2011-07-20 07:51:56 +00:00
|
|
|
StringRef CPU, StringRef FS,
|
2011-12-02 22:16:29 +00:00
|
|
|
const TargetOptions &Options,
|
2011-11-16 08:38:26 +00:00
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
2014-07-02 00:10:09 +00:00
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
2014-11-13 09:26:31 +00:00
|
|
|
TLOF(make_unique<XCoreTargetObjectFile>()),
|
2015-01-26 19:03:15 +00:00
|
|
|
DL("e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32-f64:32-a:0:32-n32"),
|
2014-07-02 00:10:09 +00:00
|
|
|
Subtarget(TT, CPU, FS, *this) {
|
2013-05-13 01:16:13 +00:00
|
|
|
initAsmInfo();
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 23:37:18 +00:00
|
|
|
XCoreTargetMachine::~XCoreTargetMachine() {}
|
|
|
|
|
2012-02-03 05:12:41 +00:00
|
|
|
namespace {
|
|
|
|
/// XCore Code Generator Pass Configuration Options.
|
|
|
|
class XCorePassConfig : public TargetPassConfig {
|
|
|
|
public:
|
2012-02-04 02:56:59 +00:00
|
|
|
XCorePassConfig(XCoreTargetMachine *TM, PassManagerBase &PM)
|
|
|
|
: TargetPassConfig(TM, PM) {}
|
2012-02-03 05:12:41 +00:00
|
|
|
|
|
|
|
XCoreTargetMachine &getXCoreTargetMachine() const {
|
|
|
|
return getTM<XCoreTargetMachine>();
|
|
|
|
}
|
|
|
|
|
Erase fence insertion from SelectionDAGBuilder.cpp (NFC)
Summary:
Backends can use setInsertFencesForAtomic to signal to the middle-end that
montonic is the only memory ordering they can accept for
stores/loads/rmws/cmpxchg. The code lowering those accesses with a stronger
ordering to fences + monotonic accesses is currently living in
SelectionDAGBuilder.cpp. In this patch I propose moving this logic out of it
for several reasons:
- There is lots of redundancy to avoid: extremely similar logic already
exists in AtomicExpand.
- The current code in SelectionDAGBuilder does not use any target-hooks, it
does the same transformation for every backend that requires it
- As a result it is plain *unsound*, as it was apparently designed for ARM.
It happens to mostly work for the other targets because they are extremely
conservative, but Power for example had to switch to AtomicExpand to be
able to use lwsync safely (see r218331).
- Because it produces IR-level fences, it cannot be made sound ! This is noted
in the C++11 standard (section 29.3, page 1140):
```
Fences cannot, in general, be used to restore sequential consistency for atomic
operations with weaker ordering semantics.
```
It can also be seen by the following example (called IRIW in the litterature):
```
atomic<int> x = y = 0;
int r1, r2, r3, r4;
Thread 0:
x.store(1);
Thread 1:
y.store(1);
Thread 2:
r1 = x.load();
r2 = y.load();
Thread 3:
r3 = y.load();
r4 = x.load();
```
r1 = r3 = 1 and r2 = r4 = 0 is impossible as long as the accesses are all seq_cst.
But if they are lowered to monotonic accesses, no amount of fences can prevent it..
This patch does three things (I could cut it into parts, but then some of them
would not be tested/testable, please tell me if you would prefer that):
- it provides a default implementation for emitLeadingFence/emitTrailingFence in
terms of IR-level fences, that mimic the original logic of SelectionDAGBuilder.
As we saw above, this is unsound, but the best that can be done without knowing
the targets well (and there is a comment warning about this risk).
- it then switches Mips/Sparc/XCore to use AtomicExpand, relying on this default
implementation (that exactly replicates the logic of SelectionDAGBuilder, so no
functional change)
- it finally erase this logic from SelectionDAGBuilder as it is dead-code.
Ideally, each target would define its own override for emitLeading/TrailingFence
using target-specific fences, but I do not know the Sparc/Mips/XCore memory model
well enough to do this, and they appear to be dealing fine with the ARM-inspired
default expansion for now (probably because they are overly conservative, as
Power was). If anyone wants to compile fences more agressively on these
platforms, the long comment should make it clear why he should first override
emitLeading/TrailingFence.
Test Plan: make check-all, no functional change
Reviewers: jfb, t.p.northover
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D5474
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219957 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-16 20:34:57 +00:00
|
|
|
void addIRPasses() override;
|
2014-04-29 07:57:00 +00:00
|
|
|
bool addPreISel() override;
|
|
|
|
bool addInstSelector() override;
|
2014-12-11 21:26:47 +00:00
|
|
|
void addPreEmitPass() override;
|
2012-02-03 05:12:41 +00:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-04 02:56:59 +00:00
|
|
|
TargetPassConfig *XCoreTargetMachine::createPassConfig(PassManagerBase &PM) {
|
|
|
|
return new XCorePassConfig(this, PM);
|
2012-02-03 05:12:41 +00:00
|
|
|
}
|
|
|
|
|
Erase fence insertion from SelectionDAGBuilder.cpp (NFC)
Summary:
Backends can use setInsertFencesForAtomic to signal to the middle-end that
montonic is the only memory ordering they can accept for
stores/loads/rmws/cmpxchg. The code lowering those accesses with a stronger
ordering to fences + monotonic accesses is currently living in
SelectionDAGBuilder.cpp. In this patch I propose moving this logic out of it
for several reasons:
- There is lots of redundancy to avoid: extremely similar logic already
exists in AtomicExpand.
- The current code in SelectionDAGBuilder does not use any target-hooks, it
does the same transformation for every backend that requires it
- As a result it is plain *unsound*, as it was apparently designed for ARM.
It happens to mostly work for the other targets because they are extremely
conservative, but Power for example had to switch to AtomicExpand to be
able to use lwsync safely (see r218331).
- Because it produces IR-level fences, it cannot be made sound ! This is noted
in the C++11 standard (section 29.3, page 1140):
```
Fences cannot, in general, be used to restore sequential consistency for atomic
operations with weaker ordering semantics.
```
It can also be seen by the following example (called IRIW in the litterature):
```
atomic<int> x = y = 0;
int r1, r2, r3, r4;
Thread 0:
x.store(1);
Thread 1:
y.store(1);
Thread 2:
r1 = x.load();
r2 = y.load();
Thread 3:
r3 = y.load();
r4 = x.load();
```
r1 = r3 = 1 and r2 = r4 = 0 is impossible as long as the accesses are all seq_cst.
But if they are lowered to monotonic accesses, no amount of fences can prevent it..
This patch does three things (I could cut it into parts, but then some of them
would not be tested/testable, please tell me if you would prefer that):
- it provides a default implementation for emitLeadingFence/emitTrailingFence in
terms of IR-level fences, that mimic the original logic of SelectionDAGBuilder.
As we saw above, this is unsound, but the best that can be done without knowing
the targets well (and there is a comment warning about this risk).
- it then switches Mips/Sparc/XCore to use AtomicExpand, relying on this default
implementation (that exactly replicates the logic of SelectionDAGBuilder, so no
functional change)
- it finally erase this logic from SelectionDAGBuilder as it is dead-code.
Ideally, each target would define its own override for emitLeading/TrailingFence
using target-specific fences, but I do not know the Sparc/Mips/XCore memory model
well enough to do this, and they appear to be dealing fine with the ARM-inspired
default expansion for now (probably because they are overly conservative, as
Power was). If anyone wants to compile fences more agressively on these
platforms, the long comment should make it clear why he should first override
emitLeading/TrailingFence.
Test Plan: make check-all, no functional change
Reviewers: jfb, t.p.northover
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D5474
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219957 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-16 20:34:57 +00:00
|
|
|
void XCorePassConfig::addIRPasses() {
|
|
|
|
addPass(createAtomicExpandPass(&getXCoreTargetMachine()));
|
|
|
|
|
|
|
|
TargetPassConfig::addIRPasses();
|
|
|
|
}
|
|
|
|
|
2013-05-04 17:01:55 +00:00
|
|
|
bool XCorePassConfig::addPreISel() {
|
|
|
|
addPass(createXCoreLowerThreadLocalPass());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-03 05:12:41 +00:00
|
|
|
bool XCorePassConfig::addInstSelector() {
|
2012-07-02 19:48:31 +00:00
|
|
|
addPass(createXCoreISelDag(getXCoreTargetMachine(), getOptLevel()));
|
2008-11-07 10:59:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-08-15 12:53:15 +00:00
|
|
|
|
2014-12-11 21:26:47 +00:00
|
|
|
void XCorePassConfig::addPreEmitPass() {
|
|
|
|
addPass(createXCoreFrameToArgsOffsetEliminationPass(), false);
|
2014-01-06 14:21:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 12:53:15 +00:00
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeXCoreTarget() {
|
|
|
|
RegisterTargetMachine<XCoreTargetMachine> X(TheXCoreTarget);
|
|
|
|
}
|
2013-09-18 12:43:35 +00:00
|
|
|
|
2015-02-01 13:20:00 +00:00
|
|
|
TargetIRAnalysis XCoreTargetMachine::getTargetIRAnalysis() {
|
|
|
|
return TargetIRAnalysis(
|
|
|
|
[this](Function &) { return TargetTransformInfo(XCoreTTIImpl(this)); });
|
2013-09-18 12:43:35 +00:00
|
|
|
}
|