Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 28ad033

Browse files
committed
Start a JS backend cost model
Implement the TargetTransformInfo interface with JSTargetTransformInfo, which gives costs used by the optimizer. The implementation is currently fairly minimal.
1 parent a0df0e0 commit 28ad033

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

lib/Target/JSBackend/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_llvm_target(JSBackendCodeGen
33
ExpandI64.cpp
44
JSBackend.cpp
55
JSTargetMachine.cpp
6+
JSTargetTransformInfo.cpp
67
Relooper.cpp
78
SimplifyAllocas.cpp
89
)

lib/Target/JSBackend/JS.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===-- JS.h - Top-level interface for JS representation ------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file contains the entry points for global functions defined in the JS
11+
// target library, as used by the LLVM JIT.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef TARGET_JS_H
16+
#define TARGET_JS_H
17+
18+
namespace llvm {
19+
20+
class ImmutablePass;
21+
class JSTargetMachine;
22+
23+
/// createJSISelDag - This pass converts a legalized DAG into a
24+
/// \brief Creates an JS-specific Target Transformation Info pass.
25+
ImmutablePass *createJSTargetTransformInfoPass(const JSTargetMachine *TM);
26+
27+
} // End llvm namespace
28+
29+
#endif

lib/Target/JSBackend/JSTargetMachine.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1+
//===-- JSTargetMachine.cpp - Define TargetMachine for the JS -------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file defines the JS specific subclass of TargetMachine.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
114
#include "JSTargetMachine.h"
15+
#include "llvm/CodeGen/Passes.h"
216
#include "llvm/Support/TargetRegistry.h"
317
#include "llvm/PassManager.h"
418
using namespace llvm;
@@ -12,3 +26,9 @@ JSTargetMachine::JSTargetMachine(const Target &T, StringRef Triple,
1226
"f32:32:32-f64:64:64-p:32:32:32-v128:32:128-n32-S128") {
1327
CodeGenInfo = T.createMCCodeGenInfo(Triple, RM, CM, OL);
1428
}
29+
30+
void JSTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
31+
// We don't currently use BasicTTI because that depends on
32+
// TargetLoweringInfo, which we don't currently implement.
33+
PM.add(createJSTargetTransformInfoPass(this));
34+
}

lib/Target/JSBackend/JSTargetMachine.h

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef JSTARGETMACHINE_H
1616
#define JSTARGETMACHINE_H
1717

18+
#include "JS.h"
1819
#include "llvm/IR/DataLayout.h"
1920
#include "llvm/Target/TargetMachine.h"
2021

@@ -39,6 +40,9 @@ class JSTargetMachine : public TargetMachine {
3940
AnalysisID StopAfter);
4041

4142
virtual const DataLayout *getDataLayout() const { return &DL; }
43+
44+
/// \brief Register X86 analysis passes with a pass manager.
45+
virtual void addAnalysisPasses(PassManagerBase &PM);
4246
};
4347

4448
} // End llvm namespace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//===-- JSTargetTransformInfo.cpp - JS specific TTI pass ------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
/// \file
10+
/// This file implements a TargetTransformInfo analysis pass specific to the
11+
/// JS target machine. It uses the target's detailed information to provide
12+
/// more precise answers to certain TTI queries, while letting the target
13+
/// independent and default TTI implementations handle the rest.
14+
///
15+
//===----------------------------------------------------------------------===//
16+
17+
#define DEBUG_TYPE "jstti"
18+
#include "JS.h"
19+
#include "JSTargetMachine.h"
20+
#include "llvm/Analysis/TargetTransformInfo.h"
21+
#include "llvm/Support/Debug.h"
22+
#include "llvm/Target/TargetLowering.h"
23+
#include "llvm/Target/CostTable.h"
24+
using namespace llvm;
25+
26+
// Declare the pass initialization routine locally as target-specific passes
27+
// don't havve a target-wide initialization entry point, and so we rely on the
28+
// pass constructor initialization.
29+
namespace llvm {
30+
void initializeJSTTIPass(PassRegistry &);
31+
}
32+
33+
namespace {
34+
35+
class JSTTI : public ImmutablePass, public TargetTransformInfo {
36+
public:
37+
JSTTI() : ImmutablePass(ID) {
38+
llvm_unreachable("This pass cannot be directly constructed");
39+
}
40+
41+
JSTTI(const JSTargetMachine *TM)
42+
: ImmutablePass(ID) {
43+
initializeJSTTIPass(*PassRegistry::getPassRegistry());
44+
}
45+
46+
virtual void initializePass() {
47+
pushTTIStack(this);
48+
}
49+
50+
virtual void finalizePass() {
51+
popTTIStack();
52+
}
53+
54+
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
55+
TargetTransformInfo::getAnalysisUsage(AU);
56+
}
57+
58+
/// Pass identification.
59+
static char ID;
60+
61+
/// Provide necessary pointer adjustments for the two base classes.
62+
virtual void *getAdjustedAnalysisPointer(const void *ID) {
63+
if (ID == &TargetTransformInfo::ID)
64+
return (TargetTransformInfo*)this;
65+
return this;
66+
}
67+
68+
virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
69+
70+
virtual unsigned getRegisterBitWidth(bool Vector) const;
71+
};
72+
73+
} // end anonymous namespace
74+
75+
INITIALIZE_AG_PASS(JSTTI, TargetTransformInfo, "jstti",
76+
"JS Target Transform Info", true, true, false)
77+
char JSTTI::ID = 0;
78+
79+
ImmutablePass *
80+
llvm::createJSTargetTransformInfoPass(const JSTargetMachine *TM) {
81+
return new JSTTI(TM);
82+
}
83+
84+
85+
//===----------------------------------------------------------------------===//
86+
//
87+
// JS cost model.
88+
//
89+
//===----------------------------------------------------------------------===//
90+
91+
JSTTI::PopcntSupportKind JSTTI::getPopcntSupport(unsigned TyWidth) const {
92+
assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
93+
// Hopefully we'll get popcnt in ES7, but for now, we just have software.
94+
return PSK_Software;
95+
}
96+
97+
unsigned JSTTI::getRegisterBitWidth(bool Vector) const {
98+
if (Vector) {
99+
return 128;
100+
}
101+
102+
return 32;
103+
}

0 commit comments

Comments
 (0)